Renamed RefType/WeakRefType typedefs to Ptr/WeakPtr

This commit is contained in:
Gunnar Beutner 2012-04-02 20:50:35 +02:00
parent 96b4cb68d4
commit 7c5d29bbc9
34 changed files with 234 additions and 234 deletions

View File

@ -6,7 +6,7 @@
using namespace icinga; using namespace icinga;
Application::RefType Application::Instance; Application::Ptr Application::Instance;
Application::Application(void) Application::Application(void)
{ {
@ -26,7 +26,7 @@ Application::~Application(void)
Timer::StopAllTimers(); Timer::StopAllTimers();
Socket::CloseAllSockets(); Socket::CloseAllSockets();
for (map<string, Component::RefType>::iterator i = m_Components.begin(); i != m_Components.end(); i++) { for (map<string, Component::Ptr>::iterator i = m_Components.begin(); i != m_Components.end(); i++) {
i->second->Stop(); i->second->Stop();
} }
@ -47,8 +47,8 @@ void Application::RunEventLoop(void)
FD_ZERO(&writefds); FD_ZERO(&writefds);
FD_ZERO(&exceptfds); FD_ZERO(&exceptfds);
for (list<Socket::WeakRefType>::iterator i = Socket::Sockets.begin(); i != Socket::Sockets.end(); i++) { for (list<Socket::WeakPtr>::iterator i = Socket::Sockets.begin(); i != Socket::Sockets.end(); i++) {
Socket::RefType socket = i->lock(); Socket::Ptr socket = i->lock();
if (socket == NULL) if (socket == NULL)
continue; continue;
@ -94,15 +94,15 @@ void Application::RunEventLoop(void)
else if (ready == 0) else if (ready == 0)
continue; continue;
EventArgs::RefType ea = new_object<EventArgs>(); EventArgs::Ptr ea = new_object<EventArgs>();
ea->Source = shared_from_this(); ea->Source = shared_from_this();
list<Socket::WeakRefType>::iterator prev, i; list<Socket::WeakPtr>::iterator prev, i;
for (i = Socket::Sockets.begin(); i != Socket::Sockets.end(); ) { for (i = Socket::Sockets.begin(); i != Socket::Sockets.end(); ) {
prev = i; prev = i;
i++; i++;
Socket::RefType socket = prev->lock(); Socket::Ptr socket = prev->lock();
if (socket == NULL) if (socket == NULL)
continue; continue;
@ -170,14 +170,14 @@ void Application::Shutdown(void)
m_ShuttingDown = true; m_ShuttingDown = true;
} }
ConfigHive::RefType Application::GetConfigHive(void) ConfigHive::Ptr Application::GetConfigHive(void)
{ {
return m_ConfigHive; return m_ConfigHive;
} }
Component::RefType Application::LoadComponent(string path, ConfigObject::RefType componentConfig) Component::Ptr Application::LoadComponent(string path, ConfigObject::Ptr componentConfig)
{ {
Component::RefType component; Component::Ptr component;
Component *(*pCreateComponent)(); Component *(*pCreateComponent)();
Log("Loading component '%s'", path.c_str()); Log("Loading component '%s'", path.c_str());
@ -207,7 +207,7 @@ Component::RefType Application::LoadComponent(string path, ConfigObject::RefType
if (pCreateComponent == NULL) if (pCreateComponent == NULL)
throw exception(/*"Module does not contain CreateComponent function"*/); throw exception(/*"Module does not contain CreateComponent function"*/);
component = Component::RefType(pCreateComponent()); component = Component::Ptr(pCreateComponent());
component->SetApplication(static_pointer_cast<Application>(shared_from_this())); component->SetApplication(static_pointer_cast<Application>(shared_from_this()));
component->SetConfig(componentConfig); component->SetConfig(componentConfig);
m_Components[component->GetName()] = component; m_Components[component->GetName()] = component;
@ -217,26 +217,26 @@ Component::RefType Application::LoadComponent(string path, ConfigObject::RefType
return component; return component;
} }
Component::RefType Application::GetComponent(string name) Component::Ptr Application::GetComponent(string name)
{ {
map<string, Component::RefType>::iterator ci = m_Components.find(name); map<string, Component::Ptr>::iterator ci = m_Components.find(name);
if (ci == m_Components.end()) if (ci == m_Components.end())
return Component::RefType(); return Component::Ptr();
return ci->second; return ci->second;
} }
void Application::UnloadComponent(string name) void Application::UnloadComponent(string name)
{ {
map<string, Component::RefType>::iterator ci = m_Components.find(name); map<string, Component::Ptr>::iterator ci = m_Components.find(name);
if (ci == m_Components.end()) if (ci == m_Components.end())
return; return;
Log("Unloading component '%s'", name.c_str()); Log("Unloading component '%s'", name.c_str());
Component::RefType component = ci->second; Component::Ptr component = ci->second;
component->Stop(); component->Stop();
m_Components.erase(ci); m_Components.erase(ci);

View File

@ -8,15 +8,15 @@ class Component;
class Application : public Object { class Application : public Object {
private: private:
bool m_ShuttingDown; bool m_ShuttingDown;
ConfigHive::RefType m_ConfigHive; ConfigHive::Ptr m_ConfigHive;
map< string, shared_ptr<Component> > m_Components; map< string, shared_ptr<Component> > m_Components;
vector<string> m_Arguments; vector<string> m_Arguments;
public: public:
typedef shared_ptr<Application> RefType; typedef shared_ptr<Application> Ptr;
typedef weak_ptr<Application> WeakRefType; typedef weak_ptr<Application> WeakPtr;
static Application::RefType Instance; static Application::Ptr Instance;
Application(void); Application(void);
~Application(void); ~Application(void);
@ -32,9 +32,9 @@ public:
void Log(const char *format, ...); void Log(const char *format, ...);
ConfigHive::RefType GetConfigHive(void); ConfigHive::Ptr GetConfigHive(void);
shared_ptr<Component> LoadComponent(string path, ConfigObject::RefType componentConfig); shared_ptr<Component> LoadComponent(string path, ConfigObject::Ptr componentConfig);
void UnloadComponent(string name); void UnloadComponent(string name);
shared_ptr<Component> GetComponent(string name); shared_ptr<Component> GetComponent(string name);
void AddComponentSearchDir(string componentDirectory); void AddComponentSearchDir(string componentDirectory);

View File

@ -2,22 +2,22 @@
using namespace icinga; using namespace icinga;
void Component::SetApplication(const Application::WeakRefType& application) void Component::SetApplication(const Application::WeakPtr& application)
{ {
m_Application = application; m_Application = application;
} }
Application::RefType Component::GetApplication(void) Application::Ptr Component::GetApplication(void)
{ {
return m_Application.lock(); return m_Application.lock();
} }
void Component::SetConfig(ConfigObject::RefType componentConfig) void Component::SetConfig(ConfigObject::Ptr componentConfig)
{ {
m_Config = componentConfig; m_Config = componentConfig;
} }
ConfigObject::RefType Component::GetConfig(void) ConfigObject::Ptr Component::GetConfig(void)
{ {
return m_Config; return m_Config;
} }

View File

@ -7,18 +7,18 @@ namespace icinga
class Component : public Object class Component : public Object
{ {
private: private:
Application::WeakRefType m_Application; Application::WeakPtr m_Application;
ConfigObject::RefType m_Config; ConfigObject::Ptr m_Config;
public: public:
typedef shared_ptr<Component> RefType; typedef shared_ptr<Component> Ptr;
typedef weak_ptr<Component> WeakRefType; typedef weak_ptr<Component> WeakPtr;
void SetApplication(const Application::WeakRefType& application); void SetApplication(const Application::WeakPtr& application);
Application::RefType GetApplication(void); Application::Ptr GetApplication(void);
void SetConfig(ConfigObject::RefType componentConfig); void SetConfig(ConfigObject::Ptr componentConfig);
ConfigObject::RefType GetConfig(void); ConfigObject::Ptr GetConfig(void);
virtual string GetName(void) = 0; virtual string GetName(void) = 0;
virtual void Start(void) = 0; virtual void Start(void) = 0;

View File

@ -2,13 +2,13 @@
using namespace icinga; using namespace icinga;
void ConfigHive::AddObject(ConfigObject::RefType object) void ConfigHive::AddObject(ConfigObject::Ptr object)
{ {
string type = object->GetType(); string type = object->GetType();
TypeIterator ti = Objects.find(type); TypeIterator ti = Objects.find(type);
if (ti == Objects.end()) { if (ti == Objects.end()) {
Objects[type] = map<string, ConfigObject::RefType>(); Objects[type] = map<string, ConfigObject::Ptr>();
ti = Objects.find(type); ti = Objects.find(type);
} }
@ -17,13 +17,13 @@ void ConfigHive::AddObject(ConfigObject::RefType object)
string name = object->GetName(); string name = object->GetName();
ti->second[name] = object; ti->second[name] = object;
ConfigHiveEventArgs::RefType ea = new_object<ConfigHiveEventArgs>(); ConfigHiveEventArgs::Ptr ea = new_object<ConfigHiveEventArgs>();
ea->Source = shared_from_this(); ea->Source = shared_from_this();
ea->Object = object; ea->Object = object;
OnObjectCreated(ea); OnObjectCreated(ea);
} }
void ConfigHive::RemoveObject(ConfigObject::RefType object) void ConfigHive::RemoveObject(ConfigObject::Ptr object)
{ {
string type = object->GetType(); string type = object->GetType();
TypeIterator ti = Objects.find(type); TypeIterator ti = Objects.find(type);
@ -33,23 +33,23 @@ void ConfigHive::RemoveObject(ConfigObject::RefType object)
ti->second.erase(object->GetName()); ti->second.erase(object->GetName());
ConfigHiveEventArgs::RefType ea = new_object<ConfigHiveEventArgs>(); ConfigHiveEventArgs::Ptr ea = new_object<ConfigHiveEventArgs>();
ea->Source = shared_from_this(); ea->Source = shared_from_this();
ea->Object = object; ea->Object = object;
OnObjectRemoved(ea); OnObjectRemoved(ea);
} }
ConfigObject::RefType ConfigHive::GetObject(const string& type, const string& name) ConfigObject::Ptr ConfigHive::GetObject(const string& type, const string& name)
{ {
ConfigHive::TypeIterator ti = Objects.find(type); ConfigHive::TypeIterator ti = Objects.find(type);
if (ti == Objects.end()) if (ti == Objects.end())
return ConfigObject::RefType(); return ConfigObject::Ptr();
ConfigHive::ObjectIterator oi = ti->second.find(name); ConfigHive::ObjectIterator oi = ti->second.find(name);
if (oi == ti->second.end()) if (oi == ti->second.end())
return ConfigObject::RefType(); return ConfigObject::Ptr();
return oi->second; return oi->second;
} }

View File

@ -6,10 +6,10 @@ namespace icinga
struct ConfigHiveEventArgs : public EventArgs struct ConfigHiveEventArgs : public EventArgs
{ {
typedef shared_ptr<ConfigHiveEventArgs> RefType; typedef shared_ptr<ConfigHiveEventArgs> Ptr;
typedef weak_ptr<ConfigHiveEventArgs> WeakRefType; typedef weak_ptr<ConfigHiveEventArgs> WeakPtr;
ConfigObject::RefType Object; ConfigObject::Ptr Object;
string Property; string Property;
string OldValue; string OldValue;
}; };
@ -17,20 +17,20 @@ struct ConfigHiveEventArgs : public EventArgs
class ConfigHive : public Object class ConfigHive : public Object
{ {
public: public:
typedef shared_ptr<ConfigHive> RefType; typedef shared_ptr<ConfigHive> Ptr;
typedef weak_ptr<ConfigHive> WeakRefType; typedef weak_ptr<ConfigHive> WeakPtr;
typedef map< string, map<string, ConfigObject::RefType> >::iterator TypeIterator; typedef map< string, map<string, ConfigObject::Ptr> >::iterator TypeIterator;
typedef map<string, ConfigObject::RefType>::iterator ObjectIterator; typedef map<string, ConfigObject::Ptr>::iterator ObjectIterator;
map< string, map<string, ConfigObject::RefType> > Objects; map< string, map<string, ConfigObject::Ptr> > Objects;
void AddObject(ConfigObject::RefType object); void AddObject(ConfigObject::Ptr object);
void RemoveObject(ConfigObject::RefType object); void RemoveObject(ConfigObject::Ptr object);
ConfigObject::RefType GetObject(const string& type, const string& name = string()); ConfigObject::Ptr GetObject(const string& type, const string& name = string());
event<ConfigHiveEventArgs::RefType> OnObjectCreated; event<ConfigHiveEventArgs::Ptr> OnObjectCreated;
event<ConfigHiveEventArgs::RefType> OnObjectRemoved; event<ConfigHiveEventArgs::Ptr> OnObjectRemoved;
event<ConfigHiveEventArgs::RefType> OnPropertyChanged; event<ConfigHiveEventArgs::Ptr> OnPropertyChanged;
}; };
} }

View File

@ -2,12 +2,12 @@
using namespace icinga; using namespace icinga;
void ConfigObject::SetHive(const ConfigHive::WeakRefType& hive) void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
{ {
m_Hive = hive; m_Hive = hive;
} }
ConfigHive::WeakRefType ConfigObject::GetHive(void) const ConfigHive::WeakPtr ConfigObject::GetHive(void) const
{ {
return m_Hive; return m_Hive;
} }
@ -36,9 +36,9 @@ void ConfigObject::SetProperty(const string& name, const string& value)
{ {
Properties[name] = value; Properties[name] = value;
ConfigHive::RefType hive = m_Hive.lock(); ConfigHive::Ptr hive = m_Hive.lock();
if (hive.get() != NULL) { if (hive.get() != NULL) {
ConfigHiveEventArgs::RefType ea = new_object<ConfigHiveEventArgs>(); ConfigHiveEventArgs::Ptr ea = new_object<ConfigHiveEventArgs>();
ea->Source = hive; ea->Source = hive;
ea->Object = static_pointer_cast<ConfigObject>(shared_from_this()); ea->Object = static_pointer_cast<ConfigObject>(shared_from_this());
ea->Property = name; ea->Property = name;

View File

@ -17,8 +17,8 @@ private:
string m_Type; string m_Type;
public: public:
typedef shared_ptr<ConfigObject> RefType; typedef shared_ptr<ConfigObject> Ptr;
typedef weak_ptr<ConfigObject> WeakRefType; typedef weak_ptr<ConfigObject> WeakPtr;
typedef map<string, string>::iterator ParameterIterator; typedef map<string, string>::iterator ParameterIterator;
map<string, string> Properties; map<string, string> Properties;

View File

@ -6,10 +6,10 @@ namespace icinga
struct EventArgs : public Object struct EventArgs : public Object
{ {
typedef shared_ptr<EventArgs> RefType; typedef shared_ptr<EventArgs> Ptr;
typedef weak_ptr<EventArgs> WeakRefType; typedef weak_ptr<EventArgs> WeakPtr;
Object::RefType Source; Object::Ptr Source;
}; };
template<class TArgs> template<class TArgs>

View File

@ -18,8 +18,8 @@ private:
public: public:
static const size_t BlockSize = 16 * 1024; static const size_t BlockSize = 16 * 1024;
typedef shared_ptr<FIFO> RefType; typedef shared_ptr<FIFO> Ptr;
typedef weak_ptr<FIFO> WeakRefType; typedef weak_ptr<FIFO> WeakPtr;
FIFO(void); FIFO(void);
~FIFO(void); ~FIFO(void);

View File

@ -13,8 +13,8 @@ protected:
Object(void); Object(void);
public: public:
typedef shared_ptr<Object> RefType; typedef shared_ptr<Object> Ptr;
typedef weak_ptr<Object> WeakRefType; typedef weak_ptr<Object> WeakPtr;
static unsigned long ActiveObjects; static unsigned long ActiveObjects;
@ -44,10 +44,10 @@ shared_ptr<T> new_object(void)
return shared_ptr<T>(instance); return shared_ptr<T>(instance);
} }
typedef function<Object::RefType ()> factory_function; typedef function<Object::Ptr ()> factory_function;
template<class T> template<class T>
Object::RefType factory(void) Object::Ptr factory(void)
{ {
return new_object<T>(); return new_object<T>();
} }

View File

@ -2,7 +2,7 @@
using namespace icinga; using namespace icinga;
list<Socket::WeakRefType> Socket::Sockets; list<Socket::WeakPtr> Socket::Sockets;
Socket::Socket(void) Socket::Socket(void)
{ {
@ -52,7 +52,7 @@ void Socket::Close(bool from_dtor)
/* nobody can possibly have a valid event subscription when the destructor has been called */ /* nobody can possibly have a valid event subscription when the destructor has been called */
if (!from_dtor) { if (!from_dtor) {
EventArgs::RefType ea = new_object<EventArgs>(); EventArgs::Ptr ea = new_object<EventArgs>();
ea->Source = shared_from_this(); ea->Source = shared_from_this();
OnClosed(ea); OnClosed(ea);
} }
@ -64,8 +64,8 @@ void Socket::Close(bool from_dtor)
void Socket::CloseAllSockets(void) void Socket::CloseAllSockets(void)
{ {
for (list<Socket::WeakRefType>::iterator i = Sockets.begin(); i != Sockets.end(); ) { for (list<Socket::WeakPtr>::iterator i = Sockets.begin(); i != Sockets.end(); ) {
Socket::RefType socket = i->lock(); Socket::Ptr socket = i->lock();
i++; i++;

View File

@ -14,10 +14,10 @@ protected:
void Close(bool from_dtor); void Close(bool from_dtor);
public: public:
typedef shared_ptr<Socket> RefType; typedef shared_ptr<Socket> Ptr;
typedef weak_ptr<Socket> WeakRefType; typedef weak_ptr<Socket> WeakPtr;
static list<Socket::WeakRefType> Sockets; static list<Socket::WeakPtr> Sockets;
~Socket(void); ~Socket(void);
@ -26,11 +26,11 @@ public:
static void CloseAllSockets(void); static void CloseAllSockets(void);
event<EventArgs::RefType> OnReadable; event<EventArgs::Ptr> OnReadable;
event<EventArgs::RefType> OnWritable; event<EventArgs::Ptr> OnWritable;
event<EventArgs::RefType> OnException; event<EventArgs::Ptr> OnException;
event<EventArgs::RefType> OnClosed; event<EventArgs::Ptr> OnClosed;
virtual bool WantsToRead(void) const; virtual bool WantsToRead(void) const;
virtual bool WantsToWrite(void) const; virtual bool WantsToWrite(void) const;

View File

@ -12,24 +12,24 @@ void TCPClient::Start(void)
{ {
TCPSocket::Start(); TCPSocket::Start();
function<int (EventArgs::RefType)> rd = bind_weak(&TCPClient::ReadableEventHandler, shared_from_this()); function<int (EventArgs::Ptr)> rd = bind_weak(&TCPClient::ReadableEventHandler, shared_from_this());
OnReadable.bind(rd); OnReadable.bind(rd);
function<int (EventArgs::RefType)> wd = bind_weak(&TCPClient::WritableEventHandler, shared_from_this()); function<int (EventArgs::Ptr)> wd = bind_weak(&TCPClient::WritableEventHandler, shared_from_this());
OnWritable.bind(wd); OnWritable.bind(wd);
} }
FIFO::RefType TCPClient::GetSendQueue(void) FIFO::Ptr TCPClient::GetSendQueue(void)
{ {
return m_SendQueue; return m_SendQueue;
} }
FIFO::RefType TCPClient::GetRecvQueue(void) FIFO::Ptr TCPClient::GetRecvQueue(void)
{ {
return m_RecvQueue; return m_RecvQueue;
} }
int TCPClient::ReadableEventHandler(EventArgs::RefType ea) int TCPClient::ReadableEventHandler(EventArgs::Ptr ea)
{ {
int rc; int rc;
@ -51,14 +51,14 @@ int TCPClient::ReadableEventHandler(EventArgs::RefType ea)
m_RecvQueue->Write(NULL, rc); m_RecvQueue->Write(NULL, rc);
EventArgs::RefType dea = new_object<EventArgs>(); EventArgs::Ptr dea = new_object<EventArgs>();
dea->Source = shared_from_this(); dea->Source = shared_from_this();
OnDataAvailable(dea); OnDataAvailable(dea);
return 0; return 0;
} }
int TCPClient::WritableEventHandler(EventArgs::RefType ea) int TCPClient::WritableEventHandler(EventArgs::Ptr ea)
{ {
int rc; int rc;

View File

@ -7,15 +7,15 @@ namespace icinga
class TCPClient : public TCPSocket class TCPClient : public TCPSocket
{ {
private: private:
FIFO::RefType m_SendQueue; FIFO::Ptr m_SendQueue;
FIFO::RefType m_RecvQueue; FIFO::Ptr m_RecvQueue;
int ReadableEventHandler(EventArgs::RefType ea); int ReadableEventHandler(EventArgs::Ptr ea);
int WritableEventHandler(EventArgs::RefType ea); int WritableEventHandler(EventArgs::Ptr ea);
public: public:
typedef shared_ptr<TCPClient> RefType; typedef shared_ptr<TCPClient> Ptr;
typedef weak_ptr<TCPClient> WeakRefType; typedef weak_ptr<TCPClient> WeakPtr;
TCPClient(void); TCPClient(void);
@ -23,13 +23,13 @@ public:
void Connect(const char *hostname, unsigned short port); void Connect(const char *hostname, unsigned short port);
FIFO::RefType GetSendQueue(void); FIFO::Ptr GetSendQueue(void);
FIFO::RefType GetRecvQueue(void); FIFO::Ptr GetRecvQueue(void);
virtual bool WantsToRead(void) const; virtual bool WantsToRead(void) const;
virtual bool WantsToWrite(void) const; virtual bool WantsToWrite(void) const;
event<EventArgs::RefType> OnDataAvailable; event<EventArgs::Ptr> OnDataAvailable;
}; };
} }

View File

@ -21,7 +21,7 @@ void TCPServer::Start(void)
{ {
TCPSocket::Start(); TCPSocket::Start();
function<int (EventArgs::RefType)> dr = bind_weak(&TCPServer::ReadableEventHandler, shared_from_this()); function<int (EventArgs::Ptr)> dr = bind_weak(&TCPServer::ReadableEventHandler, shared_from_this());
OnReadable.bind(dr); OnReadable.bind(dr);
} }
@ -32,7 +32,7 @@ void TCPServer::Listen(void)
Start(); Start();
} }
int TCPServer::ReadableEventHandler(EventArgs::RefType ea) int TCPServer::ReadableEventHandler(EventArgs::Ptr ea)
{ {
int fd; int fd;
sockaddr_in addr; sockaddr_in addr;
@ -40,7 +40,7 @@ int TCPServer::ReadableEventHandler(EventArgs::RefType ea)
fd = accept(GetFD(), (sockaddr *)&addr, &addrlen); fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
NewClientEventArgs::RefType nea = new_object<NewClientEventArgs>(); NewClientEventArgs::Ptr nea = new_object<NewClientEventArgs>();
nea->Source = shared_from_this(); nea->Source = shared_from_this();
nea->Client = static_pointer_cast<TCPSocket>(m_ClientFactory()); nea->Client = static_pointer_cast<TCPSocket>(m_ClientFactory());
nea->Client->SetFD(fd); nea->Client->SetFD(fd);

View File

@ -6,22 +6,22 @@ namespace icinga
struct NewClientEventArgs : public EventArgs struct NewClientEventArgs : public EventArgs
{ {
typedef shared_ptr<NewClientEventArgs> RefType; typedef shared_ptr<NewClientEventArgs> Ptr;
typedef weak_ptr<NewClientEventArgs> WeakRefType; typedef weak_ptr<NewClientEventArgs> WeakPtr;
TCPSocket::RefType Client; TCPSocket::Ptr Client;
}; };
class TCPServer : public TCPSocket class TCPServer : public TCPSocket
{ {
private: private:
int ReadableEventHandler(EventArgs::RefType ea); int ReadableEventHandler(EventArgs::Ptr ea);
factory_function m_ClientFactory; factory_function m_ClientFactory;
public: public:
typedef shared_ptr<TCPServer> RefType; typedef shared_ptr<TCPServer> Ptr;
typedef weak_ptr<TCPServer> WeakRefType; typedef weak_ptr<TCPServer> WeakPtr;
TCPServer(void); TCPServer(void);
@ -32,7 +32,7 @@ public:
void Listen(void); void Listen(void);
event<NewClientEventArgs::RefType> OnNewClient; event<NewClientEventArgs::Ptr> OnNewClient;
virtual bool WantsToRead(void) const; virtual bool WantsToRead(void) const;
}; };

View File

@ -7,8 +7,8 @@ namespace icinga
class TCPSocket : public Socket class TCPSocket : public Socket
{ {
public: public:
typedef shared_ptr<TCPSocket> RefType; typedef shared_ptr<TCPSocket> Ptr;
typedef weak_ptr<TCPSocket> WeakRefType; typedef weak_ptr<TCPSocket> WeakPtr;
void MakeSocket(void); void MakeSocket(void);

View File

@ -5,7 +5,7 @@
using namespace icinga; using namespace icinga;
time_t Timer::NextCall; time_t Timer::NextCall;
list<Timer::WeakRefType> Timer::Timers; list<Timer::WeakPtr> Timer::Timers;
Timer::Timer(void) Timer::Timer(void)
{ {
@ -25,8 +25,8 @@ void Timer::RescheduleTimers(void)
/* Make sure we wake up at least once every 30 seconds */ /* Make sure we wake up at least once every 30 seconds */
NextCall = time(NULL) + 30; NextCall = time(NULL) + 30;
for (list<Timer::WeakRefType>::iterator i = Timers.begin(); i != Timers.end(); i++) { for (list<Timer::WeakPtr>::iterator i = Timers.begin(); i != Timers.end(); i++) {
Timer::RefType timer = i->lock(); Timer::Ptr timer = i->lock();
if (timer == NULL) if (timer == NULL)
continue; continue;
@ -42,8 +42,8 @@ void Timer::CallExpiredTimers(void)
time(&now); time(&now);
for (list<Timer::WeakRefType>::iterator i = Timers.begin(); i != Timers.end(); ) { for (list<Timer::WeakPtr>::iterator i = Timers.begin(); i != Timers.end(); ) {
Timer::RefType timer = Timer::RefType(*i); Timer::Ptr timer = Timer::Ptr(*i);
i++; i++;
if (timer == NULL) if (timer == NULL)
@ -58,8 +58,8 @@ void Timer::CallExpiredTimers(void)
void Timer::StopAllTimers(void) void Timer::StopAllTimers(void)
{ {
for (list<Timer::WeakRefType>::iterator i = Timers.begin(); i != Timers.end(); ) { for (list<Timer::WeakPtr>::iterator i = Timers.begin(); i != Timers.end(); ) {
Timer::RefType timer = i->lock(); Timer::Ptr timer = i->lock();
i++; i++;
@ -74,7 +74,7 @@ void Timer::StopAllTimers(void)
* the timer that originally invoked the delegate */ * the timer that originally invoked the delegate */
void Timer::Call(void) void Timer::Call(void)
{ {
TimerEventArgs::RefType ea = new_object<TimerEventArgs>(); TimerEventArgs::Ptr ea = new_object<TimerEventArgs>();
ea->Source = shared_from_this(); ea->Source = shared_from_this();
ea->UserArgs = m_UserArgs; ea->UserArgs = m_UserArgs;
OnTimerExpired(ea); OnTimerExpired(ea);

View File

@ -7,16 +7,16 @@ namespace icinga {
struct TimerEventArgs : public EventArgs struct TimerEventArgs : public EventArgs
{ {
typedef shared_ptr<TimerEventArgs> RefType; typedef shared_ptr<TimerEventArgs> Ptr;
typedef weak_ptr<TimerEventArgs> WeakRefType; typedef weak_ptr<TimerEventArgs> WeakPtr;
EventArgs::RefType UserArgs; EventArgs::Ptr UserArgs;
}; };
class Timer : public Object class Timer : public Object
{ {
private: private:
EventArgs::RefType m_UserArgs; EventArgs::Ptr m_UserArgs;
unsigned int m_Interval; unsigned int m_Interval;
time_t m_Next; time_t m_Next;
@ -27,18 +27,18 @@ private:
void Call(void); void Call(void);
public: public:
typedef shared_ptr<Timer> RefType; typedef shared_ptr<Timer> Ptr;
typedef weak_ptr<Timer> WeakRefType; typedef weak_ptr<Timer> WeakPtr;
static list<Timer::WeakRefType> Timers; static list<Timer::WeakPtr> Timers;
Timer(void); Timer(void);
void SetInterval(unsigned int interval); void SetInterval(unsigned int interval);
unsigned int GetInterval(void) const; unsigned int GetInterval(void) const;
void SetUserArgs(const EventArgs::RefType& userArgs); void SetUserArgs(const EventArgs::Ptr& userArgs);
EventArgs::RefType GetUserArgs(void) const; EventArgs::Ptr GetUserArgs(void) const;
static time_t GetNextCall(void); static time_t GetNextCall(void);
static void CallExpiredTimers(void); static void CallExpiredTimers(void);
@ -49,7 +49,7 @@ public:
void Reschedule(time_t next); void Reschedule(time_t next);
event<TimerEventArgs::RefType> OnTimerExpired; event<TimerEventArgs::Ptr> OnTimerExpired;
}; };
} }

View File

@ -13,7 +13,7 @@ string ConfigFileComponent::GetName(void)
void ConfigFileComponent::Start(void) void ConfigFileComponent::Start(void)
{ {
ifstream fp; ifstream fp;
FIFO::RefType fifo = new_object<FIFO>(); FIFO::Ptr fifo = new_object<FIFO>();
string filename; string filename;
if (!GetConfig()->GetProperty("configFilename", &filename)) if (!GetConfig()->GetProperty("configFilename", &filename))
@ -49,7 +49,7 @@ void ConfigFileComponent::Start(void)
for (cJSON *object = typeobj->child; object != NULL; object = object->next) { for (cJSON *object = typeobj->child; object != NULL; object = object->next) {
string name = object->string; string name = object->string;
ConfigObject::RefType cfgobj = new_object<ConfigObject>(); ConfigObject::Ptr cfgobj = new_object<ConfigObject>();
cfgobj->SetName(name); cfgobj->SetName(name);
cfgobj->SetType(type); cfgobj->SetType(type);

View File

@ -7,8 +7,8 @@ namespace icinga
class ConfigFileComponent : public Component class ConfigFileComponent : public Component
{ {
public: public:
typedef shared_ptr<ConfigFileComponent> RefType; typedef shared_ptr<ConfigFileComponent> Ptr;
typedef weak_ptr<ConfigFileComponent> WeakRefType; typedef weak_ptr<ConfigFileComponent> WeakPtr;
virtual string GetName(void); virtual string GetName(void);
virtual void Start(void); virtual void Start(void);

View File

@ -2,7 +2,7 @@
using namespace icinga; using namespace icinga;
IcingaApplication::RefType ConfigRpcComponent::GetIcingaApplication(void) IcingaApplication::Ptr ConfigRpcComponent::GetIcingaApplication(void)
{ {
return static_pointer_cast<IcingaApplication>(GetApplication()); return static_pointer_cast<IcingaApplication>(GetApplication());
} }
@ -14,10 +14,10 @@ string ConfigRpcComponent::GetName(void)
void ConfigRpcComponent::Start(void) void ConfigRpcComponent::Start(void)
{ {
IcingaApplication::RefType icingaApp = GetIcingaApplication(); IcingaApplication::Ptr icingaApp = GetIcingaApplication();
ConnectionManager::RefType connectionManager = icingaApp->GetConnectionManager(); ConnectionManager::Ptr connectionManager = icingaApp->GetConnectionManager();
ConfigHive::RefType configHive = icingaApp->GetConfigHive(); ConfigHive::Ptr configHive = icingaApp->GetConfigHive();
int configSource; int configSource;
if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) { if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
@ -38,9 +38,9 @@ void ConfigRpcComponent::Stop(void)
// TODO: implement // TODO: implement
} }
JsonRpcMessage::RefType ConfigRpcComponent::MakeObjectMessage(const ConfigObject::RefType& object, string method, bool includeProperties) JsonRpcMessage::Ptr ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
{ {
JsonRpcMessage::RefType msg = new_object<JsonRpcMessage>(); JsonRpcMessage::Ptr msg = new_object<JsonRpcMessage>();
msg->SetVersion("2.0"); msg->SetVersion("2.0");
msg->SetMethod(method); msg->SetMethod(method);
cJSON *params = msg->GetParams(); cJSON *params = msg->GetParams();
@ -60,14 +60,14 @@ JsonRpcMessage::RefType ConfigRpcComponent::MakeObjectMessage(const ConfigObject
return msg; return msg;
} }
int ConfigRpcComponent::FetchObjectsHandler(NewMessageEventArgs::RefType ea) int ConfigRpcComponent::FetchObjectsHandler(NewMessageEventArgs::Ptr ea)
{ {
JsonRpcClient::RefType client = static_pointer_cast<JsonRpcClient>(ea->Source); JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea->Source);
ConfigHive::RefType configHive = GetIcingaApplication()->GetConfigHive(); ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
for (ConfigHive::TypeIterator ti = configHive->Objects.begin(); ti != configHive->Objects.end(); ti++) { for (ConfigHive::TypeIterator ti = configHive->Objects.begin(); ti != configHive->Objects.end(); ti++) {
for (ConfigHive::ObjectIterator oi = ti->second.begin(); oi != ti->second.end(); oi++) { for (ConfigHive::ObjectIterator oi = ti->second.begin(); oi != ti->second.end(); oi++) {
JsonRpcMessage::RefType msg = MakeObjectMessage(oi->second, "config::ObjectCreated", true); JsonRpcMessage::Ptr msg = MakeObjectMessage(oi->second, "config::ObjectCreated", true);
client->SendMessage(msg); client->SendMessage(msg);
} }
} }
@ -75,48 +75,48 @@ int ConfigRpcComponent::FetchObjectsHandler(NewMessageEventArgs::RefType ea)
return 0; return 0;
} }
int ConfigRpcComponent::LocalObjectCreatedHandler(ConfigHiveEventArgs::RefType ea) int ConfigRpcComponent::LocalObjectCreatedHandler(ConfigHiveEventArgs::Ptr ea)
{ {
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager(); ConnectionManager::Ptr connectionManager = GetIcingaApplication()->GetConnectionManager();
connectionManager->SendMessage(MakeObjectMessage(ea->Object, "config::ObjectCreated", true)); connectionManager->SendMessage(MakeObjectMessage(ea->Object, "config::ObjectCreated", true));
return 0; return 0;
} }
int ConfigRpcComponent::LocalObjectRemovedHandler(ConfigHiveEventArgs::RefType ea) int ConfigRpcComponent::LocalObjectRemovedHandler(ConfigHiveEventArgs::Ptr ea)
{ {
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager(); ConnectionManager::Ptr connectionManager = GetIcingaApplication()->GetConnectionManager();
connectionManager->SendMessage(MakeObjectMessage(ea->Object, "config::ObjectRemoved", false)); connectionManager->SendMessage(MakeObjectMessage(ea->Object, "config::ObjectRemoved", false));
return 0; return 0;
} }
int ConfigRpcComponent::LocalPropertyChangedHandler(ConfigHiveEventArgs::RefType ea) int ConfigRpcComponent::LocalPropertyChangedHandler(ConfigHiveEventArgs::Ptr ea)
{ {
JsonRpcMessage::RefType msg = MakeObjectMessage(ea->Object, "config::ObjectRemoved", false); JsonRpcMessage::Ptr msg = MakeObjectMessage(ea->Object, "config::ObjectRemoved", false);
cJSON *params = msg->GetParams(); cJSON *params = msg->GetParams();
cJSON_AddStringToObject(params, "property", ea->Property.c_str()); cJSON_AddStringToObject(params, "property", ea->Property.c_str());
string value; string value;
ea->Object->GetProperty(ea->Property, &value); ea->Object->GetProperty(ea->Property, &value);
cJSON_AddStringToObject(params, "value", value.c_str()); cJSON_AddStringToObject(params, "value", value.c_str());
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager(); ConnectionManager::Ptr connectionManager = GetIcingaApplication()->GetConnectionManager();
connectionManager->SendMessage(msg); connectionManager->SendMessage(msg);
return 0; return 0;
} }
int ConfigRpcComponent::RemoteObjectCreatedHandler(NewMessageEventArgs::RefType ea) int ConfigRpcComponent::RemoteObjectCreatedHandler(NewMessageEventArgs::Ptr ea)
{ {
JsonRpcMessage::RefType message = ea->Message; JsonRpcMessage::Ptr message = ea->Message;
// TODO: update hive // TODO: update hive
return 0; return 0;
} }
int ConfigRpcComponent::RemoteObjectRemovedHandler(NewMessageEventArgs::RefType ea) int ConfigRpcComponent::RemoteObjectRemovedHandler(NewMessageEventArgs::Ptr ea)
{ {
JsonRpcMessage::RefType message = ea->Message; JsonRpcMessage::Ptr message = ea->Message;
string name, type; string name, type;
if (!message->GetParamString("name", &name)) if (!message->GetParamString("name", &name))
@ -125,8 +125,8 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(NewMessageEventArgs::RefType
if (!message->GetParamString("type", &type)) if (!message->GetParamString("type", &type))
return 0; return 0;
ConfigHive::RefType configHive = GetIcingaApplication()->GetConfigHive(); ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
ConfigObject::RefType object = configHive->GetObject(type, name); ConfigObject::Ptr object = configHive->GetObject(type, name);
if (object.get() == NULL) if (object.get() == NULL)
return 0; return 0;
@ -136,9 +136,9 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(NewMessageEventArgs::RefType
return 0; return 0;
} }
int ConfigRpcComponent::RemotePropertyChangedHandler(NewMessageEventArgs::RefType ea) int ConfigRpcComponent::RemotePropertyChangedHandler(NewMessageEventArgs::Ptr ea)
{ {
JsonRpcMessage::RefType message = ea->Message; JsonRpcMessage::Ptr message = ea->Message;
string name, type, property, value; string name, type, property, value;
if (!message->GetParamString("name", &name)) if (!message->GetParamString("name", &name))
@ -153,8 +153,8 @@ int ConfigRpcComponent::RemotePropertyChangedHandler(NewMessageEventArgs::RefTyp
if (!message->GetParamString("value", &value)) if (!message->GetParamString("value", &value))
return 0; return 0;
ConfigHive::RefType configHive = GetIcingaApplication()->GetConfigHive(); ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
ConfigObject::RefType object = configHive->GetObject(type, name); ConfigObject::Ptr object = configHive->GetObject(type, name);
if (object.get() == NULL) if (object.get() == NULL)
return 0; return 0;

View File

@ -7,19 +7,19 @@ namespace icinga
class ConfigRpcComponent : public Component class ConfigRpcComponent : public Component
{ {
private: private:
IcingaApplication::RefType GetIcingaApplication(void); IcingaApplication::Ptr GetIcingaApplication(void);
int FetchObjectsHandler(NewMessageEventArgs::RefType ea); int FetchObjectsHandler(NewMessageEventArgs::Ptr ea);
int LocalObjectCreatedHandler(ConfigHiveEventArgs::RefType ea); int LocalObjectCreatedHandler(ConfigHiveEventArgs::Ptr ea);
int LocalObjectRemovedHandler(ConfigHiveEventArgs::RefType ea); int LocalObjectRemovedHandler(ConfigHiveEventArgs::Ptr ea);
int LocalPropertyChangedHandler(ConfigHiveEventArgs::RefType ea); int LocalPropertyChangedHandler(ConfigHiveEventArgs::Ptr ea);
int RemoteObjectCreatedHandler(NewMessageEventArgs::RefType ea); int RemoteObjectCreatedHandler(NewMessageEventArgs::Ptr ea);
int RemoteObjectRemovedHandler(NewMessageEventArgs::RefType ea); int RemoteObjectRemovedHandler(NewMessageEventArgs::Ptr ea);
int RemotePropertyChangedHandler(NewMessageEventArgs::RefType ea); int RemotePropertyChangedHandler(NewMessageEventArgs::Ptr ea);
JsonRpcMessage::RefType MakeObjectMessage(const ConfigObject::RefType& object, string method, bool includeProperties); JsonRpcMessage::Ptr MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties);
public: public:
virtual string GetName(void); virtual string GetName(void);

View File

@ -33,7 +33,7 @@ int IcingaApplication::Main(const vector<string>& args)
GetConfigHive()->OnObjectCreated.bind(bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this())); GetConfigHive()->OnObjectCreated.bind(bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this()));
GetConfigHive()->OnObjectRemoved.bind(bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this())); GetConfigHive()->OnObjectRemoved.bind(bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this()));
ConfigObject::RefType fileComponentConfig = new_object<ConfigObject>(); ConfigObject::Ptr fileComponentConfig = new_object<ConfigObject>();
fileComponentConfig->SetName("configfilecomponent"); fileComponentConfig->SetName("configfilecomponent");
fileComponentConfig->SetType("component"); fileComponentConfig->SetType("component");
fileComponentConfig->SetProperty("configFilename", args[1]); fileComponentConfig->SetProperty("configFilename", args[1]);
@ -49,12 +49,12 @@ void IcingaApplication::PrintUsage(const string& programPath)
cout << "Syntax: " << programPath << " <config-file>" << endl; cout << "Syntax: " << programPath << " <config-file>" << endl;
} }
ConnectionManager::RefType IcingaApplication::GetConnectionManager(void) ConnectionManager::Ptr IcingaApplication::GetConnectionManager(void)
{ {
return m_ConnectionManager; return m_ConnectionManager;
} }
int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType ea) int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::Ptr ea)
{ {
if (ea->Object->GetType() == "component") { if (ea->Object->GetType() == "component") {
string path; string path;
@ -75,7 +75,7 @@ int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType e
return 0; return 0;
} }
int IcingaApplication::ConfigObjectRemovedHandler(ConfigHiveEventArgs::RefType ea) int IcingaApplication::ConfigObjectRemovedHandler(ConfigHiveEventArgs::Ptr ea)
{ {
if (ea->Object->GetType() == "component") { if (ea->Object->GetType() == "component") {
UnloadComponent(ea->Object->GetName()); UnloadComponent(ea->Object->GetName());

View File

@ -7,14 +7,14 @@ namespace icinga
class IcingaApplication : public Application class IcingaApplication : public Application
{ {
private: private:
ConnectionManager::RefType m_ConnectionManager; ConnectionManager::Ptr m_ConnectionManager;
int ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType ea); int ConfigObjectCreatedHandler(ConfigHiveEventArgs::Ptr ea);
int ConfigObjectRemovedHandler(ConfigHiveEventArgs::RefType ea); int ConfigObjectRemovedHandler(ConfigHiveEventArgs::Ptr ea);
public: public:
typedef shared_ptr<IcingaApplication> RefType; typedef shared_ptr<IcingaApplication> Ptr;
typedef weak_ptr<IcingaApplication> WeakRefType; typedef weak_ptr<IcingaApplication> WeakPtr;
IcingaApplication(void); IcingaApplication(void);
@ -22,7 +22,7 @@ public:
void PrintUsage(const string& programPath); void PrintUsage(const string& programPath);
virtual ConnectionManager::RefType GetConnectionManager(void); virtual ConnectionManager::Ptr GetConnectionManager(void);
}; };
} }

View File

@ -2,55 +2,55 @@
using namespace icinga; using namespace icinga;
void ConnectionManager::RegisterServer(JsonRpcServer::RefType server) void ConnectionManager::RegisterServer(JsonRpcServer::Ptr server)
{ {
m_Servers.push_front(server); m_Servers.push_front(server);
server->OnNewClient.bind(bind_weak(&ConnectionManager::NewClientHandler, shared_from_this())); server->OnNewClient.bind(bind_weak(&ConnectionManager::NewClientHandler, shared_from_this()));
} }
void ConnectionManager::UnregisterServer(JsonRpcServer::RefType server) void ConnectionManager::UnregisterServer(JsonRpcServer::Ptr server)
{ {
m_Servers.remove(server); m_Servers.remove(server);
// TODO: unbind event // TODO: unbind event
} }
void ConnectionManager::RegisterClient(JsonRpcClient::RefType client) void ConnectionManager::RegisterClient(JsonRpcClient::Ptr client)
{ {
m_Clients.push_front(client); m_Clients.push_front(client);
client->OnNewMessage.bind(bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this())); client->OnNewMessage.bind(bind_weak(&ConnectionManager::NewMessageHandler, shared_from_this()));
} }
void ConnectionManager::UnregisterClient(JsonRpcClient::RefType client) void ConnectionManager::UnregisterClient(JsonRpcClient::Ptr client)
{ {
m_Clients.remove(client); m_Clients.remove(client);
// TODO: unbind event // TODO: unbind event
} }
int ConnectionManager::NewClientHandler(NewClientEventArgs::RefType ncea) int ConnectionManager::NewClientHandler(NewClientEventArgs::Ptr ncea)
{ {
JsonRpcClient::RefType client = static_pointer_cast<JsonRpcClient>(ncea->Client); JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ncea->Client);
RegisterClient(client); RegisterClient(client);
return 0; return 0;
} }
int ConnectionManager::CloseClientHandler(EventArgs::RefType ea) int ConnectionManager::CloseClientHandler(EventArgs::Ptr ea)
{ {
UnregisterClient(static_pointer_cast<JsonRpcClient>(ea->Source)); UnregisterClient(static_pointer_cast<JsonRpcClient>(ea->Source));
return 0; return 0;
} }
int ConnectionManager::NewMessageHandler(NewMessageEventArgs::RefType nmea) int ConnectionManager::NewMessageHandler(NewMessageEventArgs::Ptr nmea)
{ {
JsonRpcMessage::RefType request = nmea->Message; JsonRpcMessage::Ptr request = nmea->Message;
JsonRpcClient::RefType client = static_pointer_cast<JsonRpcClient>(nmea->Source); JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(nmea->Source);
map<string, event<NewMessageEventArgs::RefType> >::iterator i; map<string, event<NewMessageEventArgs::Ptr> >::iterator i;
i = m_Methods.find(request->GetMethod()); i = m_Methods.find(request->GetMethod());
if (i == m_Methods.end()) { if (i == m_Methods.end()) {
JsonRpcMessage::RefType response = new_object<JsonRpcMessage>(); JsonRpcMessage::Ptr response = new_object<JsonRpcMessage>();
response->SetVersion("2.0"); response->SetVersion("2.0");
response->SetError("Unknown method."); response->SetError("Unknown method.");
response->SetID(request->GetID()); response->SetID(request->GetID());
@ -64,30 +64,30 @@ int ConnectionManager::NewMessageHandler(NewMessageEventArgs::RefType nmea)
return 0; return 0;
} }
void ConnectionManager::RegisterMethod(string method, function<int (NewMessageEventArgs::RefType)> callback) void ConnectionManager::RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> callback)
{ {
map<string, event<NewMessageEventArgs::RefType> >::iterator i; map<string, event<NewMessageEventArgs::Ptr> >::iterator i;
i = m_Methods.find(method); i = m_Methods.find(method);
if (i == m_Methods.end()) { if (i == m_Methods.end()) {
m_Methods[method] = event<NewMessageEventArgs::RefType>(); m_Methods[method] = event<NewMessageEventArgs::Ptr>();
i = m_Methods.find(method); i = m_Methods.find(method);
} }
i->second.bind(callback); i->second.bind(callback);
} }
void ConnectionManager::UnregisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function) void ConnectionManager::UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> function)
{ {
// TODO: implement // TODO: implement
} }
void ConnectionManager::SendMessage(JsonRpcMessage::RefType message) void ConnectionManager::SendMessage(JsonRpcMessage::Ptr message)
{ {
/* TODO: filter messages based on event subscriptions */ /* TODO: filter messages based on event subscriptions */
for (list<JsonRpcClient::RefType>::iterator i = m_Clients.begin(); i != m_Clients.end(); i++) for (list<JsonRpcClient::Ptr>::iterator i = m_Clients.begin(); i != m_Clients.end(); i++)
{ {
JsonRpcClient::RefType client = *i; JsonRpcClient::Ptr client = *i;
client->SendMessage(message); client->SendMessage(message);
} }
} }

View File

@ -6,28 +6,28 @@ namespace icinga
class ConnectionManager : public Object class ConnectionManager : public Object
{ {
list<JsonRpcServer::RefType> m_Servers; list<JsonRpcServer::Ptr> m_Servers;
list<JsonRpcClient::RefType> m_Clients; list<JsonRpcClient::Ptr> m_Clients;
map< string, event<NewMessageEventArgs::RefType> > m_Methods; map< string, event<NewMessageEventArgs::Ptr> > m_Methods;
int NewClientHandler(NewClientEventArgs::RefType ncea); int NewClientHandler(NewClientEventArgs::Ptr ncea);
int CloseClientHandler(EventArgs::RefType ea); int CloseClientHandler(EventArgs::Ptr ea);
int NewMessageHandler(NewMessageEventArgs::RefType nmea); int NewMessageHandler(NewMessageEventArgs::Ptr nmea);
public: public:
typedef shared_ptr<ConnectionManager> RefType; typedef shared_ptr<ConnectionManager> Ptr;
typedef weak_ptr<ConnectionManager> WeakRefType; typedef weak_ptr<ConnectionManager> WeakPtr;
void RegisterServer(JsonRpcServer::RefType server); void RegisterServer(JsonRpcServer::Ptr server);
void UnregisterServer(JsonRpcServer::RefType server); void UnregisterServer(JsonRpcServer::Ptr server);
void RegisterClient(JsonRpcClient::RefType client); void RegisterClient(JsonRpcClient::Ptr client);
void UnregisterClient(JsonRpcClient::RefType client); void UnregisterClient(JsonRpcClient::Ptr client);
void RegisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function); void RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> function);
void UnregisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function); void UnregisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> function);
void SendMessage(JsonRpcMessage::RefType message); void SendMessage(JsonRpcMessage::Ptr message);
}; };
} }

View File

@ -9,12 +9,12 @@ void JsonRpcClient::Start(void)
OnDataAvailable.bind(bind_weak(&JsonRpcClient::DataAvailableHandler, shared_from_this())); OnDataAvailable.bind(bind_weak(&JsonRpcClient::DataAvailableHandler, shared_from_this()));
} }
void JsonRpcClient::SendMessage(JsonRpcMessage::RefType message) void JsonRpcClient::SendMessage(JsonRpcMessage::Ptr message)
{ {
Netstring::WriteJSONToFIFO(GetSendQueue(), message->GetJSON()); Netstring::WriteJSONToFIFO(GetSendQueue(), message->GetJSON());
} }
int JsonRpcClient::DataAvailableHandler(EventArgs::RefType ea) int JsonRpcClient::DataAvailableHandler(EventArgs::Ptr ea)
{ {
cJSON *json; cJSON *json;
@ -30,9 +30,9 @@ int JsonRpcClient::DataAvailableHandler(EventArgs::RefType ea)
if (json == NULL) if (json == NULL)
break; break;
JsonRpcMessage::RefType msg = new_object<JsonRpcMessage>(); JsonRpcMessage::Ptr msg = new_object<JsonRpcMessage>();
msg->SetJSON(json); msg->SetJSON(json);
NewMessageEventArgs::RefType nea = new_object<NewMessageEventArgs>(); NewMessageEventArgs::Ptr nea = new_object<NewMessageEventArgs>();
nea->Source = shared_from_this(); nea->Source = shared_from_this();
nea->Message = msg; nea->Message = msg;
OnNewMessage(nea); OnNewMessage(nea);

View File

@ -6,26 +6,26 @@ namespace icinga
struct NewMessageEventArgs : public EventArgs struct NewMessageEventArgs : public EventArgs
{ {
typedef shared_ptr<NewMessageEventArgs> RefType; typedef shared_ptr<NewMessageEventArgs> Ptr;
typedef weak_ptr<NewMessageEventArgs> WeakRefType; typedef weak_ptr<NewMessageEventArgs> WeakPtr;
JsonRpcMessage::RefType Message; JsonRpcMessage::Ptr Message;
}; };
class JsonRpcClient : public TCPClient class JsonRpcClient : public TCPClient
{ {
private: private:
int DataAvailableHandler(EventArgs::RefType ea); int DataAvailableHandler(EventArgs::Ptr ea);
public: public:
typedef shared_ptr<JsonRpcClient> RefType; typedef shared_ptr<JsonRpcClient> Ptr;
typedef weak_ptr<JsonRpcClient> WeakRefType; typedef weak_ptr<JsonRpcClient> WeakPtr;
void SendMessage(JsonRpcMessage::RefType message); void SendMessage(JsonRpcMessage::Ptr message);
virtual void Start(void); virtual void Start(void);
event<NewMessageEventArgs::RefType> OnNewMessage; event<NewMessageEventArgs::Ptr> OnNewMessage;
}; };
} }

View File

@ -19,8 +19,8 @@ private:
cJSON *GetFieldObject(const char *field); cJSON *GetFieldObject(const char *field);
public: public:
typedef shared_ptr<JsonRpcMessage> RefType; typedef shared_ptr<JsonRpcMessage> Ptr;
typedef weak_ptr<JsonRpcMessage> WeakRefType; typedef weak_ptr<JsonRpcMessage> WeakPtr;
JsonRpcMessage(void); JsonRpcMessage(void);
~JsonRpcMessage(void); ~JsonRpcMessage(void);

View File

@ -7,8 +7,8 @@ namespace icinga
class JsonRpcServer : public TCPServer class JsonRpcServer : public TCPServer
{ {
public: public:
typedef shared_ptr<JsonRpcServer> RefType; typedef shared_ptr<JsonRpcServer> Ptr;
typedef weak_ptr<JsonRpcServer> WeakRefType; typedef weak_ptr<JsonRpcServer> WeakPtr;
JsonRpcServer(void); JsonRpcServer(void);
}; };

View File

@ -4,7 +4,7 @@
using namespace icinga; using namespace icinga;
/* based on https://github.com/PeterScott/netstring-c/blob/master/netstring.c */ /* based on https://github.com/PeterScott/netstring-c/blob/master/netstring.c */
cJSON *Netstring::ReadJSONFromFIFO(FIFO::RefType fifo) cJSON *Netstring::ReadJSONFromFIFO(FIFO::Ptr fifo)
{ {
size_t buffer_length = fifo->GetSize(); size_t buffer_length = fifo->GetSize();
char *buffer = (char *)fifo->GetReadBuffer(); char *buffer = (char *)fifo->GetReadBuffer();
@ -56,7 +56,7 @@ cJSON *Netstring::ReadJSONFromFIFO(FIFO::RefType fifo)
return object; return object;
} }
void Netstring::WriteJSONToFIFO(FIFO::RefType fifo, cJSON *object) void Netstring::WriteJSONToFIFO(FIFO::Ptr fifo, cJSON *object)
{ {
char *json; char *json;
size_t len; size_t len;

View File

@ -11,11 +11,11 @@ private:
void *m_Data; void *m_Data;
public: public:
typedef shared_ptr<Netstring> RefType; typedef shared_ptr<Netstring> Ptr;
typedef weak_ptr<Netstring> WeakRefType; typedef weak_ptr<Netstring> WeakPtr;
static cJSON *ReadJSONFromFIFO(FIFO::RefType fifo); static cJSON *ReadJSONFromFIFO(FIFO::Ptr fifo);
static void WriteJSONToFIFO(FIFO::RefType fifo, cJSON *object); static void WriteJSONToFIFO(FIFO::Ptr fifo, cJSON *object);
}; };
} }