From 3c363499bb085832c70719cb230d2793ee294faf Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 12 Mar 2013 13:45:54 +0100 Subject: [PATCH] Eliminate the Component class. Fixes #3832 Fixes #3840 --- Makefile.am | 1 + components/checker/.gitignore | 1 + components/checker/Makefile.am | 17 ++- components/checker/checker-type.conf | 21 +++ components/checker/checkercomponent.cpp | 6 +- components/checker/checkercomponent.h | 4 +- components/compat/.gitignore | 1 + components/compat/Makefile.am | 17 ++- components/compat/compat-type.conf | 25 ++++ components/compat/compatcomponent.cpp | 62 ++++---- components/compat/compatcomponent.h | 10 +- components/delegation/.gitignore | 1 + components/delegation/Makefile.am | 17 ++- components/delegation/delegation-type.conf | 21 +++ components/delegation/delegationcomponent.cpp | 7 +- components/delegation/delegationcomponent.h | 4 +- components/demo/.gitignore | 1 + components/demo/Makefile.am | 17 ++- components/demo/demo-type.conf | 21 +++ components/demo/democomponent.cpp | 6 +- components/demo/democomponent.h | 4 +- components/livestatus/.gitignore | 1 + components/livestatus/Makefile.am | 17 ++- components/livestatus/component.cpp | 19 +-- components/livestatus/component.h | 7 +- components/livestatus/livestatus-type.conf | 21 +++ components/notification/.gitignore | 1 + components/notification/Makefile.am | 17 ++- .../notification/notification-type.conf | 21 +++ .../notification/notificationcomponent.cpp | 6 +- .../notification/notificationcomponent.h | 4 +- components/replication/.gitignore | 1 + components/replication/Makefile.am | 17 ++- components/replication/replication-type.conf | 21 +++ .../replication/replicationcomponent.cpp | 6 +- components/replication/replicationcomponent.h | 4 +- configure.ac | 1 + icinga-app/Makefile.am | 12 +- icinga-app/icinga.cpp | 18 ++- itl/Makefile.am | 3 +- itl/itl.conf | 2 - itl/standalone.conf | 11 +- lib/base/Makefile.am | 2 - lib/base/component.cpp | 140 ------------------ lib/base/component.h | 114 -------------- lib/base/dynamictype.h | 2 +- lib/base/i2-base.h | 1 - lib/base/scriptfunction.h | 2 +- lib/base/utility.cpp | 10 +- lib/base/utility.h | 2 +- lib/config/.gitignore | 1 + lib/config/Makefile.am | 7 + lib/config/base-type.conf | 48 ++++++ lib/config/configcompiler.cpp | 12 +- lib/config/configcompiler.h | 24 ++- lib/icinga/.gitignore | 1 + lib/icinga/Makefile.am | 7 + itl/types.conf => lib/icinga/icinga-type.conf | 44 +----- lib/remoting/.gitignore | 1 + lib/remoting/Makefile.am | 4 + lib/remoting/remoting-type.conf | 24 +++ 61 files changed, 495 insertions(+), 425 deletions(-) create mode 100644 components/checker/.gitignore create mode 100644 components/checker/checker-type.conf create mode 100644 components/compat/.gitignore create mode 100644 components/compat/compat-type.conf create mode 100644 components/delegation/.gitignore create mode 100644 components/delegation/delegation-type.conf create mode 100644 components/demo/.gitignore create mode 100644 components/demo/demo-type.conf create mode 100644 components/livestatus/.gitignore create mode 100644 components/livestatus/livestatus-type.conf create mode 100644 components/notification/.gitignore create mode 100644 components/notification/notification-type.conf create mode 100644 components/replication/.gitignore create mode 100644 components/replication/replication-type.conf delete mode 100644 lib/base/component.cpp delete mode 100644 lib/base/component.h create mode 100644 lib/config/.gitignore create mode 100644 lib/config/base-type.conf create mode 100644 lib/icinga/.gitignore rename itl/types.conf => lib/icinga/icinga-type.conf (91%) create mode 100644 lib/remoting/.gitignore create mode 100644 lib/remoting/remoting-type.conf diff --git a/Makefile.am b/Makefile.am index 9a1554db6..ca8dc863c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,6 +5,7 @@ include aminclude.am SUBDIRS = \ third-party \ + tools \ lib \ components \ icinga-app \ diff --git a/components/checker/.gitignore b/components/checker/.gitignore new file mode 100644 index 000000000..786efdebb --- /dev/null +++ b/components/checker/.gitignore @@ -0,0 +1 @@ +checker-type.cpp diff --git a/components/checker/Makefile.am b/components/checker/Makefile.am index 3b8ff6c85..e4e00dc27 100644 --- a/components/checker/Makefile.am +++ b/components/checker/Makefile.am @@ -1,28 +1,35 @@ ## Process this file with automake to produce Makefile.in pkglib_LTLIBRARIES = \ - checker.la + libchecker.la -checker_la_SOURCES = \ +EXTRA_DIST = \ + checker-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + +libchecker_la_SOURCES = \ checkercomponent.cpp \ checkercomponent.h \ + checker-type.cpp \ i2-checker.h -checker_la_CPPFLAGS = \ +libchecker_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/lib/base \ -I${top_srcdir}/lib/config \ -I${top_srcdir}/lib/remoting \ -I${top_srcdir}/lib/icinga -checker_la_LDFLAGS = \ +libchecker_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ -module \ -no-undefined \ @RELEASE_INFO@ \ @VERSION_INFO@ -checker_la_LIBADD = \ +libchecker_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/lib/base/libbase.la \ diff --git a/components/checker/checker-type.conf b/components/checker/checker-type.conf new file mode 100644 index 000000000..095492e19 --- /dev/null +++ b/components/checker/checker-type.conf @@ -0,0 +1,21 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type CheckerComponent { +} diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 8a9139492..f35fcca44 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -21,7 +21,11 @@ using namespace icinga; -REGISTER_COMPONENT("checker", CheckerComponent); +REGISTER_TYPE(CheckerComponent); + +CheckerComponent::CheckerComponent(const Dictionary::Ptr& serializedUpdate) + : DynamicObject(serializedUpdate) +{ } void CheckerComponent::Start(void) { diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index da38e84c9..f93d4f343 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -49,7 +49,7 @@ struct ServiceNextCheckExtractor /** * @ingroup checker */ -class CheckerComponent : public IComponent +class CheckerComponent : public DynamicObject { public: typedef shared_ptr Ptr; @@ -63,6 +63,8 @@ public: > > ServiceSet; + CheckerComponent(const Dictionary::Ptr& serializedUpdate); + virtual void Start(void); virtual void Stop(void); diff --git a/components/compat/.gitignore b/components/compat/.gitignore new file mode 100644 index 000000000..a3c158468 --- /dev/null +++ b/components/compat/.gitignore @@ -0,0 +1 @@ +compat-type.cpp diff --git a/components/compat/Makefile.am b/components/compat/Makefile.am index 830d100de..8896fde1b 100644 --- a/components/compat/Makefile.am +++ b/components/compat/Makefile.am @@ -1,28 +1,35 @@ ## Process this file with automake to produce Makefile.in pkglib_LTLIBRARIES = \ - compat.la + libcompat.la -compat_la_SOURCES = \ +EXTRA_DIST = \ + compat-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + +libcompat_la_SOURCES = \ compatcomponent.cpp \ compatcomponent.h \ + compat-type.cpp \ i2-compat.h -compat_la_CPPFLAGS = \ +libcompat_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/lib/base \ -I${top_srcdir}/lib/config \ -I${top_srcdir}/lib/remoting \ -I${top_srcdir}/lib/icinga -compat_la_LDFLAGS = \ +libcompat_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ -module \ -no-undefined \ @RELEASE_INFO@ \ @VERSION_INFO@ -compat_la_LIBADD = \ +libcompat_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/lib/base/libbase.la \ diff --git a/components/compat/compat-type.conf b/components/compat/compat-type.conf new file mode 100644 index 000000000..56e1fd8cc --- /dev/null +++ b/components/compat/compat-type.conf @@ -0,0 +1,25 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type CompatComponent { + %attribute string "status_path", + %attribute string "objects_path", + %attribute string "log_path", + %attribute string "command_path" +} diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index c5e3f24f6..7c06d6315 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -21,7 +21,7 @@ using namespace icinga; -REGISTER_COMPONENT("compat", CompatComponent); +REGISTER_TYPE(CompatComponent); /** * Hint: The reason why we're using "\n" rather than std::endl is because @@ -29,6 +29,23 @@ REGISTER_COMPONENT("compat", CompatComponent); * performance (see http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html). */ +/** + * Starts the component. + */ +void CompatComponent::Start(void) +{ + m_StatusTimer = boost::make_shared(); + m_StatusTimer->SetInterval(15); + m_StatusTimer->OnTimerExpired.connect(boost::bind(&CompatComponent::StatusTimerHandler, this)); + m_StatusTimer->Start(); + m_StatusTimer->Reschedule(0); + +#ifndef _WIN32 + m_CommandThread = thread(boost::bind(&CompatComponent::CommandPipeThread, this, GetCommandPath())); + m_CommandThread.detach(); +#endif /* _WIN32 */ +} + /** * Retrieves the status.dat path. * @@ -36,9 +53,7 @@ REGISTER_COMPONENT("compat", CompatComponent); */ String CompatComponent::GetStatusPath(void) const { - DynamicObject::Ptr config = GetConfig(); - - Value statusPath = config->Get("status_path"); + Value statusPath = m_StatusPath; if (statusPath.IsEmpty()) return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; else @@ -52,9 +67,7 @@ String CompatComponent::GetStatusPath(void) const */ String CompatComponent::GetObjectsPath(void) const { - DynamicObject::Ptr config = GetConfig(); - - Value objectsPath = config->Get("objects_path"); + Value objectsPath = m_ObjectsPath; if (objectsPath.IsEmpty()) return Application::GetLocalStateDir() + "/cache/icinga2/objects.cache"; else @@ -68,9 +81,7 @@ String CompatComponent::GetObjectsPath(void) const */ String CompatComponent::GetLogPath(void) const { - DynamicObject::Ptr config = GetConfig(); - - Value logPath = config->Get("log_path"); + Value logPath = m_LogPath; if (logPath.IsEmpty()) return Application::GetLocalStateDir() + "/log/icinga2/compat"; else @@ -84,37 +95,20 @@ String CompatComponent::GetLogPath(void) const */ String CompatComponent::GetCommandPath(void) const { - DynamicObject::Ptr config = GetConfig(); - - Value commandPath = config->Get("command_path"); + Value commandPath = m_CommandPath; if (commandPath.IsEmpty()) return Application::GetLocalStateDir() + "/run/icinga2/icinga2.cmd"; else return commandPath; } -/** - * Starts the component. - */ -void CompatComponent::Start(void) -{ - m_StatusTimer = boost::make_shared(); - m_StatusTimer->SetInterval(15); - m_StatusTimer->OnTimerExpired.connect(boost::bind(&CompatComponent::StatusTimerHandler, this)); - m_StatusTimer->Start(); - m_StatusTimer->Reschedule(0); - -#ifndef _WIN32 - m_CommandThread = thread(boost::bind(&CompatComponent::CommandPipeThread, this, GetCommandPath())); - m_CommandThread.detach(); -#endif /* _WIN32 */ -} - -/** - * Stops the component. - */ -void CompatComponent::Stop(void) +CompatComponent::CompatComponent(const Dictionary::Ptr& serializedUpdate) + : DynamicObject(serializedUpdate) { + RegisterAttribute("status_path", Attribute_Config, &m_StatusPath); + RegisterAttribute("objects_path", Attribute_Config, &m_ObjectsPath); + RegisterAttribute("log_path", Attribute_Config, &m_LogPath); + RegisterAttribute("command_path", Attribute_Config, &m_CommandPath); } #ifndef _WIN32 diff --git a/components/compat/compatcomponent.h b/components/compat/compatcomponent.h index 3c9e1a9e0..4da7e826f 100644 --- a/components/compat/compatcomponent.h +++ b/components/compat/compatcomponent.h @@ -32,13 +32,19 @@ enum CompatObjectType /** * @ingroup compat */ -class CompatComponent : public IComponent +class CompatComponent : public DynamicObject { public: + CompatComponent(const Dictionary::Ptr& serializedUpdate); + virtual void Start(void); - virtual void Stop(void); private: + Attribute m_StatusPath; + Attribute m_ObjectsPath; + Attribute m_LogPath; + Attribute m_CommandPath; + #ifndef _WIN32 thread m_CommandThread; diff --git a/components/delegation/.gitignore b/components/delegation/.gitignore new file mode 100644 index 000000000..90edee361 --- /dev/null +++ b/components/delegation/.gitignore @@ -0,0 +1 @@ +delegation-type.cpp diff --git a/components/delegation/Makefile.am b/components/delegation/Makefile.am index 9411e0e93..c51c69190 100644 --- a/components/delegation/Makefile.am +++ b/components/delegation/Makefile.am @@ -1,28 +1,35 @@ ## Process this file with automake to produce Makefile.in pkglib_LTLIBRARIES = \ - delegation.la + libdelegation.la -delegation_la_SOURCES = \ +EXTRA_DIST = \ + delegation-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + +libdelegation_la_SOURCES = \ delegationcomponent.cpp \ delegationcomponent.h \ + delegation-type.cpp \ i2-delegation.h -delegation_la_CPPFLAGS = \ +libdelegation_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/lib/base \ -I${top_srcdir}/lib/config \ -I${top_srcdir}/lib/remoting \ -I${top_srcdir}/lib/icinga -delegation_la_LDFLAGS = \ +libdelegation_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ -module \ -no-undefined \ @RELEASE_INFO@ \ @VERSION_INFO@ -delegation_la_LIBADD = \ +libdelegation_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/lib/base/libbase.la \ diff --git a/components/delegation/delegation-type.conf b/components/delegation/delegation-type.conf new file mode 100644 index 000000000..bd9df3771 --- /dev/null +++ b/components/delegation/delegation-type.conf @@ -0,0 +1,21 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type DelegationComponent { +} diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index 1b5fd1792..f7d51db74 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -22,13 +22,16 @@ using namespace icinga; -REGISTER_COMPONENT("delegation", DelegationComponent); +REGISTER_TYPE(DelegationComponent); + +DelegationComponent::DelegationComponent(const Dictionary::Ptr& serializedUpdate) + : DynamicObject(serializedUpdate) +{ } void DelegationComponent::Start(void) { m_DelegationTimer = boost::make_shared(); - // TODO: implement a handler for config changes for the delegation_interval variable m_DelegationTimer->SetInterval(30); m_DelegationTimer->OnTimerExpired.connect(boost::bind(&DelegationComponent::DelegationTimerHandler, this)); m_DelegationTimer->Start(); diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index c42556df5..2bbf9fa72 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -26,9 +26,11 @@ namespace icinga /** * @ingroup delegation */ -class DelegationComponent : public IComponent +class DelegationComponent : public DynamicObject { public: + DelegationComponent(const Dictionary::Ptr& serializedUpdate); + virtual void Start(void); private: diff --git a/components/demo/.gitignore b/components/demo/.gitignore new file mode 100644 index 000000000..a8e7da8c7 --- /dev/null +++ b/components/demo/.gitignore @@ -0,0 +1 @@ +demo-type.cpp diff --git a/components/demo/Makefile.am b/components/demo/Makefile.am index aaba36d16..3b5d6593f 100644 --- a/components/demo/Makefile.am +++ b/components/demo/Makefile.am @@ -1,28 +1,35 @@ ## Process this file with automake to produce Makefile.in pkglib_LTLIBRARIES = \ - demo.la + libdemo.la -demo_la_SOURCES = \ +EXTRA_DIST = \ + demo-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + +libdemo_la_SOURCES = \ democomponent.cpp \ democomponent.h \ + demo-type.cpp \ i2-demo.h -demo_la_CPPFLAGS = \ +libdemo_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/lib/base \ -I${top_srcdir}/lib/config \ -I${top_srcdir}/lib/remoting \ -I${top_srcdir}/lib/icinga -demo_la_LDFLAGS = \ +libdemo_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ -module \ -no-undefined \ @RELEASE_INFO@ \ @VERSION_INFO@ -demo_la_LIBADD = \ +libdemo_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/lib/base/libbase.la \ diff --git a/components/demo/demo-type.conf b/components/demo/demo-type.conf new file mode 100644 index 000000000..3704d1f3f --- /dev/null +++ b/components/demo/demo-type.conf @@ -0,0 +1,21 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type DemoComponent { +} diff --git a/components/demo/democomponent.cpp b/components/demo/democomponent.cpp index a974f832f..d9f7dbf27 100644 --- a/components/demo/democomponent.cpp +++ b/components/demo/democomponent.cpp @@ -21,7 +21,11 @@ using namespace icinga; -REGISTER_COMPONENT("demo", DemoComponent); +REGISTER_TYPE(DemoComponent); + +DemoComponent::DemoComponent(const Dictionary::Ptr& serializedUpdate) + : DynamicObject(serializedUpdate) +{ } /** * Starts the component. diff --git a/components/demo/democomponent.h b/components/demo/democomponent.h index 181c8ae09..c832ba9bd 100644 --- a/components/demo/democomponent.h +++ b/components/demo/democomponent.h @@ -26,9 +26,11 @@ namespace icinga /** * @ingroup demo */ -class DemoComponent : public IComponent +class DemoComponent : public DynamicObject { public: + DemoComponent(const Dictionary::Ptr& serializedUpdate); + virtual void Start(void); virtual void Stop(void); diff --git a/components/livestatus/.gitignore b/components/livestatus/.gitignore new file mode 100644 index 000000000..80684567b --- /dev/null +++ b/components/livestatus/.gitignore @@ -0,0 +1 @@ +livestatus-type.cpp diff --git a/components/livestatus/Makefile.am b/components/livestatus/Makefile.am index c8917c11c..a94b098ee 100644 --- a/components/livestatus/Makefile.am +++ b/components/livestatus/Makefile.am @@ -1,9 +1,15 @@ ## Process this file with automake to produce Makefile.in pkglib_LTLIBRARIES = \ - livestatus.la + liblivestatus.la -livestatus_la_SOURCES = \ +EXTRA_DIST = \ + livestatus-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + +liblivestatus_la_SOURCES = \ attributefilter.cpp \ attributefilter.h \ andfilter.cpp \ @@ -28,6 +34,7 @@ livestatus_la_SOURCES = \ filter.h \ hoststable.cpp \ hoststable.h \ + livestatus-type.cpp \ negatefilter.cpp \ negatefilter.h \ orfilter.cpp \ @@ -42,21 +49,21 @@ livestatus_la_SOURCES = \ table.h \ i2-livestatus.h -livestatus_la_CPPFLAGS = \ +liblivestatus_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/lib/base \ -I${top_srcdir}/lib/config \ -I${top_srcdir}/lib/remoting \ -I${top_srcdir}/lib/icinga -livestatus_la_LDFLAGS = \ +liblivestatus_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ -module \ -no-undefined \ @RELEASE_INFO@ \ @VERSION_INFO@ -livestatus_la_LIBADD = \ +liblivestatus_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/lib/base/libbase.la \ diff --git a/components/livestatus/component.cpp b/components/livestatus/component.cpp index 83c164833..b08a08ea8 100644 --- a/components/livestatus/component.cpp +++ b/components/livestatus/component.cpp @@ -22,7 +22,13 @@ using namespace icinga; using namespace livestatus; -REGISTER_COMPONENT("livestatus", LivestatusComponent); +REGISTER_TYPE(LivestatusComponent); + +LivestatusComponent::LivestatusComponent(const Dictionary::Ptr& serializedUpdate) + : DynamicObject(serializedUpdate) +{ + RegisterAttribute("socket_path", Attribute_Config, &m_SocketPath); +} /** * Starts the component. @@ -43,18 +49,9 @@ void LivestatusComponent::Start(void) m_Listener = socket; } -/** - * Stops the component. - */ -void LivestatusComponent::Stop(void) -{ -} - String LivestatusComponent::GetSocketPath(void) const { - DynamicObject::Ptr config = GetConfig(); - - Value socketPath = config->Get("socket_path"); + Value socketPath = m_SocketPath; if (socketPath.IsEmpty()) return Application::GetLocalStateDir() + "/run/icinga2/livestatus"; else diff --git a/components/livestatus/component.h b/components/livestatus/component.h index 5a1aec784..c00f7b6d3 100644 --- a/components/livestatus/component.h +++ b/components/livestatus/component.h @@ -26,15 +26,18 @@ namespace livestatus /** * @ingroup livestatus */ -class LivestatusComponent : public IComponent +class LivestatusComponent : public DynamicObject { public: + LivestatusComponent(const Dictionary::Ptr& serializedUpdate); + virtual void Start(void); - virtual void Stop(void); String GetSocketPath(void) const; private: + Attribute m_SocketPath; + Socket::Ptr m_Listener; set m_Connections; diff --git a/components/livestatus/livestatus-type.conf b/components/livestatus/livestatus-type.conf new file mode 100644 index 000000000..966237ca9 --- /dev/null +++ b/components/livestatus/livestatus-type.conf @@ -0,0 +1,21 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type LivestatusComponent { +} diff --git a/components/notification/.gitignore b/components/notification/.gitignore new file mode 100644 index 000000000..bfe7cd007 --- /dev/null +++ b/components/notification/.gitignore @@ -0,0 +1 @@ +notification-type.cpp diff --git a/components/notification/Makefile.am b/components/notification/Makefile.am index 25f1929d3..1e10da562 100644 --- a/components/notification/Makefile.am +++ b/components/notification/Makefile.am @@ -1,28 +1,35 @@ ## Process this file with automake to produce Makefile.in pkglib_LTLIBRARIES = \ - notification.la + libnotification.la -notification_la_SOURCES = \ +EXTRA_DIST = \ + notification-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + +libnotification_la_SOURCES = \ notificationcomponent.cpp \ notificationcomponent.h \ + notification-type.cpp \ i2-notification.h -notification_la_CPPFLAGS = \ +libnotification_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/lib/base \ -I${top_srcdir}/lib/config \ -I${top_srcdir}/lib/remoting \ -I${top_srcdir}/lib/icinga -notification_la_LDFLAGS = \ +libnotification_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ -module \ -no-undefined \ @RELEASE_INFO@ \ @VERSION_INFO@ -notification_la_LIBADD = \ +libnotification_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/lib/base/libbase.la \ diff --git a/components/notification/notification-type.conf b/components/notification/notification-type.conf new file mode 100644 index 000000000..7b9c05587 --- /dev/null +++ b/components/notification/notification-type.conf @@ -0,0 +1,21 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type NotificationComponent { +} diff --git a/components/notification/notificationcomponent.cpp b/components/notification/notificationcomponent.cpp index a777cb600..da823f3d3 100644 --- a/components/notification/notificationcomponent.cpp +++ b/components/notification/notificationcomponent.cpp @@ -21,7 +21,11 @@ using namespace icinga; -REGISTER_COMPONENT("notification", NotificationComponent); +REGISTER_TYPE(NotificationComponent); + +NotificationComponent::NotificationComponent(const Dictionary::Ptr& serializedUpdate) + : DynamicObject(serializedUpdate) +{ } /** * Starts the component. diff --git a/components/notification/notificationcomponent.h b/components/notification/notificationcomponent.h index c40cd8ac1..0703ad3f8 100644 --- a/components/notification/notificationcomponent.h +++ b/components/notification/notificationcomponent.h @@ -26,9 +26,11 @@ namespace icinga /** * @ingroup notification */ -class NotificationComponent : public IComponent +class NotificationComponent : public DynamicObject { public: + NotificationComponent(const Dictionary::Ptr& serializedUpdate); + virtual void Start(void); virtual void Stop(void); diff --git a/components/replication/.gitignore b/components/replication/.gitignore new file mode 100644 index 000000000..90c786996 --- /dev/null +++ b/components/replication/.gitignore @@ -0,0 +1 @@ +replication-type.cpp diff --git a/components/replication/Makefile.am b/components/replication/Makefile.am index 83c09fbae..b1eab152d 100644 --- a/components/replication/Makefile.am +++ b/components/replication/Makefile.am @@ -1,28 +1,35 @@ ## Process this file with automake to produce Makefile.in pkglib_LTLIBRARIES = \ - replication.la + libreplication.la -replication_la_SOURCES = \ +EXTRA_DIST = \ + replication-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + +libreplication_la_SOURCES = \ replicationcomponent.cpp \ replicationcomponent.h \ + replication-type.cpp \ i2-replication.h -replication_la_CPPFLAGS = \ +libreplication_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ -I${top_srcdir}/lib/base \ -I${top_srcdir}/lib/config \ -I${top_srcdir}/lib/remoting \ -I${top_srcdir}/lib/icinga -replication_la_LDFLAGS = \ +libreplication_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ -module \ -no-undefined \ @RELEASE_INFO@ \ @VERSION_INFO@ -replication_la_LIBADD = \ +libreplication_la_LIBADD = \ $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ ${top_builddir}/lib/base/libbase.la \ diff --git a/components/replication/replication-type.conf b/components/replication/replication-type.conf new file mode 100644 index 000000000..559acfdc5 --- /dev/null +++ b/components/replication/replication-type.conf @@ -0,0 +1,21 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type ReplicationComponent { +} diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp index 70dd403e4..060d22176 100644 --- a/components/replication/replicationcomponent.cpp +++ b/components/replication/replicationcomponent.cpp @@ -21,7 +21,11 @@ using namespace icinga; -REGISTER_COMPONENT("replication", ReplicationComponent); +REGISTER_TYPE(ReplicationComponent); + +ReplicationComponent::ReplicationComponent(const Dictionary::Ptr& serializedUpdate) + : DynamicObject(serializedUpdate) +{ } /** * Starts the component. diff --git a/components/replication/replicationcomponent.h b/components/replication/replicationcomponent.h index 08557c2d8..3ac10d9b9 100644 --- a/components/replication/replicationcomponent.h +++ b/components/replication/replicationcomponent.h @@ -26,9 +26,11 @@ namespace icinga /** * @ingroup replication */ -class ReplicationComponent : public IComponent +class ReplicationComponent : public DynamicObject { public: + ReplicationComponent(const Dictionary::Ptr& serializedUpdate); + virtual void Start(void); virtual void Stop(void); diff --git a/configure.ac b/configure.ac index 89319389a..e8cab61db 100644 --- a/configure.ac +++ b/configure.ac @@ -131,6 +131,7 @@ third-party/cJSON/Makefile third-party/execvpe/Makefile third-party/mmatch/Makefile third-party/popen-noshell/Makefile +tools/Makefile ]) AC_OUTPUT([ etc/init.d/icinga2 diff --git a/icinga-app/Makefile.am b/icinga-app/Makefile.am index c96be3935..5ab2c55be 100644 --- a/icinga-app/Makefile.am +++ b/icinga-app/Makefile.am @@ -29,12 +29,12 @@ icinga2_LDADD = \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ -dlopen ${top_builddir}/lib/icinga/libicinga.la \ - -dlopen ${top_builddir}/components/checker/checker.la \ - -dlopen ${top_builddir}/components/replication/replication.la \ - -dlopen ${top_builddir}/components/compat/compat.la \ - -dlopen ${top_builddir}/components/delegation/delegation.la \ - -dlopen ${top_builddir}/components/demo/demo.la \ - -dlopen ${top_builddir}/components/notification/notification.la + -dlopen ${top_builddir}/components/checker/libchecker.la \ + -dlopen ${top_builddir}/components/replication/libreplication.la \ + -dlopen ${top_builddir}/components/compat/libcompat.la \ + -dlopen ${top_builddir}/components/delegation/libdelegation.la \ + -dlopen ${top_builddir}/components/demo/libdemo.la \ + -dlopen ${top_builddir}/components/notification/libnotification.la if PYTHON_USE icinga2_LDADD += \ diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index c10b03811..af5c566fc 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -48,6 +48,11 @@ static bool LoadConfigFiles(bool validateOnly) ConfigCompiler::CompileFile(configPath); } + String name, fragment; + BOOST_FOREACH(tie(name, fragment), ConfigCompiler::GetConfigFragments()) { + ConfigCompiler::CompileText(name, fragment); + } + ConfigCompilerContext::SetContext(NULL); context.Validate(); @@ -207,13 +212,20 @@ int main(int argc, char **argv) #endif /* _WIN32 */ ); - Component::AddSearchDir(Application::GetPkgLibDir()); + String searchDir = Application::GetPkgLibDir(); + Logger::Write(LogInformation, "base", "Adding library search dir: " + searchDir); + +#ifdef _WIN32 + SetDllDirectory(searchDir.CStr()); +#else /* _WIN32 */ + lt_dladdsearchdir(searchDir.CStr()); +#endif /* _WIN32 */ - (void) Utility::LoadIcingaLibrary("icinga", false); + (void) Utility::LoadExtensionLibrary("icinga"); if (g_AppParams.count("library")) { BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as >()) { - Utility::LoadIcingaLibrary(libraryName, false); + (void) Utility::LoadExtensionLibrary(libraryName); } } diff --git a/itl/Makefile.am b/itl/Makefile.am index 5d8d03eb3..b2eb46736 100644 --- a/itl/Makefile.am +++ b/itl/Makefile.am @@ -5,5 +5,4 @@ icinga2itl_DATA = \ notification.conf \ service.conf \ service-common.conf \ - standalone.conf \ - types.conf + standalone.conf diff --git a/itl/itl.conf b/itl/itl.conf index 7ae68c7d1..0ba84e41e 100644 --- a/itl/itl.conf +++ b/itl/itl.conf @@ -22,8 +22,6 @@ * configuration templates. */ -#include "types.conf" - #include "host.conf" #include "service.conf" #include "service-common.conf" diff --git a/itl/standalone.conf b/itl/standalone.conf index 174a071cf..2ba784c78 100644 --- a/itl/standalone.conf +++ b/itl/standalone.conf @@ -16,9 +16,12 @@ * along with this program; if not, write to the Free Software Foundation * * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ - -local object Component "checker" {} -local object Component "delegation" {} +#library "checker" +local object CheckerComponent "checker" {} -local object Component "notification" {} +#library "delegation" +local object DelegationComponent "delegation" {} + +#library "notification" +local object NotificationComponent "notification" {} diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index 3dca102f0..997d8368c 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -12,8 +12,6 @@ libbase_la_SOURCES = \ asynctask.h \ attribute.cpp \ attribute.h \ - component.cpp \ - component.h \ connection.cpp \ connection.h \ convert.cpp \ diff --git a/lib/base/component.cpp b/lib/base/component.cpp deleted file mode 100644 index aecb2c622..000000000 --- a/lib/base/component.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012 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 "i2-base.h" - -using namespace icinga; - -REGISTER_TYPE(Component); - -boost::mutex Component::m_Mutex; -map Component::m_Factories; - -/** - * Constructor for the component class. - */ -Component::Component(const Dictionary::Ptr& properties) - : DynamicObject(properties) -{ - if (!IsLocal()) - BOOST_THROW_EXCEPTION(runtime_error("Component objects must be local.")); - - Logger::Write(LogInformation, "base", "Loading component '" + GetName() + "'"); - - (void) Utility::LoadIcingaLibrary(GetName(), true); - - Component::Factory factory; - - { - boost::mutex::scoped_lock lock(m_Mutex); - - map::iterator it; - it = m_Factories.find(GetName()); - - if (it == m_Factories.end()) - BOOST_THROW_EXCEPTION(invalid_argument("Unknown component: " + GetName())); - - factory = it->second; - } - - m_Impl = factory(); - - if (!m_Impl) - BOOST_THROW_EXCEPTION(runtime_error("Component factory returned NULL.")); -} - -/** - * Destructor for the Component class. - */ -Component::~Component(void) -{ - if (m_Impl) - m_Impl->Stop(); -} - -/** - * Starts the component. Called when the DynamicObject is fully - * constructed/registered. - */ -void Component::Start(void) -{ - m_Impl->SetConfig(GetSelf()); - m_Impl->Start(); -} - -/** - * Adds a directory to the component search path. - * - * @param componentDirectory The directory. - */ -void Component::AddSearchDir(const String& componentDirectory) -{ - Logger::Write(LogInformation, "base", "Adding library search dir: " + - componentDirectory); - -#ifdef _WIN32 - SetDllDirectory(componentDirectory.CStr()); -#else /* _WIN32 */ - lt_dladdsearchdir(componentDirectory.CStr()); -#endif /* _WIN32 */ -} - -/** - * Retrieves the configuration for this component. - * - * @returns The configuration. - */ -DynamicObject::Ptr IComponent::GetConfig(void) const -{ - return m_Config.lock(); -} - -/** - * Sets the configuration for this component. - */ -void IComponent::SetConfig(const DynamicObject::Ptr& config) -{ - m_Config = config; -} - -/** - * Starts the component. - */ -void IComponent::Start(void) -{ - /* Nothing to do in the default implementation. */ -} - -/** - * Stops the component. - */ -void IComponent::Stop(void) -{ - /* Nothing to do in the default implementation. */ -} - -/** - * Registers a component factory. - */ -void Component::Register(const String& name, const Component::Factory& factory) -{ - boost::mutex::scoped_lock lock(m_Mutex); - - m_Factories[name] = factory; -} diff --git a/lib/base/component.h b/lib/base/component.h deleted file mode 100644 index d6a9a8213..000000000 --- a/lib/base/component.h +++ /dev/null @@ -1,114 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012 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 COMPONENT_H -#define COMPONENT_H - -namespace icinga -{ - -/** - * Interface for application extensions. - * - * @ingroup base - */ -class I2_BASE_API IComponent : public Object -{ -public: - typedef shared_ptr Ptr; - typedef weak_ptr WeakPtr; - - virtual void Start(void); - virtual void Stop(void); - -protected: - DynamicObject::Ptr GetConfig(void) const; - -private: - DynamicObject::WeakPtr m_Config; /**< The configuration object for this - component. */ - - void SetConfig(const DynamicObject::Ptr& config); - - friend class Component; -}; - -/** - * An application extension that can be dynamically loaded - * at run-time. - * - * @ingroup base - */ -class I2_BASE_API Component : public DynamicObject -{ -public: - typedef shared_ptr Ptr; - typedef weak_ptr WeakPtr; - - typedef function Factory; - - Component(const Dictionary::Ptr& properties); - ~Component(void); - - virtual void Start(void); - - static void AddSearchDir(const String& componentDirectory); - - static void Register(const String& name, const Factory& factory); - -private: - IComponent::Ptr m_Impl; /**< The implementation object for this - component. */ - - static boost::mutex m_Mutex; - static map m_Factories; -}; - -/** - * Helper class for registering Component implementation classes. - * - * @ingroup base - */ -class RegisterComponentHelper -{ -public: - RegisterComponentHelper(const String& name, const Component::Factory& factory) - { - Component::Register(name, factory); - } -}; - -/** - * Factory function for IComponent-based classes. - * - * @ingroup base - */ -template -IComponent::Ptr ComponentFactory(void) -{ - return boost::make_shared(); -} - - -#define REGISTER_COMPONENT(name, klass) \ - static RegisterComponentHelper g_RegisterSF_ ## type(name, ComponentFactory) - -} - -#endif /* COMPONENT_H */ diff --git a/lib/base/dynamictype.h b/lib/base/dynamictype.h index 28a529216..4d10d0fbd 100644 --- a/lib/base/dynamictype.h +++ b/lib/base/dynamictype.h @@ -95,7 +95,7 @@ shared_ptr DynamicObjectFactory(const Dictionary::Ptr& serializedUpdate) } #define REGISTER_TYPE_ALIAS(type, alias) \ - static RegisterTypeHelper g_RegisterDT_ ## type(alias, DynamicObjectFactory) + static icinga::RegisterTypeHelper g_RegisterDT_ ## type(alias, DynamicObjectFactory) #define REGISTER_TYPE(type) \ REGISTER_TYPE_ALIAS(type, #type) diff --git a/lib/base/i2-base.h b/lib/base/i2-base.h index 041319c15..f1ca5c228 100644 --- a/lib/base/i2-base.h +++ b/lib/base/i2-base.h @@ -233,7 +233,6 @@ namespace signals2 = boost::signals2; #include "scriptlanguage.h" #include "logger.h" #include "application.h" -#include "component.h" #include "streamlogger.h" #include "sysloglogger.h" diff --git a/lib/base/scriptfunction.h b/lib/base/scriptfunction.h index 3a7b4167b..50bffc6e7 100644 --- a/lib/base/scriptfunction.h +++ b/lib/base/scriptfunction.h @@ -78,7 +78,7 @@ public: }; #define REGISTER_SCRIPTFUNCTION(name, callback) \ - static RegisterFunctionHelper g_RegisterSF_ ## type(name, callback) + static icinga::RegisterFunctionHelper g_RegisterSF_ ## type(name, callback) } diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index c10d8d7a3..1ad374429 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -346,25 +346,22 @@ void Utility::Sleep(double timeout) } /** - * Loads the specified library and invokes an Icinga-specific init - * function if available. + * Loads the specified library. * * @param library The name of the library. - * @param module Whether the library is a module (non-module libraries have a - * "lib" prefix on *NIX). */ #ifdef _WIN32 HMODULE #else /* _WIN32 */ lt_dlhandle #endif /* _WIN32 */ -Utility::LoadIcingaLibrary(const String& library, bool module) +Utility::LoadExtensionLibrary(const String& library) { String path; #ifdef _WIN32 path = library + ".dll"; #else /* _WIN32 */ - path = (module ? "" : "lib") + library + ".la"; + path = "lib" + library + ".la"; #endif /* _WIN32 */ Logger::Write(LogInformation, "base", "Loading library '" + path + "'"); @@ -547,4 +544,3 @@ String Utility::FormatDateTime(const char *format, double ts) return timestamp; } - diff --git a/lib/base/utility.h b/lib/base/utility.h index c5c56829f..37827f065 100644 --- a/lib/base/utility.h +++ b/lib/base/utility.h @@ -65,7 +65,7 @@ public: #else /* _WIN32 */ lt_dlhandle #endif /* _WIN32 */ - LoadIcingaLibrary(const String& library, bool module); + LoadExtensionLibrary(const String& library); #ifndef _WIN32 static void SetNonBlocking(int fd); diff --git a/lib/config/.gitignore b/lib/config/.gitignore new file mode 100644 index 000000000..e8c1bf777 --- /dev/null +++ b/lib/config/.gitignore @@ -0,0 +1 @@ +base-type.cpp diff --git a/lib/config/Makefile.am b/lib/config/Makefile.am index 18ad41c77..60f471514 100644 --- a/lib/config/Makefile.am +++ b/lib/config/Makefile.am @@ -8,7 +8,14 @@ BUILT_SOURCES = config_parser.h AM_YFLAGS = -d +EXTRA_DIST = \ + base-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + libconfig_la_SOURCES = \ + base-type.cpp \ configcompiler.cpp \ configcompiler.h \ configcompilercontext.cpp \ diff --git a/lib/config/base-type.conf b/lib/config/base-type.conf new file mode 100644 index 000000000..b1615f2dd --- /dev/null +++ b/lib/config/base-type.conf @@ -0,0 +1,48 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type DynamicObject { + %require "__local", + %attribute number "__local", + + %require "__name", + %attribute string "__name", + + %require "__type", + %attribute string "__type", + + %attribute dictionary "methods" { + }, + + %attribute any "custom::*" +} + +type Logger { + %attribute string "type", + %attribute string "path", + %attribute string "severity" +} + +type Script { + %require "language", + %attribute string "language", + + %require "code", + %attribute string "code" +} diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index a499bb7f7..487b714f6 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -108,7 +108,7 @@ void ConfigCompiler::HandleInclude(const String& include, bool search, const Deb */ void ConfigCompiler::HandleLibrary(const String& library) { - Utility::LoadIcingaLibrary(library, false); + (void) Utility::LoadExtensionLibrary(library); } /** @@ -211,3 +211,13 @@ void ConfigCompiler::AddIncludeSearchDir(const String& dir) m_IncludeSearchDirs.push_back(dir); } +void ConfigCompiler::RegisterConfigFragment(const String& name, const String& fragment) +{ + GetConfigFragments()[name] = fragment; +} + +map& ConfigCompiler::GetConfigFragments(void) +{ + static map fragments; + return fragments; +} diff --git a/lib/config/configcompiler.h b/lib/config/configcompiler.h index 036b3e8b3..04d7468b1 100644 --- a/lib/config/configcompiler.h +++ b/lib/config/configcompiler.h @@ -50,14 +50,17 @@ public: static void HandleFileInclude(const String& include, bool search, const DebugInfo& debuginfo); - + /* internally used methods */ void HandleInclude(const String& include, bool search, const DebugInfo& debuginfo); void HandleLibrary(const String& library); - + size_t ReadInput(char *buffer, size_t max_bytes); void *GetScanner(void) const; + static void RegisterConfigFragment(const String& name, const String& fragment); + static map& GetConfigFragments(void); + private: String m_Path; istream *m_Input; @@ -72,6 +75,23 @@ private: void DestroyScanner(void); }; +/** + * Helper class for registering config fragments. + * + * @ingroup base + */ +class RegisterConfigFragmentHelper +{ +public: + RegisterConfigFragmentHelper(const String& name, const String& fragment) + { + ConfigCompiler::RegisterConfigFragment(name, fragment); + } +}; + +#define REGISTER_CONFIG_FRAGMENT(name, fragment) \ + static icinga::RegisterConfigFragmentHelper g_RegisterCF_ ## type(name, fragment) + } #endif /* CONFIGCOMPILER_H */ diff --git a/lib/icinga/.gitignore b/lib/icinga/.gitignore new file mode 100644 index 000000000..93a8d0d20 --- /dev/null +++ b/lib/icinga/.gitignore @@ -0,0 +1 @@ +icinga-type.cpp diff --git a/lib/icinga/Makefile.am b/lib/icinga/Makefile.am index f4c82ae9f..242f64db9 100644 --- a/lib/icinga/Makefile.am +++ b/lib/icinga/Makefile.am @@ -4,6 +4,12 @@ pkglib_LTLIBRARIES = \ libicinga.la +EXTRA_DIST = \ + icinga-type.conf + +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + libicinga_la_SOURCES = \ api.cpp \ api.h \ @@ -19,6 +25,7 @@ libicinga_la_SOURCES = \ host.h \ i2-icinga.cpp \ i2-icinga.h \ + icinga-type.cpp \ icingaapplication.cpp \ icingaapplication.h \ macroprocessor.cpp \ diff --git a/itl/types.conf b/lib/icinga/icinga-type.conf similarity index 91% rename from itl/types.conf rename to lib/icinga/icinga-type.conf index 1a7d358dd..89fa93b72 100644 --- a/itl/types.conf +++ b/lib/icinga/icinga-type.conf @@ -17,31 +17,6 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -type DynamicObject { - %require "__local", - %attribute number "__local", - - %require "__name", - %attribute string "__name", - - %require "__type", - %attribute string "__type", - - %attribute dictionary "methods" { - }, - - %attribute any "custom::*" -} - -type Component { -} - -type Logger { - %attribute string "type", - %attribute string "path", - %attribute string "severity" -} - type Host { %attribute string "alias", %attribute string "hostcheck", @@ -227,15 +202,6 @@ type ServiceGroup { %attribute string "action_url" } -type Endpoint { - %attribute string "node", - %attribute string "service", - %attribute number "local" -} - -type TimePeriod { -} - type Notification { %require "methods", %attribute dictionary "methods" { @@ -258,21 +224,13 @@ type Notification { %attribute dictionary "groups" { %attribute string "*" }, - + %attribute dictionary "notification_command" { %attribute string "_*" }, %attribute string "notification_command" } -type Script { - %require "language", - %attribute string "language", - - %require "code", - %attribute string "code" -} - type User { %attribute string "display_name", diff --git a/lib/remoting/.gitignore b/lib/remoting/.gitignore new file mode 100644 index 000000000..83eb6c93b --- /dev/null +++ b/lib/remoting/.gitignore @@ -0,0 +1 @@ +remoting-type.cpp diff --git a/lib/remoting/Makefile.am b/lib/remoting/Makefile.am index 372dcca81..cb12b5181 100644 --- a/lib/remoting/Makefile.am +++ b/lib/remoting/Makefile.am @@ -4,6 +4,9 @@ pkglib_LTLIBRARIES = \ libremoting.la +.conf.cpp: + $(top_builddir)/tools/mkembedconfig $< $@ + libremoting_la_SOURCES = \ endpoint.cpp \ endpoint.h \ @@ -15,6 +18,7 @@ libremoting_la_SOURCES = \ jsonrpcconnection.h \ messagepart.cpp \ messagepart.h \ + remoting-type.cpp \ requestmessage.cpp \ requestmessage.h \ responsemessage.cpp \ diff --git a/lib/remoting/remoting-type.conf b/lib/remoting/remoting-type.conf new file mode 100644 index 000000000..5eab4660c --- /dev/null +++ b/lib/remoting/remoting-type.conf @@ -0,0 +1,24 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 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. * + ******************************************************************************/ + +type Endpoint { + %attribute string "node", + %attribute string "service", + %attribute number "local" +} -- 2.40.0