DDS  ver. 3.6
DDSHelper.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef _DDS_DDSHELPER_H_
6 #define _DDS_DDSHELPER_H_
7 
8 // DDS
9 #include "Logger.h"
10 #include "UserDefaults.h"
11 // BOOST
12 #include <boost/property_tree/ini_parser.hpp>
13 #include <boost/property_tree/ptree.hpp>
14 
15 namespace dds::misc
16 {
17  inline void findCommanderServerImpl(std::string* _host, std::string* _port, const std::string& _name)
18  {
19  if (nullptr == _host || nullptr == _port)
20  throw std::invalid_argument("findCommanderServer: Arguments must not be null");
21 
22  // Read server info file
23  const std::string sSrvCfg(dds::user_defaults_api::CUserDefaults::instance().getServerInfoFileLocationSrv());
24  LOG(info) << "Reading server info from: " << sSrvCfg;
25  if (sSrvCfg.empty())
26  throw std::runtime_error("Can't find server info file.");
27 
28  boost::property_tree::ptree pt;
29  boost::property_tree::ini_parser::read_ini(sSrvCfg, pt);
30  *_host = pt.get<std::string>(_name + ".host");
31  *_port = pt.get<std::string>(_name + ".port");
32  }
33 
34  inline void findCommanderServer(std::string* _host, std::string* _port)
35  {
36  findCommanderServerImpl(_host, _port, "server");
37  }
38 
39  inline void findCommanderUI(std::string* _host, std::string* _port)
40  {
41  findCommanderServerImpl(_host, _port, "ui");
42  }
43 }; // namespace dds::misc
44 
45 #endif
void findCommanderServerImpl(std::string *_host, std::string *_port, const std::string &_name)
Definition: DDSHelper.h:17
void findCommanderServer(std::string *_host, std::string *_port)
Definition: DDSHelper.h:34
void findCommanderUI(std::string *_host, std::string *_port)
Definition: DDSHelper.h:39
#define LOG(severity)
Definition: Logger.h:34
Definition: def.h:147
static CUserDefaults & instance(const boost::uuids::uuid &_sid=CUserDefaults::getInitialSID())
Return singleton instance.
Definition: UserDefaults.cpp:37
Definition: BoostHelper.h:14