swift
config.h
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_SIM_XSWIFTBUS_CONFIG_H
5 #define SWIFT_SIM_XSWIFTBUS_CONFIG_H
6 
7 #include <string>
8 
9 namespace XSwiftBus
10 {
14  class CConfig
15  {
16  public:
18  enum DBusMode
19  {
20  DBusSession,
21  DBusP2P
22  };
23 
25  CConfig();
26 
28  ~CConfig();
29 
31  void setFilePath(const std::string &filePath) { m_filePath = filePath; }
32 
34  void parse();
35 
37  void print();
38 
40  DBusMode getDBusMode() const { return m_dbusMode; }
41 
43  std::string getDBusAddress() const { return m_dbusAddress; }
44 
46  int getDBusPort() const { return m_dbusPort; }
47 
49  bool getDebugMode() const { return m_debug; }
50 
52  void setDebugMode(bool on) { m_debug = on; }
53 
55  bool getTcasEnabled() const { return m_tcas; }
56 
58  void setTcasEnabled(bool on) { m_tcas = on; }
59 
61  bool writeConfig(bool tcas, bool debug);
62 
63  private:
64  bool parseDBusMode(const std::string &value);
65  bool parseDBusAddress(const std::string &value);
66  bool parseDBusPort(const std::string &value);
67  bool parseDebug(const std::string &value);
68  bool parseTcas(const std::string &value);
69  bool writeConfigFile() const;
70 
71  static std::string dbusModeToString(DBusMode mode);
72  static std::string boolToOnOff(bool on);
73 
74  std::string m_filePath;
75  DBusMode m_dbusMode = DBusP2P;
76  std::string m_dbusAddress = "127.0.0.1";
77  int m_dbusPort = 45001;
78  bool m_debug = false;
79  bool m_tcas = true;
80  };
81 } // namespace XSwiftBus
82 
83 #endif // SWIFT_SIM_XSWIFTBUS_CONFIG_H
xswiftbus configuration class
Definition: config.h:15
int getDBusPort() const
Get current DBus server port.
Definition: config.h:46
void setFilePath(const std::string &filePath)
Set config file path.
Definition: config.h:31
CConfig()
Constructor.
Definition: config.cpp:21
void setTcasEnabled(bool on)
Set TCAS traffic on/off.
Definition: config.h:58
DBusMode
DBus Server Mode.
Definition: config.h:19
bool getDebugMode() const
Get debug on/off.
Definition: config.h:49
void print()
Print the current configuration to the X-Plane log.
Definition: config.cpp:72
DBusMode getDBusMode() const
Get current DBus mode.
Definition: config.h:40
bool writeConfig(bool tcas, bool debug)
Update and write config file.
Definition: config.cpp:80
~CConfig()
Destructor;.
Definition: config.cpp:23
bool getTcasEnabled() const
Get TCAS traffic on/off.
Definition: config.h:55
void parse()
Load and parse config file.
Definition: config.cpp:25
void setDebugMode(bool on)
Set debug mode.
Definition: config.h:52
std::string getDBusAddress() const
Get current DBus server address.
Definition: config.h:43
Plugin loaded by X-Plane which publishes a DBus service.
Definition: command.h:14