mirror of https://github.com/Icinga/icinga2.git
Removed custom new_object function.
This commit is contained in:
parent
34d50924e8
commit
66fdf079fa
|
@ -18,7 +18,7 @@ Application::Application(void)
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
m_ShuttingDown = false;
|
m_ShuttingDown = false;
|
||||||
m_ConfigHive = new_object<ConfigHive>();
|
m_ConfigHive = make_shared<ConfigHive>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application(void)
|
Application::~Application(void)
|
||||||
|
@ -94,7 +94,7 @@ void Application::RunEventLoop(void)
|
||||||
else if (ready == 0)
|
else if (ready == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
EventArgs::Ptr ea = new_object<EventArgs>();
|
EventArgs::Ptr ea = make_shared<EventArgs>();
|
||||||
ea->Source = shared_from_this();
|
ea->Source = shared_from_this();
|
||||||
|
|
||||||
list<Socket::WeakPtr>::iterator prev, i;
|
list<Socket::WeakPtr>::iterator prev, i;
|
||||||
|
|
|
@ -49,7 +49,7 @@ int application_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
Application::Instance = new_object<T>();
|
Application::Instance = make_shared<T>();
|
||||||
|
|
||||||
vector<string> args;
|
vector<string> args;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ void ConfigHive::AddObject(const ConfigObject::Ptr& object)
|
||||||
string name = object->GetName();
|
string name = object->GetName();
|
||||||
ti->second[name] = object;
|
ti->second[name] = object;
|
||||||
|
|
||||||
ConfigHiveEventArgs::Ptr ea = new_object<ConfigHiveEventArgs>();
|
ConfigHiveEventArgs::Ptr ea = make_shared<ConfigHiveEventArgs>();
|
||||||
ea->Source = shared_from_this();
|
ea->Source = shared_from_this();
|
||||||
ea->Object = object;
|
ea->Object = object;
|
||||||
OnObjectCreated(ea);
|
OnObjectCreated(ea);
|
||||||
|
@ -33,7 +33,7 @@ void ConfigHive::RemoveObject(const ConfigObject::Ptr& object)
|
||||||
|
|
||||||
ti->second.erase(object->GetName());
|
ti->second.erase(object->GetName());
|
||||||
|
|
||||||
ConfigHiveEventArgs::Ptr ea = new_object<ConfigHiveEventArgs>();
|
ConfigHiveEventArgs::Ptr ea = make_shared<ConfigHiveEventArgs>();
|
||||||
ea->Source = shared_from_this();
|
ea->Source = shared_from_this();
|
||||||
ea->Object = object;
|
ea->Object = object;
|
||||||
OnObjectRemoved(ea);
|
OnObjectRemoved(ea);
|
||||||
|
|
|
@ -38,7 +38,7 @@ void ConfigObject::SetProperty(const string& name, const string& value)
|
||||||
|
|
||||||
ConfigHive::Ptr hive = m_Hive.lock();
|
ConfigHive::Ptr hive = m_Hive.lock();
|
||||||
if (hive.get() != NULL) {
|
if (hive.get() != NULL) {
|
||||||
ConfigHiveEventArgs::Ptr ea = new_object<ConfigHiveEventArgs>();
|
ConfigHiveEventArgs::Ptr ea = make_shared<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;
|
||||||
|
|
|
@ -36,36 +36,12 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
|
||||||
shared_ptr<T> new_object(void)
|
|
||||||
{
|
|
||||||
T *instance = new T();
|
|
||||||
|
|
||||||
return shared_ptr<T>(instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T, class TArg1>
|
|
||||||
shared_ptr<T> new_object(const TArg1& arg1)
|
|
||||||
{
|
|
||||||
T *instance = new T(arg1);
|
|
||||||
|
|
||||||
return shared_ptr<T>(instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T, class TArg1, class TArg2>
|
|
||||||
shared_ptr<T> new_object(const TArg1& arg1, const TArg2& arg2)
|
|
||||||
{
|
|
||||||
T *instance = new T(arg1, arg2);
|
|
||||||
|
|
||||||
return shared_ptr<T>(instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef function<Object::Ptr ()> factory_function;
|
typedef function<Object::Ptr ()> factory_function;
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Object::Ptr factory(void)
|
Object::Ptr factory(void)
|
||||||
{
|
{
|
||||||
return new_object<T>();
|
return make_shared<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::Ptr ea = new_object<EventArgs>();
|
EventArgs::Ptr ea = make_shared<EventArgs>();
|
||||||
ea->Source = shared_from_this();
|
ea->Source = shared_from_this();
|
||||||
OnClosed(ea);
|
OnClosed(ea);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ using namespace icinga;
|
||||||
|
|
||||||
TCPClient::TCPClient(void)
|
TCPClient::TCPClient(void)
|
||||||
{
|
{
|
||||||
m_SendQueue = new_object<FIFO>();
|
m_SendQueue = make_shared<FIFO>();
|
||||||
m_RecvQueue = new_object<FIFO>();
|
m_RecvQueue = make_shared<FIFO>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPClient::Start(void)
|
void TCPClient::Start(void)
|
||||||
|
@ -48,7 +48,7 @@ int TCPClient::ReadableEventHandler(EventArgs::Ptr ea)
|
||||||
|
|
||||||
m_RecvQueue->Write(NULL, rc);
|
m_RecvQueue->Write(NULL, rc);
|
||||||
|
|
||||||
EventArgs::Ptr dea = new_object<EventArgs>();
|
EventArgs::Ptr dea = make_shared<EventArgs>();
|
||||||
dea->Source = shared_from_this();
|
dea->Source = shared_from_this();
|
||||||
OnDataAvailable(dea);
|
OnDataAvailable(dea);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ int TCPServer::ReadableEventHandler(EventArgs::Ptr ea)
|
||||||
|
|
||||||
fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
|
fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
|
||||||
|
|
||||||
NewClientEventArgs::Ptr nea = new_object<NewClientEventArgs>();
|
NewClientEventArgs::Ptr nea = make_shared<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);
|
||||||
|
|
|
@ -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::Ptr ea = new_object<TimerEventArgs>();
|
TimerEventArgs::Ptr ea = make_shared<TimerEventArgs>();
|
||||||
ea->Source = shared_from_this();
|
ea->Source = shared_from_this();
|
||||||
ea->UserArgs = m_UserArgs;
|
ea->UserArgs = m_UserArgs;
|
||||||
OnTimerExpired(ea);
|
OnTimerExpired(ea);
|
||||||
|
|
|
@ -13,7 +13,7 @@ string ConfigFileComponent::GetName(void)
|
||||||
void ConfigFileComponent::Start(void)
|
void ConfigFileComponent::Start(void)
|
||||||
{
|
{
|
||||||
ifstream fp;
|
ifstream fp;
|
||||||
FIFO::Ptr fifo = new_object<FIFO>();
|
FIFO::Ptr fifo = make_shared<FIFO>();
|
||||||
|
|
||||||
string filename;
|
string filename;
|
||||||
if (!GetConfig()->GetProperty("configFilename", &filename))
|
if (!GetConfig()->GetProperty("configFilename", &filename))
|
||||||
|
@ -51,7 +51,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::Ptr cfgobj = new_object<ConfigObject>();
|
ConfigObject::Ptr cfgobj = make_shared<ConfigObject>();
|
||||||
cfgobj->SetName(name);
|
cfgobj->SetName(name);
|
||||||
cfgobj->SetType(type);
|
cfgobj->SetType(type);
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ void ConfigRpcComponent::Stop(void)
|
||||||
|
|
||||||
JsonRpcMessage::Ptr ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
|
JsonRpcMessage::Ptr ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
|
||||||
{
|
{
|
||||||
JsonRpcMessage::Ptr msg = new_object<JsonRpcMessage>();
|
JsonRpcMessage::Ptr msg = make_shared<JsonRpcMessage>();
|
||||||
msg->SetVersion("2.0");
|
msg->SetVersion("2.0");
|
||||||
msg->SetMethod(method);
|
msg->SetMethod(method);
|
||||||
cJSON *params = msg->GetParams();
|
cJSON *params = msg->GetParams();
|
||||||
|
|
|
@ -11,7 +11,7 @@ using namespace icinga;
|
||||||
|
|
||||||
IcingaApplication::IcingaApplication(void)
|
IcingaApplication::IcingaApplication(void)
|
||||||
{
|
{
|
||||||
m_ConnectionManager = new_object<ConnectionManager>();
|
m_ConnectionManager = make_shared<ConnectionManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::Main(const vector<string>& args)
|
int IcingaApplication::Main(const vector<string>& args)
|
||||||
|
@ -33,7 +33,7 @@ int IcingaApplication::Main(const vector<string>& args)
|
||||||
GetConfigHive()->OnObjectCreated += bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this());
|
GetConfigHive()->OnObjectCreated += bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this());
|
||||||
GetConfigHive()->OnObjectRemoved += bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this());
|
GetConfigHive()->OnObjectRemoved += bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this());
|
||||||
|
|
||||||
ConfigObject::Ptr fileComponentConfig = new_object<ConfigObject>();
|
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>();
|
||||||
fileComponentConfig->SetName("configfilecomponent");
|
fileComponentConfig->SetName("configfilecomponent");
|
||||||
fileComponentConfig->SetType("component");
|
fileComponentConfig->SetType("component");
|
||||||
fileComponentConfig->SetProperty("configFilename", args[1]);
|
fileComponentConfig->SetProperty("configFilename", args[1]);
|
||||||
|
|
|
@ -50,7 +50,7 @@ int ConnectionManager::NewMessageHandler(NewMessageEventArgs::Ptr nmea)
|
||||||
i = m_Methods.find(request->GetMethod());
|
i = m_Methods.find(request->GetMethod());
|
||||||
|
|
||||||
if (i == m_Methods.end()) {
|
if (i == m_Methods.end()) {
|
||||||
JsonRpcMessage::Ptr response = new_object<JsonRpcMessage>();
|
JsonRpcMessage::Ptr response = make_shared<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());
|
||||||
|
|
|
@ -30,9 +30,9 @@ int JsonRpcClient::DataAvailableHandler(EventArgs::Ptr ea)
|
||||||
if (json == NULL)
|
if (json == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
JsonRpcMessage::Ptr msg = new_object<JsonRpcMessage>();
|
JsonRpcMessage::Ptr msg = make_shared<JsonRpcMessage>();
|
||||||
msg->SetJSON(json);
|
msg->SetJSON(json);
|
||||||
NewMessageEventArgs::Ptr nea = new_object<NewMessageEventArgs>();
|
NewMessageEventArgs::Ptr nea = make_shared<NewMessageEventArgs>();
|
||||||
nea->Source = shared_from_this();
|
nea->Source = shared_from_this();
|
||||||
nea->Message = msg;
|
nea->Message = msg;
|
||||||
OnNewMessage(nea);
|
OnNewMessage(nea);
|
||||||
|
|
Loading…
Reference in New Issue