]> granicus.if.org Git - icinga2/commitdiff
Remove the replication feature and clean up the code.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 20 Aug 2013 09:06:04 +0000 (11:06 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 26 Aug 2013 12:56:38 +0000 (14:56 +0200)
167 files changed:
components/Makefile.am
components/checker/checkercomponent.cpp
components/checker/checkercomponent.h
components/compat/checkresultreader.cpp
components/compat/checkresultreader.h
components/compat/compatcomponent.cpp
components/compat/compatcomponent.h
components/compat/compatlog.cpp
components/compat/compatlog.h
components/delegation/.gitignore [deleted file]
components/delegation/Makefile.am [deleted file]
components/delegation/delegation-type.conf [deleted file]
components/delegation/delegation.vcxproj [deleted file]
components/delegation/delegation.vcxproj.filters [deleted file]
components/delegation/delegationcomponent.cpp [deleted file]
components/delegation/delegationcomponent.h [deleted file]
components/demo/democomponent.cpp
components/demo/democomponent.h
components/ido_mysql/idomysqldbconnection.cpp
components/ido_mysql/idomysqldbconnection.h
components/livestatus/commandstable.cpp
components/livestatus/commentstable.cpp
components/livestatus/component.cpp
components/livestatus/component.h
components/livestatus/contactgroupstable.cpp
components/livestatus/contactstable.cpp
components/livestatus/downtimestable.cpp
components/livestatus/hostgroupstable.cpp
components/livestatus/hoststable.cpp
components/livestatus/servicegroupstable.cpp
components/livestatus/servicestable.cpp
components/livestatus/statustable.cpp
components/livestatus/timeperiodstable.cpp
components/notification/notificationcomponent.cpp
components/notification/notificationcomponent.h
components/replication/.gitignore [deleted file]
components/replication/Makefile.am [deleted file]
components/replication/replication-type.conf [deleted file]
components/replication/replication.filters [deleted file]
components/replication/replication.vcxproj [deleted file]
components/replication/replication.vcxproj.filters [deleted file]
components/replication/replicationcomponent.cpp [deleted file]
components/replication/replicationcomponent.h [deleted file]
configure.ac
contrib/gdb/gdbinit
etc/init.d/icinga2.in
icinga-app/Makefile.am
icinga-app/icinga.cpp
itl/Makefile.am
itl/cluster.conf [deleted file]
itl/standalone.conf
lib/base/Makefile.am
lib/base/application.cpp
lib/base/application.h
lib/base/attribute.cpp [deleted file]
lib/base/attribute.h [deleted file]
lib/base/base.vcxproj
lib/base/base.vcxproj.filters
lib/base/consolelogger.cpp
lib/base/consolelogger.h
lib/base/dynamicobject.cpp
lib/base/dynamicobject.h
lib/base/dynamictype.cpp
lib/base/dynamictype.h
lib/base/filelogger.cpp
lib/base/filelogger.h
lib/base/logger.cpp
lib/base/logger.h
lib/base/registry.h
lib/base/script.cpp
lib/base/script.h
lib/base/scriptfunctionwrapper.h
lib/base/streamlogger.cpp
lib/base/streamlogger.h
lib/base/sysloglogger.cpp
lib/base/sysloglogger.h
lib/base/threadpool.cpp
lib/base/utility.cpp
lib/config/base-type.conf
lib/config/config_lexer.cc
lib/config/config_lexer.ll
lib/config/config_parser.cc
lib/config/config_parser.h
lib/config/config_parser.yy
lib/config/configcompilercontext.cpp
lib/config/configcompilercontext.h
lib/config/configitem.cpp
lib/config/configitem.h
lib/config/configitembuilder.cpp
lib/config/configitembuilder.h
lib/config/configtype.cpp
lib/config/configtype.h
lib/config/expression.cpp
lib/config/expression.h
lib/config/expressionlist.cpp
lib/config/expressionlist.h
lib/config/typerule.cpp
lib/icinga/Makefile.am
lib/icinga/checkcommand.cpp
lib/icinga/checkcommand.h
lib/icinga/checkresultmessage.cpp [deleted file]
lib/icinga/checkresultmessage.h [deleted file]
lib/icinga/command.cpp
lib/icinga/command.h
lib/icinga/downtimemessage.cpp [deleted file]
lib/icinga/downtimemessage.h [deleted file]
lib/icinga/eventcommand.cpp
lib/icinga/eventcommand.h
lib/icinga/externalcommandprocessor.cpp
lib/icinga/flappingmessage.cpp [deleted file]
lib/icinga/flappingmessage.h [deleted file]
lib/icinga/host.cpp
lib/icinga/host.h
lib/icinga/hostgroup.cpp
lib/icinga/hostgroup.h
lib/icinga/icingaapplication.cpp
lib/icinga/icingaapplication.h
lib/icinga/legacytimeperiod.cpp
lib/icinga/macroprocessor.cpp
lib/icinga/macroresolver.cpp
lib/icinga/notification.cpp
lib/icinga/notification.h
lib/icinga/notificationcommand.cpp
lib/icinga/notificationcommand.h
lib/icinga/notificationmessage.cpp [deleted file]
lib/icinga/notificationmessage.h [deleted file]
lib/icinga/notificationrequestmessage.cpp [deleted file]
lib/icinga/notificationrequestmessage.h [deleted file]
lib/icinga/nullchecktask.cpp
lib/icinga/nulleventtask.cpp
lib/icinga/perfdatawriter.cpp
lib/icinga/perfdatawriter.h
lib/icinga/pluginchecktask.cpp
lib/icinga/plugineventtask.cpp
lib/icinga/pluginnotificationtask.cpp
lib/icinga/service-check.cpp
lib/icinga/service-comment.cpp
lib/icinga/service-downtime.cpp
lib/icinga/service-flapping.cpp
lib/icinga/service-notification.cpp
lib/icinga/service.cpp
lib/icinga/service.h
lib/icinga/servicegroup.cpp
lib/icinga/servicegroup.h
lib/icinga/timeperiod.cpp
lib/icinga/timeperiod.h
lib/icinga/user.cpp
lib/icinga/user.h
lib/icinga/usergroup.cpp
lib/icinga/usergroup.h
lib/ido/dbconnection.cpp
lib/ido/dbconnection.h
lib/ido/dbobject.cpp
lib/ido/dbobject.h
lib/ido/dbvalue.h
lib/ido/hostgroupdbobject.cpp
lib/ido/hostgroupdbobject.h
lib/ido/servicedbobject.cpp
lib/ido/servicegroupdbobject.cpp
lib/ido/servicegroupdbobject.h
lib/ido/timeperioddbobject.cpp
lib/ido/usergroupdbobject.cpp
lib/ido/usergroupdbobject.h
lib/python/pythonlanguage.cpp
lib/remoting/endpoint.cpp
lib/remoting/endpoint.h
lib/remoting/endpointmanager.cpp

index 092faf4a9a17be46fdc5ea2bd9bb506fb42c4009..6b78c486f66d31afea9ff5c717b32e952590602a 100644 (file)
@@ -4,9 +4,7 @@
 SUBDIRS = \
        checker \
        compat \
-       delegation \
        demo \
        ido_mysql \
        livestatus \
-       notification \
-       replication
+       notification
index 6cbd209f46f5ff450ef7e0594111da021e8785fb..13718f1b06cf1e6cf4066b0dccb67c4c09212961 100644 (file)
  ******************************************************************************/
 
 #include "checker/checkercomponent.h"
-#include "remoting/endpointmanager.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
+#include "base/utility.h"
 #include "base/logger_fwd.h"
 #include <boost/exception/diagnostic_information.hpp>
+#include <boost/foreach.hpp>
 
 using namespace icinga;
 
 REGISTER_TYPE(CheckerComponent);
 
-CheckerComponent::CheckerComponent(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{ }
-
 void CheckerComponent::Start(void)
 {
-       m_Endpoint = Endpoint::MakeEndpoint("checker", false);
+       DynamicObject::Start();
 
-       /* dummy registration so the delegation module knows this is a checker
-          TODO: figure out a better way for this */
-       m_Endpoint->RegisterSubscription("checker");
+       DynamicObject::OnStarted.connect(bind(&CheckerComponent::ObjectStartedHandler, this, _1));
+       DynamicObject::OnStopped.connect(bind(&CheckerComponent::ObjectStoppedHandler, this, _1));
 
-       Service::OnCheckerChanged.connect(bind(&CheckerComponent::CheckerChangedHandler, this, _1));
        Service::OnNextCheckChanged.connect(bind(&CheckerComponent::NextCheckChangedHandler, this, _1));
 
        m_Stopped = false;
@@ -51,12 +46,15 @@ void CheckerComponent::Start(void)
        m_ResultTimer->SetInterval(5);
        m_ResultTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::ResultTimerHandler, this));
        m_ResultTimer->Start();
+
+       BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
+               if (service->IsActive())
+                       ObjectStartedHandler(service);
+       }
 }
 
 void CheckerComponent::Stop(void)
 {
-       m_Endpoint->Unregister();
-
        {
                boost::mutex::scoped_lock lock(m_Mutex);
                m_Stopped = true;
@@ -83,7 +81,7 @@ void CheckerComponent::CheckThreadProc(void)
                CheckTimeView::iterator it = idx.begin();
                Service::Ptr service = *it;
 
-               if (!service->IsRegistered()) {
+               if (!service->IsActive()) {
                        idx.erase(it);
                        continue;
                }
@@ -191,19 +189,34 @@ void CheckerComponent::ResultTimerHandler(void)
        Log(LogInformation, "checker", msgbuf.str());
 }
 
-void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
+void CheckerComponent::ObjectStartedHandler(const DynamicObject::Ptr& object)
 {
-       boost::mutex::scoped_lock lock(m_Mutex);
+       if (object->GetType() != DynamicType::GetByName("Service"))
+               return;
 
-       String checker = service->GetCurrentChecker();
+       Service::Ptr service = static_pointer_cast<Service>(object);
+
+       {
+               boost::mutex::scoped_lock lock(m_Mutex);
 
-       if (checker == EndpointManager::GetInstance()->GetIdentity() || Endpoint::GetByName(checker) == m_Endpoint) {
                if (m_PendingServices.find(service) != m_PendingServices.end())
                        return;
 
                m_IdleServices.insert(service);
                m_CV.notify_all();
-       } else {
+       }
+}
+
+void CheckerComponent::ObjectStoppedHandler(const DynamicObject::Ptr& object)
+{
+       if (object->GetType() != DynamicType::GetByName("Service"))
+               return;
+
+       Service::Ptr service = static_pointer_cast<Service>(object);
+
+       {
+               boost::mutex::scoped_lock lock(m_Mutex);
+
                m_IdleServices.erase(service);
                m_PendingServices.erase(service);
                m_CV.notify_all();
index dfcc83967ad20f47be086bbc34503e2cab5b970d..d7fb22de65c1570c1285a44f846cc430d4f5fa99 100644 (file)
@@ -73,14 +73,10 @@ public:
                >
        > ServiceSet;
 
-       CheckerComponent(const Dictionary::Ptr& serializedUpdate);
-
        virtual void Start(void);
        virtual void Stop(void);
 
 private:
-       Endpoint::Ptr m_Endpoint;
-
        boost::mutex m_Mutex;
        boost::condition_variable m_CV;
        bool m_Stopped;
@@ -98,7 +94,8 @@ private:
 
        void AdjustCheckTimer(void);
 
-       void CheckerChangedHandler(const Service::Ptr& service);
+       void ObjectStartedHandler(const DynamicObject::Ptr& object);
+       void ObjectStoppedHandler(const DynamicObject::Ptr& object);
        void NextCheckChangedHandler(const Service::Ptr& service);
 
        void RescheduleCheckTimer(void);
index 82a0d592de25c19ec0d4fd30f5345dddd47f8ff2..c5cde90a38f439c84897b5f6b67482f71d8b4b9c 100644 (file)
@@ -33,12 +33,6 @@ using namespace icinga;
 
 REGISTER_TYPE(CheckResultReader);
 
-CheckResultReader::CheckResultReader(const Dictionary::Ptr& properties)
-       : DynamicObject(properties)
-{
-       RegisterAttribute("spool_dir", Attribute_Config, &m_SpoolDir);
-}
-
 /**
  * @threadsafety Always.
  */
@@ -50,16 +44,6 @@ void CheckResultReader::Start(void)
        m_ReadTimer->Start();
 }
 
-/**
- * @threadsafety Always.
- */
-CheckResultReader::Ptr CheckResultReader::GetByName(const String& name)
-{
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("CheckResultReader", name);
-
-       return dynamic_pointer_cast<CheckResultReader>(configObject);
-}
-
 /**
  * @threadsafety Always.
  */
@@ -96,7 +80,7 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const
                if (line.empty() || line[0] == '#')
                        continue; /* Ignore comments and empty lines. */
 
-               int pos = line.find_first_of('=');
+               size_t pos = line.find_first_of('=');
 
                if (pos == std::string::npos)
                        continue; /* Ignore invalid lines. */
@@ -149,3 +133,19 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const
                service->SetNextCheck(Utility::GetTime() + service->GetCheckInterval());
        }
 }
+
+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");
+}
index 3820103d2287d264eeb29c4b38513b67b0a2724a..a46b988682d5e44ef44f421c9aca443bef7fe55f 100644 (file)
@@ -37,18 +37,18 @@ class CheckResultReader : public DynamicObject
 {
 public:
        DECLARE_PTR_TYPEDEFS(CheckResultReader);
-
-       CheckResultReader(const Dictionary::Ptr& properties);
-
-       static CheckResultReader::Ptr GetByName(const String& name);
+       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:
-       Attribute<String> m_SpoolDir;
+       String m_SpoolDir;
 
        Timer::Ptr m_ReadTimer;
        void ReadTimerHandler(void) const;
index 225c8b4ae9e569976759ebf55edb701471811c6d..103ac417f5768fe845546405d521644300b99bcf 100644 (file)
@@ -56,6 +56,8 @@ REGISTER_TYPE(CompatComponent);
  */
 void CompatComponent::Start(void)
 {
+       DynamicObject::Start();
+
        m_StatusTimer = boost::make_shared<Timer>();
        m_StatusTimer->SetInterval(15);
        m_StatusTimer->OnTimerExpired.connect(boost::bind(&CompatComponent::StatusTimerHandler, this));
@@ -75,11 +77,10 @@ void CompatComponent::Start(void)
  */
 String CompatComponent::GetStatusPath(void) const
 {
-       Value statusPath = m_StatusPath;
-       if (statusPath.IsEmpty())
+       if (m_StatusPath.IsEmpty())
                return Application::GetLocalStateDir() + "/cache/icinga2/status.dat";
        else
-               return statusPath;
+               return m_StatusPath;
 }
 
 /**
@@ -89,11 +90,10 @@ String CompatComponent::GetStatusPath(void) const
  */
 String CompatComponent::GetObjectsPath(void) const
 {
-       Value objectsPath = m_ObjectsPath;
-       if (objectsPath.IsEmpty())
+       if (m_ObjectsPath.IsEmpty())
                return Application::GetLocalStateDir() + "/cache/icinga2/objects.cache";
        else
-               return objectsPath;
+               return m_ObjectsPath;
 }
 
 /**
@@ -103,20 +103,12 @@ String CompatComponent::GetObjectsPath(void) const
  */
 String CompatComponent::GetCommandPath(void) const
 {
-       Value commandPath = m_CommandPath;
-       if (commandPath.IsEmpty())
+       if (m_CommandPath.IsEmpty())
                return Application::GetLocalStateDir() + "/run/icinga2/icinga2.cmd";
        else
-               return commandPath;
+               return m_CommandPath;
 }
 
-CompatComponent::CompatComponent(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("status_path", Attribute_Config, &m_StatusPath);
-       RegisterAttribute("objects_path", Attribute_Config, &m_ObjectsPath);
-       RegisterAttribute("command_path", Attribute_Config, &m_CommandPath);
-}
 
 #ifndef _WIN32
 void CompatComponent::CommandPipeThread(const String& commandPath)
@@ -240,7 +232,7 @@ void CompatComponent::DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp
           << "\t" << "timeperiod_name" << "\t" << tp->GetName() << "\n"
           << "\t" << "alias" << "\t" << tp->GetName() << "\n";
 
-       Dictionary::Ptr ranges = tp->Get("ranges");
+       Dictionary::Ptr ranges = tp->GetRanges();
 
        if (ranges) {
                ObjectLock olock(ranges);
@@ -426,12 +418,12 @@ void CompatComponent::DumpServiceStatusAttrs(std::ostream& fp, const Service::Pt
        fp << "\t" << "check_command=" << attrs->Get("check_command") << "\n"
           << "\t" << "event_handler=" << attrs->Get("event_handler") << "\n"
           << "\t" << "check_period=" << attrs->Get("check_period") << "\n"
-          << "\t" << "check_interval=" << attrs->Get("check_interval") << "\n"
-          << "\t" << "retry_interval=" << attrs->Get("retry_interval") << "\n"
+          << "\t" << "check_interval=" << static_cast<double>(attrs->Get("check_interval")) << "\n"
+          << "\t" << "retry_interval=" << static_cast<double>(attrs->Get("retry_interval")) << "\n"
           << "\t" << "has_been_checked=" << attrs->Get("has_been_checked") << "\n"
           << "\t" << "should_be_scheduled=" << attrs->Get("should_be_scheduled") << "\n"
-          << "\t" << "check_execution_time=" << attrs->Get("check_execution_time") << "\n"
-          << "\t" << "check_latency=" << attrs->Get("check_latency") << "\n"
+          << "\t" << "check_execution_time=" << static_cast<double>(attrs->Get("check_execution_time")) << "\n"
+          << "\t" << "check_latency=" << static_cast<double>(attrs->Get("check_latency")) << "\n"
           << "\t" << "current_state=" << attrs->Get("current_state") << "\n"
           << "\t" << "state_type=" << attrs->Get("state_type") << "\n"
           << "\t" << "plugin_output=" << attrs->Get("plugin_output") << "\n"
@@ -642,9 +634,7 @@ void CompatComponent::StatusTimerHandler(void)
                 << "# This file is auto-generated. Do not modify this file." << "\n"
                 << "\n";
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
-               Host::Ptr host = static_pointer_cast<Host>(object);
-
+       BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
                std::ostringstream tempstatusfp;
                tempstatusfp << std::fixed;
                DumpHostStatus(tempstatusfp, host);
@@ -656,9 +646,7 @@ void CompatComponent::StatusTimerHandler(void)
                objectfp << tempobjectfp.str();
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
-               HostGroup::Ptr hg = static_pointer_cast<HostGroup>(object);
-
+       BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjects<HostGroup>()) {
                std::ostringstream tempobjectfp;
                tempobjectfp << std::fixed;
 
@@ -675,9 +663,7 @@ void CompatComponent::StatusTimerHandler(void)
                objectfp << tempobjectfp.str();
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = static_pointer_cast<Service>(object);
-
+       BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
                std::ostringstream tempstatusfp;
                tempstatusfp << std::fixed;
                DumpServiceStatus(tempstatusfp, service);
@@ -689,9 +675,7 @@ void CompatComponent::StatusTimerHandler(void)
                objectfp << tempobjectfp.str();
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
-               ServiceGroup::Ptr sg = static_pointer_cast<ServiceGroup>(object);
-
+       BOOST_FOREACH(const ServiceGroup::Ptr& sg, DynamicType::GetObjects<ServiceGroup>()) {
                std::ostringstream tempobjectfp;
                tempobjectfp << std::fixed;
 
@@ -721,9 +705,7 @@ void CompatComponent::StatusTimerHandler(void)
                objectfp << tempobjectfp.str();
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
-               User::Ptr user = static_pointer_cast<User>(object);
-
+       BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects<User>()) {
                std::ostringstream tempobjectfp;
                tempobjectfp << std::fixed;
 
@@ -740,9 +722,7 @@ void CompatComponent::StatusTimerHandler(void)
                objectfp << tempobjectfp.str();
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
-               UserGroup::Ptr ug = static_pointer_cast<UserGroup>(object);
-
+       BOOST_FOREACH(const UserGroup::Ptr& ug, DynamicType::GetObjects<UserGroup>()) {
                std::ostringstream tempobjectfp;
                tempobjectfp << std::fixed;
 
@@ -758,27 +738,19 @@ void CompatComponent::StatusTimerHandler(void)
                objectfp << tempobjectfp.str();
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("CheckCommand")) {
-               Command::Ptr command = static_pointer_cast<Command>(object);
-
+       BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<CheckCommand>()) {
                DumpCommand(objectfp, command);
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("NotificationCommand")) {
-               Command::Ptr command = static_pointer_cast<Command>(object);
-
+       BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<NotificationCommand>()) {
                DumpCommand(objectfp, command);
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("EventCommand")) {
-               Command::Ptr command = static_pointer_cast<Command>(object);
-
+       BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<EventCommand>()) {
                DumpCommand(objectfp, command);
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("TimePeriod")) {
-               TimePeriod::Ptr tp = static_pointer_cast<TimePeriod>(object);
-
+       BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjects<TimePeriod>()) {
                DumpTimePeriod(objectfp, tp);
        }
 
@@ -806,3 +778,25 @@ void CompatComponent::StatusTimerHandler(void)
                    << boost::errinfo_file_name(objectspathtmp));
        }
 }
+
+void CompatComponent::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);
+               bag->Set("command_path", m_CommandPath);
+       }
+}
+
+void CompatComponent::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");
+               m_CommandPath = bag->Get("command_path");
+       }
+}
index 3dd21007f3eab4da85826a6368b9c507875ff695..0e860b9bfb4d5c09d8d1fc364b9b29f885ad9013 100644 (file)
@@ -42,14 +42,16 @@ class CompatComponent : public DynamicObject
 public:
        DECLARE_PTR_TYPEDEFS(CompatComponent);
 
-       CompatComponent(const Dictionary::Ptr& serializedUpdate);
-
+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:
-       Attribute<String> m_StatusPath;
-       Attribute<String> m_ObjectsPath;
-       Attribute<String> m_CommandPath;
+       String m_StatusPath;
+       String m_ObjectsPath;
+       String m_CommandPath;
 
 #ifndef _WIN32
        boost::thread m_CommandThread;
index e4b64fffc6aee95a06c77f7b8d45196a75232fd9..0469168ac2116099ba29bff095fe8c6ba5328808 100644 (file)
  ******************************************************************************/
 
 #include "compat/compatlog.h"
-#include "icinga/checkresultmessage.h"
-#include "icinga/downtimemessage.h"
 #include "icinga/service.h"
 #include "icinga/checkcommand.h"
 #include "icinga/notification.h"
-#include "icinga/notificationmessage.h"
 #include "icinga/macroprocessor.h"
 #include "config/configcompilercontext.h"
 #include "base/dynamictype.h"
@@ -43,33 +40,16 @@ using namespace icinga;
 REGISTER_TYPE(CompatLog);
 REGISTER_SCRIPTFUNCTION(ValidateRotationMethod, &CompatLog::ValidateRotationMethod);
 
-CompatLog::CompatLog(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate), m_LastRotation(0)
-{
-       RegisterAttribute("log_dir", Attribute_Config, &m_LogDir);
-       RegisterAttribute("rotation_method", Attribute_Config, &m_RotationMethod);
-}
-
-/**
- * @threadsafety Always.
- */
-void CompatLog::OnAttributeChanged(const String& name)
-{
-       ASSERT(!OwnsLock());
-
-       if (name == "rotation_method")
-               ScheduleNextRotation();
-}
+CompatLog::CompatLog(void)
+       : m_LastRotation(0)
+{ }
 
 /**
  * @threadsafety Always.
  */
 void CompatLog::Start(void)
 {
-       m_Endpoint = Endpoint::MakeEndpoint("compatlog_" + GetName(), false);
-       m_Endpoint->RegisterTopicHandler("checker::CheckResult",
-           boost::bind(&CompatLog::CheckResultRequestHandler, this, _3));
-
+       Service::OnNewCheckResult.connect(bind(&CompatLog::CheckResultHandler, this, _1, _2));
        Service::OnDowntimeChanged.connect(bind(&CompatLog::DowntimeHandler, this, _1, _2));
        Service::OnNotificationSentChanged.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6));
        Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2));
@@ -82,16 +62,6 @@ void CompatLog::Start(void)
        ScheduleNextRotation();
 }
 
-/**
- * @threadsafety Always.
- */
-CompatLog::Ptr CompatLog::GetByName(const String& name)
-{
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("CompatLog", name);
-
-       return dynamic_pointer_cast<CompatLog>(configObject);
-}
-
 /**
  * @threadsafety Always.
  */
@@ -117,24 +87,13 @@ String CompatLog::GetRotationMethod(void) const
 /**
  * @threadsafety Always.
  */
-void CompatLog::CheckResultRequestHandler(const RequestMessage& request)
+void CompatLog::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr &cr)
 {
-       CheckResultMessage params;
-       if (!request.GetParams(&params))
-               return;
-
-       String svcname = params.GetService();
-       Service::Ptr service = Service::GetByName(svcname);
-
        Host::Ptr host = service->GetHost();
 
        if (!host)
                return;
 
-       Dictionary::Ptr cr = params.GetCheckResult();
-       if (!cr)
-               return;
-
        Dictionary::Ptr vars_after = cr->Get("vars_after");
 
        long state_after = vars_after->Get("state");
@@ -273,7 +232,7 @@ void CompatLog::DowntimeHandler(const Service::Ptr& service, DowntimeState downt
 /**
  * @threadsafety Always.
  */
-void CompatLog::NotificationSentHandler(const Service::Ptr& service, const String& username,
+void CompatLog::NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user,
                NotificationType const& notification_type, Dictionary::Ptr const& cr,
                const String& author, const String& comment_text)
 {
@@ -310,7 +269,7 @@ void CompatLog::NotificationSentHandler(const Service::Ptr& service, const Strin
 
         std::ostringstream msgbuf;
         msgbuf << "SERVICE NOTIFICATION: "
-               << username << ";"
+               << user->GetName() << ";"
                 << host->GetName() << ";"
                 << service->GetShortName() << ";"
                 << notification_type_str << " "
@@ -327,7 +286,7 @@ void CompatLog::NotificationSentHandler(const Service::Ptr& service, const Strin
         if (service == host->GetHostCheckService()) {
                 std::ostringstream msgbuf;
                 msgbuf << "HOST NOTIFICATION: "
-                       << username << ";"
+                       << user->GetName() << ";"
                         << host->GetName() << ";"
                        << notification_type_str << " "
                        << "(" << Service::StateToString(service->GetState()) << ");"
@@ -463,9 +422,7 @@ void CompatLog::ReopenFile(bool rotate)
        WriteLine("LOG ROTATION: " + GetRotationMethod());
        WriteLine("LOG VERSION: 2.0");
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
-               Host::Ptr host = static_pointer_cast<Host>(object);
-
+       BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
                Service::Ptr hc = host->GetHostCheckService();
 
                if (!hc)
@@ -486,9 +443,7 @@ void CompatLog::ReopenFile(bool rotate)
                WriteLine(msgbuf.str());
        }
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = static_pointer_cast<Service>(object);
-
+       BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
                Host::Ptr host = service->GetHost();
 
                if (!host)
@@ -580,7 +535,27 @@ void CompatLog::ValidateRotationMethod(const String& location, const Dictionary:
 
        if (!rotation_method.IsEmpty() && rotation_method != "HOURLY" && rotation_method != "DAILY" &&
            rotation_method != "WEEKLY" && rotation_method != "MONTHLY" && rotation_method != "NONE") {
-               ConfigCompilerContext::GetContext()->AddError(false, "Validation failed for " +
+               ConfigCompilerContext::GetInstance()->AddError(false, "Validation failed for " +
                    location + ": Rotation method '" + rotation_method + "' is invalid.");
        }
 }
+
+void CompatLog::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 CompatLog::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");
+       }
+}
index b45ef13f3703cdf412c360c4366eacb911678e91..d3f73a678d2ebdab47404f9d4e4a605b09ae3201 100644 (file)
@@ -38,10 +38,9 @@ class CompatLog : public DynamicObject
 {
 public:
        DECLARE_PTR_TYPEDEFS(CompatLog);
+       DECLARE_TYPENAME(CompatLog);
 
-       CompatLog(const Dictionary::Ptr& serializedUpdate);
-
-       static CompatLog::Ptr GetByName(const String& name);
+       CompatLog(void);
 
        String GetLogDir(void) const;
        String GetRotationMethod(void) const;
@@ -49,22 +48,23 @@ public:
        static void ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs);
 
 protected:
-       virtual void OnAttributeChanged(const String& name);
        virtual void Start(void);
 
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
 private:
-       Attribute<String> m_LogDir;
-       Attribute<String> m_RotationMethod;
+       String m_LogDir;
+       String m_RotationMethod;
 
        double m_LastRotation;
 
        void WriteLine(const String& line);
        void Flush(void);
 
-       Endpoint::Ptr m_Endpoint;
-       void CheckResultRequestHandler(const RequestMessage& request);
+       void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr);
        void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state);
-       void NotificationSentHandler(const Service::Ptr& service, const String& username, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text);
+       void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text);
        void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
 
        Timer::Ptr m_RotationTimer;
diff --git a/components/delegation/.gitignore b/components/delegation/.gitignore
deleted file mode 100644 (file)
index 90edee3..0000000
+++ /dev/null
@@ -1 +0,0 @@
-delegation-type.cpp
diff --git a/components/delegation/Makefile.am b/components/delegation/Makefile.am
deleted file mode 100644 (file)
index 6a1a17e..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-pkglib_LTLIBRARIES = \
-       libdelegation.la
-
-EXTRA_DIST = \
-       delegation-type.conf
-
-.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig.c
-       $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
-
-libdelegation_la_SOURCES = \
-       delegationcomponent.cpp \
-       delegationcomponent.h \
-       delegation-type.cpp
-
-libdelegation_la_CPPFLAGS = \
-       $(LTDLINCL) \
-       $(BOOST_CPPFLAGS) \
-       -I${top_srcdir}/lib \
-       -I${top_srcdir}/components
-
-libdelegation_la_LDFLAGS = \
-       $(BOOST_LDFLAGS) \
-       -module \
-       -no-undefined \
-       @RELEASE_INFO@ \
-       @VERSION_INFO@
-
-libdelegation_la_LIBADD = \
-       $(BOOST_SIGNALS_LIB) \
-       $(BOOST_THREAD_LIB) \
-       $(BOOST_SYSTEM_LIB) \
-       ${top_builddir}/lib/base/libbase.la \
-       ${top_builddir}/lib/config/libconfig.la \
-       ${top_builddir}/lib/remoting/libremoting.la \
-       ${top_builddir}/lib/icinga/libicinga.la
diff --git a/components/delegation/delegation-type.conf b/components/delegation/delegation-type.conf
deleted file mode 100644 (file)
index bd9df37..0000000
+++ /dev/null
@@ -1,21 +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.             *
- ******************************************************************************/
-
-type DelegationComponent {
-}
diff --git a/components/delegation/delegation.vcxproj b/components/delegation/delegation.vcxproj
deleted file mode 100644 (file)
index fcc240d..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Debug|x64">
-      <Configuration>Debug</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|x64">
-      <Configuration>Release</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{17C93245-8C20-4316-9573-1AE41D918C10}</ProjectGuid>
-    <Keyword>Win32Proj</Keyword>
-    <RootNamespace>delegation</RootNamespace>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <LinkIncremental>true</LinkIncremental>
-    <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
-    <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
-    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(Platform)\$(Configuration)\</IntDir>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <LinkIncremental>true</LinkIncremental>
-    <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
-    <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
-    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(Platform)\$(Configuration)\</IntDir>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <LinkIncremental>false</LinkIncremental>
-    <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
-    <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
-    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(Platform)\$(Configuration)\</IntDir>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <LinkIncremental>false</LinkIncremental>
-    <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
-    <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
-    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(Platform)\$(Configuration)\</IntDir>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>false</MinimalRebuild>
-      <MultiProcessorCompilation>true</MultiProcessorCompilation>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>false</MinimalRebuild>
-      <MultiProcessorCompilation>true</MultiProcessorCompilation>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>false</MinimalRebuild>
-      <MultiProcessorCompilation>true</MultiProcessorCompilation>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>false</MinimalRebuild>
-      <MultiProcessorCompilation>true</MultiProcessorCompilation>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="delegation-type.cpp" />
-    <ClCompile Include="delegationcomponent.cpp" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="delegationcomponent.h" />
-    <ClInclude Include="i2-delegation.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <CustomBuild Include="delegation-type.conf">
-      <FileType>Document</FileType>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
-      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Preparing config fragment for embedding</Message>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
-      <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Preparing config fragment for embedding</Message>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
-      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Preparing config fragment for embedding</Message>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
-      <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Preparing config fragment for embedding</Message>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cpp;%(Outputs)</Outputs>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).cpp;%(Outputs)</Outputs>
-      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
-      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
-      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
-      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
-    </CustomBuild>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
-</Project>
\ No newline at end of file
diff --git a/components/delegation/delegation.vcxproj.filters b/components/delegation/delegation.vcxproj.filters
deleted file mode 100644 (file)
index 4e72c1b..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="Quelldateien">
-      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
-    <Filter Include="Headerdateien">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="delegationcomponent.cpp">
-      <Filter>Quelldateien</Filter>
-    </ClCompile>
-    <ClCompile Include="delegation-type.cpp">
-      <Filter>Quelldateien</Filter>
-    </ClCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="delegationcomponent.h">
-      <Filter>Headerdateien</Filter>
-    </ClInclude>
-    <ClInclude Include="i2-delegation.h">
-      <Filter>Headerdateien</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <CustomBuild Include="delegation-type.conf">
-      <Filter>Quelldateien</Filter>
-    </CustomBuild>
-  </ItemGroup>
-</Project>
\ No newline at end of file
diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp
deleted file mode 100644 (file)
index c07424a..0000000
+++ /dev/null
@@ -1,221 +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 "delegation/delegationcomponent.h"
-#include "remoting/endpointmanager.h"
-#include "base/objectlock.h"
-#include "base/logger_fwd.h"
-#include <algorithm>
-#include "base/dynamictype.h"
-#include <boost/foreach.hpp>
-#include <boost/tuple/tuple.hpp>
-
-using namespace icinga;
-
-REGISTER_TYPE(DelegationComponent);
-
-DelegationComponent::DelegationComponent(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{ }
-
-void DelegationComponent::Start(void)
-{
-       m_DelegationTimer = boost::make_shared<Timer>();
-
-       m_DelegationTimer->SetInterval(30);
-       m_DelegationTimer->OnTimerExpired.connect(boost::bind(&DelegationComponent::DelegationTimerHandler, this));
-       m_DelegationTimer->Start();
-       m_DelegationTimer->Reschedule(Utility::GetTime() + 10);
-}
-
-bool DelegationComponent::IsEndpointChecker(const Endpoint::Ptr& endpoint)
-{
-       return (endpoint->HasSubscription("checker"));
-}
-
-std::set<Endpoint::Ptr> DelegationComponent::GetCheckerCandidates(const Service::Ptr& service) const
-{
-       std::set<Endpoint::Ptr> candidates;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
-               Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
-               String myIdentity = EndpointManager::GetInstance()->GetIdentity();
-
-               /* ignore local-only endpoints (unless this is a local-only instance) */
-               if (endpoint->IsLocal() && !myIdentity.IsEmpty())
-                       continue;
-
-               /* ignore disconnected endpoints */
-               if (!endpoint->IsConnected() && endpoint->GetName() != myIdentity)
-                       continue;
-
-               /* ignore endpoints that aren't running the checker component */
-               if (!IsEndpointChecker(endpoint))
-                       continue;
-
-               /* ignore endpoints that aren't allowed to check this service */
-               if (!service->IsAllowedChecker(endpoint->GetName()))
-                       continue;
-
-               candidates.insert(endpoint);
-       }
-
-       return candidates;
-}
-
-void DelegationComponent::DelegationTimerHandler(void)
-{
-       std::map<Endpoint::Ptr, int> histogram;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
-               Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
-
-               histogram[endpoint] = 0;
-       }
-
-       std::vector<Service::Ptr> services;
-
-       /* build "checker -> service count" histogram */
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = dynamic_pointer_cast<Service>(object);
-
-               if (!service)
-                       continue;
-
-               services.push_back(service);
-
-               String checker = service->GetCurrentChecker();
-
-               if (checker.IsEmpty())
-                       continue;
-
-               Endpoint::Ptr endpoint = Endpoint::GetByName(checker);
-
-               if (!endpoint)
-                       continue;
-
-               histogram[endpoint]++;
-       }
-
-       int delegated = 0;
-
-       /* re-assign services */
-       BOOST_FOREACH(const Service::Ptr& service, services) {
-               String checker = service->GetCurrentChecker();
-
-               Endpoint::Ptr oldEndpoint = Endpoint::GetByName(checker);
-
-               std::set<Endpoint::Ptr> candidates = GetCheckerCandidates(service);
-
-               int avg_services = 0, overflow_tolerance = 0;
-               std::vector<Endpoint::Ptr>::iterator cit;
-
-               if (!candidates.empty()) {
-#ifdef _DEBUG
-                       std::ostringstream msgbuf;
-                       msgbuf << "Service: " << service->GetName() << ", candidates: " << candidates.size();
-                       Log(LogDebug, "delegation", msgbuf.str());
-#endif /* _DEBUG */
-
-                       BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
-                               avg_services += histogram[candidate];
-                       }
-
-                       avg_services /= candidates.size();
-                       overflow_tolerance = candidates.size() * 2;
-               }
-
-               /* don't re-assign service if the checker is still valid
-                * and doesn't have too many services */
-
-               if (oldEndpoint && oldEndpoint->IsConnected() &&
-                   candidates.find(oldEndpoint) != candidates.end() &&
-                   histogram[oldEndpoint] <= avg_services + overflow_tolerance)
-                       continue;
-
-               /* clear the service's current checker */
-               if (!checker.IsEmpty()) {
-                       {
-                               ObjectLock olock(service);
-                               service->SetCurrentChecker("");
-                       }
-
-                       if (oldEndpoint)
-                               histogram[oldEndpoint]--;
-               }
-
-               /* find a new checker for the service */
-               BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
-                       /* does this checker already have too many services */
-                       if (histogram[candidate] > avg_services)
-                               continue;
-
-                       {
-                               ObjectLock olock(service);
-                               service->SetCurrentChecker(candidate->GetName());
-                       }
-
-                       histogram[candidate]++;
-
-                       /* reschedule the service; this avoids "check floods"
-                        * when a lot of services are re-assigned that haven't
-                        * been checked recently. */
-                       service->UpdateNextCheck();
-
-                       delegated++;
-
-                       break;
-               }
-
-               if (candidates.empty()) {
-                       if (service->GetState() != StateUncheckable && service->GetEnableActiveChecks()) {
-                               Dictionary::Ptr cr = boost::make_shared<Dictionary>();
-
-                               double now = Utility::GetTime();
-                               cr->Set("schedule_start", now);
-                               cr->Set("schedule_end", now);
-                               cr->Set("execution_start", now);
-                               cr->Set("execution_end", now);
-
-                               cr->Set("state", StateUncheckable);
-                               cr->Set("output", "No checker is available for this service.");
-
-                               service->ProcessCheckResult(cr);
-
-                               Log(LogWarning, "delegation", "Can't delegate service: " + service->GetName());
-                       }
-
-                       continue;
-               }
-
-               ASSERT(!service->GetCurrentChecker().IsEmpty());
-       }
-
-       Endpoint::Ptr endpoint;
-       int count;
-       BOOST_FOREACH(boost::tie(endpoint, count), histogram) {
-               std::ostringstream msgbuf;
-               msgbuf << "histogram: " << endpoint->GetName() << " - " << count;
-               Log(LogInformation, "delegation", msgbuf.str());
-       }
-
-       std::ostringstream msgbuf;
-       msgbuf << "Updated delegations for " << delegated << " services";
-       Log(LogInformation, "delegation", msgbuf.str());
-}
diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h
deleted file mode 100644 (file)
index 362bf83..0000000
+++ /dev/null
@@ -1,55 +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 DELEGATIONCOMPONENT_H
-#define DELEGATIONCOMPONENT_H
-
-#include "icinga/service.h"
-#include "remoting/endpoint.h"
-#include "base/dynamicobject.h"
-#include "base/timer.h"
-
-namespace icinga
-{
-
-/**
- * @ingroup delegation
- */
-class DelegationComponent : public DynamicObject
-{
-public:
-       DECLARE_PTR_TYPEDEFS(DelegationComponent);
-
-       DelegationComponent(const Dictionary::Ptr& serializedUpdate);
-
-       virtual void Start(void);
-
-private:
-       Timer::Ptr m_DelegationTimer;
-
-       void DelegationTimerHandler(void);
-
-       std::set<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const;
-
-       static bool IsEndpointChecker(const Endpoint::Ptr& endpoint);
-};
-
-}
-
-#endif /* DELEGATIONCOMPONENT_H */
index d5f8ce485aa5ace8dacddfd3e676494999218a68..d0bab258016ea875c7bd71444b04bad8c0faa6b2 100644 (file)
@@ -27,19 +27,12 @@ using namespace icinga;
 
 REGISTER_TYPE(DemoComponent);
 
-DemoComponent::DemoComponent(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{ }
-
 /**
  * Starts the component.
  */
 void DemoComponent::Start(void)
 {
-       m_Endpoint = Endpoint::MakeEndpoint("demo", false);
-       m_Endpoint->RegisterTopicHandler("demo::HelloWorld",
-           boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2,
-           _3));
+       DynamicObject::Start();
 
        m_DemoTimer = boost::make_shared<Timer>();
        m_DemoTimer->SetInterval(5);
@@ -52,7 +45,7 @@ void DemoComponent::Start(void)
  */
 void DemoComponent::Stop(void)
 {
-       m_Endpoint->Unregister();
+       /* Nothing to do here. */
 }
 
 /**
@@ -62,20 +55,5 @@ void DemoComponent::Stop(void)
  */
 void DemoComponent::DemoTimerHandler(void)
 {
-       Log(LogInformation, "demo", "Sending multicast 'hello world' message.");
-
-       RequestMessage request;
-       request.SetMethod("demo::HelloWorld");
-
-       EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
-}
-
-/**
- * Processes demo::HelloWorld messages.
- */
-void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender,
-    const RequestMessage&)
-{
-       Log(LogInformation, "demo", "Got 'hello world' from identity=" +
-           (sender ? sender->GetName() : "(anonymous)"));
+       Log(LogInformation, "demo", "Hello World!");
 }
index a1bcba8716e870350a79014de62955e9581e66f8..ea78933c6ae16ef82b9270568482a4d729e7e630 100644 (file)
@@ -35,17 +35,13 @@ class DemoComponent : public DynamicObject
 public:
        DECLARE_PTR_TYPEDEFS(DemoComponent);
 
-       DemoComponent(const Dictionary::Ptr& serializedUpdate);
-
        virtual void Start(void);
        virtual void Stop(void);
 
 private:
        Timer::Ptr m_DemoTimer;
-       Endpoint::Ptr m_Endpoint;
 
        void DemoTimerHandler(void);
-       void HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
 };
 
 }
index 8dd322f40eb96618c60bc707e4ece767e56716ca..a24756ba147f81c23890c9cbe9e9887c48609097 100644 (file)
@@ -32,17 +32,11 @@ using namespace icinga;
 
 REGISTER_TYPE(IdoMysqlDbConnection);
 
-IdoMysqlDbConnection::IdoMysqlDbConnection(const Dictionary::Ptr& serializedUpdate)
-       : DbConnection(serializedUpdate), m_Connected(false)
+void IdoMysqlDbConnection::Start(void)
 {
-       RegisterAttribute("host", Attribute_Config, &m_Host);
-       RegisterAttribute("port", Attribute_Config, &m_Port);
-       RegisterAttribute("user", Attribute_Config, &m_User);
-       RegisterAttribute("password", Attribute_Config, &m_Password);
-       RegisterAttribute("database", Attribute_Config, &m_Database);
+       DbConnection::Start();
 
-       RegisterAttribute("instance_name", Attribute_Config, &m_InstanceName);
-       RegisterAttribute("instance_description", Attribute_Config, &m_InstanceDescription);
+       m_Connected = false;
 
        m_TxTimer = boost::make_shared<Timer>();
        m_TxTimer->SetInterval(5);
@@ -395,7 +389,7 @@ void IdoMysqlDbConnection::ExecuteQuery(const DbQuery& query)
                                return;
 
                        if (!first)
-                               qbuf << " AND ";
+                               where << " AND ";
 
                        where << key << " = " << value;
 
@@ -492,3 +486,33 @@ void IdoMysqlDbConnection::ExecuteQuery(const DbQuery& query)
                        SetInsertID(query.Object, GetLastInsertID());
        }
 }
+
+void IdoMysqlDbConnection::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 IdoMysqlDbConnection::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");
+       }
+}
index 61fb8f593ad1227c0266ec1df3edef4636e96e74..10c7e136ff162050844c38668cacacafad665cc8 100644 (file)
@@ -37,27 +37,29 @@ namespace icinga
 class IdoMysqlDbConnection : public DbConnection
 {
 public:
-       typedef shared_ptr<IdoMysqlDbConnection> Ptr;
-       typedef weak_ptr<IdoMysqlDbConnection> WeakPtr;
-
-       IdoMysqlDbConnection(const Dictionary::Ptr& serializedUpdate);
-       virtual void Stop(void);
+       DECLARE_PTR_TYPEDEFS(IdoMysqlDbConnection);
 
        //virtual void UpdateObject(const DbObject::Ptr& dbobj, DbUpdateType kind);
 
 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);
+
        virtual void ActivateObject(const DbObject::Ptr& dbobj);
        virtual void DeactivateObject(const DbObject::Ptr& dbobj);
        virtual void ExecuteQuery(const DbQuery& query);
 
 private:
-       Attribute<String> m_Host;
-       Attribute<long> m_Port;
-       Attribute<String> m_User;
-       Attribute<String> m_Password;
-       Attribute<String> m_Database;
-       Attribute<String> m_InstanceName;
-       Attribute<String> m_InstanceDescription;
+       String m_Host;
+       Value m_Port;
+       String m_User;
+       String m_Password;
+       String m_Database;
+       String m_InstanceName;
+       String m_InstanceDescription;
 
        DbReference m_InstanceID;
 
index ecbcfb91d9b3489aef181f61ae755dd937e3ddf1..8335588d4ee283d22d85894b7ec6a4f480fa646e 100644 (file)
@@ -50,13 +50,13 @@ String CommandsTable::GetName(void) const
 
 void CommandsTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("CheckCommand")) {
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects<CheckCommand>()) {
                addRowFn(object);
        }
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("EventCommand")) {
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects<EventCommand>()) {
                addRowFn(object);
        }
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("NotificationCommand")) {
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects<NotificationCommand>()) {
                addRowFn(object);
        }
 }
index 6383107f6ad7b36f1a26cc74c5ebd0e396a145de..ee782b0ca2da67e2eda311d1811b273355b5a1dd 100644 (file)
@@ -58,8 +58,7 @@ String CommentsTable::GetName(void) const
 
 void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = static_pointer_cast<Service>(object);
+       BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
                Dictionary::Ptr comments = service->GetComments();
 
                if (!comments)
index 317fbced59df632479eff5a3689283ce7548ae91..32000fe5a00d122ce7780378eae33cbd18ce618d 100644 (file)
@@ -36,20 +36,13 @@ static int l_ClientsConnected = 0;
 static int l_Connections = 0;
 static boost::mutex l_ComponentMutex;
 
-LivestatusComponent::LivestatusComponent(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("socket_type", Attribute_Config, &m_SocketType);
-       RegisterAttribute("socket_path", Attribute_Config, &m_SocketPath);
-       RegisterAttribute("host", Attribute_Config, &m_Host);
-       RegisterAttribute("port", Attribute_Config, &m_Port);
-}
-
 /**
  * Starts the component.
  */
 void LivestatusComponent::Start(void)
 {
+       DynamicObject::Start();
+
        if (GetSocketType() == "tcp") {
                TcpSocket::Ptr socket = boost::make_shared<TcpSocket>();
                socket->Bind(GetHost(), GetPort(), AF_INET);
@@ -169,3 +162,27 @@ void LivestatusComponent::ClientThreadProc(const Socket::Ptr& client)
                l_ClientsConnected--;
        }
 }
+
+void LivestatusComponent::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("host", m_Host);
+               bag->Set("port", m_Port);
+       }
+}
+
+void LivestatusComponent::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_Host = bag->Get("host");
+               m_Port = bag->Get("port");
+       }
+}
index ad74c3829b32e222fe7721f359b6aba90fca72c6..7c959422242d41c72a98c9331c1b0a89a8e2eae1 100644 (file)
@@ -36,10 +36,6 @@ namespace livestatus
 class LivestatusComponent : public DynamicObject
 {
 public:
-       LivestatusComponent(const Dictionary::Ptr& serializedUpdate);
-
-       virtual void Start(void);
-
        String GetSocketType(void) const;
        String GetSocketPath(void) const;
        String GetHost(void) const;
@@ -48,11 +44,17 @@ public:
        static int GetClientsConnected(void);
        static int GetConnections(void);
 
+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:
-       Attribute<String> m_SocketType;
-       Attribute<String> m_SocketPath;
-       Attribute<String> m_Host;
-       Attribute<String> m_Port;
+       String m_SocketType;
+       String m_SocketPath;
+       String m_Host;
+       String m_Port;
 
        void ServerThreadProc(const Socket::Ptr& server);
        void ClientThreadProc(const Socket::Ptr& client);
index aa58d97de4ae0eb1786a08f4f1ab1860f2623f61..be3319d6716db7f9772239c7a1f3e32a07d81fbb 100644 (file)
@@ -45,8 +45,8 @@ String ContactGroupsTable::GetName(void) const
 
 void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
-               addRowFn(object);
+       BOOST_FOREACH(const UserGroup::Ptr& ug, DynamicType::GetObjects<UserGroup>()) {
+               addRowFn(ug);
        }
 }
 
index 0df56c0f6f908ab4c9bfe4bb55781188107ad982..784faf6d39dd125ba745bca9b3379e4280bba0b9 100644 (file)
@@ -63,8 +63,8 @@ String ContactsTable::GetName(void) const
 
 void ContactsTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
-               addRowFn(object);
+       BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects<User>()) {
+               addRowFn(user);
        }
 }
 
index 0911341bcf140f33a09e75e82d8c3c5d8ceba307..eca8fc7582a735ac4277053ecd24d7115bc7e913 100644 (file)
@@ -58,8 +58,7 @@ String DowntimesTable::GetName(void) const
 
 void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = static_pointer_cast<Service>(object);
+       BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
                Dictionary::Ptr downtimes = service->GetDowntimes();
 
                if (!downtimes)
index 990a2d857384d38c305cb0266d34ee13fd875c1d..dcc358e39330dc201949c32da96040268be816e9 100644 (file)
@@ -69,8 +69,8 @@ String HostGroupsTable::GetName(void) const
 
 void HostGroupsTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
-               addRowFn(object);
+       BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjects<HostGroup>()) {
+               addRowFn(hg);
        }
 }
 
index c33d19dff50686c65c6a0b6a706de836be95280f..d5af3c8a3173d998385d7181eba857b23ce33fd1 100644 (file)
@@ -167,8 +167,8 @@ String HostsTable::GetName(void) const
 
 void HostsTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
-               addRowFn(object);
+       BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
+               addRowFn(host);
        }
 }
 
index 0904173fc3d98bc3431be6483c790262be2cc326..ef98951117ce0008ef49cd42ad367f36f885b36c 100644 (file)
@@ -60,8 +60,8 @@ String ServiceGroupsTable::GetName(void) const
 
 void ServiceGroupsTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
-               addRowFn(object);
+       BOOST_FOREACH(const ServiceGroup::Ptr& sg, DynamicType::GetObjects<ServiceGroup>()) {
+               addRowFn(sg);
        }
 }
 
index 2b13b59e9bd40120c0b26e6c36f9808ab3ff3917..941e3a7dea8f528efee6ecb023dd157941a3afd3 100644 (file)
@@ -136,8 +136,8 @@ String ServicesTable::GetName(void) const
 
 void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               addRowFn(object);
+       BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
+               addRowFn(service);
        }
 }
 
index ac8417e5383bd72b6833130fafdba6f334ee4b50..e3ed9e161705e3e0f514e0991cbf725c0fb6d89e 100644 (file)
@@ -21,6 +21,8 @@
 #include "livestatus/component.h"
 #include "icinga/icingaapplication.h"
 #include "icinga/cib.h"
+#include "icinga/host.h"
+#include "icinga/service.h"
 #include "base/dynamictype.h"
 #include "base/utility.h"
 #include <boost/smart_ptr/make_shared.hpp>
@@ -334,12 +336,12 @@ Value StatusTable::IntervalLengthAccessor(const Value& row)
 
 Value StatusTable::NumHostsAccessor(const Value& row)
 {
-       return static_cast<long>(DynamicType::GetObjects("Host").size());
+       return DynamicType::GetObjects<Host>().size();
 }
 
 Value StatusTable::NumServicesAccessor(const Value& row)
 {
-       return static_cast<long>(DynamicType::GetObjects("Service").size());
+       return DynamicType::GetObjects<Service>().size();
 }
 
 Value StatusTable::ProgramVersionAccessor(const Value& row)
index 865748d9774ff6bb4b3f65d72fa5cc7a3f9c8c75..50e05de5ccadc3da1f2de56d6d1ec3fa90c56056 100644 (file)
@@ -50,8 +50,8 @@ String TimePeriodsTable::GetName(void) const
 
 void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("TimePeriod")) {
-               addRowFn(object);
+       BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjects<TimePeriod>()) {
+               addRowFn(tp);
        }
 }
 
index 9fdc6e90e3c66a17a537424ada61b1b5add79317..c2cf58870a4daa132c4f7e9def1d9cf9c7d07c51 100644 (file)
@@ -30,19 +30,15 @@ using namespace icinga;
 
 REGISTER_TYPE(NotificationComponent);
 
-NotificationComponent::NotificationComponent(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{ }
-
 /**
  * Starts the component.
  */
 void NotificationComponent::Start(void)
 {
-       m_Endpoint = Endpoint::MakeEndpoint("notification", false);
-       m_Endpoint->RegisterTopicHandler("icinga::SendNotifications",
-           boost::bind(&NotificationComponent::SendNotificationsRequestHandler, this, _2,
-           _3));
+       DynamicObject::Start();
+
+       Service::OnNotificationsRequested.connect(bind(&NotificationComponent::SendNotificationsHandler, this, _1,
+           _2, _3, _4, _5));
 
        m_NotificationTimer = boost::make_shared<Timer>();
        m_NotificationTimer->SetInterval(5);
@@ -50,14 +46,6 @@ void NotificationComponent::Start(void)
        m_NotificationTimer->Start();
 }
 
-/**
- * Stops the component.
- */
-void NotificationComponent::Stop(void)
-{
-       m_Endpoint->Unregister();
-}
-
 /**
  * Periodically sends notifications.
  *
@@ -67,9 +55,7 @@ void NotificationComponent::NotificationTimerHandler(void)
 {
        double now = Utility::GetTime();
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Notification")) {
-               Notification::Ptr notification = dynamic_pointer_cast<Notification>(object);
-
+       BOOST_FOREACH(const Notification::Ptr& notification, DynamicType::GetObjects<Notification>()) {
                if (notification->GetNotificationInterval() <= 0)
                        continue;
 
@@ -88,8 +74,6 @@ void NotificationComponent::NotificationTimerHandler(void)
                        notification->SetNextNotification(Utility::GetTime() + notification->GetNotificationInterval());
                }
 
-               bool send_notification;
-
                {
                        ObjectLock olock(service);
 
@@ -120,34 +104,8 @@ void NotificationComponent::NotificationTimerHandler(void)
 /**
  * Processes icinga::SendNotifications messages.
  */
-void NotificationComponent::SendNotificationsRequestHandler(const Endpoint::Ptr& sender,
-    const RequestMessage& request)
+void NotificationComponent::SendNotificationsHandler(const Service::Ptr& service, NotificationType type,
+    const Dictionary::Ptr& cr, const String& author, const String& text)
 {
-       MessagePart params;
-       if (!request.GetParams(&params))
-               return;
-
-       String svc;
-       if (!params.Get("service", &svc))
-               return;
-
-       int type;
-       if (!params.Get("type", &type))
-               return;
-
-       Dictionary::Ptr cr;
-       if (!params.Get("check_result", &cr))
-               return;
-
-       Service::Ptr service = Service::GetByName(svc);
-
-       if (!service)
-               return;
-
-       String author;
-       params.Get("author", &author);
-       String text;
-       params.Get("text", &text);
-
        service->SendNotifications(static_cast<NotificationType>(type), cr, author, text);
 }
index 5cff72798c240deefb186b7310bb9b9697fcb04d..4375c4c8a5e215ea6543843f962d7315f6f2403a 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef NOTIFICATIONCOMPONENT_H
 #define NOTIFICATIONCOMPONENT_H
 
-#include "remoting/endpoint.h"
+#include "icinga/service.h"
 #include "base/dynamicobject.h"
 #include "base/timer.h"
 
@@ -35,17 +35,14 @@ class NotificationComponent : public DynamicObject
 public:
        DECLARE_PTR_TYPEDEFS(NotificationComponent);
 
-       NotificationComponent(const Dictionary::Ptr& serializedUpdate);
-
        virtual void Start(void);
-       virtual void Stop(void);
 
 private:
        Timer::Ptr m_NotificationTimer;
-       Endpoint::Ptr m_Endpoint;
 
        void NotificationTimerHandler(void);
-       void SendNotificationsRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
+       void SendNotificationsHandler(const Service::Ptr& service, NotificationType type,
+           const Dictionary::Ptr& cr, const String& author, const String& text);
 };
 
 }
diff --git a/components/replication/.gitignore b/components/replication/.gitignore
deleted file mode 100644 (file)
index 90c7869..0000000
+++ /dev/null
@@ -1 +0,0 @@
-replication-type.cpp
diff --git a/components/replication/Makefile.am b/components/replication/Makefile.am
deleted file mode 100644 (file)
index 56bcc81..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-pkglib_LTLIBRARIES = \
-       libreplication.la
-
-EXTRA_DIST = \
-       replication-type.conf
-
-.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig.c
-       $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
-
-libreplication_la_SOURCES = \
-       replicationcomponent.cpp \
-       replicationcomponent.h \
-       replication-type.cpp
-
-libreplication_la_CPPFLAGS = \
-       $(LTDLINCL) \
-       $(BOOST_CPPFLAGS) \
-       -I${top_srcdir}/lib \
-       -I${top_srcdir}/components
-
-libreplication_la_LDFLAGS = \
-       $(BOOST_LDFLAGS) \
-       -module \
-       -no-undefined \
-       @RELEASE_INFO@ \
-       @VERSION_INFO@
-
-libreplication_la_LIBADD = \
-       $(BOOST_SIGNALS_LIB) \
-       $(BOOST_THREAD_LIB) \
-       $(BOOST_SYSTEM_LIB) \
-       ${top_builddir}/lib/base/libbase.la \
-       ${top_builddir}/lib/config/libconfig.la \
-       ${top_builddir}/lib/remoting/libremoting.la \
-       ${top_builddir}/lib/icinga/libicinga.la
diff --git a/components/replication/replication-type.conf b/components/replication/replication-type.conf
deleted file mode 100644 (file)
index 559acfd..0000000
+++ /dev/null
@@ -1,21 +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.             *
- ******************************************************************************/
-
-type ReplicationComponent {
-}
diff --git a/components/replication/replication.filters b/components/replication/replication.filters
deleted file mode 100644 (file)
index 411118f..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="Quelldateien">
-      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
-    <Filter Include="Headerdateien">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="replicationcomponent.h">
-      <Filter>Headerdateien</Filter>
-    </ClInclude>
-    <ClInclude Include="i2-replication.h">
-      <Filter>Headerdateien</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="replicationcomponent.cpp">
-      <Filter>Quelldateien</Filter>
-    </ClCompile>
-  </ItemGroup>
-</Project>
diff --git a/components/replication/replication.vcxproj b/components/replication/replication.vcxproj
deleted file mode 100644 (file)
index 5e3035b..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Debug|x64">
-      <Configuration>Debug</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|x64">
-      <Configuration>Release</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{704DDD8E-9E6D-4C22-80BD-6DE10F3A5E1C}</ProjectGuid>
-    <Keyword>Win32Proj</Keyword>
-    <RootNamespace>replication</RootNamespace>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <LinkIncremental>true</LinkIncremental>
-    <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
-    <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
-    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(Platform)\$(Configuration)\</IntDir>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <LinkIncremental>true</LinkIncremental>
-    <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
-    <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
-    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(Platform)\$(Configuration)\</IntDir>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <LinkIncremental>false</LinkIncremental>
-    <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
-    <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
-    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(Platform)\$(Configuration)\</IntDir>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <LinkIncremental>false</LinkIncremental>
-    <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
-    <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
-    <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
-    <IntDir>$(Platform)\$(Configuration)\</IntDir>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MultiProcessorCompilation>true</MultiProcessorCompilation>
-      <MinimalRebuild>false</MinimalRebuild>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MultiProcessorCompilation>true</MultiProcessorCompilation>
-      <MinimalRebuild>false</MinimalRebuild>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MultiProcessorCompilation>true</MultiProcessorCompilation>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MultiProcessorCompilation>true</MultiProcessorCompilation>
-      <PrecompiledHeader>NotUsing</PrecompiledHeader>
-    </ClCompile>
-    <Link>
-      <SubSystem>Windows</SubSystem>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClInclude Include="replicationcomponent.h" />
-    <ClInclude Include="i2-replication.h" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="replication-type.cpp" />
-    <ClCompile Include="replicationcomponent.cpp" />
-  </ItemGroup>
-  <ItemGroup>
-    <CustomBuild Include="replication-type.conf">
-      <FileType>Document</FileType>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
-      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Preparing config fragment for embedding</Message>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
-      <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Preparing config fragment for embedding</Message>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
-      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Preparing config fragment for embedding</Message>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
-      <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Preparing config fragment for embedding</Message>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cpp;%(Outputs)</Outputs>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).cpp;%(Outputs)</Outputs>
-      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
-      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
-      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
-      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
-    </CustomBuild>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
-</Project>
\ No newline at end of file
diff --git a/components/replication/replication.vcxproj.filters b/components/replication/replication.vcxproj.filters
deleted file mode 100644 (file)
index 0b5d123..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <ClInclude Include="i2-replication.h">
-      <Filter>Headerdateien</Filter>
-    </ClInclude>
-    <ClInclude Include="replicationcomponent.h">
-      <Filter>Headerdateien</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <Filter Include="Headerdateien">
-      <UniqueIdentifier>{85c17050-f3b5-4dbe-9d86-2c4838ddd7e0}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="Quelldateien">
-      <UniqueIdentifier>{0caf70c2-14a5-4d97-a2d0-0afbe6028b49}</UniqueIdentifier>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="replicationcomponent.cpp">
-      <Filter>Quelldateien</Filter>
-    </ClCompile>
-    <ClCompile Include="replication-type.cpp">
-      <Filter>Quelldateien</Filter>
-    </ClCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <CustomBuild Include="replication-type.conf">
-      <Filter>Quelldateien</Filter>
-    </CustomBuild>
-  </ItemGroup>
-</Project>
\ No newline at end of file
diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp
deleted file mode 100644 (file)
index 3491285..0000000
+++ /dev/null
@@ -1,268 +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 "replication/replicationcomponent.h"
-#include "icinga/service.h"
-#include "icinga/checkresultmessage.h"
-#include "remoting/endpointmanager.h"
-#include "base/dynamictype.h"
-#include "base/objectlock.h"
-#include "base/logger_fwd.h"
-#include <boost/foreach.hpp>
-
-using namespace icinga;
-
-REGISTER_TYPE(ReplicationComponent);
-
-ReplicationComponent::ReplicationComponent(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{ }
-
-/**
- * Starts the component.
- */
-void ReplicationComponent::Start(void)
-{
-       m_Endpoint = Endpoint::MakeEndpoint("replication", false);
-
-       DynamicObject::OnRegistered.connect(boost::bind(&ReplicationComponent::LocalObjectRegisteredHandler, this, _1));
-       DynamicObject::OnUnregistered.connect(boost::bind(&ReplicationComponent::LocalObjectUnregisteredHandler, this, _1));
-       DynamicObject::OnTransactionClosing.connect(boost::bind(&ReplicationComponent::TransactionClosingHandler, this, _1, _2));
-       DynamicObject::OnFlushObject.connect(boost::bind(&ReplicationComponent::FlushObjectHandler, this, _1, _2));
-
-       Endpoint::OnConnected.connect(boost::bind(&ReplicationComponent::EndpointConnectedHandler, this, _1));
-
-       m_Endpoint->RegisterTopicHandler("config::ObjectUpdate",
-           boost::bind(&ReplicationComponent::RemoteObjectUpdateHandler, this, _3));
-       m_Endpoint->RegisterTopicHandler("config::ObjectRemoved",
-           boost::bind(&ReplicationComponent::RemoteObjectRemovedHandler, this, _3));
-
-       /* service status */
-       m_Endpoint->RegisterTopicHandler("checker::CheckResult",
-           boost::bind(&ReplicationComponent::CheckResultRequestHandler, _3));
-}
-
-/**
- * Stops the component.
- */
-void ReplicationComponent::Stop(void)
-{
-       m_Endpoint->Unregister();
-}
-
-void ReplicationComponent::CheckResultRequestHandler(const RequestMessage& request)
-{
-       CheckResultMessage params;
-       if (!request.GetParams(&params))
-               return;
-
-       String svcname = params.GetService();
-       Service::Ptr service = Service::GetByName(svcname);
-
-       Dictionary::Ptr cr = params.GetCheckResult();
-       if (!cr)
-               return;
-
-       if (cr->Contains("current_checker") && cr->Get("current_checker") == EndpointManager::GetInstance()->GetIdentity())
-               return;
-
-       Service::UpdateStatistics(cr);
-}
-
-void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint)
-{
-       /* no need to sync the config with local endpoints */
-       if (endpoint->IsLocalEndpoint())
-               return;
-
-       /* we just assume the other endpoint wants object updates */
-       endpoint->RegisterSubscription("config::ObjectUpdate");
-       endpoint->RegisterSubscription("config::ObjectRemoved");
-
-       DynamicType::Ptr type;
-       BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) {
-               std::set<DynamicObject::Ptr> objects;
-
-               BOOST_FOREACH(const DynamicObject::Ptr& object, dt->GetObjects()) {
-                       if (!ShouldReplicateObject(object))
-                               continue;
-
-                       RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", 0, true);
-                       EndpointManager::GetInstance()->SendUnicastMessage(m_Endpoint, endpoint, request);
-
-               }
-       }
-}
-
-RequestMessage ReplicationComponent::MakeObjectMessage(const DynamicObject::Ptr& object, const String& method, double sinceTx, bool includeProperties)
-{
-       RequestMessage msg;
-       msg.SetMethod(method);
-
-       MessagePart params;
-       msg.SetParams(params);
-
-       params.Set("name", object->GetName());
-       params.Set("type", object->GetType()->GetName());
-
-       String source = object->GetSource();
-
-       if (source.IsEmpty())
-               source = EndpointManager::GetInstance()->GetIdentity();
-
-       params.Set("source", source);
-
-       if (includeProperties)
-               params.Set("update", object->BuildUpdate(sinceTx, Attribute_Replicated | Attribute_Config));
-
-       return msg;
-}
-
-bool ReplicationComponent::ShouldReplicateObject(const DynamicObject::Ptr& object)
-{
-       return (!object->IsLocal());
-}
-
-void ReplicationComponent::LocalObjectRegisteredHandler(const DynamicObject::Ptr& object)
-{
-       if (!ShouldReplicateObject(object))
-               return;
-
-       EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint,
-           MakeObjectMessage(object, "config::ObjectUpdate", 0, true));
-}
-
-void ReplicationComponent::LocalObjectUnregisteredHandler(const DynamicObject::Ptr& object)
-{
-       if (!ShouldReplicateObject(object))
-               return;
-
-       EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint,
-           MakeObjectMessage(object, "config::ObjectRemoved", 0, false));
-}
-
-void ReplicationComponent::TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects)
-{
-       if (modifiedObjects.empty())
-               return;
-
-       std::ostringstream msgbuf;
-       msgbuf << "Sending " << modifiedObjects.size() << " replication updates.";
-       Log(LogInformation, "replication", msgbuf.str());
-
-       BOOST_FOREACH(const DynamicObject::WeakPtr& wobject, modifiedObjects) {
-               DynamicObject::Ptr object = wobject.lock();
-
-               if (!object)
-                       continue;
-
-               FlushObjectHandler(tx, object);
-       }
-}
-
-void ReplicationComponent::FlushObjectHandler(double tx, const DynamicObject::Ptr& object)
-{
-       if (!ShouldReplicateObject(object))
-               return;
-
-       /* Don't replicate objects that haven't had any local updates. */
-       if (object->GetLocalTx() < tx)
-               return;
-
-       RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", tx, true);
-       EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
-}
-
-void ReplicationComponent::RemoteObjectUpdateHandler(const RequestMessage& request)
-{
-       MessagePart params;
-       if (!request.GetParams(&params))
-               return;
-
-       String name;
-       if (!params.Get("name", &name))
-               return;
-
-       String type;
-       if (!params.Get("type", &type))
-               return;
-
-       String source;
-       if (!params.Get("source", &source))
-               return;
-
-       Dictionary::Ptr update;
-       if (!params.Get("update", &update))
-               return;
-
-       DynamicType::Ptr dtype = DynamicType::GetByName(type);
-       DynamicObject::Ptr object = dtype->GetObject(name);
-
-       // TODO: sanitize update, disallow __local
-
-       if (!object) {
-               object = dtype->CreateObject(update);
-
-               if (source == EndpointManager::GetInstance()->GetIdentity()) {
-                       /* the peer sent us an object that was originally created by us -
-                        * however it was deleted locally so we have to tell the peer to destroy
-                        * its copy of the object. */
-                       EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint,
-                           MakeObjectMessage(object, "config::ObjectRemoved", 0, false));
-
-                       return;
-               }
-
-               Log(LogDebug, "replication", "Received object from source: " + source);
-
-               object->SetSource(source);
-               object->Register();
-       } else {
-               if (object->IsLocal())
-                       BOOST_THROW_EXCEPTION(std::invalid_argument("Replicated remote object is marked as local."));
-
-               // TODO: disallow config updates depending on endpoint config
-
-               object->ApplyUpdate(update, Attribute_All);
-       }
-}
-
-void ReplicationComponent::RemoteObjectRemovedHandler(const RequestMessage& request)
-{
-       MessagePart params;
-       if (!request.GetParams(&params))
-               return;
-
-       String name;
-       if (!params.Get("name", &name))
-               return;
-
-       String type;
-       if (!params.Get("type", &type))
-               return;
-
-       DynamicObject::Ptr object = DynamicObject::GetObject(type, name);
-
-       if (!object)
-               return;
-
-       if (!object->IsLocal()) {
-               object->Unregister();
-       }
-}
diff --git a/components/replication/replicationcomponent.h b/components/replication/replicationcomponent.h
deleted file mode 100644 (file)
index 1950ef2..0000000
+++ /dev/null
@@ -1,65 +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 REPLICATIONCOMPONENT_H
-#define REPLICATIONCOMPONENT_H
-
-#include "base/dynamicobject.h"
-#include "remoting/endpoint.h"
-
-namespace icinga
-{
-
-/**
- * @ingroup replication
- */
-class ReplicationComponent : public DynamicObject
-{
-public:
-       DECLARE_PTR_TYPEDEFS(ReplicationComponent);
-
-       ReplicationComponent(const Dictionary::Ptr& serializedUpdate);
-
-       virtual void Start(void);
-       virtual void Stop(void);
-
-private:
-       Endpoint::Ptr m_Endpoint;
-
-       static void CheckResultRequestHandler(const RequestMessage& request);
-
-       void EndpointConnectedHandler(const Endpoint::Ptr& endpoint);
-
-       void LocalObjectRegisteredHandler(const DynamicObject::Ptr& object);
-       void LocalObjectUnregisteredHandler(const DynamicObject::Ptr& object);
-       void TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects);
-       void FlushObjectHandler(double tx, const DynamicObject::Ptr& object);
-
-       void RemoteObjectUpdateHandler(const RequestMessage& request);
-       void RemoteObjectRemovedHandler(const RequestMessage& request);
-
-       static RequestMessage MakeObjectMessage(const DynamicObject::Ptr& object,
-           const String& method, double sinceTx, bool includeProperties);
-
-       static bool ShouldReplicateObject(const DynamicObject::Ptr& object);
-};
-
-}
-
-#endif /* REPLICATIONCOMPONENT_H */
index 6cf9042d0ca8dc0952e4ccb28012c52e1487173c..6df0855f5df509d47839a943ba3f9552055c1093 100644 (file)
@@ -124,12 +124,10 @@ Makefile
 components/Makefile
 components/checker/Makefile
 components/compat/Makefile
-components/delegation/Makefile
 components/demo/Makefile
 components/ido_mysql/Makefile
 components/livestatus/Makefile
 components/notification/Makefile
-components/replication/Makefile
 docs/Doxyfile
 docs/Makefile
 etc/Makefile
index b15fb55ba04a42701739192bfc12b606984fcb8f..09bb0cf654f1377a0fca2eed5b4cee99593d133b 100644 (file)
@@ -6,3 +6,10 @@ sys.path.insert(0, '/home/gbeutner/strawberry/contrib/gdb')
 from icingadbg import register_icinga_printers
 register_icinga_printers()
 end
+
+python
+import sys
+sys.path.insert(0, '/home/gbeutner/gdb_printers/python')
+from libstdcxx.v6.printers import register_libstdcxx_printers
+register_libstdcxx_printers (None)
+end
index d11be413a2e4ea77e8d6289018bb925ba8c992e2..8491cff1e784c7c3f52a634fef107e38e0d67a66 100644 (file)
@@ -84,23 +84,6 @@ stop() {
        echo "Done"
 }
 
-# Reload Icinga 2
-reload() {
-        printf "Reloading Icinga 2: "
-        if [ ! -e $ICINGA2_PID_FILE ]; then
-                echo "The PID file '$ICINGA2_PID_FILE' does not exist."
-                exit 1
-        fi
-        
-       pid=`cat $ICINGA2_PID_FILE`
-       
-        if ! kill -HUP $pid >/dev/null 2>&1; then
-               echo "Failed - Icinga 2 is not running."
-       else
-               echo "Done"
-       fi
-}
-
 # Print status for Icinga 2
 status() {
        printf "Icinga 2 status: "
@@ -128,11 +111,8 @@ case "$1" in
         stop
         start
         ;;
-  reload)
-        reload
-        ;;
   *)
-        echo $"Usage: $0 {start|stop|restart|reload|status}"
+        echo $"Usage: $0 {start|stop|restart|status}"
         exit 1
 esac
 exit 0
index 961a6d20da5ddb77ed6e12b863171581e1dd4ab4..13fccb178f71580d529997fb5bf1947bc63c9189 100644 (file)
@@ -27,9 +27,7 @@ icinga2_LDADD = \
        ${top_builddir}/lib/config/libconfig.la \
        -dlopen ${top_builddir}/lib/icinga/libicinga.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/livestatus/liblivestatus.la \
        -dlopen ${top_builddir}/components/notification/libnotification.la
index 94e7fed28e70394c66258c1a6477fc7bfe6da345..3772479c5b5896e2be6b638715cac415dad6bda5 100644 (file)
@@ -39,18 +39,10 @@ using namespace icinga;
 namespace po = boost::program_options;
 
 static po::variables_map g_AppParams;
-static String g_ConfigUnit;
-
-#ifndef _WIN32
-static bool l_ReloadConfig = false;
-static Timer::Ptr l_ReloadConfigTimer;
-#endif /* _WIN32 */
 
 static bool LoadConfigFiles(bool validateOnly)
 {
-       ConfigCompilerContext context;
-
-       ConfigCompilerContext::SetContext(&context);
+       ConfigCompilerContext::GetInstance()->Reset();
 
        BOOST_FOREACH(const String& configPath, g_AppParams["config"].as<std::vector<String> >()) {
                ConfigCompiler::CompileFile(configPath);
@@ -61,11 +53,9 @@ static bool LoadConfigFiles(bool validateOnly)
                ConfigCompiler::CompileText(name, fragment);
        }
 
-       ConfigCompilerContext::SetContext(NULL);
-
        bool hasError = false;
 
-       BOOST_FOREACH(const ConfigCompilerError& error, context.GetErrors()) {
+       BOOST_FOREACH(const ConfigCompilerError& error, ConfigCompilerContext::GetInstance()->GetErrors()) {
                if (!error.Warning) {
                        hasError = true;
                        break;
@@ -74,13 +64,13 @@ static bool LoadConfigFiles(bool validateOnly)
 
        /* Don't link or validate if we have already encountered at least one error. */
        if (!hasError) {
-               context.LinkItems();
-               context.ValidateItems();
+               ConfigItem::LinkItems();
+               ConfigItem::ValidateItems();
        }
 
        hasError = false;
 
-       BOOST_FOREACH(const ConfigCompilerError& error, context.GetErrors()) {
+       BOOST_FOREACH(const ConfigCompilerError& error, ConfigCompilerContext::GetInstance()->GetErrors()) {
                if (error.Warning) {
                        Log(LogWarning, "icinga-app", "Config warning: " + error.Message);
                } else {
@@ -95,40 +85,14 @@ static bool LoadConfigFiles(bool validateOnly)
        if (validateOnly)
                return true;
 
-       context.ActivateItems();
+       ConfigItem::ActivateItems();
 
-       if (!g_ConfigUnit.IsEmpty()) {
-               /* ActivateItems has taken care of replacing all previous items
-                * with new versions - which are automatically in a different
-                * compilation unit. This UnloadUnit() call takes care of
-                * removing all left-over items from the previous config. */
-               ConfigItem::UnloadUnit(g_ConfigUnit);
-       }
-
-       g_ConfigUnit = context.GetUnit();
+       ConfigItem::DiscardItems();
+       ConfigType::DiscardTypes();
 
        return true;
 }
 
-#ifndef _WIN32
-static void ReloadConfigTimerHandler(void)
-{
-       if (l_ReloadConfig) {
-               Log(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files.");
-               LoadConfigFiles(false);
-
-               l_ReloadConfig = false;
-       }
-}
-
-static void SigHupHandler(int signum)
-{
-       ASSERT(signum == SIGHUP);
-
-       l_ReloadConfig = true;
-}
-#endif /* _WIN32 */
-
 static bool Daemonize(const String& stderrFile)
 {
 #ifndef _WIN32
@@ -343,17 +307,5 @@ int main(int argc, char **argv)
        if (!app)
                BOOST_THROW_EXCEPTION(std::runtime_error("Configuration must create an Application object."));
 
-#ifndef _WIN32
-       struct sigaction sa;
-       memset(&sa, 0, sizeof(sa));
-       sa.sa_handler = &SigHupHandler;
-       sigaction(SIGHUP, &sa, NULL);
-
-       l_ReloadConfigTimer = boost::make_shared<Timer>();
-       l_ReloadConfigTimer->SetInterval(1);
-       l_ReloadConfigTimer->OnTimerExpired.connect(boost::bind(&ReloadConfigTimerHandler));
-       l_ReloadConfigTimer->Start();
-#endif /* _WIN32 */
-
        return app->Run();
 }
index 2df5b68ef7137d1d628a603a6eb7268d6714eb16..978f8aa99e81717e81e4a453dbea438c7deda467 100644 (file)
@@ -1,6 +1,5 @@
 icinga2itldir = ${pkgdatadir}/itl
 icinga2itl_DATA = \
-       cluster.conf \
        command.conf \
        command-common.conf \
        constants.conf \
diff --git a/itl/cluster.conf b/itl/cluster.conf
deleted file mode 100644 (file)
index 1f32798..0000000
+++ /dev/null
@@ -1,21 +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.             *
- ******************************************************************************/
-
-library "replication"
-local object ReplicationComponent "replication" {}
index 0da22a8c0558817ad283e668835302f7294b6c39..0938abb3e2f66a25bb374b797394dc4ca5ab6e8c 100644 (file)
  ******************************************************************************/
 
 library "checker"
-local object CheckerComponent "checker" {}
-
-library "delegation"
-local object DelegationComponent "delegation" {}
+object CheckerComponent "checker" {}
 
 library "notification"
-local object NotificationComponent "notification" {}
+object NotificationComponent "notification" {}
index 0e5de80f55999e155fbeaf39c3684f7c354012e7..38806031e7559a207c3429f91309a317def04a61 100644 (file)
@@ -9,8 +9,6 @@ libbase_la_SOURCES =  \
        application.h \
        array.cpp \
        array.h \
-       attribute.cpp \
-       attribute.h \
        bufferedstream.cpp \
        bufferedstream.h \
        consolelogger.cpp \
index b3872e79da94c0186b659ed6bbd063812ce11baa..e822895aee006a0f5d289d9cc79c24d42412af35 100644 (file)
@@ -52,11 +52,11 @@ char **Application::m_ArgV;
 /**
  * Constructor for the Application class.
  */
-Application::Application(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate), m_PidFile(NULL)
+void Application::Start(void)
 {
-       if (!IsLocal())
-               BOOST_THROW_EXCEPTION(std::runtime_error("Application objects must be local."));
+       DynamicObject::Start();
+
+       m_PidFile = NULL;
 
 #ifdef _WIN32
        /* disable GUI-based error messages for LoadLibrary() */
@@ -82,10 +82,8 @@ Application::Application(const Dictionary::Ptr& serializedUpdate)
 /**
  * Destructor for the application class.
  */
-Application::~Application(void)
+void Application::Stop(void)
 {
-       m_Instance = NULL;
-
        m_ShuttingDown = true;
 
 #ifdef _WIN32
@@ -95,6 +93,11 @@ Application::~Application(void)
        ClosePidFile();
 }
 
+Application::~Application(void)
+{
+       m_Instance = NULL;
+}
+
 /**
  * Retrieves a pointer to the application singleton object.
  *
@@ -134,7 +137,7 @@ void Application::ShutdownTimerHandler(void)
                Log(LogInformation, "base", "Shutting down Icinga...");
                Application::GetInstance()->OnShutdown();
 
-               DynamicObject::DeactivateObjects();
+               DynamicObject::StopObjects();
                GetTP().Stop();
                m_ShuttingDown = false;
        }
@@ -314,12 +317,10 @@ void Application::DisplayBugMessage(void)
  * Signal handler for SIGINT. Prepares the application for cleanly
  * shutting down during the next execution of the event loop.
  *
- * @param signum The signal number.
+ * @param - The signal number.
  */
-void Application::SigIntHandler(int signum)
+void Application::SigIntHandler(int)
 {
-       ASSERT(signum == SIGINT);
-
        struct sigaction sa;
        memset(&sa, 0, sizeof(sa));
        sa.sa_handler = SIG_DFL;
@@ -336,12 +337,10 @@ void Application::SigIntHandler(int signum)
 /**
  * Signal handler for SIGABRT. Helps with debugging ASSERT()s.
  *
- * @param signum The signal number.
+ * @param - The signal number.
  */
-void Application::SigAbrtHandler(int signum)
+void Application::SigAbrtHandler(int)
 {
-       ASSERT(signum == SIGABRT);
-
 #ifndef _WIN32
        struct sigaction sa;
        memset(&sa, 0, sizeof(sa));
index fdea6a0924395f5c2f6c720d909a04ca535c3740..44eb65fb7d53e5b670bdc1d23ff591b303f0fc59 100644 (file)
@@ -37,7 +37,6 @@ class I2_BASE_API Application : public DynamicObject {
 public:
        DECLARE_PTR_TYPEDEFS(Application);
 
-       explicit Application(const Dictionary::Ptr& serializedUpdate);
        ~Application(void);
 
        static Application::Ptr GetInstance(void);
@@ -84,6 +83,9 @@ public:
        static ThreadPool& GetTP(void);
 
 protected:
+       virtual void Start(void);
+       virtual void Stop(void);
+
        void RunEventLoop(void) const;
 
        virtual void OnShutdown(void) = 0;
diff --git a/lib/base/attribute.cpp b/lib/base/attribute.cpp
deleted file mode 100644 (file)
index dca8281..0000000
+++ /dev/null
@@ -1,142 +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 "base/attribute.h"
-#include "base/utility.h"
-
-using namespace icinga;
-
-static boost::mutex l_Mutex;
-
-AttributeBase::AttributeBase(void)
-       : m_Value()
-{ }
-
-void AttributeBase::Set(const Value& value)
-{
-       boost::mutex::scoped_lock lock(l_Mutex);
-       InternalSet(value);
-}
-
-Value AttributeBase::Get(void) const
-{
-       boost::mutex::scoped_lock lock(l_Mutex);
-       return InternalGet();
-}
-
-AttributeBase::operator Value(void) const
-{
-       boost::mutex::scoped_lock lock(l_Mutex);
-       return InternalGet();
-}
-
-bool AttributeBase::IsEmpty(void) const
-{
-       boost::mutex::scoped_lock lock(l_Mutex);
-       return InternalGet().IsEmpty();
-}
-
-/**
- * Note: Caller must hold l_Mutex;
- */
-void AttributeBase::InternalSet(const Value& value)
-{
-       m_Value = value;
-}
-
-/**
- * Note: Caller must hold l_Mutex.
- */
-const Value& AttributeBase::InternalGet(void) const
-{
-       return m_Value;
-}
-
-AttributeHolder::AttributeHolder(AttributeType type, AttributeBase *boundAttribute)
-       : m_Type(type), m_Tx(0)
-{
-       if (boundAttribute) {
-               m_Attribute = boundAttribute;
-               m_OwnsAttribute = false;
-       } else {
-               m_Attribute = new Attribute<Value>();
-               m_OwnsAttribute = true;
-       }
-}
-
-AttributeHolder::AttributeHolder(const AttributeHolder& other)
-{
-       m_Type = other.m_Type;
-       m_Tx = other.m_Tx;
-       m_OwnsAttribute = other.m_OwnsAttribute;
-
-       if (other.m_OwnsAttribute) {
-               m_Attribute = new Attribute<Value>();
-               m_Attribute->Set(other.m_Attribute->Get());
-       } else {
-               m_Attribute = other.m_Attribute;
-       }
-}
-
-AttributeHolder::~AttributeHolder(void)
-{
-       if (m_OwnsAttribute)
-               delete m_Attribute;
-}
-
-void AttributeHolder::Bind(AttributeBase *boundAttribute)
-{
-       ASSERT(m_OwnsAttribute);
-       boundAttribute->Set(m_Attribute->Get());
-       if (m_OwnsAttribute)
-               delete m_Attribute;
-       m_Attribute = boundAttribute;
-       m_OwnsAttribute = false;
-}
-
-void AttributeHolder::SetValue(double tx, const Value& value)
-{
-       m_Tx = tx;
-       m_Attribute->Set(value);
-}
-
-Value AttributeHolder::GetValue(void) const
-{
-       return m_Attribute->Get();
-}
-
-void AttributeHolder::SetType(AttributeType type)
-{
-       m_Type = type;
-}
-
-AttributeType AttributeHolder::GetType(void) const
-{
-       return m_Type;
-}
-
-void AttributeHolder::SetTx(double tx)
-{
-       m_Tx = tx;
-}
-
-double AttributeHolder::GetTx(void) const
-{
-       return m_Tx;
-}
diff --git a/lib/base/attribute.h b/lib/base/attribute.h
deleted file mode 100644 (file)
index 2dd27b1..0000000
+++ /dev/null
@@ -1,137 +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 ATTRIBUTE_H
-#define ATTRIBUTE_H
-
-#include "base/value.h"
-
-namespace icinga
-{
-
-/**
- * The type of an attribute for a DynamicObject.
- *
- * @ingroup base
- */
-enum AttributeType
-{
-       Attribute_Transient = 1,
-
-       /* Unlike transient attributes local attributes are persisted
-        * in the program state file. */
-       Attribute_Local = 2,
-
-       /* Replicated attributes are sent to other daemons for which
-        * replication is enabled. */
-       Attribute_Replicated = 4,
-
-       /* Attributes read from the config file are implicitly marked
-        * as config attributes. */
-       Attribute_Config = 8,
-
-       /* Combination of all attribute types */
-       Attribute_All = Attribute_Transient | Attribute_Local | Attribute_Replicated | Attribute_Config
-};
-
-class I2_BASE_API AttributeBase
-{
-public:
-       AttributeBase(void);
-
-       void Set(const Value& value);
-       Value Get(void) const;
-       operator Value(void) const;
-       bool IsEmpty(void) const;
-
-protected:
-       void InternalSet(const Value& value);
-       const Value& InternalGet(void) const;
-
-private:
-       Value m_Value;
-
-       AttributeBase(const AttributeBase& other);
-       AttributeBase& operator=(const AttributeBase& other);
-};
-
-template<typename T>
-class Attribute : public AttributeBase
-{
-public:
-       void Set(const T& value)
-       {
-               AttributeBase::Set(value);
-       }
-
-       Attribute<T>& operator=(const T& rhs)
-       {
-               Set(rhs);
-               return *this;
-       }
-
-       T Get(void) const
-       {
-               Value value = AttributeBase::Get();
-
-               if (value.IsEmpty())
-                       return T();
-
-               return static_cast<T>(value);
-       }
-
-       operator T(void) const
-       {
-               return Get();
-       }
-};
-
-/**
- * An attribute for a DynamicObject.
- *
- * @ingroup base
- */
-class I2_BASE_API AttributeHolder
-{
-public:
-       AttributeHolder(AttributeType type, AttributeBase *boundAttribute = NULL);
-       AttributeHolder(const AttributeHolder& other);
-       ~AttributeHolder(void);
-
-       void Bind(AttributeBase *boundAttribute);
-
-       void SetValue(double tx, const Value& value);
-       Value GetValue(void) const;
-
-       void SetType(AttributeType type);
-       AttributeType GetType(void) const;
-
-       void SetTx(double tx);
-       double GetTx(void) const;
-
-private:
-       AttributeType m_Type; /**< The type of the attribute. */
-       double m_Tx; /**< The timestamp of the last value change. */
-       bool m_OwnsAttribute; /**< Whether we own the Data pointer. */
-       AttributeBase *m_Attribute; /**< The current value of the attribute. */
-};
-
-}
-
-#endif /* ATTRIBUTE_H */
index daf3c8d8ff928bc8eebfcdc986cae0c2d997b23f..34040ed01d742db16b564f907bf648cd042b6c2f 100644 (file)
@@ -21,7 +21,6 @@
   <ItemGroup>
     <ClCompile Include="application.cpp" />
     <ClCompile Include="array.cpp" />
-    <ClCompile Include="attribute.cpp" />
     <ClCompile Include="bufferedstream.cpp" />
     <ClCompile Include="consolelogger.cpp" />
     <ClCompile Include="convert.cpp" />
@@ -66,7 +65,6 @@
   <ItemGroup>
     <ClInclude Include="application.h" />
     <ClInclude Include="array.h" />
-    <ClInclude Include="attribute.h" />
     <ClInclude Include="bufferedstream.h" />
     <ClInclude Include="consolelogger.h" />
     <ClInclude Include="convert.h" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index b636307cfab68a3950810f6a37cb59bdfeda2706..3db70d8b722e8f3bfbded65a418827a9e960cddd 100644 (file)
@@ -88,9 +88,6 @@
     <ClCompile Include="process-windows.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
-    <ClCompile Include="attribute.cpp">
-      <Filter>Quelldateien</Filter>
-    </ClCompile>
     <ClCompile Include="stacktrace.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
     <ClInclude Include="objectlock.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
-    <ClInclude Include="attribute.h">
-      <Filter>Headerdateien</Filter>
-    </ClInclude>
     <ClInclude Include="stacktrace.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
       <UniqueIdentifier>{7bbee99c-5763-4063-836c-ddbcc8966ae3}</UniqueIdentifier>
     </Filter>
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
index ac3630d6afa63be304caadf7a6db9198f7dcfdaf..55bd54fdc25a04faf1d45f47e0eb4f5520ec56c7 100644 (file)
@@ -28,8 +28,9 @@ REGISTER_TYPE(ConsoleLogger);
 /**
  * Constructor for the ConsoleLogger class.
  */
-ConsoleLogger::ConsoleLogger(const Dictionary::Ptr& serializedUpdate)
-       : StreamLogger(serializedUpdate)
+void ConsoleLogger::Start()
 {
+       StreamLogger::Start();
+
        BindStream(&std::cout, false);
 }
index f39ef56af9b76f2cd97389480ab58473f98b0316..011c9340a6f5b7c0084d1bf0ce4058b01d9eda16 100644 (file)
@@ -36,7 +36,7 @@ class I2_BASE_API ConsoleLogger : public StreamLogger
 public:
        DECLARE_PTR_TYPEDEFS(ConsoleLogger);
 
-       explicit ConsoleLogger(const Dictionary::Ptr& serializedUpdate);
+       virtual void Start(void);
 };
 
 }
index 659e23acf0815b6d705c14ebb7c5503b4915cac9..73a5d40bad26df332c168b93974aeafbc7cf1582 100644 (file)
@@ -30,6 +30,7 @@
 #include "base/scriptfunction.h"
 #include <fstream>
 #include <boost/make_shared.hpp>
+#include <boost/tuple/tuple.hpp>
 #include <boost/foreach.hpp>
 #include <boost/exception/errinfo_api_function.hpp>
 #include <boost/exception/errinfo_errno.hpp>
 
 using namespace icinga;
 
-static double l_CurrentTx = 0;
-static std::set<DynamicObject::WeakPtr> l_ModifiedObjects;
-static boost::mutex l_TransactionMutex;
-static boost::once_flag l_TransactionOnce = BOOST_ONCE_INIT;
-static Timer::Ptr l_TransactionTimer;
+boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnStarted;
+boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnStopped;
+boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnStateChanged;
 
-boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRegistered;
-boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnUnregistered;
-boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)> DynamicObject::OnTransactionClosing;
-boost::signals2::signal<void (double, const DynamicObject::Ptr&)> DynamicObject::OnFlushObject;
-boost::signals2::signal<void (const DynamicObject::Ptr&, const std::set<String, string_iless>&)> DynamicObject::OnAttributesChanged;
-
-DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject)
-       : m_ConfigTx(0), m_LocalTx(0), m_Registered(false)
-{
-       RegisterAttribute("__name", Attribute_Config, &m_Name);
-       RegisterAttribute("__type", Attribute_Config, &m_Type);
-       RegisterAttribute("__local", Attribute_Config, &m_Local);
-       RegisterAttribute("__source", Attribute_Local, &m_Source);
-       RegisterAttribute("__extensions", Attribute_Local, &m_Extensions);
-       RegisterAttribute("methods", Attribute_Config, &m_Methods);
-       RegisterAttribute("custom", Attribute_Config, &m_Custom);
-
-       if (!serializedObject->Contains("configTx"))
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Serialized object must contain a config snapshot."));
-
-       /* apply config state from the config item/remote update;
-        * The DynamicType::CreateObject function takes care of restoring
-        * non-config state after the object has been fully constructed */
-       ApplyUpdate(serializedObject, Attribute_Config);
-
-       boost::call_once(l_TransactionOnce, &DynamicObject::Initialize);
-}
+DynamicObject::DynamicObject(void)
+       : m_Active(false)
+{ }
 
 DynamicObject::~DynamicObject(void)
 { }
 
-void DynamicObject::Initialize(void)
+Dictionary::Ptr DynamicObject::Serialize(int attributeTypes) const
 {
-       /* Set up a timer to periodically create a new transaction. */
-       l_TransactionTimer = boost::make_shared<Timer>();
-       l_TransactionTimer->SetInterval(0.5);
-       l_TransactionTimer->OnTimerExpired.connect(boost::bind(&DynamicObject::NewTx));
-       l_TransactionTimer->Start();
-}
-
-Dictionary::Ptr DynamicObject::BuildUpdate(double sinceTx, int attributeTypes) const
-{
-       ObjectLock olock(this);
-
-       DynamicObject::AttributeConstIterator it;
-
-       Dictionary::Ptr attrs = boost::make_shared<Dictionary>();
-
-       {
-               boost::mutex::scoped_lock lock(m_AttributeMutex);
-
-               for (it = m_Attributes.begin(); it != m_Attributes.end(); ++it) {
-                       if (it->second.GetType() == Attribute_Transient)
-                               continue;
-
-                       if ((it->second.GetType() & attributeTypes) == 0)
-                               continue;
-
-                       if (it->second.GetTx() == 0)
-                               continue;
-
-                       if (it->second.GetTx() < sinceTx && !(it->second.GetType() == Attribute_Config && m_ConfigTx >= sinceTx))
-                               continue;
-
-                       Dictionary::Ptr attr = boost::make_shared<Dictionary>();
-                       attr->Set("data", it->second.GetValue());
-                       attr->Set("type", it->second.GetType());
-                       attr->Set("tx", it->second.GetTx());
-
-                       attrs->Set(it->first, attr);
-               }
-       }
-
        Dictionary::Ptr update = boost::make_shared<Dictionary>();
-       update->Set("attrs", attrs);
-
-       if (m_ConfigTx >= sinceTx && attributeTypes & Attribute_Config)
-               update->Set("configTx", m_ConfigTx);
-       else if (attrs->GetLength() == 0)
-               return Dictionary::Ptr();
-
-       return update;
-}
-
-void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate,
-    int allowedTypes)
-{
-       ObjectLock olock(this);
-
-       Value configTxValue = serializedUpdate->Get("configTx");
-
-       boost::mutex::scoped_lock lock(m_AttributeMutex);
-
-       if ((allowedTypes & Attribute_Config) != 0 && !configTxValue.IsEmpty()) {
-               double configTx = configTxValue;
-
-               if (configTx > m_ConfigTx) {
-                       DynamicObject::AttributeIterator at;
-                       for (at = m_Attributes.begin(); at != m_Attributes.end(); ++at) {
-                               if ((at->second.GetType() & Attribute_Config) == 0)
-                                       continue;
-
-                               at->second.SetValue(0, Empty);
-                       }
-               }
-       }
-
-       Dictionary::Ptr attrs = serializedUpdate->Get("attrs");
-
-       {
-               ObjectLock alock(attrs);
-
-               Dictionary::Iterator it;
-               for (it = attrs->Begin(); it != attrs->End(); ++it) {
-                       if (!it->second.IsObjectType<Dictionary>())
-                               continue;
-
-                       Dictionary::Ptr attr = it->second;
-
-                       int type = attr->Get("type");
-
-                       if ((type & ~allowedTypes) != 0)
-                               continue;
-
-                       Value data = attr->Get("data");
-                       double tx = attr->Get("tx");
 
-                       if (type & Attribute_Config)
-                               InternalRegisterAttribute(it->first, Attribute_Config);
-
-                       if (m_Attributes.find(it->first) == m_Attributes.end())
-                               InternalRegisterAttribute(it->first, static_cast<AttributeType>(type));
-
-                       InternalSetAttribute(it->first, data, tx, true);
-               }
-       }
-}
-
-void DynamicObject::RegisterAttribute(const String& name,
-    AttributeType type, AttributeBase *boundAttribute)
-{
        ASSERT(!OwnsLock());
        ObjectLock olock(this);
 
-       boost::mutex::scoped_lock lock(m_AttributeMutex);
-
-       InternalRegisterAttribute(name, type, boundAttribute);
-}
-
-/**
- * Note: Caller must hold m_AttributeMutex.
- */
-void DynamicObject::InternalRegisterAttribute(const String& name,
-    AttributeType type, AttributeBase *boundAttribute)
-{
-       ASSERT(OwnsLock());
-
-       AttributeHolder attr(type, boundAttribute);
-
-       std::pair<DynamicObject::AttributeIterator, bool> tt;
-       tt = m_Attributes.insert(std::make_pair(name, attr));
+       InternalSerialize(update, attributeTypes);
 
-       if (!tt.second) {
-               tt.first->second.SetType(type);
+       /* Make sure our own InternalSerialize() method was called. */
+       ASSERT(update->Contains("__marker"));
+       update->Remove("__marker");
 
-               if (boundAttribute)
-                       tt.first->second.Bind(boundAttribute);
-       }
+       return update;
 }
 
-void DynamicObject::Set(const String& name, const Value& data)
+void DynamicObject::Deserialize(const Dictionary::Ptr& update, int attributeTypes)
 {
        ASSERT(!OwnsLock());
        ObjectLock olock(this);
 
-       boost::mutex::scoped_lock lock(m_AttributeMutex);
-
-       InternalSetAttribute(name, data, GetCurrentTx());
+       InternalDeserialize(update, attributeTypes);
 }
 
-void DynamicObject::Touch(const String& name)
+void DynamicObject::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
 {
-       ASSERT(OwnsLock());
-
-       boost::mutex::scoped_lock lock(m_AttributeMutex);
-
-       AttributeIterator it = m_Attributes.find(name);
-
-       if (it == m_Attributes.end())
-               BOOST_THROW_EXCEPTION(std::runtime_error("Touch() called for unknown attribute: " + name));
-
-       double tx = GetCurrentTx();
-       it->second.SetTx(tx);
-       m_LocalTx = tx;
-
-       m_ModifiedAttributes.insert(name);
-
-       {
-               boost::mutex::scoped_lock lock(l_TransactionMutex);
-               l_ModifiedObjects.insert(GetSelf());
+       if (attributeTypes & Attribute_Config) {
+               bag->Set("__name", m_Name);
+               bag->Set("__type", m_Type);
+               bag->Set("methods", m_Methods);
+               bag->Set("custom", m_Custom);
        }
-}
-
-double DynamicObject::GetLocalTx(void) const
-{
-       boost::mutex::scoped_lock lock(m_AttributeMutex);
-       return m_LocalTx;
-}
-
-Value DynamicObject::Get(const String& name) const
-{
-       ASSERT(!OwnsLock());
-       ObjectLock olock(this);
 
-       boost::mutex::scoped_lock lock(m_AttributeMutex);
+       bag->Set("extensions", m_Extensions);
 
-       return InternalGetAttribute(name);
+       /* This attribute is used by Serialize() to check that this
+        * method was called. */
+       bag->Set("__marker", 1);
 }
 
-/**
- * Note: Caller must hold m_AttributeMutex.
- */
-void DynamicObject::InternalSetAttribute(const String& name, const Value& data,
-    double tx, bool allowEditConfig)
+void DynamicObject::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
 {
-       ASSERT(OwnsLock());
-
-       DynamicObject::AttributeIterator it;
-       it = m_Attributes.find(name);
-
-       if (it == m_Attributes.end()) {
-               AttributeHolder attr(Attribute_Transient);
-               attr.SetValue(tx, data);
-
-               m_Attributes.insert(std::make_pair(name, attr));
-       } else {
-               if (!allowEditConfig && (it->second.GetType() & Attribute_Config))
-                       BOOST_THROW_EXCEPTION(std::runtime_error("Config properties are immutable: '" + name + "'."));
-
-               if (tx > it->second.GetTx()) {
-                       it->second.SetValue(tx, data);
-
-                       if (it->second.GetType() & Attribute_Config)
-                               m_ConfigTx = tx;
-               }
-       }
-
-       if (IsRegistered()) {
-               /* We can't call GetSelf() in the constructor or destructor.
-                * The Register() function will take care of adding this
-                * object to the list of modified objects later on if we can't
-                * do it here. */
-
-               {
-                       boost::mutex::scoped_lock lock(l_TransactionMutex);
-                       l_ModifiedObjects.insert(GetSelf());
-               }
+       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_ModifiedAttributes.insert(name);
-}
-
-/**
- * Note: Caller must hold m_AttributeMutex.
- */
-Value DynamicObject::InternalGetAttribute(const String& name) const
-{
-       ASSERT(OwnsLock());
-
-       DynamicObject::AttributeConstIterator it;
-       it = m_Attributes.find(name);
-
-       if (it == m_Attributes.end())
-               return Empty;
-
-       return it->second.GetValue();
+       m_Extensions = bag->Get("extensions");
 }
 
 DynamicType::Ptr DynamicObject::GetType(void) const
@@ -331,26 +111,9 @@ String DynamicObject::GetName(void) const
        return m_Name;
 }
 
-bool DynamicObject::IsLocal(void) const
+bool DynamicObject::IsActive(void) const
 {
-       return m_Local;
-}
-
-bool DynamicObject::IsRegistered(void) const
-{
-       ObjectLock olock(GetType());
-       return m_Registered;
-}
-
-void DynamicObject::SetSource(const String& value)
-{
-       m_Source = value;
-       Touch("__source");
-}
-
-String DynamicObject::GetSource(void) const
-{
-       return m_Source;
+       return m_Active;
 }
 
 void DynamicObject::SetExtension(const String& key, const Object::Ptr& object)
@@ -363,7 +126,6 @@ void DynamicObject::SetExtension(const String& key, const Object::Ptr& object)
        }
 
        extensions->Set(key, object);
-       Touch("__extensions");
 }
 
 Object::Ptr DynamicObject::GetExtension(const String& key)
@@ -384,67 +146,34 @@ void DynamicObject::ClearExtension(const String& key)
                return;
 
        extensions->Remove(key);
-       Touch("__extensions");
 }
 
 void DynamicObject::Register(void)
 {
        ASSERT(!OwnsLock());
 
-       /* Add this new object to the list of modified objects.
-        * We're doing this here because we can't construct
-        * a while WeakPtr from within the object's constructor. */
-       {
-               boost::mutex::scoped_lock lock(l_TransactionMutex);
-               l_ModifiedObjects.insert(GetSelf());
-       }
-
        DynamicType::Ptr dtype = GetType();
        dtype->RegisterObject(GetSelf());
 }
 
-void DynamicObject::OnRegistrationCompleted(void)
-{
-       ASSERT(!OwnsLock());
-
-       Start();
-
-       OnRegistered(GetSelf());
-}
-
-void DynamicObject::OnUnregistrationCompleted(void)
-{
-       ASSERT(!OwnsLock());
-
-       Stop();
-
-       OnUnregistered(GetSelf());
-}
-
 void DynamicObject::Start(void)
 {
        ASSERT(!OwnsLock());
 
-       /* Nothing to do here. */
-}
-
-void DynamicObject::Stop(void)
-{
-       ASSERT(!OwnsLock());
+       ASSERT(!m_Active);
+       m_Active = true;
 
-       /* Nothing to do here. */
+       OnStarted(GetSelf());
 }
 
-void DynamicObject::Unregister(void)
+void DynamicObject::Stop(void)
 {
        ASSERT(!OwnsLock());
 
-       DynamicType::Ptr dtype = GetType();
-
-       if (!dtype)
-               return;
+       ASSERT(m_Active);
+       m_Active = false;
 
-       dtype->UnregisterObject(GetSelf());
+       OnStopped(GetSelf());
 }
 
 Value DynamicObject::InvokeMethod(const String& method,
@@ -470,7 +199,7 @@ Value DynamicObject::InvokeMethod(const String& method,
        return func->Invoke(arguments);
 }
 
-void DynamicObject::DumpObjects(const String& filename)
+void DynamicObject::DumpObjects(const String& filename, int attributeTypes)
 {
        Log(LogInformation, "base", "Dumping program state to file '" + filename + "'");
 
@@ -486,22 +215,12 @@ void DynamicObject::DumpObjects(const String& filename)
 
        BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
                BOOST_FOREACH(const DynamicObject::Ptr& object, type->GetObjects()) {
-                       if (object->IsLocal())
-                               continue;
-
                        Dictionary::Ptr persistentObject = boost::make_shared<Dictionary>();
 
                        persistentObject->Set("type", type->GetName());
                        persistentObject->Set("name", object->GetName());
 
-                       int types = Attribute_Local | Attribute_Replicated;
-
-                       /* only persist properties for replicated objects or for objects
-                        * that are marked as persistent */
-                       if (!object->GetSource().IsEmpty() /*|| object->IsPersistent()*/)
-                               types |= Attribute_Config;
-
-                       Dictionary::Ptr update = object->BuildUpdate(0, types);
+                       Dictionary::Ptr update = object->Serialize(attributeTypes);
 
                        if (!update)
                                continue;
@@ -531,7 +250,7 @@ void DynamicObject::DumpObjects(const String& filename)
        }
 }
 
-void DynamicObject::RestoreObjects(const String& filename)
+void DynamicObject::RestoreObjects(const String& filename, int attributeTypes)
 {
        Log(LogInformation, "base", "Restoring program state from file '" + filename + "'");
 
@@ -550,8 +269,6 @@ void DynamicObject::RestoreObjects(const String& filename)
                String name = persistentObject->Get("name");
                Dictionary::Ptr update = persistentObject->Get("update");
 
-               bool hasConfig = update->Contains("configTx");
-
                DynamicType::Ptr dt = DynamicType::GetByName(type);
 
                if (!dt)
@@ -559,12 +276,8 @@ void DynamicObject::RestoreObjects(const String& filename)
 
                DynamicObject::Ptr object = dt->GetObject(name);
 
-               if (hasConfig && !object) {
-                       object = dt->DynamicType::CreateObject(update);
-                       object->Register();
-               } else if (object) {
-                       object->ApplyUpdate(update, Attribute_All);
-               }
+               if (object)
+                       object->Deserialize(update, attributeTypes);
 
                restored++;
        }
@@ -576,86 +289,22 @@ void DynamicObject::RestoreObjects(const String& filename)
        Log(LogInformation, "base", msgbuf.str());
 }
 
-void DynamicObject::DeactivateObjects(void)
+void DynamicObject::StopObjects(void)
 {
        BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) {
                BOOST_FOREACH(const DynamicObject::Ptr& object, dt->GetObjects()) {
-                       object->Unregister();
+                       if (object->IsActive())
+                               object->Stop();
                }
        }
 }
 
-double DynamicObject::GetCurrentTx(void)
-{
-       boost::mutex::scoped_lock lock(l_TransactionMutex);
-
-       if (l_CurrentTx == 0) {
-               /* Set the initial transaction ID. */
-               l_CurrentTx = Utility::GetTime();
-       }
-
-       return l_CurrentTx;
-}
-
-void DynamicObject::Flush(void)
-{
-       OnFlushObject(GetCurrentTx(), GetSelf());
-}
-
-void DynamicObject::NewTx(void)
-{
-       double tx;
-       std::set<DynamicObject::WeakPtr> objects;
-
-       {
-               boost::mutex::scoped_lock lock(l_TransactionMutex);
-
-               tx = l_CurrentTx;
-               l_ModifiedObjects.swap(objects);
-               l_CurrentTx = Utility::GetTime();
-       }
-
-       BOOST_FOREACH(const DynamicObject::WeakPtr& wobject, objects) {
-               DynamicObject::Ptr object = wobject.lock();
-
-               if (!object || !object->IsRegistered())
-                       continue;
-
-               std::set<String, string_iless> attrs;
-
-               {
-                       ObjectLock olock(object);
-                       attrs.swap(object->m_ModifiedAttributes);
-               }
-
-               OnAttributesChanged(object, attrs);
-
-               BOOST_FOREACH(const String& attr, attrs) {
-                       object->OnAttributeChanged(attr);
-               }
-       }
-
-       OnTransactionClosing(tx, objects);
-}
-
-void DynamicObject::OnAttributeChanged(const String&)
-{
-       ASSERT(!OwnsLock());
-}
-
 DynamicObject::Ptr DynamicObject::GetObject(const String& type, const String& name)
 {
        DynamicType::Ptr dtype = DynamicType::GetByName(type);
        return dtype->GetObject(name);
 }
 
-const DynamicObject::AttributeMap& DynamicObject::GetAttributes(void) const
-{
-       ASSERT(OwnsLock());
-
-       return m_Attributes;
-}
-
 Dictionary::Ptr DynamicObject::GetCustom(void) const
 {
        return m_Custom;
index ba6b419d4a86086b37b046f9593f56ed0801dd6f..8412844dca32d7612a37c34f208fb6763849ecbd 100644 (file)
@@ -21,7 +21,6 @@
 #define DYNAMICOBJECT_H
 
 #include "base/i2-base.h"
-#include "base/attribute.h"
 #include "base/object.h"
 #include "base/dictionary.h"
 #include <boost/signals2.hpp>
@@ -33,6 +32,27 @@ namespace icinga
 
 class DynamicType;
 
+/**
+ * The type of an attribute for a DynamicObject.
+ *
+ * @ingroup base
+ */
+enum AttributeType
+{
+       Attribute_Transient = 1,
+
+       /* Unlike transient attributes local attributes are persisted
+        * in the program state file. */
+       Attribute_Local = 2,
+
+       /* Attributes read from the config file are implicitly marked
+        * as config attributes. */
+       Attribute_Config = 4,
+
+       /* Combination of all attribute types */
+       Attribute_All = Attribute_Transient | Attribute_Local | Attribute_Config
+};
+
 /**
  * A dynamic object that can be instantiated from the configuration file
  * and that supports attribute replication to remote application instances.
@@ -44,106 +64,77 @@ class I2_BASE_API DynamicObject : public Object
 public:
        DECLARE_PTR_TYPEDEFS(DynamicObject);
 
-       typedef std::map<String, AttributeHolder, string_iless> AttributeMap;
-       typedef AttributeMap::iterator AttributeIterator;
-       typedef AttributeMap::const_iterator AttributeConstIterator;
-
        ~DynamicObject(void);
 
-       static void Initialize(void);
-
-       Dictionary::Ptr BuildUpdate(double sinceTx, int attributeTypes) const;
-       void ApplyUpdate(const Dictionary::Ptr& serializedUpdate, int allowedTypes);
-
-       void RegisterAttribute(const String& name, AttributeType type, AttributeBase *boundAttribute = NULL);
-
-       void Set(const String& name, const Value& data);
-       void Touch(const String& name);
-       Value Get(const String& name) const;
-
-       void BindAttribute(const String& name, Value *boundValue);
+       Dictionary::Ptr Serialize(int attributeTypes) const;
+       void Deserialize(const Dictionary::Ptr& update, int attributeTypes);
 
-       void ClearAttributesByType(AttributeType type);
-
-       static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnRegistered;
-       static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnUnregistered;
-       static boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)> OnTransactionClosing;
-       static boost::signals2::signal<void (double, const DynamicObject::Ptr&)> OnFlushObject;
-       static boost::signals2::signal<void (const DynamicObject::Ptr&, const std::set<String, string_iless>&)> OnAttributesChanged;
+       static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStarted;
+       static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStopped;
+       static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStateChanged;
 
        Value InvokeMethod(const String& method, const std::vector<Value>& arguments);
 
        shared_ptr<DynamicType> GetType(void) const;
        String GetName(void) const;
 
-       bool IsLocal(void) const;
-       bool IsRegistered(void) const;
-
-       void SetSource(const String& value);
-       String GetSource(void) const;
+       bool IsActive(void) const;
 
        void SetExtension(const String& key, const Object::Ptr& object);
        Object::Ptr GetExtension(const String& key);
        void ClearExtension(const String& key);
 
-       void Flush(void);
-
        void Register(void);
-       void Unregister(void);
+
+       void Activate(void);
+       void Deactivate(void);
 
        virtual void Start(void);
        virtual void Stop(void);
 
-       double GetLocalTx(void) const;
-
-       const AttributeMap& GetAttributes(void) const;
-
-       static DynamicObject::Ptr GetObject(const String& type, const String& name);
+       template<typename T>
+       static shared_ptr<T> GetObject(const String& name)
+       {
+               DynamicObject::Ptr object = GetObject(T::GetTypeName(), name);
 
-       static void DumpObjects(const String& filename);
-       static void RestoreObjects(const String& filename);
-       static void DeactivateObjects(void);
+               return dynamic_pointer_cast<T>(object);
+       }
 
-       static double GetCurrentTx(void);
+       static void DumpObjects(const String& filename, int attributeTypes = Attribute_Local);
+       static void RestoreObjects(const String& filename, int attributeTypes = Attribute_Local);
+       static void StopObjects(void);
 
        Dictionary::Ptr GetCustom(void) const;
 
 protected:
-       explicit DynamicObject(const Dictionary::Ptr& serializedObject);
+       explicit DynamicObject(void);
 
-       virtual void OnRegistrationCompleted(void);
-       virtual void OnUnregistrationCompleted(void);
-
-       virtual void OnAttributeChanged(const String& name);
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
 
 private:
-       void InternalSetAttribute(const String& name, const Value& data, double tx, bool allowEditConfig = false);
-       Value InternalGetAttribute(const String& name) const;
-       void InternalRegisterAttribute(const String& name, AttributeType type, AttributeBase *boundAttribute = NULL);
-
-       mutable boost::mutex m_AttributeMutex;
-       AttributeMap m_Attributes;
-       std::set<String, string_iless> m_ModifiedAttributes;
-       double m_ConfigTx;
-       double m_LocalTx;
-
-       Attribute<String> m_Name;
-       Attribute<String> m_Type;
-       Attribute<bool> m_Local;
-       Attribute<String> m_Source;
-       Attribute<Dictionary::Ptr> m_Extensions;
-       Attribute<Dictionary::Ptr> m_Methods;
-       Attribute<Dictionary::Ptr> m_Custom;
-
-       bool m_Registered;      /**< protected by the type mutex */
+       String m_Name;
+       String m_Type;
+       Dictionary::Ptr m_Extensions;
+       Dictionary::Ptr m_Methods;
+       Dictionary::Ptr m_Custom;
 
-       static double m_CurrentTx;
+       bool m_Active;
 
-       static void NewTx(void);
-
-       friend class DynamicType; /* for OnRegistrationCompleted. */
+       static DynamicObject::Ptr GetObject(const String& type, const String& name);
 };
 
+#define DECLARE_TYPENAME(klass)                                                \
+       inline static String GetTypeName(void)                          \
+       {                                                               \
+               return #klass;                                          \
+       }                                                               \
+                                                                       \
+       inline static shared_ptr<klass> GetByName(const String& name)   \
+       {                                                               \
+               return DynamicObject::GetObject<klass>(name);           \
+       }
+
 }
 
 #endif /* DYNAMICOBJECT_H */
index 492d12ab753317c118296f5a8dc38bfaa3d2c232..4f25a1961ad46876746fc046428b48579188e82a 100644 (file)
@@ -48,29 +48,29 @@ DynamicType::TypeMap& DynamicType::InternalGetTypeMap(void)
        return typemap;
 }
 
-DynamicType::TypeSet& DynamicType::InternalGetTypeSet(void)
+DynamicType::TypeVector& DynamicType::InternalGetTypeVector(void)
 {
-       static DynamicType::TypeSet typeset;
-       return typeset;
+       static DynamicType::TypeVector typevector;
+       return typevector;
 }
 
-DynamicType::TypeSet DynamicType::GetTypes(void)
+DynamicType::TypeVector DynamicType::GetTypes(void)
 {
        boost::mutex::scoped_lock lock(GetStaticMutex());
-       return InternalGetTypeSet(); /* Making a copy of the set here. */
+       return InternalGetTypeVector(); /* Making a copy of the vector here. */
 }
 
-std::set<DynamicObject::Ptr> DynamicType::GetObjects(const String& type)
+std::vector<DynamicObject::Ptr> DynamicType::GetObjects(const String& type)
 {
        DynamicType::Ptr dt = GetByName(type);
        return dt->GetObjects();
 }
 
-std::set<DynamicObject::Ptr> DynamicType::GetObjects(void) const
+std::vector<DynamicObject::Ptr> DynamicType::GetObjects(void) const
 {
        ObjectLock olock(this);
 
-       return m_ObjectSet; /* Making a copy of the set here. */
+       return m_ObjectVector; /* Making a copy of the vector here. */
 }
 
 String DynamicType::GetName(void) const
@@ -95,26 +95,8 @@ void DynamicType::RegisterObject(const DynamicObject::Ptr& object)
                }
 
                m_ObjectMap[name] = object;
-               m_ObjectSet.insert(object);
-
-               object->m_Registered = true;
+               m_ObjectVector.push_back(object);
        }
-
-       object->OnRegistrationCompleted();
-}
-
-void DynamicType::UnregisterObject(const DynamicObject::Ptr& object)
-{
-       {
-               ObjectLock olock(this);
-
-               m_ObjectMap.erase(object->GetName());
-               m_ObjectSet.erase(object);
-
-               object->m_Registered = false;
-       }
-
-       object->OnUnregistrationCompleted();
 }
 
 DynamicObject::Ptr DynamicType::GetObject(const String& name) const
@@ -140,7 +122,7 @@ void DynamicType::RegisterType(const DynamicType::Ptr& type)
                    type->GetName() + "': Objects of this type already exist."));
 
        InternalGetTypeMap()[type->GetName()] = type;
-       InternalGetTypeSet().insert(type);
+       InternalGetTypeVector().push_back(type);
 }
 
 DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUpdate)
@@ -154,10 +136,9 @@ DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUp
                factory = m_ObjectFactory;
        }
 
-       DynamicObject::Ptr object = factory(serializedUpdate);
+       DynamicObject::Ptr object = factory();
 
-       /* apply the object's non-config attributes */
-       object->ApplyUpdate(serializedUpdate, Attribute_All & ~Attribute_Config);
+       object->Deserialize(serializedUpdate, Attribute_All);
 
        return object;
 }
index 7b7c8dd90b8ebbdac7f4ea568e84d7f12eeb83e7..9e574d444575b67fd022610349fa54476afe4fa4 100644 (file)
@@ -23,6 +23,7 @@
 #include "base/i2-base.h"
 #include "base/registry.h"
 #include "base/dynamicobject.h"
+#include "base/utility.h"
 #include <map>
 #include <set>
 #include <boost/function.hpp>
@@ -36,7 +37,7 @@ class I2_BASE_API DynamicType : public Object
 public:
        DECLARE_PTR_TYPEDEFS(DynamicType);
 
-       typedef boost::function<DynamicObject::Ptr (const Dictionary::Ptr&)> ObjectFactory;
+       typedef boost::function<DynamicObject::Ptr (void)> ObjectFactory;
 
        DynamicType(const String& name, const ObjectFactory& factory);
 
@@ -50,29 +51,44 @@ public:
        DynamicObject::Ptr GetObject(const String& name) const;
 
        void RegisterObject(const DynamicObject::Ptr& object);
-       void UnregisterObject(const DynamicObject::Ptr& object);
 
-       static std::set<DynamicType::Ptr> GetTypes(void);
-       std::set<DynamicObject::Ptr> GetObjects(void) const;
+       static std::vector<DynamicType::Ptr> GetTypes(void);
+       std::vector<DynamicObject::Ptr> GetObjects(void) const;
 
-       static std::set<DynamicObject::Ptr> GetObjects(const String& type);
+       template<typename T>
+       static std::vector<shared_ptr<T> > GetObjects(void)
+       {
+               std::vector<shared_ptr<T> > objects;
+
+               BOOST_FOREACH(const DynamicObject::Ptr& object, GetObjects(T::GetTypeName())) {
+                       shared_ptr<T> tobject = dynamic_pointer_cast<T>(object);
+
+                       ASSERT(tobject);
+
+                       objects.push_back(tobject);
+               }
+
+               return objects;
+       }
 
 private:
        String m_Name;
        ObjectFactory m_ObjectFactory;
 
        typedef std::map<String, DynamicObject::Ptr, string_iless> ObjectMap;
-       typedef std::set<DynamicObject::Ptr> ObjectSet;
+       typedef std::vector<DynamicObject::Ptr> ObjectVector;
 
        ObjectMap m_ObjectMap;
-       ObjectSet m_ObjectSet;
+       ObjectVector m_ObjectVector;
 
        typedef std::map<String, DynamicType::Ptr, string_iless> TypeMap;
-       typedef std::set<DynamicType::Ptr> TypeSet;
+       typedef std::vector<DynamicType::Ptr> TypeVector;
 
        static TypeMap& InternalGetTypeMap(void);
-       static TypeSet& InternalGetTypeSet(void);
+       static TypeVector& InternalGetTypeVector(void);
        static boost::mutex& GetStaticMutex(void);
+
+       static std::vector<DynamicObject::Ptr> GetObjects(const String& type);
 };
 
 /**
@@ -104,9 +120,9 @@ public:
  * @ingroup base
  */
 template<typename T>
-shared_ptr<T> DynamicObjectFactory(const Dictionary::Ptr& serializedUpdate)
+shared_ptr<T> DynamicObjectFactory(void)
 {
-       return boost::make_shared<T>(serializedUpdate);
+       return boost::make_shared<T>();
 }
 
 #define REGISTER_TYPE_ALIAS(type, alias) \
index f4e15bbe504945cd01885d6ce9df4c226ccfa4a4..00056ec133a83299ced59ed775e15520b39c2e7b 100644 (file)
@@ -28,10 +28,9 @@ REGISTER_TYPE(FileLogger);
 /**
  * Constructor for the FileLogger class.
  */
-FileLogger::FileLogger(const Dictionary::Ptr& serializedUpdate)
-       : StreamLogger(serializedUpdate)
+void FileLogger::Start()
 {
-       RegisterAttribute("path", Attribute_Config, &m_Path);
+       StreamLogger::Start();
 
        std::ofstream *stream = new std::ofstream();
 
@@ -48,4 +47,19 @@ FileLogger::FileLogger(const Dictionary::Ptr& serializedUpdate)
        }
 
        BindStream(stream, true);
-}
\ No newline at end of file
+}
+
+void FileLogger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       StreamLogger::InternalSerialize(bag, attributeTypes);
+
+       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");
+}
index 5ed0f2df78b6e756724639f9e9d056b71be044a7..a2bf893cba48f1ede6abdf418bd7a8492860ee61 100644 (file)
@@ -36,10 +36,14 @@ class I2_BASE_API FileLogger : public StreamLogger
 public:
        DECLARE_PTR_TYPEDEFS(FileLogger);
 
-       explicit FileLogger(const Dictionary::Ptr& serializedUpdate);
+       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:
-       Attribute<String> m_Path;
+       String m_Path;
 };
 
 }
index fa6a799a029ac0c39bceeb6667675b49e61495b5..cfdae35781d78532a9b28101f4e8646bef701e36 100644 (file)
@@ -34,20 +34,11 @@ boost::mutex Logger::m_Mutex;
 
 /**
  * Constructor for the Logger class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
  */
-Logger::Logger(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("severity", Attribute_Config, &m_Severity);
-
-       if (!IsLocal())
-               BOOST_THROW_EXCEPTION(std::runtime_error("Logger objects must be local."));
-}
-
 void Logger::Start(void)
 {
+       DynamicObject::Start();
+
        boost::mutex::scoped_lock(m_Mutex);
        m_Loggers.insert(GetSelf());
 }
@@ -161,12 +152,17 @@ LogSeverity Logger::StringToSeverity(const String& severity)
                BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
 }
 
-///**
-// * Retrieves the configuration object that belongs to this logger.
-// *
-// * @returns The configuration object.
-// */
-//DynamicObject::Ptr ILogger::GetConfig(void) const
-//{
-//     return m_Config.lock();
-//}
+void Logger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       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");
+}
index 085ebbb893ea915a4d637eae0493e8b562773efb..9f8f6b9479b7e07ea3dc62ba9975308d2ab8638d 100644 (file)
@@ -50,8 +50,6 @@ class I2_BASE_API Logger : public DynamicObject
 public:
        DECLARE_PTR_TYPEDEFS(Logger);
 
-       explicit Logger(const Dictionary::Ptr& serializedUpdate);
-
        static String SeverityToString(LogSeverity severity);
        static LogSeverity StringToSeverity(const String& severity);
 
@@ -71,8 +69,11 @@ 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:
-       Attribute<String> m_Severity;
+       String m_Severity;
 
        LogSeverity m_MinSeverity;
 
index 100b2a45c3034edd7aa891f6df577cdb7e37fdc8..3a0b1ca337c18398a92f5a6cb07cf15b885b7271 100644 (file)
@@ -26,6 +26,8 @@
 #include <map>
 #include <boost/thread/mutex.hpp>
 #include <boost/signals2.hpp>
+#include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
 
 namespace icinga
 {
@@ -78,6 +80,26 @@ public:
                        OnUnregistered(name);
        }
 
+       void Clear(void)
+       {
+               typename Registry<T>::ItemMap items;
+
+               {
+                       boost::mutex::scoped_lock lock(m_Mutex);
+                       items = m_Items;
+               }
+
+               String name;
+               BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), items) {
+                       OnUnregistered(name);
+               }
+
+               {
+                       boost::mutex::scoped_lock lock(m_Mutex);
+                       m_Items.clear();
+               }
+       }
+
        T GetItem(const String& name) const
        {
                boost::mutex::scoped_lock lock(m_Mutex);
index bde14a3937369efeb1e3aa8b361b9ac65ef6e0ca..1cf5d0fba00191ceb6da809e574d8b519716afa6 100644 (file)
@@ -28,20 +28,10 @@ using namespace icinga;
 
 REGISTER_TYPE(Script);
 
-/**
- * Constructor for the Script class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-Script::Script(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("language", Attribute_Config, &m_Language);
-       RegisterAttribute("code", Attribute_Config, &m_Code);
-}
-
 void Script::Start(void)
 {
+       DynamicObject::Start();
+
        ASSERT(OwnsLock());
 
        SpawnInterpreter();
@@ -61,14 +51,6 @@ String Script::GetCode(void) const
        return m_Code;
 }
 
-void Script::OnAttributeUpdate(const String& name)
-{
-       ASSERT(!OwnsLock());
-
-       if (name == "language" || name == "code")
-               SpawnInterpreter();
-}
-
 void Script::SpawnInterpreter(void)
 {
        Log(LogInformation, "base", "Reloading script '" + GetName() + "'");
@@ -76,3 +58,20 @@ 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);
+
+       bag->Set("language", m_Language);
+       bag->Set("code", m_Code);
+}
+
+void Script::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       m_Language = bag->Get("language");
+       m_Code = bag->Get("code");
+
+}
\ No newline at end of file
index e34d55d941bb0f63d0ec18b081c8dd7012280f6a..4f4be30f1789971d6191a9ae49a22bacf967172f 100644 (file)
@@ -38,19 +38,18 @@ class I2_BASE_API Script : public DynamicObject
 public:
        DECLARE_PTR_TYPEDEFS(Script);
 
-       Script(const Dictionary::Ptr& serializedUpdate);
-
        virtual void Start(void);
 
        String GetLanguage(void) const;
        String GetCode(void) const;
 
 protected:
-       virtual void OnAttributeUpdate(const String& name);
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
 
 private:
-       Attribute<String> m_Language;
-       Attribute<String> m_Code;
+       String m_Language;
+       String m_Code;
 
        shared_ptr<ScriptInterpreter> m_Interpreter;
 
index 48ff2858ad4bc1bf9e33a81b08c2691514aa8e8d..80582d0c021554c905d71a00f932f86c92521eb0 100644 (file)
@@ -34,7 +34,7 @@ Value ScriptFunctionWrapperVV(void (*function)(void), const std::vector<Value>&
 boost::function<Value (const std::vector<Value>& arguments)> I2_BASE_API WrapScriptFunction(void (*function)(void));
 
 template<typename TR>
-Value ScriptFunctionWrapperR(TR (*function)(void), const std::vector<Value>& arguments)
+Value ScriptFunctionWrapperR(TR (*function)(void), const std::vector<Value>&)
 {
        return function();
 }
index f5821b951579d8876505ac60047368ae565f7230..5701b226dbbaab986b387cbf52b1f68eaf4d0d44 100644 (file)
@@ -31,9 +31,14 @@ boost::mutex StreamLogger::m_Mutex;
 /**
  * Constructor for the StreamLogger class.
  */
-StreamLogger::StreamLogger(const Dictionary::Ptr& serializedUpdate)
-       : Logger(serializedUpdate), m_Stream(NULL), m_OwnsStream(false), m_Tty(false)
-{ }
+void StreamLogger::Start(void)
+{
+       Logger::Start();
+
+       m_Stream = NULL;
+       m_OwnsStream = false;
+       m_Tty = false;
+}
 
 /**
  * Destructor for the StreamLogger class.
index 9d85c0e31e81c2606d407f0f492e81df0d7abb3c..71e111b0d0e963073c39fe26821a61b5dd4b9ce1 100644 (file)
@@ -37,7 +37,7 @@ class I2_BASE_API StreamLogger : public Logger
 public:
        DECLARE_PTR_TYPEDEFS(StreamLogger);
 
-       StreamLogger(const Dictionary::Ptr& serializedUpdate);
+       virtual void Start(void);
        ~StreamLogger(void);
 
        void BindStream(std::ostream *stream, bool ownsStream);
index 8f56d1c45d55557982d438ecb26ceeef82fcf40f..61f5d4218ff77794c0259e2c5c346c40362d5904 100644 (file)
@@ -25,13 +25,6 @@ using namespace icinga;
 
 REGISTER_TYPE(SyslogLogger);
 
-/**
- * Constructor for the SyslogLogger class.
- */
-SyslogLogger::SyslogLogger(const Dictionary::Ptr& serializedUpdate)
-       : Logger(serializedUpdate)
-{ }
-
 /**
  * Processes a log entry and outputs it to syslog.
  *
index 9a1bb0e009fd6000396df6e03c5991c74c16ccb5..3678d107146b702407c5a634c03f1f90b683c427 100644 (file)
@@ -37,8 +37,6 @@ class I2_BASE_API SyslogLogger : public Logger
 public:
        DECLARE_PTR_TYPEDEFS(SyslogLogger);
 
-       explicit SyslogLogger(const Dictionary::Ptr& serializedUpdate);
-
 protected:
        virtual void ProcessLogEntry(const LogEntry& entry);
 };
index 2f11749ea59c1257c0dd7c8488c82c04d77dc43b..45455dafa9c9798e2741c334988881f6c417c8b6 100644 (file)
@@ -30,8 +30,8 @@
 using namespace icinga;
 
 ThreadPool::ThreadPool(void)
-       : m_Stopped(false), m_ThreadDeaths(0), m_WaitTime(0),
-         m_ServiceTime(0), m_TaskCount(0)
+       : m_ThreadDeaths(0), m_WaitTime(0), m_ServiceTime(0),
+         m_TaskCount(0), m_Stopped(false)
 {
        for (int i = 0; i < 2; i++)
                SpawnWorker();
@@ -71,7 +71,7 @@ void ThreadPool::Join(void)
 
        do {
                alive = 0;
-               for (int i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
+               for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
                        if (m_ThreadStats[i].State != ThreadDead) {
                                alive++;
                                KillWorker();
@@ -223,7 +223,7 @@ void ThreadPool::ManagerThreadProc(void)
        Utility::SetThreadName(idbuf.str());
 
        for (;;) {
-               int pending, alive;
+               size_t pending, alive;
                double avg_latency, max_latency;
                double utilization = 0;
 
@@ -239,7 +239,7 @@ void ThreadPool::ManagerThreadProc(void)
 
                        alive = 0;
 
-                       for (int i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
+                       for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
                                if (m_ThreadStats[i].State != ThreadDead) {
                                        alive++;
                                        utilization += m_ThreadStats[i].Utilization * 100;
@@ -294,7 +294,7 @@ void ThreadPool::ManagerThreadProc(void)
  */
 void ThreadPool::SpawnWorker(void)
 {
-       for (int i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
+       for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
                if (m_ThreadStats[i].State == ThreadDead) {
                        Log(LogDebug, "debug", "Spawning worker thread.");
 
@@ -331,7 +331,7 @@ void ThreadPool::StatsThreadProc(void)
                if (m_Stopped)
                        break;
 
-               for (int i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++)
+               for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++)
                        UpdateThreadUtilization(i);
        }
 }
index 80f730d24112b27ea9c3a7d7bdf4c8ddce4f2dc1..9013d194d73ffbb5cdc900d90450b3ad25e607bb 100644 (file)
@@ -454,7 +454,7 @@ String Utility::FormatDateTime(const char *format, double ts)
 String Utility::EscapeShellCmd(const String& s)
 {
        String result;
-       int prev_quote = String::NPos;
+       size_t prev_quote = String::NPos;
        int index = -1;
 
        BOOST_FOREACH(char ch, s) {
index b9b53d0e358af3ba6e9a0fb5e49e983762c1e199..e576ed5e94e6887058f40998f6a168dbe1fa9814 100644 (file)
@@ -18,9 +18,6 @@
  ******************************************************************************/
 
 type DynamicObject {
-       %require "__local",
-       %attribute number "__local",
-
        %require "__name",
        %attribute string "__name",
 
index 28e93c5313679632915e5de1947f4f71c7a8cb69..b5bdcedba98ac35f1c21d5ce40e6818d7b9a627d 100644 (file)
@@ -370,8 +370,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
        *yy_cp = '\0'; \
        yyg->yy_c_buf_p = yy_cp;
 
-#define YY_NUM_RULES 60
-#define YY_END_OF_BUFFER 61
+#define YY_NUM_RULES 59
+#define YY_END_OF_BUFFER 60
 /* This struct is not used in this scanner,
    but its presence is necessary. */
 struct yy_trans_info
@@ -379,29 +379,29 @@ struct yy_trans_info
        flex_int32_t yy_verify;
        flex_int32_t yy_nxt;
        };
-static yyconst flex_int16_t yy_accept[199] =
+static yyconst flex_int16_t yy_accept[195] =
     {   0,
-        0,    0,    0,    0,    0,    0,    0,    0,   61,   59,
-       21,   21,    1,   59,   59,   59,   59,   59,   53,   59,
-       54,   59,   47,   47,   47,   47,   47,   47,   47,   47,
-       47,   47,   47,   59,   18,   19,   12,    3,    2,   60,
-       15,   15,    0,    0,    0,   57,   55,   53,   56,   16,
-       20,   58,    0,   50,   51,   52,    0,   45,   48,   46,
-       47,   47,   47,   47,   47,   47,   47,   47,   47,   47,
-       47,   47,   47,   47,   47,   47,   47,   47,   47,    0,
-       17,   12,   11,    4,    5,    9,   10,    6,    8,    7,
-        0,    0,    0,    0,   20,   53,   49,   47,   28,   47,
-
-       47,   47,   47,   47,   47,   47,   47,   47,   47,   47,
-       47,   47,   44,   47,   47,   47,   47,   13,    4,    5,
-       14,    0,    0,    0,   47,   47,   47,   47,   47,   47,
-       47,   47,   29,   40,   47,   47,   47,   47,   47,   47,
-       42,   22,    4,    0,    0,    0,   47,   24,   47,   43,
-       47,   47,   47,   34,   47,   47,   47,   47,   47,   47,
-        0,    0,    0,   47,   47,   47,   47,   47,   25,   35,
-       47,   27,   26,   47,    0,    0,    0,   47,   47,   37,
-       47,   38,   41,   47,    0,   31,    0,   33,   47,   39,
-       36,    0,    0,   47,   32,   30,   23,    0
+        0,    0,    0,    0,    0,    0,    0,    0,   60,   58,
+       21,   21,    1,   58,   58,   58,   58,   58,   52,   58,
+       53,   58,   46,   46,   46,   46,   46,   46,   46,   46,
+       46,   46,   46,   58,   18,   19,   12,    3,    2,   59,
+       15,   15,    0,    0,    0,   56,   54,   52,   55,   16,
+       20,   57,    0,   49,   50,   51,    0,   44,   47,   45,
+       46,   46,   46,   46,   46,   46,   46,   46,   46,   46,
+       46,   46,   46,   46,   46,   46,   46,   46,    0,   17,
+       12,   11,    4,    5,    9,   10,    6,    8,    7,    0,
+        0,    0,    0,   20,   52,   48,   46,   28,   46,   46,
+
+       46,   46,   46,   46,   46,   46,   46,   46,   46,   46,
+       43,   46,   46,   46,   46,   13,    4,    5,   14,    0,
+        0,    0,   46,   46,   46,   46,   46,   46,   46,   29,
+       39,   46,   46,   46,   46,   46,   46,   41,   22,    4,
+        0,    0,    0,   46,   24,   46,   42,   46,   46,   46,
+       46,   46,   46,   46,   46,   46,    0,    0,    0,   46,
+       46,   46,   46,   46,   25,   34,   46,   27,   26,   46,
+        0,    0,    0,   46,   46,   36,   46,   37,   40,   46,
+        0,   31,    0,   33,   46,   38,   35,    0,    0,   46,
+       32,   30,   23,    0
 
     } ;
 
@@ -446,61 +446,61 @@ static yyconst flex_int32_t yy_meta[43] =
         1,    1
     } ;
 
-static yyconst flex_int16_t yy_base[207] =
+static yyconst flex_int16_t yy_base[203] =
     {   0,
-        0,    0,  247,  246,   40,   42,  209,  208,  249,  254,
-      254,  254,  254,   28,  233,  232,   37,   44,   44,   48,
-      254,  230,    0,   37,  218,  225,  212,   34,   46,  222,
-      222,   48,   52,  199,  254,  229,    0,  254,  254,   82,
-      254,  196,  200,  213,  216,  254,  254,   79,  254,  254,
-        0,  254,   65,  254,  198,  254,  217,  216,  254,  254,
-        0,  195,  190,  194,  207,  198,   52,  206,  204,  194,
-       52,  195,  187,  202,  183,  184,  188,  179,  183,  174,
-      254,    0,  254,   84,   86,  254,  254,  254,  254,  254,
-      172,  176,  178,  182,    0,   88,  254,  173,    0,  190,
-
-      171,  171,  177,  182,  169,  184,  179,  172,  180,  176,
-      161,  168,    0,  169,  162,  171,  170,  254,   92,   96,
-      254,  157,  153,  163,  154,  148,  160,  163,  147,  149,
-      164,  153,    0,    0,  158,  159,  152,  159,  146,  147,
-        0,    0,   99,  148,  147,  151,  153,    0,  139,    0,
-      148,  142,  133,    0,  132,  129,  146,  129,  138,  143,
-      141,  125,  140,  137,  126,  133,  118,  114,    0,    0,
-      124,    0,    0,  113,  105,  119,   86,   85,  102,    0,
-       84,    0,    0,   93,   75,  254,   69,    0,   54,    0,
-        0,   63,   48,   39,  254,  254,    0,  254,  124,  128,
-
-      132,  136,   47,  140,  144,  148
+        0,    0,  243,  242,   40,   42,  205,  204,  245,  250,
+      250,  250,  250,   28,  229,  228,   37,   44,   44,   48,
+      250,  226,    0,   37,  214,  221,  208,  211,   46,  217,
+      217,   48,   38,  194,  250,  224,    0,  250,  250,   75,
+      250,  191,  195,  208,  211,  250,  250,   79,  250,  250,
+        0,  250,   64,  250,  193,  250,  212,  211,  250,  250,
+        0,  190,  185,  189,  202,  193,   56,  201,  190,   63,
+      191,  183,  198,  179,  180,  184,  175,  179,  170,  250,
+        0,  250,   85,   89,  250,  250,  250,  250,  250,  168,
+      172,  174,  178,    0,   91,  250,  169,    0,  186,  167,
+
+      167,  173,  178,  165,  176,  169,  177,  173,  158,  165,
+        0,  166,  159,  168,  167,  250,   96,  102,  250,  154,
+      150,  160,  151,  145,  157,  160,  144,  146,  161,    0,
+        0,  156,  157,  150,  157,  144,  145,    0,    0,  107,
+      146,  145,  149,  151,    0,  137,    0,  146,  140,  131,
+      130,  127,  144,  127,  136,  141,  139,  123,  138,  135,
+      122,  123,  108,   86,    0,    0,   96,    0,    0,   87,
+       85,   99,   83,   79,   92,    0,   68,    0,    0,   75,
+       57,  250,   57,    0,   48,    0,    0,   58,   44,   26,
+      250,  250,    0,  250,  127,  131,  135,  139,   47,  143,
+
+      147,  151
     } ;
 
-static yyconst flex_int16_t yy_def[207] =
+static yyconst flex_int16_t yy_def[203] =
     {   0,
-      198,    1,  199,  199,  200,  200,  201,  201,  198,  198,
-      198,  198,  198,  198,  198,  198,  198,  198,  198,  202,
-      198,  198,  203,  203,  203,  203,  203,  203,  203,  203,
-      203,  203,  203,  198,  198,  198,  204,  198,  198,  205,
-      198,  198,  198,  198,  198,  198,  198,  198,  198,  198,
-      206,  198,  198,  198,  198,  198,  202,  202,  198,  198,
-      203,  203,  203,  203,  203,  203,  203,  203,  203,  203,
-      203,  203,  203,  203,  203,  203,  203,  203,  203,  198,
-      198,  204,  198,  198,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  206,  198,  198,  203,  203,  203,
-
-      203,  203,  203,  203,  203,  203,  203,  203,  203,  203,
-      203,  203,  203,  203,  203,  203,  203,  198,  198,  198,
-      198,  198,  198,  198,  203,  203,  203,  203,  203,  203,
-      203,  203,  203,  203,  203,  203,  203,  203,  203,  203,
-      203,  203,  198,  198,  198,  198,  203,  203,  203,  203,
-      203,  203,  203,  203,  203,  203,  203,  203,  203,  203,
-      198,  198,  198,  203,  203,  203,  203,  203,  203,  203,
-      203,  203,  203,  203,  198,  198,  198,  203,  203,  203,
-      203,  203,  203,  203,  198,  198,  198,  203,  203,  203,
-      203,  198,  198,  203,  198,  198,  203,    0,  198,  198,
-
-      198,  198,  198,  198,  198,  198
+      194,    1,  195,  195,  196,  196,  197,  197,  194,  194,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  198,
+      194,  194,  199,  199,  199,  199,  199,  199,  199,  199,
+      199,  199,  199,  194,  194,  194,  200,  194,  194,  201,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      202,  194,  194,  194,  194,  194,  198,  198,  194,  194,
+      199,  199,  199,  199,  199,  199,  199,  199,  199,  199,
+      199,  199,  199,  199,  199,  199,  199,  199,  194,  194,
+      200,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194,  194,  202,  194,  194,  199,  199,  199,  199,
+
+      199,  199,  199,  199,  199,  199,  199,  199,  199,  199,
+      199,  199,  199,  199,  199,  194,  194,  194,  194,  194,
+      194,  194,  199,  199,  199,  199,  199,  199,  199,  199,
+      199,  199,  199,  199,  199,  199,  199,  199,  199,  194,
+      194,  194,  194,  199,  199,  199,  199,  199,  199,  199,
+      199,  199,  199,  199,  199,  199,  194,  194,  194,  199,
+      199,  199,  199,  199,  199,  199,  199,  199,  199,  199,
+      194,  194,  194,  199,  199,  199,  199,  199,  199,  199,
+      194,  194,  194,  199,  199,  199,  199,  194,  194,  199,
+      194,  194,  199,    0,  194,  194,  194,  194,  194,  194,
+
+      194,  194
     } ;
 
-static yyconst flex_int16_t yy_nxt[297] =
+static yyconst flex_int16_t yy_nxt[293] =
     {   0,
        10,   11,   12,   13,   14,   15,   16,   17,   10,   18,
        19,   19,   10,   20,   21,   22,   23,   10,   24,   23,
@@ -508,79 +508,79 @@ static yyconst flex_int16_t yy_nxt[297] =
        29,   30,   31,   23,   23,   32,   33,   23,   23,   23,
        34,   10,   38,   39,   38,   39,   43,   48,   48,   50,
        61,   49,   53,   51,   48,   48,   62,   40,   52,   40,
-       68,   58,   44,   59,   70,   69,   45,   63,   74,   54,
-       75,   64,  103,   55,   77,   96,   96,  104,  197,   56,
-      108,  109,  196,   71,   76,  195,   78,   53,  194,   48,
-       48,   79,   84,   85,  119,  120,  120,  120,   96,   96,
-
-      193,   86,  143,  120,   54,   87,  120,  120,   55,  120,
-      120,  192,   88,   54,   56,  191,   89,   55,   90,  190,
-      189,  188,  187,   56,   35,   35,   35,   35,   37,   37,
-       37,   37,   41,   41,   41,   41,   57,   57,   57,   57,
-       82,  186,  185,   82,   83,   83,   83,   83,   95,  184,
-       95,   95,  183,  182,  181,  180,  179,  178,  177,  176,
-      175,  174,  173,  172,  171,  170,  169,  168,  167,  166,
-      165,  164,  163,  162,  161,  160,  159,  158,  157,  156,
-      155,  154,  153,  152,  151,  150,  149,  148,  147,  146,
-      145,  144,  142,  141,  140,  139,  138,  137,  136,  135,
-
-      134,  133,  132,  131,  130,  129,  128,  127,  126,  125,
-      124,  123,  122,  121,  118,  117,  116,  115,  114,  113,
-      112,  111,  110,  107,  106,  105,  102,  101,  100,   99,
-       98,   59,   59,   97,   94,   93,   92,   91,   81,   80,
-       73,   72,   67,   66,   65,   60,   47,   46,  198,   42,
-       42,   36,   36,    9,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  198,  198
+       76,   58,   44,   59,   69,  193,   45,   63,   73,   54,
+       74,   64,   77,   55,   95,   95,  102,   78,  192,   56,
+      191,  103,  190,   70,   75,   83,   84,   53,  189,   48,
+       48,  106,  107,  188,   85,  117,  118,  187,   86,  118,
+
+      118,   95,   95,  186,   54,   87,  140,  118,   55,   88,
+      185,   89,  118,  118,   56,  184,   54,  118,  118,  183,
+       55,  182,  181,  180,  179,  178,   56,   35,   35,   35,
+       35,   37,   37,   37,   37,   41,   41,   41,   41,   57,
+       57,   57,   57,   81,  177,  176,   81,   82,   82,   82,
+       82,   94,  175,   94,   94,  174,  173,  172,  171,  170,
+      169,  168,  167,  166,  165,  164,  163,  162,  161,  160,
+      159,  158,  157,  156,  155,  154,  153,  152,  151,  150,
+      149,  148,  147,  146,  145,  144,  143,  142,  141,  139,
+      138,  137,  136,  135,  134,  133,  132,  131,  130,  129,
+
+      128,  127,  126,  125,  124,  123,  122,  121,  120,  119,
+      116,  115,  114,  113,  112,  111,  110,  109,  108,  105,
+      104,  101,  100,   99,   98,   97,   59,   59,   96,   93,
+       92,   91,   90,   80,   79,   72,   71,   68,   67,   66,
+       65,   60,   47,   46,  194,   42,   42,   36,   36,    9,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194
 
     } ;
 
-static yyconst flex_int16_t yy_chk[297] =
+static yyconst flex_int16_t yy_chk[293] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    5,    5,    6,    6,   14,   17,   17,   18,
-      203,   17,   19,   18,   19,   19,   24,    5,   18,    6,
-       28,   20,   14,   20,   29,   28,   14,   24,   32,   19,
-       32,   24,   67,   19,   33,   53,   53,   67,  194,   19,
-       71,   71,  193,   29,   32,  192,   33,   48,  189,   48,
-       48,   33,   40,   40,   84,   84,   85,   85,   96,   96,
-
-      187,   40,  119,  119,   48,   40,  120,  120,   48,  143,
-      143,  185,   40,   96,   48,  184,   40,   96,   40,  181,
-      179,  178,  177,   96,  199,  199,  199,  199,  200,  200,
-      200,  200,  201,  201,  201,  201,  202,  202,  202,  202,
-      204,  176,  175,  204,  205,  205,  205,  205,  206,  174,
-      206,  206,  171,  168,  167,  166,  165,  164,  163,  162,
-      161,  160,  159,  158,  157,  156,  155,  153,  152,  151,
-      149,  147,  146,  145,  144,  140,  139,  138,  137,  136,
-      135,  132,  131,  130,  129,  128,  127,  126,  125,  124,
-      123,  122,  117,  116,  115,  114,  112,  111,  110,  109,
-
-      108,  107,  106,  105,  104,  103,  102,  101,  100,   98,
-       94,   93,   92,   91,   80,   79,   78,   77,   76,   75,
-       74,   73,   72,   70,   69,   68,   66,   65,   64,   63,
-       62,   58,   57,   55,   45,   44,   43,   42,   36,   34,
-       31,   30,   27,   26,   25,   22,   16,   15,    9,    8,
-        7,    4,    3,  198,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  198,  198,  198,  198,  198,  198,
-      198,  198,  198,  198,  198,  198
+      199,   17,   19,   18,   19,   19,   24,    5,   18,    6,
+       33,   20,   14,   20,   29,  190,   14,   24,   32,   19,
+       32,   24,   33,   19,   53,   53,   67,   33,  189,   19,
+      188,   67,  185,   29,   32,   40,   40,   48,  183,   48,
+       48,   70,   70,  181,   40,   83,   83,  180,   40,   84,
+
+       84,   95,   95,  177,   48,   40,  117,  117,   48,   40,
+      175,   40,  118,  118,   48,  174,   95,  140,  140,  173,
+       95,  172,  171,  170,  167,  164,   95,  195,  195,  195,
+      195,  196,  196,  196,  196,  197,  197,  197,  197,  198,
+      198,  198,  198,  200,  163,  162,  200,  201,  201,  201,
+      201,  202,  161,  202,  202,  160,  159,  158,  157,  156,
+      155,  154,  153,  152,  151,  150,  149,  148,  146,  144,
+      143,  142,  141,  137,  136,  135,  134,  133,  132,  129,
+      128,  127,  126,  125,  124,  123,  122,  121,  120,  115,
+      114,  113,  112,  110,  109,  108,  107,  106,  105,  104,
+
+      103,  102,  101,  100,   99,   97,   93,   92,   91,   90,
+       79,   78,   77,   76,   75,   74,   73,   72,   71,   69,
+       68,   66,   65,   64,   63,   62,   58,   57,   55,   45,
+       44,   43,   42,   36,   34,   31,   30,   28,   27,   26,
+       25,   22,   16,   15,    9,    8,    7,    4,    3,  194,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194,  194,  194,  194,  194,  194,  194,  194,  194,
+      194,  194
 
     } ;
 
 /* Table of booleans, true if rule could match eol. */
-static yyconst flex_int32_t yy_rule_can_match_eol[61] =
+static yyconst flex_int32_t yy_rule_can_match_eol[60] =
     {   0,
 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 
     0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-    0,     };
+    0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+        };
 
 /* The intent behind this definition is that it'll catch
  * any uses of REJECT which flex missed.
@@ -998,13 +998,13 @@ yy_match:
                        while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                                {
                                yy_current_state = (int) yy_def[yy_current_state];
-                               if ( yy_current_state >= 199 )
+                               if ( yy_current_state >= 195 )
                                        yy_c = yy_meta[(unsigned int) yy_c];
                                }
                        yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
                        ++yy_cp;
                        }
-               while ( yy_current_state != 198 );
+               while ( yy_current_state != 194 );
                yy_cp = yyg->yy_last_accepting_cpos;
                yy_current_state = yyg->yy_last_accepting_state;
 
@@ -1061,7 +1061,7 @@ YY_RULE_SETUP
 {
        std::ostringstream msgbuf;
        msgbuf << "Unterminated string found: " << *yylloc;
-       ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+       ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
        BEGIN(INITIAL);
                                }
        YY_BREAK
@@ -1078,7 +1078,7 @@ YY_RULE_SETUP
                /* error, constant is out-of-bounds */
                std::ostringstream msgbuf;
                msgbuf << "Constant is out-of-bounds: " << yytext << " " << *yylloc;
-               ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+               ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
        }
 
        lb_append_char(&string_buf, result);
@@ -1093,7 +1093,7 @@ YY_RULE_SETUP
         */
        std::ostringstream msgbuf;
        msgbuf << "Bad escape sequence found: " << yytext << " " << *yylloc;
-       ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+       ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
                                }
        YY_BREAK
 case 6:
@@ -1261,93 +1261,93 @@ return T_ABSTRACT;
 case 34:
 YY_RULE_SETUP
 #line 202 "config_lexer.ll"
-return T_LOCAL;
+return T_OBJECT;
        YY_BREAK
 case 35:
 YY_RULE_SETUP
 #line 203 "config_lexer.ll"
-return T_OBJECT;
+return T_TEMPLATE;
        YY_BREAK
 case 36:
 YY_RULE_SETUP
 #line 204 "config_lexer.ll"
-return T_TEMPLATE;
+return T_INCLUDE;
        YY_BREAK
 case 37:
 YY_RULE_SETUP
 #line 205 "config_lexer.ll"
-return T_INCLUDE;
+return T_LIBRARY;
        YY_BREAK
 case 38:
 YY_RULE_SETUP
 #line 206 "config_lexer.ll"
-return T_LIBRARY;
+return T_INHERITS;
        YY_BREAK
 case 39:
 YY_RULE_SETUP
 #line 207 "config_lexer.ll"
-return T_INHERITS;
+return T_NULL;
        YY_BREAK
 case 40:
 YY_RULE_SETUP
 #line 208 "config_lexer.ll"
-return T_NULL;
+return T_PARTIAL;
        YY_BREAK
 case 41:
 YY_RULE_SETUP
 #line 209 "config_lexer.ll"
-return T_PARTIAL;
+{ yylval->num = 1; return T_NUMBER; }
        YY_BREAK
 case 42:
 YY_RULE_SETUP
 #line 210 "config_lexer.ll"
-{ yylval->num = 1; return T_NUMBER; }
+{ yylval->num = 0; return T_NUMBER; }
        YY_BREAK
 case 43:
 YY_RULE_SETUP
 #line 211 "config_lexer.ll"
-{ yylval->num = 0; return T_NUMBER; }
+return T_SET;
        YY_BREAK
 case 44:
 YY_RULE_SETUP
 #line 212 "config_lexer.ll"
-return T_SET;
+return T_SHIFT_LEFT;
        YY_BREAK
 case 45:
 YY_RULE_SETUP
 #line 213 "config_lexer.ll"
-return T_SHIFT_LEFT;
+return T_SHIFT_RIGHT;
        YY_BREAK
 case 46:
 YY_RULE_SETUP
 #line 214 "config_lexer.ll"
-return T_SHIFT_RIGHT;
+{ yylval->text = strdup(yytext); return T_IDENTIFIER; }
        YY_BREAK
 case 47:
+/* rule 47 can match eol */
 YY_RULE_SETUP
 #line 215 "config_lexer.ll"
-{ yylval->text = strdup(yytext); return T_IDENTIFIER; }
+{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
        YY_BREAK
 case 48:
-/* rule 48 can match eol */
 YY_RULE_SETUP
 #line 216 "config_lexer.ll"
-{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
+{ yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
        YY_BREAK
 case 49:
 YY_RULE_SETUP
 #line 217 "config_lexer.ll"
-{ yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
+{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
        YY_BREAK
 case 50:
 YY_RULE_SETUP
 #line 218 "config_lexer.ll"
-{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
+{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
        YY_BREAK
 case 51:
 YY_RULE_SETUP
 #line 219 "config_lexer.ll"
-{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
+{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
        YY_BREAK
 case 52:
 YY_RULE_SETUP
@@ -1357,45 +1357,40 @@ YY_RULE_SETUP
 case 53:
 YY_RULE_SETUP
 #line 221 "config_lexer.ll"
-{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
+{ yylval->op = OperatorSet; return T_EQUAL; }
        YY_BREAK
 case 54:
 YY_RULE_SETUP
 #line 222 "config_lexer.ll"
-{ yylval->op = OperatorSet; return T_EQUAL; }
+{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
        YY_BREAK
 case 55:
 YY_RULE_SETUP
 #line 223 "config_lexer.ll"
-{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
+{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
        YY_BREAK
 case 56:
 YY_RULE_SETUP
 #line 224 "config_lexer.ll"
-{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
+{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
        YY_BREAK
 case 57:
 YY_RULE_SETUP
 #line 225 "config_lexer.ll"
-{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
-       YY_BREAK
-case 58:
-YY_RULE_SETUP
-#line 226 "config_lexer.ll"
 { yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; }
        YY_BREAK
 
-case 59:
+case 58:
 YY_RULE_SETUP
-#line 229 "config_lexer.ll"
+#line 228 "config_lexer.ll"
 return yytext[0];
        YY_BREAK
-case 60:
+case 59:
 YY_RULE_SETUP
-#line 231 "config_lexer.ll"
+#line 230 "config_lexer.ll"
 ECHO;
        YY_BREAK
-#line 1399 "../../../lib/config/config_lexer.cc"
+#line 1394 "../../../lib/config/config_lexer.cc"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(C_COMMENT):
 case YY_STATE_EOF(STRING):
@@ -1693,7 +1688,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
                while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                        {
                        yy_current_state = (int) yy_def[yy_current_state];
-                       if ( yy_current_state >= 199 )
+                       if ( yy_current_state >= 195 )
                                yy_c = yy_meta[(unsigned int) yy_c];
                        }
                yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1722,11 +1717,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
        while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                {
                yy_current_state = (int) yy_def[yy_current_state];
-               if ( yy_current_state >= 199 )
+               if ( yy_current_state >= 195 )
                        yy_c = yy_meta[(unsigned int) yy_c];
                }
        yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-       yy_is_jam = (yy_current_state == 198);
+       yy_is_jam = (yy_current_state == 194);
 
        return yy_is_jam ? 0 : yy_current_state;
 }
@@ -2585,7 +2580,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 231 "config_lexer.ll"
+#line 230 "config_lexer.ll"
 
 
 
index c40c0430dcdb3d4d48e63f2f3df6215a9f4effd2..f6ca1a65f010c9f7066c3a5e1c411b144bd9849a 100644 (file)
@@ -116,7 +116,7 @@ static char *lb_steal(lex_buf *lb)
 <STRING>\n                     {
        std::ostringstream msgbuf;
        msgbuf << "Unterminated string found: " << *yylloc;
-       ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+       ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
        BEGIN(INITIAL);
                                }
 
@@ -130,7 +130,7 @@ static char *lb_steal(lex_buf *lb)
                /* error, constant is out-of-bounds */
                std::ostringstream msgbuf;
                msgbuf << "Constant is out-of-bounds: " << yytext << " " << *yylloc;
-               ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+               ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
        }
 
        lb_append_char(&string_buf, result);
@@ -142,7 +142,7 @@ static char *lb_steal(lex_buf *lb)
         */
        std::ostringstream msgbuf;
        msgbuf << "Bad escape sequence found: " << yytext << " " << *yylloc;
-       ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+       ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
                                }
 
 <STRING>\\n                    { lb_append_char(&string_buf, '\n'); }
@@ -199,7 +199,6 @@ name                                { yylval->type = TypeName; return T_TYPE_NAME; }
 %require                       { return T_REQUIRE; }
 %attribute                     { return T_ATTRIBUTE; }
 abstract                       return T_ABSTRACT;
-local                          return T_LOCAL;
 object                         return T_OBJECT;
 template                       return T_TEMPLATE;
 include                                return T_INCLUDE;
index 1454019d5f53d81f1a9856644d67e37ede5a6f5e..6857ef60479a2ea07e7974379eeba69de343c7ac 100644 (file)
@@ -170,13 +170,12 @@ using namespace icinga;
      T_ATTRIBUTE = 280,
      T_TYPE = 281,
      T_ABSTRACT = 282,
-     T_LOCAL = 283,
-     T_OBJECT = 284,
-     T_TEMPLATE = 285,
-     T_INCLUDE = 286,
-     T_LIBRARY = 287,
-     T_INHERITS = 288,
-     T_PARTIAL = 289
+     T_OBJECT = 283,
+     T_TEMPLATE = 284,
+     T_INCLUDE = 285,
+     T_LIBRARY = 286,
+     T_INHERITS = 287,
+     T_PARTIAL = 288
    };
 #endif
 /* Tokens.  */
@@ -205,13 +204,12 @@ using namespace icinga;
 #define T_ATTRIBUTE 280
 #define T_TYPE 281
 #define T_ABSTRACT 282
-#define T_LOCAL 283
-#define T_OBJECT 284
-#define T_TEMPLATE 285
-#define T_INCLUDE 286
-#define T_LIBRARY 287
-#define T_INHERITS 288
-#define T_PARTIAL 289
+#define T_OBJECT 283
+#define T_TEMPLATE 284
+#define T_INCLUDE 285
+#define T_LIBRARY 286
+#define T_INHERITS 287
+#define T_PARTIAL 288
 
 
 
@@ -236,7 +234,7 @@ typedef union YYSTYPE
 
 
 /* Line 293 of yacc.c  */
-#line 240 "../../../lib/config/config_parser.cc"
+#line 238 "../../../lib/config/config_parser.cc"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -260,7 +258,7 @@ typedef struct YYLTYPE
 /* Copy the second part of user declarations.  */
 
 /* Line 343 of yacc.c  */
-#line 120 "config_parser.yy"
+#line 119 "config_parser.yy"
 
 
 int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
@@ -269,26 +267,23 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err)
 {
        std::ostringstream message;
        message << *locp << ": " << err;
-       ConfigCompilerContext::GetContext()->AddError(false, message.str());
+       ConfigCompilerContext::GetInstance()->AddError(false, message.str());
 }
 
 int yyparse(ConfigCompiler *context);
 
 static std::stack<Array::Ptr> m_Arrays;
 static bool m_Abstract;
-static bool m_Local;
 
 static std::stack<TypeRuleList::Ptr> m_RuleLists;
 static ConfigType::Ptr m_Type;
 
 void ConfigCompiler::Compile(void)
 {
-       ASSERT(ConfigCompilerContext::GetContext() != NULL);
-
        try {
                yyparse(this);
        } catch (const std::exception& ex) {
-               ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex));
+               ConfigCompilerContext::GetInstance()->AddError(false, boost::diagnostic_information(ex));
        }
 }
 
@@ -297,7 +292,7 @@ void ConfigCompiler::Compile(void)
 
 
 /* Line 343 of yacc.c  */
-#line 301 "../../../lib/config/config_parser.cc"
+#line 296 "../../../lib/config/config_parser.cc"
 
 #ifdef short
 # undef short
@@ -518,20 +513,20 @@ union yyalloc
 /* YYFINAL -- State number of the termination state.  */
 #define YYFINAL  2
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   147
+#define YYLAST   149
 
 /* YYNTOKENS -- Number of terminals.  */
-#define YYNTOKENS  48
+#define YYNTOKENS  47
 /* YYNNTS -- Number of nonterminals.  */
 #define YYNNTS  35
 /* YYNRULES -- Number of rules.  */
-#define YYNRULES  90
+#define YYNRULES  89
 /* YYNRULES -- Number of states.  */
-#define YYNSTATES  132
+#define YYNSTATES  131
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
 #define YYUNDEFTOK  2
-#define YYMAXUTOK   289
+#define YYMAXUTOK   288
 
 #define YYTRANSLATE(YYX)                                               \
   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@@ -542,16 +537,16 @@ static const yytype_uint8 yytranslate[] =
        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,     2,     2,     2,     2,     2,    39,     2,
-      44,    45,    37,    35,    43,    36,     2,    38,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,    38,     2,
+      43,    44,    36,    34,    42,    35,     2,    37,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,    46,     2,    47,     2,     2,     2,     2,     2,     2,
+       2,    45,     2,    46,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
-       2,     2,     2,    41,    40,    42,     2,     2,     2,     2,
+       2,     2,     2,    40,    39,    41,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
@@ -567,7 +562,7 @@ static const yytype_uint8 yytranslate[] =
        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
-      25,    26,    27,    28,    29,    30,    31,    32,    33,    34
+      25,    26,    27,    28,    29,    30,    31,    32,    33
 };
 
 #if YYDEBUG
@@ -579,57 +574,55 @@ static const yytype_uint8 yyprhs[] =
       20,    23,    26,    31,    33,    35,    36,    43,    44,    46,
       47,    52,    54,    57,    58,    60,    64,    67,    70,    74,
       81,    86,    87,    90,    92,    94,    96,    98,   100,   102,
-     104,   105,   112,   115,   117,   118,   121,   123,   125,   126,
-     128,   132,   133,   136,   140,   142,   145,   146,   148,   152,
-     156,   163,   165,   167,   169,   171,   173,   177,   179,   182,
-     183,   185,   189,   191,   193,   195,   197,   201,   203,   205,
-     209,   213,   217,   221,   225,   229,   233,   237,   241,   243,
-     245
+     104,   105,   112,   115,   117,   118,   121,   123,   124,   126,
+     130,   131,   134,   138,   140,   143,   144,   146,   150,   154,
+     161,   163,   165,   167,   169,   171,   175,   177,   180,   181,
+     183,   187,   189,   191,   193,   195,   199,   201,   203,   207,
+     211,   215,   219,   223,   227,   231,   235,   239,   241,   243
 };
 
 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
 static const yytype_int8 yyrhs[] =
 {
-      49,     0,    -1,    -1,    49,    50,    -1,    64,    -1,    55,
-      -1,    51,    -1,    52,    -1,    53,    -1,    31,     3,    -1,
-      31,     4,    -1,    32,     3,    -1,    13,    54,     8,    82,
-      -1,     7,    -1,     3,    -1,    -1,    57,    26,    54,    56,
-      63,    58,    -1,    -1,    34,    -1,    -1,    41,    59,    60,
-      42,    -1,    61,    -1,    61,    43,    -1,    -1,    62,    -1,
-      61,    43,    62,    -1,    24,     3,    -1,    23,     3,    -1,
-      25,    55,     3,    -1,    25,    22,    44,    54,    45,     3,
-      -1,    25,    55,     3,    58,    -1,    -1,    33,    54,    -1,
+      48,     0,    -1,    -1,    48,    49,    -1,    63,    -1,    54,
+      -1,    50,    -1,    51,    -1,    52,    -1,    30,     3,    -1,
+      30,     4,    -1,    31,     3,    -1,    13,    53,     8,    81,
+      -1,     7,    -1,     3,    -1,    -1,    56,    26,    53,    55,
+      62,    57,    -1,    -1,    33,    -1,    -1,    40,    58,    59,
+      41,    -1,    60,    -1,    60,    42,    -1,    -1,    61,    -1,
+      60,    42,    61,    -1,    24,     3,    -1,    23,     3,    -1,
+      25,    54,     3,    -1,    25,    22,    43,    53,    44,     3,
+      -1,    25,    54,     3,    57,    -1,    -1,    32,    53,    -1,
       16,    -1,    17,    -1,    18,    -1,    19,    -1,    20,    -1,
-      21,    -1,    22,    -1,    -1,    65,    66,    54,     3,    70,
-      71,    -1,    67,    29,    -1,    30,    -1,    -1,    67,    68,
-      -1,    27,    -1,    28,    -1,    -1,     3,    -1,    69,    43,
-       3,    -1,    -1,    33,    69,    -1,    41,    72,    42,    -1,
-      73,    -1,    73,    43,    -1,    -1,    74,    -1,    73,    43,
-      74,    -1,    54,    75,    82,    -1,    54,    46,     3,    47,
-      75,    82,    -1,     8,    -1,     9,    -1,    10,    -1,    11,
-      -1,    12,    -1,    46,    77,    47,    -1,    78,    -1,    78,
-      43,    -1,    -1,    82,    -1,    78,    43,    82,    -1,     3,
-      -1,     5,    -1,     6,    -1,    76,    -1,    44,    81,    45,
-      -1,     5,    -1,    54,    -1,    81,    35,    81,    -1,    81,
-      36,    81,    -1,    81,    37,    81,    -1,    81,    38,    81,
-      -1,    81,    39,    81,    -1,    81,    40,    81,    -1,    81,
-      14,    81,    -1,    81,    15,    81,    -1,    44,    81,    45,
-      -1,    79,    -1,    71,    -1,    80,    -1
+      21,    -1,    22,    -1,    -1,    64,    65,    53,     3,    69,
+      70,    -1,    66,    28,    -1,    29,    -1,    -1,    66,    67,
+      -1,    27,    -1,    -1,     3,    -1,    68,    42,     3,    -1,
+      -1,    32,    68,    -1,    40,    71,    41,    -1,    72,    -1,
+      72,    42,    -1,    -1,    73,    -1,    72,    42,    73,    -1,
+      53,    74,    81,    -1,    53,    45,     3,    46,    74,    81,
+      -1,     8,    -1,     9,    -1,    10,    -1,    11,    -1,    12,
+      -1,    45,    76,    46,    -1,    77,    -1,    77,    42,    -1,
+      -1,    81,    -1,    77,    42,    81,    -1,     3,    -1,     5,
+      -1,     6,    -1,    75,    -1,    43,    80,    44,    -1,     5,
+      -1,    53,    -1,    80,    34,    80,    -1,    80,    35,    80,
+      -1,    80,    36,    80,    -1,    80,    37,    80,    -1,    80,
+      38,    80,    -1,    80,    39,    80,    -1,    80,    14,    80,
+      -1,    80,    15,    80,    -1,    43,    80,    44,    -1,    78,
+      -1,    70,    -1,    79,    -1
 };
 
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint16 yyrline[] =
 {
-       0,   156,   156,   157,   160,   160,   160,   160,   160,   163,
-     168,   174,   180,   187,   188,   195,   194,   224,   227,   234,
-     233,   245,   246,   248,   249,   250,   253,   258,   263,   270,
-     278,   287,   288,   295,   296,   297,   298,   299,   300,   301,
-     308,   308,   353,   354,   359,   360,   363,   367,   374,   377,
-     383,   396,   399,   405,   411,   415,   421,   424,   430,   442,
-     448,   462,   463,   464,   465,   466,   472,   478,   482,   488,
-     491,   506,   526,   531,   535,   539,   549,   554,   558,   563,
-     567,   571,   575,   579,   583,   587,   591,   595,   601,   602,
-     607
+       0,   152,   152,   153,   156,   156,   156,   156,   156,   159,
+     164,   170,   176,   183,   184,   191,   190,   220,   223,   230,
+     229,   241,   242,   244,   245,   246,   249,   254,   259,   266,
+     274,   283,   284,   291,   292,   293,   294,   295,   296,   297,
+     304,   304,   345,   346,   351,   352,   355,   362,   365,   371,
+     384,   387,   393,   399,   403,   409,   412,   418,   430,   436,
+     450,   451,   452,   453,   454,   460,   466,   470,   476,   479,
+     494,   514,   519,   523,   527,   537,   542,   546,   551,   555,
+     559,   563,   567,   571,   575,   579,   583,   589,   590,   595
 };
 #endif
 
@@ -648,20 +641,19 @@ static const char *const yytname[] =
   "\"any (T_TYPE_ANY)\"", "\"name (T_TYPE_NAME)\"",
   "\"%validator (T_VALIDATOR)\"", "\"%require (T_REQUIRE)\"",
   "\"%attribute (T_ATTRIBUTE)\"", "\"type (T_TYPE)\"",
-  "\"abstract (T_ABSTRACT)\"", "\"local (T_LOCAL)\"",
-  "\"object (T_OBJECT)\"", "\"template (T_TEMPLATE)\"",
-  "\"include (T_INCLUDE)\"", "\"library (T_LIBRARY)\"",
-  "\"inherits (T_INHERITS)\"", "\"partial (T_PARTIAL)\"", "'+'", "'-'",
-  "'*'", "'/'", "'&'", "'|'", "'{'", "'}'", "','", "'('", "')'", "'['",
-  "']'", "$accept", "statements", "statement", "include", "library",
-  "variable", "identifier", "type", "$@1", "partial_specifier",
-  "typerulelist", "$@2", "typerules", "typerules_inner", "typerule",
-  "type_inherits_specifier", "object", "$@3", "object_declaration",
-  "attributes", "attribute", "object_inherits_list",
-  "object_inherits_specifier", "expressionlist", "expressions",
-  "expressions_inner", "expression", "operator", "array", "array_items",
-  "array_items_inner", "simplevalue", "constterm", "constexpression",
-  "value", 0
+  "\"abstract (T_ABSTRACT)\"", "\"object (T_OBJECT)\"",
+  "\"template (T_TEMPLATE)\"", "\"include (T_INCLUDE)\"",
+  "\"library (T_LIBRARY)\"", "\"inherits (T_INHERITS)\"",
+  "\"partial (T_PARTIAL)\"", "'+'", "'-'", "'*'", "'/'", "'&'", "'|'",
+  "'{'", "'}'", "','", "'('", "')'", "'['", "']'", "$accept", "statements",
+  "statement", "include", "library", "variable", "identifier", "type",
+  "$@1", "partial_specifier", "typerulelist", "$@2", "typerules",
+  "typerules_inner", "typerule", "type_inherits_specifier", "object",
+  "$@3", "object_declaration", "attributes", "attribute",
+  "object_inherits_list", "object_inherits_specifier", "expressionlist",
+  "expressions", "expressions_inner", "expression", "operator", "array",
+  "array_items", "array_items_inner", "simplevalue", "constterm",
+  "constexpression", "value", 0
 };
 #endif
 
@@ -673,24 +665,23 @@ static const yytype_uint16 yytoknum[] =
        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
-     285,   286,   287,   288,   289,    43,    45,    42,    47,    38,
-     124,   123,   125,    44,    40,    41,    91,    93
+     285,   286,   287,   288,    43,    45,    42,    47,    38,   124,
+     123,   125,    44,    40,    41,    91,    93
 };
 # endif
 
 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
 static const yytype_uint8 yyr1[] =
 {
-       0,    48,    49,    49,    50,    50,    50,    50,    50,    51,
-      51,    52,    53,    54,    54,    56,    55,    57,    57,    59,
-      58,    60,    60,    61,    61,    61,    62,    62,    62,    62,
-      62,    63,    63,    55,    55,    55,    55,    55,    55,    55,
-      65,    64,    66,    66,    67,    67,    68,    68,    69,    69,
-      69,    70,    70,    71,    72,    72,    73,    73,    73,    74,
-      74,    75,    75,    75,    75,    75,    76,    77,    77,    78,
-      78,    78,    79,    79,    79,    79,    80,    81,    81,    81,
-      81,    81,    81,    81,    81,    81,    81,    81,    82,    82,
-      82
+       0,    47,    48,    48,    49,    49,    49,    49,    49,    50,
+      50,    51,    52,    53,    53,    55,    54,    56,    56,    58,
+      57,    59,    59,    60,    60,    60,    61,    61,    61,    61,
+      61,    62,    62,    54,    54,    54,    54,    54,    54,    54,
+      64,    63,    65,    65,    66,    66,    67,    68,    68,    68,
+      69,    69,    70,    71,    71,    72,    72,    72,    73,    73,
+      74,    74,    74,    74,    74,    75,    76,    76,    77,    77,
+      77,    78,    78,    78,    78,    79,    80,    80,    80,    80,
+      80,    80,    80,    80,    80,    80,    80,    81,    81,    81
 };
 
 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
@@ -700,12 +691,11 @@ static const yytype_uint8 yyr2[] =
        2,     2,     4,     1,     1,     0,     6,     0,     1,     0,
        4,     1,     2,     0,     1,     3,     2,     2,     3,     6,
        4,     0,     2,     1,     1,     1,     1,     1,     1,     1,
-       0,     6,     2,     1,     0,     2,     1,     1,     0,     1,
-       3,     0,     2,     3,     1,     2,     0,     1,     3,     3,
-       6,     1,     1,     1,     1,     1,     3,     1,     2,     0,
-       1,     3,     1,     1,     1,     1,     3,     1,     1,     3,
-       3,     3,     3,     3,     3,     3,     3,     3,     1,     1,
-       1
+       0,     6,     2,     1,     0,     2,     1,     0,     1,     3,
+       0,     2,     3,     1,     2,     0,     1,     3,     3,     6,
+       1,     1,     1,     1,     1,     3,     1,     2,     0,     1,
+       3,     1,     1,     1,     1,     3,     1,     1,     3,     3,
+       3,     3,     3,     3,     3,     3,     3,     1,     1,     1
 };
 
 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
@@ -716,56 +706,56 @@ static const yytype_uint8 yydefact[] =
        2,    40,     1,     0,    33,    34,    35,    36,    37,    38,
       39,     0,     0,    18,     3,     6,     7,     8,     5,     0,
        4,    44,    14,    13,     0,     9,    10,    11,     0,    43,
-       0,     0,     0,    15,     0,    46,    47,    42,    45,    72,
-      73,    74,    56,     0,    69,    89,    75,    88,    90,    12,
-      31,    51,     0,     0,    54,    57,    77,     0,    78,     0,
-       0,    67,    70,     0,     0,    48,     0,    61,    62,    63,
-      64,    65,     0,     0,    53,    55,     0,     0,     0,     0,
-       0,     0,     0,     0,     0,    76,    66,    68,    32,    19,
-      16,    49,    52,    41,     0,    59,    58,    87,    85,    86,
-      79,    80,    81,    82,    83,    84,    71,    23,     0,     0,
-       0,     0,    17,     0,    21,    24,    50,     0,    27,    26,
-      39,     0,    20,    22,    60,     0,    28,    25,     0,    30,
-       0,    29
+       0,     0,     0,    15,     0,    46,    42,    45,    71,    72,
+      73,    55,     0,    68,    88,    74,    87,    89,    12,    31,
+      50,     0,     0,    53,    56,    76,     0,    77,     0,     0,
+      66,    69,     0,     0,    47,     0,    60,    61,    62,    63,
+      64,     0,     0,    52,    54,     0,     0,     0,     0,     0,
+       0,     0,     0,     0,    75,    65,    67,    32,    19,    16,
+      48,    51,    41,     0,    58,    57,    86,    84,    85,    78,
+      79,    80,    81,    82,    83,    70,    23,     0,     0,     0,
+       0,    17,     0,    21,    24,    49,     0,    27,    26,    39,
+       0,    20,    22,    59,     0,    28,    25,     0,    30,     0,
+      29
 };
 
 /* YYDEFGOTO[NTERM-NUM].  */
 static const yytype_int8 yydefgoto[] =
 {
-      -1,     1,    14,    15,    16,    17,    58,    18,    50,    19,
-      90,   107,   113,   114,   115,    64,    20,    21,    30,    31,
-      38,    92,    66,    45,    53,    54,    55,    73,    46,    60,
-      61,    47,    48,    59,    49
+      -1,     1,    14,    15,    16,    17,    57,    18,    49,    19,
+      89,   106,   112,   113,   114,    63,    20,    21,    30,    31,
+      37,    91,    65,    44,    52,    53,    54,    72,    45,    59,
+      60,    46,    47,    58,    48
 };
 
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
-#define YYPACT_NINF -44
+#define YYPACT_NINF -43
 static const yytype_int8 yypact[] =
 {
-     -44,    35,   -44,     0,   -44,   -44,   -44,   -44,   -44,   -44,
-     -44,    19,    21,   -44,   -44,   -44,   -44,   -44,   -44,   -17,
-     -44,   -19,   -44,   -44,    18,   -44,   -44,   -44,     0,   -44,
-       0,   -10,    -1,   -44,    31,   -44,   -44,   -44,   -44,   -44,
-     -44,   -44,     0,     3,    -1,   -44,   -44,   -44,   -44,   -44,
-       9,    16,     4,    -6,    -2,   -44,   -44,     3,   -44,    44,
-      17,    22,   -44,     0,    27,    70,    34,   -44,   -44,   -44,
-     -44,   -44,    73,    -1,   -44,     0,    56,     3,     3,     3,
-       3,     3,     3,     3,     3,   -44,   -44,    -1,   -44,   -44,
-     -44,   -44,    43,   -44,    30,   -44,   -44,   -44,    88,    88,
-      99,    99,    23,    23,     6,    14,   -44,     8,    75,   107,
-      84,    85,   113,    48,    54,   -44,   -44,    -1,   -44,   -44,
-      55,    95,   -44,     8,   -44,     0,    27,   -44,    59,   -44,
-      97,   -44
+     -43,    35,   -43,     1,   -43,   -43,   -43,   -43,   -43,   -43,
+     -43,    20,    -1,   -43,   -43,   -43,   -43,   -43,   -43,   -16,
+     -43,   -17,   -43,   -43,    18,   -43,   -43,   -43,     1,   -43,
+       1,     6,     0,   -43,    28,   -43,   -43,   -43,   -43,   -43,
+     -43,     1,     4,     0,   -43,   -43,   -43,   -43,   -43,     9,
+      10,     5,    -9,    -6,   -43,   -43,     4,   -43,    48,    -7,
+      16,   -43,     1,    24,    34,    27,   -43,   -43,   -43,   -43,
+     -43,    46,     0,   -43,     1,    61,     4,     4,     4,     4,
+       4,     4,     4,     4,   -43,   -43,     0,   -43,   -43,   -43,
+     -43,    30,   -43,    43,   -43,   -43,   -43,    88,    88,    92,
+      92,    55,    55,     7,    14,   -43,    -5,    57,    69,    70,
+      87,   116,    50,    59,   -43,   -43,     0,   -43,   -43,    73,
+     101,   -43,    -5,   -43,     1,    24,   -43,    74,   -43,   114,
+     -43
 };
 
 /* YYPGOTO[NTERM-NUM].  */
 static const yytype_int8 yypgoto[] =
 {
-     -44,   -44,   -44,   -44,   -44,   -44,    -3,    29,   -44,   -44,
-      -5,   -44,   -44,   -44,    20,   -44,   -44,   -44,   -44,   -44,
-     -44,   -44,   -44,    74,   -44,   -44,    45,    33,   -44,   -44,
-     -44,   -44,   -44,    28,   -43
+     -43,   -43,   -43,   -43,   -43,   -43,    -3,     8,   -43,   -43,
+      15,   -43,   -43,   -43,    -2,   -43,   -43,   -43,   -43,   -43,
+     -43,   -43,   -43,    76,   -43,   -43,    65,    36,   -43,   -43,
+     -43,   -43,   -43,    32,   -42
 };
 
 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
@@ -774,66 +764,66 @@ static const yytype_int8 yypgoto[] =
 #define YYTABLE_NINF -18
 static const yytype_int16 yytable[] =
 {
-      24,    62,    39,    22,    40,    41,    22,    23,    56,    28,
-      23,    29,    67,    68,    69,    70,    71,    35,    36,    37,
-      77,    78,    25,    26,    27,    33,    32,    34,    77,    78,
-      95,   110,   111,   112,    51,     2,    74,    77,    78,    52,
-      42,    75,    63,    43,   106,    44,    84,    57,     3,    65,
-      72,     4,     5,     6,     7,     8,     9,    10,    77,    78,
-      88,   -17,    83,    84,    86,    87,    11,    12,    89,    13,
-      77,    78,    52,    91,   124,    42,    94,   109,   116,    79,
-      80,    81,    82,    83,    84,    76,   108,   118,   119,    85,
-     122,    79,    80,    81,    82,    83,    84,   123,   126,   125,
-     131,    97,    77,    78,   130,    98,    99,   100,   101,   102,
-     103,   104,   105,    77,    78,    67,    68,    69,    70,    71,
-      96,   129,   128,    79,    80,    81,    82,    83,    84,     4,
-       5,     6,     7,     8,     9,   120,    81,    82,    83,    84,
-      93,   121,   117,   127,     0,     0,     0,    13
+      24,    61,    27,    38,    22,    39,    40,    22,    23,    55,
+      28,    23,    29,    66,    67,    68,    69,    70,   109,   110,
+     111,    76,    77,    25,    26,    33,    32,    34,    76,    77,
+      94,    50,    73,    35,    36,     2,    74,    90,    51,    85,
+      41,    62,    64,    42,   105,    43,    83,    56,     3,    93,
+      71,     4,     5,     6,     7,     8,     9,    10,    86,    87,
+     115,   -17,    76,    77,    88,    11,    12,    41,    13,    76,
+      77,    51,   107,   117,   123,    76,    77,    66,    67,    68,
+      69,    70,    78,    79,    80,    81,    82,    83,    75,   108,
+     118,   121,    84,    82,    83,    78,    79,    80,    81,    82,
+      83,   122,    76,    77,   125,    96,    76,    77,    97,    98,
+      99,   100,   101,   102,   103,   104,   124,   130,   129,   120,
+     126,   127,    78,    79,    80,    81,    82,    83,    80,    81,
+      82,    83,     4,     5,     6,     7,     8,     9,   119,    95,
+     128,    92,     0,     0,   116,     0,     0,     0,     0,    13
 };
 
 #define yypact_value_is_default(yystate) \
-  ((yystate) == (-44))
+  ((yystate) == (-43))
 
 #define yytable_value_is_error(yytable_value) \
   YYID (0)
 
 static const yytype_int8 yycheck[] =
 {
-       3,    44,     3,     3,     5,     6,     3,     7,     5,    26,
-       7,    30,     8,     9,    10,    11,    12,    27,    28,    29,
-      14,    15,     3,     4,     3,    28,     8,    30,    14,    15,
-      73,    23,    24,    25,     3,     0,    42,    14,    15,    42,
-      41,    43,    33,    44,    87,    46,    40,    44,    13,    33,
-      46,    16,    17,    18,    19,    20,    21,    22,    14,    15,
-      63,    26,    39,    40,    47,    43,    31,    32,    41,    34,
-      14,    15,    75,     3,   117,    41,     3,    47,     3,    35,
-      36,    37,    38,    39,    40,    57,    43,     3,     3,    45,
-      42,    35,    36,    37,    38,    39,    40,    43,     3,    44,
-       3,    45,    14,    15,    45,    77,    78,    79,    80,    81,
-      82,    83,    84,    14,    15,     8,     9,    10,    11,    12,
-      75,   126,   125,    35,    36,    37,    38,    39,    40,    16,
-      17,    18,    19,    20,    21,    22,    37,    38,    39,    40,
-      66,   112,   109,   123,    -1,    -1,    -1,    34
+       3,    43,     3,     3,     3,     5,     6,     3,     7,     5,
+      26,     7,    29,     8,     9,    10,    11,    12,    23,    24,
+      25,    14,    15,     3,     4,    28,     8,    30,    14,    15,
+      72,     3,    41,    27,    28,     0,    42,     3,    41,    46,
+      40,    32,    32,    43,    86,    45,    39,    43,    13,     3,
+      45,    16,    17,    18,    19,    20,    21,    22,    42,    62,
+       3,    26,    14,    15,    40,    30,    31,    40,    33,    14,
+      15,    74,    42,     3,   116,    14,    15,     8,     9,    10,
+      11,    12,    34,    35,    36,    37,    38,    39,    56,    46,
+       3,    41,    44,    38,    39,    34,    35,    36,    37,    38,
+      39,    42,    14,    15,     3,    44,    14,    15,    76,    77,
+      78,    79,    80,    81,    82,    83,    43,     3,    44,   111,
+     122,   124,    34,    35,    36,    37,    38,    39,    36,    37,
+      38,    39,    16,    17,    18,    19,    20,    21,    22,    74,
+     125,    65,    -1,    -1,   108,    -1,    -1,    -1,    -1,    33
 };
 
 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
    symbol of state STATE-NUM.  */
 static const yytype_uint8 yystos[] =
 {
-       0,    49,     0,    13,    16,    17,    18,    19,    20,    21,
-      22,    31,    32,    34,    50,    51,    52,    53,    55,    57,
-      64,    65,     3,     7,    54,     3,     4,     3,    26,    30,
-      66,    67,     8,    54,    54,    27,    28,    29,    68,     3,
-       5,     6,    41,    44,    46,    71,    76,    79,    80,    82,
-      56,     3,    54,    72,    73,    74,     5,    44,    54,    81,
-      77,    78,    82,    33,    63,    33,    70,     8,     9,    10,
-      11,    12,    46,    75,    42,    43,    81,    14,    15,    35,
-      36,    37,    38,    39,    40,    45,    47,    43,    54,    41,
-      58,     3,    69,    71,     3,    82,    74,    45,    81,    81,
-      81,    81,    81,    81,    81,    81,    82,    59,    43,    47,
-      23,    24,    25,    60,    61,    62,     3,    75,     3,     3,
-      22,    55,    42,    43,    82,    44,     3,    62,    54,    58,
-      45,     3
+       0,    48,     0,    13,    16,    17,    18,    19,    20,    21,
+      22,    30,    31,    33,    49,    50,    51,    52,    54,    56,
+      63,    64,     3,     7,    53,     3,     4,     3,    26,    29,
+      65,    66,     8,    53,    53,    27,    28,    67,     3,     5,
+       6,    40,    43,    45,    70,    75,    78,    79,    81,    55,
+       3,    53,    71,    72,    73,     5,    43,    53,    80,    76,
+      77,    81,    32,    62,    32,    69,     8,     9,    10,    11,
+      12,    45,    74,    41,    42,    80,    14,    15,    34,    35,
+      36,    37,    38,    39,    44,    46,    42,    53,    40,    57,
+       3,    68,    70,     3,    81,    73,    44,    80,    80,    80,
+      80,    80,    80,    80,    80,    81,    58,    42,    46,    23,
+      24,    25,    59,    60,    61,     3,    74,     3,     3,    22,
+      54,    41,    42,    81,    43,     3,    61,    53,    57,    44,
+       3
 };
 
 #define yyerrok                (yyerrstatus = 0)
@@ -1719,7 +1709,7 @@ yyreduce:
         case 9:
 
 /* Line 1806 of yacc.c  */
-#line 164 "config_parser.yy"
+#line 160 "config_parser.yy"
     {
                context->HandleInclude((yyvsp[(2) - (2)].text), false, yylloc);
                free((yyvsp[(2) - (2)].text));
@@ -1729,7 +1719,7 @@ yyreduce:
   case 10:
 
 /* Line 1806 of yacc.c  */
-#line 169 "config_parser.yy"
+#line 165 "config_parser.yy"
     {
                context->HandleInclude((yyvsp[(2) - (2)].text), true, yylloc);
                free((yyvsp[(2) - (2)].text));
@@ -1739,7 +1729,7 @@ yyreduce:
   case 11:
 
 /* Line 1806 of yacc.c  */
-#line 175 "config_parser.yy"
+#line 171 "config_parser.yy"
     {
                context->HandleLibrary((yyvsp[(2) - (2)].text));
                free((yyvsp[(2) - (2)].text));
@@ -1749,7 +1739,7 @@ yyreduce:
   case 12:
 
 /* Line 1806 of yacc.c  */
-#line 181 "config_parser.yy"
+#line 177 "config_parser.yy"
     {
                ScriptVariable::Set((yyvsp[(2) - (4)].text), *(yyvsp[(4) - (4)].variant));
                free((yyvsp[(2) - (4)].text));
@@ -1760,7 +1750,7 @@ yyreduce:
   case 14:
 
 /* Line 1806 of yacc.c  */
-#line 189 "config_parser.yy"
+#line 185 "config_parser.yy"
     {
                (yyval.text) = (yyvsp[(1) - (1)].text);
        }
@@ -1769,19 +1759,19 @@ yyreduce:
   case 15:
 
 /* Line 1806 of yacc.c  */
-#line 195 "config_parser.yy"
+#line 191 "config_parser.yy"
     {
                String name = String((yyvsp[(3) - (3)].text));
                free((yyvsp[(3) - (3)].text));
 
-               m_Type = ConfigCompilerContext::GetContext()->GetType(name);
+               m_Type = ConfigType::GetByName(name);
 
                if (!m_Type) {
                        if ((yyvsp[(1) - (3)].num))
                                BOOST_THROW_EXCEPTION(std::invalid_argument("Partial type definition for unknown type '" + name + "'"));
 
                        m_Type = boost::make_shared<ConfigType>(name, yylloc);
-                       ConfigCompilerContext::GetContext()->AddType(m_Type);
+                       m_Type->Register();
                }
        }
     break;
@@ -1789,7 +1779,7 @@ yyreduce:
   case 16:
 
 /* Line 1806 of yacc.c  */
-#line 210 "config_parser.yy"
+#line 206 "config_parser.yy"
     {
                TypeRuleList::Ptr ruleList = *(yyvsp[(6) - (6)].variant);
                m_Type->GetRuleList()->AddRules(ruleList);
@@ -1806,7 +1796,7 @@ yyreduce:
   case 17:
 
 /* Line 1806 of yacc.c  */
-#line 224 "config_parser.yy"
+#line 220 "config_parser.yy"
     {
                (yyval.num) = 0;
        }
@@ -1815,7 +1805,7 @@ yyreduce:
   case 18:
 
 /* Line 1806 of yacc.c  */
-#line 228 "config_parser.yy"
+#line 224 "config_parser.yy"
     {
                (yyval.num) = 1;
        }
@@ -1824,7 +1814,7 @@ yyreduce:
   case 19:
 
 /* Line 1806 of yacc.c  */
-#line 234 "config_parser.yy"
+#line 230 "config_parser.yy"
     {
                m_RuleLists.push(boost::make_shared<TypeRuleList>());
        }
@@ -1833,7 +1823,7 @@ yyreduce:
   case 20:
 
 /* Line 1806 of yacc.c  */
-#line 239 "config_parser.yy"
+#line 235 "config_parser.yy"
     {
                (yyval.variant) = new Value(m_RuleLists.top());
                m_RuleLists.pop();
@@ -1843,7 +1833,7 @@ yyreduce:
   case 26:
 
 /* Line 1806 of yacc.c  */
-#line 254 "config_parser.yy"
+#line 250 "config_parser.yy"
     {
                m_RuleLists.top()->AddRequire((yyvsp[(2) - (2)].text));
                free((yyvsp[(2) - (2)].text));
@@ -1853,7 +1843,7 @@ yyreduce:
   case 27:
 
 /* Line 1806 of yacc.c  */
-#line 259 "config_parser.yy"
+#line 255 "config_parser.yy"
     {
                m_RuleLists.top()->SetValidator((yyvsp[(2) - (2)].text));
                free((yyvsp[(2) - (2)].text));
@@ -1863,7 +1853,7 @@ yyreduce:
   case 28:
 
 /* Line 1806 of yacc.c  */
-#line 264 "config_parser.yy"
+#line 260 "config_parser.yy"
     {
                TypeRule rule((yyvsp[(2) - (3)].type), String(), (yyvsp[(3) - (3)].text), TypeRuleList::Ptr(), yylloc);
                free((yyvsp[(3) - (3)].text));
@@ -1875,7 +1865,7 @@ yyreduce:
   case 29:
 
 /* Line 1806 of yacc.c  */
-#line 271 "config_parser.yy"
+#line 267 "config_parser.yy"
     {
                TypeRule rule((yyvsp[(2) - (6)].type), (yyvsp[(4) - (6)].text), (yyvsp[(6) - (6)].text), TypeRuleList::Ptr(), yylloc);
                free((yyvsp[(4) - (6)].text));
@@ -1888,7 +1878,7 @@ yyreduce:
   case 30:
 
 /* Line 1806 of yacc.c  */
-#line 279 "config_parser.yy"
+#line 275 "config_parser.yy"
     {
                TypeRule rule((yyvsp[(2) - (4)].type), String(), (yyvsp[(3) - (4)].text), *(yyvsp[(4) - (4)].variant), yylloc);
                free((yyvsp[(3) - (4)].text));
@@ -1900,7 +1890,7 @@ yyreduce:
   case 32:
 
 /* Line 1806 of yacc.c  */
-#line 289 "config_parser.yy"
+#line 285 "config_parser.yy"
     {
                m_Type->SetParent((yyvsp[(2) - (2)].text));
                free((yyvsp[(2) - (2)].text));
@@ -1910,7 +1900,7 @@ yyreduce:
   case 39:
 
 /* Line 1806 of yacc.c  */
-#line 302 "config_parser.yy"
+#line 298 "config_parser.yy"
     {
                (yyval.type) = (yyvsp[(1) - (1)].type);
        }
@@ -1919,17 +1909,16 @@ yyreduce:
   case 40:
 
 /* Line 1806 of yacc.c  */
-#line 308 "config_parser.yy"
+#line 304 "config_parser.yy"
     {
                m_Abstract = false;
-               m_Local = false;
        }
     break;
 
   case 41:
 
 /* Line 1806 of yacc.c  */
-#line 313 "config_parser.yy"
+#line 308 "config_parser.yy"
     {
                ConfigItemBuilder::Ptr item = boost::make_shared<ConfigItemBuilder>(yylloc);
 
@@ -1947,8 +1936,6 @@ yyreduce:
                item->SetName((yyvsp[(4) - (6)].text));
                free((yyvsp[(4) - (6)].text));
 
-               item->SetUnit(ConfigCompilerContext::GetContext()->GetUnit());
-
                if ((yyvsp[(5) - (6)].slist)) {
                        BOOST_FOREACH(const String& parent, *(yyvsp[(5) - (6)].slist)) {
                                item->AddParent(parent);
@@ -1962,10 +1949,9 @@ yyreduce:
                        item->AddExpressionList(exprl);
                }
 
-               item->SetLocal(m_Local);
                item->SetAbstract(m_Abstract);
 
-               ConfigCompilerContext::GetContext()->AddItem(item->Compile());
+               item->Compile()->Register();
                item.reset();
        }
     break;
@@ -1973,7 +1959,7 @@ yyreduce:
   case 43:
 
 /* Line 1806 of yacc.c  */
-#line 355 "config_parser.yy"
+#line 347 "config_parser.yy"
     {
                m_Abstract = true;
        }
@@ -1982,7 +1968,7 @@ yyreduce:
   case 46:
 
 /* Line 1806 of yacc.c  */
-#line 364 "config_parser.yy"
+#line 356 "config_parser.yy"
     {
                m_Abstract = true;
        }
@@ -1991,25 +1977,16 @@ yyreduce:
   case 47:
 
 /* Line 1806 of yacc.c  */
-#line 368 "config_parser.yy"
-    {
-               m_Local = true;
-       }
-    break;
-
-  case 48:
-
-/* Line 1806 of yacc.c  */
-#line 374 "config_parser.yy"
+#line 362 "config_parser.yy"
     {
                (yyval.slist) = NULL;
        }
     break;
 
-  case 49:
+  case 48:
 
 /* Line 1806 of yacc.c  */
-#line 378 "config_parser.yy"
+#line 366 "config_parser.yy"
     {
                (yyval.slist) = new std::vector<String>();
                (yyval.slist)->push_back((yyvsp[(1) - (1)].text));
@@ -2017,10 +1994,10 @@ yyreduce:
        }
     break;
 
-  case 50:
+  case 49:
 
 /* Line 1806 of yacc.c  */
-#line 384 "config_parser.yy"
+#line 372 "config_parser.yy"
     {
                if ((yyvsp[(1) - (3)].slist))
                        (yyval.slist) = (yyvsp[(1) - (3)].slist);
@@ -2032,64 +2009,64 @@ yyreduce:
        }
     break;
 
-  case 51:
+  case 50:
 
 /* Line 1806 of yacc.c  */
-#line 396 "config_parser.yy"
+#line 384 "config_parser.yy"
     {
                (yyval.slist) = NULL;
        }
     break;
 
-  case 52:
+  case 51:
 
 /* Line 1806 of yacc.c  */
-#line 400 "config_parser.yy"
+#line 388 "config_parser.yy"
     {
                (yyval.slist) = (yyvsp[(2) - (2)].slist);
        }
     break;
 
-  case 53:
+  case 52:
 
 /* Line 1806 of yacc.c  */
-#line 406 "config_parser.yy"
+#line 394 "config_parser.yy"
     {
                (yyval.exprl) = (yyvsp[(2) - (3)].exprl);
        }
     break;
 
-  case 54:
+  case 53:
 
 /* Line 1806 of yacc.c  */
-#line 412 "config_parser.yy"
+#line 400 "config_parser.yy"
     {
                (yyval.exprl) = (yyvsp[(1) - (1)].exprl);
        }
     break;
 
-  case 55:
+  case 54:
 
 /* Line 1806 of yacc.c  */
-#line 416 "config_parser.yy"
+#line 404 "config_parser.yy"
     {
                (yyval.exprl) = (yyvsp[(1) - (2)].exprl);
        }
     break;
 
-  case 56:
+  case 55:
 
 /* Line 1806 of yacc.c  */
-#line 421 "config_parser.yy"
+#line 409 "config_parser.yy"
     {
                (yyval.exprl) = NULL;
        }
     break;
 
-  case 57:
+  case 56:
 
 /* Line 1806 of yacc.c  */
-#line 425 "config_parser.yy"
+#line 413 "config_parser.yy"
     {
                (yyval.exprl) = new ExpressionList();
                (yyval.exprl)->AddExpression(*(yyvsp[(1) - (1)].expr));
@@ -2097,10 +2074,10 @@ yyreduce:
        }
     break;
 
-  case 58:
+  case 57:
 
 /* Line 1806 of yacc.c  */
-#line 431 "config_parser.yy"
+#line 419 "config_parser.yy"
     {
                if ((yyvsp[(1) - (3)].exprl))
                        (yyval.exprl) = (yyvsp[(1) - (3)].exprl);
@@ -2112,10 +2089,10 @@ yyreduce:
        }
     break;
 
-  case 59:
+  case 58:
 
 /* Line 1806 of yacc.c  */
-#line 443 "config_parser.yy"
+#line 431 "config_parser.yy"
     {
                (yyval.expr) = new Expression((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc);
                free((yyvsp[(1) - (3)].text));
@@ -2123,10 +2100,10 @@ yyreduce:
        }
     break;
 
-  case 60:
+  case 59:
 
 /* Line 1806 of yacc.c  */
-#line 449 "config_parser.yy"
+#line 437 "config_parser.yy"
     {
                Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc);
                free((yyvsp[(3) - (6)].text));
@@ -2140,55 +2117,55 @@ yyreduce:
        }
     break;
 
-  case 65:
+  case 64:
 
 /* Line 1806 of yacc.c  */
-#line 467 "config_parser.yy"
+#line 455 "config_parser.yy"
     {
                (yyval.op) = (yyvsp[(1) - (1)].op);
        }
     break;
 
-  case 66:
+  case 65:
 
 /* Line 1806 of yacc.c  */
-#line 473 "config_parser.yy"
+#line 461 "config_parser.yy"
     {
                (yyval.array) = (yyvsp[(2) - (3)].array);
        }
     break;
 
-  case 67:
+  case 66:
 
 /* Line 1806 of yacc.c  */
-#line 479 "config_parser.yy"
+#line 467 "config_parser.yy"
     {
                (yyval.array) = (yyvsp[(1) - (1)].array);
        }
     break;
 
-  case 68:
+  case 67:
 
 /* Line 1806 of yacc.c  */
-#line 483 "config_parser.yy"
+#line 471 "config_parser.yy"
     {
                (yyval.array) = (yyvsp[(1) - (2)].array);
        }
     break;
 
-  case 69:
+  case 68:
 
 /* Line 1806 of yacc.c  */
-#line 488 "config_parser.yy"
+#line 476 "config_parser.yy"
     {
                (yyval.array) = NULL;
        }
     break;
 
-  case 70:
+  case 69:
 
 /* Line 1806 of yacc.c  */
-#line 492 "config_parser.yy"
+#line 480 "config_parser.yy"
     {
                (yyval.array) = new Array();
 
@@ -2205,10 +2182,10 @@ yyreduce:
        }
     break;
 
-  case 71:
+  case 70:
 
 /* Line 1806 of yacc.c  */
-#line 507 "config_parser.yy"
+#line 495 "config_parser.yy"
     {
                if ((yyvsp[(1) - (3)].array))
                        (yyval.array) = (yyvsp[(1) - (3)].array);
@@ -2228,38 +2205,38 @@ yyreduce:
        }
     break;
 
-  case 72:
+  case 71:
 
 /* Line 1806 of yacc.c  */
-#line 527 "config_parser.yy"
+#line 515 "config_parser.yy"
     {
                (yyval.variant) = new Value((yyvsp[(1) - (1)].text));
                free((yyvsp[(1) - (1)].text));
        }
     break;
 
-  case 73:
+  case 72:
 
 /* Line 1806 of yacc.c  */
-#line 532 "config_parser.yy"
+#line 520 "config_parser.yy"
     {
                (yyval.variant) = new Value((yyvsp[(1) - (1)].num));
        }
     break;
 
-  case 74:
+  case 73:
 
 /* Line 1806 of yacc.c  */
-#line 536 "config_parser.yy"
+#line 524 "config_parser.yy"
     {
                (yyval.variant) = new Value();
        }
     break;
 
-  case 75:
+  case 74:
 
 /* Line 1806 of yacc.c  */
-#line 540 "config_parser.yy"
+#line 528 "config_parser.yy"
     {
                if ((yyvsp[(1) - (1)].array) == NULL)
                        (yyvsp[(1) - (1)].array) = new Array();
@@ -2269,129 +2246,129 @@ yyreduce:
        }
     break;
 
-  case 76:
+  case 75:
 
 /* Line 1806 of yacc.c  */
-#line 550 "config_parser.yy"
+#line 538 "config_parser.yy"
     {
                (yyval.num) = (yyvsp[(2) - (3)].num);
        }
     break;
 
-  case 77:
+  case 76:
 
 /* Line 1806 of yacc.c  */
-#line 555 "config_parser.yy"
+#line 543 "config_parser.yy"
     {
                (yyval.num) = (yyvsp[(1) - (1)].num);
        }
     break;
 
-  case 78:
+  case 77:
 
 /* Line 1806 of yacc.c  */
-#line 559 "config_parser.yy"
+#line 547 "config_parser.yy"
     {
                (yyval.num) = ScriptVariable::Get((yyvsp[(1) - (1)].text));
                free((yyvsp[(1) - (1)].text));
        }
     break;
 
-  case 79:
+  case 78:
 
 /* Line 1806 of yacc.c  */
-#line 564 "config_parser.yy"
+#line 552 "config_parser.yy"
     {
                (yyval.num) = (yyvsp[(1) - (3)].num) + (yyvsp[(3) - (3)].num);
        }
     break;
 
-  case 80:
+  case 79:
 
 /* Line 1806 of yacc.c  */
-#line 568 "config_parser.yy"
+#line 556 "config_parser.yy"
     {
                (yyval.num) = (yyvsp[(1) - (3)].num) - (yyvsp[(3) - (3)].num);
        }
     break;
 
-  case 81:
+  case 80:
 
 /* Line 1806 of yacc.c  */
-#line 572 "config_parser.yy"
+#line 560 "config_parser.yy"
     {
                (yyval.num) = (yyvsp[(1) - (3)].num) * (yyvsp[(3) - (3)].num);
        }
     break;
 
-  case 82:
+  case 81:
 
 /* Line 1806 of yacc.c  */
-#line 576 "config_parser.yy"
+#line 564 "config_parser.yy"
     {
                (yyval.num) = (yyvsp[(1) - (3)].num) / (yyvsp[(3) - (3)].num);
        }
     break;
 
-  case 83:
+  case 82:
 
 /* Line 1806 of yacc.c  */
-#line 580 "config_parser.yy"
+#line 568 "config_parser.yy"
     {
                (yyval.num) = (long)(yyvsp[(1) - (3)].num) & (long)(yyvsp[(3) - (3)].num);
        }
     break;
 
-  case 84:
+  case 83:
 
 /* Line 1806 of yacc.c  */
-#line 584 "config_parser.yy"
+#line 572 "config_parser.yy"
     {
                (yyval.num) = (long)(yyvsp[(1) - (3)].num) | (long)(yyvsp[(3) - (3)].num);
        }
     break;
 
-  case 85:
+  case 84:
 
 /* Line 1806 of yacc.c  */
-#line 588 "config_parser.yy"
+#line 576 "config_parser.yy"
     {
                (yyval.num) = (long)(yyvsp[(1) - (3)].num) << (long)(yyvsp[(3) - (3)].num);
        }
     break;
 
-  case 86:
+  case 85:
 
 /* Line 1806 of yacc.c  */
-#line 592 "config_parser.yy"
+#line 580 "config_parser.yy"
     {
                (yyval.num) = (long)(yyvsp[(1) - (3)].num) >> (long)(yyvsp[(3) - (3)].num);
        }
     break;
 
-  case 87:
+  case 86:
 
 /* Line 1806 of yacc.c  */
-#line 596 "config_parser.yy"
+#line 584 "config_parser.yy"
     {
                (yyval.num) = (yyvsp[(2) - (3)].num);
        }
     break;
 
-  case 89:
+  case 88:
 
 /* Line 1806 of yacc.c  */
-#line 603 "config_parser.yy"
+#line 591 "config_parser.yy"
     {
                ExpressionList::Ptr exprl = ExpressionList::Ptr((yyvsp[(1) - (1)].exprl));
                (yyval.variant) = new Value(exprl);
        }
     break;
 
-  case 90:
+  case 89:
 
 /* Line 1806 of yacc.c  */
-#line 608 "config_parser.yy"
+#line 596 "config_parser.yy"
     {
                (yyval.variant) = new Value((yyvsp[(1) - (1)].num));
        }
@@ -2400,7 +2377,7 @@ yyreduce:
 
 
 /* Line 1806 of yacc.c  */
-#line 2404 "../../../lib/config/config_parser.cc"
+#line 2381 "../../../lib/config/config_parser.cc"
       default: break;
     }
   /* User semantic actions sometimes alter yychar, and that requires
@@ -2638,6 +2615,6 @@ yyreturn:
 
 
 /* Line 2067 of yacc.c  */
-#line 612 "config_parser.yy"
+#line 600 "config_parser.yy"
 
 
index f514b3523b93c2af036ca62959c98126df6eef8f..3988a16f4dffc8b1b71e532912a714ebc6d2bb41 100644 (file)
@@ -113,13 +113,12 @@ using namespace icinga;
      T_ATTRIBUTE = 280,
      T_TYPE = 281,
      T_ABSTRACT = 282,
-     T_LOCAL = 283,
-     T_OBJECT = 284,
-     T_TEMPLATE = 285,
-     T_INCLUDE = 286,
-     T_LIBRARY = 287,
-     T_INHERITS = 288,
-     T_PARTIAL = 289
+     T_OBJECT = 283,
+     T_TEMPLATE = 284,
+     T_INCLUDE = 285,
+     T_LIBRARY = 286,
+     T_INHERITS = 287,
+     T_PARTIAL = 288
    };
 #endif
 /* Tokens.  */
@@ -148,13 +147,12 @@ using namespace icinga;
 #define T_ATTRIBUTE 280
 #define T_TYPE 281
 #define T_ABSTRACT 282
-#define T_LOCAL 283
-#define T_OBJECT 284
-#define T_TEMPLATE 285
-#define T_INCLUDE 286
-#define T_LIBRARY 287
-#define T_INHERITS 288
-#define T_PARTIAL 289
+#define T_OBJECT 283
+#define T_TEMPLATE 284
+#define T_INCLUDE 285
+#define T_LIBRARY 286
+#define T_INHERITS 287
+#define T_PARTIAL 288
 
 
 
@@ -179,7 +177,7 @@ typedef union YYSTYPE
 
 
 /* Line 2068 of yacc.c  */
-#line 183 "../../../lib/config/config_parser.h"
+#line 181 "../../../lib/config/config_parser.h"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
index 8c8d6d1b566b6e5d1aa231baffa62673a50fb7c9..0f39a9c7afa888a026083d449bc04ab8359d09b4 100644 (file)
@@ -88,7 +88,6 @@ using namespace icinga;
 %token T_ATTRIBUTE "%attribute (T_ATTRIBUTE)"
 %token T_TYPE "type (T_TYPE)"
 %token T_ABSTRACT "abstract (T_ABSTRACT)"
-%token T_LOCAL "local (T_LOCAL)"
 %token T_OBJECT "object (T_OBJECT)"
 %token T_TEMPLATE "template (T_TEMPLATE)"
 %token T_INCLUDE "include (T_INCLUDE)"
@@ -125,26 +124,23 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err)
 {
        std::ostringstream message;
        message << *locp << ": " << err;
-       ConfigCompilerContext::GetContext()->AddError(false, message.str());
+       ConfigCompilerContext::GetInstance()->AddError(false, message.str());
 }
 
 int yyparse(ConfigCompiler *context);
 
 static std::stack<Array::Ptr> m_Arrays;
 static bool m_Abstract;
-static bool m_Local;
 
 static std::stack<TypeRuleList::Ptr> m_RuleLists;
 static ConfigType::Ptr m_Type;
 
 void ConfigCompiler::Compile(void)
 {
-       ASSERT(ConfigCompilerContext::GetContext() != NULL);
-
        try {
                yyparse(this);
        } catch (const std::exception& ex) {
-               ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex));
+               ConfigCompilerContext::GetInstance()->AddError(false, boost::diagnostic_information(ex));
        }
 }
 
@@ -196,14 +192,14 @@ type: partial_specifier T_TYPE identifier
                String name = String($3);
                free($3);
 
-               m_Type = ConfigCompilerContext::GetContext()->GetType(name);
+               m_Type = ConfigType::GetByName(name);
 
                if (!m_Type) {
                        if ($1)
                                BOOST_THROW_EXCEPTION(std::invalid_argument("Partial type definition for unknown type '" + name + "'"));
 
                        m_Type = boost::make_shared<ConfigType>(name, yylloc);
-                       ConfigCompilerContext::GetContext()->AddType(m_Type);
+                       m_Type->Register();
                }
        }
        type_inherits_specifier typerulelist
@@ -307,7 +303,6 @@ type: T_TYPE_DICTIONARY
 object:
        {
                m_Abstract = false;
-               m_Local = false;
        }
 object_declaration identifier T_STRING object_inherits_specifier expressionlist
        {
@@ -327,8 +322,6 @@ object_declaration identifier T_STRING object_inherits_specifier expressionlist
                item->SetName($4);
                free($4);
 
-               item->SetUnit(ConfigCompilerContext::GetContext()->GetUnit());
-
                if ($5) {
                        BOOST_FOREACH(const String& parent, *$5) {
                                item->AddParent(parent);
@@ -342,10 +335,9 @@ object_declaration identifier T_STRING object_inherits_specifier expressionlist
                        item->AddExpressionList(exprl);
                }
 
-               item->SetLocal(m_Local);
                item->SetAbstract(m_Abstract);
 
-               ConfigCompilerContext::GetContext()->AddItem(item->Compile());
+               item->Compile()->Register();
                item.reset();
        }
        ;
@@ -364,10 +356,6 @@ attribute: T_ABSTRACT
        {
                m_Abstract = true;
        }
-       | T_LOCAL
-       {
-               m_Local = true;
-       }
        ;
 
 object_inherits_list:
index 36f1eb9a8fe400fe3e0ce088045af13643298ceb..953ab2af5a7df94c3c26df7e48e3aa8e564c6878 100644 (file)
 #include "config/configcompilercontext.h"
 #include "base/utility.h"
 #include "base/logger_fwd.h"
+#include "base/singleton.h"
 #include <boost/foreach.hpp>
 
-using std::ifstream;
-
 using namespace icinga;
 
-ConfigCompilerContext *ConfigCompilerContext::m_Context = NULL;
-
-ConfigCompilerContext::ConfigCompilerContext(void)
-       : m_Unit(Utility::NewUniqueID()), m_Flags(0)
-{ }
-
-void ConfigCompilerContext::AddItem(const ConfigItem::Ptr& item)
-{
-       Log(LogDebug, "config", "Adding item to compiler context: type=" +
-           item->GetType() + "; name=" + item->GetName());
-
-       m_Items.push_back(item);
-       m_ItemsMap[std::make_pair(item->GetType(), item->GetName())] = item;
-}
-
-ConfigItem::Ptr ConfigCompilerContext::GetItem(const String& type, const String& name) const
-{
-       std::map<std::pair<String, String>, ConfigItem::Ptr, pair_string_iless>::const_iterator it;
-
-       it = m_ItemsMap.find(std::make_pair(type, name));
-
-       if (it == m_ItemsMap.end())
-               return ConfigItem::Ptr();
-
-       return it->second;
-}
-
-std::vector<ConfigItem::Ptr> ConfigCompilerContext::GetItems(void) const
-{
-       return m_Items;
-}
-
-void ConfigCompilerContext::AddType(const ConfigType::Ptr& type)
-{
-       m_Types[type->GetName()] = type;
-}
-
-ConfigType::Ptr ConfigCompilerContext::GetType(const String& name) const
-{
-       std::map<String, ConfigType::Ptr, string_iless>::const_iterator it;
-
-       it = m_Types.find(name);
-
-       if (it == m_Types.end())
-               return ConfigType::Ptr();
-
-       return it->second;
-}
-
 void ConfigCompilerContext::AddError(bool warning, const String& message)
 {
        m_Errors.push_back(ConfigCompilerError(warning, message));
@@ -85,81 +35,12 @@ std::vector<ConfigCompilerError> ConfigCompilerContext::GetErrors(void) const
        return m_Errors;
 }
 
-void ConfigCompilerContext::SetFlags(int flags)
+void ConfigCompilerContext::Reset(void)
 {
-       m_Flags = flags;
+       m_Errors.clear();
 }
 
-int ConfigCompilerContext::GetFlags(void) const
+ConfigCompilerContext *ConfigCompilerContext::GetInstance(void)
 {
-       return m_Flags;
-}
-
-void ConfigCompilerContext::SetContext(ConfigCompilerContext *context)
-{
-       ASSERT(m_Context == NULL || context == NULL);
-
-       m_Context = context;
-}
-
-ConfigCompilerContext *ConfigCompilerContext::GetContext(void)
-{
-       return m_Context;
-}
-
-String ConfigCompilerContext::GetUnit(void) const
-{
-       return m_Unit;
-}
-
-void ConfigCompilerContext::LinkItems(void)
-{
-       SetContext(this);
-
-       Log(LogInformation, "config", "Linking config items...");
-
-       BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
-               item->Link();
-       }
-
-       SetContext(NULL);
-}
-
-void ConfigCompilerContext::ValidateItems(void)
-{
-       SetContext(this);
-
-       Log(LogInformation, "config", "Validating config items...");
-
-       BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
-               ConfigType::Ptr ctype;
-
-               {
-                       ctype = GetType(item->GetType());
-
-                       if (!ctype) {
-                               AddError(true, "No validation type found for object '" + item->GetName() + "' of type '" + item->GetType() + "'");
-
-                               continue;
-                       }
-               }
-
-               ctype->ValidateItem(item);
-       }
-
-       SetContext(NULL);
-}
-
-void ConfigCompilerContext::ActivateItems(void)
-{
-       ASSERT(m_Context == NULL);
-
-       Log(LogInformation, "config", "Activating config items in compilation unit '" + m_Unit + "'");
-       BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
-               item->Register();
-       }
-
-       BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
-               item->Commit();
-       }
-}
+       return Singleton<ConfigCompilerContext>::GetInstance();
+}
\ No newline at end of file
index 8852bcf943dbf4a353f0b4599bce690719d56506..8c9adecfa235fb533984ef9e6faf3b4b9d7a879f 100644 (file)
 namespace icinga
 {
 
-/**
- * @ingroup config
- */
-enum ConfigCompilerFlag
-{
-        CompilerStrict = 1, /**< Treat warnings as errors. */
-        CompilerLinkExisting = 2 /**< Link objects to existing config items. */
-};
-
 struct I2_CONFIG_API ConfigCompilerError
 {
        bool Warning;
@@ -52,43 +43,15 @@ struct I2_CONFIG_API ConfigCompilerError
 class I2_CONFIG_API ConfigCompilerContext
 {
 public:
-       ConfigCompilerContext(void);
-
-       void AddItem(const ConfigItem::Ptr& item);
-       ConfigItem::Ptr GetItem(const String& type, const String& name) const;
-       std::vector<ConfigItem::Ptr> GetItems(void) const;
-
-       void AddType(const ConfigType::Ptr& type);
-       ConfigType::Ptr GetType(const String& name) const;
-
        void AddError(bool warning, const String& message);
        std::vector<ConfigCompilerError> GetErrors(void) const;
 
-       void SetFlags(int flags);
-       int GetFlags(void) const;
+       void Reset(void);
 
-       String GetUnit(void) const;
-
-       void LinkItems(void);
-       void ValidateItems(void);
-       void ActivateItems(void);
-
-       static void SetContext(ConfigCompilerContext *context);
-       static ConfigCompilerContext *GetContext(void);
+       static ConfigCompilerContext *GetInstance(void);
 
 private:
-       String m_Unit;
-
-        int m_Flags;
-
-       std::vector<ConfigItem::Ptr> m_Items;
-        std::map<std::pair<String, String>, ConfigItem::Ptr, pair_string_iless> m_ItemsMap;
-
-        std::map<String, shared_ptr<ConfigType>, string_iless> m_Types;
-
         std::vector<ConfigCompilerError> m_Errors;
-
-       static ConfigCompilerContext *m_Context;
 };
 
 }
index ed8564cd6aed15b03ae729ea44579e7bce573a77..7ea26928d9f5eceb65a5546109bf772114320f87 100644 (file)
@@ -32,8 +32,6 @@ using namespace icinga;
 
 boost::mutex ConfigItem::m_Mutex;
 ConfigItem::ItemMap ConfigItem::m_Items;
-boost::signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnCommitted;
-boost::signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnRemoved;
 
 /**
  * Constructor for the ConfigItem class.
@@ -47,9 +45,9 @@ boost::signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnRemoved;
  * @param debuginfo Debug information.
  */
 ConfigItem::ConfigItem(const String& type, const String& name,
-    const String& unit, bool abstract, const ExpressionList::Ptr& exprl,
+    bool abstract, const ExpressionList::Ptr& exprl,
     const std::vector<String>& parents, const DebugInfo& debuginfo)
-       : m_Type(type), m_Name(name), m_Unit(unit), m_Abstract(abstract),
+       : m_Type(type), m_Name(name), m_Abstract(abstract),
          m_ExpressionList(exprl), m_ParentNames(parents), m_DebugInfo(debuginfo)
 {
 }
@@ -74,16 +72,6 @@ String ConfigItem::GetName(void) const
        return m_Name;
 }
 
-/**
- * Retrieves the name of the compilation unit this item belongs to.
- *
- * @returns The unit name.
- */
-String ConfigItem::GetUnit(void) const
-{
-       return m_Unit;
-}
-
 /**
  * Checks whether the item is abstract.
  *
@@ -114,36 +102,14 @@ ExpressionList::Ptr ConfigItem::GetExpressionList(void) const
        return m_ExpressionList;
 }
 
-/**
- * Retrieves the list of parents for the configuration item.
- *
- * @returns The list of parents.
- */
-std::vector<ConfigItem::Ptr> ConfigItem::GetParents(void) const
-{
-       return m_Parents;
-}
-
 void ConfigItem::Link(void)
 {
        ObjectLock olock(this);
 
        m_LinkedExpressionList = boost::make_shared<ExpressionList>();
 
-       m_Parents.clear();
-
        BOOST_FOREACH(const String& name, m_ParentNames) {
-               ConfigItem::Ptr parent;
-
-               ConfigCompilerContext *context = ConfigCompilerContext::GetContext();
-
-               if (context)
-                       parent = context->GetItem(m_Type, name);
-
-               /* ignore already active objects while we're in the compiler
-                * context and linking to existing items is disabled. */
-               if (!parent && (!context || (context->GetFlags() & CompilerLinkExisting)))
-                       parent = ConfigItem::GetObject(m_Type, name);
+               ConfigItem::Ptr parent = ConfigItem::GetObject(m_Type, name);
 
                if (!parent) {
                        std::ostringstream message;
@@ -156,8 +122,6 @@ void ConfigItem::Link(void)
 
                ExpressionList::Ptr pexprl = parent->GetLinkedExpressionList();
                m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, pexprl, m_DebugInfo));
-
-               m_Parents.push_back(parent);
        }
 
        m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, m_ExpressionList, m_DebugInfo));
@@ -190,61 +154,16 @@ DynamicObject::Ptr ConfigItem::Commit(void)
        if (!dtype)
                BOOST_THROW_EXCEPTION(std::runtime_error("Type '" + GetType() + "' does not exist."));
 
-       /* Try to find an existing item with the same type and name. */
-       std::pair<String, String> ikey = std::make_pair(GetType(), GetName());
-       ConfigItem::Ptr oldItem;
+       if (m_DynamicObject.lock() || dtype->GetObject(m_Name))
+           BOOST_THROW_EXCEPTION(std::runtime_error("An object with type '" + GetType() + "' and name '" + GetName() + "' already exists."));
 
-       {
-               boost::mutex::scoped_lock lock(m_Mutex);
-
-               ItemMap::iterator it = m_Items.find(ikey);
-
-               if (it != m_Items.end())
-                       oldItem = it->second;
-       }
-
-       std::set<ConfigItem::WeakPtr> children;
-
-       if (oldItem) {
-               ObjectLock olock(oldItem);
-
-               /* Unregister the old item from its parents. */
-               oldItem->UnregisterFromParents();
-
-               /* Steal the old item's children. */
-               children = oldItem->m_ChildObjects;
-       }
-
-       {
-               ObjectLock olock(this);
-               m_ChildObjects = children;
-       }
-
-       ConfigItem::Ptr self = GetSelf();
-
-       {
-               boost::mutex::scoped_lock lock(m_Mutex);
-
-               /* Register this item. */
-               m_Items[ikey] = self;
-       }
-
-       DynamicObject::Ptr dobj = m_DynamicObject.lock();
-
-       if (!dobj)
-               dobj = dtype->GetObject(m_Name);
-
-       /* Register this item with its parents. */
-       BOOST_FOREACH(const ConfigItem::Ptr& parent, m_Parents) {
-               parent->m_ChildObjects.insert(self);
-       }
+       if (IsAbstract())
+               return DynamicObject::Ptr();
 
        /* Create a fake update in the format that
-        * DynamicObject::ApplyUpdate expects. */
+        * DynamicObject::Deserialize expects. */
        Dictionary::Ptr attrs = boost::make_shared<Dictionary>();
 
-       double tx = DynamicObject::GetCurrentTx();
-
        Link();
 
        Dictionary::Ptr properties = boost::make_shared<Dictionary>();
@@ -256,60 +175,14 @@ DynamicObject::Ptr ConfigItem::Commit(void)
                String key;
                Value data;
                BOOST_FOREACH(boost::tie(key, data), properties) {
-                       Dictionary::Ptr attr = boost::make_shared<Dictionary>();
-                       attr->Set("data", data);
-                       attr->Set("type", Attribute_Config);
-                       attr->Set("tx", tx);
-                       attr->Seal();
-
-                       attrs->Set(key, attr);
+                       attrs->Set(key, data);
                }
        }
 
        attrs->Seal();
 
-       Dictionary::Ptr update = boost::make_shared<Dictionary>();
-       update->Set("attrs", attrs);
-       update->Set("configTx", DynamicObject::GetCurrentTx());
-       update->Seal();
-
-       /* Update or create the object and apply the configuration settings. */
-       bool was_null = false;
-
-       if (!dobj) {
-               if (!IsAbstract())
-                       dobj = dtype->CreateObject(update);
-
-               was_null = true;
-       }
-
-       if (!was_null)
-               dobj->ApplyUpdate(update, Attribute_Config);
-
-       {
-               ObjectLock olock(this);
-
-               m_DynamicObject = dobj;
-       }
-
-       if (dobj) {
-               if (IsAbstract())
-                       dobj->Unregister();
-               else
-                       dobj->Register();
-       }
-
-       /* notify our children of the update */
-       BOOST_FOREACH(const ConfigItem::WeakPtr wchild, children) {
-               const ConfigItem::Ptr& child = wchild.lock();
-
-               if (!child)
-                       continue;
-
-               child->OnParentCommitted();
-       }
-
-       OnCommitted(self);
+       DynamicObject::Ptr dobj = dtype->CreateObject(attrs);
+       dobj->Register();
 
        return dobj;
 }
@@ -328,57 +201,6 @@ void ConfigItem::Register(void)
        }
 }
 
-/**
- * Unregisters the configuration item.
- */
-void ConfigItem::Unregister(void)
-{
-       ASSERT(!OwnsLock());
-
-       DynamicObject::Ptr dobj = m_DynamicObject.lock();
-
-       if (dobj)
-               dobj->Unregister();
-
-       {
-               ObjectLock olock(this);
-
-               ConfigItem::ItemMap::iterator it;
-               it = m_Items.find(std::make_pair(m_Type, m_Name));
-
-               if (it != m_Items.end())
-                       m_Items.erase(it);
-
-               UnregisterFromParents();
-       }
-
-       OnRemoved(GetSelf());
-}
-
-void ConfigItem::UnregisterFromParents(void)
-{
-       ASSERT(OwnsLock());
-
-       BOOST_FOREACH(const ConfigItem::Ptr& parent, m_Parents) {
-               parent->m_ChildObjects.erase(GetSelf());
-       }
-}
-
-/*
- * Notifies an item that one of its parents has been committed.
- */
-void ConfigItem::OnParentCommitted(void)
-{
-       ASSERT(!OwnsLock());
-
-       ConfigItem::Ptr self = GetSelf();
-
-       if (GetObject(m_Type, m_Name) != self)
-               return;
-
-       Commit();
-}
-
 /**
  * Retrieves the DynamicObject that belongs to the configuration item.
  *
@@ -412,58 +234,57 @@ ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name)
        return ConfigItem::Ptr();
 }
 
-/**
- * Dumps the config item to the specified stream using Icinga's config item
- * syntax.
- *
- * @param fp The stream.
- */
-void ConfigItem::Dump(std::ostream& fp) const
+void ConfigItem::LinkItems(void)
 {
-       ObjectLock olock(this);
+       Log(LogInformation, "config", "Linking config items...");
 
-       fp << "object \"" << m_Type << "\" \"" << m_Name << "\"";
+       ConfigItem::Ptr item;
+       BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
+               item->Link();
+       }
+}
+
+void ConfigItem::ValidateItems(void)
+{
+       Log(LogInformation, "config", "Validating config items...");
 
-       if (m_Parents.size() > 0) {
-               fp << " inherits";
+       ConfigItem::Ptr item;
+       BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
+               ConfigType::Ptr ctype = ConfigType::GetByName(item->GetType());
 
-               bool first = true;
-               BOOST_FOREACH(const String& name, m_ParentNames) {
-                       if (!first)
-                               fp << ",";
-                       else
-                               first = false;
+               if (!ctype) {
+                       ConfigCompilerContext::GetInstance()->AddError(true, "No validation type found for object '" + item->GetName() + "' of type '" + item->GetType() + "'");
 
-                       fp << " \"" << name << "\"";
+                       continue;
                }
-       }
 
-       fp << " {" << "\n";
-       m_ExpressionList->Dump(fp, 1);
-       fp << "}" << "\n";
+               ctype->ValidateItem(item);
+       }
 }
 
-void ConfigItem::UnloadUnit(const String& unit)
+void ConfigItem::ActivateItems(void)
 {
-       std::vector<ConfigItem::Ptr> obsoleteItems;
+       Log(LogInformation, "config", "Activating config items");
 
-       {
-               boost::mutex::scoped_lock lock(m_Mutex);
+       std::vector<DynamicObject::Ptr> objects;
 
-               Log(LogInformation, "config", "Unloading config items from compilation unit '" + unit + "'");
+       ConfigItem::Ptr item;
+       BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
+               DynamicObject::Ptr object = item->Commit();
 
-               ConfigItem::Ptr item;
-               BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
-                       ObjectLock olock(item);
+               if (object)
+                       objects.push_back(object);
+       }
 
-                       if (item->m_Unit != unit)
-                               continue;
+       BOOST_FOREACH(const DynamicObject::Ptr& object, objects) {
+               Log(LogDebug, "config", "Activating object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "'");
+               object->Start();
 
-                       obsoleteItems.push_back(item);
-               }
+               ASSERT(object->IsActive());
        }
+}
 
-       BOOST_FOREACH(const ConfigItem::Ptr& item, obsoleteItems) {
-               item->Unregister();
-       }
+void ConfigItem::DiscardItems(void)
+{
+       m_Items.clear();
 }
index 175544c8bd4e8f41fdc640dcc1670ecb3a34a5f0..e85cb91a6e141d3c8b05993e0d5737d3fd059e1f 100644 (file)
@@ -37,13 +37,12 @@ class I2_CONFIG_API ConfigItem : public Object {
 public:
        DECLARE_PTR_TYPEDEFS(ConfigItem);
 
-       ConfigItem(const String& type, const String& name, const String& unit,
-           bool abstract, const ExpressionList::Ptr& exprl, const std::vector<String>& parents,
+       ConfigItem(const String& type, const String& name, bool abstract,
+           const ExpressionList::Ptr& exprl, const std::vector<String>& parents,
            const DebugInfo& debuginfo);
 
        String GetType(void) const;
        String GetName(void) const;
-       String GetUnit(void) const;
        bool IsAbstract(void) const;
 
        std::vector<ConfigItem::Ptr> GetParents(void) const;
@@ -55,9 +54,6 @@ public:
 
        DynamicObject::Ptr Commit(void);
        void Register(void);
-       void Unregister(void);
-
-       void Dump(std::ostream& fp) const;
 
        DynamicObject::Ptr GetDynamicObject(void) const;
 
@@ -66,35 +62,27 @@ public:
        static ConfigItem::Ptr GetObject(const String& type,
            const String& name);
 
-       static void UnloadUnit(const String& unit);
-
-       static boost::signals2::signal<void (const ConfigItem::Ptr&)> OnCommitted;
-       static boost::signals2::signal<void (const ConfigItem::Ptr&)> OnRemoved;
+       static void LinkItems(void);
+       static void ValidateItems(void);
+       static void ActivateItems(void);
+       static void DiscardItems(void);
 
 private:
        ExpressionList::Ptr GetExpressionList(void) const;
 
-       void UnregisterFromParents(void);
-
-       void OnParentCommitted(void);
-
        String m_Type; /**< The object type. */
        String m_Name; /**< The name. */
-       String m_Unit; /**< The compilation unit. */
        bool m_Abstract; /**< Whether this is a template. */
 
        ExpressionList::Ptr m_ExpressionList;
        std::vector<String> m_ParentNames; /**< The names of parent configuration
                                       items. */
-       std::vector<ConfigItem::Ptr> m_Parents;
        DebugInfo m_DebugInfo; /**< Debug information. */
 
        ExpressionList::Ptr m_LinkedExpressionList;
 
        DynamicObject::WeakPtr m_DynamicObject; /**< The instantiated version
                                                  * of this configuration item */
-       std::set<ConfigItem::WeakPtr> m_ChildObjects; /**< Instantiated items
-                                                     * that inherit from this item */
 
        static boost::mutex m_Mutex;
 
index cbe1b6014557a7fb2f949d164242c455fac4ac75..e970bafe148ee508f4064d1bb6aa1d69cdea52ac 100644 (file)
@@ -27,8 +27,7 @@
 using namespace icinga;
 
 ConfigItemBuilder::ConfigItemBuilder(void)
-       : m_Local(false), m_Abstract(false),
-         m_ExpressionList(boost::make_shared<ExpressionList>())
+       : m_Abstract(false), m_ExpressionList(boost::make_shared<ExpressionList>())
 {
        m_DebugInfo.FirstLine = 0;
        m_DebugInfo.FirstColumn = 0;
@@ -37,8 +36,7 @@ ConfigItemBuilder::ConfigItemBuilder(void)
 }
 
 ConfigItemBuilder::ConfigItemBuilder(const DebugInfo& debugInfo)
-       : m_Local(false), m_Abstract(false),
-         m_ExpressionList(boost::make_shared<ExpressionList>())
+       : m_Abstract(false), m_ExpressionList(boost::make_shared<ExpressionList>())
 {
        m_DebugInfo = debugInfo;
 }
@@ -53,16 +51,6 @@ void ConfigItemBuilder::SetName(const String& name)
        m_Name = name;
 }
 
-void ConfigItemBuilder::SetUnit(const String& unit)
-{
-       m_Unit = unit;
-}
-
-void ConfigItemBuilder::SetLocal(bool local)
-{
-       m_Local = local;
-}
-
 void ConfigItemBuilder::SetAbstract(bool abstract)
 {
        m_Abstract = abstract;
@@ -126,9 +114,6 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void)
        Expression nameExpr("__name", OperatorSet, m_Name, m_DebugInfo);
        exprl->AddExpression(nameExpr);
 
-       Expression localExpr("__local", OperatorSet, m_Local, m_DebugInfo);
-       exprl->AddExpression(localExpr);
-
-       return boost::make_shared<ConfigItem>(m_Type, m_Name, m_Unit, m_Abstract, exprl, m_Parents,
-           m_DebugInfo);
+       return boost::make_shared<ConfigItem>(m_Type, m_Name, m_Abstract, exprl,
+           m_Parents, m_DebugInfo);
 }
index 27ba051306db21d50227002aec4d7daf66d0558b..55e777971c1aefd79f60779ee7f2e246f027c3f0 100644 (file)
@@ -45,8 +45,6 @@ public:
 
        void SetType(const String& type);
        void SetName(const String& name);
-       void SetUnit(const String& unit);
-       void SetLocal(bool local);
        void SetAbstract(bool abstract);
 
        void AddParent(const String& parent);
@@ -61,8 +59,6 @@ public:
 private:
        String m_Type; /**< The object type. */
        String m_Name; /**< The name. */
-       String m_Unit; /**< The compilation unit. */
-       bool m_Local; /**< Whether the item is local. */
        bool m_Abstract; /**< Whether the item is abstract. */
        std::vector<String> m_Parents; /**< The names of parent configuration
                                       items. */
index ba2a350f92276da99b3a9a131bf2baab76c5cd3c..9c7f3966aef0e3622ad94355315704d02e468bf8 100644 (file)
@@ -62,9 +62,9 @@ void ConfigType::AddParentRules(std::vector<TypeRuleList::Ptr>& ruleLists, const
        ConfigType::Ptr parent;
        if (item->m_Parent.IsEmpty()) {
                if (item->GetName() != "DynamicObject")
-                       parent = ConfigCompilerContext::GetContext()->GetType("DynamicObject");
+                       parent = ConfigType::GetByName("DynamicObject");
        } else {
-               parent = ConfigCompilerContext::GetContext()->GetType(item->m_Parent);
+               parent = ConfigType::GetByName(item->m_Parent);
        }
 
        if (parent) {
@@ -121,7 +121,7 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary,
                        Value value = dictionary->Get(require);
 
                        if (value.IsEmpty()) {
-                               ConfigCompilerContext::GetContext()->AddError(false,
+                               ConfigCompilerContext::GetInstance()->AddError(false,
                                    "Required attribute is missing: " + LocationToString(locations));
                        }
 
@@ -175,14 +175,14 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary,
                }
 
                if (overallResult == ValidationUnknownField)
-                       ConfigCompilerContext::GetContext()->AddError(true, "Unknown attribute: " + LocationToString(locations));
+                       ConfigCompilerContext::GetInstance()->AddError(true, "Unknown attribute: " + LocationToString(locations));
                else if (overallResult == ValidationInvalidType) {
                        String message = "Invalid value for attribute: " + LocationToString(locations);
 
                        if (!hint.IsEmpty())
                                message += ": " + hint;
 
-                       ConfigCompilerContext::GetContext()->AddError(false, message);
+                       ConfigCompilerContext::GetInstance()->AddError(false, message);
                }
 
                if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
@@ -204,7 +204,7 @@ void ConfigType::ValidateArray(const Array::Ptr& array,
                        locations.push_back("Attribute '" + require + "'");
 
                        if (array->GetLength() < index) {
-                               ConfigCompilerContext::GetContext()->AddError(false,
+                               ConfigCompilerContext::GetInstance()->AddError(false,
                                    "Required array index is missing: " + LocationToString(locations));
                        }
 
@@ -261,14 +261,14 @@ void ConfigType::ValidateArray(const Array::Ptr& array,
                }
 
                if (overallResult == ValidationUnknownField)
-                       ConfigCompilerContext::GetContext()->AddError(true, "Unknown attribute: " + LocationToString(locations));
+                       ConfigCompilerContext::GetInstance()->AddError(true, "Unknown attribute: " + LocationToString(locations));
                else if (overallResult == ValidationInvalidType) {
                        String message = "Invalid value for array index: " + LocationToString(locations);
 
                        if (!hint.IsEmpty())
                                message += ": " + hint;
 
-                       ConfigCompilerContext::GetContext()->AddError(false, message);
+                       ConfigCompilerContext::GetInstance()->AddError(false, message);
                }
 
                if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
@@ -279,3 +279,23 @@ void ConfigType::ValidateArray(const Array::Ptr& array,
                locations.pop_back();
        }
 }
+
+void ConfigType::Register(void)
+{
+       Registry<ConfigType::Ptr>::GetInstance()->Register(GetName(), GetSelf());
+}
+
+ConfigType::Ptr ConfigType::GetByName(const String& name)
+{
+       return Registry<ConfigType::Ptr>::GetInstance()->GetItem(name);
+}
+
+Registry<ConfigType::Ptr>::ItemMap ConfigType::GetTypes(void)
+{
+       return Registry<ConfigType::Ptr>::GetInstance()->GetItems();
+}
+
+void ConfigType::DiscardTypes(void)
+{
+       Registry<ConfigType::Ptr>::GetInstance()->Clear();
+}
index 03dd9664cf7134db654b5ceb4ed8c3caf7f5ed8f..94e91c6477381db89e1928b10dd5487346c97f91 100644 (file)
@@ -25,6 +25,7 @@
 #include "config/typerulelist.h"\r
 #include "config/configitem.h"\r
 #include "base/array.h"\r
+#include "base/registry.h"\r
 \r
 namespace icinga\r
 {\r
@@ -51,6 +52,11 @@ public:
 \r
        void ValidateItem(const ConfigItem::Ptr& object);\r
 \r
+       void Register(void);\r
+       static ConfigType::Ptr GetByName(const String& name);\r
+       static Registry<ConfigType::Ptr>::ItemMap GetTypes(void);\r
+       static void DiscardTypes(void);\r
+\r
 private:\r
        String m_Name; /**< The type name. */\r
        String m_Parent; /**< The parent type. */\r
index 397bf2013f1f36a174a0c9bce45ef56efc36351d..e2939747401f1884c43f06d0870e140c3639dc77 100644 (file)
@@ -132,87 +132,6 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
        dictionary->Set(m_Key, newValue);
 }
 
-void Expression::DumpValue(std::ostream& fp, int indent, const Value& value, bool inlineDict)
-{
-       ExpressionList::Ptr valueExprl;
-       Dictionary::Ptr valueDict;
-       if (value.IsObjectType<ExpressionList>()) {
-               if (!inlineDict)
-                       fp << "{ " << "\n";
-
-               static_cast<ExpressionList::Ptr>(value)->Dump(fp, indent);
-
-               if (!inlineDict) {
-                       for (int i = 0; i < indent - 1; i++)
-                               fp << "\t";
-
-                       fp << "}";
-               }
-
-               return;
-       }
-
-       if (value.IsObjectType<Dictionary>()) {
-               if (!inlineDict)
-                       fp << "{ " << "\n";
-
-               String k;
-               Value v;
-               BOOST_FOREACH(boost::tie(k, v), static_cast<Dictionary::Ptr>(value)) {
-                       for (int i = 0; i < indent; i++)
-                               fp << "\t";
-
-                       fp << "\"" << k << "\" = ";
-                       DumpValue(fp, indent, v);
-                       fp << "," << "\n";
-
-                       fp << "}";
-               }
-
-               if (!inlineDict)
-                       fp << "}";
-
-               return;
-       }
-
-       if (value.IsScalar()) {
-               fp << "\"" << static_cast<String>(value) << "\"";
-               return;
-       }
-
-       BOOST_THROW_EXCEPTION(std::runtime_error("Encountered unknown type while dumping value."));
-}
-
-void Expression::Dump(std::ostream& fp, int indent) const
-{
-       if (m_Operator == OperatorExecute) {
-               DumpValue(fp, indent, m_Value, true);
-               return;
-       }
-
-       for (int i = 0; i < indent; i++)
-               fp << "\t";
-
-       fp << "\"" << m_Key << "\" ";
-
-       switch (m_Operator) {
-               case OperatorSet:
-                       fp << "=";
-                       break;
-               case OperatorPlus:
-                       fp << "+=";
-                       break;
-               default:
-                       BOOST_THROW_EXCEPTION(std::runtime_error("Not yet implemented."));
-       }
-
-       fp << " ";
-
-       DumpValue(fp, indent + 1, m_Value);
-
-       fp << ", " << "\n";
-}
-
 void Expression::ExtractPath(const std::vector<String>& path, const ExpressionList::Ptr& result) const
 {
        ASSERT(!path.empty());
index aad06e11e7982cdfcd1f699caf8dde6b697c24d6..b9cd012dcd0624bf298b4e32a7db747db3bd86a7 100644 (file)
@@ -59,7 +59,6 @@ public:
            const DebugInfo& debuginfo);
 
        void Execute(const Dictionary::Ptr& dictionary) const;
-       void Dump(std::ostream& fp, int indent = 0) const;
 
        void ExtractPath(const std::vector<String>& path, const shared_ptr<ExpressionList>& result) const;
        void ExtractFiltered(const std::set<String, string_iless>& keys, const shared_ptr<ExpressionList>& result) const;
@@ -69,8 +68,6 @@ private:
        ExpressionOperator m_Operator;
        Value m_Value;
        DebugInfo m_DebugInfo;
-
-       static void DumpValue(std::ostream& fp, int indent, const Value& value, bool inlineDict = false);
 };
 
 }
index c5f404fa524fe0f5964ba04850122ab31d2ba3c8..feebaaff7ee78c710b3d22cd8238ea7bd6a69f40 100644 (file)
@@ -55,19 +55,6 @@ void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const
        }
 }
 
-/**
- * Dumps the expression list to the specified stream.
- *
- * @param fp The stream.
- * @param indent The indentation level.
- */
-void ExpressionList::Dump(std::ostream& fp, int indent) const
-{
-       BOOST_FOREACH(const Expression& expression, m_Expressions) {
-               expression.Dump(fp, indent);
-       }
-}
-
 void ExpressionList::ExtractPath(const std::vector<String>& path, const ExpressionList::Ptr& result) const
 {
        BOOST_FOREACH(const Expression& expression, m_Expressions) {
index b809bd6ef3e6a570b8a4a4a1742a0131be466342..51e77aa4a2a6dc7d66e42ee8a80230c40a05d6d0 100644 (file)
@@ -41,7 +41,6 @@ public:
        void AddExpression(const Expression& expression);
 
        void Execute(const Dictionary::Ptr& dictionary) const;
-       void Dump(std::ostream& fp, int indent) const;
 
        size_t GetLength(void) const;
 
index 314734962ed843900ec918a0f91e460a2671fdbb..62d6ad443331817427e5a48e179cf6fcac1b003b 100644 (file)
@@ -45,7 +45,6 @@ bool TypeRule::MatchName(const String& name) const
 
 bool TypeRule::MatchValue(const Value& value, String *hint) const
 {
-       ConfigCompilerContext *context;
        ConfigItem::Ptr item;
 
        if (value.IsEmpty())
@@ -79,13 +78,7 @@ bool TypeRule::MatchValue(const Value& value, String *hint) const
                        if (!value.IsScalar())
                                return false;
 
-                       context = ConfigCompilerContext::GetContext();
-
-                       if (context)
-                               item = context->GetItem(m_NameType, value);
-
-                       if (!item && (!context || (context->GetFlags() & CompilerLinkExisting)))
-                               item = ConfigItem::GetObject(m_NameType, value);
+                       item = ConfigItem::GetObject(m_NameType, value);
 
                        if (!item) {
                                *hint = "Object '" + value + "' of type '" + m_NameType + "' does not exist.";
index 819afab23f3252b22766799322150974971e5e64..0472df905cb8d56578ee4f590ccf0d9308f528ff 100644 (file)
@@ -15,22 +15,16 @@ libicinga_la_SOURCES =  \
        api.h \
        checkcommand.cpp \
        checkcommand.h \
-       checkresultmessage.cpp \
-       checkresultmessage.h \
        cib.cpp \
        cib.h \
        command.cpp \
        command.h \
        compatutility.cpp \
        compatutility.h \
-       downtimemessage.cpp \
-       downtimemessage.h \
        eventcommand.cpp \
        eventcommand.h \
        externalcommandprocessor.cpp \
        externalcommandprocessor.h \
-       flappingmessage.cpp \
-       flappingmessage.h \
        host.cpp \
        hostgroup.cpp \
        hostgroup.h \
@@ -49,10 +43,6 @@ libicinga_la_SOURCES =  \
        notification.h \
        notificationcommand.cpp \
        notificationcommand.h \
-       notificationmessage.cpp \
-       notificationmessage.h \
-       notificationrequestmessage.cpp \
-       notificationrequestmessage.h \
        nullchecktask.cpp \
        nullchecktask.h \
        nulleventtask.cpp \
index f0c494639bd437a0aec070369be6aa36454358ca..030c0de28b5434c5b71529de7c4d9591799df937 100644 (file)
@@ -24,22 +24,6 @@ using namespace icinga;
 
 REGISTER_TYPE(CheckCommand);
 
-/**
- * Constructor for the CheckCommand class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-CheckCommand::CheckCommand(const Dictionary::Ptr& serializedUpdate)
-       : Command(serializedUpdate)
-{ }
-
-CheckCommand::Ptr CheckCommand::GetByName(const String& name)
-{
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("CheckCommand", name);
-
-       return dynamic_pointer_cast<CheckCommand>(configObject);
-}
-
 Dictionary::Ptr CheckCommand::Execute(const Service::Ptr& service)
 {
        std::vector<Value> arguments;
index f0abae68e3bb332e8ab4ffc4b45ce0ff544ff150..40e4b9244e24a5b49948949741bb34bf4c99dba5 100644 (file)
@@ -35,10 +35,7 @@ class I2_ICINGA_API CheckCommand : public Command
 {
 public:
        DECLARE_PTR_TYPEDEFS(CheckCommand);
-
-       explicit CheckCommand(const Dictionary::Ptr& serializedUpdate);
-
-       static CheckCommand::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(CheckCommand);
 
        virtual Dictionary::Ptr Execute(const Service::Ptr& service);
 };
diff --git a/lib/icinga/checkresultmessage.cpp b/lib/icinga/checkresultmessage.cpp
deleted file mode 100644 (file)
index f63105d..0000000
+++ /dev/null
@@ -1,46 +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 "icinga/checkresultmessage.h"
-
-using namespace icinga;
-
-String CheckResultMessage::GetService(void) const
-{
-       String service;
-       Get("service", &service);
-       return service;
-}
-
-void CheckResultMessage::SetService(const String& service)
-{
-       Set("service", service);
-}
-
-Dictionary::Ptr CheckResultMessage::GetCheckResult(void) const
-{
-       Dictionary::Ptr cr;
-       Get("check_result", &cr);
-       return cr;
-}
-
-void CheckResultMessage::SetCheckResult(const Dictionary::Ptr& result)
-{
-       Set("check_result", result);
-}
diff --git a/lib/icinga/checkresultmessage.h b/lib/icinga/checkresultmessage.h
deleted file mode 100644 (file)
index 314f3a6..0000000
+++ /dev/null
@@ -1,49 +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 CHECKRESULTMESSAGE_H
-#define CHECKRESULTMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * A state change message for a service.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API CheckResultMessage : public MessagePart
-{
-public:
-       CheckResultMessage(void) : MessagePart() { }
-       explicit CheckResultMessage(const MessagePart& message) : MessagePart(message) { }
-
-       String GetService(void) const;
-       void SetService(const String& service);
-
-       Dictionary::Ptr GetCheckResult(void) const;
-       void SetCheckResult(const Dictionary::Ptr& result);
-};
-
-}
-
-#endif /* CHECKRESULTMESSAGE_H */
index 12b615e99fc419890015d923458f712f7c899f12..298bfc5b5bad465de1741b6764aaabec7f41ba93 100644 (file)
 
 using namespace icinga;
 
-/**
- * Constructor for the Command class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-Command::Command(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
+Value Command::GetCommandLine(void) const
+{
+       return m_CommandLine;
+}
+
+double Command::GetTimeout(void) const
 {
-       RegisterAttribute("macros", Attribute_Config, &m_Macros);
-       RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
+       if (m_Timeout.IsEmpty())
+               return 300;
+       else
+               return m_Timeout;
 }
 
 Dictionary::Ptr Command::GetMacros(void) const
@@ -43,7 +44,7 @@ Array::Ptr Command::GetExportMacros(void) const
        return m_ExportMacros;
 }
 
-bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
 {
        Dictionary::Ptr macros = GetMacros();
 
@@ -55,7 +56,27 @@ bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, Strin
        return false;
 }
 
-Value Command::GetCommandLine(void) const
+void Command::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               bag->Set("command", m_CommandLine);
+               bag->Set("timeout", m_Timeout);
+               bag->Set("macros", m_Macros);
+               bag->Set("export_macros", m_ExportMacros);
+       }
+}
+
+void Command::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
 {
-       return Get("command");
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               m_CommandLine = bag->Get("command");
+               m_Timeout = bag->Get("timeout");
+               m_Macros = bag->Get("macros");
+               m_Macros = bag->Get("macros");
+               m_ExportMacros = bag->Get("export_macros");
+       }
 }
index 323e769647ff0f87db9863cfcf21ce86ebec915d..e4fedc260d63aa2457a8f7296264b1270b6bc1b4 100644 (file)
@@ -40,19 +40,24 @@ class I2_ICINGA_API Command : public DynamicObject, public MacroResolver
 public:
        DECLARE_PTR_TYPEDEFS(Command);
 
-       explicit Command(const Dictionary::Ptr& serializedUpdate);
-
        //virtual Dictionary::Ptr Execute(const Object::Ptr& context) = 0;
 
+       Value GetCommandLine(void) const;
+       double GetTimeout(void) const;
+
        Dictionary::Ptr GetMacros(void) const;
        Array::Ptr GetExportMacros(void) const;
        virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
 
-       Value GetCommandLine(void) const;
+protected:
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
 
 private:
-       Attribute<Dictionary::Ptr> m_Macros;
-       Attribute<Array::Ptr> m_ExportMacros;
+       Value m_CommandLine;
+       Value m_Timeout;
+       Dictionary::Ptr m_Macros;
+       Array::Ptr m_ExportMacros;
 };
 
 }
diff --git a/lib/icinga/downtimemessage.cpp b/lib/icinga/downtimemessage.cpp
deleted file mode 100644 (file)
index 1a5b496..0000000
+++ /dev/null
@@ -1,46 +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 "icinga/downtimemessage.h"
-
-using namespace icinga;
-
-String DowntimeMessage::GetService(void) const
-{
-       String service;
-       Get("service", &service);
-       return service;
-}
-
-void DowntimeMessage::SetService(const String& service)
-{
-       Set("service", service);
-}
-
-DowntimeState DowntimeMessage::GetState(void) const
-{
-       long state;
-       Get("state", &state);
-       return static_cast<DowntimeState>(state);
-}
-
-void DowntimeMessage::SetState(DowntimeState state)
-{
-       Set("state", state);
-}
diff --git a/lib/icinga/downtimemessage.h b/lib/icinga/downtimemessage.h
deleted file mode 100644 (file)
index 63ee375..0000000
+++ /dev/null
@@ -1,50 +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 DOWNTIMEMESSAGE_H
-#define DOWNTIMEMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "icinga/service.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * A downtime message for a service.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API DowntimeMessage : public MessagePart
-{
-public:
-       DowntimeMessage(void) : MessagePart() { }
-       explicit DowntimeMessage(const MessagePart& message) : MessagePart(message) { }
-
-       String GetService(void) const;
-       void SetService(const String& service);
-
-       DowntimeState GetState(void) const;
-       void SetState(DowntimeState state);
-};
-
-}
-
-#endif /* DOWNTIMEMESSAGE_H */
index a6d6540fab9b8e39f5154acccb4bbf6cc89bbd1c..e36c68402c3a23b0a8b8139b29167eabe897df27 100644 (file)
@@ -24,22 +24,6 @@ using namespace icinga;
 
 REGISTER_TYPE(EventCommand);
 
-/**
- * Constructor for the EventCommand class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-EventCommand::EventCommand(const Dictionary::Ptr& serializedUpdate)
-       : Command(serializedUpdate)
-{ }
-
-EventCommand::Ptr EventCommand::GetByName(const String& name)
-{
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("EventCommand", name);
-
-       return dynamic_pointer_cast<EventCommand>(configObject);
-}
-
 void EventCommand::Execute(const Service::Ptr& service)
 {
        std::vector<Value> arguments;
index eafdcdbdc2d024d1f74d73ce3b6e5bccd984ddc8..ce00bfd452728580ebf94c7a62478c2f98214db4 100644 (file)
@@ -35,10 +35,7 @@ class I2_ICINGA_API EventCommand : public Command
 {
 public:
        DECLARE_PTR_TYPEDEFS(EventCommand);
-
-       explicit EventCommand(const Dictionary::Ptr& serializedUpdate);
-
-       static EventCommand::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(EventCommand);
 
        virtual void Execute(const Service::Ptr& context);
 };
index 8e371af8a605be06e57c76005111c5a86533c1ef..ef8e8768cc432ded259075ddaae55531f523af8f 100644 (file)
 #include "icinga/hostgroup.h"
 #include "icinga/servicegroup.h"
 #include "icinga/pluginchecktask.h"
-#include "icinga/flappingmessage.h"
 #include "base/convert.h"
 #include "base/logger_fwd.h"
 #include "base/objectlock.h"
 #include "base/application.h"
 #include "base/utility.h"
-#include "remoting/endpointmanager.h"
 #include <fstream>
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/foreach.hpp>
@@ -1127,10 +1125,9 @@ void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vec
                if (options & 2) {
                        ObjectLock olock(service);
                        service->SetForceNextNotification(true);
-                       service->Flush();
                }
 
-               service->RequestNotifications(NotificationCustom, service->GetLastCheckResult(), arguments[2], arguments[3]);
+               Service::OnNotificationsRequested(service, NotificationCustom, service->GetLastCheckResult(), arguments[2], arguments[3]);
        }
 }
 
@@ -1147,10 +1144,9 @@ void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vect
        if (options & 2) {
                ObjectLock olock(service);
                service->SetForceNextNotification(true);
-               service->Flush();
        }
 
-       service->RequestNotifications(NotificationCustom, service->GetLastCheckResult(), arguments[3], arguments[4]);
+       Service::OnNotificationsRequested(service, NotificationCustom, service->GetLastCheckResult(), arguments[3], arguments[4]);
 }
 
 void ExternalCommandProcessor::DelayHostNotification(double, const std::vector<String>& arguments)
@@ -1517,16 +1513,5 @@ void ExternalCommandProcessor::DisableSvcFlapping(double, const std::vector<Stri
                ObjectLock olock(service);
 
                service->SetEnableFlapping(false);
-
-               RequestMessage rm;
-               rm.SetMethod("icinga::Flapping");
-
-               FlappingMessage params;
-               params.SetService(service->GetName());
-               params.SetState(FlappingDisabled);
-
-               rm.SetParams(params);
-
-               EndpointManager::GetInstance()->SendMulticastMessage(rm);
        }
 }
diff --git a/lib/icinga/flappingmessage.cpp b/lib/icinga/flappingmessage.cpp
deleted file mode 100644 (file)
index 2b4bc43..0000000
+++ /dev/null
@@ -1,46 +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 "icinga/flappingmessage.h"
-
-using namespace icinga;
-
-String FlappingMessage::GetService(void) const
-{
-       String service;
-       Get("service", &service);
-       return service;
-}
-
-void FlappingMessage::SetService(const String& service)
-{
-       Set("service", service);
-}
-
-FlappingState FlappingMessage::GetState(void) const
-{
-       long state;
-       Get("state", &state);
-       return static_cast<FlappingState>(state);
-}
-
-void FlappingMessage::SetState(FlappingState state)
-{
-       Set("state", state);
-}
diff --git a/lib/icinga/flappingmessage.h b/lib/icinga/flappingmessage.h
deleted file mode 100644 (file)
index 59a586b..0000000
+++ /dev/null
@@ -1,50 +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 FLAPPINGMESSAGE_H
-#define FLAPPINGMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "icinga/service.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * A downtime message for a service.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API FlappingMessage : public MessagePart
-{
-public:
-       FlappingMessage(void) : MessagePart() { }
-       explicit FlappingMessage(const MessagePart& message) : MessagePart(message) { }
-
-       String GetService(void) const;
-       void SetService(const String& service);
-
-       FlappingState GetState(void) const;
-       void SetState(FlappingState state);
-};
-
-}
-
-#endif /* FLAPPINGMESSAGE_H */
index 4ef46cfab6ef465787b5d68bba90abf60983f09a..f59e4e1b45b22815748673f7b530e4b96d7e6900 100644 (file)
 
 using namespace icinga;
 
-static boost::mutex l_ServiceMutex;
-static std::map<String, std::map<String, Service::WeakPtr> > l_ServicesCache;
-static bool l_ServicesCacheNeedsUpdate = false;
-static Timer::Ptr l_ServicesCacheTimer;
-
 REGISTER_SCRIPTFUNCTION(ValidateServiceDictionary, &Host::ValidateServiceDictionary);
 
 REGISTER_TYPE(Host);
 
-Host::Host(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
+void Host::Start(void)
 {
-       RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-       RegisterAttribute("hostgroups", Attribute_Config, &m_HostGroups);
-       RegisterAttribute("macros", Attribute_Config, &m_Macros);
-       RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies);
-       RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies);
-       RegisterAttribute("hostcheck", Attribute_Config, &m_HostCheck);
+       DynamicObject::Start();
 
-}
+       ASSERT(!OwnsLock());
 
-Host::~Host(void)
-{
-       HostGroup::InvalidateMembersCache();
+       Array::Ptr groups = GetGroups();
+
+       if (groups) {
+               BOOST_FOREACH(const String& name, groups) {
+                       HostGroup::Ptr hg = HostGroup::GetByName(name);
 
-       if (m_SlaveServices) {
-               ConfigItem::Ptr service;
-               BOOST_FOREACH(boost::tie(boost::tuples::ignore, service), m_SlaveServices) {
-                       service->Unregister();
+                       if (hg)
+                               hg->AddMember(GetSelf());
                }
        }
+
+       UpdateSlaveServices();
 }
 
-void Host::OnRegistrationCompleted(void)
+void Host::Stop(void)
 {
-       ASSERT(!OwnsLock());
+       DynamicObject::Stop();
 
-       DynamicObject::OnRegistrationCompleted();
+       Array::Ptr groups = GetGroups();
 
-       Host::InvalidateServicesCache();
-       UpdateSlaveServices();
+       if (groups) {
+               BOOST_FOREACH(const String& name, groups) {
+                       HostGroup::Ptr hg = HostGroup::GetByName(name);
+
+                       if (hg)
+                               hg->RemoveMember(GetSelf());
+               }
+       }
+
+       // TODO: unregister slave services/notifications?
 }
 
 String Host::GetDisplayName(void) const
@@ -87,13 +86,6 @@ String Host::GetDisplayName(void) const
                return GetName();
 }
 
-Host::Ptr Host::GetByName(const String& name)
-{
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("Host", name);
-
-       return dynamic_pointer_cast<Host>(configObject);
-}
-
 Array::Ptr Host::GetGroups(void) const
 {
        return m_HostGroups;
@@ -119,6 +111,11 @@ String Host::GetHostCheck(void) const
        return m_HostCheck;
 }
 
+Dictionary::Ptr Host::GetNotificationDescriptions(void) const
+{
+       return m_NotificationDescriptions;
+}
+
 bool Host::IsReachable(void) const
 {
        ASSERT(!OwnsLock());
@@ -179,122 +176,83 @@ void Host::UpdateSlaveServices(void)
        if (!item)
                return;
 
-       Dictionary::Ptr oldServices = m_SlaveServices;
-       Dictionary::Ptr serviceDescs = Get("services");
-
-       Dictionary::Ptr newServices = boost::make_shared<Dictionary>();
+       if (!m_ServiceDescriptions)
+               return;
 
-       if (serviceDescs) {
-               ObjectLock olock(serviceDescs);
-               String svcname;
-               Value svcdesc;
-               BOOST_FOREACH(boost::tie(svcname, svcdesc), serviceDescs) {
-                       if (svcdesc.IsScalar())
-                               svcname = svcdesc;
+       ObjectLock olock(m_ServiceDescriptions);
+       String svcname;
+       Value svcdesc;
+       BOOST_FOREACH(boost::tie(svcname, svcdesc), m_ServiceDescriptions) {
+               if (svcdesc.IsScalar())
+                       svcname = svcdesc;
 
-                       std::ostringstream namebuf;
-                       namebuf << GetName() << ":" << svcname;
-                       String name = namebuf.str();
+               std::ostringstream namebuf;
+               namebuf << GetName() << ":" << svcname;
+               String name = namebuf.str();
 
-                       ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(item->GetDebugInfo());
-                       builder->SetType("Service");
-                       builder->SetName(name);
-                       builder->AddExpression("host_name", OperatorSet, GetName());
-                       builder->AddExpression("display_name", OperatorSet, svcname);
-                       builder->AddExpression("short_name", OperatorSet, svcname);
+               ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(item->GetDebugInfo());
+               builder->SetType("Service");
+               builder->SetName(name);
+               builder->AddExpression("host_name", OperatorSet, GetName());
+               builder->AddExpression("display_name", OperatorSet, svcname);
+               builder->AddExpression("short_name", OperatorSet, svcname);
 
-                       if (!svcdesc.IsObjectType<Dictionary>())
-                               BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary."));
+               if (!svcdesc.IsObjectType<Dictionary>())
+                       BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary."));
 
-                       Dictionary::Ptr service = svcdesc;
+               Dictionary::Ptr service = svcdesc;
 
-                       Array::Ptr templates = service->Get("templates");
+               Array::Ptr templates = service->Get("templates");
 
-                       if (templates) {
-                               ObjectLock olock(templates);
+               if (templates) {
+                       ObjectLock olock(templates);
 
-                               BOOST_FOREACH(const Value& tmpl, templates) {
-                                       builder->AddParent(tmpl);
-                               }
+                       BOOST_FOREACH(const Value& tmpl, templates) {
+                               builder->AddParent(tmpl);
                        }
-
-                       /* Clone attributes from the host object. */
-                       std::set<String, string_iless> keys;
-                       keys.insert("check_interval");
-                       keys.insert("retry_interval");
-                       keys.insert("servicegroups");
-                       keys.insert("checkers");
-                       keys.insert("notification_interval");
-                       keys.insert("notification_type_filter");
-                       keys.insert("notification_state_filter");
-                       keys.insert("check_period");
-                       keys.insert("servicedependencies");
-                       keys.insert("hostdependencies");
-                       keys.insert("export_macros");
-                       keys.insert("macros");
-                       keys.insert("custom");
-
-                       ExpressionList::Ptr host_exprl = boost::make_shared<ExpressionList>();
-                       item->GetLinkedExpressionList()->ExtractFiltered(keys, host_exprl);
-                       builder->AddExpressionList(host_exprl);
-
-                       /* Clone attributes from the service expression list. */
-                       std::vector<String> path;
-                       path.push_back("services");
-                       path.push_back(svcname);
-
-                       ExpressionList::Ptr svc_exprl = boost::make_shared<ExpressionList>();
-                       item->GetLinkedExpressionList()->ExtractPath(path, svc_exprl);
-                       builder->AddExpressionList(svc_exprl);
-
-                       ConfigItem::Ptr serviceItem = builder->Compile();
-                       DynamicObject::Ptr dobj = serviceItem->Commit();
-
-                       newServices->Set(name, serviceItem);
                }
-       }
-
-       if (oldServices) {
-               ObjectLock olock(oldServices);
 
-               ConfigItem::Ptr service;
-               BOOST_FOREACH(boost::tie(boost::tuples::ignore, service), oldServices) {
-                       if (!service)
-                               continue;
-
-                       if (!newServices->Contains(service->GetName()))
-                               service->Unregister();
-               }
-       }
-
-       newServices->Seal();
-
-       Set("slave_services", newServices);
-}
-
-void Host::OnAttributeChanged(const String& name)
-{
-       ASSERT(!OwnsLock());
-
-       if (name == "hostgroups")
-               HostGroup::InvalidateMembersCache();
-       else if (name == "services") {
-               UpdateSlaveServices();
-       } else if (name == "notifications") {
-               BOOST_FOREACH(const Service::Ptr& service, GetServices()) {
-                       service->UpdateSlaveNotifications();
-               }
+               /* Clone attributes from the host object. */
+               std::set<String, string_iless> keys;
+               keys.insert("check_interval");
+               keys.insert("retry_interval");
+               keys.insert("servicegroups");
+               keys.insert("checkers");
+               keys.insert("notification_interval");
+               keys.insert("notification_type_filter");
+               keys.insert("notification_state_filter");
+               keys.insert("check_period");
+               keys.insert("servicedependencies");
+               keys.insert("hostdependencies");
+               keys.insert("export_macros");
+               keys.insert("macros");
+               keys.insert("custom");
+
+               ExpressionList::Ptr host_exprl = boost::make_shared<ExpressionList>();
+               item->GetLinkedExpressionList()->ExtractFiltered(keys, host_exprl);
+               builder->AddExpressionList(host_exprl);
+
+               /* Clone attributes from the service expression list. */
+               std::vector<String> path;
+               path.push_back("services");
+               path.push_back(svcname);
+
+               ExpressionList::Ptr svc_exprl = boost::make_shared<ExpressionList>();
+               item->GetLinkedExpressionList()->ExtractPath(path, svc_exprl);
+               builder->AddExpressionList(svc_exprl);
+
+               ConfigItem::Ptr serviceItem = builder->Compile();
+               DynamicObject::Ptr dobj = serviceItem->Commit();
        }
 }
 
 std::set<Service::Ptr> Host::GetServices(void) const
 {
-       std::set<Service::Ptr> services;
-
-       boost::mutex::scoped_lock lock(l_ServiceMutex);
+       boost::mutex::scoped_lock lock(m_ServicesMutex);
 
+       std::set<Service::Ptr> services;
        Service::WeakPtr wservice;
-       BOOST_FOREACH(boost::tie(boost::tuples::ignore, wservice), l_ServicesCache[GetName()]) {
+       BOOST_FOREACH(boost::tie(boost::tuples::ignore, wservice), m_Services) {
                Service::Ptr service = wservice.lock();
 
                if (!service)
@@ -306,60 +264,23 @@ std::set<Service::Ptr> Host::GetServices(void) const
        return services;
 }
 
-int Host::GetTotalServices(void) const
+void Host::AddService(const Service::Ptr& service)
 {
-       return GetServices().size();
+       boost::mutex::scoped_lock lock(m_ServicesMutex);
+
+       m_Services[service->GetShortName()] = service;
 }
 
-void Host::InvalidateServicesCache(void)
+void Host::RemoveService(const Service::Ptr& service)
 {
-       {
-               boost::mutex::scoped_lock lock(l_ServiceMutex);
-
-               if (l_ServicesCacheNeedsUpdate)
-                       return; /* Someone else has already requested a refresh. */
+       boost::mutex::scoped_lock lock(m_ServicesMutex);
 
-               if (!l_ServicesCacheTimer) {
-                       l_ServicesCacheTimer = boost::make_shared<Timer>();
-                       l_ServicesCacheTimer->SetInterval(0.5);
-                       l_ServicesCacheTimer->OnTimerExpired.connect(boost::bind(&Host::RefreshServicesCache));
-                       l_ServicesCacheTimer->Start();
-               }
-
-               l_ServicesCacheNeedsUpdate = true;
-       }
+       m_Services.erase(service->GetShortName());
 }
 
-void Host::RefreshServicesCache(void)
+int Host::GetTotalServices(void) const
 {
-       {
-               boost::mutex::scoped_lock lock(l_ServiceMutex);
-
-               if (!l_ServicesCacheNeedsUpdate)
-                       return;
-
-               l_ServicesCacheNeedsUpdate = false;
-       }
-
-       Log(LogDebug, "icinga", "Updating Host services cache.");
-
-       std::map<String, std::map<String, Service::WeakPtr> > newServicesCache;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               const Service::Ptr& service = static_pointer_cast<Service>(object);
-
-               Host::Ptr host = service->GetHost();
-
-               if (!host)
-                       continue;
-
-               // TODO: assert for duplicate short_names
-
-               newServicesCache[host->GetName()][service->GetShortName()] = service;
-       }
-
-       boost::mutex::scoped_lock lock(l_ServiceMutex);
-       l_ServicesCache.swap(newServicesCache);
+       return GetServices().size();
 }
 
 Value Host::ValidateServiceDictionary(const String& location, const Dictionary::Ptr& attrs)
@@ -387,22 +308,11 @@ Value Host::ValidateServiceDictionary(const String& location, const Dictionary::
                }
 
                BOOST_FOREACH(const String& name, templates) {
-                       ConfigItem::Ptr item;
-
-                       ConfigCompilerContext *context = ConfigCompilerContext::GetContext();
-
-                       if (context)
-                               item = context->GetItem("Service", name);
+                       ConfigItem::Ptr item = ConfigItem::GetObject("Service", name);
 
-                       /* ignore already active objects while we're in the compiler
-                        * context and linking to existing items is disabled. */
-                       if (!item && (!context || (context->GetFlags() & CompilerLinkExisting)))
-                               item = ConfigItem::GetObject("Service", name);
-
-                       if (!item) {
-                               ConfigCompilerContext::GetContext()->AddError(false, "Validation failed for " +
-                                   location + ": Template '" + name + "' not found.");
-                       }
+                       if (!item)
+                               ConfigCompilerContext::GetInstance()->AddError(false, "Validation failed for " +
+                                           location + ": Template '" + name + "' not found.");
                }
        }
 
@@ -413,16 +323,12 @@ Service::Ptr Host::GetServiceByShortName(const Value& name) const
 {
        if (name.IsScalar()) {
                {
-                       boost::mutex::scoped_lock lock(l_ServiceMutex);
+                       boost::mutex::scoped_lock lock(m_ServicesMutex);
 
-                       std::map<String, Service::WeakPtr>& services = l_ServicesCache[GetName()];
-                       std::map<String, Service::WeakPtr>::iterator it = services.find(name);
+                       std::map<String, Service::Ptr>::const_iterator it = m_Services.find(name);
 
-                       if (it != services.end()) {
-                               Service::Ptr service = it->second.lock();
-                               ASSERT(service);
-                               return service;
-                       }
+                       if (it != m_Services.end())
+                               return it->second;
                }
 
                return Service::Ptr();
@@ -465,9 +371,7 @@ std::set<Host::Ptr> Host::GetChildHosts(void) const
 {
        std::set<Host::Ptr> childs;
 
-        BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
-               const Host::Ptr& host = static_pointer_cast<Host>(object);
-
+        BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
                Array::Ptr dependencies = host->GetHostDependencies();
 
                if (dependencies) {
@@ -773,3 +677,35 @@ bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *res
 
        return false;
 }
+
+void Host::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               bag->Set("display_name", m_DisplayName);
+               bag->Set("hostgroups", m_HostGroups);
+               bag->Set("macros", m_Macros);
+               bag->Set("hostdependencies", m_HostDependencies);
+               bag->Set("servicedependencies", m_ServiceDependencies);
+               bag->Set("hostcheck", m_HostCheck);
+               bag->Set("services", m_ServiceDescriptions);
+               bag->Set("notifications", m_NotificationDescriptions);
+       }
+}
+
+void Host::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               m_DisplayName = bag->Get("display_name");
+               m_HostGroups = bag->Get("hostgroups");
+               m_Macros = bag->Get("macros");
+               m_HostDependencies = bag->Get("hostdependencies");
+               m_ServiceDependencies = bag->Get("servicedependencies");
+               m_HostCheck = bag->Get("hostcheck");
+               m_ServiceDescriptions = bag->Get("services");
+               m_NotificationDescriptions = bag->Get("notifications");
+       }
+}
index f87d304d1bd807fdf15eeb8f6caa73e937bc56b3..c73cacfbb02591ecc8761a0fab37cd8ab80d9e61 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "icinga/i2-icinga.h"
 #include "icinga/macroresolver.h"
-//#include "base/i2-base.h"
 #include "base/array.h"
 #include "base/dynamicobject.h"
 #include "base/dictionary.h"
@@ -78,11 +77,7 @@ class I2_ICINGA_API Host : public DynamicObject, public MacroResolver
 {
 public:
        DECLARE_PTR_TYPEDEFS(Host);
-
-       explicit Host(const Dictionary::Ptr& serializedUpdate);
-       ~Host(void);
-
-       static Host::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(Host);
 
        String GetDisplayName(void) const;
        Array::Ptr GetGroups(void) const;
@@ -91,6 +86,8 @@ public:
        Array::Ptr GetHostDependencies(void) const;
        Array::Ptr GetServiceDependencies(void) const;
        String GetHostCheck(void) const;
+       //Dictionary::Ptr GetServiceDescriptions(void) const;
+       Dictionary::Ptr GetNotificationDescriptions(void) const;
 
        shared_ptr<Service> GetHostCheckService(void) const;
        std::set<Host::Ptr> GetParentHosts(void) const;
@@ -102,8 +99,10 @@ public:
        shared_ptr<Service> GetServiceByShortName(const Value& name) const;
 
        std::set<shared_ptr<Service> > GetServices(void) const;
+       void AddService(const shared_ptr<Service>& service);
+       void RemoveService(const shared_ptr<Service>& service);
+
        int GetTotalServices(void) const;
-       static void InvalidateServicesCache(void);
 
        static Value ValidateServiceDictionary(const String& location, const Dictionary::Ptr& attrs);
 
@@ -123,18 +122,26 @@ public:
        static String StateToString(HostState state);
 
        virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
+
 protected:
-       virtual void OnRegistrationCompleted(void);
-       virtual void OnAttributeChanged(const String& name);
+       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:
-       Attribute<String> m_DisplayName;
-       Attribute<Array::Ptr> m_HostGroups;
-       Attribute<Dictionary::Ptr> m_Macros;
-       Attribute<Array::Ptr> m_HostDependencies;
-       Attribute<Array::Ptr> m_ServiceDependencies;
-       Attribute<String> m_HostCheck;
-       Dictionary::Ptr m_SlaveServices;
+       String m_DisplayName;
+       Array::Ptr m_HostGroups;
+       Dictionary::Ptr m_Macros;
+       Array::Ptr m_HostDependencies;
+       Array::Ptr m_ServiceDependencies;
+       String m_HostCheck;
+       Dictionary::Ptr m_ServiceDescriptions;
+       Dictionary::Ptr m_NotificationDescriptions;
+
+       mutable boost::mutex m_ServicesMutex;
+       std::map<String, shared_ptr<Service> > m_Services;
 
        void UpdateSlaveServices(void);
 
index 53547bcc18d1ca1bc2392982296b7f05660a63b3..20cf983271f628c76678810e6861049c90b099ca 100644 (file)
 
 using namespace icinga;
 
-static boost::mutex l_Mutex;
-static std::map<String, std::vector<Host::WeakPtr> > l_MembersCache;
-static bool l_MembersCacheNeedsUpdate = false;
-static Timer::Ptr l_MembersCacheTimer;
-boost::signals2::signal<void (void)> HostGroup::OnMembersChanged;
-
 REGISTER_TYPE(HostGroup);
 
-HostGroup::HostGroup(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-}
-
-HostGroup::~HostGroup(void)
-{
-       InvalidateMembersCache();
-}
-
-void HostGroup::OnRegistrationCompleted(void)
-{
-       ASSERT(!OwnsLock());
-
-       InvalidateMembersCache();
-}
-
 String HostGroup::GetDisplayName(void) const
 {
        if (!m_DisplayName.IsEmpty())
@@ -62,86 +38,33 @@ String HostGroup::GetDisplayName(void) const
                return GetName();
 }
 
-HostGroup::Ptr HostGroup::GetByName(const String& name)
+std::set<Host::Ptr> HostGroup::GetMembers(void) const
 {
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("HostGroup", name);
-
-       if (!configObject)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("HostGroup '" + name + "' does not exist."));
-
-       return dynamic_pointer_cast<HostGroup>(configObject);
+       return m_Members;
 }
 
-std::set<Host::Ptr> HostGroup::GetMembers(void) const
+void HostGroup::AddMember(const Host::Ptr& host)
 {
-       std::set<Host::Ptr> hosts;
-
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-
-               BOOST_FOREACH(const Host::WeakPtr& whost, l_MembersCache[GetName()]) {
-                       Host::Ptr host = whost.lock();
-
-                       if (!host)
-                               continue;
-
-                       hosts.insert(host);
-               }
-       }
-
-       return hosts;
+       m_Members.insert(host);
 }
 
-void HostGroup::InvalidateMembersCache(void)
+void HostGroup::RemoveMember(const Host::Ptr& host)
 {
-       boost::mutex::scoped_lock lock(l_Mutex);
-
-       if (l_MembersCacheNeedsUpdate)
-               return; /* Someone else has already requested a refresh. */
-
-       if (!l_MembersCacheTimer) {
-               l_MembersCacheTimer = boost::make_shared<Timer>();
-               l_MembersCacheTimer->SetInterval(0.5);
-               l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&HostGroup::RefreshMembersCache));
-               l_MembersCacheTimer->Start();
-       }
-
-       l_MembersCacheNeedsUpdate = true;
+       m_Members.erase(host);
 }
 
-void HostGroup::RefreshMembersCache(void)
+void HostGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
 {
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-
-               if (!l_MembersCacheNeedsUpdate)
-                       return;
+       DynamicObject::InternalSerialize(bag, attributeTypes);
 
-               l_MembersCacheNeedsUpdate = false;
-       }
-
-       Log(LogDebug, "icinga", "Updating HostGroup members cache.");
-
-       std::map<String, std::vector<Host::WeakPtr> > newMembersCache;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
-               const Host::Ptr& host = static_pointer_cast<Host>(object);
-
-               Array::Ptr groups;
-               groups = host->GetGroups();
-
-               if (groups) {
-                       ObjectLock mlock(groups);
-                       BOOST_FOREACH(const Value& group, groups) {
-                               newMembersCache[group].push_back(host);
-                       }
-               }
-       }
+       if (attributeTypes & Attribute_Config)
+               bag->Set("display_name", m_DisplayName);
+}
 
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-               l_MembersCache.swap(newMembersCache);
-       }
+void HostGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
 
-       OnMembersChanged();
+       if (attributeTypes & Attribute_Config)
+               m_DisplayName = bag->Get("display_name");
 }
index a9e1aef4b6504d975455b99d65867f32f3d0b09f..8e370f4bf33d24418251deeed61784b5365e5bdf 100644 (file)
@@ -23,7 +23,6 @@
 #include "icinga/i2-icinga.h"
 #include "icinga/host.h"
 #include "base/dynamicobject.h"
-#include <set>
 
 namespace icinga
 {
@@ -37,27 +36,21 @@ class I2_ICINGA_API HostGroup : public DynamicObject
 {
 public:
        DECLARE_PTR_TYPEDEFS(HostGroup);
-
-       explicit HostGroup(const Dictionary::Ptr& serializedUpdate);
-       ~HostGroup(void);
-
-       static HostGroup::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(HostGroup);
 
        String GetDisplayName(void) const;
 
        std::set<Host::Ptr> GetMembers(void) const;
-
-       static void InvalidateMembersCache(void);
-
-       static boost::signals2::signal<void (void)> OnMembersChanged;
+       void AddMember(const Host::Ptr& host);
+       void RemoveMember(const Host::Ptr& host);
 
 protected:
-       virtual void OnRegistrationCompleted(void);
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
 
 private:
-       Attribute<String> m_DisplayName;
-
-       static void RefreshMembersCache(void);
+       String m_DisplayName;
+       std::set<Host::Ptr> m_Members;
 };
 
 }
index 5125e93abef1cb525a0342a4156d815f28496882..919bd12d35fcfe7e0dd55628a39ac0511bda281c 100644 (file)
@@ -37,18 +37,6 @@ REGISTER_TYPE(IcingaApplication);
 #      define ICINGA_VERSION GIT_MESSAGE
 #endif /* _WIN32 */
 
-IcingaApplication::IcingaApplication(const Dictionary::Ptr& serializedUpdate)
-       : Application(serializedUpdate)
-{
-       RegisterAttribute("cert_path", Attribute_Config, &m_CertPath);
-       RegisterAttribute("ca_path", Attribute_Config, &m_CAPath);
-       RegisterAttribute("node", Attribute_Config, &m_Node);
-       RegisterAttribute("service", Attribute_Config, &m_Service);
-       RegisterAttribute("pid_path", Attribute_Config, &m_PidPath);
-       RegisterAttribute("state_path", Attribute_Config, &m_StatePath);
-       RegisterAttribute("macros", Attribute_Config, &m_Macros);
-}
-
 /**
  * The entry point for the Icinga application.
  *
@@ -215,3 +203,33 @@ bool IcingaApplication::ResolveMacro(const String& macro, const Dictionary::Ptr&
 
        return false;
 }
+
+void IcingaApplication::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               bag->Set("cert_path", m_CertPath);
+               bag->Set("ca_path", m_CAPath);
+               bag->Set("node", m_Node);
+               bag->Set("service", m_Service);
+               bag->Set("pid_path", m_PidPath);
+               bag->Set("state_path", m_StatePath);
+               bag->Set("macros", m_Macros);
+       }
+}
+
+void IcingaApplication::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               m_CertPath = bag->Get("cert_path");
+               m_CAPath = bag->Get("ca_path");
+               m_Node = bag->Get("node");
+               m_Service = bag->Get("service");
+               m_PidPath = bag->Get("pid_path");
+               m_StatePath = bag->Get("state_path");
+               m_Macros = bag->Get("macros");
+       }
+}
index fee06816facd2eefb0d9f58ff4e338090baa5234..daedadc04cbaab7b64f9d14aff92916c12791e47 100644 (file)
@@ -37,8 +37,7 @@ class I2_ICINGA_API IcingaApplication : public Application, public MacroResolver
 {
 public:
        DECLARE_PTR_TYPEDEFS(IcingaApplication);
-
-       explicit IcingaApplication(const Dictionary::Ptr& serializedUpdate);
+       DECLARE_TYPENAME(IcingaApplication);
 
        int Main(void);
 
@@ -57,14 +56,18 @@ public:
 
        virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
 
+protected:
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
 private:
-       Attribute<String> m_CertPath;
-       Attribute<String> m_CAPath;
-       Attribute<String> m_Node;
-       Attribute<String> m_Service;
-       Attribute<String> m_PidPath;
-       Attribute<String> m_StatePath;
-       Attribute<Dictionary::Ptr> m_Macros;
+       String m_CertPath;
+       String m_CAPath;
+       String m_Node;
+       String m_Service;
+       String m_PidPath;
+       String m_StatePath;
+       Dictionary::Ptr m_Macros;
 
        shared_ptr<SSL_CTX> m_SSLContext;
 
index 26fa5fe08d1b096962678a16d90531e1c9d0e63a..6237023d22fc0fb0837b623a78c95deb92962b48 100644 (file)
@@ -386,7 +386,7 @@ Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin,
 {
        Array::Ptr segments = boost::make_shared<Array>();
 
-       Dictionary::Ptr ranges = tp->Get("ranges");
+       Dictionary::Ptr ranges = tp->GetRanges();
 
        if (ranges) {
                for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
index 39b0eede7892d37ec0283f524f8a3240bf859d39..dcb0caf56dfe29a8a7db3635fbea9bfd1721010f 100644 (file)
@@ -98,5 +98,8 @@ String MacroProcessor::InternalResolveMacros(const String& str, const std::vecto
                offset = pos_first + resolved_macro.GetLength();
        }
 
+       if (escapeFn)
+               result = escapeFn(result);
+
        return result;
 }
index 720d2c94f44662f19ab06006df756441d77c1dd3..e21f6dbf844c401e0ea069631708f1c47907a45b 100644 (file)
@@ -31,7 +31,7 @@ void StaticMacroResolver::Add(const String& macro, const String& value)
        m_Macros->Set(macro, value);
 }
 
-bool StaticMacroResolver::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+bool StaticMacroResolver::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
 {
        if (m_Macros->Contains(macro)) {
                *result = m_Macros->Get(macro);
index d56495f12a928889f4955e572ee24d06fb62e856..4d8069ffcca8d3e675782afb503ccbfde37fa32a 100644 (file)
@@ -21,7 +21,6 @@
 #include "icinga/notificationcommand.h"
 #include "icinga/macroprocessor.h"
 #include "icinga/service.h"
-#include "icinga/notificationmessage.h"
 #include "remoting/endpointmanager.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
@@ -36,36 +35,18 @@ using namespace icinga;
 
 REGISTER_TYPE(Notification);
 
-Notification::Notification(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
+void Notification::Start(void)
 {
-       RegisterAttribute("notification_command", Attribute_Config, &m_NotificationCommand);
-       RegisterAttribute("notification_interval", Attribute_Config, &m_NotificationInterval);
-       RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod);
-       RegisterAttribute("last_notification", Attribute_Replicated, &m_LastNotification);
-       RegisterAttribute("next_notification", Attribute_Replicated, &m_NextNotification);
-       RegisterAttribute("notification_number", Attribute_Replicated, &m_NotificationNumber);
-       RegisterAttribute("macros", Attribute_Config, &m_Macros);
-       RegisterAttribute("users", Attribute_Config, &m_Users);
-       RegisterAttribute("groups", Attribute_Config, &m_Groups);
-       RegisterAttribute("times", Attribute_Config, &m_Times);
-       RegisterAttribute("notification_type_filter", Attribute_Config, &m_NotificationTypeFilter);
-       RegisterAttribute("notification_state_filter", Attribute_Config, &m_NotificationStateFilter);
-       RegisterAttribute("host_name", Attribute_Config, &m_HostName);
-       RegisterAttribute("service", Attribute_Config, &m_Service);
-       RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
-}
+       DynamicObject::Start();
 
-Notification::~Notification(void)
-{
-       Service::InvalidateNotificationsCache();
+       GetService()->AddNotification(GetSelf());
 }
 
-Notification::Ptr Notification::GetByName(const String& name)
+void Notification::Stop(void)
 {
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("Notification", name);
+       DynamicObject::Stop();
 
-       return dynamic_pointer_cast<Notification>(configObject);
+       GetService()->RemoveNotification(GetSelf());
 }
 
 Service::Ptr Notification::GetService(void) const
@@ -188,7 +169,6 @@ double Notification::GetLastNotification(void) const
 void Notification::SetLastNotification(double time)
 {
        m_LastNotification = time;
-       Touch("last_notification");
 }
 
 double Notification::GetNextNotification(void) const
@@ -206,10 +186,9 @@ double Notification::GetNextNotification(void) const
 void Notification::SetNextNotification(double time)
 {
        m_NextNotification = time;
-       Touch("next_notification");
 }
 
-int Notification::GetNotificationNumber(void) const
+long Notification::GetNotificationNumber(void) const
 {
        if (m_NotificationNumber.IsEmpty())
                return 0;
@@ -220,13 +199,11 @@ int Notification::GetNotificationNumber(void) const
 void Notification::UpdateNotificationNumber(void)
 {
        m_NotificationNumber = m_NotificationNumber + 1;
-       Touch("notification_number");
 }
 
 void Notification::ResetNotificationNumber(void)
 {
        m_NotificationNumber = 0;
-       Touch("notification_number");
 }
 
 String Notification::NotificationTypeToString(NotificationType type)
@@ -361,21 +338,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
                        SetLastNotification(Utility::GetTime());
                }
 
-               RequestMessage rm;
-               rm.SetMethod("icinga::NotificationSent");
-
-               NotificationMessage params;
-
-               params.SetService(GetService()->GetName());
-               params.SetUser(user->GetName());
-               params.SetType(type);
-               params.SetAuthor(author);
-               params.SetCommentText(text);
-               params.SetCheckResult(cr);
-
-               rm.SetParams(params);
-
-               EndpointManager::GetInstance()->SendMulticastMessage(rm);
+               Service::OnNotificationSentChanged(GetSelf(), user, type, cr, author, text);
 
                Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'");
        } catch (const std::exception& ex) {
@@ -388,14 +351,6 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
        }
 }
 
-void Notification::OnAttributeChanged(const String& name)
-{
-       ASSERT(!OwnsLock());
-
-       if (name == "host_name" || name == "service")
-               Service::InvalidateNotificationsCache();
-}
-
 bool Notification::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
 {
        Dictionary::Ptr macros = GetMacros();
@@ -407,3 +362,45 @@ bool Notification::ResolveMacro(const String& macro, const Dictionary::Ptr&, Str
 
        return false;
 }
+
+void Notification::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       bag->Set("notification_command", m_NotificationCommand);
+       bag->Set("notification_interval", m_NotificationInterval);
+       bag->Set("notification_period", m_NotificationPeriod);
+       bag->Set("last_notification", m_LastNotification);
+       bag->Set("next_notification", m_NextNotification);
+       bag->Set("notification_number", m_NotificationNumber);
+       bag->Set("macros", m_Macros);
+       bag->Set("users", m_Users);
+       bag->Set("groups", m_Groups);
+       bag->Set("times", m_Times);
+       bag->Set("notification_type_filter", m_NotificationTypeFilter);
+       bag->Set("notification_state_filter", m_NotificationStateFilter);
+       bag->Set("host_name", m_HostName);
+       bag->Set("export_macros", m_ExportMacros);
+       bag->Set("service", m_Service);
+}
+
+void Notification::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       m_NotificationCommand = bag->Get("notification_command");
+       m_NotificationInterval = bag->Get("notification_interval");
+       m_NotificationPeriod = bag->Get("notification_period");
+       m_LastNotification = bag->Get("last_notification");
+       m_NextNotification = bag->Get("next_notification");
+       m_NotificationNumber = bag->Get("notification_number");
+       m_Macros = bag->Get("macros");
+       m_Users = bag->Get("users");
+       m_Groups = bag->Get("groups");
+       m_Times = bag->Get("times");
+       m_NotificationTypeFilter = bag->Get("notification_type_filter");
+       m_NotificationStateFilter = bag->Get("notification_state_filter");
+       m_HostName = bag->Get("host_name");
+       m_ExportMacros = bag->Get("export_macros");
+       m_Service = bag->Get("service");
+}
index c85c8c1d4153989ad6fb40794b257c2092d3d132..77a05fa2618561bc9468e842f1d2ad674a5def92 100644 (file)
@@ -59,11 +59,7 @@ class I2_ICINGA_API Notification : public DynamicObject, public MacroResolver
 {
 public:
        DECLARE_PTR_TYPEDEFS(Notification);
-
-       explicit Notification(const Dictionary::Ptr& serializedUpdate);
-       ~Notification(void);
-
-       static Notification::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(Notification);
 
        shared_ptr<Service> GetService(void) const;
        shared_ptr<NotificationCommand> GetNotificationCommand(void) const;
@@ -83,7 +79,7 @@ public:
        double GetNextNotification(void) const;
        void SetNextNotification(double time);
 
-       int GetNotificationNumber(void) const;
+       long GetNotificationNumber(void) const;
        void UpdateNotificationNumber(void);
        void ResetNotificationNumber(void);
 
@@ -94,25 +90,28 @@ public:
        virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
 
 protected:
-       void OnAttributeChanged(const String& name);
+       virtual void Start(void);
+       virtual void Stop(void);
 
-private:
-       Attribute<String> m_NotificationCommand;
-       Attribute<double> m_NotificationInterval;
-       Attribute<String> m_NotificationPeriod;
-       Attribute<double> m_LastNotification;
-       Attribute<double> m_NextNotification;
-       Attribute<int> m_NotificationNumber;
-       Attribute<Dictionary::Ptr> m_Macros;
-       Attribute<Array::Ptr> m_ExportMacros;
-       Attribute<Array::Ptr> m_Users;
-       Attribute<Array::Ptr> m_Groups;
-       Attribute<Dictionary::Ptr> m_Times;
-       Attribute<long> m_NotificationTypeFilter;
-       Attribute<long> m_NotificationStateFilter;
-       Attribute<String> m_HostName;
-       Attribute<String> m_Service;
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
 
+private:
+       String m_NotificationCommand;
+       Value m_NotificationInterval;
+       String m_NotificationPeriod;
+       Value m_LastNotification;
+       Value m_NextNotification;
+       Value m_NotificationNumber;
+       Dictionary::Ptr m_Macros;
+       Array::Ptr m_ExportMacros;
+       Array::Ptr m_Users;
+       Array::Ptr m_Groups;
+       Dictionary::Ptr m_Times;
+       Value m_NotificationTypeFilter;
+       Value m_NotificationStateFilter;
+       String m_HostName;
+       String m_Service;
 
        void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = "");
 };
index d9bb54eae375910b71c3bfcf704366e8c128e57d..9b97398ca18ab6b82567f1143309f45f8b7691ba 100644 (file)
@@ -24,22 +24,6 @@ using namespace icinga;
 
 REGISTER_TYPE(NotificationCommand);
 
-/**
- * Constructor for the NotificationCommand class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-NotificationCommand::NotificationCommand(const Dictionary::Ptr& serializedUpdate)
-       : Command(serializedUpdate)
-{ }
-
-NotificationCommand::Ptr NotificationCommand::GetByName(const String& name)
-{
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("NotificationCommand", name);
-
-       return dynamic_pointer_cast<NotificationCommand>(configObject);
-}
-
 Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification,
     const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type)
 {
index 2eb8c0d459fc931edd18b6c5432c25e6281b78be..a4b09d1dc3b5a9fcbded0be04f9d7dacc29e90ad 100644 (file)
@@ -37,10 +37,7 @@ class I2_ICINGA_API NotificationCommand : public Command
 {
 public:
        DECLARE_PTR_TYPEDEFS(NotificationCommand);
-
-       explicit NotificationCommand(const Dictionary::Ptr& serializedUpdate);
-
-       static NotificationCommand::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(NotificationCommand);
 
        virtual Dictionary::Ptr Execute(const shared_ptr<Notification>& notification,
            const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type);
diff --git a/lib/icinga/notificationmessage.cpp b/lib/icinga/notificationmessage.cpp
deleted file mode 100644 (file)
index 7875899..0000000
+++ /dev/null
@@ -1,95 +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 "icinga/notificationmessage.h"
-
-using namespace icinga;
-
-String NotificationMessage::GetService(void) const
-{
-       String service;
-       Get("service", &service);
-       return service;
-}
-
-void NotificationMessage::SetService(const String& service)
-{
-       Set("service", service);
-}
-
-String NotificationMessage::GetUser(void) const
-{
-       String user;
-       Get("user", &user);
-       return user;
-}
-
-void NotificationMessage::SetUser(const String& user)
-{
-       Set("user", user);
-}
-
-NotificationType NotificationMessage::GetType(void) const
-{
-       long type;
-       Get("type", &type);
-       return static_cast<NotificationType>(type);
-}
-
-void NotificationMessage::SetType(NotificationType type)
-{
-       Set("type", type);
-}
-
-String NotificationMessage::GetAuthor(void) const
-{
-       String author;
-       Get("author", &author);
-       return author;
-}
-
-void NotificationMessage::SetAuthor(const String& author)
-{
-       Set("author", author);
-}
-
-String NotificationMessage::GetCommentText(void) const
-{
-       String comment_text;
-       Get("comment_text", &comment_text);
-       return comment_text;
-}
-
-void NotificationMessage::SetCommentText(const String& comment_text)
-{
-       Set("comment_text", comment_text);
-}
-
-Dictionary::Ptr NotificationMessage::GetCheckResult(void) const
-{
-       Dictionary::Ptr cr;
-       Get("check_result", &cr);
-       return cr;
-}
-
-void NotificationMessage::SetCheckResult(const Dictionary::Ptr& result)
-{
-       Set("check_result", result);
-}
-
diff --git a/lib/icinga/notificationmessage.h b/lib/icinga/notificationmessage.h
deleted file mode 100644 (file)
index 4348e30..0000000
+++ /dev/null
@@ -1,62 +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 NOTIFICATIONMESSAGE_H
-#define NOTIFICATIONMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "icinga/notification.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * A notification message for a service.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API NotificationMessage : public MessagePart
-{
-public:
-       NotificationMessage(void) : MessagePart() { }
-       explicit NotificationMessage(const MessagePart& message) : MessagePart(message) { }
-
-       String GetService(void) const;
-       void SetService(const String& service);
-
-       String GetUser(void) const;
-       void SetUser(const String& user);
-
-       NotificationType GetType(void) const;
-       void SetType(NotificationType type);
-
-       String GetAuthor(void) const;
-       void SetAuthor(const String& author);
-
-       String GetCommentText(void) const;
-       void SetCommentText(const String& comment_text);
-
-       Dictionary::Ptr GetCheckResult(void) const;
-       void SetCheckResult(const Dictionary::Ptr& result);
-};
-
-}
-
-#endif /* NOTIFICATIONMESSAGE_H */
diff --git a/lib/icinga/notificationrequestmessage.cpp b/lib/icinga/notificationrequestmessage.cpp
deleted file mode 100644 (file)
index 587a0c2..0000000
+++ /dev/null
@@ -1,82 +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 "icinga/notificationrequestmessage.h"
-
-using namespace icinga;
-
-String NotificationRequestMessage::GetService(void) const
-{
-       String service;
-       Get("service", &service);
-       return service;
-}
-
-void NotificationRequestMessage::SetService(const String& service)
-{
-       Set("service", service);
-}
-
-NotificationType NotificationRequestMessage::GetType(void) const
-{
-       int type;
-       Get("type", &type);
-       return static_cast<NotificationType>(type);
-}
-
-void NotificationRequestMessage::SetType(NotificationType type)
-{
-       Set("type", type);
-}
-
-Dictionary::Ptr NotificationRequestMessage::GetCheckResult(void) const
-{
-       Dictionary::Ptr cr;
-       Get("check_result", &cr);
-       return cr;
-}
-
-void NotificationRequestMessage::SetCheckResult(const Dictionary::Ptr& cr)
-{
-       Set("check_result", cr);
-}
-
-String NotificationRequestMessage::GetAuthor(void) const
-{
-       String author;
-       Get("author", &author);
-       return author;
-}
-
-void NotificationRequestMessage::SetAuthor(const String& author)
-{
-       Set("author", author);
-}
-
-String NotificationRequestMessage::GetText(void) const
-{
-       String text;
-       Get("text", &text);
-       return text;
-}
-
-void NotificationRequestMessage::SetText(const String& text)
-{
-       Set("text", text);
-}
diff --git a/lib/icinga/notificationrequestmessage.h b/lib/icinga/notificationrequestmessage.h
deleted file mode 100644 (file)
index 26cb29a..0000000
+++ /dev/null
@@ -1,59 +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 NOTIFICATIONREQUESTMESSAGE_H
-#define NOTIFICATIONREQUESTMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "icinga/notification.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * An API request for sending notifications.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API NotificationRequestMessage : public MessagePart
-{
-public:
-       NotificationRequestMessage(void) : MessagePart() { }
-       explicit NotificationRequestMessage(const MessagePart& message) : MessagePart(message) { }
-
-       String GetService(void) const;
-       void SetService(const String& service);
-
-       NotificationType GetType(void) const;
-       void SetType(NotificationType type);
-
-       Dictionary::Ptr GetCheckResult(void) const;
-       void SetCheckResult(const Dictionary::Ptr& cr);
-
-       String GetAuthor(void) const;
-       void SetAuthor(const String& author);
-
-       String GetText(void) const;
-       void SetText(const String& text);
-};
-
-}
-
-#endif /* NOTIFICATIONREQUESTMESSAGE_H */
index 1f7534130fe25c322983fd2a596c19897a297b03..2450c20de85a254f989cb958d64344e3e74f4271 100644 (file)
@@ -26,10 +26,10 @@ using namespace icinga;
 
 REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc);
 
-Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr& service)
+Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&)
 {
        Dictionary::Ptr cr = boost::make_shared<Dictionary>();
-       cr->Set("state", StateUnknown);
+       cr->Set("state", StateOK);
 
        return cr;
 }
index 0ae74400941e374c84ce6e538871f1158b0dbd65..acdd4b8b49bf6d03ed6c7893cdba432af6c988f1 100644 (file)
@@ -26,6 +26,5 @@ using namespace icinga;
 
 REGISTER_SCRIPTFUNCTION(NullEvent, &NullEventTask::ScriptFunc);
 
-void NullEventTask::ScriptFunc(const Service::Ptr& service)
-{
-}
+void NullEventTask::ScriptFunc(const Service::Ptr&)
+{ }
index d84a54280f9be90efab416e14a968f5d43d1519b..2ed7439397b8804e2590773a7942689d561ddb34 100644 (file)
@@ -18,7 +18,6 @@
  ******************************************************************************/
 
 #include "icinga/perfdatawriter.h"
-#include "icinga/checkresultmessage.h"
 #include "icinga/service.h"
 #include "icinga/macroprocessor.h"
 #include "icinga/icingaapplication.h"
@@ -34,28 +33,15 @@ using namespace icinga;
 
 REGISTER_TYPE(PerfdataWriter);
 
-PerfdataWriter::PerfdataWriter(const Dictionary::Ptr& properties)
-       : DynamicObject(properties)
-{
-       RegisterAttribute("perfdata_path", Attribute_Config, &m_PerfdataPath);
-       RegisterAttribute("format_template", Attribute_Config, &m_FormatTemplate);
-       RegisterAttribute("rotation_interval", Attribute_Config, &m_RotationInterval);
-}
-
-void PerfdataWriter::OnAttributeChanged(const String& name)
-{
-       ASSERT(!OwnsLock());
-
-       if (name == "rotation_interval") {
-               m_RotationTimer->SetInterval(GetRotationInterval());
-       }
-}
+PerfdataWriter::PerfdataWriter(void)
+       : m_RotationInterval(30)
+{ }
 
 void PerfdataWriter::Start(void)
 {
-       m_Endpoint = Endpoint::MakeEndpoint("perfdata_" + GetName(), false);
-       m_Endpoint->RegisterTopicHandler("checker::CheckResult",
-           boost::bind(&PerfdataWriter::CheckResultRequestHandler, this, _3));
+       DynamicObject::Start();
+
+       Service::OnNewCheckResult.connect(bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
 
        m_RotationTimer = boost::make_shared<Timer>();
        m_RotationTimer->OnTimerExpired.connect(boost::bind(&PerfdataWriter::RotationTimerHandler, this));
@@ -65,13 +51,6 @@ void PerfdataWriter::Start(void)
        RotateFile();
 }
 
-PerfdataWriter::Ptr PerfdataWriter::GetByName(const String& name)
-{
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("PerfdataWriter", name);
-
-       return dynamic_pointer_cast<PerfdataWriter>(configObject);
-}
-
 String PerfdataWriter::GetPerfdataPath(void) const
 {
        if (!m_PerfdataPath.IsEmpty())
@@ -100,28 +79,19 @@ String PerfdataWriter::GetFormatTemplate(void) const
 
 double PerfdataWriter::GetRotationInterval(void) const
 {
-       if (!m_RotationInterval.IsEmpty())
-               return m_RotationInterval;
-       else
-               return 30;
+       return m_RotationInterval;
 }
 
-void PerfdataWriter::CheckResultRequestHandler(const RequestMessage& request)
+void PerfdataWriter::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr)
 {
-       CheckResultMessage params;
-       if (!request.GetParams(&params))
-               return;
-
-       String svcname = params.GetService();
-       Service::Ptr service = Service::GetByName(svcname);
+       Host::Ptr host = service->GetHost();
 
-       Dictionary::Ptr cr = params.GetCheckResult();
-       if (!cr)
+       if (!host)
                return;
 
        std::vector<MacroResolver::Ptr> resolvers;
        resolvers.push_back(service);
-       resolvers.push_back(service->GetHost());
+       resolvers.push_back(host);
        resolvers.push_back(IcingaApplication::GetInstance());
 
        String line = MacroProcessor::ResolveMacros(GetFormatTemplate(), resolvers, cr);
@@ -156,3 +126,25 @@ 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");
+       }
+}
index cc5fd7532660099b350fd3827195ceabbacc40ec..561a11ef2f163056286865a954c1d9cd8a769a49 100644 (file)
@@ -21,7 +21,7 @@
 #define PERFDATAWRITER_H
 
 #include "icinga/i2-icinga.h"
-#include "remoting/endpoint.h"
+#include "icinga/service.h"
 #include "base/dynamicobject.h"
 #include "base/timer.h"
 #include <fstream>
@@ -38,26 +38,26 @@ class I2_ICINGA_API PerfdataWriter : public DynamicObject
 {
 public:
        DECLARE_PTR_TYPEDEFS(PerfdataWriter);
+       DECLARE_TYPENAME(PerfdataWriter);
 
-       PerfdataWriter(const Dictionary::Ptr& properties);
-
-       static PerfdataWriter::Ptr GetByName(const String& name);
+       PerfdataWriter(void);
 
        String GetPerfdataPath(void) const;
        String GetFormatTemplate(void) const;
        double GetRotationInterval(void) const;
 
 protected:
-       virtual void OnAttributeChanged(const String& name);
        virtual void Start(void);
 
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
 private:
-       Attribute<String> m_PerfdataPath;
-       Attribute<String> m_FormatTemplate;
-       Attribute<double> m_RotationInterval;
+       String m_PerfdataPath;
+       String m_FormatTemplate;
+       double m_RotationInterval;
 
-       Endpoint::Ptr m_Endpoint;
-       void CheckResultRequestHandler(const RequestMessage& request);
+       void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr);
 
        Timer::Ptr m_RotationTimer;
        void RotationTimerHandler(void);
index 93abbca9cc6ab7e3adc9d39beda0f77243ca148e..bc9fe9b91d97be0c3ed23762800df2878e7ec49a 100644 (file)
@@ -67,10 +67,7 @@ Dictionary::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service)
 
        Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), envMacros);
 
-       Value timeout = commandObj->Get("timeout");
-
-       if (!timeout.IsEmpty())
-               process->SetTimeout(timeout);
+       process->SetTimeout(commandObj->GetTimeout());
 
        ProcessResult pr = process->Run();
 
index e2ee6fd8a5039db114a6e16b030944347e326256..0cfc2343ebc15f4e1acb4056b0a630a57ada7ce9 100644 (file)
@@ -65,10 +65,7 @@ void PluginEventTask::ScriptFunc(const Service::Ptr& service)
 
        Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), envMacros);
 
-       Value timeout = commandObj->Get("timeout");
-
-       if (!timeout.IsEmpty())
-               process->SetTimeout(timeout);
+       process->SetTimeout(commandObj->GetTimeout());
 
        process->Run();
 }
index 977eb71c3e1688137a3733a134cde04f312ee802..6981c8c07f46013b12ab1b64c595ff978e32393e 100644 (file)
@@ -77,10 +77,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, c
 
        Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), envMacros);
 
-       Value timeout = commandObj->Get("timeout");
-
-       if (!timeout.IsEmpty())
-               process->SetTimeout(timeout);
+       process->SetTimeout(commandObj->GetTimeout());
 
        ProcessResult pr = process->Run();
 
index cf090dd8893a4d7ae07697f6fe6d4022b62c2065..db2cd643b34fb630e59298440140a8ac7165c511 100644 (file)
 #include "icinga/service.h"
 #include "icinga/checkcommand.h"
 #include "icinga/icingaapplication.h"
-#include "icinga/checkresultmessage.h"
-#include "icinga/flappingmessage.h"
 #include "icinga/cib.h"
-#include "remoting/endpointmanager.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
 #include "base/logger_fwd.h"
 #include "base/convert.h"
+#include "base/utility.h"
 #include <boost/smart_ptr/make_shared.hpp>
 #include <boost/foreach.hpp>
 #include <boost/exception/diagnostic_information.hpp>
@@ -39,7 +37,8 @@ const int Service::DefaultMaxCheckAttempts = 3;
 const double Service::DefaultCheckInterval = 5 * 60;
 const double Service::CheckIntervalDivisor = 5.0;
 
-boost::signals2::signal<void (const Service::Ptr&)> Service::OnCheckerChanged;
+boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> Service::OnNewCheckResult;
+boost::signals2::signal<void (const Service::Ptr&, NotificationType, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationsRequested;
 boost::signals2::signal<void (const Service::Ptr&)> Service::OnNextCheckChanged;
 boost::signals2::signal<void (const Service::Ptr&, FlappingState)> Service::OnFlappingChanged;
 
@@ -95,7 +94,8 @@ long Service::GetSchedulingOffset(void)
 void Service::SetNextCheck(double nextCheck)
 {
        m_NextCheck = nextCheck;
-       Touch("next_check");
+
+       Utility::QueueAsyncCallback(bind(boost::ref(Service::OnNextCheckChanged), GetSelf()));
 }
 
 double Service::GetNextCheck(void)
@@ -126,7 +126,6 @@ void Service::UpdateNextCheck(void)
 void Service::SetCurrentChecker(const String& checker)
 {
        m_CurrentChecker = checker;
-       Touch("current_checker");
 }
 
 String Service::GetCurrentChecker(void) const
@@ -137,7 +136,6 @@ String Service::GetCurrentChecker(void) const
 void Service::SetCurrentCheckAttempt(long attempt)
 {
        m_CheckAttempt = attempt;
-       Touch("check_attempt");
 }
 
 long Service::GetCurrentCheckAttempt(void) const
@@ -151,7 +149,6 @@ long Service::GetCurrentCheckAttempt(void) const
 void Service::SetState(ServiceState state)
 {
        m_State = static_cast<long>(state);
-       Touch("state");
 }
 
 ServiceState Service::GetState(void) const
@@ -166,8 +163,6 @@ ServiceState Service::GetState(void) const
 void Service::SetLastState(ServiceState state)
 {
        m_LastState = static_cast<long>(state);
-
-       Touch("last_state");
 }
 
 ServiceState Service::GetLastState(void) const
@@ -182,8 +177,6 @@ ServiceState Service::GetLastState(void) const
 void Service::SetLastHardState(ServiceState state)
 {
        m_LastHardState = static_cast<long>(state);
-
-       Touch("last_hard_state");
 }
 
 ServiceState Service::GetLastHardState(void) const
@@ -198,7 +191,6 @@ ServiceState Service::GetLastHardState(void) const
 void Service::SetStateType(StateType type)
 {
        m_StateType = static_cast<long>(type);
-       Touch("state_type");
 }
 
 StateType Service::GetStateType(void) const
@@ -213,7 +205,6 @@ StateType Service::GetStateType(void) const
 void Service::SetLastStateType(StateType type)
 {
        m_LastStateType = static_cast<long>(type);
-       Touch("last_state_type");
 }
 
 StateType Service::GetLastStateType(void) const
@@ -228,7 +219,6 @@ StateType Service::GetLastStateType(void) const
 void Service::SetLastStateOK(double ts)
 {
        m_LastStateOK = ts;
-       Touch("last_state_ok");
 }
 
 double Service::GetLastStateOK(void) const
@@ -242,7 +232,6 @@ double Service::GetLastStateOK(void) const
 void Service::SetLastStateWarning(double ts)
 {
        m_LastStateWarning = ts;
-       Touch("last_state_warning");
 }
 
 double Service::GetLastStateWarning(void) const
@@ -256,7 +245,6 @@ double Service::GetLastStateWarning(void) const
 void Service::SetLastStateCritical(double ts)
 {
        m_LastStateCritical = ts;
-       Touch("last_state_critical");
 }
 
 double Service::GetLastStateCritical(void) const
@@ -270,7 +258,6 @@ double Service::GetLastStateCritical(void) const
 void Service::SetLastStateUnknown(double ts)
 {
        m_LastStateUnknown = ts;
-       Touch("last_state_unknown");
 }
 
 double Service::GetLastStateUnknown(void) const
@@ -284,7 +271,6 @@ double Service::GetLastStateUnknown(void) const
 void Service::SetLastStateUnreachable(double ts)
 {
        m_LastStateUnreachable = ts;
-       Touch("last_state_unreachable");
 }
 
 double Service::GetLastStateUnreachable(void) const
@@ -298,7 +284,6 @@ double Service::GetLastStateUnreachable(void) const
 void Service::SetLastReachable(bool reachable)
 {
        m_LastReachable = reachable;
-       Touch("last_reachable");
 }
 
 bool Service::GetLastReachable(void) const
@@ -312,7 +297,6 @@ bool Service::GetLastReachable(void) const
 void Service::SetLastCheckResult(const Dictionary::Ptr& result)
 {
        m_LastResult = result;
-       Touch("last_result");
 }
 
 Dictionary::Ptr Service::GetLastCheckResult(void) const
@@ -386,7 +370,6 @@ String Service::GetLastCheckPerfData(void) const
 void Service::SetLastStateChange(double ts)
 {
        m_LastStateChange = ts;
-       Touch("last_state_change");
 }
 
 double Service::GetLastStateChange(void) const
@@ -400,7 +383,6 @@ double Service::GetLastStateChange(void) const
 void Service::SetLastHardStateChange(double ts)
 {
        m_LastHardStateChange = ts;
-       Touch("last_hard_state_change");
 }
 
 double Service::GetLastHardStateChange(void) const
@@ -422,7 +404,6 @@ bool Service::GetEnableActiveChecks(void) const
 void Service::SetEnableActiveChecks(bool enabled)
 {
        m_EnableActiveChecks = enabled ? 1 : 0;
-       Touch("enable_active_checks");
 }
 
 bool Service::GetEnablePassiveChecks(void) const
@@ -436,7 +417,6 @@ bool Service::GetEnablePassiveChecks(void) const
 void Service::SetEnablePassiveChecks(bool enabled)
 {
        m_EnablePassiveChecks = enabled ? 1 : 0;
-       Touch("enable_passive_checks");
 }
 
 bool Service::GetForceNextCheck(void) const
@@ -450,7 +430,6 @@ bool Service::GetForceNextCheck(void) const
 void Service::SetForceNextCheck(bool forced)
 {
        m_ForceNextCheck = forced ? 1 : 0;
-       Touch("force_next_check");
 }
 
 void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
@@ -593,7 +572,6 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 
        bool send_downtime_notification = m_LastInDowntime != in_downtime;
        m_LastInDowntime = in_downtime;
-       Touch("last_in_downtime");
 
        olock.Unlock();
 
@@ -631,62 +609,27 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
                        " threshold: " + Convert::ToString(GetFlappingThreshold()) +
                        "% current: " + Convert::ToString(GetFlappingCurrent()) + "%.");
 
-       /* Flush the object so other instances see the service's
-        * new state when they receive the CheckResult message */
-       Flush();
-
-       RequestMessage rm;
-       rm.SetMethod("checker::CheckResult");
-
-       /* TODO: add _old_ state to message */
-       CheckResultMessage params;
-       params.SetService(GetName());
-       params.SetCheckResult(cr);
-
-       rm.SetParams(params);
-
-       EndpointManager::GetInstance()->SendMulticastMessage(rm);
+       OnNewCheckResult(GetSelf(), cr);
+       OnStateChanged(GetSelf());
 
        if (call_eventhandler)
                ExecuteEventHandler();
 
        if (send_downtime_notification)
-               RequestNotifications(in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr);
+               OnNotificationsRequested(GetSelf(), in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr, "", "");
 
        if (!was_flapping && is_flapping) {
-               RequestNotifications(NotificationFlappingStart, cr);
-
-               RequestMessage rm;
-               rm.SetMethod("icinga::Flapping");
-
-               FlappingMessage params;
-               params.SetService(GetName());
-               params.SetState(FlappingStarted);
-
-               rm.SetParams(params);
-
-               EndpointManager::GetInstance()->SendMulticastMessage(rm);
+               OnNotificationsRequested(GetSelf(), NotificationFlappingStart, cr, "", "");
 
                Log(LogDebug, "icinga", "Flapping: Service " + GetName() + " started flapping (" + Convert::ToString(GetFlappingThreshold()) + "% < " + Convert::ToString(GetFlappingCurrent()) + "%).");
-       }
-       else if (was_flapping && !is_flapping) {
-               RequestNotifications(NotificationFlappingEnd, cr);
-
-               RequestMessage rm;
-               rm.SetMethod("icinga::Flapping");
-
-               FlappingMessage params;
-               params.SetService(GetName());
-               params.SetState(FlappingStopped);
-
-               rm.SetParams(params);
-
-               EndpointManager::GetInstance()->SendMulticastMessage(rm);
+               OnFlappingChanged(GetSelf(), FlappingStarted);
+       } else if (was_flapping && !is_flapping) {
+               OnNotificationsRequested(GetSelf(), NotificationFlappingEnd, cr, "", "");
 
                Log(LogDebug, "icinga", "Flapping: Service " + GetName() + " stopped flapping (" + Convert::ToString(GetFlappingThreshold()) + "% >= " + Convert::ToString(GetFlappingCurrent()) + "%).");
-       }
-       else if (send_notification)
-               RequestNotifications(recovery ? NotificationRecovery : NotificationProblem, cr);
+               OnFlappingChanged(GetSelf(), FlappingStopped);
+       else if (send_notification)
+               OnNotificationsRequested(GetSelf(), recovery ? NotificationRecovery : NotificationProblem, cr, "", "");
 }
 
 ServiceState Service::StateFromString(const String& state)
@@ -826,9 +769,6 @@ void Service::ExecuteCheck(void)
 
                if (!result->Contains("active"))
                        result->Set("active", 1);
-
-               if (!result->Contains("current_checker"))
-                       result->Set("current_checker", EndpointManager::GetInstance()->GetIdentity());
        }
 
        if (result)
index d3083b0259eec772460d0615dab5dc70bce41c64..c1fef430fd9feb827af5b89937171db280206c78 100644 (file)
@@ -33,8 +33,8 @@ static int l_NextCommentID = 1;
 static boost::mutex l_CommentMutex;
 static std::map<int, String> l_LegacyCommentsCache;
 static std::map<String, Service::WeakPtr> l_CommentsCache;
-static bool l_CommentsCacheNeedsUpdate = false;
-static Timer::Ptr l_CommentsCacheTimer;
+//static bool l_CommentsCacheNeedsUpdate = false;
+//static Timer::Ptr l_CommentsCacheTimer;
 static Timer::Ptr l_CommentsExpireTimer;
 
 boost::signals2::signal<void (const Service::Ptr&, const String&, CommentChangedType)> Service::OnCommentsChanged;
@@ -89,11 +89,11 @@ String Service::AddComment(CommentType entryType, const String& author,
                ObjectLock olock(this);
 
                comments->Set(id, comment);
-               Touch("comments");
        }
 
        {
                boost::mutex::scoped_lock lock(l_CommentMutex);
+               l_LegacyCommentsCache[legacy_id] = id;
                l_CommentsCache[id] = GetSelf();
        }
 
@@ -104,10 +104,15 @@ String Service::AddComment(CommentType entryType, const String& author,
 
 void Service::RemoveAllComments(void)
 {
-       OnCommentsChanged(GetSelf(), Empty, CommentChangedDeleted);
-
        m_Comments = Empty;
-       Touch("comments");
+
+       {
+               boost::mutex::scoped_lock lock(l_CommentMutex);
+               l_LegacyCommentsCache.clear();
+               l_CommentsCache.clear();
+       }
+
+       OnCommentsChanged(GetSelf(), Empty, CommentChangedDeleted);
 }
 
 void Service::RemoveComment(const String& id)
@@ -122,8 +127,20 @@ void Service::RemoveComment(const String& id)
        if (comments) {
                ObjectLock olock(owner);
 
+               Dictionary::Ptr comment = comments->Get(id);
+
+               if (!comment)
+                       return;
+
+               int legacy_id = comment->Get("legacy_id");
+
                comments->Remove(id);
-               owner->Touch("comments");
+
+               {
+                       boost::mutex::scoped_lock lock(l_CommentMutex);
+                       l_LegacyCommentsCache.erase(legacy_id);
+                       l_CommentsCache.erase(id);
+               }
 
                OnCommentsChanged(owner, id, CommentChangedDeleted);
        }
@@ -170,85 +187,29 @@ bool Service::IsCommentExpired(const Dictionary::Ptr& comment)
        return (expire_time != 0 && expire_time < Utility::GetTime());
 }
 
-void Service::InvalidateCommentsCache(void)
+void Service::AddCommentsToCache(void)
 {
-       boost::mutex::scoped_lock lock(l_CommentMutex);
-
-       if (l_CommentsCacheNeedsUpdate)
-               return; /* Someone else has already requested a refresh. */
-
-       if (!l_CommentsCacheTimer) {
-               l_CommentsCacheTimer = boost::make_shared<Timer>();
-               l_CommentsCacheTimer->SetInterval(0.5);
-               l_CommentsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshCommentsCache));
-               l_CommentsCacheTimer->Start();
-       }
-
-       l_CommentsCacheNeedsUpdate = true;
-}
-
-void Service::RefreshCommentsCache(void)
-{
-       {
-               boost::mutex::scoped_lock lock(l_CommentMutex);
-
-               if (!l_CommentsCacheNeedsUpdate)
-                       return;
-
-               l_CommentsCacheNeedsUpdate = false;
-       }
-
        Log(LogDebug, "icinga", "Updating Service comments cache.");
 
-       std::map<int, String> newLegacyCommentsCache;
-       std::map<String, Service::WeakPtr> newCommentsCache;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = dynamic_pointer_cast<Service>(object);
-
-               Dictionary::Ptr comments = service->GetComments();
-
-               if (!comments)
-                       continue;
-
-               ObjectLock olock(comments);
-
-               String id;
-               Dictionary::Ptr comment;
-               BOOST_FOREACH(tie(id, comment), comments) {
-                       int legacy_id = comment->Get("legacy_id");
-
-                       if (legacy_id >= l_NextCommentID)
-                               l_NextCommentID = legacy_id + 1;
-
-                       if (newLegacyCommentsCache.find(legacy_id) != newLegacyCommentsCache.end()) {
-                               /* The legacy_id is already in use by another comment;
-                                * this shouldn't usually happen - assign it a new ID */
-
-                               legacy_id = l_NextCommentID++;
-                               comment->Set("legacy_id", legacy_id);
+       Dictionary::Ptr comments = GetComments();
 
-                               {
-                                       ObjectLock olock(service);
-                                       service->Touch("comments");
-                               }
-                       }
+       if (!comments)
+               return;
 
-                       newLegacyCommentsCache[legacy_id] = id;
-                       newCommentsCache[id] = service;
-               }
-       }
+       ObjectLock olock(comments);
 
        boost::mutex::scoped_lock lock(l_CommentMutex);
 
-       l_CommentsCache.swap(newCommentsCache);
-       l_LegacyCommentsCache.swap(newLegacyCommentsCache);
+       String id;
+       Dictionary::Ptr comment;
+       BOOST_FOREACH(tie(id, comment), comments) {
+               int legacy_id = comment->Get("legacy_id");
+
+               if (legacy_id >= l_NextCommentID)
+                       l_NextCommentID = legacy_id + 1;
 
-       if (!l_CommentsExpireTimer) {
-               l_CommentsExpireTimer = boost::make_shared<Timer>();
-               l_CommentsExpireTimer->SetInterval(300);
-               l_CommentsExpireTimer->OnTimerExpired.connect(boost::bind(&Service::CommentsExpireTimerHandler));
-               l_CommentsExpireTimer->Start();
+               l_LegacyCommentsCache[legacy_id] = id;
+               l_CommentsCache[id] = GetSelf();
        }
 }
 
@@ -274,15 +235,9 @@ void Service::RemoveCommentsByType(int type)
 
        if (!removedComments.empty()) {
                BOOST_FOREACH(const String& id, removedComments) {
-                       comments->Remove(id);
+                       RemoveComment(id);
                }
-
-               OnCommentsChanged(GetSelf(), Empty, CommentChangedDeleted);
-
-               ObjectLock olock(this);
-               Touch("comments");
        }
-
 }
 
 void Service::RemoveExpiredComments(void)
@@ -307,21 +262,15 @@ void Service::RemoveExpiredComments(void)
 
        if (!expiredComments.empty()) {
                BOOST_FOREACH(const String& id, expiredComments) {
-                       comments->Remove(id);
+                       RemoveComment(id);
                }
-
-               OnCommentsChanged(GetSelf(), Empty, CommentChangedDeleted);
-
-               ObjectLock olock(this);
-               Touch("comments");
        }
 
 }
 
 void Service::CommentsExpireTimerHandler(void)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = dynamic_pointer_cast<Service>(object);
+       BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
                service->RemoveExpiredComments();
        }
 }
index f23117f1fd3d0e96c702eb777fccafa8c118ef93..83619710484d0b647507b593bff9dcdf48457976 100644 (file)
@@ -18,8 +18,6 @@
  ******************************************************************************/
 
 #include "icinga/service.h"
-#include "icinga/downtimemessage.h"
-#include "remoting/endpointmanager.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
 #include "base/logger_fwd.h"
@@ -35,25 +33,11 @@ static int l_NextDowntimeID = 1;
 static boost::mutex l_DowntimeMutex;
 static std::map<int, String> l_LegacyDowntimesCache;
 static std::map<String, Service::WeakPtr> l_DowntimesCache;
-static bool l_DowntimesCacheNeedsUpdate = false;
-static Timer::Ptr l_DowntimesCacheTimer;
 static Timer::Ptr l_DowntimesExpireTimer;
 
 boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> Service::OnDowntimeChanged;
 boost::signals2::signal<void (const Service::Ptr&, const String&, DowntimeChangedType)> Service::OnDowntimesChanged;
 
-void Service::DowntimeRequestHandler(const RequestMessage& request)
-{
-       DowntimeMessage params;
-       if (!request.GetParams(&params))
-               return;
-
-       String svcname = params.GetService();
-       Service::Ptr service = Service::GetByName(svcname);
-
-       OnDowntimeChanged(service, params.GetState());
-}
-
 int Service::GetNextDowntimeID(void)
 {
        boost::mutex::scoped_lock lock(l_DowntimeMutex);
@@ -93,14 +77,13 @@ String Service::AddDowntime(const String& author, const String& comment,
 
        if (!triggeredBy.IsEmpty()) {
                Service::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy);
-               Dictionary::Ptr otherDowntimes = otherOwner->Get("downtimes");
+               Dictionary::Ptr otherDowntimes = otherOwner->m_Downtimes;
                Dictionary::Ptr otherDowntime = otherDowntimes->Get(triggeredBy);
                Dictionary::Ptr triggers = otherDowntime->Get("triggers");
 
                {
                        ObjectLock olock(otherOwner);
                        triggers->Set(triggeredBy, triggeredBy);
-                       otherOwner->Touch("downtimes");
                }
        }
 
@@ -120,15 +103,11 @@ String Service::AddDowntime(const String& author, const String& comment,
        String id = Utility::NewUniqueID();
        downtimes->Set(id, downtime);
 
-       {
-               ObjectLock olock(this);
-               Touch("downtimes");
-       }
-
        (void) AddComment(CommentDowntime, author, comment, endTime);
 
        {
                boost::mutex::scoped_lock lock(l_DowntimeMutex);
+               l_LegacyDowntimesCache[legacy_id] = id;
                l_DowntimesCache[id] = GetSelf();
        }
 
@@ -152,22 +131,21 @@ void Service::RemoveDowntime(const String& id)
        {
                ObjectLock olock(owner);
 
-               downtimes->Remove(id);
-
-               RequestMessage rm;
-               rm.SetMethod("icinga::Downtime");
-
-               DowntimeMessage params;
-               params.SetService(owner->GetName());
-               params.SetState(DowntimeCancelled);
+               Dictionary::Ptr downtime = downtimes->Get(id);
 
-               rm.SetParams(params);
+               int legacy_id = downtime->Get("legacy_id");
 
-               EndpointManager::GetInstance()->SendMulticastMessage(rm);
+               downtimes->Remove(id);
 
-               owner->Touch("downtimes");
+               {
+                       boost::mutex::scoped_lock lock(l_DowntimeMutex);
+                       l_LegacyDowntimesCache.erase(legacy_id);
+                       l_DowntimesCache.erase(id);
+               }
        }
 
+       OnDowntimeChanged(owner, DowntimeCancelled);
+
        OnDowntimesChanged(owner, id, DowntimeChangedDeleted);
 }
 
@@ -186,7 +164,6 @@ void Service::TriggerDowntimes(void)
                String id;
                BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) {
                        ids.push_back(id);
-
                }
        }
 
@@ -219,19 +196,7 @@ void Service::TriggerDowntime(const String& id)
                TriggerDowntime(tid);
        }
 
-       RequestMessage rm;
-       rm.SetMethod("icinga::Downtime");
-
-       DowntimeMessage params;
-       params.SetService(owner->GetName());
-       params.SetState(DowntimeStarted);
-
-       rm.SetParams(params);
-
-       EndpointManager::GetInstance()->SendMulticastMessage(rm);
-
-       owner->Touch("downtimes");
-
+       OnDowntimeChanged(owner, DowntimeStarted);
        OnDowntimesChanged(owner, Empty, DowntimeChangedUpdated);
 }
 
@@ -292,80 +257,29 @@ bool Service::IsDowntimeExpired(const Dictionary::Ptr& downtime)
        return (downtime->Get("end_time") < Utility::GetTime());
 }
 
-void Service::InvalidateDowntimesCache(void)
-{
-       boost::mutex::scoped_lock lock(l_DowntimeMutex);
-
-       if (l_DowntimesCacheNeedsUpdate)
-               return; /* Someone else has already requested a refresh. */
-
-       if (!l_DowntimesCacheTimer) {
-               l_DowntimesCacheTimer = boost::make_shared<Timer>();
-               l_DowntimesCacheTimer->SetInterval(0.5);
-               l_DowntimesCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshDowntimesCache));
-               l_DowntimesCacheTimer->Start();
-       }
-
-       l_DowntimesCacheNeedsUpdate = true;
-}
-
-void Service::RefreshDowntimesCache(void)
+void Service::AddDowntimesToCache(void)
 {
-       {
-               boost::mutex::scoped_lock lock(l_DowntimeMutex);
-
-               if (!l_DowntimesCacheNeedsUpdate)
-                       return;
-
-               l_DowntimesCacheNeedsUpdate = false;
-       }
-
        Log(LogDebug, "icinga", "Updating Service downtimes cache.");
 
-       std::map<int, String> newLegacyDowntimesCache;
-       std::map<String, Service::WeakPtr> newDowntimesCache;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = dynamic_pointer_cast<Service>(object);
-
-               Dictionary::Ptr downtimes = service->GetDowntimes();
-
-               if (!downtimes)
-                       continue;
-
-               ObjectLock olock(downtimes);
-
-               String id;
-               Dictionary::Ptr downtime;
-               BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
-                       int legacy_id = downtime->Get("legacy_id");
+       Dictionary::Ptr downtimes = GetDowntimes();
 
-                       if (legacy_id >= l_NextDowntimeID)
-                               l_NextDowntimeID = legacy_id + 1;
+       if (!downtimes)
+               return;
 
-                       if (newLegacyDowntimesCache.find(legacy_id) != newLegacyDowntimesCache.end()) {
-                               /* The legacy_id is already in use by another downtime;
-                                * this shouldn't usually happen - assign it a new ID. */
-                               legacy_id = l_NextDowntimeID++;
-                               downtime->Set("legacy_id", legacy_id);
-                               service->Touch("downtimes");
-                       }
+       boost::mutex::scoped_lock lock(l_DowntimeMutex);
 
-                       newLegacyDowntimesCache[legacy_id] = id;
-                       newDowntimesCache[id] = service;
-               }
-       }
+       ObjectLock olock(downtimes);
 
-       boost::mutex::scoped_lock lock(l_DowntimeMutex);
+       String id;
+       Dictionary::Ptr downtime;
+       BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
+               int legacy_id = downtime->Get("legacy_id");
 
-       l_DowntimesCache.swap(newDowntimesCache);
-       l_LegacyDowntimesCache.swap(newLegacyDowntimesCache);
+               if (legacy_id >= l_NextDowntimeID)
+                       l_NextDowntimeID = legacy_id + 1;
 
-       if (!l_DowntimesExpireTimer) {
-               l_DowntimesExpireTimer = boost::make_shared<Timer>();
-               l_DowntimesExpireTimer->SetInterval(300);
-               l_DowntimesExpireTimer->OnTimerExpired.connect(boost::bind(&Service::DowntimesExpireTimerHandler));
-               l_DowntimesExpireTimer->Start();
+               l_LegacyDowntimesCache[legacy_id] = id;
+               l_DowntimesCache[id] = GetSelf();
        }
 }
 
@@ -391,33 +305,14 @@ void Service::RemoveExpiredDowntimes(void)
 
        if (!expiredDowntimes.empty()) {
                BOOST_FOREACH(const String& id, expiredDowntimes) {
-                       RequestMessage rm;
-                       rm.SetMethod("icinga::Downtime");
-
-                       DowntimeMessage params;
-                       params.SetService(GetName());
-                       params.SetState(DowntimeStopped);
-
-                       rm.SetParams(params);
-
-                       EndpointManager::GetInstance()->SendMulticastMessage(rm);
-
-                       downtimes->Remove(id);
+                       RemoveDowntime(id);
                }
-
-               {
-                       ObjectLock olock(this);
-                       Touch("downtimes");
-               }
-
-               OnDowntimesChanged(GetSelf(), Empty, DowntimeChangedDeleted);
        }
 }
 
 void Service::DowntimesExpireTimerHandler(void)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               Service::Ptr service = dynamic_pointer_cast<Service>(object);
+       BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
                service->RemoveExpiredDowntimes();
        }
 }
index 01cb7603947756e0707b91127e15dd556be72031..562af91310265168905a9c5c9dfd5de772480efb 100644 (file)
@@ -18,7 +18,6 @@
  ******************************************************************************/
 
 #include "icinga/service.h"
-#include "icinga/flappingmessage.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
 #include "base/logger_fwd.h"
@@ -35,9 +34,6 @@ using namespace icinga;
 
 double Service::GetFlappingCurrent(void) const
 {
-       if (m_FlappingNegative.IsEmpty() || m_FlappingPositive.IsEmpty())
-               return 0;
-
        if (m_FlappingPositive + m_FlappingNegative <= 0)
                return 0;
 
@@ -52,18 +48,6 @@ double Service::GetFlappingThreshold(void) const
                return m_FlappingThreshold;
 }
 
-void Service::FlappingRequestHandler(const RequestMessage& request)
-{
-       FlappingMessage params;
-       if (!request.GetParams(&params))
-               return;
-
-       String svcname = params.GetService();
-       Service::Ptr service = Service::GetByName(svcname);
-
-       OnFlappingChanged(service, params.GetState());
-}
-
 bool Service::GetEnableFlapping(void) const
 {
        if (m_EnableFlapping.IsEmpty())
@@ -75,8 +59,9 @@ bool Service::GetEnableFlapping(void) const
 
 void Service::SetEnableFlapping(bool enabled)
 {
-       m_EnableFlapping = enabled ? 1 : 0;
-       Touch("enable_flapping");
+       OnFlappingChanged(GetSelf(), enabled ? FlappingEnabled : FlappingDisabled);
+
+       m_EnableFlapping = enabled;
 }
 
 void Service::UpdateFlappingStatus(bool stateChange)
@@ -118,13 +103,8 @@ void Service::UpdateFlappingStatus(bool stateChange)
        Log(LogDebug, "icinga", "Flapping counter for '" + GetName() + "' is positive=" + Convert::ToString(positive) + ", negative=" + Convert::ToString(negative));
 
        m_FlappingPositive = positive;
-       Touch("flapping_positive");
-
        m_FlappingNegative = negative;
-       Touch("flapping_negative");
-
        m_FlappingLastChange = now;
-       Touch("flapping_lastchange");
 }
 
 bool Service::IsFlapping(void) const
index 58b6b24a5e8f7f4fcc0aca7c3b90de4db3d33520..d4f1e81a680ede6b41eb26f9416b94037e9b43c0 100644 (file)
  ******************************************************************************/
 
 #include "icinga/service.h"
-#include "icinga/notificationrequestmessage.h"
-#include "icinga/notificationmessage.h"
-#include "remoting/endpointmanager.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
 #include "base/logger_fwd.h"
+#include "base/timer.h"
 #include "config/configitembuilder.h"
 #include <boost/tuple/tuple.hpp>
 #include <boost/smart_ptr/make_shared.hpp>
 
 using namespace icinga;
 
-static boost::mutex l_NotificationMutex;
-static std::map<String, std::set<Notification::WeakPtr> > l_NotificationsCache;
-static bool l_NotificationsCacheNeedsUpdate = false;
-static Timer::Ptr l_NotificationsCacheTimer;
+boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentChanged;
 
-boost::signals2::signal<void (const Service::Ptr&, const String&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentChanged;
+Dictionary::Ptr Service::GetNotificationDescriptions(void) const
+{
+       return m_NotificationDescriptions;
+}
 
 void Service::ResetNotificationNumbers(void)
 {
@@ -47,43 +45,6 @@ void Service::ResetNotificationNumbers(void)
        }
 }
 
-void Service::NotificationSentRequestHandler(const RequestMessage& request)
-{
-       NotificationMessage params;
-       if (!request.GetParams(&params))
-               return;
-
-       String svcname = params.GetService();
-       Service::Ptr service = Service::GetByName(svcname);
-
-       String username = params.GetUser();
-       String author = params.GetAuthor();
-       String comment_text = params.GetCommentText();
-
-       NotificationType notification_type = params.GetType();
-       Dictionary::Ptr cr = params.GetCheckResult();
-
-       OnNotificationSentChanged(service, username, notification_type, cr, author, comment_text);
-}
-
-void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text)
-{
-       RequestMessage msg;
-       msg.SetMethod("icinga::SendNotifications");
-
-       NotificationRequestMessage params;
-       msg.SetParams(params);
-
-       params.SetService(GetName());
-       params.SetType(type);
-       params.SetCheckResult(cr);
-       params.SetAuthor(author);
-       params.SetText(text);
-
-       Log(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'");
-       EndpointManager::GetInstance()->SendAnycastMessage(Endpoint::Ptr(), msg);
-}
-
 void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text)
 {
        bool force = false;
@@ -119,76 +80,23 @@ void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr
        }
 }
 
-void Service::InvalidateNotificationsCache(void)
+std::set<Notification::Ptr> Service::GetNotifications(void) const
 {
-       boost::mutex::scoped_lock lock(l_NotificationMutex);
-
-       if (l_NotificationsCacheNeedsUpdate)
-               return; /* Someone else has already requested a refresh. */
-
-       if (!l_NotificationsCacheTimer) {
-               l_NotificationsCacheTimer = boost::make_shared<Timer>();
-               l_NotificationsCacheTimer->SetInterval(0.5);
-               l_NotificationsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshNotificationsCache));
-               l_NotificationsCacheTimer->Start();
-       }
-
-       l_NotificationsCacheNeedsUpdate = true;
+       return m_Notifications;
 }
 
-void Service::RefreshNotificationsCache(void)
+void Service::AddNotification(const Notification::Ptr& notification)
 {
-       {
-               boost::mutex::scoped_lock lock(l_NotificationMutex);
-
-               if (!l_NotificationsCacheNeedsUpdate)
-                       return;
-
-               l_NotificationsCacheNeedsUpdate = false;
-       }
-
-       Log(LogDebug, "icinga", "Updating Service notifications cache.");
-
-       std::map<String, std::set<Notification::WeakPtr> > newNotificationsCache;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Notification")) {
-               const Notification::Ptr& notification = static_pointer_cast<Notification>(object);
-
-               Service::Ptr service = notification->GetService();
-
-               if (!service)
-                       continue;
-
-               newNotificationsCache[service->GetName()].insert(notification);
-       }
-
-       boost::mutex::scoped_lock lock(l_NotificationMutex);
-       l_NotificationsCache.swap(newNotificationsCache);
+       m_Notifications.insert(notification);
 }
 
-std::set<Notification::Ptr> Service::GetNotifications(void) const
+void Service::RemoveNotification(const Notification::Ptr& notification)
 {
-       std::set<Notification::Ptr> notifications;
-
-       {
-               boost::mutex::scoped_lock lock(l_NotificationMutex);
-
-               BOOST_FOREACH(const Notification::WeakPtr& wservice, l_NotificationsCache[GetName()]) {
-                       Notification::Ptr notification = wservice.lock();
-
-                       if (!notification)
-                               continue;
-
-                       notifications.insert(notification);
-               }
-       }
-
-       return notifications;
+       m_Notifications.erase(notification);
 }
 
 void Service::UpdateSlaveNotifications(void)
 {
-       Dictionary::Ptr oldNotifications;
        ConfigItem::Ptr serviceItem, hostItem;
 
        serviceItem = ConfigItem::GetObject("Service", GetName());
@@ -208,19 +116,10 @@ void Service::UpdateSlaveNotifications(void)
        if (!hostItem)
                return;
 
-       {
-               ObjectLock olock(this);
-               oldNotifications = m_SlaveNotifications;
-       }
-
        std::vector<Dictionary::Ptr> descLists;
 
-       descLists.push_back(Get("notifications"));
-
-       Dictionary::Ptr newNotifications;
-       newNotifications = boost::make_shared<Dictionary>();
-
-       descLists.push_back(host->Get("notifications"));
+       descLists.push_back(GetNotificationDescriptions());
+       descLists.push_back(host->GetNotificationDescriptions());
 
        for (int i = 0; i < 2; i++) {
                Dictionary::Ptr descs;
@@ -228,11 +127,11 @@ void Service::UpdateSlaveNotifications(void)
 
                if (i == 0) {
                        /* Host notification descs */
-                       descs = host->Get("notifications");
+                       descs = host->GetNotificationDescriptions();
                        item = hostItem;
                } else {
                        /* Service notification descs */
-                       descs = Get("notifications");
+                       descs = GetNotificationDescriptions();
                        item = serviceItem;
                }
 
@@ -294,28 +193,8 @@ void Service::UpdateSlaveNotifications(void)
 
                        ConfigItem::Ptr notificationItem = builder->Compile();
                        notificationItem->Commit();
-
-                       newNotifications->Set(name, notificationItem);
                }
        }
-
-       if (oldNotifications) {
-               ObjectLock olock(oldNotifications);
-
-               ConfigItem::Ptr notification;
-               BOOST_FOREACH(boost::tie(boost::tuples::ignore, notification), oldNotifications) {
-                       if (!notification)
-                               continue;
-
-                       if (!newNotifications->Contains(notification->GetName()))
-                               notification->Unregister();
-               }
-       }
-
-       {
-               ObjectLock olock(this);
-               m_SlaveNotifications = newNotifications;
-       }
 }
 
 bool Service::GetEnableNotifications(void) const
@@ -329,7 +208,6 @@ bool Service::GetEnableNotifications(void) const
 void Service::SetEnableNotifications(bool enabled)
 {
        m_EnableNotifications = enabled;
-       Touch("enable_notifications");
 }
 
 bool Service::GetForceNextNotification(void) const
@@ -343,5 +221,4 @@ bool Service::GetForceNextNotification(void) const
 void Service::SetForceNextNotification(bool forced)
 {
        m_ForceNextNotification = forced ? 1 : 0;
-       Touch("force_next_notification");
 }
index 57321b3aa3659bfa90c0b25b33e425f3fa2358a0..efa2139999eafb4da9b2f404e2f0f6085486c731 100644 (file)
@@ -22,7 +22,6 @@
 #include "icinga/checkcommand.h"
 #include "icinga/icingaapplication.h"
 #include "icinga/macroprocessor.h"
-#include "icinga/downtimemessage.h"
 #include "config/configitembuilder.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
@@ -35,101 +34,30 @@ using namespace icinga;
 
 REGISTER_TYPE(Service);
 
-Endpoint::Ptr Service::m_Endpoint;
-boost::once_flag Service::m_OnceFlag = BOOST_ONCE_INIT;
-
-Service::Service(const Dictionary::Ptr& serializedObject)
-       : DynamicObject(serializedObject), m_CheckRunning(false)
+void Service::Start(void)
 {
-
-       RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-       RegisterAttribute("macros", Attribute_Config, &m_Macros);
-       RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies);
-       RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies);
-       RegisterAttribute("servicegroups", Attribute_Config, &m_ServiceGroups);
-
-       RegisterAttribute("check_command", Attribute_Config, &m_CheckCommand);
-       RegisterAttribute("max_check_attempts", Attribute_Config, &m_MaxCheckAttempts);
-       RegisterAttribute("check_period", Attribute_Config, &m_CheckPeriod);
-       RegisterAttribute("check_interval", Attribute_Config, &m_CheckInterval);
-       RegisterAttribute("retry_interval", Attribute_Config, &m_RetryInterval);
-       RegisterAttribute("checkers", Attribute_Config, &m_Checkers);
-
-       RegisterAttribute("event_command", Attribute_Config, &m_EventCommand);
-       RegisterAttribute("volatile", Attribute_Config, &m_Volatile);
-
-       RegisterAttribute("next_check", Attribute_Replicated, &m_NextCheck);
-       RegisterAttribute("current_checker", Attribute_Replicated, &m_CurrentChecker);
-       RegisterAttribute("check_attempt", Attribute_Replicated, &m_CheckAttempt);
-       RegisterAttribute("state", Attribute_Replicated, &m_State);
-       RegisterAttribute("state_type", Attribute_Replicated, &m_StateType);
-       RegisterAttribute("last_state", Attribute_Replicated, &m_LastState);
-       RegisterAttribute("last_hard_state", Attribute_Replicated, &m_LastHardState);
-       RegisterAttribute("last_state_type", Attribute_Replicated, &m_LastStateType);
-       RegisterAttribute("last_reachable", Attribute_Replicated, &m_LastReachable);
-       RegisterAttribute("last_result", Attribute_Replicated, &m_LastResult);
-       RegisterAttribute("last_state_change", Attribute_Replicated, &m_LastStateChange);
-       RegisterAttribute("last_hard_state_change", Attribute_Replicated, &m_LastHardStateChange);
-       RegisterAttribute("last_state_ok", Attribute_Replicated, &m_LastStateOK);
-       RegisterAttribute("last_state_warning", Attribute_Replicated, &m_LastStateWarning);
-       RegisterAttribute("last_state_critical", Attribute_Replicated, &m_LastStateCritical);
-       RegisterAttribute("last_state_unknown", Attribute_Replicated, &m_LastStateUnknown);
-       RegisterAttribute("last_state_unreachable", Attribute_Replicated, &m_LastStateUnreachable);
-       RegisterAttribute("last_in_downtime", Attribute_Replicated, &m_LastInDowntime);
-       RegisterAttribute("enable_active_checks", Attribute_Replicated, &m_EnableActiveChecks);
-       RegisterAttribute("enable_passive_checks", Attribute_Replicated, &m_EnablePassiveChecks);
-       RegisterAttribute("force_next_check", Attribute_Replicated, &m_ForceNextCheck);
-
-       RegisterAttribute("short_name", Attribute_Config, &m_ShortName);
-       RegisterAttribute("host_name", Attribute_Config, &m_HostName);
-
-       RegisterAttribute("acknowledgement", Attribute_Replicated, &m_Acknowledgement);
-       RegisterAttribute("acknowledgement_expiry", Attribute_Replicated, &m_AcknowledgementExpiry);
-
-       RegisterAttribute("comments", Attribute_Replicated, &m_Comments);
-
-       RegisterAttribute("downtimes", Attribute_Replicated, &m_Downtimes);
-
-       RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications);
-       RegisterAttribute("force_next_notification", Attribute_Replicated, &m_ForceNextNotification);
-
-       RegisterAttribute("flapping_positive", Attribute_Replicated, &m_FlappingPositive);
-       RegisterAttribute("flapping_negative", Attribute_Replicated, &m_FlappingNegative);
-       RegisterAttribute("flapping_lastchange", Attribute_Replicated, &m_FlappingLastChange);
-       RegisterAttribute("flapping_threshold", Attribute_Config, &m_FlappingThreshold);
-       RegisterAttribute("enable_flapping", Attribute_Replicated, &m_EnableFlapping);
+       DynamicObject::Start();
 
        SetSchedulingOffset(rand());
+       UpdateNextCheck();
 
-       boost::call_once(m_OnceFlag, &Service::Initialize);
-}
+       Array::Ptr groups = GetGroups();
 
-Service::~Service(void)
-{
-       ServiceGroup::InvalidateMembersCache();
-       Host::InvalidateServicesCache();
-       Service::InvalidateDowntimesCache();
-       Service::InvalidateCommentsCache();
-}
+       if (groups) {
+               BOOST_FOREACH(const String& name, groups) {
+                       ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
 
-void Service::Initialize(void)
-{
-       m_Endpoint = Endpoint::MakeEndpoint("service", false);
-       m_Endpoint->RegisterTopicHandler("icinga::NotificationSent",
-           boost::bind(&Service::NotificationSentRequestHandler, _3));
-       m_Endpoint->RegisterTopicHandler("icinga::Downtime",
-           boost::bind(&Service::DowntimeRequestHandler, _3));
-       m_Endpoint->RegisterTopicHandler("icinga::Flapping",
-           boost::bind(&Service::FlappingRequestHandler, _3));
-}
-
-void Service::OnRegistrationCompleted(void)
-{
-       ASSERT(!OwnsLock());
+                       if (sg)
+                               sg->AddMember(GetSelf());
+               }
+       }
 
-       DynamicObject::OnRegistrationCompleted();
+       AddDowntimesToCache();
+       AddCommentsToCache();
 
-       InvalidateNotificationsCache();
+       Host::Ptr host = GetHost();
+       if (host)
+               host->AddService(GetSelf());
 }
 
 String Service::GetDisplayName(void) const
@@ -140,13 +68,6 @@ String Service::GetDisplayName(void) const
                return m_DisplayName;
 }
 
-Service::Ptr Service::GetByName(const String& name)
-{
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("Service", name);
-
-       return dynamic_pointer_cast<Service>(configObject);
-}
-
 Service::Ptr Service::GetByNamePair(const String& hostName, const String& serviceName)
 {
        if (!hostName.IsEmpty()) {
@@ -300,7 +221,6 @@ AcknowledgementType Service::GetAcknowledgement(void)
 void Service::SetAcknowledgement(AcknowledgementType acknowledgement)
 {
        m_Acknowledgement = acknowledgement;
-       Touch("acknowledgement");
 }
 
 bool Service::IsAcknowledged(void)
@@ -319,7 +239,6 @@ double Service::GetAcknowledgementExpiry(void) const
 void Service::SetAcknowledgementExpiry(double timestamp)
 {
        m_AcknowledgementExpiry = timestamp;
-       Touch("acknowledgement_expiry");
 }
 
 void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry)
@@ -333,7 +252,7 @@ void Service::AcknowledgeProblem(const String& author, const String& comment, Ac
 
        (void) AddComment(CommentAcknowledgement, author, comment, 0);
 
-       RequestNotifications(NotificationAcknowledgement, GetLastCheckResult(), author, comment);
+       OnNotificationsRequested(GetSelf(), NotificationAcknowledgement, GetLastCheckResult(), author, comment);
 }
 
 void Service::ClearAcknowledgement(void)
@@ -344,37 +263,6 @@ void Service::ClearAcknowledgement(void)
        SetAcknowledgementExpiry(0);
 }
 
-void Service::OnAttributeChanged(const String& name)
-{
-       ASSERT(!OwnsLock());
-
-       Service::Ptr self = GetSelf();
-
-       if (name == "current_checker")
-               OnCheckerChanged(self);
-       else if (name == "next_check")
-               OnNextCheckChanged(self);
-       else if (name == "servicegroups")
-               ServiceGroup::InvalidateMembersCache();
-       else if (name == "host_name" || name == "short_name") {
-               Host::InvalidateServicesCache();
-
-               UpdateSlaveNotifications();
-       } else if (name == "downtimes")
-               Service::InvalidateDowntimesCache();
-       else if (name == "comments")
-               Service::InvalidateCommentsCache();
-       else if (name == "notifications")
-               UpdateSlaveNotifications();
-       else if (name == "check_interval") {
-               ConfigItem::Ptr item = ConfigItem::GetObject("Service", GetName());
-
-               /* update the next check timestamp if we're the owner of this service */
-               if (item)
-                       UpdateNextCheck();
-       }
-}
-
 std::set<Host::Ptr> Service::GetParentHosts(void) const
 {
        std::set<Host::Ptr> parents;
@@ -505,3 +393,117 @@ bool Service::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, Strin
 
        return false;
 }
+
+void Service::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               bag->Set("display_name", m_DisplayName);
+               bag->Set("macros", m_Macros);
+               bag->Set("hostdependencies", m_HostDependencies);
+               bag->Set("servicedependencies", m_ServiceDependencies);
+               bag->Set("servicegroups", m_ServiceGroups);
+               bag->Set("check_command", m_CheckCommand);
+               bag->Set("max_check_attempts", m_MaxCheckAttempts);
+               bag->Set("check_period", m_CheckPeriod);
+               bag->Set("check_interval", m_CheckInterval);
+               bag->Set("retry_interval", m_RetryInterval);
+               bag->Set("checkers", m_Checkers);
+               bag->Set("event_command", m_EventCommand);
+               bag->Set("volatile", m_Volatile);
+               bag->Set("short_name", m_ShortName);
+               bag->Set("host_name", m_HostName);
+               bag->Set("flapping_threshold", m_FlappingThreshold);
+               bag->Set("notifications", m_NotificationDescriptions);
+       }
+
+       bag->Set("next_check", m_NextCheck);
+       bag->Set("current_checker", m_CurrentChecker);
+       bag->Set("check_attempt", m_CheckAttempt);
+       bag->Set("state", m_State);
+       bag->Set("state_type", m_StateType);
+       bag->Set("last_state", m_LastState);
+       bag->Set("last_hard_state", m_LastHardState);
+       bag->Set("last_state_type", m_LastStateType);
+       bag->Set("last_reachable", m_LastReachable);
+       bag->Set("last_result", m_LastResult);
+       bag->Set("last_state_change", m_LastStateChange);
+       bag->Set("last_hard_state_change", m_LastHardStateChange);
+       bag->Set("last_state_ok", m_LastStateOK);
+       bag->Set("last_state_warning", m_LastStateWarning);
+       bag->Set("last_state_critical", m_LastStateCritical);
+       bag->Set("last_state_unknown", m_LastStateUnknown);
+       bag->Set("last_state_unreachable", m_LastStateUnreachable);
+       bag->Set("last_in_downtime", m_LastInDowntime);
+       bag->Set("enable_active_checks", m_EnableActiveChecks);
+       bag->Set("enable_passive_checks", m_EnablePassiveChecks);
+       bag->Set("force_next_check", m_ForceNextCheck);
+       bag->Set("acknowledgement", m_Acknowledgement);
+       bag->Set("acknowledgement_expiry", m_AcknowledgementExpiry);
+       bag->Set("comments", m_Comments);
+       bag->Set("downtimes", m_Downtimes);
+       bag->Set("enable_notifications", m_EnableNotifications);
+       bag->Set("force_next_notification", m_ForceNextNotification);
+       bag->Set("flapping_positive", m_FlappingPositive);
+       bag->Set("flapping_negative", m_FlappingNegative);
+       bag->Set("flapping_lastchange", m_FlappingLastChange);
+       bag->Set("enable_flapping", m_EnableFlapping);
+}
+
+void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               m_DisplayName = bag->Get("display_name");
+               m_Macros = bag->Get("macros");
+               m_HostDependencies = bag->Get("hostdependencies");
+               m_ServiceDependencies = bag->Get("servicedependencies");
+               m_ServiceGroups = bag->Get("servicegroups");
+               m_CheckCommand = bag->Get("check_command");
+               m_MaxCheckAttempts = bag->Get("max_check_attempts");
+               m_CheckPeriod = bag->Get("check_period");
+               m_CheckInterval = bag->Get("check_interval");
+               m_RetryInterval = bag->Get("retry_interval");
+               m_Checkers = bag->Get("checkers");
+               m_EventCommand = bag->Get("event_command");
+               m_Volatile = bag->Get("volatile");
+               m_ShortName = bag->Get("short_name");
+               m_HostName = bag->Get("host_name");
+               m_FlappingThreshold = bag->Get("flapping_threshold");
+               m_NotificationDescriptions = bag->Get("notifications");
+       }
+
+       m_NextCheck = bag->Get("next_check");
+       m_CurrentChecker = bag->Get("current_checker");
+       m_CheckAttempt = bag->Get("check_attempt");
+       m_State = bag->Get("state");
+       m_StateType = bag->Get("state_type");
+       m_LastState = bag->Get("last_state");
+       m_LastHardState = bag->Get("last_hard_state");
+       m_LastStateType = bag->Get("last_state_type");
+       m_LastReachable = bag->Get("last_reachable");
+       m_LastResult = bag->Get("last_result");
+       m_LastStateChange = bag->Get("last_state_change");
+       m_LastHardStateChange = bag->Get("last_hard_state_change");
+       m_LastStateOK = bag->Get("last_state_ok");
+       m_LastStateWarning = bag->Get("last_state_warning");
+       m_LastStateCritical = bag->Get("last_state_critical");
+       m_LastStateUnknown = bag->Get("last_state_unknown");
+       m_LastStateUnreachable = bag->Get("last_state_unreachable");
+       m_LastInDowntime = bag->Get("last_in_downtime");
+       m_EnableActiveChecks = bag->Get("enable_active_checks");
+       m_EnablePassiveChecks = bag->Get("enable_passive_checks");
+       m_ForceNextCheck = bag->Get("force_next_check");
+       m_Acknowledgement = bag->Get("acknowledgement");
+       m_AcknowledgementExpiry = bag->Get("acknowledgement_expiry");
+       m_Comments = bag->Get("comments");
+       m_Downtimes = bag->Get("downtimes");
+       m_EnableNotifications = bag->Get("enable_notifications");
+       m_ForceNextNotification = bag->Get("force_next_notification");
+       m_FlappingPositive = bag->Get("flapping_positive");
+       m_FlappingNegative = bag->Get("flapping_negative");
+       m_FlappingLastChange = bag->Get("flapping_lastchange");
+       m_EnableFlapping = bag->Get("enable_flapping");
+}
index a338001f7ba234b9547c09a2ddce3e8de481576c..0b3c6fc57bebba231bfac7c8ccd2df51711dc187 100644 (file)
@@ -82,7 +82,8 @@ enum FlappingState
 {
        FlappingStarted = 0,
        FlappingDisabled = 1,
-       FlappingStopped = 2
+       FlappingStopped = 2,
+       FlappingEnabled = 3
 };
 
 /**
@@ -121,11 +122,7 @@ class I2_ICINGA_API Service : public DynamicObject, public MacroResolver
 {
 public:
        DECLARE_PTR_TYPEDEFS(Service);
-
-       explicit Service(const Dictionary::Ptr& serializedUpdate);
-       ~Service(void);
-
-       static Service::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(Service);
 
        static Service::Ptr GetByNamePair(const String& hostName, const String& serviceName);
 
@@ -251,9 +248,10 @@ public:
        static StateType StateTypeFromString(const String& state);
        static String StateTypeToString(StateType state);
 
-       static boost::signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
        static boost::signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
-       static boost::signals2::signal<void (const Service::Ptr&, const String&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentChanged;
+       static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> OnNewCheckResult;
+       static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const Dictionary::Ptr&, const String&, const String&)> OnNotificationsRequested;
+       static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentChanged;
        static boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> OnDowntimeChanged;
        static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
        static boost::signals2::signal<void (const Service::Ptr&, const String&, CommentChangedType)> OnCommentsChanged;
@@ -283,8 +281,6 @@ public:
        static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
        static bool IsDowntimeExpired(const Dictionary::Ptr& downtime);
 
-       static void InvalidateDowntimesCache(void);
-
        bool IsInDowntime(void) const;
        bool IsAcknowledged(void);
 
@@ -306,24 +302,23 @@ public:
 
        static bool IsCommentExpired(const Dictionary::Ptr& comment);
 
-       static void InvalidateCommentsCache(void);
-
        /* Notifications */
+       Dictionary::Ptr GetNotificationDescriptions(void) const;
+
        bool GetEnableNotifications(void) const;
        void SetEnableNotifications(bool enabled);
 
-       void RequestNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = "");
        void SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = "");
 
        std::set<Notification::Ptr> GetNotifications(void) const;
+       void AddNotification(const Notification::Ptr& notification);
+       void RemoveNotification(const Notification::Ptr& notification);
 
        void SetForceNextNotification(bool force);
        bool GetForceNextNotification(void) const;
 
        void ResetNotificationNumbers(void);
 
-       static void InvalidateNotificationsCache(void);
-
        void UpdateSlaveNotifications(void);
 
        /* Event Handler */
@@ -341,99 +336,90 @@ public:
        void UpdateFlappingStatus(bool stateChange);
 
 protected:
-       virtual void OnRegistrationCompleted(void);
-       virtual void OnAttributeChanged(const String& name);
+       virtual void Start(void);
+
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
 
 private:
-       Dictionary::Ptr m_SlaveNotifications;
-
-       Attribute<String> m_DisplayName;
-       Attribute<Dictionary::Ptr> m_Macros;
-       Attribute<Array::Ptr> m_HostDependencies;
-       Attribute<Array::Ptr> m_ServiceDependencies;
-       Attribute<Array::Ptr> m_ServiceGroups;
-       Attribute<String> m_ShortName;
-       Attribute<long> m_Acknowledgement;
-       Attribute<double> m_AcknowledgementExpiry;
-       Attribute<String> m_HostName;
-       Attribute<bool> m_Volatile;
+       String m_DisplayName;
+       Dictionary::Ptr m_Macros;
+       Array::Ptr m_HostDependencies;
+       Array::Ptr m_ServiceDependencies;
+       Array::Ptr m_ServiceGroups;
+       String m_ShortName;
+       Value m_Acknowledgement;
+       Value m_AcknowledgementExpiry;
+       String m_HostName;
+       Value m_Volatile;
 
        /* Checks */
-       Attribute<String> m_CheckCommand;
-       Attribute<long> m_MaxCheckAttempts;
-       Attribute<String> m_CheckPeriod;
-       Attribute<double> m_CheckInterval;
-       Attribute<double> m_RetryInterval;
-       Attribute<double> m_NextCheck;
-       Attribute<Array::Ptr> m_Checkers;
-       Attribute<String> m_CurrentChecker;
-       Attribute<long> m_CheckAttempt;
-       Attribute<long> m_State;
-       Attribute<long> m_StateType;
-       Attribute<long> m_LastState;
-       Attribute<long> m_LastHardState;
-       Attribute<long> m_LastStateType;
-       Attribute<bool> m_LastReachable;
-       Attribute<Dictionary::Ptr> m_LastResult;
-       Attribute<double> m_LastStateChange;
-       Attribute<double> m_LastHardStateChange;
-       Attribute<double> m_LastStateOK;
-       Attribute<double> m_LastStateWarning;
-       Attribute<double> m_LastStateCritical;
-       Attribute<double> m_LastStateUnknown;
-       Attribute<double> m_LastStateUnreachable;
-       Attribute<bool> m_LastInDowntime;
-       Attribute<bool> m_EnableActiveChecks;
-       Attribute<bool> m_EnablePassiveChecks;
-       Attribute<bool> m_ForceNextCheck;
+       String m_CheckCommand;
+       Value m_MaxCheckAttempts;
+       String m_CheckPeriod;
+       Value m_CheckInterval;
+       Value m_RetryInterval;
+       double m_NextCheck;
+       Array::Ptr m_Checkers;
+       String m_CurrentChecker;
+       Value m_CheckAttempt;
+       Value m_State;
+       Value m_StateType;
+       Value m_LastState;
+       Value m_LastHardState;
+       Value m_LastStateType;
+       Value m_LastReachable;
+       Dictionary::Ptr m_LastResult;
+       Value m_LastStateChange;
+       Value m_LastHardStateChange;
+       Value m_LastStateOK;
+       Value m_LastStateWarning;
+       Value m_LastStateCritical;
+       Value m_LastStateUnknown;
+       Value m_LastStateUnreachable;
+       bool m_LastInDowntime;
+       Value m_EnableActiveChecks;
+       Value m_EnablePassiveChecks;
+       Value m_ForceNextCheck;
 
        bool m_CheckRunning;
        long m_SchedulingOffset;
 
-       static boost::once_flag m_OnceFlag;
-       static Endpoint::Ptr m_Endpoint;
-
-       static void Initialize(void);
-
        /* Downtimes */
-       Attribute<Dictionary::Ptr> m_Downtimes;
+       Dictionary::Ptr m_Downtimes;
 
        static void DowntimesExpireTimerHandler(void);
-       static void DowntimeRequestHandler(const RequestMessage& request);
 
        void RemoveExpiredDowntimes(void);
 
-       static void RefreshDowntimesCache(void);
+       void AddDowntimesToCache(void);
 
        /* Comments */
-       Attribute<Dictionary::Ptr> m_Comments;
+       Dictionary::Ptr m_Comments;
 
        static void CommentsExpireTimerHandler(void);
 
-       void AddCommentsToCache(void);
        void RemoveExpiredComments(void);
 
-       static void RefreshCommentsCache(void);
+       void AddCommentsToCache(void);
 
        /* Notifications */
-       Attribute<bool> m_EnableNotifications;
-       Attribute<bool> m_ForceNextNotification;
+       Dictionary::Ptr m_NotificationDescriptions;
 
-       static void RefreshNotificationsCache(void);
+       Value m_EnableNotifications;
+       Value m_ForceNextNotification;
 
-       static void NotificationSentRequestHandler(const RequestMessage& request);
+       std::set<Notification::Ptr> m_Notifications;
 
        /* Event Handler */
-       Attribute<String> m_EventCommand;
+       String m_EventCommand;
 
        /* Flapping */
-       Attribute<bool> m_EnableFlapping;
-       Attribute<long> m_FlappingPositive;
-       Attribute<long> m_FlappingNegative;
-       Attribute<double> m_FlappingLastChange;
-       Attribute<double> m_FlappingThreshold;
-
-       static void FlappingRequestHandler(const RequestMessage& request);
+       Value m_EnableFlapping;
+       long m_FlappingPositive;
+       long m_FlappingNegative;
+       Value m_FlappingLastChange;
+       Value m_FlappingThreshold;
 };
 
 }
index 3f1694e178ade9e79f6cd927345567b4db1a84b0..82ab209f715bda6ab94a9d60723857df5195768f 100644 (file)
 
 using namespace icinga;
 
-static boost::mutex l_Mutex;
-static std::map<String, std::vector<Service::WeakPtr> > l_MembersCache;
-static bool l_MembersCacheNeedsUpdate = false;
-static Timer::Ptr l_MembersCacheTimer;
-boost::signals2::signal<void (void)> ServiceGroup::OnMembersChanged;
-
 REGISTER_TYPE(ServiceGroup);
 
-ServiceGroup::ServiceGroup(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-}
-
-ServiceGroup::~ServiceGroup(void)
-{
-       InvalidateMembersCache();
-}
-
-void ServiceGroup::OnRegistrationCompleted(void)
-{
-       ASSERT(!OwnsLock());
-
-       InvalidateMembersCache();
-}
-
 String ServiceGroup::GetDisplayName(void) const
 {
-       if (!m_DisplayName.Get().IsEmpty())
+       if (!m_DisplayName.IsEmpty())
                return m_DisplayName;
        else
                return GetName();
 }
 
-ServiceGroup::Ptr ServiceGroup::GetByName(const String& name)
+std::set<Service::Ptr> ServiceGroup::GetMembers(void) const
 {
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("ServiceGroup", name);
-
-       if (!configObject)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("ServiceGroup '" + name + "' does not exist."));
-
-       return dynamic_pointer_cast<ServiceGroup>(configObject);
+       return m_Members;
 }
 
-std::set<Service::Ptr> ServiceGroup::GetMembers(void) const
+void ServiceGroup::AddMember(const Service::Ptr& service)
 {
-       std::set<Service::Ptr> services;
-
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-
-               BOOST_FOREACH(const Service::WeakPtr& wservice, l_MembersCache[GetName()]) {
-                       Service::Ptr service = wservice.lock();
-
-                       if (!service)
-                               continue;
-
-                       services.insert(service);
-               }
-       }
-
-       return services;
+       m_Members.insert(service);
 }
 
-void ServiceGroup::InvalidateMembersCache(void)
+void ServiceGroup::RemoveMember(const Service::Ptr& service)
 {
-       boost::mutex::scoped_lock lock(l_Mutex);
-
-       if (l_MembersCacheNeedsUpdate)
-               return; /* Someone else has already requested a refresh. */
-
-       if (!l_MembersCacheTimer) {
-               l_MembersCacheTimer = boost::make_shared<Timer>();
-               l_MembersCacheTimer->SetInterval(0.5);
-               l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&ServiceGroup::RefreshMembersCache));
-               l_MembersCacheTimer->Start();
-       }
-
-       l_MembersCacheNeedsUpdate = true;
+       m_Members.erase(service);
 }
 
-void ServiceGroup::RefreshMembersCache(void)
+void ServiceGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
 {
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-
-               if (!l_MembersCacheNeedsUpdate)
-                       return;
+       DynamicObject::InternalSerialize(bag, attributeTypes);
 
-               l_MembersCacheNeedsUpdate = false;
-       }
-
-       Log(LogDebug, "icinga", "Updating ServiceGroup members cache.");
-
-       std::map<String, std::vector<Service::WeakPtr> > newMembersCache;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-               const Service::Ptr& service = static_pointer_cast<Service>(object);
-
-               Array::Ptr groups = service->GetGroups();
-
-               if (groups) {
-                       ObjectLock mlock(groups);
-                       BOOST_FOREACH(const Value& group, groups) {
-                               newMembersCache[group].push_back(service);
-                       }
-               }
-       }
+       if (attributeTypes & Attribute_Config)
+               bag->Set("display_name", m_DisplayName);
+}
 
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-               l_MembersCache.swap(newMembersCache);
-       }
+void ServiceGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
 
-       OnMembersChanged();
+       if (attributeTypes & Attribute_Config)
+               m_DisplayName = bag->Get("display_name");
 }
index 62f0838596d217b761379fc1d9e57d368f88d592..4e3f8e1a3076dc52cacdda6b2bf2e0508f34050b 100644 (file)
@@ -23,7 +23,6 @@
 #include "icinga/i2-icinga.h"
 #include "icinga/service.h"
 #include "base/dynamictype.h"
-#include <set>
 
 namespace icinga
 {
@@ -37,27 +36,21 @@ class I2_ICINGA_API ServiceGroup : public DynamicObject
 {
 public:
        DECLARE_PTR_TYPEDEFS(ServiceGroup);
-
-       explicit ServiceGroup(const Dictionary::Ptr& serializedUpdate);
-       ~ServiceGroup(void);
-
-       static ServiceGroup::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(ServiceGroup);
 
        String GetDisplayName(void) const;
 
        std::set<Service::Ptr> GetMembers(void) const;
-
-       static void InvalidateMembersCache(void);
-
-       static boost::signals2::signal<void (void)> OnMembersChanged;
+       void AddMember(const Service::Ptr& service);
+       void RemoveMember(const Service::Ptr& service);
 
 protected:
-       virtual void OnRegistrationCompleted(void);
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
 
 private:
-       Attribute<String> m_DisplayName;
-
-       static void RefreshMembersCache(void);
+       String m_DisplayName;
+       std::set<Service::Ptr> m_Members;
 };
 
 }
index 5d6f924afb322bb87a189ad5004b9a09d1026b31..999dce9fdad1fb6c9c928b0480f30bed83419645 100644 (file)
@@ -36,13 +36,9 @@ REGISTER_SCRIPTFUNCTION(EvenMinutesTimePeriod, &TimePeriod::EvenMinutesTimePerio
 
 static Timer::Ptr l_UpdateTimer;
 
-TimePeriod::TimePeriod(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
+void TimePeriod::Start(void)
 {
-       RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-       RegisterAttribute("valid_begin", Attribute_Replicated, &m_ValidBegin);
-       RegisterAttribute("valid_end", Attribute_Replicated, &m_ValidEnd);
-       RegisterAttribute("segments", Attribute_Replicated, &m_Segments);
+       DynamicObject::Start();
 
        if (!l_UpdateTimer) {
                l_UpdateTimer = boost::make_shared<Timer>();
@@ -50,10 +46,7 @@ TimePeriod::TimePeriod(const Dictionary::Ptr& serializedUpdate)
                l_UpdateTimer->OnTimerExpired.connect(boost::bind(&TimePeriod::UpdateTimerHandler));
                l_UpdateTimer->Start();
        }
-}
 
-void TimePeriod::Start(void)
-{
        /* Pre-fill the time period for the next 24 hours. */
        double now = Utility::GetTime();
        UpdateRegion(now, now + 24 * 3600, true);
@@ -68,26 +61,20 @@ String TimePeriod::GetDisplayName(void) const
                 return GetName();
 }
 
-TimePeriod::Ptr TimePeriod::GetByName(const String& name)
+Dictionary::Ptr TimePeriod::GetRanges(void) const
 {
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("TimePeriod", name);
-
-       return dynamic_pointer_cast<TimePeriod>(configObject);
+       return m_Ranges;
 }
 
 void TimePeriod::AddSegment(double begin, double end)
 {
        ASSERT(OwnsLock());
 
-       if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin) {
+       if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin)
                m_ValidBegin = begin;
-               Touch("valid_begin");
-       }
 
-       if (m_ValidEnd.IsEmpty() || end > m_ValidEnd) {
+       if (m_ValidEnd.IsEmpty() || end > m_ValidEnd)
                m_ValidEnd = end;
-               Touch("valid_end");
-       }
 
        Array::Ptr segments = m_Segments;
 
@@ -121,7 +108,6 @@ void TimePeriod::AddSegment(double begin, double end)
        }
 
        segments->Add(segment);
-       Touch("segments");
 }
 
 void TimePeriod::AddSegment(const Dictionary::Ptr& segment)
@@ -133,15 +119,11 @@ void TimePeriod::RemoveSegment(double begin, double end)
 {
        ASSERT(OwnsLock());
 
-       if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin) {
+       if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin)
                m_ValidBegin = begin;
-               Touch("valid_begin");
-       }
 
-       if (m_ValidEnd.IsEmpty() || end > m_ValidEnd) {
+       if (m_ValidEnd.IsEmpty() || end > m_ValidEnd)
                m_ValidEnd = end;
-               Touch("valid_end");
-       }
 
        Array::Ptr segments = m_Segments;
 
@@ -175,7 +157,6 @@ void TimePeriod::RemoveSegment(double begin, double end)
        }
 
        m_Segments = newSegments;
-       Touch("segments");
 }
 
 void TimePeriod::PurgeSegments(double end)
@@ -186,7 +167,6 @@ void TimePeriod::PurgeSegments(double end)
                return;
 
        m_ValidBegin = end;
-       Touch("valid_begin");
 
        Array::Ptr segments = m_Segments;
 
@@ -203,7 +183,6 @@ void TimePeriod::PurgeSegments(double end)
        }
 
        m_Segments = newSegments;
-       Touch("segments");
 }
 
 void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
@@ -284,9 +263,7 @@ void TimePeriod::UpdateTimerHandler(void)
 {
        double now = Utility::GetTime();
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("TimePeriod")) {
-               TimePeriod::Ptr tp = static_pointer_cast<TimePeriod>(object);
-
+       BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjects<TimePeriod>()) {
                /* Only update time periods that have been defined on this node. */
                if (!ConfigItem::GetObject("TimePeriod", tp->GetName()))
                        continue;
@@ -345,3 +322,31 @@ void TimePeriod::Dump(void)
 
        Log(LogDebug, "icinga", "---");
 }
+
+void TimePeriod::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               bag->Set("display_name", m_DisplayName);
+               bag->Set("ranges", m_Ranges);
+       }
+
+       bag->Set("valid_begin", m_ValidBegin);
+       bag->Set("valid_end", m_ValidEnd);
+       bag->Set("segments", m_Segments);
+}
+
+void TimePeriod::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               m_DisplayName = bag->Get("display_name");
+               m_Ranges = bag->Get("ranges");
+       }
+
+       m_ValidBegin = bag->Get("valid_begin");
+       m_ValidEnd = bag->Get("valid_end");
+       m_Segments = bag->Get("segments");
+}
index d41abe9b10e3d144a74fc7b6761b26d859b5ada6..20e6363c127126c2c50eb5eeafe4293092784f37 100644 (file)
@@ -36,12 +36,10 @@ class I2_ICINGA_API TimePeriod : public DynamicObject
 {
 public:
        DECLARE_PTR_TYPEDEFS(TimePeriod);
-
-       explicit TimePeriod(const Dictionary::Ptr& serializedUpdate);
-
-       static TimePeriod::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(TimePeriod);
 
        String GetDisplayName(void) const;
+       Dictionary::Ptr GetRanges(void) const;
 
        virtual void Start(void);
 
@@ -53,11 +51,16 @@ public:
        static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
        static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
 
+protected:
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
 private:
-       Attribute<String> m_DisplayName;
-       Attribute<double> m_ValidBegin;
-       Attribute<double> m_ValidEnd;
-       Attribute<Array::Ptr> m_Segments;
+       String m_DisplayName;
+       Dictionary::Ptr m_Ranges;
+       Value m_ValidBegin;
+       Value m_ValidEnd;
+       Array::Ptr m_Segments;
 
        void AddSegment(double s, double end);
        void AddSegment(const Dictionary::Ptr& segment);
index d89765a4192ab256c49460c47596fc5df7f21446..47ec2110a5307f2937c1afce5189eb206abdceac 100644 (file)
@@ -27,37 +27,36 @@ using namespace icinga;
 
 REGISTER_TYPE(User);
 
-User::User(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
+void User::Start(void)
 {
-       RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-       RegisterAttribute("macros", Attribute_Config, &m_Macros);
-       RegisterAttribute("groups", Attribute_Config, &m_Groups);
-       RegisterAttribute("enable_notifications", Attribute_Config, &m_EnableNotifications);
-       RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod);
-       RegisterAttribute("notification_type_filter", Attribute_Config, &m_NotificationTypeFilter);
-       RegisterAttribute("notification_state_filter", Attribute_Config, &m_NotificationStateFilter);
-       RegisterAttribute("last_notification", Attribute_Replicated, &m_LastNotification);
-}
+       DynamicObject::Start();
 
-User::~User(void)
-{
-       UserGroup::InvalidateMembersCache();
-}
+       Array::Ptr groups = GetGroups();
 
-void User::OnAttributeChanged(const String& name)
-{
-       ASSERT(!OwnsLock());
+       if (groups) {
+               BOOST_FOREACH(const String& name, groups) {
+                       UserGroup::Ptr ug = UserGroup::GetByName(name);
 
-       if (name == "groups")
-               UserGroup::InvalidateMembersCache();
+                       if (ug)
+                               ug->AddMember(GetSelf());
+               }
+       }
 }
 
-User::Ptr User::GetByName(const String& name)
+void User::Stop(void)
 {
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("User", name);
+       DynamicObject::Stop();
+
+       Array::Ptr groups = GetGroups();
+
+       if (groups) {
+               BOOST_FOREACH(const String& name, groups) {
+                       UserGroup::Ptr ug = UserGroup::GetByName(name);
 
-       return dynamic_pointer_cast<User>(configObject);
+                       if (ug)
+                               ug->RemoveMember(GetSelf());
+               }
+       }
 }
 
 String User::GetDisplayName(void) const
@@ -89,7 +88,6 @@ bool User::GetEnableNotifications(void) const
 void User::SetEnableNotifications(bool enabled)
 {
        m_EnableNotifications = enabled;
-       Touch("enable_notifications");
 }
 
 TimePeriod::Ptr User::GetNotificationPeriod(void) const
@@ -116,7 +114,6 @@ unsigned long User::GetNotificationStateFilter(void) const
 void User::SetLastNotification(double ts)
 {
        m_LastNotification = ts;
-       Touch("last_notification");
 }
 
 double User::GetLastNotification(void) const
@@ -124,7 +121,7 @@ double User::GetLastNotification(void) const
        return m_LastNotification;
 }
 
-bool User::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+bool User::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
 {
        if (macro == "CONTACTNAME") {
                *result = GetName();
@@ -144,3 +141,36 @@ bool User::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *
        }
 }
 
+void User::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               bag->Set("display_name", m_DisplayName);
+               bag->Set("macros", m_Macros);
+               bag->Set("groups", m_Groups);
+               bag->Set("notification_period", m_NotificationPeriod);
+               bag->Set("notification_type_filter", m_NotificationTypeFilter);
+               bag->Set("notification_state_filter", m_NotificationStateFilter);
+       }
+
+       bag->Set("enable_notifications", m_EnableNotifications);
+       bag->Set("last_notification", m_LastNotification);
+}
+
+void User::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               m_DisplayName = bag->Get("display_name");
+               m_Macros = bag->Get("macros");
+               m_Groups = bag->Get("groups");
+               m_NotificationPeriod = bag->Get("notification_period");
+               m_NotificationTypeFilter = bag->Get("notification_type_filter");
+               m_NotificationStateFilter = bag->Get("notification_state_filter");
+       }
+
+       m_EnableNotifications = bag->Get("enable_notifications");
+       m_LastNotification = bag->Get("last_notification");
+}
index 5b610068fab00d8fcae4c917d5a900a610d6e0ec..26e65427c9cd4e0554b6f9c6ffb2a7832f6c6627 100644 (file)
@@ -38,11 +38,7 @@ class I2_ICINGA_API User : public DynamicObject, public MacroResolver
 {
 public:
        DECLARE_PTR_TYPEDEFS(User);
-
-       explicit User(const Dictionary::Ptr& serializedUpdate);
-       ~User(void);
-
-       static User::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(User);
 
        String GetDisplayName(void) const;
        Array::Ptr GetGroups(void) const;
@@ -61,17 +57,21 @@ public:
        virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
 
 protected:
-       virtual void OnAttributeChanged(const String& name);
+       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:
-       Attribute<String> m_DisplayName;
-       Attribute<Dictionary::Ptr> m_Macros;
-       Attribute<Array::Ptr> m_Groups;
-       Attribute<bool> m_EnableNotifications;
-       Attribute<String> m_NotificationPeriod;
-       Attribute<long> m_NotificationTypeFilter;
-       Attribute<long> m_NotificationStateFilter;
-       Attribute<double> m_LastNotification;
+       String m_DisplayName;
+       Dictionary::Ptr m_Macros;
+       Array::Ptr m_Groups;
+       Value m_EnableNotifications;
+       String m_NotificationPeriod;
+       Value m_NotificationTypeFilter;
+       Value m_NotificationStateFilter;
+       double m_LastNotification;
 };
 
 }
index 915d6b89bc881c00c8cbad64b16a144aa48d5092..987972045ba9b0b7761eb88ac3d520d83923e5e9 100644 (file)
 
 using namespace icinga;
 
-static boost::mutex l_Mutex;
-static std::map<String, std::vector<User::WeakPtr> > l_MembersCache;
-static bool l_MembersCacheNeedsUpdate = false;
-static Timer::Ptr l_MembersCacheTimer;
-boost::signals2::signal<void (void)> UserGroup::OnMembersChanged;
-
 REGISTER_TYPE(UserGroup);
 
-UserGroup::UserGroup(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-}
-
-UserGroup::~UserGroup(void)
-{
-       InvalidateMembersCache();
-}
-
-void UserGroup::OnRegistrationCompleted(void)
-{
-       ASSERT(!OwnsLock());
-
-       InvalidateMembersCache();
-}
-
 String UserGroup::GetDisplayName(void) const
 {
        if (!m_DisplayName.IsEmpty())
@@ -62,85 +38,33 @@ String UserGroup::GetDisplayName(void) const
                return GetName();
 }
 
-UserGroup::Ptr UserGroup::GetByName(const String& name)
+std::set<User::Ptr> UserGroup::GetMembers(void) const
 {
-       DynamicObject::Ptr configObject = DynamicObject::GetObject("UserGroup", name);
-
-       if (!configObject)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("UserGroup '" + name + "' does not exist."));
-
-       return dynamic_pointer_cast<UserGroup>(configObject);
+       return m_Members;
 }
 
-std::set<User::Ptr> UserGroup::GetMembers(void) const
+void UserGroup::AddMember(const User::Ptr& user)
 {
-       std::set<User::Ptr> users;
-
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-
-               BOOST_FOREACH(const User::WeakPtr& wuser, l_MembersCache[GetName()]) {
-                       User::Ptr user = wuser.lock();
-
-                       if (!user)
-                               continue;
-
-                       users.insert(user);
-               }
-       }
-
-       return users;
+       m_Members.insert(user);
 }
 
-void UserGroup::InvalidateMembersCache(void)
+void UserGroup::RemoveMember(const User::Ptr& user)
 {
-       boost::mutex::scoped_lock lock(l_Mutex);
-
-       if (l_MembersCacheNeedsUpdate)
-               return; /* Someone else has already requested a refresh. */
-
-       if (!l_MembersCacheTimer) {
-               l_MembersCacheTimer = boost::make_shared<Timer>();
-               l_MembersCacheTimer->SetInterval(0.5);
-               l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&UserGroup::RefreshMembersCache));
-               l_MembersCacheTimer->Start();
-       }
-
-       l_MembersCacheNeedsUpdate = true;
+       m_Members.erase(user);
 }
 
-void UserGroup::RefreshMembersCache(void)
+void UserGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
 {
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-
-               if (!l_MembersCacheNeedsUpdate)
-                       return;
+       DynamicObject::InternalSerialize(bag, attributeTypes);
 
-               l_MembersCacheNeedsUpdate = false;
-       }
-
-       Log(LogDebug, "icinga", "Updating UserGroup members cache.");
-
-       std::map<String, std::vector<User::WeakPtr> > newMembersCache;
-
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
-               const User::Ptr& user = static_pointer_cast<User>(object);
-
-               Array::Ptr groups = user->GetGroups();
-
-               if (groups) {
-                       ObjectLock mlock(groups);
-                       BOOST_FOREACH(const Value& group, groups) {
-                               newMembersCache[group].push_back(user);
-                       }
-               }
-       }
+       if (attributeTypes & Attribute_Config)
+               bag->Set("display_name", m_DisplayName);
+}
 
-       {
-               boost::mutex::scoped_lock lock(l_Mutex);
-               l_MembersCache.swap(newMembersCache);
-       }
+void UserGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
 
-       OnMembersChanged();
+       if (attributeTypes & Attribute_Config)
+               m_DisplayName = bag->Get("display_name");
 }
index b4e9a56d56a9d4af0f19ddf3980f71f55bcfa51b..06c6f43caeb0c2121e3f25c636678bc15c8d368e 100644 (file)
@@ -36,29 +36,23 @@ class I2_ICINGA_API UserGroup : public DynamicObject
 {
 public:
        DECLARE_PTR_TYPEDEFS(UserGroup);
-
-       explicit UserGroup(const Dictionary::Ptr& serializedUpdate);
-       ~UserGroup(void);
-
-       static UserGroup::Ptr GetByName(const String& name);
+       DECLARE_TYPENAME(UserGroup);
 
        String GetDisplayName(void) const;
 
        std::set<User::Ptr> GetMembers(void) const;
-
-       static void InvalidateMembersCache(void);
-
-       static boost::signals2::signal<void (void)> OnMembersChanged;
+       void AddMember(const User::Ptr& user);
+       void RemoveMember(const User::Ptr& user);
 
 protected:
-       virtual void OnRegistrationCompleted(void);
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
 
 private:
-       Attribute<String> m_DisplayName;
-
-       static void RefreshMembersCache(void);
+       String m_DisplayName;
+       std::set<User::Ptr> m_Members;
 };
 
 }
 
-#endif /* HOSTGROUP_H */
+#endif /* USERGROUP_H */
index 819d3821702763382ce5cb295c62301c65f27e29..4c6e790e806d082ec778ae3d4822564e6a53b9b1 100644 (file)
@@ -20,6 +20,8 @@
 #include "ido/dbconnection.h"
 #include "ido/dbvalue.h"
 #include "icinga/icingaapplication.h"
+#include "icinga/host.h"
+#include "icinga/service.h"
 #include "base/dynamictype.h"
 #include "base/utility.h"
 #include "base/initialize.h"
@@ -31,14 +33,10 @@ Timer::Ptr DbConnection::m_ProgramStatusTimer;
 
 INITIALIZE_ONCE(DbConnection, &DbConnection::StaticInitialize);
 
-DbConnection::DbConnection(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("table_prefix", Attribute_Config, &m_TablePrefix);
-}
-
 void DbConnection::Start(void)
 {
+       DynamicObject::Start();
+
        DbObject::OnRegistered.connect(boost::bind(&DbConnection::ActivateObject, this, _1));
        DbObject::OnUnregistered.connect(boost::bind(&DbConnection::DeactivateObject, this, _1));
        DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
@@ -109,10 +107,10 @@ void DbConnection::ProgramStatusHandler(void)
        query3.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
        DbObject::OnQuery(query3);
 
-       InsertRuntimeVariable("total_services", DynamicType::GetObjects("Service").size());
-       InsertRuntimeVariable("total_scheduled_services", DynamicType::GetObjects("Service").size());
-       InsertRuntimeVariable("total_hosts", DynamicType::GetObjects("Host").size());
-       InsertRuntimeVariable("total_scheduled_hosts", DynamicType::GetObjects("Host").size());
+       InsertRuntimeVariable("total_services", DynamicType::GetObjects<Service>().size());
+       InsertRuntimeVariable("total_scheduled_services", DynamicType::GetObjects<Service>().size());
+       InsertRuntimeVariable("total_hosts", DynamicType::GetObjects<Host>().size());
+       InsertRuntimeVariable("total_scheduled_hosts", DynamicType::GetObjects<Host>().size());
 }
 
 void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref)
@@ -201,3 +199,19 @@ void DbConnection::UpdateAllObjects(void)
                }
        }
 }
+
+void DbConnection::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config)
+               bag->Set("table_prefix", m_TablePrefix);
+}
+
+void DbConnection::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config)
+               m_TablePrefix = bag->Get("table_prefix");
+}
\ No newline at end of file
index 36ab73ba28a2a0f3cd70488821bfcb472f54c1d9..b8221c5b3724abe28f6973793f6a591996cdfe19 100644 (file)
@@ -38,8 +38,6 @@ class DbConnection : public DynamicObject
 public:
        DECLARE_PTR_TYPEDEFS(DbConnection);
 
-       DbConnection(const Dictionary::Ptr& serializedUpdate);
-
        static void StaticInitialize(void);
 
        void SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref);
@@ -59,6 +57,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);
+
        virtual void ExecuteQuery(const DbQuery& query) = 0;
        virtual void ActivateObject(const DbObject::Ptr& dbobj) = 0;
        virtual void DeactivateObject(const DbObject::Ptr& dbobj) = 0;
@@ -66,7 +67,7 @@ protected:
        void UpdateAllObjects(void);
 
 private:
-       Attribute<String> m_TablePrefix;
+       String m_TablePrefix;
 
        std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
        std::map<DbObject::Ptr, DbReference> m_InsertIDs;
@@ -76,8 +77,6 @@ private:
 
        static void InsertRuntimeVariable(const String& key, const Value& value);
        static void ProgramStatusHandler(void);
-
-       friend class DbType;
 };
 
 }
index 2fc45385d6477bc78007f14ebd8e05e1b0737d02..50291f6ebe1ea1c64f9070c119c086f05f37e365 100644 (file)
@@ -42,9 +42,10 @@ DbObject::DbObject(const shared_ptr<DbType>& type, const String& name1, const St
 
 void DbObject::StaticInitialize(void)
 {
-       DynamicObject::OnRegistered.connect(boost::bind(&DbObject::ObjectRegisteredHandler, _1));
-       DynamicObject::OnUnregistered.connect(boost::bind(&DbObject::ObjectUnregisteredHandler, _1));
-       DynamicObject::OnAttributesChanged.connect(boost::bind(&DbObject::AttributesChangedHandler, _1, _2));
+       DynamicObject::OnStarted.connect(boost::bind(&DbObject::ObjectStartedHandler, _1));
+       DynamicObject::OnStopped.connect(boost::bind(&DbObject::ObjectStoppedHandler, _1));
+
+       DynamicObject::OnStateChanged.connect(boost::bind(&DbObject::StateChangedHandler, _1));
 }
 
 void DbObject::SetObject(const DynamicObject::Ptr& object)
@@ -132,20 +133,6 @@ double DbObject::GetLastStatusUpdate(void) const
        return m_LastStatusUpdate;
 }
 
-bool DbObject::IsConfigAttribute(const String& attribute) const
-{
-       DynamicObject::Ptr object = GetObject();
-       ObjectLock olock(object);
-       DynamicObject::AttributeConstIterator it;
-
-       it = object->GetAttributes().find(attribute);
-
-       if (it == object->GetAttributes().end())
-               return false;
-
-       return (it->second.GetType() == Attribute_Config);
-}
-
 bool DbObject::IsStatusAttribute(const String&) const
 {
        return false;
@@ -201,7 +188,7 @@ DbObject::Ptr DbObject::GetOrCreateByObject(const DynamicObject::Ptr& object)
        return dbobj;
 }
 
-void DbObject::ObjectRegisteredHandler(const DynamicObject::Ptr& object)
+void DbObject::ObjectStartedHandler(const DynamicObject::Ptr& object)
 {
        DbObject::Ptr dbobj = GetOrCreateByObject(object);
 
@@ -214,7 +201,7 @@ void DbObject::ObjectRegisteredHandler(const DynamicObject::Ptr& object)
        dbobj->SendStatusUpdate();
 }
 
-void DbObject::ObjectUnregisteredHandler(const DynamicObject::Ptr& object)
+void DbObject::ObjectStoppedHandler(const DynamicObject::Ptr& object)
 {
        DbObject::Ptr dbobj = GetOrCreateByObject(object);
 
@@ -229,26 +216,12 @@ void DbObject::ObjectUnregisteredHandler(const DynamicObject::Ptr& object)
        }
 }
 
-void DbObject::AttributesChangedHandler(const DynamicObject::Ptr& object, const std::set<String, string_iless>& attributes)
+void DbObject::StateChangedHandler(const DynamicObject::Ptr& object)
 {
        DbObject::Ptr dbobj = GetOrCreateByObject(object);
 
        if (!dbobj)
                return;
 
-       bool configUpdate = false, statusUpdate = false;
-
-       BOOST_FOREACH(const String& attribute, attributes) {
-               if (!configUpdate && dbobj->IsConfigAttribute(attribute))
-                       configUpdate = true;
-
-               if (!statusUpdate && dbobj->IsStatusAttribute(attribute))
-                       statusUpdate = true;
-       }
-
-       if (configUpdate)
-               dbobj->SendConfigUpdate();
-
-       if (statusUpdate)
-               dbobj->SendStatusUpdate();
+       dbobj->SendStatusUpdate();
 }
index 5e4d90867fb73368512cca4660ce09766a5b4d36..36ce3b921d93e5afc3469dd4be4e3d710ce2a7d7 100644 (file)
@@ -24,6 +24,7 @@
 #include "ido/dbquery.h"
 #include "ido/dbtype.h"
 #include "base/dynamicobject.h"
+#include <boost/smart_ptr.hpp>
 
 namespace icinga
 {
@@ -87,7 +88,6 @@ public:
 protected:
        DbObject(const boost::shared_ptr<DbType>& type, const String& name1, const String& name2);
 
-       virtual bool IsConfigAttribute(const String& attribute) const;
        virtual bool IsStatusAttribute(const String& attribute) const;
 
        virtual void OnConfigUpdate(void);
@@ -101,13 +101,9 @@ private:
        double m_LastConfigUpdate;
        double m_LastStatusUpdate;
 
-       friend boost::shared_ptr<DbObject> boost::make_shared<>(const icinga::String&, const icinga::String&);
-
-       static void ObjectRegisteredHandler(const DynamicObject::Ptr& object);
-       static void ObjectUnregisteredHandler(const DynamicObject::Ptr& object);
-       static void AttributesChangedHandler(const DynamicObject::Ptr& object, const std::set<String, string_iless>& attributes);
-       //static void TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects);
-       //static void FlushObjectHandler(double tx, const DynamicObject::Ptr& object);
+       static void ObjectStartedHandler(const DynamicObject::Ptr& object);
+       static void ObjectStoppedHandler(const DynamicObject::Ptr& object);
+       static void StateChangedHandler(const DynamicObject::Ptr& object);
 
        friend class DbType;
 };
index 0aff0d78b17b6ebf0ad83a4ed92d2ba7cf97b1f4..cb2ddc043e554c847ece163c795ccee7ae567253 100644 (file)
@@ -60,12 +60,11 @@ public:
 protected:
        DbValue(DbValueType type, const Value& value);
 
+       friend DbValue::Ptr boost::make_shared<DbValue, DbValueType, Value>(const icinga::DbValueType&, const icinga::Value&);
+
 private:
        DbValueType m_Type;
        Value m_Value;
-
-       friend boost::shared_ptr<DbValue> boost::make_shared<>(const icinga::DbValueType&, const double&);
-       friend boost::shared_ptr<DbValue> boost::make_shared<>(const icinga::DbValueType&, const icinga::Value&);
 };
 
 }
index 0517300de20f47578de6a806d5c9c0cd2fda346a..4444a2a1eab395b079bfe949a6a0444dec1ba4df 100644 (file)
 using namespace icinga;
 
 REGISTER_DBTYPE(HostGroup, "hostgroup", DbObjectTypeHostGroup, "hostgroup_object_id", HostGroupDbObject);
-INITIALIZE_ONCE(HostGroupDbObject, &HostGroupDbObject::StaticInitialize);
 
 HostGroupDbObject::HostGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
        : DbObject(type, name1, name2)
 { }
 
-void HostGroupDbObject::StaticInitialize(void)
-{
-       HostGroup::OnMembersChanged.connect(boost::bind(&HostGroupDbObject::MembersChangedHandler, HostGroup::Ptr()));
-}
-
 Dictionary::Ptr HostGroupDbObject::GetConfigFields(void) const
 {
        Dictionary::Ptr fields = boost::make_shared<Dictionary>();
@@ -57,33 +51,22 @@ Dictionary::Ptr HostGroupDbObject::GetStatusFields(void) const
 void HostGroupDbObject::OnConfigUpdate(void)
 {
        HostGroup::Ptr group = static_pointer_cast<HostGroup>(GetObject());
-       MembersChangedHandler(group);
-}
 
-void HostGroupDbObject::MembersChangedHandler(const HostGroup::Ptr& hgfilter)
-{
        DbQuery query1;
        query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
        query1.Type = DbQueryDelete;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
-       query1.WhereCriteria->Set("instance_id", 0);
+       query1.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
        OnQuery(query1);
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
-               HostGroup::Ptr hg = static_pointer_cast<HostGroup>(object);
-
-               if (hgfilter && hg != hgfilter)
-                       continue;
-
-               BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
-                       DbQuery query2;
-                       query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
-                       query2.Type = DbQueryInsert;
-                       query2.Fields = boost::make_shared<Dictionary>();
-                       query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(hg));
-                       query2.Fields->Set("host_object_id", host);
-                       OnQuery(query2);
-               }
+       BOOST_FOREACH(const Host::Ptr& host, group->GetMembers()) {
+               DbQuery query2;
+               query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
+               query2.Type = DbQueryInsert;
+               query2.Fields = boost::make_shared<Dictionary>();
+               query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
+               query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
+               query2.Fields->Set("host_object_id", host);
+               OnQuery(query2);
        }
 }
index 07fe7d150ff4edecfc3007e660ecf557abb71c26..7ec72a4f0ff9e146f0e898ef853fe32b674cb26f 100644 (file)
@@ -39,8 +39,6 @@ public:
 
        HostGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2);
 
-       static void StaticInitialize(void);
-
        virtual Dictionary::Ptr GetConfigFields(void) const;
        virtual Dictionary::Ptr GetStatusFields(void) const;
 
index fb85f6db5cb07e61b7cf3fc30d6eaf0d2824db71..644a902df169e72cc73c952f88af4704d0b57809 100644 (file)
@@ -294,9 +294,7 @@ void ServiceDbObject::CommentsChangedHandler(const Service::Ptr& svcfilter, cons
                /* we cannot determine which comment id is deleted
                 * id cache may not be in sync
                 */
-               BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-                       Service::Ptr service = static_pointer_cast<Service>(object);
-
+               BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
                        if (svcfilter && svcfilter != service)
                                continue;
 
@@ -437,9 +435,7 @@ void ServiceDbObject::DowntimesChangedHandler(const Service::Ptr& svcfilter, con
                /* we cannot determine which downtime id is deleted
                 * id cache may not be in sync
                 */
-               BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
-                       Service::Ptr service = static_pointer_cast<Service>(object);
-
+               BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
                        if (svcfilter && svcfilter != service)
                                continue;
 
@@ -505,11 +501,8 @@ void ServiceDbObject::AddDowntime(const Service::Ptr& service, const Dictionary:
 
 void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& downtime)
 {
-       unsigned long entry_time = static_cast<long>(downtime->Get("entry_time"));
-       unsigned long entry_time_usec = (downtime->Get("entry_time") - entry_time) * 1000 * 1000;
-
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
-       fields1->Set("entry_time", DbValue::FromTimestamp(entry_time));
+       fields1->Set("entry_time", DbValue::FromTimestamp(downtime->Get("entry_time")));
        fields1->Set("object_id", object);
 
        if (object->GetType() == DynamicType::GetByName("Host")) {
index 23ca8691a3968703d7e364a58d12cce1d0998bb4..7a7a135a5e59eb9063fdcd120ce5f4e976681d95 100644 (file)
 using namespace icinga;
 
 REGISTER_DBTYPE(ServiceGroup, "servicegroup", DbObjectTypeServiceGroup, "servicegroup_object_id", ServiceGroupDbObject);
-INITIALIZE_ONCE(ServiceGroupDbObject, &ServiceGroupDbObject::StaticInitialize);
 
 ServiceGroupDbObject::ServiceGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
        : DbObject(type, name1, name2)
 { }
 
-void ServiceGroupDbObject::StaticInitialize(void)
-{
-       ServiceGroup::OnMembersChanged.connect(boost::bind(&ServiceGroupDbObject::MembersChangedHandler, ServiceGroup::Ptr()));
-}
-
 Dictionary::Ptr ServiceGroupDbObject::GetConfigFields(void) const
 {
        Dictionary::Ptr fields = boost::make_shared<Dictionary>();
@@ -57,33 +51,21 @@ void ServiceGroupDbObject::OnConfigUpdate(void)
 {
        ServiceGroup::Ptr group = static_pointer_cast<ServiceGroup>(GetObject());
 
-       MembersChangedHandler(group);
-}
-
-void ServiceGroupDbObject::MembersChangedHandler(const ServiceGroup::Ptr& sgfilter)
-{
        DbQuery query1;
        query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
        query1.Type = DbQueryDelete;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
-       query1.WhereCriteria->Set("instance_id", 0);
+       query1.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
        OnQuery(query1);
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
-               ServiceGroup::Ptr sg = static_pointer_cast<ServiceGroup>(object);
-
-               if (sgfilter && sgfilter != sg)
-                       continue;
-
-               BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
-                       DbQuery query2;
-                       query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
-                       query2.Type = DbQueryInsert;
-                       query2.Fields = boost::make_shared<Dictionary>();
-                       query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(sg));
-                       query2.Fields->Set("service_object_id", service);
-                       OnQuery(query2);
-               }
+       BOOST_FOREACH(const Service::Ptr& service, group->GetMembers()) {
+               DbQuery query2;
+               query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
+               query2.Type = DbQueryInsert;
+               query2.Fields = boost::make_shared<Dictionary>();
+               query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
+               query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
+               query2.Fields->Set("service_object_id", service);
+               OnQuery(query2);
        }
 }
index 7f1cb8d9d1e7f0720744d60ffb7ac557d83e6c57..0965eaeb0715bdf46257945f2871191d4329f9a7 100644 (file)
@@ -39,16 +39,11 @@ public:
 
        ServiceGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2);
 
-       static void StaticInitialize(void);
-
        virtual Dictionary::Ptr GetConfigFields(void) const;
        virtual Dictionary::Ptr GetStatusFields(void) const;
 
 protected:
        virtual void OnConfigUpdate(void);
-
-private:
-       static void MembersChangedHandler(const ServiceGroup::Ptr& sgfilter);
 };
 
 }
index c4093119c2b25ac4810b81fece0a91ca34197d74..28f9f9d44dd5ceed8abb1757ec2b015f63939d4f 100644 (file)
@@ -62,7 +62,7 @@ void TimePeriodDbObject::OnConfigUpdate(void)
        query_del1.WhereCriteria->Set("timeperiod_id", DbValue::FromObjectInsertID(tp));
        OnQuery(query_del1);
 
-       Dictionary::Ptr ranges = tp->Get("ranges");
+       Dictionary::Ptr ranges = tp->GetRanges();
 
        if (!ranges)
                return;
index fdf6a6e2787061b6db8f8535918f5bcc7d7e0891..6a82fff69986632cc46de6e2b97456d48ec038b7 100644 (file)
 using namespace icinga;
 
 REGISTER_DBTYPE(UserGroup, "contactgroup", DbObjectTypeContactGroup, "contactgroup_object_id", UserGroupDbObject);
-INITIALIZE_ONCE(UserGroupDbObject, &UserGroupDbObject::StaticInitialize);
 
 UserGroupDbObject::UserGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
        : DbObject(type, name1, name2)
 { }
 
-void UserGroupDbObject::StaticInitialize(void)
-{
-       UserGroup::OnMembersChanged.connect(boost::bind(&UserGroupDbObject::MembersChangedHandler, UserGroup::Ptr()));
-}
-
 Dictionary::Ptr UserGroupDbObject::GetConfigFields(void) const
 {
        Dictionary::Ptr fields = boost::make_shared<Dictionary>();
@@ -58,33 +52,22 @@ void UserGroupDbObject::OnConfigUpdate(void)
 {
        UserGroup::Ptr group = static_pointer_cast<UserGroup>(GetObject());
 
-       MembersChangedHandler(group);
-}
-
-void UserGroupDbObject::MembersChangedHandler(const UserGroup::Ptr& ugfilter)
-{
        DbQuery query1;
        query1.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
        query1.Type = DbQueryDelete;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("instance_id", 0);
+       query1.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
        OnQuery(query1);
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
-               UserGroup::Ptr ug = static_pointer_cast<UserGroup>(object);
-
-               if (ugfilter && ugfilter != ug)
-                       continue;
-
-               BOOST_FOREACH(const User::Ptr& user, ug->GetMembers()) {
-                       DbQuery query2;
-                       query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
-                       query2.Type = DbQueryInsert;
-                       query2.Fields = boost::make_shared<Dictionary>();
-                       query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
-                       query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(ug));
-                       query2.Fields->Set("contact_object_id", user);
-                       OnQuery(query2);
-               }
+       BOOST_FOREACH(const User::Ptr& user, group->GetMembers()) {
+               DbQuery query2;
+               query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
+               query2.Type = DbQueryInsert;
+               query2.Fields = boost::make_shared<Dictionary>();
+               query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
+               query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
+               query2.Fields->Set("contact_object_id", user);
+               OnQuery(query2);
        }
 }
index 8abcf9b88c8f263addb39d672f91549b281c4424..eeebc42543328586f1af973797f11578986ea0ab 100644 (file)
@@ -39,16 +39,11 @@ public:
 
        UserGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2);
 
-       static void StaticInitialize(void);
-
        virtual Dictionary::Ptr GetConfigFields(void) const;
        virtual Dictionary::Ptr GetStatusFields(void) const;
 
 protected:
        virtual void OnConfigUpdate(void);
-
-private:
-       static void MembersChangedHandler(const UserGroup::Ptr& ugfilter);
 };
 
 }
index 6f952df4e36ec100a23dd200988a6ad33332385e..db868cab91dff74906cb722d990f10055c27a867 100644 (file)
@@ -237,7 +237,12 @@ Value PythonLanguage::MarshalFromPython(PyObject *value)
 
                String name = PyString_AsString(pname);
 
-               DynamicObject::Ptr object = DynamicObject::GetObject(type, name);
+               DynamicType::Ptr dtype = DynamicType::GetByName(type);
+
+               if (!dtype)
+                       BOOST_THROW_EXCEPTION(std::invalid_argument("Type '" + type + "' does not exist."));
+
+               DynamicObject::Ptr object = dtype->GetObject(name);
 
                if (!object)
                        BOOST_THROW_EXCEPTION(std::invalid_argument("Object '" + name + "' of type '" + type + "' does not exist."));
index 151e3c3ef05d5b0fb092cd6243e3c5febf2cdd79..fe6820af03e646c722ee0e992da88e6a151eb564 100644 (file)
@@ -34,37 +34,6 @@ REGISTER_TYPE(Endpoint);
 
 boost::signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnConnected;
 
-/**
- * Constructor for the Endpoint class.
- *
- * @param properties A serialized dictionary containing attributes.
- */
-Endpoint::Endpoint(const Dictionary::Ptr& serializedUpdate)
-       : DynamicObject(serializedUpdate)
-{
-       RegisterAttribute("local", Attribute_Config, &m_Local);
-
-       RegisterAttribute("node", Attribute_Replicated, &m_Node);
-       RegisterAttribute("service", Attribute_Replicated, &m_Service);
-       RegisterAttribute("subscriptions", Attribute_Replicated, &m_Subscriptions);
-}
-
-Endpoint::~Endpoint(void)
-{ }
-
-/**
- * Retrieves an endpoint by name.
- *
- * @param name The name of the endpoint.
- * @returns The endpoint.
- */
-Endpoint::Ptr Endpoint::GetByName(const String& name)
-{
-        DynamicObject::Ptr configObject = DynamicObject::GetObject("Endpoint", name);
-
-        return dynamic_pointer_cast<Endpoint>(configObject);
-}
-
 /**
  * Helper function for creating new endpoint objects.
  *
@@ -78,7 +47,7 @@ Endpoint::Ptr Endpoint::MakeEndpoint(const String& name, bool replicated, bool l
        ConfigItemBuilder::Ptr endpointConfig = boost::make_shared<ConfigItemBuilder>();
        endpointConfig->SetType("Endpoint");
        endpointConfig->SetName((!replicated && local) ? "local:" + name : name);
-       endpointConfig->SetLocal(!replicated);
+       //TODO: endpointConfig->SetLocal(!replicated);
        endpointConfig->AddExpression("local", OperatorSet, local);
 
        ConfigItem::Ptr item = endpointConfig->Compile();
@@ -190,7 +159,6 @@ bool Endpoint::HasSubscription(const String& topic) const
 void Endpoint::ClearSubscriptions(void)
 {
        m_Subscriptions = Empty;
-       Touch("subscriptions");
 }
 
 Dictionary::Ptr Endpoint::GetSubscriptions(void) const
@@ -202,7 +170,6 @@ void Endpoint::SetSubscriptions(const Dictionary::Ptr& subscriptions)
 {
        subscriptions->Seal();
        m_Subscriptions = subscriptions;
-       Touch("subscriptions");
 }
 
 void Endpoint::RegisterTopicHandler(const String& topic, const boost::function<Endpoint::Callback>& callback)
@@ -341,3 +308,29 @@ String Endpoint::GetService(void) const
 
        return m_Service;
 }
+
+void Endpoint::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+       DynamicObject::InternalSerialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               bag->Set("local", m_Local);
+               bag->Set("node", m_Node);
+               bag->Set("service", m_Service);
+       }
+
+       bag->Set("subscriptions", m_Subscriptions);
+}
+
+void Endpoint::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+       DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+       if (attributeTypes & Attribute_Config) {
+               m_Local = bag->Get("local");
+               m_Node = bag->Get("node");
+               m_Service = bag->Get("service");
+       }
+
+       bag->Set("subscriptions", m_Subscriptions);
+}
\ No newline at end of file
index e813ef578d1cc0c29c29e2ab86179301e2bf46a6..564515fda88e6230f463219ad46c4fdcf7818409 100644 (file)
@@ -41,14 +41,10 @@ class I2_REMOTING_API Endpoint : public DynamicObject
 {
 public:
        DECLARE_PTR_TYPEDEFS(Endpoint);
+       DECLARE_TYPENAME(Endpoint);
 
        typedef void (Callback)(const Endpoint::Ptr&, const Endpoint::Ptr&, const RequestMessage&);
 
-       explicit Endpoint(const Dictionary::Ptr& serializedUpdate);
-       ~Endpoint(void);
-
-       static Endpoint::Ptr GetByName(const String& name);
-
        Stream::Ptr GetClient(void) const;
        void SetClient(const Stream::Ptr& client);
 
@@ -76,11 +72,15 @@ public:
 
        static boost::signals2::signal<void (const Endpoint::Ptr&)> OnConnected;
 
+protected:
+       virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+       virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
 private:
-       Attribute<bool> m_Local;
-       Attribute<Dictionary::Ptr> m_Subscriptions;
-       Attribute<String> m_Node;
-       Attribute<String> m_Service;
+       bool m_Local;
+       Dictionary::Ptr m_Subscriptions;
+       String m_Node;
+       String m_Service;
 
        Stream::Ptr m_Client;
 
index e49a94ef8b8dbb641b1ef74253e542acd59de007..3a20d5a6b49edf796b01bd90ea1ab2245f035788 100644 (file)
@@ -89,12 +89,12 @@ void EndpointManager::SetIdentity(const String& identity)
        m_Identity = identity;
 
        if (m_Endpoint)
-               m_Endpoint->Unregister();
+               m_Endpoint->Stop();
 
-       DynamicObject::Ptr object = DynamicObject::GetObject("Endpoint", identity);
+       Endpoint::Ptr endpoint = DynamicObject::GetObject<Endpoint>(identity);
 
-       if (object)
-               m_Endpoint = dynamic_pointer_cast<Endpoint>(object);
+       if (endpoint)
+               m_Endpoint = endpoint;
        else
                m_Endpoint = Endpoint::MakeEndpoint(identity, true, true);
 }
@@ -230,8 +230,8 @@ void EndpointManager::SendUnicastMessage(const Endpoint::Ptr& sender,
 {
        /* don't forward messages between non-local endpoints, assume that
         * anonymous senders (sender == null) are local */
-       if ((sender && !sender->IsLocal()) && !recipient->IsLocal())
-               return;
+//     if ((sender && !sender->IsLocal()) && !recipient->IsLocal())
+//             return;
 
        if (ResponseMessage::IsResponseMessage(message))
                recipient->ProcessResponse(sender, message);
@@ -255,11 +255,10 @@ void EndpointManager::SendAnycastMessage(const Endpoint::Ptr& sender,
 
        std::vector<Endpoint::Ptr> candidates;
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
-               Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
+       BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
                /* don't forward messages between non-local endpoints */
-               if ((sender && !sender->IsLocal()) && !endpoint->IsLocal())
-                       continue;
+//             if ((sender && !sender->IsLocal()) && !endpoint->IsLocal())
+//                     continue;
 
                if (endpoint->HasSubscription(method))
                        candidates.push_back(endpoint);
@@ -301,9 +300,7 @@ void EndpointManager::SendMulticastMessage(const Endpoint::Ptr& sender,
        if (!message.GetMethod(&method))
                BOOST_THROW_EXCEPTION(std::invalid_argument("Message is missing the 'method' property."));
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
-               Endpoint::Ptr recipient = dynamic_pointer_cast<Endpoint>(object);
-
+       BOOST_FOREACH(const Endpoint::Ptr& recipient, DynamicType::GetObjects<Endpoint>()) {
                /* don't forward messages back to the sender */
                if (sender == recipient)
                        continue;
@@ -348,12 +345,10 @@ void EndpointManager::SubscriptionTimerHandler(void)
 {
        Dictionary::Ptr subscriptions = boost::make_shared<Dictionary>();
 
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
-               Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
-
+       BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
                /* don't copy subscriptions from non-local endpoints or the identity endpoint */
-               if (!endpoint->IsLocalEndpoint() || endpoint == m_Endpoint)
-                       continue;
+//             if (!endpoint->IsLocalEndpoint() || endpoint == m_Endpoint)
+//                     continue;
 
                Dictionary::Ptr endpointSubscriptions = endpoint->GetSubscriptions();
 
@@ -377,9 +372,7 @@ void EndpointManager::SubscriptionTimerHandler(void)
 
 void EndpointManager::ReconnectTimerHandler(void)
 {
-       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
-               Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
-
+       BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
                if (endpoint->IsConnected() || endpoint == m_Endpoint)
                        continue;