From db4b3b78d6b0cb6e703b362b8293e5b2f78efcce Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 26 Oct 2013 09:41:45 +0200 Subject: [PATCH] Implement class compiler. Refs #4963 --- .gitignore | 1 + components/checker/Makefile.am | 7 + components/checker/checkercomponent.ti | 10 + components/cluster/Makefile.am | 9 + components/cluster/clusterlistener.cpp | 101 +---- components/cluster/clusterlistener.h | 26 +- components/cluster/clusterlistener.ti | 18 + components/cluster/endpoint.cpp | 121 ------ components/cluster/endpoint.h | 42 +- components/cluster/endpoint.ti | 23 ++ components/compat/Makefile.am | 13 + components/compat/checkresultreader.cpp | 26 -- components/compat/checkresultreader.h | 11 +- components/compat/checkresultreader.ti | 14 + components/compat/compatlogger.cpp | 47 +-- components/compat/compatlogger.h | 13 +- components/compat/compatlogger.ti | 17 + components/compat/externalcommandlistener.cpp | 30 -- components/compat/externalcommandlistener.h | 11 +- components/compat/externalcommandlistener.ti | 14 + components/compat/statusdatawriter.cpp | 55 +-- components/compat/statusdatawriter.h | 13 +- components/compat/statusdatawriter.ti | 17 + components/db_ido_mysql/Makefile.am | 9 +- .../db_ido_mysql/idomysqlconnection.cpp | 54 +-- components/db_ido_mysql/idomysqlconnection.h | 15 +- components/db_ido_mysql/idomysqlconnection.ti | 19 + components/demo/Makefile.am | 7 + components/demo/demo.h | 4 +- components/demo/demo.ti | 10 + components/livestatus/Makefile.am | 7 + components/livestatus/commentstable.cpp | 3 - components/livestatus/downtimestable.cpp | 3 - components/livestatus/hoststable.cpp | 19 +- components/livestatus/listener.cpp | 57 --- components/livestatus/listener.h | 17 +- components/livestatus/listener.ti | 31 ++ components/livestatus/servicestable.cpp | 19 +- components/livestatus/statustable.cpp | 6 +- components/notification/Makefile.am | 7 + .../notification/notificationcomponent.h | 3 +- .../notification/notificationcomponent.ti | 10 + components/perfdata/Makefile.am | 9 + components/perfdata/graphitewriter.cpp | 37 +- components/perfdata/graphitewriter.h | 11 +- components/perfdata/graphitewriter.ti | 16 + components/perfdata/perfdatawriter.cpp | 56 --- components/perfdata/perfdatawriter.h | 17 +- components/perfdata/perfdatawriter.ti | 32 ++ configure.ac | 1 + doc/4.3-object-types.md | 2 +- icinga-app/icinga.cpp | 2 + icinga2.sln | 20 + lib/base/Makefile.am | 23 ++ lib/base/application.cpp | 11 + lib/base/application.h | 7 +- lib/base/application.ti | 10 + lib/base/base.vcxproj | 100 +++++ lib/base/base.vcxproj.filters | 56 +++ lib/base/consolelogger.h | 4 +- lib/base/consolelogger.ti | 10 + lib/base/debug.h | 31 +- lib/base/dynamicobject.cpp | 117 +----- lib/base/dynamicobject.h | 30 +- lib/base/dynamicobject.ti | 21 + lib/base/filelogger.cpp | 18 +- lib/base/filelogger.h | 11 +- lib/base/filelogger.ti | 11 + lib/base/logger.cpp | 18 +- lib/base/logger.h | 8 +- lib/base/logger.ti | 11 + lib/base/process-unix.cpp | 2 +- lib/base/reflectionobject.cpp | 54 +++ lib/base/reflectionobject.h | 76 ++++ lib/base/script.cpp | 34 -- lib/base/script.h | 14 +- lib/base/script.ti | 12 + lib/base/streamlogger.h | 10 +- lib/base/streamlogger.ti | 10 + lib/base/sysloglogger.h | 4 +- lib/base/sysloglogger.ti | 10 + lib/db_ido/Makefile.am | 7 + lib/db_ido/db_ido.vcxproj | 12 + lib/db_ido/db_ido.vcxproj.filters | 6 + lib/db_ido/dbconnection.cpp | 293 +++++--------- lib/db_ido/dbconnection.h | 58 +-- lib/db_ido/dbconnection.ti | 18 + lib/db_ido/servicedbobject.cpp | 8 +- lib/icinga/Makefile.am | 39 +- lib/icinga/checkcommand.h | 4 +- lib/icinga/checkcommand.ti | 10 + lib/icinga/command.cpp | 55 --- lib/icinga/command.h | 21 +- lib/icinga/command.ti | 17 + lib/icinga/compatutility.cpp | 4 +- lib/icinga/domain.cpp | 25 +- lib/icinga/domain.h | 12 +- lib/icinga/domain.ti | 11 + lib/icinga/eventcommand.h | 4 +- lib/icinga/eventcommand.ti | 10 + lib/icinga/host.cpp | 91 +---- lib/icinga/host.h | 50 +-- lib/icinga/host.ti | 45 +++ lib/icinga/hostgroup.cpp | 24 -- lib/icinga/hostgroup.h | 11 +- lib/icinga/hostgroup.ti | 13 + lib/icinga/icinga.vcxproj | 168 +++++++- lib/icinga/icinga.vcxproj.filters | 87 +++++ lib/icinga/icingaapplication.cpp | 75 +--- lib/icinga/icingaapplication.h | 18 +- lib/icinga/icingaapplication.ti | 15 + lib/icinga/notification.cpp | 140 +------ lib/icinga/notification.h | 32 +- lib/icinga/notification.ti | 31 ++ lib/icinga/notificationcommand.h | 4 +- lib/icinga/notificationcommand.ti | 10 + lib/icinga/pluginnotificationtask.cpp | 2 +- lib/icinga/service-check.cpp | 290 ++------------ lib/icinga/service-comment.cpp | 41 +- lib/icinga/service-downtime.cpp | 40 +- lib/icinga/service-event.cpp | 12 +- lib/icinga/service-flapping.cpp | 38 +- lib/icinga/service-notification.cpp | 19 +- lib/icinga/service.cpp | 235 +----------- lib/icinga/service.h | 158 +------- lib/icinga/service.ti | 134 +++++++ lib/icinga/servicegroup.cpp | 24 -- lib/icinga/servicegroup.h | 11 +- lib/icinga/servicegroup.ti | 13 + lib/icinga/timeperiod.cpp | 95 ++--- lib/icinga/timeperiod.h | 17 +- lib/icinga/timeperiod.ti | 17 + lib/icinga/user.cpp | 97 +---- lib/icinga/user.h | 28 +- lib/icinga/user.ti | 24 ++ lib/icinga/usergroup.cpp | 24 -- lib/icinga/usergroup.h | 11 +- lib/icinga/usergroup.ti | 13 + third-party/execvpe/execvpe.c | 2 +- third-party/execvpe/execvpe.h | 8 +- tools/Makefile.am | 1 + tools/mkclass/.gitignore | 5 + tools/mkclass/Makefile.am | 23 ++ tools/mkclass/base.int | 27 ++ tools/mkclass/class_lexer.ll | 144 +++++++ tools/mkclass/class_parser.yy | 310 +++++++++++++++ tools/mkclass/classcompiler.cpp | 358 ++++++++++++++++++ tools/mkclass/classcompiler.h | 150 ++++++++ tools/mkclass/icinga.int | 0 tools/mkclass/mkclass.cpp | 33 ++ tools/mkclass/mkclass.filters | 25 ++ tools/mkclass/mkclass.vcxproj | 222 +++++++++++ tools/mkclass/packages.config | 15 + 153 files changed, 3159 insertions(+), 2800 deletions(-) create mode 100644 components/checker/checkercomponent.ti create mode 100644 components/cluster/clusterlistener.ti create mode 100644 components/cluster/endpoint.ti create mode 100644 components/compat/checkresultreader.ti create mode 100644 components/compat/compatlogger.ti create mode 100644 components/compat/externalcommandlistener.ti create mode 100644 components/compat/statusdatawriter.ti create mode 100644 components/db_ido_mysql/idomysqlconnection.ti create mode 100644 components/demo/demo.ti create mode 100644 components/livestatus/listener.ti create mode 100644 components/notification/notificationcomponent.ti create mode 100644 components/perfdata/graphitewriter.ti create mode 100644 components/perfdata/perfdatawriter.ti create mode 100644 lib/base/application.ti create mode 100644 lib/base/consolelogger.ti create mode 100644 lib/base/dynamicobject.ti create mode 100644 lib/base/filelogger.ti create mode 100644 lib/base/logger.ti create mode 100644 lib/base/reflectionobject.cpp create mode 100644 lib/base/reflectionobject.h create mode 100644 lib/base/script.ti create mode 100644 lib/base/streamlogger.ti create mode 100644 lib/base/sysloglogger.ti create mode 100644 lib/db_ido/dbconnection.ti create mode 100644 lib/icinga/checkcommand.ti create mode 100644 lib/icinga/command.ti create mode 100644 lib/icinga/domain.ti create mode 100644 lib/icinga/eventcommand.ti create mode 100644 lib/icinga/host.ti create mode 100644 lib/icinga/hostgroup.ti create mode 100644 lib/icinga/icingaapplication.ti create mode 100644 lib/icinga/notification.ti create mode 100644 lib/icinga/notificationcommand.ti create mode 100644 lib/icinga/service.ti create mode 100644 lib/icinga/servicegroup.ti create mode 100644 lib/icinga/timeperiod.ti create mode 100644 lib/icinga/user.ti create mode 100644 lib/icinga/usergroup.ti create mode 100644 tools/mkclass/.gitignore create mode 100644 tools/mkclass/Makefile.am create mode 100644 tools/mkclass/base.int create mode 100644 tools/mkclass/class_lexer.ll create mode 100644 tools/mkclass/class_parser.yy create mode 100644 tools/mkclass/classcompiler.cpp create mode 100644 tools/mkclass/classcompiler.h create mode 100644 tools/mkclass/icinga.int create mode 100644 tools/mkclass/mkclass.cpp create mode 100644 tools/mkclass/mkclass.filters create mode 100644 tools/mkclass/mkclass.vcxproj create mode 100644 tools/mkclass/packages.config diff --git a/.gitignore b/.gitignore index a70e3e9fa..d0804d04d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ ipch *.gcda *.o *.a +*.th .deps *.in Makefile diff --git a/components/checker/Makefile.am b/components/checker/Makefile.am index 600edef70..22945b025 100644 --- a/components/checker/Makefile.am +++ b/components/checker/Makefile.am @@ -3,15 +3,22 @@ pkglib_LTLIBRARIES = \ libchecker.la +BUILT_SOURCES = \ + checkercomponent.th + CLEANFILES = \ checker-type.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + libchecker_la_SOURCES = \ checkercomponent.cpp \ checkercomponent.h \ + checkercomponent.th \ checker-type.conf libchecker_la_CPPFLAGS = \ diff --git a/components/checker/checkercomponent.ti b/components/checker/checkercomponent.ti new file mode 100644 index 000000000..38d38bd31 --- /dev/null +++ b/components/checker/checkercomponent.ti @@ -0,0 +1,10 @@ +#include "base/dynamicobject.h" + +namespace icinga +{ + +class CheckerComponent : DynamicObject +{ +}; + +} diff --git a/components/cluster/Makefile.am b/components/cluster/Makefile.am index f8a0cceb2..89eec5be8 100644 --- a/components/cluster/Makefile.am +++ b/components/cluster/Makefile.am @@ -3,18 +3,27 @@ pkglib_LTLIBRARIES = \ libcluster.la +BUILT_SOURCES = \ + clusterlistener.th \ + endpoint.th + CLEANFILES = \ cluster-type.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + libcluster_la_SOURCES = \ clusterlistener.cpp \ clusterlistener.h \ + clusterlistener.ti \ cluster-type.conf \ endpoint.cpp \ endpoint.h \ + endpoint.ti \ jsonrpc.cpp \ jsonrpc.h diff --git a/components/cluster/clusterlistener.cpp b/components/cluster/clusterlistener.cpp index 32828005b..9ece96ae5 100644 --- a/components/cluster/clusterlistener.cpp +++ b/components/cluster/clusterlistener.cpp @@ -51,16 +51,16 @@ void ClusterListener::Start(void) } /* set up SSL context */ - shared_ptr cert = GetX509Certificate(GetCertificateFile()); - m_Identity = GetCertificateCN(cert); - Log(LogInformation, "cluster", "My identity: " + m_Identity); + shared_ptr cert = GetX509Certificate(GetCertPath()); + SetIdentity(GetCertificateCN(cert)); + Log(LogInformation, "cluster", "My identity: " + GetIdentity()); Endpoint::Ptr self = Endpoint::GetByName(GetIdentity()); if (!self) BOOST_THROW_EXCEPTION(std::invalid_argument("No configuration available for the local endpoint.")); - m_SSLContext = MakeSSLContext(GetCertificateFile(), GetKeyFile(), GetCAFile()); + m_SSLContext = MakeSSLContext(GetCertPath(), GetKeyPath(), GetCaPath()); /* create the primary JSON-RPC listener */ if (!GetBindPort().IsEmpty()) @@ -127,62 +127,11 @@ void ClusterListener::Stop(void) RotateLogFile(); } -String ClusterListener::GetCertificateFile(void) const -{ - ObjectLock olock(this); - - return m_CertPath; -} - -String ClusterListener::GetKeyFile(void) const -{ - ObjectLock olock(this); - - return m_KeyPath; -} - -String ClusterListener::GetCAFile(void) const -{ - ObjectLock olock(this); - - return m_CAPath; -} - -String ClusterListener::GetBindHost(void) const -{ - ObjectLock olock(this); - - return m_BindHost; -} - -String ClusterListener::GetBindPort(void) const -{ - ObjectLock olock(this); - - return m_BindPort; -} - -Array::Ptr ClusterListener::GetPeers(void) const -{ - ObjectLock olock(this); - - return m_Peers; -} - shared_ptr ClusterListener::GetSSLContext(void) const { - ObjectLock olock(this); - return m_SSLContext; } -String ClusterListener::GetIdentity(void) const -{ - ObjectLock olock(this); - - return m_Identity; -} - /** * Creates a new JSON-RPC listener on the specified port. * @@ -270,7 +219,7 @@ void ClusterListener::PersistMessage(const Endpoint::Ptr& source, const Dictiona String json = Value(pmessage).Serialize(); NetString::WriteStringToStream(m_LogFile, json); m_LogMessageCount++; - m_LogMessageTimestamp = ts; + SetLogMessageTimestamp(ts); if (m_LogMessageCount > 50000) { CloseLogFile(); @@ -330,7 +279,7 @@ void ClusterListener::RelayMessage(const Endpoint::Ptr& source, const Dictionary { ObjectLock olock(endpoint); - if (!endpoint->IsSyncing()) + if (!endpoint->GetSyncing()) endpoint->SendMessage(message); } } @@ -361,7 +310,7 @@ void ClusterListener::OpenLogFile(void) m_LogFile = logStream; #endif /* HAVE_BIOZLIB */ m_LogMessageCount = 0; - m_LogMessageTimestamp = 0; + SetLogMessageTimestamp(0); } void ClusterListener::CloseLogFile(void) @@ -380,7 +329,7 @@ void ClusterListener::RotateLogFile(void) { ASSERT(OwnsLock()); - double ts = m_LogMessageTimestamp; + double ts = GetLogMessageTimestamp(); if (ts == 0) ts = Utility::GetTime(); @@ -1579,37 +1528,3 @@ bool ClusterListener::SupportsNotifications(void) return !type->GetObjects().empty() && IcingaApplication::GetInstance()->GetEnableNotifications(); } - -void ClusterListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("cert_path", m_CertPath); - bag->Set("key_path", m_KeyPath); - bag->Set("ca_path", m_CAPath); - bag->Set("bind_host", m_BindHost); - bag->Set("bind_port", m_BindPort); - bag->Set("peers", m_Peers); - } - - if (attributeTypes & Attribute_State) - bag->Set("log_message_timestamp", m_LogMessageTimestamp); -} - -void ClusterListener::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_CertPath = bag->Get("cert_path"); - m_KeyPath = bag->Get("key_path"); - m_CAPath = bag->Get("ca_path"); - m_BindHost = bag->Get("bind_host"); - m_BindPort = bag->Get("bind_port"); - m_Peers = bag->Get("peers"); - } - - if (attributeTypes & Attribute_State) - m_LogMessageTimestamp = bag->Get("log_message_timestamp"); -} diff --git a/components/cluster/clusterlistener.h b/components/cluster/clusterlistener.h index a057880c6..a5abcb4bf 100644 --- a/components/cluster/clusterlistener.h +++ b/components/cluster/clusterlistener.h @@ -20,6 +20,7 @@ #ifndef CLUSTERLISTENER_H #define CLUSTERLISTENER_H +#include "cluster/clusterlistener.th" #include "base/dynamicobject.h" #include "base/timer.h" #include "base/array.h" @@ -38,7 +39,7 @@ namespace icinga /** * @ingroup cluster */ -class ClusterListener : public DynamicObject +class ClusterListener : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(ClusterListener); @@ -47,31 +48,11 @@ public: virtual void Start(void); virtual void Stop(void); - String GetCertificateFile(void) const; - String GetKeyFile(void) const; - String GetCAFile(void) const; - String GetBindHost(void) const; - String GetBindPort(void) const; - Array::Ptr GetPeers(void) const; + shared_ptr GetSSLContext(void) const; String GetClusterDir(void) const; - shared_ptr GetSSLContext(void) const; - String GetIdentity(void) const; - -protected: - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_CertPath; - String m_KeyPath; - String m_CAPath; - String m_BindHost; - String m_BindPort; - Array::Ptr m_Peers; - shared_ptr m_SSLContext; - String m_Identity; WorkQueue m_RelayQueue; WorkQueue m_MessageQueue; @@ -100,7 +81,6 @@ private: void ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Ptr& stream); Stream::Ptr m_LogFile; - double m_LogMessageTimestamp; size_t m_LogMessageCount; void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr, const String& authority); diff --git a/components/cluster/clusterlistener.ti b/components/cluster/clusterlistener.ti new file mode 100644 index 000000000..420a39efa --- /dev/null +++ b/components/cluster/clusterlistener.ti @@ -0,0 +1,18 @@ +#include "base/dynamicobject.h" + +namespace icinga +{ + +class ClusterListener : DynamicObject +{ + [config] String cert_path; + [config] String key_path; + [config] String ca_path; + [config] String bind_host; + [config] String bind_port; + [config] Array::Ptr peers; + [state] double log_message_timestamp; + String identity; +}; + +} diff --git a/components/cluster/endpoint.cpp b/components/cluster/endpoint.cpp index 8ba326c79..18bf6ea43 100644 --- a/components/cluster/endpoint.cpp +++ b/components/cluster/endpoint.cpp @@ -34,10 +34,6 @@ REGISTER_TYPE(Endpoint); boost::signals2::signal Endpoint::OnConnected; boost::signals2::signal Endpoint::OnMessageReceived; -Endpoint::Endpoint(void) - : m_Syncing(false) -{ } - /** * Checks whether this endpoint is connected. * @@ -107,86 +103,6 @@ void Endpoint::MessageThreadProc(const Stream::Ptr& stream) } } -/** - * Gets the node address for this endpoint. - * - * @returns The node address (hostname). - */ -String Endpoint::GetHost(void) const -{ - return m_Host; -} - -/** - * Gets the service name for this endpoint. - * - * @returns The service name (port). - */ -String Endpoint::GetPort(void) const -{ - return m_Port; -} - -Array::Ptr Endpoint::GetConfigFiles(void) const -{ - return m_ConfigFiles; -} - -Array::Ptr Endpoint::GetAcceptConfig(void) const -{ - return m_AcceptConfig; -} - -double Endpoint::GetSeen(void) const -{ - return m_Seen; -} - -void Endpoint::SetSeen(double ts) -{ - m_Seen = ts; -} - -double Endpoint::GetLocalLogPosition(void) const -{ - return m_LocalLogPosition; -} - -void Endpoint::SetLocalLogPosition(double ts) -{ - m_LocalLogPosition = ts; -} - -double Endpoint::GetRemoteLogPosition(void) const -{ - return m_RemoteLogPosition; -} - -void Endpoint::SetRemoteLogPosition(double ts) -{ - m_RemoteLogPosition = ts; -} - -bool Endpoint::IsSyncing(void) const -{ - return m_Syncing; -} - -void Endpoint::SetSyncing(bool syncing) -{ - m_Syncing = syncing; -} - -Dictionary::Ptr Endpoint::GetFeatures(void) const -{ - return m_Features; -} - -void Endpoint::SetFeatures(const Dictionary::Ptr& features) -{ - m_Features = features; -} - bool Endpoint::HasFeature(const String& type) const { Dictionary::Ptr features = GetFeatures(); @@ -197,40 +113,3 @@ bool Endpoint::HasFeature(const String& type) const return features->Get(type); } -void Endpoint::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("host", m_Host); - bag->Set("port", m_Port); - bag->Set("config_files", m_ConfigFiles); - bag->Set("accept_config", m_AcceptConfig); - } - - if (attributeTypes & Attribute_State) { - bag->Set("seen", m_Seen); - bag->Set("local_log_position", m_LocalLogPosition); - bag->Set("remote_log_position", m_RemoteLogPosition); - bag->Set("features", m_Features); - } -} - -void Endpoint::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_Host = bag->Get("host"); - m_Port = bag->Get("port"); - m_ConfigFiles = bag->Get("config_files"); - m_AcceptConfig = bag->Get("accept_config"); - } - - if (attributeTypes & Attribute_State) { - m_Seen = bag->Get("seen"); - m_LocalLogPosition = bag->Get("local_log_position"); - m_RemoteLogPosition = bag->Get("remote_log_position"); - m_Features = bag->Get("features"); - } -} diff --git a/components/cluster/endpoint.h b/components/cluster/endpoint.h index 04e3a7490..50807b4a8 100644 --- a/components/cluster/endpoint.h +++ b/components/cluster/endpoint.h @@ -20,7 +20,7 @@ #ifndef ENDPOINT_H #define ENDPOINT_H -#include "base/dynamicobject.h" +#include "cluster/endpoint.th" #include "base/stream.h" #include "base/array.h" #include @@ -35,14 +35,12 @@ class EndpointManager; * * @ingroup cluster */ -class Endpoint : public DynamicObject +class Endpoint : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(Endpoint); DECLARE_TYPENAME(Endpoint); - Endpoint(void); - static boost::signals2::signal OnConnected; static boost::signals2::signal OnMessageReceived; @@ -53,46 +51,10 @@ public: void SendMessage(const Dictionary::Ptr& request); - String GetHost(void) const; - String GetPort(void) const; - Array::Ptr GetConfigFiles(void) const; - Array::Ptr GetAcceptConfig(void) const; - - double GetSeen(void) const; - void SetSeen(double ts); - - double GetLocalLogPosition(void) const; - void SetLocalLogPosition(double ts); - - double GetRemoteLogPosition(void) const; - void SetRemoteLogPosition(double ts); - - Dictionary::Ptr GetFeatures(void) const; - void SetFeatures(const Dictionary::Ptr& features); - bool HasFeature(const String& type) const; - bool IsSyncing(void) const; - void SetSyncing(bool syncing); - -protected: - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - Dictionary::Ptr m_Subscriptions; - String m_Host; - String m_Port; - Array::Ptr m_ConfigFiles; - Array::Ptr m_AcceptConfig; - Stream::Ptr m_Client; - double m_Seen; - double m_LocalLogPosition; - double m_RemoteLogPosition; - Dictionary::Ptr m_Features; - bool m_Syncing; - boost::thread m_Thread; void MessageThreadProc(const Stream::Ptr& stream); diff --git a/components/cluster/endpoint.ti b/components/cluster/endpoint.ti new file mode 100644 index 000000000..b54b464cb --- /dev/null +++ b/components/cluster/endpoint.ti @@ -0,0 +1,23 @@ +#include "base/dynamicobject.h" + +namespace icinga +{ + +class Endpoint : DynamicObject +{ + [config] String host; + [config] String port; + [config] Array::Ptr config_files; + [config] Array::Ptr accept_config; + + [state] double seen; + [state] double local_log_position; + [state] double remote_log_position; + [state] Dictionary::Ptr features; + + bool syncing { + default {{{ return false; }}} + }; +}; + +} diff --git a/components/compat/Makefile.am b/components/compat/Makefile.am index 030ca3c47..279689fe6 100644 --- a/components/compat/Makefile.am +++ b/components/compat/Makefile.am @@ -3,21 +3,34 @@ pkglib_LTLIBRARIES = \ libcompat.la +BUILT_SOURCES = \ + checkresultreader.th \ + externalcommandlistener.th \ + statusdatawriter.th \ + compatlogger.th + CLEANFILES = \ compat-type.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + libcompat_la_SOURCES = \ checkresultreader.cpp \ checkresultreader.h \ + checkresultreader.th \ externalcommandlistener.cpp \ externalcommandlistener.h \ + externalcommandlistener.th \ statusdatawriter.cpp \ statusdatawriter.h \ + statusdatawriter.th \ compatlogger.cpp \ compatlogger.h \ + compatlogger.th \ compat-type.conf libcompat_la_CPPFLAGS = \ diff --git a/components/compat/checkresultreader.cpp b/components/compat/checkresultreader.cpp index 55d680c6e..03df0211c 100644 --- a/components/compat/checkresultreader.cpp +++ b/components/compat/checkresultreader.cpp @@ -44,17 +44,6 @@ void CheckResultReader::Start(void) m_ReadTimer->Start(); } -/** - * @threadsafety Always. - */ -String CheckResultReader::GetSpoolDir(void) const -{ - if (!m_SpoolDir.IsEmpty()) - return m_SpoolDir; - else - return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/"; -} - /** * @threadsafety Always. */ @@ -134,18 +123,3 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const } } -void CheckResultReader::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) - bag->Set("spool_dir", m_SpoolDir); -} - -void CheckResultReader::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) - m_SpoolDir = bag->Get("spool_dir"); -} diff --git a/components/compat/checkresultreader.h b/components/compat/checkresultreader.h index a66aa4b44..939f7afcb 100644 --- a/components/compat/checkresultreader.h +++ b/components/compat/checkresultreader.h @@ -20,7 +20,7 @@ #ifndef CHECKRESULTREADER_H #define CHECKRESULTREADER_H -#include "base/dynamicobject.h" +#include "compat/checkresultreader.th" #include "base/timer.h" #include @@ -32,23 +32,16 @@ namespace icinga * * @ingroup compat */ -class CheckResultReader : public DynamicObject +class CheckResultReader : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(CheckResultReader); DECLARE_TYPENAME(CheckResultReader); - String GetSpoolDir(void) const; - protected: virtual void Start(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_SpoolDir; - Timer::Ptr m_ReadTimer; void ReadTimerHandler(void) const; void ProcessCheckResultFile(const String& path) const; diff --git a/components/compat/checkresultreader.ti b/components/compat/checkresultreader.ti new file mode 100644 index 000000000..6daee2df3 --- /dev/null +++ b/components/compat/checkresultreader.ti @@ -0,0 +1,14 @@ +#include "base/dynamicobject.h" +#include "base/application.h" + +namespace icinga +{ + +class CheckResultReader : DynamicObject +{ + [config] String spool_dir { + default {{{ return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/"; }}} + }; +}; + +} diff --git a/components/compat/compatlogger.cpp b/components/compat/compatlogger.cpp index 7ce65879c..82d0dbadc 100644 --- a/components/compat/compatlogger.cpp +++ b/components/compat/compatlogger.cpp @@ -67,28 +67,6 @@ void CompatLogger::Start(void) ScheduleNextRotation(); } -/** - * @threadsafety Always. - */ -String CompatLogger::GetLogDir(void) const -{ - if (!m_LogDir.IsEmpty()) - return m_LogDir; - else - return Application::GetLocalStateDir() + "/log/icinga2/compat"; -} - -/** - * @threadsafety Always. - */ -String CompatLogger::GetRotationMethod(void) const -{ - if (!m_RotationMethod.IsEmpty()) - return m_RotationMethod; - else - return "HOURLY"; -} - /** * @threadsafety Always. */ @@ -412,10 +390,8 @@ void CompatLogger::FlappingHandler(const Service::Ptr& service, FlappingState fl ObjectLock oLock(this); Flush(); } - } - void CompatLogger::ExternalCommandHandler(const String& command, const std::vector& arguments) { std::ostringstream msgbuf; @@ -496,7 +472,7 @@ void CompatLogger::ReopenFile(bool rotate) << host->GetName() << ";" << Host::StateToString(Host::CalculateState(hc->GetState(), reachable)) << ";" << Service::StateTypeToString(hc->GetStateType()) << ";" - << hc->GetCurrentCheckAttempt() << ";" + << hc->GetCheckAttempt() << ";" << ""; WriteLine(msgbuf.str()); @@ -514,7 +490,7 @@ void CompatLogger::ReopenFile(bool rotate) << service->GetShortName() << ";" << Service::StateToString(service->GetState()) << ";" << Service::StateTypeToString(service->GetStateType()) << ";" - << service->GetCurrentCheckAttempt() << ";" + << service->GetCheckAttempt() << ";" << ""; WriteLine(msgbuf.str()); @@ -599,22 +575,3 @@ void CompatLogger::ValidateRotationMethod(const String& location, const Dictiona } } -void CompatLogger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("log_dir", m_LogDir); - bag->Set("rotation_method", m_RotationMethod); - } -} - -void CompatLogger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_LogDir = bag->Get("log_dir"); - m_RotationMethod = bag->Get("rotation_method"); - } -} diff --git a/components/compat/compatlogger.h b/components/compat/compatlogger.h index 8b84ed390..5374e0982 100644 --- a/components/compat/compatlogger.h +++ b/components/compat/compatlogger.h @@ -20,8 +20,8 @@ #ifndef COMPATLOGGER_H #define COMPATLOGGER_H +#include "compat/compatlogger.th" #include "icinga/service.h" -#include "base/dynamicobject.h" #include "base/timer.h" #include @@ -33,7 +33,7 @@ namespace icinga * * @ingroup compat */ -class CompatLogger : public DynamicObject +class CompatLogger : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(CompatLogger); @@ -41,21 +41,12 @@ public: CompatLogger(void); - String GetLogDir(void) const; - String GetRotationMethod(void) const; - static void ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs); protected: virtual void Start(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_LogDir; - String m_RotationMethod; - double m_LastRotation; void WriteLine(const String& line); diff --git a/components/compat/compatlogger.ti b/components/compat/compatlogger.ti new file mode 100644 index 000000000..957ec3f3c --- /dev/null +++ b/components/compat/compatlogger.ti @@ -0,0 +1,17 @@ +#include "base/dynamicobject.h" +#include "base/application.h" + +namespace icinga +{ + +class CompatLogger : DynamicObject +{ + [config] String log_dir { + default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}} + }; + [config] String rotation_method { + default {{{ return "HOURLY"; }}} + }; +}; + +} diff --git a/components/compat/externalcommandlistener.cpp b/components/compat/externalcommandlistener.cpp index 22e62c735..599010588 100644 --- a/components/compat/externalcommandlistener.cpp +++ b/components/compat/externalcommandlistener.cpp @@ -42,20 +42,6 @@ void ExternalCommandListener::Start(void) #endif /* _WIN32 */ } -/** - * Retrieves the icinga.cmd path. - * - * @returns icinga.cmd path - */ -String ExternalCommandListener::GetCommandPath(void) const -{ - if (m_CommandPath.IsEmpty()) - return Application::GetLocalStateDir() + "/run/icinga2/cmd/icinga2.cmd"; - else - return m_CommandPath; -} - - #ifndef _WIN32 void ExternalCommandListener::CommandPipeThread(const String& commandPath) { @@ -143,19 +129,3 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath) } } #endif /* _WIN32 */ - -void ExternalCommandListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) - bag->Set("command_path", m_CommandPath); -} - -void ExternalCommandListener::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) - m_CommandPath = bag->Get("command_path"); -} diff --git a/components/compat/externalcommandlistener.h b/components/compat/externalcommandlistener.h index e4b468e90..e07b332b2 100644 --- a/components/compat/externalcommandlistener.h +++ b/components/compat/externalcommandlistener.h @@ -20,7 +20,7 @@ #ifndef EXTERNALCOMMANDLISTENER_H #define EXTERNALCOMMANDLISTENER_H -#include "base/dynamicobject.h" +#include "compat/externalcommandlistener.th" #include "base/objectlock.h" #include "base/timer.h" #include "base/utility.h" @@ -33,7 +33,7 @@ namespace icinga /** * @ingroup compat */ -class ExternalCommandListener : public DynamicObject +class ExternalCommandListener : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(ExternalCommandListener); @@ -41,19 +41,12 @@ public: protected: virtual void Start(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_CommandPath; - #ifndef _WIN32 boost::thread m_CommandThread; void CommandPipeThread(const String& commandPath); #endif /* _WIN32 */ - - String GetCommandPath(void) const; }; } diff --git a/components/compat/externalcommandlistener.ti b/components/compat/externalcommandlistener.ti new file mode 100644 index 000000000..70f9fd051 --- /dev/null +++ b/components/compat/externalcommandlistener.ti @@ -0,0 +1,14 @@ +#include "base/dynamicobject.h" +#include "base/application.h" + +namespace icinga +{ + +class ExternalCommandListener : DynamicObject +{ + [config] String command_path { + default {{{ return Application::GetLocalStateDir() + "/run/icinga2/cmd/icinga2.cmd"; }}} + }; +}; + +} diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index 4e0b1c8c6..72725b940 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -64,40 +64,11 @@ void StatusDataWriter::Start(void) m_StatusTimer->Reschedule(0); } -/** - * Retrieves the status.dat path. - * - * @returns statuspath from config, or static default - */ -String StatusDataWriter::GetStatusPath(void) const -{ - if (m_StatusPath.IsEmpty()) - return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; - else - return m_StatusPath; -} - -/** - * Retrieves the objects.cache path. - * - * @returns objectspath from config, or static default - */ -String StatusDataWriter::GetObjectsPath(void) const -{ - if (m_ObjectsPath.IsEmpty()) - return Application::GetLocalStateDir() + "/cache/icinga2/objects.cache"; - else - return m_ObjectsPath; -} - void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type) { Service::Ptr service; Dictionary::Ptr comments = owner->GetComments(); - if (!comments) - return; - Host::Ptr host = owner->GetHost(); if (!host) @@ -202,9 +173,6 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner Dictionary::Ptr downtimes = owner->GetDowntimes(); - if (!downtimes) - return; - ObjectLock olock(downtimes); String id; @@ -474,7 +442,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s << "\t" << "active_checks_enabled" << "\t" << (service->GetEnableActiveChecks() ? 1 : 0) << "\n" << "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n" << "\t" << "flap_detection_enabled" << "\t" << (service->GetEnableFlapping() ? 1 : 0) << "\n" - << "\t" << "is_volatile" << "\t" << (service->IsVolatile() ? 1 : 0) << "\n" + << "\t" << "is_volatile" << "\t" << (service->GetVolatile() ? 1 : 0) << "\n" << "\t" << "notifications_enabled" << "\t" << (service->GetEnableNotifications() ? 1 : 0) << "\n" << "\t" << "notification_options" << "\t" << "u,w,c,r" << "\n" << "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n" @@ -610,7 +578,7 @@ void StatusDataWriter::StatusTimerHandler(void) statusfp << "programstatus {" << "\n" << "\t" << "icinga_pid=" << Utility::GetPid() << "\n" << "\t" << "daemon_mode=1" << "\n" - << "\t" << "program_start=" << static_cast(IcingaApplication::GetInstance()->GetStartTime()) << "\n" + << "\t" << "program_start=" << static_cast(Application::GetStartTime()) << "\n" << "\t" << "active_service_checks_enabled=" << (IcingaApplication::GetInstance()->GetEnableChecks() ? 1 : 0) << "\n" << "\t" << "passive_service_checks_enabled=1" << "\n" << "\t" << "active_host_checks_enabled=1" << "\n" @@ -782,22 +750,3 @@ void StatusDataWriter::StatusTimerHandler(void) } } -void StatusDataWriter::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("status_path", m_StatusPath); - bag->Set("objects_path", m_ObjectsPath); - } -} - -void StatusDataWriter::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_StatusPath = bag->Get("status_path"); - m_ObjectsPath = bag->Get("objects_path"); - } -} diff --git a/components/compat/statusdatawriter.h b/components/compat/statusdatawriter.h index 2f63b12eb..ba9e8c922 100644 --- a/components/compat/statusdatawriter.h +++ b/components/compat/statusdatawriter.h @@ -20,11 +20,11 @@ #ifndef STATUSDATAWRITER_H #define STATUSDATAWRITER_H +#include "compat/statusdatawriter.th" #include "icinga/host.h" #include "icinga/service.h" #include "icinga/command.h" #include "icinga/compatutility.h" -#include "base/dynamicobject.h" #include "base/objectlock.h" #include "base/timer.h" #include "base/utility.h" @@ -37,7 +37,7 @@ namespace icinga /** * @ingroup compat */ -class StatusDataWriter : public DynamicObject +class StatusDataWriter : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(StatusDataWriter); @@ -45,18 +45,9 @@ public: protected: virtual void Start(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_StatusPath; - String m_ObjectsPath; - Timer::Ptr m_StatusTimer; - String GetStatusPath(void) const; - String GetObjectsPath(void) const; - void DumpCommand(std::ostream& fp, const Command::Ptr& command); void DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp); void DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type); diff --git a/components/compat/statusdatawriter.ti b/components/compat/statusdatawriter.ti new file mode 100644 index 000000000..ff6efb24d --- /dev/null +++ b/components/compat/statusdatawriter.ti @@ -0,0 +1,17 @@ +#include "base/dynamicobject.h" +#include "base/application.h" + +namespace icinga +{ + +class StatusDataWriter : DynamicObject +{ + [config] String status_path { + default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; }}} + }; + [config] String objects_path { + default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/objects.cache"; }}} + }; +}; + +} diff --git a/components/db_ido_mysql/Makefile.am b/components/db_ido_mysql/Makefile.am index 975215f34..6e8b8137c 100644 --- a/components/db_ido_mysql/Makefile.am +++ b/components/db_ido_mysql/Makefile.am @@ -8,16 +8,23 @@ SUBDIRS = \ pkglib_LTLIBRARIES = \ libdb_ido_mysql.la +BUILT_SOURCES = \ + idomysqlconnection.th + CLEANFILES = \ db_ido_mysql-type.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + libdb_ido_mysql_la_SOURCES = \ db_ido_mysql-type.conf \ idomysqlconnection.cpp \ - idomysqlconnection.h + idomysqlconnection.h \ + idomysqlconnection.ti libdb_ido_mysql_la_CPPFLAGS = \ $(LTDLINCL) \ diff --git a/components/db_ido_mysql/idomysqlconnection.cpp b/components/db_ido_mysql/idomysqlconnection.cpp index 332d12328..e380a26b4 100644 --- a/components/db_ido_mysql/idomysqlconnection.cpp +++ b/components/db_ido_mysql/idomysqlconnection.cpp @@ -22,6 +22,7 @@ #include "base/convert.h" #include "base/utility.h" #include "base/application.h" +#include "base/dynamictype.h" #include "db_ido/dbtype.h" #include "db_ido/dbvalue.h" #include "db_ido_mysql/idomysqlconnection.h" @@ -34,12 +35,13 @@ using namespace icinga; REGISTER_TYPE(IdoMysqlConnection); +#define SCHEMA_VERSION "1.10.0" + void IdoMysqlConnection::Start(void) { DbConnection::Start(); m_Connected = false; - m_RequiredSchemaVersion = "1.10.0"; m_TxTimer = boost::make_shared(); m_TxTimer->SetInterval(5); @@ -99,13 +101,13 @@ void IdoMysqlConnection::ReconnectTimerHandler(void) const char *host, *user , *passwd, *db; long port; - ihost = m_Host; - iuser = m_User; - ipasswd = m_Password; - idb = m_Database; + ihost = GetHost(); + iuser = GetUser(); + ipasswd = GetPassword(); + idb = GetDatabase(); host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL; - port = m_Port; + port = GetPort(); user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL; passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL; db = (!idb.IsEmpty()) ? idb.CStr() : NULL; @@ -127,20 +129,17 @@ void IdoMysqlConnection::ReconnectTimerHandler(void) Dictionary::Ptr version_row = version_rows->Get(0); String version = version_row->Get("version"); - if (Utility::CompareVersion(m_RequiredSchemaVersion, version) < 0) { + if (Utility::CompareVersion(SCHEMA_VERSION, version) < 0) { BOOST_THROW_EXCEPTION(std::runtime_error("Schema version '" + version + "' does not match the required version '" + - m_RequiredSchemaVersion + "'! Please check the upgrade documentation.")); + SCHEMA_VERSION + "'! Please check the upgrade documentation.")); } - String instanceName = "default"; - - if (!m_InstanceName.IsEmpty()) - instanceName = m_InstanceName; + String instanceName = GetInstanceName(); Array::Ptr rows = Query("SELECT instance_id FROM " + GetTablePrefix() + "instances WHERE instance_name = '" + Escape(instanceName) + "'"); if (rows->GetLength() == 0) { - Query("INSERT INTO " + GetTablePrefix() + "instances (instance_name, instance_description) VALUES ('" + Escape(instanceName) + "', '" + m_InstanceDescription + "')"); + Query("INSERT INTO " + GetTablePrefix() + "instances (instance_name, instance_description) VALUES ('" + Escape(instanceName) + "', '" + Escape(GetInstanceDescription()) + "')"); m_InstanceID = GetLastInsertID(); } else { Dictionary::Ptr row = rows->Get(0); @@ -539,32 +538,3 @@ void IdoMysqlConnection::CleanUpExecuteQuery(const String& table, const String& "(time_value)) + ")"); } -void IdoMysqlConnection::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DbConnection::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("host", m_Host); - bag->Set("port", m_Port); - bag->Set("user", m_User); - bag->Set("password", m_Password); - bag->Set("database", m_Database); - bag->Set("instance_name", m_InstanceName); - bag->Set("instance_description", m_InstanceDescription); - } -} - -void IdoMysqlConnection::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DbConnection::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_Host = bag->Get("host"); - m_Port = bag->Get("port"); - m_User = bag->Get("user"); - m_Password = bag->Get("password"); - m_Database = bag->Get("database"); - m_InstanceName = bag->Get("instance_name"); - m_InstanceDescription = bag->Get("instance_description"); - } -} diff --git a/components/db_ido_mysql/idomysqlconnection.h b/components/db_ido_mysql/idomysqlconnection.h index 2eca680c6..876fef840 100644 --- a/components/db_ido_mysql/idomysqlconnection.h +++ b/components/db_ido_mysql/idomysqlconnection.h @@ -20,10 +20,9 @@ #ifndef IDOMYSQLCONNECTION_H #define IDOMYSQLCONNECTION_H +#include "db_ido_mysql/idomysqlconnection.th" #include "base/array.h" -#include "base/dynamictype.h" #include "base/timer.h" -#include "db_ido/dbconnection.h" #include namespace icinga @@ -34,7 +33,7 @@ namespace icinga * * @ingroup ido */ -class IdoMysqlConnection : public DbConnection +class IdoMysqlConnection : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(IdoMysqlConnection); @@ -54,14 +53,6 @@ protected: virtual void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value); private: - String m_Host; - Value m_Port; - String m_User; - String m_Password; - String m_Database; - String m_InstanceName; - String m_InstanceDescription; - DbReference m_InstanceID; DbReference m_LastNotificationID; @@ -69,8 +60,6 @@ private: bool m_Connected; MYSQL m_Connection; - String m_RequiredSchemaVersion; - Timer::Ptr m_ReconnectTimer; Timer::Ptr m_TxTimer; diff --git a/components/db_ido_mysql/idomysqlconnection.ti b/components/db_ido_mysql/idomysqlconnection.ti new file mode 100644 index 000000000..202a20af8 --- /dev/null +++ b/components/db_ido_mysql/idomysqlconnection.ti @@ -0,0 +1,19 @@ +#include "db_ido/dbconnection.h" + +namespace icinga +{ + +class IdoMysqlConnection : DbConnection +{ + [config] String host; + [config] int port; + [config] String user; + [config] String password; + [config] String database; + [config] String instance_name { + default {{{ return "default"; }}} + }; + [config] String instance_description; +}; + +} diff --git a/components/demo/Makefile.am b/components/demo/Makefile.am index df5e5963e..3151556ea 100644 --- a/components/demo/Makefile.am +++ b/components/demo/Makefile.am @@ -3,15 +3,22 @@ pkglib_LTLIBRARIES = \ libdemo.la +BUILT_SOURCES = \ + demo.th + CLEANFILES = \ demo-type.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + libdemo_la_SOURCES = \ demo.cpp \ demo.h \ + demo.ti \ demo-type.conf libdemo_la_CPPFLAGS = \ diff --git a/components/demo/demo.h b/components/demo/demo.h index 860ae2272..11537961c 100644 --- a/components/demo/demo.h +++ b/components/demo/demo.h @@ -20,7 +20,7 @@ #ifndef DEMO_H #define DEMO_H -#include "base/dynamicobject.h" +#include "demo/demo.th" #include "base/timer.h" namespace icinga @@ -29,7 +29,7 @@ namespace icinga /** * @ingroup demo */ -class Demo : public DynamicObject +class Demo : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(Demo); diff --git a/components/demo/demo.ti b/components/demo/demo.ti new file mode 100644 index 000000000..71e14d487 --- /dev/null +++ b/components/demo/demo.ti @@ -0,0 +1,10 @@ +#include "base/dynamicobject.h" + +namespace icinga +{ + +class Demo : DynamicObject +{ +}; + +} diff --git a/components/livestatus/Makefile.am b/components/livestatus/Makefile.am index a986bbe54..91775b984 100644 --- a/components/livestatus/Makefile.am +++ b/components/livestatus/Makefile.am @@ -3,12 +3,18 @@ pkglib_LTLIBRARIES = \ liblivestatus.la +BUILT_SOURCES = \ + listener.th + CLEANFILES = \ livestatus-type.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + liblivestatus_la_SOURCES = \ aggregator.cpp \ aggregator.h \ @@ -46,6 +52,7 @@ liblivestatus_la_SOURCES = \ invsumaggregator.h \ listener.cpp \ listener.h \ + listener.ti \ livestatus-type.conf \ logtable.cpp \ logtable.h \ diff --git a/components/livestatus/commentstable.cpp b/components/livestatus/commentstable.cpp index b95e8aac8..f261911f2 100644 --- a/components/livestatus/commentstable.cpp +++ b/components/livestatus/commentstable.cpp @@ -61,9 +61,6 @@ void CommentsTable::FetchRows(const AddRowFunction& addRowFn) BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { Dictionary::Ptr comments = service->GetComments(); - if (!comments) - continue; - ObjectLock olock(comments); String id; diff --git a/components/livestatus/downtimestable.cpp b/components/livestatus/downtimestable.cpp index 6a901b0cb..adb991719 100644 --- a/components/livestatus/downtimestable.cpp +++ b/components/livestatus/downtimestable.cpp @@ -61,9 +61,6 @@ void DowntimesTable::FetchRows(const AddRowFunction& addRowFn) BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects()) { Dictionary::Ptr downtimes = service->GetDowntimes(); - if (!downtimes) - continue; - ObjectLock olock(downtimes); String id; diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 893b996a3..64262e746 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -604,7 +604,7 @@ Value HostsTable::CurrentAttemptAccessor(const Value& row) if (!hc) return Empty; - return hc->GetCurrentCheckAttempt(); + return hc->GetCheckAttempt(); } Value HostsTable::LastNotificationAccessor(const Value& row) @@ -761,7 +761,7 @@ Value HostsTable::NoMoreNotificationsAccessor(const Value& row) notification_interval = notification->GetNotificationInterval(); } - if (notification_interval == 0 && !hc->IsVolatile()) + if (notification_interval == 0 && !hc->GetVolatile()) return 1; return 0; @@ -1054,9 +1054,6 @@ Value HostsTable::DowntimesAccessor(const Value& row) Dictionary::Ptr downtimes = hc->GetDowntimes(); - if (!downtimes) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(downtimes); @@ -1087,9 +1084,6 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row) Dictionary::Ptr downtimes = hc->GetDowntimes(); - if (!downtimes) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(downtimes); @@ -1124,9 +1118,6 @@ Value HostsTable::CommentsAccessor(const Value& row) Dictionary::Ptr comments = hc->GetComments(); - if (!comments) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(comments); @@ -1157,9 +1148,6 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row) Dictionary::Ptr comments = hc->GetComments(); - if (!comments) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(comments); @@ -1194,9 +1182,6 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row) Dictionary::Ptr comments = hc->GetComments(); - if (!comments) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(comments); diff --git a/components/livestatus/listener.cpp b/components/livestatus/listener.cpp index 88473ad7b..a508a4697 100644 --- a/components/livestatus/listener.cpp +++ b/components/livestatus/listener.cpp @@ -83,40 +83,6 @@ void LivestatusListener::Start(void) } } -String LivestatusListener::GetSocketType(void) const -{ - Value socketType = m_SocketType; - if (socketType.IsEmpty()) - return "unix"; - else - return socketType; -} - -String LivestatusListener::GetSocketPath(void) const -{ - Value socketPath = m_SocketPath; - if (socketPath.IsEmpty()) - return Application::GetLocalStateDir() + "/run/icinga2/cmd/livestatus"; - else - return socketPath; -} - -String LivestatusListener::GetBindHost(void) const -{ - if (m_BindHost.IsEmpty()) - return "127.0.0.1"; - else - return m_BindHost; -} - -String LivestatusListener::GetBindPort(void) const -{ - if (m_BindPort.IsEmpty()) - return "6558"; - else - return m_BindPort; -} - int LivestatusListener::GetClientsConnected(void) { boost::mutex::scoped_lock lock(l_ComponentMutex); @@ -189,26 +155,3 @@ void LivestatusListener::ValidateSocketType(const String& location, const Dictio } } -void LivestatusListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("socket_type", m_SocketType); - bag->Set("socket_path", m_SocketPath); - bag->Set("bind_host", m_BindHost); - bag->Set("bind_port", m_BindPort); - } -} - -void LivestatusListener::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_SocketType = bag->Get("socket_type"); - m_SocketPath = bag->Get("socket_path"); - m_BindHost = bag->Get("bind_host"); - m_BindPort = bag->Get("bind_port"); - } -} diff --git a/components/livestatus/listener.h b/components/livestatus/listener.h index a181c4f3e..e348f226f 100644 --- a/components/livestatus/listener.h +++ b/components/livestatus/listener.h @@ -20,8 +20,8 @@ #ifndef LIVESTATUSLISTENER_H #define LIVESTATUSLISTENER_H +#include "livestatus/listener.th" #include "livestatus/query.h" -#include "base/dynamicobject.h" #include "base/socket.h" #include @@ -33,16 +33,11 @@ namespace livestatus /** * @ingroup livestatus */ -class LivestatusListener : public DynamicObject +class LivestatusListener : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(LivestatusListener); - String GetSocketType(void) const; - String GetSocketPath(void) const; - String GetBindHost(void) const; - String GetBindPort(void) const; - static int GetClientsConnected(void); static int GetConnections(void); @@ -51,15 +46,7 @@ public: protected: virtual void Start(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_SocketType; - String m_SocketPath; - String m_BindHost; - String m_BindPort; - void ServerThreadProc(const Socket::Ptr& server); void ClientThreadProc(const Socket::Ptr& client); }; diff --git a/components/livestatus/listener.ti b/components/livestatus/listener.ti new file mode 100644 index 000000000..7f7c8455d --- /dev/null +++ b/components/livestatus/listener.ti @@ -0,0 +1,31 @@ +#include "base/dynamicobject.h" +#include "base/application.h" + +namespace livestatus +{ + +code {{{ +class LivestatusListener; +}}} + +} + +namespace icinga +{ + +class livestatus::LivestatusListener : DynamicObject { + [config] String socket_type { + default {{{ return "unix"; }}} + }; + [config] String socket_path { + default {{{ return Application::GetLocalStateDir() + "/run/icinga2/cmd/livestatus"; }}} + }; + [config] String bind_host { + default {{{ return "127.0.0.1"; }}} + }; + [config] String bind_port { + default {{{ return "6558"; }}} + }; +}; + +} diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index 328557ab6..bee708cbd 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -407,7 +407,7 @@ Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row) Value ServicesTable::CurrentAttemptAccessor(const Value& row) { - return static_cast(row)->GetCurrentCheckAttempt(); + return static_cast(row)->GetCheckAttempt(); } Value ServicesTable::StateAccessor(const Value& row) @@ -471,7 +471,7 @@ Value ServicesTable::NoMoreNotificationsAccessor(const Value& row) notification_interval = notification->GetNotificationInterval(); } - if (notification_interval == 0 && !service->IsVolatile()) + if (notification_interval == 0 && !service->GetVolatile()) return 1; return 0; @@ -731,9 +731,6 @@ Value ServicesTable::DowntimesAccessor(const Value& row) { Dictionary::Ptr downtimes = static_cast(row)->GetDowntimes(); - if (!downtimes) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(downtimes); @@ -758,9 +755,6 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row) { Dictionary::Ptr downtimes = static_cast(row)->GetDowntimes(); - if (!downtimes) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(downtimes); @@ -789,9 +783,6 @@ Value ServicesTable::CommentsAccessor(const Value& row) { Dictionary::Ptr comments = static_cast(row)->GetComments(); - if (!comments) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(comments); @@ -816,9 +807,6 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row) { Dictionary::Ptr comments = static_cast(row)->GetComments(); - if (!comments) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(comments); @@ -847,9 +835,6 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row) { Dictionary::Ptr comments = static_cast(row)->GetComments(); - if (!comments) - return Empty; - Array::Ptr ids = boost::make_shared(); ObjectLock olock(comments); diff --git a/components/livestatus/statustable.cpp b/components/livestatus/statustable.cpp index 1be42ebc1..58d94395b 100644 --- a/components/livestatus/statustable.cpp +++ b/components/livestatus/statustable.cpp @@ -120,7 +120,7 @@ Value StatusTable::ConnectionsAccessor(const Value& row) Value StatusTable::ConnectionsRateAccessor(const Value& row) { - return (LivestatusListener::GetConnections() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime())); + return (LivestatusListener::GetConnections() / (Utility::GetTime() - Application::GetStartTime())); } Value StatusTable::ExternalCommandsAccessor(const Value& row) @@ -130,7 +130,7 @@ Value StatusTable::ExternalCommandsAccessor(const Value& row) Value StatusTable::ExternalCommandsRateAccessor(const Value& row) { - return (Query::GetExternalCommands() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime())); + return (Query::GetExternalCommands() / (Utility::GetTime() - Application::GetStartTime())); } Value StatusTable::NagiosPidAccessor(const Value& row) @@ -140,7 +140,7 @@ Value StatusTable::NagiosPidAccessor(const Value& row) Value StatusTable::ProgramStartAccessor(const Value& row) { - return static_cast(IcingaApplication::GetInstance()->GetStartTime()); + return Application::GetStartTime(); } Value StatusTable::NumHostsAccessor(const Value& row) diff --git a/components/notification/Makefile.am b/components/notification/Makefile.am index 11864fa5c..69134f368 100644 --- a/components/notification/Makefile.am +++ b/components/notification/Makefile.am @@ -3,15 +3,22 @@ pkglib_LTLIBRARIES = \ libnotification.la +BUILT_SOURCES = \ + notificationcomponent.th + CLEANFILES = \ notification-type.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + libnotification_la_SOURCES = \ notificationcomponent.cpp \ notificationcomponent.h \ + notificationcomponent.ti \ notification-type.conf libnotification_la_CPPFLAGS = \ diff --git a/components/notification/notificationcomponent.h b/components/notification/notificationcomponent.h index 90a515710..1bb1ea6f0 100644 --- a/components/notification/notificationcomponent.h +++ b/components/notification/notificationcomponent.h @@ -20,6 +20,7 @@ #ifndef NOTIFICATIONCOMPONENT_H #define NOTIFICATIONCOMPONENT_H +#include "notification/notificationcomponent.th" #include "icinga/service.h" #include "base/dynamicobject.h" #include "base/timer.h" @@ -30,7 +31,7 @@ namespace icinga /** * @ingroup notification */ -class NotificationComponent : public DynamicObject +class NotificationComponent : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(NotificationComponent); diff --git a/components/notification/notificationcomponent.ti b/components/notification/notificationcomponent.ti new file mode 100644 index 000000000..d19f1c2a6 --- /dev/null +++ b/components/notification/notificationcomponent.ti @@ -0,0 +1,10 @@ +#include "base/dynamicobject.h" + +namespace icinga +{ + +class NotificationComponent : DynamicObject +{ +}; + +} diff --git a/components/perfdata/Makefile.am b/components/perfdata/Makefile.am index d27d84762..67c5b8292 100644 --- a/components/perfdata/Makefile.am +++ b/components/perfdata/Makefile.am @@ -4,17 +4,26 @@ pkglib_LTLIBRARIES = \ libperfdata.la +BUILT_SOURCES = \ + graphitewriter.th \ + perfdatawriter.th + CLEANFILES = \ perfdata-type.cpp .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + libperfdata_la_SOURCES = \ graphitewriter.cpp \ graphitewriter.h \ + graphitewriter.ti \ perfdatawriter.cpp \ perfdatawriter.h \ + perfdatawriter.th \ perfdata-type.conf libperfdata_la_CPPFLAGS = \ diff --git a/components/perfdata/graphitewriter.cpp b/components/perfdata/graphitewriter.cpp index b679d72ba..31ba55fb5 100644 --- a/components/perfdata/graphitewriter.cpp +++ b/components/perfdata/graphitewriter.cpp @@ -57,22 +57,6 @@ void GraphiteWriter::Start(void) Service::OnNewCheckResult.connect(boost::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2)); } -String GraphiteWriter::GetHost(void) const -{ - if (m_Host.IsEmpty()) - return "127.0.0.1"; - else - return m_Host; -} - -String GraphiteWriter::GetPort(void) const -{ - if (m_Port.IsEmpty()) - return "2003"; - else - return m_Port; -} - void GraphiteWriter::ReconnectTimerHandler(void) { try { @@ -110,7 +94,7 @@ void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const Dicti Value metricValue; /* basic metrics */ - AddServiceMetric(metrics, service, "current_attempt", service->GetCurrentCheckAttempt()); + AddServiceMetric(metrics, service, "current_attempt", service->GetCheckAttempt()); AddServiceMetric(metrics, service, "max_check_attempts", service->GetMaxCheckAttempts()); AddServiceMetric(metrics, service, "state_type", service->GetStateType()); AddServiceMetric(metrics, service, "state", service->GetState()); @@ -267,22 +251,3 @@ void GraphiteWriter::SanitizeMetric(String& str) boost::replace_all(str, "/", "_"); } -void GraphiteWriter::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("host", m_Host); - bag->Set("port", m_Port); - } -} - -void GraphiteWriter::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_Host = bag->Get("host"); - m_Port = bag->Get("port"); - } -} diff --git a/components/perfdata/graphitewriter.h b/components/perfdata/graphitewriter.h index cb3162490..a17e8ed65 100644 --- a/components/perfdata/graphitewriter.h +++ b/components/perfdata/graphitewriter.h @@ -20,6 +20,7 @@ #ifndef GRAPHITEWRITER_H #define GRAPHITEWRITER_H +#include "perfdata/graphitewriter.th" #include "icinga/service.h" #include "base/dynamicobject.h" #include "base/tcpsocket.h" @@ -34,24 +35,16 @@ namespace icinga * * @ingroup perfdata */ -class GraphiteWriter : public DynamicObject +class GraphiteWriter : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(GraphiteWriter); DECLARE_TYPENAME(GraphiteWriter); - String GetHost(void) const; - String GetPort(void) const; - protected: virtual void Start(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_Host; - String m_Port; Stream::Ptr m_Stream; Timer::Ptr m_ReconnectTimer; diff --git a/components/perfdata/graphitewriter.ti b/components/perfdata/graphitewriter.ti new file mode 100644 index 000000000..379663fa6 --- /dev/null +++ b/components/perfdata/graphitewriter.ti @@ -0,0 +1,16 @@ +#include "base/dynamicobject.h" + +namespace icinga +{ + +class GraphiteWriter : DynamicObject +{ + [config] String host { + default {{{ return "127.0.0.1"; }}} + }; + [config] String port { + default {{{ return "2003"; }}} + }; +}; + +} diff --git a/components/perfdata/perfdatawriter.cpp b/components/perfdata/perfdatawriter.cpp index 6d9282dd1..853968672 100644 --- a/components/perfdata/perfdatawriter.cpp +++ b/components/perfdata/perfdatawriter.cpp @@ -33,10 +33,6 @@ using namespace icinga; REGISTER_TYPE(PerfdataWriter); -PerfdataWriter::PerfdataWriter(void) - : m_RotationInterval(30) -{ } - void PerfdataWriter::Start(void) { DynamicObject::Start(); @@ -51,37 +47,6 @@ void PerfdataWriter::Start(void) RotateFile(); } -String PerfdataWriter::GetPerfdataPath(void) const -{ - if (!m_PerfdataPath.IsEmpty()) - return m_PerfdataPath; - else - return Application::GetLocalStateDir() + "/cache/icinga2/perfdata/perfdata"; -} - -String PerfdataWriter::GetFormatTemplate(void) const -{ - if (!m_FormatTemplate.IsEmpty()) { - return m_FormatTemplate; - } else { - return "DATATYPE::SERVICEPERFDATA\t" - "TIMET::$TIMET$\t" - "HOSTNAME::$HOSTNAME$\t" - "SERVICEDESC::$SERVICEDESC$\t" - "SERVICEPERFDATA::$SERVICEPERFDATA$\t" - "SERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\t" - "HOSTSTATE::$HOSTSTATE$\t" - "HOSTSTATETYPE::$HOSTSTATETYPE$\t" - "SERVICESTATE::$SERVICESTATE$\t" - "SERVICESTATETYPE::$SERVICESTATETYPE$"; - } -} - -double PerfdataWriter::GetRotationInterval(void) const -{ - return m_RotationInterval; -} - void PerfdataWriter::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr) { if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata()) @@ -130,24 +95,3 @@ void PerfdataWriter::RotationTimerHandler(void) RotateFile(); } -void PerfdataWriter::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("perfdata_path", m_PerfdataPath); - bag->Set("format_template", m_FormatTemplate); - bag->Set("rotation_interval", m_RotationInterval); - } -} - -void PerfdataWriter::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_PerfdataPath = bag->Get("perfdata_path"); - m_FormatTemplate = bag->Get("format_template"); - m_RotationInterval = bag->Get("rotation_interval"); - } -} diff --git a/components/perfdata/perfdatawriter.h b/components/perfdata/perfdatawriter.h index 9518924f4..8ae295fdb 100644 --- a/components/perfdata/perfdatawriter.h +++ b/components/perfdata/perfdatawriter.h @@ -20,7 +20,7 @@ #ifndef PERFDATAWRITER_H #define PERFDATAWRITER_H -#include "icinga/i2-icinga.h" +#include "perfdata/perfdatawriter.th" #include "icinga/service.h" #include "base/dynamicobject.h" #include "base/timer.h" @@ -34,29 +34,16 @@ namespace icinga * * @ingroup icinga */ -class PerfdataWriter : public DynamicObject +class PerfdataWriter : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(PerfdataWriter); DECLARE_TYPENAME(PerfdataWriter); - PerfdataWriter(void); - - String GetPerfdataPath(void) const; - String GetFormatTemplate(void) const; - double GetRotationInterval(void) const; - protected: virtual void Start(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_PerfdataPath; - String m_FormatTemplate; - double m_RotationInterval; - void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr); Timer::Ptr m_RotationTimer; diff --git a/components/perfdata/perfdatawriter.ti b/components/perfdata/perfdatawriter.ti new file mode 100644 index 000000000..0045cb36a --- /dev/null +++ b/components/perfdata/perfdatawriter.ti @@ -0,0 +1,32 @@ +#include "base/dynamicobject.h" +#include "base/application.h" + +namespace icinga +{ + +class PerfdataWriter : DynamicObject +{ + [config] String perfdata_path { + default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/perfdata/perfdata"; }}} + }; + [config] String format_template { + default {{{ + return "DATATYPE::SERVICEPERFDATA\t" + "TIMET::$TIMET$\t" + "HOSTNAME::$HOSTNAME$\t" + "SERVICEDESC::$SERVICEDESC$\t" + "SERVICEPERFDATA::$SERVICEPERFDATA$\t" + "SERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\t" + "HOSTSTATE::$HOSTSTATE$\t" + "HOSTSTATETYPE::$HOSTSTATETYPE$\t" + "SERVICESTATE::$SERVICESTATE$\t" + "SERVICESTATETYPE::$SERVICESTATETYPE$"; + }}} + }; + + [config] double rotation_interval { + default {{{ return 30; }}} + }; +}; + +} diff --git a/configure.ac b/configure.ac index 18b847663..7957084b2 100644 --- a/configure.ac +++ b/configure.ac @@ -210,6 +210,7 @@ third-party/mmatch/Makefile tools/Makefile tools/migration/Makefile tools/icinga2-enable-feature +tools/mkclass/Makefile tools/mkembedconfig/Makefile ]) diff --git a/doc/4.3-object-types.md b/doc/4.3-object-types.md index 4bdfa0861..0203cfa67 100644 --- a/doc/4.3-object-types.md +++ b/doc/4.3-object-types.md @@ -111,7 +111,7 @@ Attributes: max\_check\_attempts|**Optional.** The number of times a service is re-checked before changing into a hard state. Defaults to 3. check\_period |**Optional.** The name of a time period which determines when this service should be checked. Not set by default. check\_interval |**Optional.** The check interval (in seconds). This interval is used for checks when the service is in a `HARD` state. Defaults to 5 minutes. - retry\_interval |**Optional.** The retry interval (in seconds). This interval is used for checks when the service is in a `SOFT` state. Defaults to 1/5th of the check interval if not specified. + retry\_interval |**Optional.** The retry interval (in seconds). This interval is used for checks when the service is in a `SOFT` state. Defaults to 1 minute. enable\_active\_checks|**Optional.** Whether active checks are enabled. Defaults to true. enable\_passive\_checks|**Optional.** Whether passive checks are enabled. Defaults to true. enable\_event\_handler|**Optional.** Enables event handlers for this service. Defaults to true. diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 2ff859138..958ce5122 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -160,6 +160,8 @@ static bool Daemonize(const String& stderrFile) */ int main(int argc, char **argv) { + Application::SetStartTime(Utility::GetTime()); + #ifndef _WIN32 LTDL_SET_PRELOADED_SYMBOLS(); #endif /* _WIN32 */ diff --git a/icinga2.sln b/icinga2.sln index 66a3aa898..cb5655c4d 100644 --- a/icinga2.sln +++ b/icinga2.sln @@ -14,6 +14,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "components\demo\demo.vcxproj", "{2E6C1133-730F-4875-A72C-B455B1DD4C5C}" ProjectSection(ProjectDependencies) = postProject {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} + {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} @@ -21,6 +22,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo", "components\demo\dem EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "notification", "components\notification\notification.vcxproj", "{EBEA7D10-66FB-4760-8AA8-81CD500D899E}" ProjectSection(ProjectDependencies) = postProject + {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F} = {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} @@ -34,6 +36,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checker", "components\checker\checker.vcxproj", "{38CE81CC-2660-4EF0-A936-4A337591DA3E}" ProjectSection(ProjectDependencies) = postProject {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} + {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} @@ -42,6 +45,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compat", "components\compat\compat.vcxproj", "{2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}" ProjectSection(ProjectDependencies) = postProject {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} + {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} @@ -57,6 +61,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base", "lib\base\base.vcxpr ProjectSection(ProjectDependencies) = postProject {19CBCE06-3F5C-479A-BD75-E2AB6215D345} = {19CBCE06-3F5C-479A-BD75-E2AB6215D345} {66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {66BED474-C33F-48F9-90BA-BBCFEDC006B8} + {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "config", "lib\config\config.vcxproj", "{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}" @@ -68,6 +73,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga", "lib\icinga\icinga.vcxproj", "{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}" ProjectSection(ProjectDependencies) = postProject {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} + {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} EndProjectSection @@ -80,6 +86,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "livestatus", "components\livestatus\livestatus.vcxproj", "{950E8743-BB34-4F8A-99EC-C87E8FC0EB3F}" ProjectSection(ProjectDependencies) = postProject {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} + {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} @@ -90,6 +97,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cluster", "components\cluster\cluster.vcxproj", "{8732E0CD-E3D0-41F2-A538-94884543890F}" ProjectSection(ProjectDependencies) = postProject {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} + {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} @@ -107,6 +115,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db_ido", "lib\db_ido\db_ido.vcxproj", "{87BBCE4C-36F5-4C04-90FB-9B74618AF988}" ProjectSection(ProjectDependencies) = postProject {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} + {CBC9DD83-BAEB-4995-8D0B-F711898908E7} = {CBC9DD83-BAEB-4995-8D0B-F711898908E7} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} @@ -114,12 +123,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db_ido", "lib\db_ido\db_ido EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perfdata", "components\perfdata\perfdata.vcxproj", "{E08A9B69-97E2-4203-B4D7-501DFF020CCF}" ProjectSection(ProjectDependencies) = postProject + {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F} = {950E8743-BB34-4F8A-99EC-C87E8FC0EB3F} {D5EE8062-8FC5-40E8-81C0-B435B06AB311} = {D5EE8062-8FC5-40E8-81C0-B435B06AB311} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677} {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mkclass", "tools\mkclass\mkclass.vcxproj", "{CBC9DD83-BAEB-4995-8D0B-F711898908E7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -265,6 +277,14 @@ Global {E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|Win32.Build.0 = Release|Win32 {E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|x64.ActiveCfg = Release|x64 {E08A9B69-97E2-4203-B4D7-501DFF020CCF}.Release|x64.Build.0 = Release|x64 + {CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Debug|Win32.ActiveCfg = Debug|Win32 + {CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Debug|Win32.Build.0 = Debug|Win32 + {CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Debug|x64.ActiveCfg = Debug|x64 + {CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Debug|x64.Build.0 = Debug|x64 + {CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Release|Win32.ActiveCfg = Release|Win32 + {CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Release|Win32.Build.0 = Release|Win32 + {CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Release|x64.ActiveCfg = Release|x64 + {CBC9DD83-BAEB-4995-8D0B-F711898908E7}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index 52f0f447c..0fea3da05 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -4,15 +4,30 @@ pkglib_LTLIBRARIES = \ libbase.la +BUILT_SOURCES = \ + application.th \ + consolelogger.th \ + dynamicobject.th \ + filelogger.th \ + logger.th \ + script.th \ + streamlogger.th \ + sysloglogger.th + +.ti.th: $(top_builddir)/tools/mkclass/mkclass + $(top_builddir)/tools/mkclass/mkclass $< > $@ + libbase_la_SOURCES = \ application.cpp \ application.h \ + application.ti \ array.cpp \ array.h \ bufferedstream.cpp \ bufferedstream.h \ consolelogger.cpp \ consolelogger.h \ + consolelogger.ti \ convert.cpp \ convert.h \ debug.h \ @@ -20,6 +35,7 @@ libbase_la_SOURCES = \ dictionary.h \ dynamicobject.cpp \ dynamicobject.h \ + dynamicobject.ti \ dynamictype.cpp \ dynamictype.h \ exception.cpp \ @@ -28,10 +44,12 @@ libbase_la_SOURCES = \ fifo.h \ filelogger.cpp \ filelogger.h \ + filelogger.ti \ i2-base.h \ initialize.h \ logger.cpp \ logger.h \ + logger.ti \ logger_fwd.h \ netstring.cpp \ netstring.h \ @@ -47,11 +65,14 @@ libbase_la_SOURCES = \ process.h \ qstring.cpp \ qstring.h \ + reflectionobject.cpp \ + reflectionobject.h \ registry.h \ ringbuffer.cpp \ ringbuffer.h \ script.cpp \ script.h \ + script.ti \ scriptfunction.cpp \ scriptfunction.h \ scriptfunctionwrapper.cpp \ @@ -75,8 +96,10 @@ libbase_la_SOURCES = \ stream_bio.h \ streamlogger.cpp \ streamlogger.h \ + streamlogger.ti \ sysloglogger.cpp \ sysloglogger.h \ + sysloglogger.ti \ tcpsocket.cpp \ tcpsocket.h \ threadpool.cpp \ diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 16ccb6434..d578ee896 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -51,6 +51,7 @@ bool Application::m_Restarting = false; bool Application::m_Debugging = false; int Application::m_ArgC; char **Application::m_ArgV; +double Application::m_StartTime; /** * Constructor for the Application class. @@ -718,3 +719,13 @@ String Application::GetVersion(void) return "unspecified version"; #endif /* _WIN32 */ } + +double Application::GetStartTime(void) +{ + return m_StartTime; +} + +void Application::SetStartTime(double ts) +{ + m_StartTime = ts; +} diff --git a/lib/base/application.h b/lib/base/application.h index c98b7dc7b..b93f5910e 100644 --- a/lib/base/application.h +++ b/lib/base/application.h @@ -21,6 +21,7 @@ #define APPLICATION_H #include "base/i2-base.h" +#include "base/application.th" #include "base/threadpool.h" #include "base/dynamicobject.h" @@ -33,7 +34,7 @@ class Component; * * @ingroup base */ -class I2_BASE_API Application : public DynamicObject { +class I2_BASE_API Application : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(Application); @@ -94,6 +95,9 @@ public: static String GetVersion(void); + static double GetStartTime(void); + static void SetStartTime(double ts); + protected: virtual void OnConfigLoaded(void); virtual void Stop(void); @@ -112,6 +116,7 @@ private: static char **m_ArgV; /**< Command-line arguments. */ FILE *m_PidFile; /**< The PID file */ static bool m_Debugging; /**< Whether debugging is enabled. */ + static double m_StartTime; #ifndef _WIN32 static void SigIntHandler(int signum); diff --git a/lib/base/application.ti b/lib/base/application.ti new file mode 100644 index 000000000..4347dd2d8 --- /dev/null +++ b/lib/base/application.ti @@ -0,0 +1,10 @@ +#include "base/dynamicobject.h" + +namespace icinga +{ + +class Application : DynamicObject +{ +}; + +} diff --git a/lib/base/base.vcxproj b/lib/base/base.vcxproj index 534e443d5..099310ac4 100644 --- a/lib/base/base.vcxproj +++ b/lib/base/base.vcxproj @@ -30,6 +30,7 @@ + @@ -78,6 +79,7 @@ + @@ -118,7 +120,105 @@ + + Document + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + + + Document + + + Document + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + + + + Document + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + + + Document + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + + + Document + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + + + + + + Document + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + + + + Document + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + + + + Document + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + "$(SolutionDir)$(Platform)\$(Configuration)\mkclass.exe" "%(Identity)" > "%(Filename).th" + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + %(Filename).th;%(Outputs) + + {9C92DA90-FD53-43A9-A244-90F2E8AF9677} diff --git a/lib/base/base.vcxproj.filters b/lib/base/base.vcxproj.filters index b7861d761..827a23c36 100644 --- a/lib/base/base.vcxproj.filters +++ b/lib/base/base.vcxproj.filters @@ -133,6 +133,9 @@ Quelldateien + + Quelldateien + @@ -285,6 +288,12 @@ Headerdateien + + Headerdateien + + + Headerdateien + @@ -296,5 +305,52 @@ + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + \ No newline at end of file diff --git a/lib/base/consolelogger.h b/lib/base/consolelogger.h index 75a8fcb64..6fd7a7ff0 100644 --- a/lib/base/consolelogger.h +++ b/lib/base/consolelogger.h @@ -21,7 +21,7 @@ #define CONSOLELOGGER_H #include "base/i2-base.h" -#include "base/streamlogger.h" +#include "base/consolelogger.th" namespace icinga { @@ -31,7 +31,7 @@ namespace icinga * * @ingroup base */ -class I2_BASE_API ConsoleLogger : public StreamLogger +class I2_BASE_API ConsoleLogger : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(ConsoleLogger); diff --git a/lib/base/consolelogger.ti b/lib/base/consolelogger.ti new file mode 100644 index 000000000..4059f4551 --- /dev/null +++ b/lib/base/consolelogger.ti @@ -0,0 +1,10 @@ +#include "base/streamlogger.h" + +namespace icinga +{ + +class ConsoleLogger : StreamLogger +{ +}; + +} \ No newline at end of file diff --git a/lib/base/debug.h b/lib/base/debug.h index 98050f3f4..b46587b15 100644 --- a/lib/base/debug.h +++ b/lib/base/debug.h @@ -22,30 +22,45 @@ #include "i2-base.h" -#ifdef NDEBUG +#ifndef _DEBUG # define ASSERT(expr) ((void)0) -#else /* NDEBUG */ +#else /* _DEBUG */ # define ASSERT(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__)) -#endif /* NDEBUG */ +#endif /* _DEBUG */ #define VERIFY(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__)) +#ifdef _MSC_VER +# define NORETURNPRE __declspec(noreturn) +#else /* _MSC_VER */ +# define NORETURNPRE +#endif /* _MSC_VER */ + #ifdef __GNUC__ -# define NORETURN __attribute__((noreturn)) +# define NORETURNPOST __attribute__((noreturn)) #else /* __GNUC__ */ -# define NORETURN +# define NORETURNPOST #endif /* __GNUC__ */ -int icinga_assert_fail(const char *expr, const char *file, int line) NORETURN; +NORETURNPRE int icinga_assert_fail(const char *expr, const char *file, int line) NORETURNPOST; + +#ifdef _MSC_VER +# pragma warning( push ) +# pragma warning( disable : 4646 ) /* function declared with __declspec(noreturn) has non-void return type */ +#endif /* _MSC_VER */ inline int icinga_assert_fail(const char *expr, const char *file, int line) { fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr); abort(); -#ifndef __GNUC__ +#if !defined(__GNUC__) && !defined(_MSC_VER) return 0; -#endif /* __GNUC__ */ +#endif /* !defined(__GNUC__) && !defined(_MSC_VER) */ } +#ifdef _MSC_VER +# pragma warning( pop ) +#endif /* _MSC_VER */ + #endif /* DEBUG_H */ diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 4f359b9fd..21ad26167 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -42,90 +42,21 @@ boost::signals2::signal DynamicObject::OnState boost::signals2::signal DynamicObject::OnAuthorityChanged; DynamicObject::DynamicObject(void) - : m_Active(false) -{ } +{ + SetActive(false); +} DynamicObject::~DynamicObject(void) { } -Dictionary::Ptr DynamicObject::Serialize(int attributeTypes) const -{ - Dictionary::Ptr update = boost::make_shared(); - - ASSERT(!OwnsLock()); - ObjectLock olock(this); - - InternalSerialize(update, attributeTypes); - - /* Make sure our own InternalSerialize() method was called. */ - ASSERT(update->Contains("__marker")); - update->Remove("__marker"); - - return update; -} - -void DynamicObject::Deserialize(const Dictionary::Ptr& update, int attributeTypes) -{ - ASSERT(!OwnsLock()); - - { - ObjectLock olock(this); - InternalDeserialize(update, attributeTypes); - } -} - -void DynamicObject::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - if (attributeTypes & Attribute_Config) { - bag->Set("__name", m_Name); - bag->Set("__type", m_Type); - bag->Set("methods", m_Methods); - bag->Set("custom", m_Custom); - bag->Set("authorities", m_Authorities); - bag->Set("domains", m_Domains); - } - - if (attributeTypes & Attribute_State) - bag->Set("extensions", m_Extensions); - - /* This attribute is used by Serialize() to check that this - * method was called. */ - bag->Set("__marker", 1); -} - -void DynamicObject::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - if (attributeTypes & Attribute_Config) { - m_Name = bag->Get("__name"); - m_Type = bag->Get("__type"); - m_Methods = bag->Get("methods"); - m_Custom = bag->Get("custom"); - m_Authorities = bag->Get("authorities"); - m_Domains = bag->Get("domains"); - } - - if (attributeTypes & Attribute_State) - m_Extensions = bag->Get("extensions"); -} - DynamicType::Ptr DynamicObject::GetType(void) const { - return DynamicType::GetByName(m_Type); -} - -String DynamicObject::GetName(void) const -{ - return m_Name; + return DynamicType::GetByName(GetTypeName()); } bool DynamicObject::IsActive(void) const { - return m_Active; -} - -Array::Ptr DynamicObject::GetAuthorities(void) const -{ - return m_Authorities; + return GetActive(); } void DynamicObject::SetAuthority(const String& type, bool value) @@ -135,15 +66,12 @@ void DynamicObject::SetAuthority(const String& type, bool value) { ObjectLock olock(this); - if (!m_Authority) - m_Authority = boost::make_shared(); - bool old_value = HasAuthority(type); if (old_value == value) return; - m_Authority->Set(type, value); + GetAuthorityInfo()->Set(type, value); } OnAuthorityChanged(GetSelf(), type, value); @@ -151,15 +79,7 @@ void DynamicObject::SetAuthority(const String& type, bool value) bool DynamicObject::HasAuthority(const String& type) const { - if (!m_Authority) - return true; - - return m_Authority->Get(type); -} - -Array::Ptr DynamicObject::GetDomains(void) const -{ - return m_Domains; + return GetAuthorityInfo()->Get(type); } void DynamicObject::SetPrivileges(const String& instance, int privs) @@ -183,11 +103,11 @@ bool DynamicObject::HasPrivileges(const String& instance, int privs) const void DynamicObject::SetExtension(const String& key, const Object::Ptr& object) { - Dictionary::Ptr extensions = m_Extensions; + Dictionary::Ptr extensions = GetExtensions(); if (!extensions) { extensions = boost::make_shared(); - m_Extensions = extensions; + SetExtensions(extensions); } extensions->Set(key, object); @@ -195,7 +115,7 @@ void DynamicObject::SetExtension(const String& key, const Object::Ptr& object) Object::Ptr DynamicObject::GetExtension(const String& key) { - Dictionary::Ptr extensions = m_Extensions; + Dictionary::Ptr extensions = GetExtensions(); if (!extensions) return Object::Ptr(); @@ -205,7 +125,7 @@ Object::Ptr DynamicObject::GetExtension(const String& key) void DynamicObject::ClearExtension(const String& key) { - Dictionary::Ptr extensions = m_Extensions; + Dictionary::Ptr extensions = GetExtensions(); if (!extensions) return; @@ -225,8 +145,8 @@ void DynamicObject::Start(void) { ASSERT(!OwnsLock()); - ASSERT(!m_Active); - m_Active = true; + ASSERT(!IsActive()); + SetActive(true); OnStarted(GetSelf()); } @@ -235,8 +155,8 @@ void DynamicObject::Stop(void) { ASSERT(!OwnsLock()); - ASSERT(m_Active); - m_Active = false; + ASSERT(IsActive()); + SetActive(false); OnStopped(GetSelf()); } @@ -256,7 +176,7 @@ Value DynamicObject::InvokeMethod(const String& method, { Dictionary::Ptr methods; - methods = m_Methods; + methods = GetMethods(); if (!methods) BOOST_THROW_EXCEPTION(std::invalid_argument("Method '" + method + "' does not exist.")); @@ -383,8 +303,3 @@ DynamicObject::Ptr DynamicObject::GetObject(const String& type, const String& na DynamicType::Ptr dtype = DynamicType::GetByName(type); return dtype->GetObject(name); } - -Dictionary::Ptr DynamicObject::GetCustom(void) const -{ - return m_Custom; -} diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index d9138f69e..a2dcb4c26 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -21,6 +21,7 @@ #define DYNAMICOBJECT_H #include "base/i2-base.h" +#include "base/dynamicobject.th" #include "base/object.h" #include "base/dictionary.h" #include "base/array.h" @@ -40,8 +41,8 @@ class DynamicType; */ enum AttributeType { - Attribute_State = 1, - Attribute_Config = 2, + Attribute_State = FAState, + Attribute_Config = FAConfig }; enum DomainPriv @@ -57,16 +58,13 @@ enum DomainPriv * * @ingroup base */ -class I2_BASE_API DynamicObject : public Object +class I2_BASE_API DynamicObject : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(DynamicObject); ~DynamicObject(void); - Dictionary::Ptr Serialize(int attributeTypes) const; - void Deserialize(const Dictionary::Ptr& update, int attributeTypes); - static boost::signals2::signal OnStarted; static boost::signals2::signal OnStopped; static boost::signals2::signal OnStateChanged; @@ -75,17 +73,12 @@ public: Value InvokeMethod(const String& method, const std::vector& arguments); shared_ptr GetType(void) const; - String GetName(void) const; bool IsActive(void) const; - Array::Ptr GetAuthorities(void) const; - void SetAuthority(const String& type, bool value); bool HasAuthority(const String& type) const; - Array::Ptr GetDomains(void) const; - void SetPrivileges(const String& instance, int privs); bool HasPrivileges(const String& instance, int privs) const; @@ -116,27 +109,12 @@ public: static void RestoreObjects(const String& filename, int attributeTypes = Attribute_State); static void StopObjects(void); - Dictionary::Ptr GetCustom(void) const; - protected: explicit DynamicObject(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_Name; - String m_Type; - Dictionary::Ptr m_Extensions; - Dictionary::Ptr m_Methods; - Dictionary::Ptr m_Custom; - Array::Ptr m_Authorities; - Array::Ptr m_Domains; std::map m_Privileges; - bool m_Active; - Dictionary::Ptr m_Authority; - static DynamicObject::Ptr GetObject(const String& type, const String& name); }; diff --git a/lib/base/dynamicobject.ti b/lib/base/dynamicobject.ti new file mode 100644 index 000000000..5e982697e --- /dev/null +++ b/lib/base/dynamicobject.ti @@ -0,0 +1,21 @@ +#include + +namespace icinga +{ + +class DynamicObject +{ + [config] String __name (Name); + [config, get_protected] String __type (TypeName); + [config] Dictionary::Ptr methods; + [config] Dictionary::Ptr custom; + [config] Array::Ptr domains; + [config] Array::Ptr authorities; + [get_protected] bool active; + Dictionary::Ptr authority_info { + default {{{ return boost::make_shared(); }}} + }; + [protected] Dictionary::Ptr extensions; +}; + +} diff --git a/lib/base/filelogger.cpp b/lib/base/filelogger.cpp index 5e649411d..0888e9008 100644 --- a/lib/base/filelogger.cpp +++ b/lib/base/filelogger.cpp @@ -34,7 +34,7 @@ void FileLogger::Start() std::ofstream *stream = new std::ofstream(); - String path = m_Path; + String path = GetPath(); try { stream->open(path.CStr(), std::fstream::out | std::fstream::trunc); @@ -48,19 +48,3 @@ void FileLogger::Start() BindStream(stream, true); } - -void FileLogger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - StreamLogger::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) - bag->Set("path", m_Path); -} - -void FileLogger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - StreamLogger::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) - m_Path = bag->Get("path"); -} diff --git a/lib/base/filelogger.h b/lib/base/filelogger.h index 7f52ffe64..e1d138a0d 100644 --- a/lib/base/filelogger.h +++ b/lib/base/filelogger.h @@ -21,7 +21,7 @@ #define FILELOGGER_H #include "base/i2-base.h" -#include "base/streamlogger.h" +#include "base/filelogger.th" namespace icinga { @@ -31,19 +31,12 @@ namespace icinga * * @ingroup base */ -class I2_BASE_API FileLogger : public StreamLogger +class I2_BASE_API FileLogger : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(FileLogger); virtual void Start(void); - -protected: - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - -private: - String m_Path; }; } diff --git a/lib/base/filelogger.ti b/lib/base/filelogger.ti new file mode 100644 index 000000000..882b1c46d --- /dev/null +++ b/lib/base/filelogger.ti @@ -0,0 +1,11 @@ +#include "base/streamlogger.h" + +namespace icinga +{ + +class FileLogger : StreamLogger +{ + [config] String path; +}; + +} \ No newline at end of file diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 90a2b3f6c..4faa31bde 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -105,7 +105,7 @@ void icinga::Log(LogSeverity severity, const String& facility, */ LogSeverity Logger::GetMinSeverity(void) const { - String severity = m_Severity; + String severity = GetSeverity(); if (severity.IsEmpty()) return LogInformation; else @@ -151,19 +151,3 @@ LogSeverity Logger::StringToSeverity(const String& severity) else BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity)); } - -void Logger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) - bag->Set("severity", m_Severity); -} - -void Logger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) - m_Severity = bag->Get("severity"); -} diff --git a/lib/base/logger.h b/lib/base/logger.h index c99f97e83..4098870c2 100644 --- a/lib/base/logger.h +++ b/lib/base/logger.h @@ -21,6 +21,7 @@ #define LOGGER_H #include "base/i2-base.h" +#include "base/logger.th" #include "base/dynamicobject.h" #include "base/logger_fwd.h" #include @@ -45,7 +46,7 @@ struct LogEntry { * * @ingroup base */ -class I2_BASE_API Logger : public DynamicObject +class I2_BASE_API Logger : public ReflectionObjectImpl { public: DECLARE_PTR_TYPEDEFS(Logger); @@ -69,12 +70,7 @@ protected: virtual void Start(void); virtual void Stop(void); - virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; - virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); - private: - String m_Severity; - static boost::mutex m_Mutex; static std::set m_Loggers; diff --git a/lib/base/logger.ti b/lib/base/logger.ti new file mode 100644 index 000000000..a50033bc5 --- /dev/null +++ b/lib/base/logger.ti @@ -0,0 +1,11 @@ +#include "base/dynamicobject.h" + +namespace icinga +{ + +class Logger : DynamicObject +{ + [config] String severity; +}; + +} \ No newline at end of file diff --git a/lib/base/process-unix.cpp b/lib/base/process-unix.cpp index a7e82d356..3e910d97e 100644 --- a/lib/base/process-unix.cpp +++ b/lib/base/process-unix.cpp @@ -129,7 +129,7 @@ ProcessResult Process::Run(void) (void) close(fds[0]); (void) close(fds[1]); - if (execvpe(argv[0], argv, envp) < 0) { + if (icinga2_execvpe(argv[0], argv, envp) < 0) { perror("execvpe() failed."); _exit(128); } diff --git a/lib/base/reflectionobject.cpp b/lib/base/reflectionobject.cpp new file mode 100644 index 000000000..ab990fcda --- /dev/null +++ b/lib/base/reflectionobject.cpp @@ -0,0 +1,54 @@ +/****************************************************************************** + * 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 "base/reflectionobject.h" +#include + +using namespace icinga; + +Dictionary::Ptr ReflectionObject::Serialize(int attributeTypes) const +{ + Dictionary::Ptr update = boost::make_shared(); + + for (int i = 0; i < GetFieldCount(); i++) { + ReflectionField field = GetFieldInfo(i); + + if ((field.Attributes & attributeTypes) == 0) + continue; + + update->Set(field.Name, GetField(i)); + } + + return update; +} + +void ReflectionObject::Deserialize(const Dictionary::Ptr& update, int attributeTypes) +{ + for (int i = 0; i < GetFieldCount(); i++) { + ReflectionField field = GetFieldInfo(i); + + if ((field.Attributes & attributeTypes) == 0) + continue; + + if (!update->Contains(field.Name)) + continue; + + SetField(i, update->Get(field.Name)); + } +} diff --git a/lib/base/reflectionobject.h b/lib/base/reflectionobject.h new file mode 100644 index 000000000..842aa3a78 --- /dev/null +++ b/lib/base/reflectionobject.h @@ -0,0 +1,76 @@ +/****************************************************************************** + * 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 REFLECTIONOBJECT_H +#define REFLECTIONOBJECT_H + +#include "base/object.h" +#include "base/dictionary.h" +#include + +namespace icinga +{ + +enum ReflectionFieldAttribute +{ + FAConfig = 1, + FAState = 2 +}; + +struct ReflectionField +{ + int ID; + String Name; + int Attributes; + Value DefaultValue; + + ReflectionField(int id, const String& name, int attributes, const Value& default_value = Empty) + : ID(id), Name(name), Attributes(attributes), DefaultValue(default_value) + { } +}; + +enum InvokationType +{ + ITGet, + ITSet +}; + +class I2_BASE_API ReflectionObject : public Object +{ +public: + DECLARE_PTR_TYPEDEFS(ReflectionObject); + + virtual int GetFieldId(const String& name) const = 0; + virtual ReflectionField GetFieldInfo(int id) const = 0; + virtual int GetFieldCount(void) const = 0; + virtual void SetField(int id, const Value& value) = 0; + virtual Value GetField(int id) const = 0; + + Dictionary::Ptr Serialize(int attributeTypes) const; + void Deserialize(const Dictionary::Ptr& update, int attributeTypes); +}; + +template +class ReflectionObjectImpl +{ +}; + +} + +#endif /* REFLECTIONOBJECT_H */ diff --git a/lib/base/script.cpp b/lib/base/script.cpp index a4489a6d8..1c0a7d74c 100644 --- a/lib/base/script.cpp +++ b/lib/base/script.cpp @@ -37,20 +37,6 @@ void Script::Start(void) SpawnInterpreter(); } -String Script::GetLanguage(void) const -{ - ObjectLock olock(this); - - return m_Language; -} - -String Script::GetCode(void) const -{ - ObjectLock olock(this); - - return m_Code; -} - void Script::SpawnInterpreter(void) { Log(LogInformation, "base", "Reloading script '" + GetName() + "'"); @@ -58,23 +44,3 @@ void Script::SpawnInterpreter(void) ScriptLanguage::Ptr language = ScriptLanguage::GetByName(GetLanguage()); m_Interpreter = language->CreateInterpreter(GetSelf()); } - -void Script::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const -{ - DynamicObject::InternalSerialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - bag->Set("language", m_Language); - bag->Set("code", m_Code); - } -} - -void Script::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) -{ - DynamicObject::InternalDeserialize(bag, attributeTypes); - - if (attributeTypes & Attribute_Config) { - m_Language = bag->Get("language"); - m_Code = bag->Get("code"); - } -} diff --git a/lib/base/script.h b/lib/base/script.h index d3c0b0a35..4243a71ee 100644 --- a/lib/base/script.h +++ b/lib/base/script.h @@ -21,7 +21,7 @@ #define SCRIPT_H #include "base/i2-base.h" -#include "base/dynamicobject.h" +#include "base/script.th" namespace icinga { @@ -33,24 +33,14 @@ class ScriptInterpreter; * * @ingroup base */ -class I2_BASE_API Script : public DynamicObject +class I2_BASE_API Script : public ReflectionObjectImpl