Code cleanup.

This commit is contained in:
Gunnar Beutner 2012-08-03 15:35:27 +02:00
parent 94af0d5414
commit bb7e1e639d
8 changed files with 28 additions and 28 deletions

View File

@ -25,7 +25,7 @@ vector<Event> Event::m_Events;
condition_variable Event::m_EventAvailable; condition_variable Event::m_EventAvailable;
mutex Event::m_Mutex; mutex Event::m_Mutex;
Event::Event(const function<void ()>& callback) Event::Event(const Event::Callback& callback)
: m_Callback(callback) : m_Callback(callback)
{ } { }
@ -59,7 +59,7 @@ void Event::ProcessEvents(const system_time& wait_until)
} }
} }
void Event::Post(const function<void ()>& callback) void Event::Post(const Event::Callback& callback)
{ {
if (Application::IsMainThread()) { if (Application::IsMainThread()) {
callback(); callback();
@ -74,3 +74,4 @@ void Event::Post(const function<void ()>& callback)
m_EventAvailable.notify_all(); m_EventAvailable.notify_all();
} }
} }

View File

@ -26,13 +26,15 @@ namespace icinga
class I2_BASE_API Event class I2_BASE_API Event
{ {
public: public:
typedef function<void ()> Callback;
static void ProcessEvents(const system_time& wait_until); static void ProcessEvents(const system_time& wait_until);
static void Post(const function<void ()>& callback); static void Post(const Callback& callback);
private: private:
Event(const function<void ()>& callback); Event(const Callback& callback);
function<void ()> m_Callback; Callback m_Callback;
static vector<Event> m_Events; static vector<Event> m_Events;
static condition_variable m_EventAvailable; static condition_variable m_EventAvailable;

View File

@ -27,12 +27,8 @@ using namespace icinga;
* Constructor for the FIFO class. * Constructor for the FIFO class.
*/ */
FIFO::FIFO(void) 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. * Destructor for the FIFO class.

View File

@ -25,16 +25,15 @@ using namespace icinga;
* Constructor for the TcpServer class. * Constructor for the TcpServer class.
*/ */
TcpServer::TcpServer(void) TcpServer::TcpServer(void)
{ : m_ClientFactory(boost::bind(&TcpClientFactory, RoleInbound))
m_ClientFactory = boost::bind(&TcpClientFactory, RoleInbound); { }
}
/** /**
* Sets the client factory. * Sets the client factory.
* *
* @param clientFactory The client factory function. * @param clientFactory The client factory function.
*/ */
void TcpServer::SetClientFactory(function<TcpClient::Ptr(SOCKET)> clientFactory) void TcpServer::SetClientFactory(const TcpServer::ClientFactory& clientFactory)
{ {
m_ClientFactory = clientFactory; m_ClientFactory = clientFactory;
} }
@ -44,7 +43,7 @@ void TcpServer::SetClientFactory(function<TcpClient::Ptr(SOCKET)> clientFactory)
* *
* @returns The client factory function. * @returns The client factory function.
*/ */
function<TcpClient::Ptr(SOCKET)> TcpServer::GetFactoryFunction(void) const TcpServer::ClientFactory TcpServer::GetFactoryFunction(void) const
{ {
return m_ClientFactory; return m_ClientFactory;
} }
@ -87,3 +86,4 @@ void TcpServer::HandleReadable(void)
Event::Post(boost::bind(boost::ref(OnNewClient), GetSelf(), client)); Event::Post(boost::bind(boost::ref(OnNewClient), GetSelf(), client));
} }

View File

@ -35,10 +35,12 @@ public:
typedef shared_ptr<TcpServer> Ptr; typedef shared_ptr<TcpServer> Ptr;
typedef weak_ptr<TcpServer> WeakPtr; typedef weak_ptr<TcpServer> WeakPtr;
typedef function<TcpClient::Ptr(SOCKET)> ClientFactory;
TcpServer(void); TcpServer(void);
void SetClientFactory(function<TcpClient::Ptr(SOCKET)> function); void SetClientFactory(const ClientFactory& function);
function<TcpClient::Ptr(SOCKET)> GetFactoryFunction(void) const; ClientFactory GetFactoryFunction(void) const;
void Listen(void); void Listen(void);
@ -50,7 +52,7 @@ protected:
virtual void HandleReadable(void); virtual void HandleReadable(void);
private: private:
function<TcpClient::Ptr(SOCKET)> m_ClientFactory; ClientFactory m_ClientFactory;
}; };
} }

View File

@ -27,9 +27,8 @@ Timer::CollectionType Timer::m_Timers;
* Constructor for the Timer class. * Constructor for the Timer class.
*/ */
Timer::Timer(void) Timer::Timer(void)
{ : m_Interval(0)
m_Interval = 0; { }
}
/** /**
* Calls expired timers and returned when the next wake-up should happen. * Calls expired timers and returned when the next wake-up should happen.

View File

@ -30,12 +30,10 @@ bool I2_EXPORT TlsClient::m_SSLIndexInitialized = false;
* @param role The role of the client. * @param role The role of the client.
* @param sslContext The SSL context for the client. * @param sslContext The SSL context for the client.
*/ */
TlsClient::TlsClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext) : TcpClient(role) TlsClient::TlsClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
{ : TcpClient(role), m_SSLContext(sslContext),
m_SSLContext = sslContext; m_BlockRead(false), m_BlockWrite(false)
m_BlockRead = false; { }
m_BlockWrite = false;
}
void TlsClient::Start(void) void TlsClient::Start(void)
{ {

View File

@ -210,6 +210,8 @@ void CIBSyncComponent::RemoteObjectUpdateHandler(const Endpoint::Ptr& sender, co
DynamicObject::Ptr object = DynamicObject::GetObject(type, name); DynamicObject::Ptr object = DynamicObject::GetObject(type, name);
// TODO: sanitize update, disallow __local
if (!object) { if (!object) {
object = DynamicObject::Create(type, update); object = DynamicObject::Create(type, update);