diff options
Diffstat (limited to 'lib/CommLayer')
| -rw-r--r-- | lib/CommLayer/CommLayer.h | 2 | ||||
| -rw-r--r-- | lib/CommLayer/CommLayerInner.cpp | 69 | ||||
| -rw-r--r-- | lib/CommLayer/CommLayerInner.h | 102 | ||||
| -rw-r--r-- | lib/CommLayer/CommLayerServer.cpp | 2 | ||||
| -rw-r--r-- | lib/CommLayer/Observer.h | 2 |
5 files changed, 104 insertions, 73 deletions
diff --git a/lib/CommLayer/CommLayer.h b/lib/CommLayer/CommLayer.h index 19c0aa7..044d36d 100644 --- a/lib/CommLayer/CommLayer.h +++ b/lib/CommLayer/CommLayer.h @@ -2,6 +2,6 @@ #define COMMLAYER_H_ #include "CommLayerInner.h" -extern "C" CCommLayerInner* get_commlayer(); +//extern "C" CCommLayerInner* get_commlayer(); #endif /* COMMLAYER_H_ */ diff --git a/lib/CommLayer/CommLayerInner.cpp b/lib/CommLayer/CommLayerInner.cpp index 41fd3c1..a7c5123 100644 --- a/lib/CommLayer/CommLayerInner.cpp +++ b/lib/CommLayer/CommLayerInner.cpp @@ -1,28 +1,57 @@ #include "CommLayerInner.h" -CCommLayerInner::CCommLayerInner(CObserver *pObs) -: DEBUGINFO(pObs), - WARNING(pObs), - STATUS(pObs) +namespace CommLayerInner { - m_pObs = pObs; -} -CCommLayerInner::~CCommLayerInner() -{ -} + static CDebug* g_pDebug = NULL; + static CWarning* g_pWarning = NULL; + static CStatus* g_pStatus = NULL; -CDebug& CCommLayerInner::Debug() -{ - return DEBUGINFO; -} -CWarning& CCommLayerInner::Warning() -{ - return WARNING; -} + void init_debug(CObserver* pObserver) + { + if (!g_pDebug) + { + g_pDebug = new CDebug(pObserver); + } + } -CStatusUpdate& CCommLayerInner::Status() -{ - return STATUS; + void init_warning(CObserver* pObserver) + { + if (!g_pWarning) + { + g_pWarning = new CWarning(pObserver); + } + } + + void init_status(CObserver* pObserver) + { + if (!g_pStatus) + { + g_pStatus = new CStatus(pObserver); + } + } + + void debug(const std::string& pMessage) + { + if (g_pDebug) + { + g_pDebug->Message(pMessage); + } + } + void warning(const std::string& pMessage) + { + if (g_pWarning) + { + g_pWarning->Message(pMessage); + } + } + + void status(const std::string& pMessage) + { + if (g_pStatus) + { + g_pStatus->Message(pMessage); + } + } } diff --git a/lib/CommLayer/CommLayerInner.h b/lib/CommLayer/CommLayerInner.h index 2cca935..7edd257 100644 --- a/lib/CommLayer/CommLayerInner.h +++ b/lib/CommLayer/CommLayerInner.h @@ -4,60 +4,62 @@ #include <iostream> #include "Observer.h" -class CDebug +namespace CommLayerInner { - private: - CObserver *m_pObs; - public: - CDebug(CObserver *pObs){ m_pObs = pObs; } - - void operator << (const std::string& pMsg) - { - if(m_pObs) - m_pObs->Debug(pMsg); - } -}; -class CWarning -{ - private: - CObserver *m_pObs; - public: - CWarning(CObserver *pObs){ m_pObs = pObs; } - - void operator << (const std::string& pMsg) - { - if(m_pObs) - m_pObs->Warning(pMsg); - } -}; + class CDebug + { + private: + CObserver *m_pObs; + public: + CDebug(CObserver *pObs) : + m_pObs(pObs) + {} + void Message(const std::string& pMsg) + { + if(m_pObs) + m_pObs->Debug(pMsg); + } + }; -class CStatusUpdate -{ - private: - CObserver *m_pObs; - public: - CStatusUpdate(CObserver *pObs){ m_pObs = pObs; } - - void operator << (const std::string& pMsg) - { - if(m_pObs) - m_pObs->StatusUpdate(pMsg); - } -}; + class CWarning + { + private: + CObserver *m_pObs; + public: + CWarning(CObserver *pObs) : + m_pObs(pObs) + {} + void Message(const std::string& pMsg) + { + if(m_pObs) + m_pObs->Warning(pMsg); + } + }; + + class CStatus + { + private: + CObserver *m_pObs; + public: + CStatus(CObserver *pObs) : + m_pObs(pObs) + {} + void Message(const std::string& pMsg) + { + if(m_pObs) + m_pObs->Status(pMsg); + } + }; + + + void init_debug(CObserver* pObserver); + void init_warning(CObserver* pObserver); + void init_status(CObserver* pObserver); -class CCommLayerInner{ - private: - CObserver *m_pObs; - public: - CDebug DEBUGINFO; - CWarning WARNING; - CStatusUpdate STATUS; - CCommLayerInner(CObserver *pObs); - ~CCommLayerInner(); - CDebug& Debug(); - CWarning& Warning(); - CStatusUpdate& Status(); + void debug(const std::string& pMessage); + void warning(const std::string& pMessage); + void status(const std::string& pMessage); }; #endif /* COMMLAYERINNER_H_ */ diff --git a/lib/CommLayer/CommLayerServer.cpp b/lib/CommLayer/CommLayerServer.cpp index 271f753..328986e 100644 --- a/lib/CommLayer/CommLayerServer.cpp +++ b/lib/CommLayer/CommLayerServer.cpp @@ -20,5 +20,5 @@ void CCommLayerServer::Detach(CObserver *pObs) void CCommLayerServer::Notify(const std::string& pMessage) { if(m_pObserver) - m_pObserver->StatusUpdate(pMessage); + m_pObserver->Status(pMessage); } diff --git a/lib/CommLayer/Observer.h b/lib/CommLayer/Observer.h index 6f276d7..a26b7b7 100644 --- a/lib/CommLayer/Observer.h +++ b/lib/CommLayer/Observer.h @@ -7,7 +7,7 @@ class CObserver { public: //CObserver(); virtual ~CObserver() {} - virtual void StatusUpdate(const std::string& pMessage) = 0; + virtual void Status(const std::string& pMessage) = 0; virtual void Debug(const std::string& pMessage) = 0; virtual void Warning(const std::string& pMessage) = 0; /* this should be implemented in daemon */ |
