DDS  ver. 3.4
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 
12 // BOOST
13 #include <boost/property_tree/ptree.hpp>
14 
15 #pragma clang diagnostic push
16 #pragma clang diagnostic ignored "-Wunused-local-typedef"
17 #include <boost/property_tree/ini_parser.hpp>
18 #pragma clang diagnostic pop
19 
20 namespace MiscCommon
21 {
22  inline void findCommanderServerImpl(std::string* _host, std::string* _port, const std::string& _name)
23  {
24  if (nullptr == _host || nullptr == _port)
25  throw std::invalid_argument("findCommanderServer: Arguments must not be null");
26 
27  // Read server info file
28  const std::string sSrvCfg(dds::user_defaults_api::CUserDefaults::instance().getServerInfoFileLocationSrv());
29  LOG(MiscCommon::info) << "Reading server info from: " << sSrvCfg;
30  if (sSrvCfg.empty())
31  throw std::runtime_error("Can't find server info file.");
32 
33  boost::property_tree::ptree pt;
34  boost::property_tree::ini_parser::read_ini(sSrvCfg, pt);
35  *_host = pt.get<std::string>(_name + ".host");
36  *_port = pt.get<std::string>(_name + ".port");
37  }
38 
39  inline void findCommanderServer(std::string* _host, std::string* _port)
40  {
41  findCommanderServerImpl(_host, _port, "server");
42  }
43 
44  inline void findCommanderUI(std::string* _host, std::string* _port)
45  {
46  findCommanderServerImpl(_host, _port, "ui");
47  }
48 }; // namespace MiscCommon
49 
50 #endif
void findCommanderServerImpl(std::string *_host, std::string *_port, const std::string &_name)
Definition: DDSHelper.h:22
#define LOG(severity)
Definition: Logger.h:56
void findCommanderUI(std::string *_host, std::string *_port)
Definition: DDSHelper.h:44
void findCommanderServer(std::string *_host, std::string *_port)
Definition: DDSHelper.h:39
static CUserDefaults & instance(const boost::uuids::uuid &_sid=CUserDefaults::getInitialSID())
Return singleton instance.
Definition: UserDefaults.cpp:36
Definition: def.h:150
Miscellaneous functions and helpers are located here.
Definition: BOOST_FILESYSTEM.h:21