正在显示
1 个修改的文件
包含
197 行增加
和
0 行删除
src/core/dmpapplication.cpp
0 → 100644
1 | +/************************************************************************** | ||
2 | +* file: dmpapplication.cpp | ||
3 | + | ||
4 | +* Author: wanzhongping | ||
5 | +* Date: 2021-02-24 11:23:15 | ||
6 | +* Email: zhongpingw@chinadci.com | ||
7 | +* copyright: 广州城市信息研究所有限公司 | ||
8 | +***************************************************************************/ | ||
9 | +#include "dmpapplication.h" | ||
10 | +#include <iostream> | ||
11 | +#include <fstream> | ||
12 | +#include "dmpconfig.h" | ||
13 | +#include "dmplogger.h" | ||
14 | + | ||
15 | +bool DmpApplication::running_from_build_dir_ = false; | ||
16 | +bool DmpApplication::initialized_ = false; | ||
17 | +std::string DmpApplication::plugin_path_ = ""; | ||
18 | +std::string DmpApplication::prefix_path_ = ""; | ||
19 | +std::string DmpApplication::libexec_path_ = ""; | ||
20 | +std::string DmpApplication::library_path_ = ""; | ||
21 | +std::string DmpApplication::build_source_path_ = ""; | ||
22 | +std::string DmpApplication::build_output_path_ = ""; | ||
23 | +std::string DmpApplication::pkg_data_path_ = ""; | ||
24 | + | ||
25 | +DmpApplication::DmpApplication() | ||
26 | +{ | ||
27 | + std::cout << "constructor called!" << std::endl; | ||
28 | + LOGGER_DEBUG("constructor called!"); | ||
29 | +} | ||
30 | + | ||
31 | +DmpApplication::~DmpApplication() | ||
32 | +{ | ||
33 | + std::cout << "destructor called!" << std::endl; | ||
34 | + LOGGER_DEBUG("destructor called!"); | ||
35 | +} | ||
36 | + | ||
37 | +DmpApplication &DmpApplication::Instance() | ||
38 | +{ | ||
39 | + static DmpApplication instance; | ||
40 | + return instance; | ||
41 | +} | ||
42 | + | ||
43 | +void DmpApplication::Init() | ||
44 | +{ | ||
45 | + LOGGER_INFO("DmpApplication init..."); | ||
46 | + ResolvePkgPath(); | ||
47 | + if (running_from_build_dir_) | ||
48 | + { | ||
49 | + // we run from source directory - not installed to destination (specified prefix) | ||
50 | + prefix_path_ = ""; | ||
51 | + set_plugin_path(build_source_path_ + '/' + DMAP_PLUGIN_SUBDIR); | ||
52 | + set_pkg_data_path(build_output_path_ + "/data"); // in buildDir/data - used for: doc, resources, svg | ||
53 | + library_path_ = build_output_path_ + '/' + DMAP_LIB_SUBDIR + '/'; | ||
54 | + libexec_path_ = build_output_path_ + '/' + DMAP_LIBEXEC_SUBDIR + '/'; | ||
55 | + } | ||
56 | + else | ||
57 | + { | ||
58 | + char *prefix_path = getenv("DMAP_PREFIX_PATH"); | ||
59 | + if (!prefix_path) | ||
60 | + { | ||
61 | + set_prefix_path("/usr/local"); | ||
62 | + }else{ | ||
63 | + set_prefix_path(prefix_path); | ||
64 | + } | ||
65 | + } | ||
66 | + initialized_ = true; | ||
67 | + LOGGER_INFO("DmpApplication init done"); | ||
68 | +} | ||
69 | +bool DmpApplication::IsRunningFromBuildDir() | ||
70 | +{ | ||
71 | + return running_from_build_dir_; | ||
72 | +} | ||
73 | +std::string DmpApplication::ApplicationDirPath() | ||
74 | +{ | ||
75 | + boost::filesystem::path libDir = boost::filesystem::current_path(); | ||
76 | + return libDir.c_str(); | ||
77 | +} | ||
78 | + | ||
79 | +std::string DmpApplication::ResolvePkgPath() | ||
80 | +{ | ||
81 | + std::string app_path = ApplicationDirPath(); | ||
82 | + if (!app_path.empty() || getenv("DMAP_PREFIX_PATH")) | ||
83 | + { | ||
84 | + std::string prefix_Path = getenv("DMAP_PREFIX_PATH") ? getenv("DMAP_PREFIX_PATH") : app_path; | ||
85 | + // check if DMAP is run from build directory (not the install directory) | ||
86 | + boost::filesystem::path dmapbuildpath; | ||
87 | + boost::filesystem::path dir(prefix_Path); | ||
88 | + if (SearchFile(dir, "dmapbuildpath.txt", dmapbuildpath)) | ||
89 | + { | ||
90 | + std::cout << dmapbuildpath.c_str() << std::endl; | ||
91 | + running_from_build_dir_ = true; | ||
92 | + std::ifstream fin(dmapbuildpath.c_str()); | ||
93 | + std::getline(fin, build_source_path_); | ||
94 | + boost::trim(build_source_path_); | ||
95 | + std::getline(fin, build_output_path_); | ||
96 | + boost::trim(build_output_path_); | ||
97 | + } | ||
98 | + | ||
99 | + if (IsRunningFromBuildDir) | ||
100 | + { | ||
101 | + return build_output_path_ + "/Data"; | ||
102 | + } | ||
103 | + else | ||
104 | + { | ||
105 | + return prefix_Path + '/' + DMAP_DATA_SUBDIR; | ||
106 | + } | ||
107 | + } | ||
108 | + return ""; | ||
109 | +} | ||
110 | +std::string DmpApplication::pkg_data_path() | ||
111 | +{ | ||
112 | + return pkg_data_path_; | ||
113 | +} | ||
114 | +void DmpApplication::set_pkg_data_path(const std::string &pkg_data_path) | ||
115 | +{ | ||
116 | + pkg_data_path_ = pkg_data_path; | ||
117 | +} | ||
118 | + | ||
119 | +std::string DmpApplication::library_path() | ||
120 | +{ | ||
121 | + return library_path_; | ||
122 | +} | ||
123 | + | ||
124 | +void DmpApplication::set_prefix_path(const std::string &prefix_path) | ||
125 | +{ | ||
126 | + LOGGER_DEBUG("set_prefix_path: " + prefix_path); | ||
127 | + prefix_path_ = prefix_path; | ||
128 | + if(IsRunningFromBuildDir) | ||
129 | + { | ||
130 | + set_plugin_path(prefix_path_ + '/' + DMAP_PLUGIN_SUBDIR); | ||
131 | + set_pkg_data_path(prefix_path_ + '/' + DMAP_DATA_SUBDIR); | ||
132 | + } | ||
133 | + library_path_ = prefix_path_ + '/' + DMAP_LIB_SUBDIR + '/'; | ||
134 | + libexec_path_ = prefix_path_ + '/' + DMAP_LIBEXEC_SUBDIR + '/'; | ||
135 | +} | ||
136 | + | ||
137 | +bool DmpApplication::SearchFile(const boost::filesystem::path &dir, const std::string file_name, boost::filesystem::path &path) | ||
138 | +{ | ||
139 | + if (!boost::filesystem::exists(dir)) | ||
140 | + { | ||
141 | + return false; | ||
142 | + } | ||
143 | + | ||
144 | + boost::filesystem::directory_iterator end_iter; | ||
145 | + for (boost::filesystem::directory_iterator iter(dir); iter != end_iter; ++iter) | ||
146 | + { | ||
147 | + if (boost::filesystem::is_regular_file(iter->status()) && iter->path().filename() == file_name) | ||
148 | + { | ||
149 | + path = iter->path(); | ||
150 | + return true; | ||
151 | + } | ||
152 | + | ||
153 | + if (boost::filesystem::is_directory(iter->status())) | ||
154 | + { | ||
155 | + if (SearchFile(iter->path(), file_name, path)) | ||
156 | + { | ||
157 | + return true; | ||
158 | + } | ||
159 | + } | ||
160 | + } | ||
161 | + return false; | ||
162 | +} | ||
163 | + | ||
164 | +void DmpApplication::set_plugin_path(const std::string &plugin_path) | ||
165 | +{ | ||
166 | + plugin_path_ = plugin_path; | ||
167 | +} | ||
168 | + | ||
169 | +std::string DmpApplication::prefix_path() | ||
170 | +{ | ||
171 | + return prefix_path_; | ||
172 | +} | ||
173 | + | ||
174 | +std::string DmpApplication::libexec_path() | ||
175 | +{ | ||
176 | + return libexec_path_; | ||
177 | +} | ||
178 | + | ||
179 | +std::string DmpApplication::plugin_path() | ||
180 | +{ | ||
181 | + return plugin_path_; | ||
182 | +} | ||
183 | + | ||
184 | +bool DmpApplication::CreateDatabase() | ||
185 | +{ | ||
186 | + return false; | ||
187 | +} | ||
188 | + | ||
189 | +std::string DmpApplication::build_output_path() | ||
190 | +{ | ||
191 | + return build_output_path_; | ||
192 | +} | ||
193 | + | ||
194 | +std::string DmpApplication::DMapSettingsDirPath() | ||
195 | +{ | ||
196 | + return ""; | ||
197 | +} |
请
注册
或
登录
后发表评论