mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-31 01:24:19 +02:00
Introduce Registry::GetInstance() to deduplicate such methods
in derived classes and inline them, as side effect, to speed up calls.
This commit is contained in:
parent
6af2f9bd19
commit
e0911991e7
@ -7,6 +7,7 @@
|
|||||||
#include "base/atomic.hpp"
|
#include "base/atomic.hpp"
|
||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/string.hpp"
|
#include "base/string.hpp"
|
||||||
|
#include "base/singleton.hpp"
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -26,6 +27,11 @@ class Registry
|
|||||||
public:
|
public:
|
||||||
typedef std::unordered_map<String, T> ItemMap;
|
typedef std::unordered_map<String, T> ItemMap;
|
||||||
|
|
||||||
|
static Registry* GetInstance()
|
||||||
|
{
|
||||||
|
return Singleton<Registry>::GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
void Register(const String& name, const T& item)
|
void Register(const String& name, const T& item)
|
||||||
{
|
{
|
||||||
std::unique_lock lock (m_Mutex);
|
std::unique_lock lock (m_Mutex);
|
||||||
|
@ -133,8 +133,3 @@ std::set<DbType::Ptr> DbType::GetAllTypes()
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DbTypeRegistry *DbTypeRegistry::GetInstance()
|
|
||||||
{
|
|
||||||
return Singleton<DbTypeRegistry>::GetInstance();
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "db_ido/i2-db_ido.hpp"
|
#include "db_ido/i2-db_ido.hpp"
|
||||||
#include "base/object.hpp"
|
#include "base/object.hpp"
|
||||||
#include "base/registry.hpp"
|
#include "base/registry.hpp"
|
||||||
#include "base/singleton.hpp"
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
@ -64,8 +63,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
class DbTypeRegistry : public Registry<DbTypeRegistry, DbType::Ptr>
|
class DbTypeRegistry : public Registry<DbTypeRegistry, DbType::Ptr>
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
static DbTypeRegistry *GetInstance();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
||||||
|
|
||||||
#include "remote/apiaction.hpp"
|
#include "remote/apiaction.hpp"
|
||||||
#include "base/singleton.hpp"
|
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
@ -28,8 +27,3 @@ void ApiAction::Register(const String& name, const ApiAction::Ptr& action)
|
|||||||
{
|
{
|
||||||
ApiActionRegistry::GetInstance()->Register(name, action);
|
ApiActionRegistry::GetInstance()->Register(name, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiActionRegistry *ApiActionRegistry::GetInstance()
|
|
||||||
{
|
|
||||||
return Singleton<ApiActionRegistry>::GetInstance();
|
|
||||||
}
|
|
||||||
|
@ -47,8 +47,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
class ApiActionRegistry : public Registry<ApiActionRegistry, ApiAction::Ptr>
|
class ApiActionRegistry : public Registry<ApiActionRegistry, ApiAction::Ptr>
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
static ApiActionRegistry *GetInstance();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_APIACTION(name, types, callback) \
|
#define REGISTER_APIACTION(name, types, callback) \
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
||||||
|
|
||||||
#include "remote/apifunction.hpp"
|
#include "remote/apifunction.hpp"
|
||||||
#include "base/singleton.hpp"
|
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
@ -23,8 +22,3 @@ void ApiFunction::Register(const String& name, const ApiFunction::Ptr& function)
|
|||||||
{
|
{
|
||||||
ApiFunctionRegistry::GetInstance()->Register(name, function);
|
ApiFunctionRegistry::GetInstance()->Register(name, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiFunctionRegistry *ApiFunctionRegistry::GetInstance()
|
|
||||||
{
|
|
||||||
return Singleton<ApiFunctionRegistry>::GetInstance();
|
|
||||||
}
|
|
||||||
|
@ -43,8 +43,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
class ApiFunctionRegistry : public Registry<ApiFunctionRegistry, ApiFunction::Ptr>
|
class ApiFunctionRegistry : public Registry<ApiFunctionRegistry, ApiFunction::Ptr>
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
static ApiFunctionRegistry *GetInstance();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_APIFUNCTION(name, ns, callback) \
|
#define REGISTER_APIFUNCTION(name, ns, callback) \
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "remote/eventqueue.hpp"
|
#include "remote/eventqueue.hpp"
|
||||||
#include "remote/filterutility.hpp"
|
#include "remote/filterutility.hpp"
|
||||||
#include "base/io-engine.hpp"
|
#include "base/io-engine.hpp"
|
||||||
#include "base/singleton.hpp"
|
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/utility.hpp"
|
#include "base/utility.hpp"
|
||||||
#include <boost/asio/spawn.hpp>
|
#include <boost/asio/spawn.hpp>
|
||||||
@ -127,11 +126,6 @@ void EventQueue::Register(const String& name, const EventQueue::Ptr& function)
|
|||||||
EventQueueRegistry::GetInstance()->Register(name, function);
|
EventQueueRegistry::GetInstance()->Register(name, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventQueueRegistry *EventQueueRegistry::GetInstance()
|
|
||||||
{
|
|
||||||
return Singleton<EventQueueRegistry>::GetInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::mutex EventsInbox::m_FiltersMutex;
|
std::mutex EventsInbox::m_FiltersMutex;
|
||||||
std::map<String, EventsInbox::Filter> EventsInbox::m_Filters ({{"", EventsInbox::Filter{1, Expression::Ptr()}}});
|
std::map<String, EventsInbox::Filter> EventsInbox::m_Filters ({{"", EventsInbox::Filter{1, Expression::Ptr()}}});
|
||||||
|
|
||||||
|
@ -61,8 +61,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
class EventQueueRegistry : public Registry<EventQueueRegistry, EventQueue::Ptr>
|
class EventQueueRegistry : public Registry<EventQueueRegistry, EventQueue::Ptr>
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
static EventQueueRegistry *GetInstance();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class EventType : uint_fast8_t
|
enum class EventType : uint_fast8_t
|
||||||
|
Loading…
x
Reference in New Issue
Block a user