dmpserverconfig.cpp
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**************************************************************************
* file: dmpserverconfig.cpp
* Author: wanzhongping
* Date: 2021-12-16 16:55:51
* Email: zhongpingw@chinadci.com
* copyright: 广州城市信息研究所有限公司
***************************************************************************/
#include <iostream>
#include "dmpserverconfig.h"
#include "dmpapplication.h"
#include "dmphttputils.h"
DmpServerConfig::DmpServerConfig()
{
std::string iniFile = DmpApplication::Instance()->libexecPath() + iniFileName_;
if (boost::filesystem::exists(iniFile))
{
boost::property_tree::ini_parser::read_ini(iniFile, ptIni_);
}
else
{
ptIni_.put<std::string>("MetaData.pgsqlConnect", "\"hostaddr=localhost port=5432 dbname='dmap_dms' user='postgres' password='chinadci'\"");
ptIni_.put<std::string>("MetaData.metaUrl", "http://ip:port");
boost::property_tree::ini_parser::write_ini(iniFile, ptIni_);
}
}
DmpServerConfig::~DmpServerConfig()
{
}
DmpServerConfig *DmpServerConfig::Instance()
{
static DmpServerConfig instance;
return &instance;
}
std::string DmpServerConfig::getPqsqlConnect()
{
std::string conn = "";
try
{
boost::property_tree::ptree ptMeta;
ptMeta = ptIni_.get_child("MetaData");
conn = ptMeta.get<std::string>("pgsqlConnect");
}
catch (std::exception &e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return conn;
}
std::string DmpServerConfig::getMetaUrl()
{
std::string url = "";
try
{
boost::property_tree::ptree ptMeta;
ptMeta = ptIni_.get_child("MetaData");
url = ptMeta.get<std::string>("metaUrl");
}
catch (std::exception &e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return url;
}
std::string DmpServerConfig::getValue(const std::string §ion,const std::string &key)
{
std::string value = "";
try
{
boost::property_tree::ptree ptMeta;
ptMeta = ptIni_.get_child(section);
value = ptMeta.get<std::string>(key);
}
catch (std::exception &e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return value;
}
std::string DmpServerConfig::HttpPost(const std::string& url, std::string& postData)
{
return DmpHttp::post(url, postData);
}
std::string DmpServerConfig::HttpGet(const std::string& url)
{
return DmpHttp::get(url);
}