diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index e2b472022..9d806ca53 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -28,7 +28,6 @@ using namespace icinga; -REGISTER_NTYPE(CheckerComponent); REGISTER_TYPE(CheckerComponent); void CheckerComponent::Start(void) diff --git a/components/cluster/clusterlistener.cpp b/components/cluster/clusterlistener.cpp index 1ddd45b53..f064c2bcb 100644 --- a/components/cluster/clusterlistener.cpp +++ b/components/cluster/clusterlistener.cpp @@ -34,7 +34,6 @@ using namespace icinga; -REGISTER_NTYPE(ClusterListener); REGISTER_TYPE(ClusterListener); /** diff --git a/components/cluster/endpoint.cpp b/components/cluster/endpoint.cpp index b74aeddaf..396ecd751 100644 --- a/components/cluster/endpoint.cpp +++ b/components/cluster/endpoint.cpp @@ -28,7 +28,6 @@ using namespace icinga; -REGISTER_NTYPE(Endpoint); REGISTER_TYPE(Endpoint); boost::signals2::signal Endpoint::OnConnected; diff --git a/components/compat/checkresultreader.cpp b/components/compat/checkresultreader.cpp index 6c7e1eccf..1059314ef 100644 --- a/components/compat/checkresultreader.cpp +++ b/components/compat/checkresultreader.cpp @@ -30,7 +30,6 @@ using namespace icinga; -REGISTER_NTYPE(CheckResultReader); REGISTER_TYPE(CheckResultReader); /** diff --git a/components/compat/compatlogger.cpp b/components/compat/compatlogger.cpp index 315ee184a..2574a75fc 100644 --- a/components/compat/compatlogger.cpp +++ b/components/compat/compatlogger.cpp @@ -39,7 +39,6 @@ using namespace icinga; -REGISTER_NTYPE(CompatLogger); REGISTER_TYPE(CompatLogger); REGISTER_SCRIPTFUNCTION(ValidateRotationMethod, &CompatLogger::ValidateRotationMethod); diff --git a/components/compat/externalcommandlistener.cpp b/components/compat/externalcommandlistener.cpp index c8b2fa6d9..599010588 100644 --- a/components/compat/externalcommandlistener.cpp +++ b/components/compat/externalcommandlistener.cpp @@ -27,7 +27,6 @@ using namespace icinga; -REGISTER_NTYPE(ExternalCommandListener); REGISTER_TYPE(ExternalCommandListener); /** diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index fedc15c9f..cb69a0998 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -41,7 +41,6 @@ using namespace icinga; -REGISTER_NTYPE(StatusDataWriter); REGISTER_TYPE(StatusDataWriter); /** diff --git a/components/db_ido_mysql/idomysqlconnection.cpp b/components/db_ido_mysql/idomysqlconnection.cpp index ac51cb8f1..cf80061d7 100644 --- a/components/db_ido_mysql/idomysqlconnection.cpp +++ b/components/db_ido_mysql/idomysqlconnection.cpp @@ -33,7 +33,6 @@ using namespace icinga; -REGISTER_NTYPE(IdoMysqlConnection); REGISTER_TYPE(IdoMysqlConnection); #define SCHEMA_VERSION "1.10.0" diff --git a/components/db_ido_pgsql/idopgsqlconnection.cpp b/components/db_ido_pgsql/idopgsqlconnection.cpp index b573a08bb..677771e8f 100644 --- a/components/db_ido_pgsql/idopgsqlconnection.cpp +++ b/components/db_ido_pgsql/idopgsqlconnection.cpp @@ -33,7 +33,6 @@ using namespace icinga; -REGISTER_NTYPE(IdoPgsqlConnection); REGISTER_TYPE(IdoPgsqlConnection); #define SCHEMA_VERSION "1.10.0" diff --git a/components/demo/demo.cpp b/components/demo/demo.cpp index 104f0f460..ad5446ce1 100644 --- a/components/demo/demo.cpp +++ b/components/demo/demo.cpp @@ -23,7 +23,6 @@ using namespace icinga; -REGISTER_NTYPE(Demo); REGISTER_TYPE(Demo); /** diff --git a/components/livestatus/listener.cpp b/components/livestatus/listener.cpp index 8ef222196..b77fd0272 100644 --- a/components/livestatus/listener.cpp +++ b/components/livestatus/listener.cpp @@ -34,7 +34,6 @@ using namespace icinga; using namespace livestatus; -REGISTER_NTYPE(LivestatusListener); REGISTER_TYPE(LivestatusListener); REGISTER_SCRIPTFUNCTION(ValidateSocketType, &LivestatusListener::ValidateSocketType); diff --git a/components/notification/notificationcomponent.cpp b/components/notification/notificationcomponent.cpp index 3abfe672d..b3d3d108f 100644 --- a/components/notification/notificationcomponent.cpp +++ b/components/notification/notificationcomponent.cpp @@ -28,7 +28,6 @@ using namespace icinga; -REGISTER_NTYPE(NotificationComponent); REGISTER_TYPE(NotificationComponent); /** diff --git a/components/perfdata/graphitewriter.cpp b/components/perfdata/graphitewriter.cpp index edeeb734f..c82c70382 100644 --- a/components/perfdata/graphitewriter.cpp +++ b/components/perfdata/graphitewriter.cpp @@ -42,7 +42,6 @@ using namespace icinga; -REGISTER_NTYPE(GraphiteWriter); REGISTER_TYPE(GraphiteWriter); void GraphiteWriter::Start(void) diff --git a/components/perfdata/perfdatawriter.cpp b/components/perfdata/perfdatawriter.cpp index 14aee6d58..4a88cd71c 100644 --- a/components/perfdata/perfdatawriter.cpp +++ b/components/perfdata/perfdatawriter.cpp @@ -30,7 +30,6 @@ using namespace icinga; -REGISTER_NTYPE(PerfdataWriter); REGISTER_TYPE(PerfdataWriter); void PerfdataWriter::Start(void) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 32ba6c1b8..8315a6b60 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -43,7 +43,7 @@ using namespace icinga; -REGISTER_NTYPE(Application); +REGISTER_TYPE(Application); Application *Application::m_Instance = NULL; bool Application::m_ShuttingDown = false; diff --git a/lib/base/consolelogger.cpp b/lib/base/consolelogger.cpp index 4d27b424b..3a47b3af2 100644 --- a/lib/base/consolelogger.cpp +++ b/lib/base/consolelogger.cpp @@ -23,7 +23,6 @@ using namespace icinga; -REGISTER_NTYPE(ConsoleLogger); REGISTER_TYPE(ConsoleLogger); /** diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 810a70ebc..ba7f52c08 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -37,7 +37,7 @@ using namespace icinga; -REGISTER_NTYPE(DynamicObject); +REGISTER_TYPE(DynamicObject); boost::signals2::signal DynamicObject::OnStarted; boost::signals2::signal DynamicObject::OnStopped; diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index fb8849b15..6a4b37d72 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -24,8 +24,8 @@ using namespace icinga; -DynamicType::DynamicType(const String& name, const DynamicType::ObjectFactory& factory) - : m_Name(name), m_ObjectFactory(factory) +DynamicType::DynamicType(const String& name) + : m_Name(name) { } DynamicType::Ptr DynamicType::GetByName(const String& name) @@ -34,8 +34,20 @@ DynamicType::Ptr DynamicType::GetByName(const String& name) DynamicType::TypeMap::const_iterator tt = InternalGetTypeMap().find(name); - if (tt == InternalGetTypeMap().end()) - return DynamicType::Ptr(); + if (tt == InternalGetTypeMap().end()) { + const Type *type = Type::GetByName(name); + + if (!type || !GetType()->IsAssignableFrom(type) + || type->IsAbstract()) + return DynamicType::Ptr(); + + DynamicType::Ptr dtype = make_shared(name); + + InternalGetTypeMap()[type->GetName()] = dtype; + InternalGetTypeVector().push_back(dtype); + + return dtype; + } return tt->second; } @@ -112,36 +124,17 @@ DynamicObject::Ptr DynamicType::GetObject(const String& name) const return nt->second; } -void DynamicType::RegisterType(const DynamicType::Ptr& type) -{ - boost::mutex::scoped_lock lock(GetStaticMutex()); - - DynamicType::TypeMap::const_iterator tt = InternalGetTypeMap().find(type->GetName()); - - if (tt != InternalGetTypeMap().end()) - BOOST_THROW_EXCEPTION(std::runtime_error("Cannot register class for type '" + - type->GetName() + "': Objects of this type already exist.")); - - InternalGetTypeMap()[type->GetName()] = type; - InternalGetTypeVector().push_back(type); -} - DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUpdate) { ASSERT(!OwnsLock()); - ObjectFactory factory; + const Type *type = Type::GetByName(m_Name); - { - ObjectLock olock(this); - factory = m_ObjectFactory; - } - - DynamicObject::Ptr object = factory(); + Object::Ptr object = type->Instantiate(); Deserialize(object, serializedUpdate, FAConfig); - return object; + return dynamic_pointer_cast(object); } boost::mutex& DynamicType::GetStaticMutex(void) diff --git a/lib/base/dynamictype.h b/lib/base/dynamictype.h index 1737976c0..993e85d8a 100644 --- a/lib/base/dynamictype.h +++ b/lib/base/dynamictype.h @@ -36,16 +36,12 @@ class I2_BASE_API DynamicType : public Object public: DECLARE_PTR_TYPEDEFS(DynamicType); - typedef boost::function ObjectFactory; - - DynamicType(const String& name, const ObjectFactory& factory); + DynamicType(const String& name); String GetName(void) const; static DynamicType::Ptr GetByName(const String& name); - static void RegisterType(const DynamicType::Ptr& type); - DynamicObject::Ptr CreateObject(const Dictionary::Ptr& serializedUpdate); DynamicObject::Ptr GetObject(const String& name) const; @@ -72,7 +68,6 @@ public: private: String m_Name; - ObjectFactory m_ObjectFactory; typedef std::map ObjectMap; typedef std::vector ObjectVector; @@ -90,46 +85,6 @@ private: static std::vector GetObjects(const String& type); }; -/** - * A registry for DynamicType objects. - * - * @ingroup base - */ -class DynamicTypeRegistry : public Registry -{ }; - -/** - * Helper class for registering DynamicObject implementation classes. - * - * @ingroup base - */ -class RegisterTypeHelper -{ -public: - RegisterTypeHelper(const String& name, const DynamicType::ObjectFactory& factory) - { - DynamicType::Ptr type = make_shared(name, factory); - DynamicType::RegisterType(type); - } -}; - -/** - * Factory function for DynamicObject-based classes. - * - * @ingroup base - */ -template -shared_ptr DynamicObjectFactory(void) -{ - return make_shared(); -} - -#define REGISTER_TYPE_ALIAS(type, alias) \ - I2_EXPORT icinga::RegisterTypeHelper g_RegisterDT_ ## type(alias, DynamicObjectFactory); - -#define REGISTER_TYPE(type) \ - REGISTER_TYPE_ALIAS(type, #type) - } #endif /* DYNAMICTYPE_H */ diff --git a/lib/base/filelogger.cpp b/lib/base/filelogger.cpp index d00692ba4..0888e9008 100644 --- a/lib/base/filelogger.cpp +++ b/lib/base/filelogger.cpp @@ -23,7 +23,6 @@ using namespace icinga; -REGISTER_NTYPE(FileLogger); REGISTER_TYPE(FileLogger); /** diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 578aba2ab..e1c7a8983 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -29,7 +29,7 @@ using namespace icinga; -REGISTER_NTYPE(Logger); +REGISTER_TYPE(Logger); std::set Logger::m_Loggers; boost::mutex Logger::m_Mutex; diff --git a/lib/base/script.cpp b/lib/base/script.cpp index 9fe876599..1c0a7d74c 100644 --- a/lib/base/script.cpp +++ b/lib/base/script.cpp @@ -26,7 +26,6 @@ using namespace icinga; -REGISTER_NTYPE(Script); REGISTER_TYPE(Script); void Script::Start(void) diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index 9406cd6d2..6acc39e70 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -26,7 +26,7 @@ using namespace icinga; -REGISTER_NTYPE(StreamLogger); +REGISTER_TYPE(StreamLogger); boost::mutex StreamLogger::m_Mutex; diff --git a/lib/base/sysloglogger.cpp b/lib/base/sysloglogger.cpp index 6b5b093dd..a1517b64e 100644 --- a/lib/base/sysloglogger.cpp +++ b/lib/base/sysloglogger.cpp @@ -23,7 +23,6 @@ #ifndef _WIN32 using namespace icinga; -REGISTER_NTYPE(SyslogLogger); REGISTER_TYPE(SyslogLogger); /** diff --git a/lib/base/type.h b/lib/base/type.h index 9a2a0ee63..0588ef42f 100644 --- a/lib/base/type.h +++ b/lib/base/type.h @@ -95,7 +95,7 @@ struct FactoryHelper } }; -#define REGISTER_NTYPE(type) \ +#define REGISTER_TYPE(type) \ namespace { \ void RegisterType(void) \ { \ diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index ba9cfaf6c..e938249eb 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -31,7 +31,7 @@ using namespace icinga; -REGISTER_NTYPE(DbConnection); +REGISTER_TYPE(DbConnection); Timer::Ptr DbConnection::m_ProgramStatusTimer; diff --git a/lib/hello/hello.cpp b/lib/hello/hello.cpp index e6e86ebc5..7b483e431 100644 --- a/lib/hello/hello.cpp +++ b/lib/hello/hello.cpp @@ -23,7 +23,6 @@ using namespace icinga; -REGISTER_NTYPE(Hello); REGISTER_TYPE(Hello); /** diff --git a/lib/icinga/checkcommand.cpp b/lib/icinga/checkcommand.cpp index 53052f7c3..6767f91a5 100644 --- a/lib/icinga/checkcommand.cpp +++ b/lib/icinga/checkcommand.cpp @@ -22,7 +22,6 @@ using namespace icinga; -REGISTER_NTYPE(CheckCommand); REGISTER_TYPE(CheckCommand); Dictionary::Ptr CheckCommand::Execute(const Service::Ptr& service) diff --git a/lib/icinga/command.cpp b/lib/icinga/command.cpp index 38d328c5d..c063c140c 100644 --- a/lib/icinga/command.cpp +++ b/lib/icinga/command.cpp @@ -21,7 +21,7 @@ using namespace icinga; -REGISTER_NTYPE(Command); +REGISTER_TYPE(Command); bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const { diff --git a/lib/icinga/domain.cpp b/lib/icinga/domain.cpp index ff3601b04..3a049de02 100644 --- a/lib/icinga/domain.cpp +++ b/lib/icinga/domain.cpp @@ -22,7 +22,6 @@ using namespace icinga; -REGISTER_NTYPE(Domain); REGISTER_TYPE(Domain); int Domain::GetPrivileges(const String& instance) const diff --git a/lib/icinga/eventcommand.cpp b/lib/icinga/eventcommand.cpp index 9fcca2c36..76fbf5a16 100644 --- a/lib/icinga/eventcommand.cpp +++ b/lib/icinga/eventcommand.cpp @@ -22,7 +22,6 @@ using namespace icinga; -REGISTER_NTYPE(EventCommand); REGISTER_TYPE(EventCommand); void EventCommand::Execute(const Service::Ptr& service) diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index b0b7ff0b2..297c22a5e 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -38,7 +38,6 @@ using namespace icinga; -REGISTER_NTYPE(Host); REGISTER_TYPE(Host); void Host::Start(void) diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index 1d515bafa..108251463 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -27,7 +27,6 @@ using namespace icinga; -REGISTER_NTYPE(HostGroup); REGISTER_TYPE(HostGroup); std::set HostGroup::GetMembers(void) const diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index cd4d14d81..c0502a2c8 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -32,7 +32,6 @@ using namespace icinga; static Timer::Ptr l_RetentionTimer; -REGISTER_NTYPE(IcingaApplication); REGISTER_TYPE(IcingaApplication); INITIALIZE_ONCE(IcingaApplication, &IcingaApplication::StaticInitialize); diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 978d8d2ad..53e91413a 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -32,7 +32,6 @@ using namespace icinga; -REGISTER_NTYPE(Notification); REGISTER_TYPE(Notification); boost::signals2::signal Notification::OnNextNotificationChanged; diff --git a/lib/icinga/notificationcommand.cpp b/lib/icinga/notificationcommand.cpp index 1c2a03087..e9968a5b3 100644 --- a/lib/icinga/notificationcommand.cpp +++ b/lib/icinga/notificationcommand.cpp @@ -22,7 +22,6 @@ using namespace icinga; -REGISTER_NTYPE(NotificationCommand); REGISTER_TYPE(NotificationCommand); Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification, diff --git a/lib/icinga/perfdatavalue.cpp b/lib/icinga/perfdatavalue.cpp index 9d21344f0..9cc5fa00c 100644 --- a/lib/icinga/perfdatavalue.cpp +++ b/lib/icinga/perfdatavalue.cpp @@ -25,7 +25,7 @@ using namespace icinga; -REGISTER_NTYPE(PerfdataValue); +REGISTER_TYPE(PerfdataValue); PerfdataValue::PerfdataValue(void) { } diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index b091f5593..484c9abda 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -33,7 +33,6 @@ using namespace icinga; -REGISTER_NTYPE(Service); REGISTER_TYPE(Service); boost::signals2::signal Service::OnAcknowledgementSet; diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index a0a4a6f56..a81783c63 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -28,7 +28,6 @@ using namespace icinga; -REGISTER_NTYPE(ServiceGroup); REGISTER_TYPE(ServiceGroup); std::set ServiceGroup::GetMembers(void) const diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index 028c291f0..2c963e7ed 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -29,7 +29,6 @@ using namespace icinga; -REGISTER_NTYPE(TimePeriod); REGISTER_TYPE(TimePeriod); REGISTER_SCRIPTFUNCTION(EmptyTimePeriod, &TimePeriod::EmptyTimePeriodUpdate); REGISTER_SCRIPTFUNCTION(EvenMinutesTimePeriod, &TimePeriod::EvenMinutesTimePeriodUpdate); diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index e5214fbfb..7a8cddb13 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -25,7 +25,6 @@ using namespace icinga; -REGISTER_NTYPE(User); REGISTER_TYPE(User); void User::OnConfigLoaded(void) diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index 265da7edd..0278fb5e2 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -27,7 +27,6 @@ using namespace icinga; -REGISTER_NTYPE(UserGroup); REGISTER_TYPE(UserGroup); std::set UserGroup::GetMembers(void) const