// mqttcfg.h : // #if !defined(AGD_MQTTCFG_H__35CD3AFA_36BC_442B_83B7_D12E407E6B3A__INCLUDED_) #define AGD_MQTTCFG_H__35CD3AFA_36BC_442B_83B7_D12E407E6B3A__INCLUDED_ #include #include #include #include #include #include #include #ifndef _LIBBUILD #include #include #else // _LIBBUILD #include "common/logfile.h" #include "mqttjson.h" #endif // _LIBBUILD #ifdef __cplusplus ///////////////////////////////////////////////////////////////////////////// // mqttcfg.h - Declarations: #define MQTTCL_TLS_MODE_OFF 0 // no TLS #define MQTTCL_TLS_MODE_CRT 1 // TLS using certificates #define MQTTCL_TLS_MODE_PSK 2 // TLS using preshared key #define MQTTCL_MIN_QOS 0 #define MQTTCL_MAX_QOS 2 #define MQTTCL_DEFAULT_QOS MQTTCL_MAX_QOS #define MQTTCL_DEFAULT_RETAIN false #define MQTTCL_DEVICE_PREFIX "GfA" ///////////////////////////////////////////////////////////////////////////// class CMqttClConfig { public: CMqttClConfig(const char *pszShmUuid); virtual ~CMqttClConfig(void); bool LoadCfg(const char *pszCfgFilePath, CLogfile &rlf); inline const char* GetBrokerAddr(void) const { return m_strBrokerAddr.empty() ? NULL : m_strBrokerAddr.c_str(); } inline unsigned short GetBrokerPort(void) const { return (unsigned short)m_nBrokerPort; } inline int GetDefaultQOS(void) const { return m_nDefaultQOS; } inline int GetTLSMode(void) const { return m_nTlsMode; } inline bool GetDefaultRetain(void) const { return m_bDefaultRetain; } inline const char* GetDevicePrefix(void) const { return m_strDevicePrefix.empty() ? NULL : m_strDevicePrefix.c_str(); } inline const char* GetTlsCaCrtFile(void) const { return m_strTlsCaCrtFile.empty() ? NULL : m_strTlsCaCrtFile.c_str(); } inline const char* GetTlsClCrtFile(void) const { return m_strTlsClCrtFile.empty() ? NULL : m_strTlsClCrtFile.c_str(); } inline const char* GetTlsClKeyFile(void) const { return m_strTlsClKeyFile.empty() ? NULL : m_strTlsClKeyFile.c_str(); } inline const char* GetTlsPSK(void) const { return m_strTlsPSK.empty() ? NULL : m_strTlsPSK.c_str(); } inline const char* GetDeviceID(void) const { return m_strDeviceID.empty() ? NULL : m_strDeviceID.c_str(); } inline const char* GetShmID(void) const { return m_strShmID.empty() ? NULL : m_strShmID.c_str(); } static sa_family_t GetDevIdInterfaceName(char *pszItfName, size_t nCChItfName, const char *pszRequested); static const char* GetMacAddress(std::string &s); static std::string CreateDeviceID(const char *pszDevicePrefix); private: bool GetValue(CJson_t &rjtParent, const char *pszKey, CJson_t &rjtVal, std::string &strErr); bool GetBoolValue(CJson_t &rjtParent, const char *pszKey, bool &rbVal, std::string &strErr); bool GetIntValue(CJson_t &rjtParent, const char *pszKey, int &rnVal, std::string &strErr); bool GetStringValue(CJson_t &rjtParent, const char *pszKey, std::string &rstrVal, std::string &strErr); private: std::string m_strBrokerAddr; std::string m_strDevicePrefix; std::string m_strTlsCaCrtFile; std::string m_strTlsClCrtFile; std::string m_strTlsClKeyFile; std::string m_strTlsPSK; std::string m_strDeviceID; std::string m_strShmID; int m_nBrokerPort; int m_nDefaultQOS; bool m_bDefaultRetain; int m_nTlsMode; }; ///////////////////////////////////////////////////////////////////////////// #endif // __cplusplus #endif // !defined(AGD_MQTTCFG_H__35CD3AFA_36BC_442B_83B7_D12E407E6B3A__INCLUDED_)