提交 00c3feaaa7d37eb2174c4e7bba62b17c787dec3d

作者 WZP 万忠平
1 个父辈 3787f4fa

wzp

@@ -13,15 +13,6 @@ @@ -13,15 +13,6 @@
13 #include <boost/property_tree/ini_parser.hpp> 13 #include <boost/property_tree/ini_parser.hpp>
14 #include <boost/property_tree/ptree.hpp> 14 #include <boost/property_tree/ptree.hpp>
15 15
16 -// bool DmpApplication::running_from_build_dir_ = false;  
17 -// bool DmpApplication::initialized_ = false;  
18 -// std::string DmpApplication::plugin_path_ = "";  
19 -// std::string DmpApplication::prefix_path_ = "";  
20 -// std::string DmpApplication::libexec_path_ = "";  
21 -// std::string DmpApplication::library_path_ = "";  
22 -// std::string DmpApplication::build_source_path_ = "";  
23 -// std::string DmpApplication::build_output_path_ = "";  
24 -// std::string DmpApplication::pkgDataPath_ = "";  
25 16
26 DmpApplication::DmpApplication() 17 DmpApplication::DmpApplication()
27 { 18 {
@@ -60,7 +51,6 @@ void DmpApplication::initialize() @@ -60,7 +51,6 @@ void DmpApplication::initialize()
60 setPrefixPath(prefixPath); 51 setPrefixPath(prefixPath);
61 } 52 }
62 } 53 }
63 - // createIniFile(libexecPath_);  
64 initialized_ = true; 54 initialized_ = true;
65 } 55 }
66 bool DmpApplication::isRunningFromBuildDir() 56 bool DmpApplication::isRunningFromBuildDir()
@@ -195,21 +185,4 @@ std::string DmpApplication::buildOutputPath() @@ -195,21 +185,4 @@ std::string DmpApplication::buildOutputPath()
195 std::string DmpApplication::dmapSettingsDirPath() 185 std::string DmpApplication::dmapSettingsDirPath()
196 { 186 {
197 return ""; 187 return "";
198 -}  
199 -  
200 -void DmpApplication::createIniFile(const std::string &filePath)  
201 -{  
202 - std::string fileName = filePath + iniFileName_;  
203 - if(!boost::filesystem::exists(fileName)) {  
204 - boost::property_tree::ptree pt;  
205 - pt.put<std::string>("Core.Filter","%Severity% >= debug");  
206 - pt.put<std::string>("Sinks.TextFileSettings.Destination","TextFile");  
207 - // pt.put<std::string>("Sinks.TextFileSettings.FileName","/var/log/dmap/%Y%m%d.log");  
208 - // pt.put<bool>("Sinks.TextFileSettings.AutoFlush",true);  
209 - boost::property_tree::ini_parser::write_ini(fileName,pt);  
210 - }  
211 -  
212 - // boost::property_tree::ptree root_node, tag_system;  
213 - // boost::property_tree::ini_parser::read_ini("config.ini", root_node);  
214 -  
215 -} 188 +}
@@ -26,10 +26,9 @@ public: @@ -26,10 +26,9 @@ public:
26 //static bool CreateDatabase(); 26 //static bool CreateDatabase();
27 std::string resolvePkgPath(); 27 std::string resolvePkgPath();
28 std::string applicationDirPath(); 28 std::string applicationDirPath();
29 - bool searchFile(const boost::filesystem::path &dir, const std::string fileName, boost::filesystem::path &path); 29 + std::string dmapSettingsDirPath();
  30 +
30 bool isRunningFromBuildDir(); 31 bool isRunningFromBuildDir();
31 - static std::string dmapSettingsDirPath();  
32 -  
33 std::string prefixPath(); 32 std::string prefixPath();
34 void setPrefixPath(const std::string &prefixPath); 33 void setPrefixPath(const std::string &prefixPath);
35 void setPluginPath(const std::string &pluginPath); 34 void setPluginPath(const std::string &pluginPath);
@@ -40,12 +39,11 @@ public: @@ -40,12 +39,11 @@ public:
40 std::string pkgDataPath(); 39 std::string pkgDataPath();
41 std::string libraryPath(); 40 std::string libraryPath();
42 std::string buildOutputPath(); 41 std::string buildOutputPath();
43 -  
44 - void createIniFile(const std::string &filePath);  
45 - 42 +
46 private: 43 private:
47 DmpApplication(); 44 DmpApplication();
48 - 45 + bool searchFile(const boost::filesystem::path &dir, const std::string fileName, boost::filesystem::path &path);
  46 +
49 std::string prefixPath_; 47 std::string prefixPath_;
50 std::string libexecPath_; 48 std::string libexecPath_;
51 std::string libraryPath_; 49 std::string libraryPath_;
@@ -53,9 +51,9 @@ private: @@ -53,9 +51,9 @@ private:
53 std::string buildSourcePath_; 51 std::string buildSourcePath_;
54 std::string buildOutputPath_; 52 std::string buildOutputPath_;
55 std::string pkgDataPath_; 53 std::string pkgDataPath_;
  54 + std::string iniFilePath_;
56 bool runningFromBuildDir_; 55 bool runningFromBuildDir_;
57 bool initialized_; 56 bool initialized_;
58 - const std::string iniFileName_ = "dmap.ini";  
59 }; 57 };
60 58
61 #endif //__dmpapplication_h__ 59 #endif //__dmpapplication_h__
@@ -18,6 +18,7 @@ SET (DMAP_SERVER_SRCS @@ -18,6 +18,7 @@ SET (DMAP_SERVER_SRCS
18 dmprequesthandler.cpp 18 dmprequesthandler.cpp
19 dmpserver.cpp 19 dmpserver.cpp
20 dmpserverapi.cpp 20 dmpserverapi.cpp
  21 + dmpserverconfig.cpp
21 dmpservercontext.cpp 22 dmpservercontext.cpp
22 dmpserverapicontext.cpp 23 dmpserverapicontext.cpp
23 dmpserverapihandler.cpp 24 dmpserverapihandler.cpp
@@ -48,8 +49,9 @@ SET (DMAP_SERVER_HDRS @@ -48,8 +49,9 @@ SET (DMAP_SERVER_HDRS
48 dmpserver.h 49 dmpserver.h
49 dmpserverapi.h 50 dmpserverapi.h
50 dmpserverapihandler.h 51 dmpserverapihandler.h
51 - dmpservercontext.h  
52 dmpserverapicontext.h 52 dmpserverapicontext.h
  53 + dmpservercontext.h
  54 + dmpserverconfig.h
53 dmpserverentity.h 55 dmpserverentity.h
54 dmpserverfilter.h 56 dmpserverfilter.h
55 dmpserverinterface.h 57 dmpserverinterface.h
@@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
20 #include "dmpspserverrequest.h" 20 #include "dmpspserverrequest.h"
21 #include "dmpspserverresponse.h" 21 #include "dmpspserverresponse.h"
22 #include "dmpapplication.h" 22 #include "dmpapplication.h"
  23 +#include "dmpserverconfig.h"
23 24
24 DmpMainServer *pDmpServer = nullptr; 25 DmpMainServer *pDmpServer = nullptr;
25 class SP_HttpEchoHandler : public SP_HttpHandler 26 class SP_HttpEchoHandler : public SP_HttpHandler
@@ -113,6 +114,8 @@ int main(int argc, char *argv[]) @@ -113,6 +114,8 @@ int main(int argc, char *argv[])
113 int c; 114 int c;
114 DmpApplication::Instance()->initialize(); 115 DmpApplication::Instance()->initialize();
115 pDmpServer = new DmpMainServer(); 116 pDmpServer = new DmpMainServer();
  117 + // std::string conn = DmpServerConfig::Instance()->getPqsqlConnect();
  118 + // std::string email = DmpServerConfig::Instance()->getValue("MetaData","email");
116 while ((c = getopt(argc, argv, "p:t:s:v")) != EOF) 119 while ((c = getopt(argc, argv, "p:t:s:v")) != EOF)
117 { 120 {
118 switch (c) 121 switch (c)
@@ -162,13 +162,11 @@ void DmpHttp::DmpHttpUtils::handle_read_content(const boost::system::error_code& @@ -162,13 +162,11 @@ void DmpHttp::DmpHttpUtils::handle_read_content(const boost::system::error_code&
162 else { 162 else {
163 socket_.close(); 163 socket_.close();
164 resolver_.cancel(); 164 resolver_.cancel();
165 - std::cout << "读取响应数据完毕." << std::endl;  
166 - //std::cout << responseData_;  
167 } 165 }
168 } 166 }
169 167
170 168
171 -std::string DmpHttp::post(std::string url) { 169 +std::string DmpHttp::post(const std::string &url) {
172 boost::asio::io_service io; 170 boost::asio::io_service io;
173 DmpHttp::DmpHttpUtils c(io); 171 DmpHttp::DmpHttpUtils c(io);
174 c.post(url); 172 c.post(url);
@@ -176,7 +174,7 @@ std::string DmpHttp::post(std::string url) { @@ -176,7 +174,7 @@ std::string DmpHttp::post(std::string url) {
176 return c.getResponse(); 174 return c.getResponse();
177 } 175 }
178 176
179 -std::string DmpHttp::get(std::string url) { 177 +std::string DmpHttp::get(const std::string &url) {
180 boost::asio::io_service io; 178 boost::asio::io_service io;
181 DmpHttp::DmpHttpUtils c(io); 179 DmpHttp::DmpHttpUtils c(io);
182 c.get(url); 180 c.get(url);
@@ -51,8 +51,8 @@ namespace DmpHttp @@ -51,8 +51,8 @@ namespace DmpHttp
51 // 响应数据 51 // 响应数据
52 std::string responseData_; 52 std::string responseData_;
53 }; 53 };
54 - std::string post(std::string url);  
55 - std::string get(std::string url); 54 + std::string post(const std::string &url);
  55 + std::string get(const std::string &url);
56 } 56 }
57 57
58 #endif //__dmphttpsutils_h__ 58 #endif //__dmphttpsutils_h__
  1 +/**************************************************************************
  2 +* file: dmpserverconfig.cpp
  3 +
  4 +* Author: wanzhongping
  5 +* Date: 2021-12-16 16:55:51
  6 +* Email: zhongpingw@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#include <iostream>
  11 +#include "dmpserverconfig.h"
  12 +#include "dmpapplication.h"
  13 +
  14 +DmpServerConfig::DmpServerConfig()
  15 +{
  16 + std::string iniFile = DmpApplication::Instance()->libexecPath() + iniFileName_;
  17 + if (boost::filesystem::exists(iniFile))
  18 + {
  19 + boost::property_tree::ini_parser::read_ini(iniFile, ptIni_);
  20 + }
  21 + else
  22 + {
  23 + ptIni_.put<std::string>("MetaData.pgsqlConnect", "\"hostaddr=localhost port=5432 dbname='dmap_dms' user='postgres' password='chinadci'\"");
  24 + ptIni_.put<std::string>("MetaData.metaUrl", "http://ip:port");
  25 + boost::property_tree::ini_parser::write_ini(iniFile, ptIni_);
  26 + }
  27 +}
  28 +
  29 +DmpServerConfig::~DmpServerConfig()
  30 +{
  31 +}
  32 +
  33 +DmpServerConfig *DmpServerConfig::Instance()
  34 +{
  35 + static DmpServerConfig instance;
  36 + return &instance;
  37 +}
  38 +
  39 +std::string DmpServerConfig::getPqsqlConnect()
  40 +{
  41 + std::string conn = "";
  42 + try
  43 + {
  44 + boost::property_tree::ptree ptMeta;
  45 + ptMeta = ptIni_.get_child("MetaData");
  46 + conn = ptMeta.get<std::string>("pgsqlConnect");
  47 + }
  48 + catch (std::exception &e)
  49 + {
  50 + std::cerr << "Exception: " << e.what() << "\n";
  51 + }
  52 + return conn;
  53 +}
  54 +
  55 +std::string DmpServerConfig::getMetaUrl()
  56 +{
  57 + std::string url = "";
  58 + try
  59 + {
  60 + boost::property_tree::ptree ptMeta;
  61 + ptMeta = ptIni_.get_child("MetaData");
  62 + url = ptMeta.get<std::string>("metaUrl");
  63 + }
  64 + catch (std::exception &e)
  65 + {
  66 + std::cerr << "Exception: " << e.what() << "\n";
  67 + }
  68 + return url;
  69 +}
  70 +
  71 +std::string DmpServerConfig::getValue(const std::string &section,const std::string &key)
  72 +{
  73 + std::string value = "";
  74 + try
  75 + {
  76 + boost::property_tree::ptree ptMeta;
  77 + ptMeta = ptIni_.get_child(section);
  78 + value = ptMeta.get<std::string>(key);
  79 + }
  80 + catch (std::exception &e)
  81 + {
  82 + std::cerr << "Exception: " << e.what() << "\n";
  83 + }
  84 + return value;
  85 +}
  1 +/**************************************************************************
  2 +* file: dmpserverconfig.h
  3 +
  4 +* Author: wanzhongping
  5 +* Date: 2021-12-16 16:55:44
  6 +* Email: zhongpingw@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmpserverconfig_h__
  11 +#define __dmpserverconfig_h__
  12 +
  13 +#include "dmap_server.h"
  14 +#include <boost/property_tree/ini_parser.hpp>
  15 +#include <boost/property_tree/ptree.hpp>
  16 +
  17 +class SERVER_EXPORT DmpServerConfig
  18 +{
  19 +public:
  20 + ~DmpServerConfig();
  21 + static DmpServerConfig* Instance();
  22 + std::string getPqsqlConnect();
  23 + std::string getMetaUrl();
  24 + std::string getValue(const std::string &section,const std::string &key);
  25 +private:
  26 + DmpServerConfig();
  27 + boost::property_tree::ptree ptIni_;
  28 + const std::string iniFileName_ = "dmpserver.ini";
  29 +};
  30 +
  31 +#endif // __dmpserverconfig_h__
注册登录 后发表评论