From b1ddc71925cd61f1592330d56d92a6b57eb952dd Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 4 Nov 2013 23:14:34 +0100 Subject: [PATCH] Merge ReflectionObject methods into the Object class. Refs #4996 --- components/cluster/clusterlistener.h | 2 +- components/cluster/endpoint.h | 2 +- components/compat/checkresultreader.h | 2 +- components/compat/compatlogger.h | 2 +- components/compat/externalcommandlistener.h | 2 +- components/compat/statusdatawriter.h | 2 +- components/db_ido_mysql/idomysqlconnection.h | 2 +- components/db_ido_pgsql/idopgsqlconnection.h | 2 +- components/demo/demo.h | 2 +- components/livestatus/listener.h | 2 +- .../notification/notificationcomponent.h | 2 +- components/perfdata/graphitewriter.h | 2 +- components/perfdata/perfdatawriter.h | 2 +- lib/base/CMakeLists.txt | 12 ++-- lib/base/application.h | 2 +- lib/base/consolelogger.h | 2 +- lib/base/dynamicobject.cpp | 5 +- lib/base/dynamicobject.h | 17 +----- lib/base/dynamictype.cpp | 3 +- lib/base/filelogger.h | 2 +- lib/base/logger.h | 2 +- lib/base/object.cpp | 15 +++++ lib/base/object.h | 16 +++++ lib/base/script.h | 2 +- lib/base/serializer.cpp | 59 +++++++++++++++++++ .../{reflectionobject.cpp => serializer.h} | 50 ++++++---------- lib/base/streamlogger.h | 2 +- lib/base/sysloglogger.h | 2 +- lib/base/{reflectionobject.h => type.h} | 50 ++++------------ lib/db_ido/dbconnection.h | 2 +- lib/icinga/checkcommand.h | 2 +- lib/icinga/command.h | 2 +- lib/icinga/domain.h | 2 +- lib/icinga/eventcommand.h | 2 +- lib/icinga/host.h | 2 +- lib/icinga/hostgroup.h | 2 +- lib/icinga/icingaapplication.h | 2 +- lib/icinga/notification.h | 2 +- lib/icinga/notificationcommand.h | 2 +- lib/icinga/service.h | 2 +- lib/icinga/servicegroup.h | 2 +- lib/icinga/timeperiod.h | 2 +- lib/icinga/user.h | 2 +- lib/icinga/usergroup.h | 2 +- tools/mkclass/classcompiler.cpp | 45 +++++++------- 45 files changed, 191 insertions(+), 151 deletions(-) create mode 100644 lib/base/serializer.cpp rename lib/base/{reflectionobject.cpp => serializer.h} (61%) rename lib/base/{reflectionobject.h => type.h} (65%) diff --git a/components/cluster/clusterlistener.h b/components/cluster/clusterlistener.h index a5abcb4bf..ea6fc6289 100644 --- a/components/cluster/clusterlistener.h +++ b/components/cluster/clusterlistener.h @@ -39,7 +39,7 @@ namespace icinga /** * @ingroup cluster */ -class ClusterListener : public ReflectionObjectImpl +class ClusterListener : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(ClusterListener); diff --git a/components/cluster/endpoint.h b/components/cluster/endpoint.h index 50807b4a8..299223af0 100644 --- a/components/cluster/endpoint.h +++ b/components/cluster/endpoint.h @@ -35,7 +35,7 @@ class EndpointManager; * * @ingroup cluster */ -class Endpoint : public ReflectionObjectImpl +class Endpoint : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(Endpoint); diff --git a/components/compat/checkresultreader.h b/components/compat/checkresultreader.h index 939f7afcb..dd89d9ef8 100644 --- a/components/compat/checkresultreader.h +++ b/components/compat/checkresultreader.h @@ -32,7 +32,7 @@ namespace icinga * * @ingroup compat */ -class CheckResultReader : public ReflectionObjectImpl +class CheckResultReader : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(CheckResultReader); diff --git a/components/compat/compatlogger.h b/components/compat/compatlogger.h index 3dd72a821..b6595a8df 100644 --- a/components/compat/compatlogger.h +++ b/components/compat/compatlogger.h @@ -33,7 +33,7 @@ namespace icinga * * @ingroup compat */ -class CompatLogger : public ReflectionObjectImpl +class CompatLogger : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(CompatLogger); diff --git a/components/compat/externalcommandlistener.h b/components/compat/externalcommandlistener.h index e07b332b2..83a4f9568 100644 --- a/components/compat/externalcommandlistener.h +++ b/components/compat/externalcommandlistener.h @@ -33,7 +33,7 @@ namespace icinga /** * @ingroup compat */ -class ExternalCommandListener : public ReflectionObjectImpl +class ExternalCommandListener : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(ExternalCommandListener); diff --git a/components/compat/statusdatawriter.h b/components/compat/statusdatawriter.h index ba9e8c922..5ffd0340b 100644 --- a/components/compat/statusdatawriter.h +++ b/components/compat/statusdatawriter.h @@ -37,7 +37,7 @@ namespace icinga /** * @ingroup compat */ -class StatusDataWriter : public ReflectionObjectImpl +class StatusDataWriter : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(StatusDataWriter); diff --git a/components/db_ido_mysql/idomysqlconnection.h b/components/db_ido_mysql/idomysqlconnection.h index c9e36ccff..3ac475152 100644 --- a/components/db_ido_mysql/idomysqlconnection.h +++ b/components/db_ido_mysql/idomysqlconnection.h @@ -34,7 +34,7 @@ namespace icinga * * @ingroup ido */ -class IdoMysqlConnection : public ReflectionObjectImpl +class IdoMysqlConnection : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(IdoMysqlConnection); diff --git a/components/db_ido_pgsql/idopgsqlconnection.h b/components/db_ido_pgsql/idopgsqlconnection.h index 61583ce89..353517d72 100644 --- a/components/db_ido_pgsql/idopgsqlconnection.h +++ b/components/db_ido_pgsql/idopgsqlconnection.h @@ -34,7 +34,7 @@ namespace icinga * * @ingroup ido */ -class IdoPgsqlConnection : public ReflectionObjectImpl +class IdoPgsqlConnection : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(IdoPgsqlConnection); diff --git a/components/demo/demo.h b/components/demo/demo.h index 11537961c..390183a21 100644 --- a/components/demo/demo.h +++ b/components/demo/demo.h @@ -29,7 +29,7 @@ namespace icinga /** * @ingroup demo */ -class Demo : public ReflectionObjectImpl +class Demo : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(Demo); diff --git a/components/livestatus/listener.h b/components/livestatus/listener.h index e348f226f..a534bdeba 100644 --- a/components/livestatus/listener.h +++ b/components/livestatus/listener.h @@ -33,7 +33,7 @@ namespace livestatus /** * @ingroup livestatus */ -class LivestatusListener : public ReflectionObjectImpl +class LivestatusListener : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(LivestatusListener); diff --git a/components/notification/notificationcomponent.h b/components/notification/notificationcomponent.h index 1bb1ea6f0..c2217da85 100644 --- a/components/notification/notificationcomponent.h +++ b/components/notification/notificationcomponent.h @@ -31,7 +31,7 @@ namespace icinga /** * @ingroup notification */ -class NotificationComponent : public ReflectionObjectImpl +class NotificationComponent : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(NotificationComponent); diff --git a/components/perfdata/graphitewriter.h b/components/perfdata/graphitewriter.h index a17e8ed65..b99736338 100644 --- a/components/perfdata/graphitewriter.h +++ b/components/perfdata/graphitewriter.h @@ -35,7 +35,7 @@ namespace icinga * * @ingroup perfdata */ -class GraphiteWriter : public ReflectionObjectImpl +class GraphiteWriter : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(GraphiteWriter); diff --git a/components/perfdata/perfdatawriter.h b/components/perfdata/perfdatawriter.h index 8ae295fdb..00246c06b 100644 --- a/components/perfdata/perfdatawriter.h +++ b/components/perfdata/perfdatawriter.h @@ -34,7 +34,7 @@ namespace icinga * * @ingroup icinga */ -class PerfdataWriter : public ReflectionObjectImpl +class PerfdataWriter : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(PerfdataWriter); diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index f95b095ae..7a73a4b09 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -30,12 +30,12 @@ add_library(base SHARED dynamicobject.th dynamictype.cpp exception.cpp fifo.cpp filelogger.cpp filelogger.th logger.cpp logger.th netstring.cpp networkstream.cpp object.cpp objectlock.cpp process.cpp process-unix.cpp process-windows.cpp qstring.cpp - reflectionobject.cpp ringbuffer.cpp script.cpp script.th scriptfunction.cpp - scriptfunctionwrapper.cpp scriptinterpreter.cpp scriptlanguage.cpp - scriptvariable.cpp socket.cpp stacktrace.cpp stdiostream.cpp stream_bio.cpp - stream.cpp streamlogger.cpp streamlogger.th sysloglogger.cpp sysloglogger.th - tcpsocket.cpp threadpool.cpp timer.cpp tlsstream.cpp tlsutility.cpp - unixsocket.cpp utility.cpp value.cpp workqueue.cpp zlibstream.cpp + ringbuffer.cpp script.cpp script.th scriptfunction.cpp scriptfunctionwrapper.cpp + scriptinterpreter.cpp scriptlanguage.cpp scriptvariable.cpp serializer.cpp + socket.cpp stacktrace.cpp stdiostream.cpp stream_bio.cpp stream.cpp + streamlogger.cpp streamlogger.th sysloglogger.cpp sysloglogger.th tcpsocket.cpp + threadpool.cpp timer.cpp tlsstream.cpp tlsutility.cpp unixsocket.cpp + utility.cpp value.cpp workqueue.cpp zlibstream.cpp ) target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cJSON mmatch) diff --git a/lib/base/application.h b/lib/base/application.h index 7f6c483a5..19b64fb58 100644 --- a/lib/base/application.h +++ b/lib/base/application.h @@ -34,7 +34,7 @@ class Component; * * @ingroup base */ -class I2_BASE_API Application : public ReflectionObjectImpl { +class I2_BASE_API Application : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(Application); diff --git a/lib/base/consolelogger.h b/lib/base/consolelogger.h index 6fd7a7ff0..8e8306dca 100644 --- a/lib/base/consolelogger.h +++ b/lib/base/consolelogger.h @@ -31,7 +31,7 @@ namespace icinga * * @ingroup base */ -class I2_BASE_API ConsoleLogger : public ReflectionObjectImpl +class I2_BASE_API ConsoleLogger : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(ConsoleLogger); diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index f1ec498c5..46bdfe1fc 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -19,6 +19,7 @@ #include "base/dynamicobject.h" #include "base/dynamictype.h" +#include "base/serializer.h" #include "base/netstring.h" #include "base/registry.h" #include "base/stdiostream.h" @@ -220,7 +221,7 @@ void DynamicObject::DumpObjects(const String& filename, int attributeTypes) persistentObject->Set("type", type->GetName()); persistentObject->Set("name", object->GetName()); - Dictionary::Ptr update = object->Serialize(attributeTypes); + Dictionary::Ptr update = Serializer::Serialize(object, attributeTypes); if (!update) continue; @@ -279,7 +280,7 @@ void DynamicObject::RestoreObjects(const String& filename, int attributeTypes) if (object) { ASSERT(!object->IsActive()); Log(LogDebug, "base", "Restoring object '" + name + "' of type '" + type + "'."); - object->Deserialize(update, attributeTypes); + Serializer::Deserialize(object, update, attributeTypes); object->OnStateLoaded(); } diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index a2dcb4c26..df3baf724 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -34,17 +34,6 @@ namespace icinga class DynamicType; -/** - * The type of an attribute for a DynamicObject. - * - * @ingroup base - */ -enum AttributeType -{ - Attribute_State = FAState, - Attribute_Config = FAConfig -}; - enum DomainPriv { DomainPrivRead = (1<<0), @@ -58,7 +47,7 @@ enum DomainPriv * * @ingroup base */ -class I2_BASE_API DynamicObject : public ReflectionObjectImpl +class I2_BASE_API DynamicObject : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(DynamicObject); @@ -105,8 +94,8 @@ public: return dynamic_pointer_cast(object); } - static void DumpObjects(const String& filename, int attributeTypes = Attribute_State); - static void RestoreObjects(const String& filename, int attributeTypes = Attribute_State); + static void DumpObjects(const String& filename, int attributeTypes = FAState); + static void RestoreObjects(const String& filename, int attributeTypes = FAState); static void StopObjects(void); protected: diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 6059d8d31..f077de95c 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "base/dynamictype.h" +#include "base/serializer.h" #include "base/debug.h" #include "base/objectlock.h" @@ -138,7 +139,7 @@ DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUp DynamicObject::Ptr object = factory(); - object->Deserialize(serializedUpdate, Attribute_Config); + Serializer::Deserialize(object, serializedUpdate, FAConfig); return object; } diff --git a/lib/base/filelogger.h b/lib/base/filelogger.h index e1d138a0d..3e961f249 100644 --- a/lib/base/filelogger.h +++ b/lib/base/filelogger.h @@ -31,7 +31,7 @@ namespace icinga * * @ingroup base */ -class I2_BASE_API FileLogger : public ReflectionObjectImpl +class I2_BASE_API FileLogger : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(FileLogger); diff --git a/lib/base/logger.h b/lib/base/logger.h index 4098870c2..9f61dda5e 100644 --- a/lib/base/logger.h +++ b/lib/base/logger.h @@ -46,7 +46,7 @@ struct LogEntry { * * @ingroup base */ -class I2_BASE_API Logger : public ReflectionObjectImpl +class I2_BASE_API Logger : public ObjectImpl { public: DECLARE_PTR_TYPEDEFS(Logger); diff --git a/lib/base/object.cpp b/lib/base/object.cpp index ad3d2b7db..c232a07f2 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -69,3 +69,18 @@ Object::SharedPtrHolder::operator Value(void) const { return m_Object; } + +const Type *Object::GetReflectionType(void) const +{ + return NULL; +} + +void Object::SetField(int id, const Value& value) +{ + throw std::runtime_error("Invalid field ID."); +} + +Value Object::GetField(int id) const +{ + throw std::runtime_error("Invalid field ID."); +} diff --git a/lib/base/object.h b/lib/base/object.h index e4156c9b0..7dd38e718 100644 --- a/lib/base/object.h +++ b/lib/base/object.h @@ -48,6 +48,8 @@ class Value; typedef shared_ptr Ptr; \ typedef weak_ptr WeakPtr +class Type; + /** * Base class for all heap-allocated objects. At least one of its methods * has to be virtual for RTTI to work. @@ -62,6 +64,10 @@ public: Object(void); virtual ~Object(void); + virtual const Type *GetReflectionType(void) const; + virtual void SetField(int id, const Value& value); + virtual Value GetField(int id) const; + /** * Holds a shared pointer and provides support for implicit upcasts. * @@ -175,6 +181,16 @@ public: } }; +template +class TypeImpl +{ +}; + +template +class ObjectImpl +{ +}; + } #endif /* OBJECT_H */ diff --git a/lib/base/script.h b/lib/base/script.h index 4243a71ee..d14966863 100644 --- a/lib/base/script.h +++ b/lib/base/script.h @@ -33,7 +33,7 @@ class ScriptInterpreter; * * @ingroup base */ -class I2_BASE_API Script : public ReflectionObjectImpl