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;
Application::RefType Application::Instance;
Application::Ptr Application::Instance;
Application::Application(void)
{
@ -26,7 +26,7 @@ Application::~Application(void)
Timer::StopAllTimers();
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();
}
@ -47,8 +47,8 @@ void Application::RunEventLoop(void)
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
for (list<Socket::WeakRefType>::iterator i = Socket::Sockets.begin(); i != Socket::Sockets.end(); i++) {
Socket::RefType socket = i->lock();
for (list<Socket::WeakPtr>::iterator i = Socket::Sockets.begin(); i != Socket::Sockets.end(); i++) {
Socket::Ptr socket = i->lock();
if (socket == NULL)
continue;
@ -94,15 +94,15 @@ void Application::RunEventLoop(void)
else if (ready == 0)
continue;
EventArgs::RefType ea = new_object<EventArgs>();
EventArgs::Ptr ea = new_object<EventArgs>();
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(); ) {
prev = i;
i++;
Socket::RefType socket = prev->lock();
Socket::Ptr socket = prev->lock();
if (socket == NULL)
continue;
@ -170,14 +170,14 @@ void Application::Shutdown(void)
m_ShuttingDown = true;
}
ConfigHive::RefType Application::GetConfigHive(void)
ConfigHive::Ptr Application::GetConfigHive(void)
{
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)();
Log("Loading component '%s'", path.c_str());
@ -207,7 +207,7 @@ Component::RefType Application::LoadComponent(string path, ConfigObject::RefType
if (pCreateComponent == NULL)
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->SetConfig(componentConfig);
m_Components[component->GetName()] = component;
@ -217,26 +217,26 @@ Component::RefType Application::LoadComponent(string path, ConfigObject::RefType
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())
return Component::RefType();
return Component::Ptr();
return ci->second;
}
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())
return;
Log("Unloading component '%s'", name.c_str());
Component::RefType component = ci->second;
Component::Ptr component = ci->second;
component->Stop();
m_Components.erase(ci);

View File

@ -8,15 +8,15 @@ class Component;
class Application : public Object {
private:
bool m_ShuttingDown;
ConfigHive::RefType m_ConfigHive;
ConfigHive::Ptr m_ConfigHive;
map< string, shared_ptr<Component> > m_Components;
vector<string> m_Arguments;
public:
typedef shared_ptr<Application> RefType;
typedef weak_ptr<Application> WeakRefType;
typedef shared_ptr<Application> Ptr;
typedef weak_ptr<Application> WeakPtr;
static Application::RefType Instance;
static Application::Ptr Instance;
Application(void);
~Application(void);
@ -32,9 +32,9 @@ public:
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);
shared_ptr<Component> GetComponent(string name);
void AddComponentSearchDir(string componentDirectory);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
using namespace icinga;
list<Socket::WeakRefType> Socket::Sockets;
list<Socket::WeakPtr> Socket::Sockets;
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 */
if (!from_dtor) {
EventArgs::RefType ea = new_object<EventArgs>();
EventArgs::Ptr ea = new_object<EventArgs>();
ea->Source = shared_from_this();
OnClosed(ea);
}
@ -64,8 +64,8 @@ void Socket::Close(bool from_dtor)
void Socket::CloseAllSockets(void)
{
for (list<Socket::WeakRefType>::iterator i = Sockets.begin(); i != Sockets.end(); ) {
Socket::RefType socket = i->lock();
for (list<Socket::WeakPtr>::iterator i = Sockets.begin(); i != Sockets.end(); ) {
Socket::Ptr socket = i->lock();
i++;

View File

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

View File

@ -12,24 +12,24 @@ void TCPClient::Start(void)
{
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);
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);
}
FIFO::RefType TCPClient::GetSendQueue(void)
FIFO::Ptr TCPClient::GetSendQueue(void)
{
return m_SendQueue;
}
FIFO::RefType TCPClient::GetRecvQueue(void)
FIFO::Ptr TCPClient::GetRecvQueue(void)
{
return m_RecvQueue;
}
int TCPClient::ReadableEventHandler(EventArgs::RefType ea)
int TCPClient::ReadableEventHandler(EventArgs::Ptr ea)
{
int rc;
@ -51,14 +51,14 @@ int TCPClient::ReadableEventHandler(EventArgs::RefType ea)
m_RecvQueue->Write(NULL, rc);
EventArgs::RefType dea = new_object<EventArgs>();
EventArgs::Ptr dea = new_object<EventArgs>();
dea->Source = shared_from_this();
OnDataAvailable(dea);
return 0;
}
int TCPClient::WritableEventHandler(EventArgs::RefType ea)
int TCPClient::WritableEventHandler(EventArgs::Ptr ea)
{
int rc;

View File

@ -7,15 +7,15 @@ namespace icinga
class TCPClient : public TCPSocket
{
private:
FIFO::RefType m_SendQueue;
FIFO::RefType m_RecvQueue;
FIFO::Ptr m_SendQueue;
FIFO::Ptr m_RecvQueue;
int ReadableEventHandler(EventArgs::RefType ea);
int WritableEventHandler(EventArgs::RefType ea);
int ReadableEventHandler(EventArgs::Ptr ea);
int WritableEventHandler(EventArgs::Ptr ea);
public:
typedef shared_ptr<TCPClient> RefType;
typedef weak_ptr<TCPClient> WeakRefType;
typedef shared_ptr<TCPClient> Ptr;
typedef weak_ptr<TCPClient> WeakPtr;
TCPClient(void);
@ -23,13 +23,13 @@ public:
void Connect(const char *hostname, unsigned short port);
FIFO::RefType GetSendQueue(void);
FIFO::RefType GetRecvQueue(void);
FIFO::Ptr GetSendQueue(void);
FIFO::Ptr GetRecvQueue(void);
virtual bool WantsToRead(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();
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);
}
@ -32,7 +32,7 @@ void TCPServer::Listen(void)
Start();
}
int TCPServer::ReadableEventHandler(EventArgs::RefType ea)
int TCPServer::ReadableEventHandler(EventArgs::Ptr ea)
{
int fd;
sockaddr_in addr;
@ -40,7 +40,7 @@ int TCPServer::ReadableEventHandler(EventArgs::RefType ea)
fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
NewClientEventArgs::RefType nea = new_object<NewClientEventArgs>();
NewClientEventArgs::Ptr nea = new_object<NewClientEventArgs>();
nea->Source = shared_from_this();
nea->Client = static_pointer_cast<TCPSocket>(m_ClientFactory());
nea->Client->SetFD(fd);

View File

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

View File

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

View File

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

View File

@ -7,16 +7,16 @@ namespace icinga {
struct TimerEventArgs : public EventArgs
{
typedef shared_ptr<TimerEventArgs> RefType;
typedef weak_ptr<TimerEventArgs> WeakRefType;
typedef shared_ptr<TimerEventArgs> Ptr;
typedef weak_ptr<TimerEventArgs> WeakPtr;
EventArgs::RefType UserArgs;
EventArgs::Ptr UserArgs;
};
class Timer : public Object
{
private:
EventArgs::RefType m_UserArgs;
EventArgs::Ptr m_UserArgs;
unsigned int m_Interval;
time_t m_Next;
@ -27,18 +27,18 @@ private:
void Call(void);
public:
typedef shared_ptr<Timer> RefType;
typedef weak_ptr<Timer> WeakRefType;
typedef shared_ptr<Timer> Ptr;
typedef weak_ptr<Timer> WeakPtr;
static list<Timer::WeakRefType> Timers;
static list<Timer::WeakPtr> Timers;
Timer(void);
void SetInterval(unsigned int interval);
unsigned int GetInterval(void) const;
void SetUserArgs(const EventArgs::RefType& userArgs);
EventArgs::RefType GetUserArgs(void) const;
void SetUserArgs(const EventArgs::Ptr& userArgs);
EventArgs::Ptr GetUserArgs(void) const;
static time_t GetNextCall(void);
static void CallExpiredTimers(void);
@ -49,7 +49,7 @@ public:
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)
{
ifstream fp;
FIFO::RefType fifo = new_object<FIFO>();
FIFO::Ptr fifo = new_object<FIFO>();
string filename;
if (!GetConfig()->GetProperty("configFilename", &filename))
@ -49,7 +49,7 @@ void ConfigFileComponent::Start(void)
for (cJSON *object = typeobj->child; object != NULL; object = object->next) {
string name = object->string;
ConfigObject::RefType cfgobj = new_object<ConfigObject>();
ConfigObject::Ptr cfgobj = new_object<ConfigObject>();
cfgobj->SetName(name);
cfgobj->SetType(type);

View File

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

View File

@ -2,7 +2,7 @@
using namespace icinga;
IcingaApplication::RefType ConfigRpcComponent::GetIcingaApplication(void)
IcingaApplication::Ptr ConfigRpcComponent::GetIcingaApplication(void)
{
return static_pointer_cast<IcingaApplication>(GetApplication());
}
@ -14,10 +14,10 @@ string ConfigRpcComponent::GetName(void)
void ConfigRpcComponent::Start(void)
{
IcingaApplication::RefType icingaApp = GetIcingaApplication();
IcingaApplication::Ptr icingaApp = GetIcingaApplication();
ConnectionManager::RefType connectionManager = icingaApp->GetConnectionManager();
ConfigHive::RefType configHive = icingaApp->GetConfigHive();
ConnectionManager::Ptr connectionManager = icingaApp->GetConnectionManager();
ConfigHive::Ptr configHive = icingaApp->GetConfigHive();
int configSource;
if (GetConfig()->GetPropertyInteger("configSource", &configSource) && configSource != 0) {
@ -38,9 +38,9 @@ void ConfigRpcComponent::Stop(void)
// 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->SetMethod(method);
cJSON *params = msg->GetParams();
@ -60,14 +60,14 @@ JsonRpcMessage::RefType ConfigRpcComponent::MakeObjectMessage(const ConfigObject
return msg;
}
int ConfigRpcComponent::FetchObjectsHandler(NewMessageEventArgs::RefType ea)
int ConfigRpcComponent::FetchObjectsHandler(NewMessageEventArgs::Ptr ea)
{
JsonRpcClient::RefType client = static_pointer_cast<JsonRpcClient>(ea->Source);
ConfigHive::RefType configHive = GetIcingaApplication()->GetConfigHive();
JsonRpcClient::Ptr client = static_pointer_cast<JsonRpcClient>(ea->Source);
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
for (ConfigHive::TypeIterator ti = configHive->Objects.begin(); ti != configHive->Objects.end(); ti++) {
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);
}
}
@ -75,48 +75,48 @@ int ConfigRpcComponent::FetchObjectsHandler(NewMessageEventArgs::RefType ea)
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));
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));
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_AddStringToObject(params, "property", ea->Property.c_str());
string value;
ea->Object->GetProperty(ea->Property, &value);
cJSON_AddStringToObject(params, "value", value.c_str());
ConnectionManager::RefType connectionManager = GetIcingaApplication()->GetConnectionManager();
ConnectionManager::Ptr connectionManager = GetIcingaApplication()->GetConnectionManager();
connectionManager->SendMessage(msg);
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
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;
if (!message->GetParamString("name", &name))
@ -125,8 +125,8 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(NewMessageEventArgs::RefType
if (!message->GetParamString("type", &type))
return 0;
ConfigHive::RefType configHive = GetIcingaApplication()->GetConfigHive();
ConfigObject::RefType object = configHive->GetObject(type, name);
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
ConfigObject::Ptr object = configHive->GetObject(type, name);
if (object.get() == NULL)
return 0;
@ -136,9 +136,9 @@ int ConfigRpcComponent::RemoteObjectRemovedHandler(NewMessageEventArgs::RefType
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;
if (!message->GetParamString("name", &name))
@ -153,8 +153,8 @@ int ConfigRpcComponent::RemotePropertyChangedHandler(NewMessageEventArgs::RefTyp
if (!message->GetParamString("value", &value))
return 0;
ConfigHive::RefType configHive = GetIcingaApplication()->GetConfigHive();
ConfigObject::RefType object = configHive->GetObject(type, name);
ConfigHive::Ptr configHive = GetIcingaApplication()->GetConfigHive();
ConfigObject::Ptr object = configHive->GetObject(type, name);
if (object.get() == NULL)
return 0;

View File

@ -7,19 +7,19 @@ namespace icinga
class ConfigRpcComponent : public Component
{
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 LocalObjectRemovedHandler(ConfigHiveEventArgs::RefType ea);
int LocalPropertyChangedHandler(ConfigHiveEventArgs::RefType ea);
int LocalObjectCreatedHandler(ConfigHiveEventArgs::Ptr ea);
int LocalObjectRemovedHandler(ConfigHiveEventArgs::Ptr ea);
int LocalPropertyChangedHandler(ConfigHiveEventArgs::Ptr ea);
int RemoteObjectCreatedHandler(NewMessageEventArgs::RefType ea);
int RemoteObjectRemovedHandler(NewMessageEventArgs::RefType ea);
int RemotePropertyChangedHandler(NewMessageEventArgs::RefType ea);
int RemoteObjectCreatedHandler(NewMessageEventArgs::Ptr ea);
int RemoteObjectRemovedHandler(NewMessageEventArgs::Ptr 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:
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()->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->SetType("component");
fileComponentConfig->SetProperty("configFilename", args[1]);
@ -49,12 +49,12 @@ void IcingaApplication::PrintUsage(const string& programPath)
cout << "Syntax: " << programPath << " <config-file>" << endl;
}
ConnectionManager::RefType IcingaApplication::GetConnectionManager(void)
ConnectionManager::Ptr IcingaApplication::GetConnectionManager(void)
{
return m_ConnectionManager;
}
int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType ea)
int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::Ptr ea)
{
if (ea->Object->GetType() == "component") {
string path;
@ -75,7 +75,7 @@ int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType e
return 0;
}
int IcingaApplication::ConfigObjectRemovedHandler(ConfigHiveEventArgs::RefType ea)
int IcingaApplication::ConfigObjectRemovedHandler(ConfigHiveEventArgs::Ptr ea)
{
if (ea->Object->GetType() == "component") {
UnloadComponent(ea->Object->GetName());

View File

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

View File

@ -2,55 +2,55 @@
using namespace icinga;
void ConnectionManager::RegisterServer(JsonRpcServer::RefType server)
void ConnectionManager::RegisterServer(JsonRpcServer::Ptr server)
{
m_Servers.push_front(server);
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);
// TODO: unbind event
}
void ConnectionManager::RegisterClient(JsonRpcClient::RefType client)
void ConnectionManager::RegisterClient(JsonRpcClient::Ptr client)
{
m_Clients.push_front(client);
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);
// 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);
return 0;
}
int ConnectionManager::CloseClientHandler(EventArgs::RefType ea)
int ConnectionManager::CloseClientHandler(EventArgs::Ptr ea)
{
UnregisterClient(static_pointer_cast<JsonRpcClient>(ea->Source));
return 0;
}
int ConnectionManager::NewMessageHandler(NewMessageEventArgs::RefType nmea)
int ConnectionManager::NewMessageHandler(NewMessageEventArgs::Ptr nmea)
{
JsonRpcMessage::RefType request = nmea->Message;
JsonRpcClient::RefType client = static_pointer_cast<JsonRpcClient>(nmea->Source);
JsonRpcMessage::Ptr request = nmea->Message;
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());
if (i == m_Methods.end()) {
JsonRpcMessage::RefType response = new_object<JsonRpcMessage>();
JsonRpcMessage::Ptr response = new_object<JsonRpcMessage>();
response->SetVersion("2.0");
response->SetError("Unknown method.");
response->SetID(request->GetID());
@ -64,30 +64,30 @@ int ConnectionManager::NewMessageHandler(NewMessageEventArgs::RefType nmea)
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);
if (i == m_Methods.end()) {
m_Methods[method] = event<NewMessageEventArgs::RefType>();
m_Methods[method] = event<NewMessageEventArgs::Ptr>();
i = m_Methods.find(method);
}
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
}
void ConnectionManager::SendMessage(JsonRpcMessage::RefType message)
void ConnectionManager::SendMessage(JsonRpcMessage::Ptr message)
{
/* 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);
}
}

View File

@ -6,28 +6,28 @@ namespace icinga
class ConnectionManager : public Object
{
list<JsonRpcServer::RefType> m_Servers;
list<JsonRpcClient::RefType> m_Clients;
map< string, event<NewMessageEventArgs::RefType> > m_Methods;
list<JsonRpcServer::Ptr> m_Servers;
list<JsonRpcClient::Ptr> m_Clients;
map< string, event<NewMessageEventArgs::Ptr> > m_Methods;
int NewClientHandler(NewClientEventArgs::RefType ncea);
int CloseClientHandler(EventArgs::RefType ea);
int NewMessageHandler(NewMessageEventArgs::RefType nmea);
int NewClientHandler(NewClientEventArgs::Ptr ncea);
int CloseClientHandler(EventArgs::Ptr ea);
int NewMessageHandler(NewMessageEventArgs::Ptr nmea);
public:
typedef shared_ptr<ConnectionManager> RefType;
typedef weak_ptr<ConnectionManager> WeakRefType;
typedef shared_ptr<ConnectionManager> Ptr;
typedef weak_ptr<ConnectionManager> WeakPtr;
void RegisterServer(JsonRpcServer::RefType server);
void UnregisterServer(JsonRpcServer::RefType server);
void RegisterServer(JsonRpcServer::Ptr server);
void UnregisterServer(JsonRpcServer::Ptr server);
void RegisterClient(JsonRpcClient::RefType client);
void UnregisterClient(JsonRpcClient::RefType client);
void RegisterClient(JsonRpcClient::Ptr client);
void UnregisterClient(JsonRpcClient::Ptr client);
void RegisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function);
void UnregisterMethod(string method, function<int (NewMessageEventArgs::RefType)> function);
void RegisterMethod(string method, function<int (NewMessageEventArgs::Ptr)> 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()));
}
void JsonRpcClient::SendMessage(JsonRpcMessage::RefType message)
void JsonRpcClient::SendMessage(JsonRpcMessage::Ptr message)
{
Netstring::WriteJSONToFIFO(GetSendQueue(), message->GetJSON());
}
int JsonRpcClient::DataAvailableHandler(EventArgs::RefType ea)
int JsonRpcClient::DataAvailableHandler(EventArgs::Ptr ea)
{
cJSON *json;
@ -30,9 +30,9 @@ int JsonRpcClient::DataAvailableHandler(EventArgs::RefType ea)
if (json == NULL)
break;
JsonRpcMessage::RefType msg = new_object<JsonRpcMessage>();
JsonRpcMessage::Ptr msg = new_object<JsonRpcMessage>();
msg->SetJSON(json);
NewMessageEventArgs::RefType nea = new_object<NewMessageEventArgs>();
NewMessageEventArgs::Ptr nea = new_object<NewMessageEventArgs>();
nea->Source = shared_from_this();
nea->Message = msg;
OnNewMessage(nea);

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@
using namespace icinga;
/* 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();
char *buffer = (char *)fifo->GetReadBuffer();
@ -56,7 +56,7 @@ cJSON *Netstring::ReadJSONFromFIFO(FIFO::RefType fifo)
return object;
}
void Netstring::WriteJSONToFIFO(FIFO::RefType fifo, cJSON *object)
void Netstring::WriteJSONToFIFO(FIFO::Ptr fifo, cJSON *object)
{
char *json;
size_t len;

View File

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