From: Gunnar Beutner Date: Fri, 3 Aug 2012 13:35:27 +0000 (+0200) Subject: Code cleanup. X-Git-Tag: v0.0.1~172 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bb7e1e639dfeb85721ff9e17110f6c0b1066e230;p=icinga2 Code cleanup. --- diff --git a/base/event.cpp b/base/event.cpp index 404ad5c6e..e68bc5e50 100644 --- a/base/event.cpp +++ b/base/event.cpp @@ -25,7 +25,7 @@ vector Event::m_Events; condition_variable Event::m_EventAvailable; mutex Event::m_Mutex; -Event::Event(const function& callback) +Event::Event(const Event::Callback& callback) : m_Callback(callback) { } @@ -59,7 +59,7 @@ void Event::ProcessEvents(const system_time& wait_until) } } -void Event::Post(const function& callback) +void Event::Post(const Event::Callback& callback) { if (Application::IsMainThread()) { callback(); @@ -74,3 +74,4 @@ void Event::Post(const function& callback) m_EventAvailable.notify_all(); } } + diff --git a/base/event.h b/base/event.h index 4f1b16e7b..797711866 100644 --- a/base/event.h +++ b/base/event.h @@ -26,13 +26,15 @@ namespace icinga class I2_BASE_API Event { public: + typedef function Callback; + static void ProcessEvents(const system_time& wait_until); - static void Post(const function& callback); + static void Post(const Callback& callback); private: - Event(const function& callback); + Event(const Callback& callback); - function m_Callback; + Callback m_Callback; static vector m_Events; static condition_variable m_EventAvailable; diff --git a/base/fifo.cpp b/base/fifo.cpp index 5ea4dff9e..e46c9f4d0 100644 --- a/base/fifo.cpp +++ b/base/fifo.cpp @@ -27,12 +27,8 @@ using namespace icinga; * Constructor for the FIFO class. */ FIFO::FIFO(void) -{ - m_Buffer = NULL; - m_DataSize = 0; - m_AllocSize = 0; - m_Offset = 0; -} + : m_Buffer(NULL), m_DataSize(0), m_AllocSize(0), m_Offset(0) +{ } /** * Destructor for the FIFO class. diff --git a/base/tcpserver.cpp b/base/tcpserver.cpp index 866530084..4bfb3db81 100644 --- a/base/tcpserver.cpp +++ b/base/tcpserver.cpp @@ -25,16 +25,15 @@ using namespace icinga; * Constructor for the TcpServer class. */ TcpServer::TcpServer(void) -{ - m_ClientFactory = boost::bind(&TcpClientFactory, RoleInbound); -} + : m_ClientFactory(boost::bind(&TcpClientFactory, RoleInbound)) +{ } /** * Sets the client factory. * * @param clientFactory The client factory function. */ -void TcpServer::SetClientFactory(function clientFactory) +void TcpServer::SetClientFactory(const TcpServer::ClientFactory& clientFactory) { m_ClientFactory = clientFactory; } @@ -44,7 +43,7 @@ void TcpServer::SetClientFactory(function clientFactory) * * @returns The client factory function. */ -function TcpServer::GetFactoryFunction(void) const +TcpServer::ClientFactory TcpServer::GetFactoryFunction(void) const { return m_ClientFactory; } @@ -87,3 +86,4 @@ void TcpServer::HandleReadable(void) Event::Post(boost::bind(boost::ref(OnNewClient), GetSelf(), client)); } + diff --git a/base/tcpserver.h b/base/tcpserver.h index fa64a34e4..3ac03f08f 100644 --- a/base/tcpserver.h +++ b/base/tcpserver.h @@ -35,10 +35,12 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; + typedef function ClientFactory; + TcpServer(void); - void SetClientFactory(function function); - function GetFactoryFunction(void) const; + void SetClientFactory(const ClientFactory& function); + ClientFactory GetFactoryFunction(void) const; void Listen(void); @@ -50,7 +52,7 @@ protected: virtual void HandleReadable(void); private: - function m_ClientFactory; + ClientFactory m_ClientFactory; }; } diff --git a/base/timer.cpp b/base/timer.cpp index cf2eac609..ce2436908 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -27,9 +27,8 @@ Timer::CollectionType Timer::m_Timers; * Constructor for the Timer class. */ Timer::Timer(void) -{ - m_Interval = 0; -} + : m_Interval(0) +{ } /** * Calls expired timers and returned when the next wake-up should happen. diff --git a/base/tlsclient.cpp b/base/tlsclient.cpp index d9dd42779..2ba222d14 100644 --- a/base/tlsclient.cpp +++ b/base/tlsclient.cpp @@ -30,12 +30,10 @@ bool I2_EXPORT TlsClient::m_SSLIndexInitialized = false; * @param role The role of the client. * @param sslContext The SSL context for the client. */ -TlsClient::TlsClient(TcpClientRole role, shared_ptr sslContext) : TcpClient(role) -{ - m_SSLContext = sslContext; - m_BlockRead = false; - m_BlockWrite = false; -} +TlsClient::TlsClient(TcpClientRole role, shared_ptr sslContext) + : TcpClient(role), m_SSLContext(sslContext), + m_BlockRead(false), m_BlockWrite(false) +{ } void TlsClient::Start(void) { diff --git a/components/cibsync/cibsynccomponent.cpp b/components/cibsync/cibsynccomponent.cpp index 9b1264a3a..c65053d08 100644 --- a/components/cibsync/cibsynccomponent.cpp +++ b/components/cibsync/cibsynccomponent.cpp @@ -210,6 +210,8 @@ void CIBSyncComponent::RemoteObjectUpdateHandler(const Endpoint::Ptr& sender, co DynamicObject::Ptr object = DynamicObject::GetObject(type, name); + // TODO: sanitize update, disallow __local + if (!object) { object = DynamicObject::Create(type, update);