From 7c990eff6e14e1fb02e7908491689d0e9b3bdbde Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 8 Nov 2013 16:06:59 +0100 Subject: [PATCH 1/8] Add missing copyrights. Refs #5036 --- lib/icinga/perfdatavalue.cpp | 19 +++++++++++++++++++ lib/icinga/perfdatavalue.h | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/icinga/perfdatavalue.cpp b/lib/icinga/perfdatavalue.cpp index 2830eb107..9d21344f0 100644 --- a/lib/icinga/perfdatavalue.cpp +++ b/lib/icinga/perfdatavalue.cpp @@ -1,3 +1,22 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + #include "icinga/perfdatavalue.h" #include "base/convert.h" #include diff --git a/lib/icinga/perfdatavalue.h b/lib/icinga/perfdatavalue.h index e57279a2a..a04de09f6 100644 --- a/lib/icinga/perfdatavalue.h +++ b/lib/icinga/perfdatavalue.h @@ -1,3 +1,22 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + #ifndef PERFDATAVALUE_H #define PERFDATAVALUE_H From e546cd854de6f88f0048aa823a6947f504551140 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 8 Nov 2013 16:07:21 +0100 Subject: [PATCH 2/8] Clean up the DynamicType class. Refs #5036 --- components/checker/checkercomponent.cpp | 1 - components/cluster/clusterlistener.cpp | 1 - components/cluster/endpoint.cpp | 1 - components/compat/checkresultreader.cpp | 1 - components/compat/compatlogger.cpp | 1 - components/compat/externalcommandlistener.cpp | 1 - components/compat/statusdatawriter.cpp | 1 - .../db_ido_mysql/idomysqlconnection.cpp | 1 - .../db_ido_pgsql/idopgsqlconnection.cpp | 1 - components/demo/demo.cpp | 1 - components/livestatus/listener.cpp | 1 - .../notification/notificationcomponent.cpp | 1 - components/perfdata/graphitewriter.cpp | 1 - components/perfdata/perfdatawriter.cpp | 1 - lib/base/application.cpp | 2 +- lib/base/consolelogger.cpp | 1 - lib/base/dynamicobject.cpp | 2 +- lib/base/dynamictype.cpp | 45 ++++++++---------- lib/base/dynamictype.h | 47 +------------------ lib/base/filelogger.cpp | 1 - lib/base/logger.cpp | 2 +- lib/base/script.cpp | 1 - lib/base/streamlogger.cpp | 2 +- lib/base/sysloglogger.cpp | 1 - lib/base/type.h | 2 +- lib/db_ido/dbconnection.cpp | 2 +- lib/hello/hello.cpp | 1 - lib/icinga/checkcommand.cpp | 1 - lib/icinga/command.cpp | 2 +- lib/icinga/domain.cpp | 1 - lib/icinga/eventcommand.cpp | 1 - lib/icinga/host.cpp | 1 - lib/icinga/hostgroup.cpp | 1 - lib/icinga/icingaapplication.cpp | 1 - lib/icinga/notification.cpp | 1 - lib/icinga/notificationcommand.cpp | 1 - lib/icinga/perfdatavalue.cpp | 2 +- lib/icinga/service.cpp | 1 - lib/icinga/servicegroup.cpp | 1 - lib/icinga/timeperiod.cpp | 1 - lib/icinga/user.cpp | 1 - lib/icinga/usergroup.cpp | 1 - 42 files changed, 28 insertions(+), 112 deletions(-) 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 From 98c3431ddaef018dd37bfc644eefda3fb87acfe5 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 8 Nov 2013 21:12:22 +0100 Subject: [PATCH 3/8] Add missing == operator for the Value class. Refs #5036 --- lib/base/value.cpp | 13 +++++++++++++ lib/base/value.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/lib/base/value.cpp b/lib/base/value.cpp index 8094fe6ea..5a6bfa9ea 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -198,6 +198,19 @@ ValueType Value::GetType(void) const return static_cast(m_Value.which()); } +bool Value::operator==(bool rhs) +{ + if (!IsScalar()) + return false; + + return static_cast(*this) == rhs; +} + +bool Value::operator!=(bool rhs) +{ + return !(*this == rhs); +} + bool Value::operator==(int rhs) { if (!IsScalar()) diff --git a/lib/base/value.h b/lib/base/value.h index 777b7d86f..ecac6ee86 100644 --- a/lib/base/value.h +++ b/lib/base/value.h @@ -73,6 +73,9 @@ public: operator double(void) const; operator String(void) const; + bool operator==(bool rhs); + bool operator!=(bool rhs); + bool operator==(int rhs); bool operator!=(int rhs); From 2a6151e935e30d27f3d6941f82e2fc6eb871234c Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 8 Nov 2013 21:12:47 +0100 Subject: [PATCH 4/8] Use anonymous namespaces for INITIALIZE_ONCE(). Refs #5036 --- lib/base/initialize.h | 6 ++++-- lib/base/type.h | 2 +- lib/db_ido/dbconnection.cpp | 2 +- lib/db_ido/dbobject.cpp | 2 +- lib/db_ido/servicedbobject.cpp | 2 +- lib/icinga/icingaapplication.cpp | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/base/initialize.h b/lib/base/initialize.h index 120b2bf2b..f465176dc 100644 --- a/lib/base/initialize.h +++ b/lib/base/initialize.h @@ -34,8 +34,10 @@ inline bool InitializeOnceHelper(InitializeFunc func) return true; } -#define INITIALIZE_ONCE(name, func) \ - I2_EXPORT bool l_InitializeOnce ## name(InitializeOnceHelper(func)) +#define INITIALIZE_ONCE(func) \ + namespace { \ + I2_EXPORT bool l_InitializeOnce(InitializeOnceHelper(func)); \ + } } diff --git a/lib/base/type.h b/lib/base/type.h index 0588ef42f..af82212b9 100644 --- a/lib/base/type.h +++ b/lib/base/type.h @@ -104,7 +104,7 @@ struct FactoryHelper icinga::Type::Register(GetType()); \ } \ \ - INITIALIZE_ONCE(type, RegisterType); \ + INITIALIZE_ONCE(RegisterType); \ } } diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index e938249eb..b20c6b27e 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -35,7 +35,7 @@ REGISTER_TYPE(DbConnection); Timer::Ptr DbConnection::m_ProgramStatusTimer; -INITIALIZE_ONCE(DbConnection, &DbConnection::StaticInitialize); +INITIALIZE_ONCE(&DbConnection::StaticInitialize); void DbConnection::Start(void) { diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index df7afaa8a..e85856c8a 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -32,7 +32,7 @@ using namespace icinga; boost::signals2::signal DbObject::OnQuery; -INITIALIZE_ONCE(DbObject, &DbObject::StaticInitialize); +INITIALIZE_ONCE(&DbObject::StaticInitialize); DbObject::DbObject(const shared_ptr& type, const String& name1, const String& name2) : m_Name1(name1), m_Name2(name2), m_Type(type), m_LastConfigUpdate(0), m_LastStatusUpdate(0) diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 6c9862db1..24611b8e9 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -38,7 +38,7 @@ using namespace icinga; REGISTER_DBTYPE(Service, "service", DbObjectTypeService, "service_object_id", ServiceDbObject); -INITIALIZE_ONCE(ServiceDbObject, &ServiceDbObject::StaticInitialize); +INITIALIZE_ONCE(&ServiceDbObject::StaticInitialize); void ServiceDbObject::StaticInitialize(void) { diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index c0502a2c8..abbd9da45 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -33,7 +33,7 @@ using namespace icinga; static Timer::Ptr l_RetentionTimer; REGISTER_TYPE(IcingaApplication); -INITIALIZE_ONCE(IcingaApplication, &IcingaApplication::StaticInitialize); +INITIALIZE_ONCE(&IcingaApplication::StaticInitialize); void IcingaApplication::StaticInitialize(void) { From ba6f64a0ec9a71e0f04d0c893539f1329f7d276c Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 8 Nov 2013 21:37:21 +0100 Subject: [PATCH 5/8] Remove GetType(). Refs #5036 --- lib/base/dynamictype.cpp | 2 +- lib/base/type.cpp | 3 ++- lib/base/type.h | 10 ++-------- test/base-type.cpp | 6 +++--- tools/mkclass/classcompiler.cpp | 7 +++---- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 6a4b37d72..eecdc2134 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -37,7 +37,7 @@ DynamicType::Ptr DynamicType::GetByName(const String& name) if (tt == InternalGetTypeMap().end()) { const Type *type = Type::GetByName(name); - if (!type || !GetType()->IsAssignableFrom(type) + if (!type || !Type::GetByName("DynamicObject")->IsAssignableFrom(type) || type->IsAbstract()) return DynamicType::Ptr(); diff --git a/lib/base/type.cpp b/lib/base/type.cpp index 7507fdddc..94f504316 100644 --- a/lib/base/type.cpp +++ b/lib/base/type.cpp @@ -54,9 +54,10 @@ Object::Ptr Type::Instantiate(void) const bool Type::IsAssignableFrom(const Type *other) const { - for (const Type *t = other; t; t = t->GetBaseType()) + for (const Type *t = other; t; t = t->GetBaseType()) { if (t == this) return true; + } return false; } diff --git a/lib/base/type.h b/lib/base/type.h index af82212b9..0821247b9 100644 --- a/lib/base/type.h +++ b/lib/base/type.h @@ -74,12 +74,6 @@ class TypeImpl { }; -template -Type *GetType(void) -{ - return TypeImpl::GetInstance(); -} - template shared_ptr ObjectFactory(void) { @@ -99,9 +93,9 @@ struct FactoryHelper namespace { \ void RegisterType(void) \ { \ - icinga::Type *t = icinga::GetType(); \ + icinga::Type *t = new TypeImpl(); \ t->SetFactory(FactoryHelper().GetFactory()); \ - icinga::Type::Register(GetType()); \ + icinga::Type::Register(t); \ } \ \ INITIALIZE_ONCE(RegisterType); \ diff --git a/test/base-type.cpp b/test/base-type.cpp index 47b160b02..820eb9a1a 100644 --- a/test/base-type.cpp +++ b/test/base-type.cpp @@ -32,15 +32,15 @@ BOOST_AUTO_TEST_SUITE(base_type) BOOST_AUTO_TEST_CASE(gettype) { - const Type *t = GetType(); + const Type *t = Type::GetByName("Application"); BOOST_CHECK(t); } BOOST_AUTO_TEST_CASE(assign) { - const Type *t1 = GetType(); - const Type *t2 = GetType(); + const Type *t1 = Type::GetByName("Application"); + const Type *t2 = Type::GetByName("DynamicObject"); BOOST_CHECK(t1->IsAssignableFrom(t1)); BOOST_CHECK(t2->IsAssignableFrom(t1)); diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index 3797a9ea8..9b750b3b1 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -88,7 +88,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp) /* TypeImpl */ std::cout << "template<>" << std::endl << "class TypeImpl<" << klass.Name << ">" - << " : public Type, public Singleton >" << std::endl + << " : public Type" << std::endl << "{" << std::endl << "public:" << std::endl; @@ -111,7 +111,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp) std::cout << "\t\t" << "return "; if (!klass.Parent.empty()) - std::cout << "Singleton >::GetInstance()"; + std::cout << "Type::GetByName(\"" << klass.Parent << "\")"; else std::cout << "NULL"; @@ -220,7 +220,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp) /* GetReflectionType */ std::cout << "\t" << "virtual const Type *GetReflectionType(void) const" << std::endl << "\t" << "{" << std::endl - << "\t\t" << "return TypeImpl<" << klass.Name << ">::GetInstance();" << std::endl + << "\t\t" << "return Type::GetByName(\"" << klass.Name << "\");" << std::endl << "\t" << "}" << std::endl << std::endl; if (!klass.Fields.empty()) { @@ -408,7 +408,6 @@ void ClassCompiler::CompileStream(const std::string& path, std::istream *stream) std::cout << "#include \"base/object.h\"" << std::endl << "#include \"base/type.h\"" << std::endl - << "#include \"base/singleton.h\"" << std::endl << "#include \"base/debug.h\"" << std::endl << "#include \"base/value.h\"" << std::endl << "#include \"base/array.h\"" << std::endl From 135c2b23093425ca85c3f8ca28885bc360c8ea6f Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 8 Nov 2013 21:45:27 +0100 Subject: [PATCH 6/8] Fix compiler warnings in auto-generated code. Refs #5036 --- tools/mkclass/classcompiler.cpp | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index 9b750b3b1..28892309e 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -168,25 +168,31 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp) std::cout << "\t\t" << "int real_id = id - " << "TypeImpl<" << klass.Parent << ">::StaticGetFieldCount();" << std::endl << "\t\t" << "if (real_id < 0) { return " << "TypeImpl<" << klass.Parent << ">::StaticGetFieldInfo(id); }" << std::endl; - std::cout << "\t\t" << "switch ("; + if (klass.Fields.size() > 0) { + std::cout << "\t\t" << "switch ("; - if (!klass.Parent.empty()) - std::cout << "real_id"; - else - std::cout << "id"; + if (!klass.Parent.empty()) + std::cout << "real_id"; + else + std::cout << "id"; - std::cout << ") {" << std::endl; + std::cout << ") {" << std::endl; - num = 0; - for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { - std::cout << "\t\t\t" << "case " << num << ":" << std::endl - << "\t\t\t\t" << "return Field(" << num << ", \"" << it->Name << "\", " << it->Attributes << ");" << std::endl; - num++; + num = 0; + for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { + std::cout << "\t\t\t" << "case " << num << ":" << std::endl + << "\t\t\t\t" << "return Field(" << num << ", \"" << it->Name << "\", " << it->Attributes << ");" << std::endl; + num++; + } + + std::cout << "\t\t\t" << "default:" << std::endl + << "\t\t"; } - std::cout << "\t\t\t" << "default:" << std::endl - << "\t\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl - << "\t\t" << "}" << std::endl; + std::cout << "\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl; + + if (klass.Fields.size() > 0) + std::cout << "\t\t" << "}" << std::endl; std::cout << "\t" << "}" << std::endl << std::endl; From 49435b80a3d9e74abbda984750a7bda8d59a7e59 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 8 Nov 2013 21:56:42 +0100 Subject: [PATCH 7/8] Fix unit tests. Refs #5036 --- test/CMakeLists.txt | 4 ++++ test/base-convert.cpp | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 946468a36..94c13a626 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,6 +47,10 @@ add_boost_test(base base_object/construct base_object/getself base_object/weak + base_serialize/scalar + base_serialize/array + base_serialize/dictionary + base_serialize/object base_shellescape/escape_basic base_shellescape/escape_quoted base_stacktrace/stacktrace diff --git a/test/base-convert.cpp b/test/base-convert.cpp index 4656d2327..1a7d889be 100644 --- a/test/base-convert.cpp +++ b/test/base-convert.cpp @@ -43,11 +43,8 @@ BOOST_AUTO_TEST_CASE(todouble) BOOST_AUTO_TEST_CASE(tostring) { BOOST_CHECK(Convert::ToString(7) == "7"); - BOOST_CHECK(Convert::ToString(7.3) == "7.3"); + BOOST_CHECK(Convert::ToString(7.5) == "7.5"); BOOST_CHECK(Convert::ToString("hello") == "hello"); - - Object::Ptr object = make_shared(); - BOOST_CHECK(Convert::ToString(object) == "Object of type 'icinga::Object'"); } BOOST_AUTO_TEST_CASE(tobool) From e525410b75589bb9d507c06d3299dd21315f5836 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 8 Nov 2013 21:52:42 +0100 Subject: [PATCH 8/8] Add missing new-line. Refs #5036 --- lib/icinga/service-event.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/icinga/service-event.cpp b/lib/icinga/service-event.cpp index 205a54e38..7b697b8c0 100644 --- a/lib/icinga/service-event.cpp +++ b/lib/icinga/service-event.cpp @@ -58,4 +58,4 @@ void Service::ExecuteEventHandler(void) ec->Execute(GetSelf()); OnEventCommandExecuted(GetSelf()); -} \ No newline at end of file +}