forked from domoticz/domoticz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDomoticzHardware.h
80 lines (63 loc) · 2.31 KB
/
DomoticzHardware.h
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
#pragma once
#include <boost/signals2.hpp>
#include "../main/StoppableTask.h"
enum _eLogLevel : uint32_t;
enum _eDebugLevel : uint32_t;
//Base class with functions all notification systems should have
class CDomoticzHardwareBase : public StoppableTask
{
friend class MainWorker;
public:
CDomoticzHardwareBase();
virtual ~CDomoticzHardwareBase();
bool Start();
bool Stop();
bool Restart();
bool RestartWithDelay(const long seconds);
virtual bool WriteToHardware(const char *pdata, const unsigned char length) = 0;
virtual bool CustomCommand(const uint64_t idx, const std::string &sCommand);
void EnableOutputLog(const bool bEnableLog);
bool IsStarted() { return m_bIsStarted; }
void SetHeartbeatReceived();
time_t m_LastHeartbeat = { 0 };
time_t m_LastHeartbeatReceive = { 0 };
int m_InterfaceID = { 0 }; //must be uniquely assigned
bool m_bSkipReceiveCheck = { false };
unsigned long m_DataTimeout = { 0 };
std::string m_Name;
std::string m_ShortName;
unsigned char m_SeqNr = { 0 };
bool m_bEnableReceive = { false };
boost::signals2::signal<void(CDomoticzHardwareBase *pHardware, const unsigned char *pRXCommand, const char *defaultName, const int BatteryLevel)> sDecodeRXMessage;
boost::signals2::signal<void(CDomoticzHardwareBase *pDevice)> sOnConnected;
void *m_pUserData = { NULL };
bool m_bOutputLog = { true };
int SetThreadNameInt(const std::thread::native_handle_type &thread);
//Log Helper functions
void Log(const _eLogLevel level, const std::string& sLogline);
void Log(const _eLogLevel level, const char* logline, ...)
#ifdef __GNUC__
__attribute__((format(printf, 3, 4)))
#endif
;
void Debug(const _eDebugLevel level, const std::string& sLogline);
void Debug(const _eDebugLevel level, const char* logline, ...)
#ifdef __GNUC__
__attribute__((format(printf, 3, 4)))
#endif
;
protected:
virtual bool StartHardware()=0;
virtual bool StopHardware()=0;
//Heartbeat thread for classes that can not provide this themselves
void StartHeartbeatThread();
void StartHeartbeatThread(const char* ThreadName);
void StopHeartbeatThread();
void HandleHBCounter(const int iInterval);
int m_iHBCounter = { 0 };
bool m_bIsStarted = { false };
private:
void Do_Heartbeat_Work();
volatile bool m_stopHeartbeatrequested = { false };
std::shared_ptr<std::thread> m_Heartbeatthread = { nullptr };
};