]> granicus.if.org Git - icinga2/commitdiff
Refactor ScriptFunctions.
authorGunnar Beutner <gunnar@beutner.name>
Mon, 25 Mar 2013 19:47:02 +0000 (19:47 +0000)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 25 Mar 2013 19:47:02 +0000 (19:47 +0000)
19 files changed:
components/compat/compatlog.cpp
components/compat/compatlog.h
lib/base/Makefile.am
lib/base/base.vcxproj
lib/base/scriptfunction.h
lib/base/scriptfunctionwrapper.cpp [new file with mode: 0644]
lib/base/scriptfunctionwrapper.h [new file with mode: 0644]
lib/icinga/api.cpp
lib/icinga/api.h
lib/icinga/host.cpp
lib/icinga/host.h
lib/icinga/nullchecktask.cpp
lib/icinga/nullchecktask.h
lib/icinga/pluginchecktask.cpp
lib/icinga/pluginchecktask.h
lib/icinga/pluginnotificationtask.cpp
lib/icinga/pluginnotificationtask.h
lib/icinga/timeperiod.cpp
lib/icinga/timeperiod.h

index 348775f0b13a3b1416dc5eaac60ff054e64d71a3..20df8965a306fbb15c96128b8108778ee559480d 100644 (file)
@@ -335,17 +335,8 @@ void CompatLog::RotationTimerHandler(void)
        ScheduleNextRotation();
 }
 
-Value CompatLog::ValidateRotationMethod(const std::vector<Value>& arguments)
+void CompatLog::ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs)
 {
-       if (arguments.size() < 1)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Location must be specified."));
-
-       if (arguments.size() < 2)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Attribute dictionary must be specified."));
-
-       String location = arguments[0];
-       Dictionary::Ptr attrs = arguments[1];
-
        Value rotation_method = attrs->Get("rotation_method");
 
        if (!rotation_method.IsEmpty() && rotation_method != "HOURLY" && rotation_method != "DAILY" &&
@@ -353,6 +344,4 @@ Value CompatLog::ValidateRotationMethod(const std::vector<Value>& arguments)
                ConfigCompilerContext::GetContext()->AddError(false, "Validation failed for " +
                    location + ": Rotation method '" + rotation_method + "' is invalid.");
        }
-
-       return Empty;
 }
index 31a1a667c7e1a7549c6b21bb5af2854a2616eece..d07a17850f08a6b5aa2b3d2c4f77f7a0614a27e2 100644 (file)
@@ -46,7 +46,7 @@ public:
        String GetLogDir(void) const;
        String GetRotationMethod(void) const;
 
-       static Value ValidateRotationMethod(const std::vector<Value>& arguments);
+       static void ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs);
 
 protected:
        virtual void OnAttributeChanged(const String& name);
index f48abbee14f27ead45264863b0749b42c8a6c822..991b177b87d0658dc6d7934ac3ab1659b8a99dd3 100644 (file)
@@ -51,6 +51,8 @@ libbase_la_SOURCES =  \
        script.h \
        scriptfunction.cpp \
        scriptfunction.h \
+       scriptfunctionwrapper.cpp \
+       scriptfunctionwrapper.h \
        scriptinterpreter.cpp \
        scriptinterpreter.h \
        scriptlanguage.cpp \
index 7d5882544ea600e86cca75eb1b916e5ce97a928c..121e3987d606a89a0e877ffb349a106b2441da76 100644 (file)
@@ -40,6 +40,7 @@
     <ClCompile Include="qstring.cpp" />
     <ClCompile Include="ringbuffer.cpp" />
     <ClCompile Include="scriptfunction.cpp" />
+    <ClCompile Include="scriptfunctionwrapper.cpp" />
     <ClCompile Include="socket.cpp" />
     <ClCompile Include="stacktrace.cpp" />
     <ClCompile Include="stdiostream.cpp" />
@@ -75,6 +76,7 @@
     <ClInclude Include="netstring.h" />
     <ClInclude Include="qstring.h" />
     <ClInclude Include="scriptfunction.h" />
+    <ClInclude Include="scriptfunctionwrapper.h" />
     <ClInclude Include="logger.h" />
     <ClInclude Include="exception.h" />
     <ClInclude Include="i2-base.h" />
index 669fbeee0fd04713e97161bd7e3fd35137846e54..3ad5184b67196ffb62d7aa1f1931da1ff26ea2e6 100644 (file)
 #include "base/i2-base.h"
 #include "base/registry.h"
 #include "base/value.h"
+#include "base/scriptfunctionwrapper.h"
 #include <vector>
 #include <boost/function.hpp>
 
 namespace icinga
 {
 
-class ScriptTask;
-
 /**
  * A script function that can be used to execute a script task.
  *
@@ -72,7 +71,7 @@ public:
 };
 
 #define REGISTER_SCRIPTFUNCTION(name, callback) \
-       I2_EXPORT icinga::RegisterFunctionHelper g_RegisterSF_ ## name(#name, callback)
+       I2_EXPORT icinga::RegisterFunctionHelper g_RegisterSF_ ## name(#name, WrapScriptFunction(callback))
 
 }
 
diff --git a/lib/base/scriptfunctionwrapper.cpp b/lib/base/scriptfunctionwrapper.cpp
new file mode 100644 (file)
index 0000000..5a81bfa
--- /dev/null
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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/scriptfunctionwrapper.h"
+
+using namespace icinga;
+
+Value icinga::ScriptFunctionWrapperVV(void (*function)(void), const std::vector<Value>& arguments)
+{
+       function();
+
+       return Empty;
+}
+
+boost::function<Value (const std::vector<Value>& arguments)> icinga::WrapScriptFunction(void (*function)(void))
+{
+       return boost::bind(&ScriptFunctionWrapperVV, function, _1);
+}
+
+boost::function<Value (const std::vector<Value>& arguments)> icinga::WrapScriptFunction(Value (*function)(const std::vector<Value>&))
+{
+       return boost::bind(function, _1);
+}
diff --git a/lib/base/scriptfunctionwrapper.h b/lib/base/scriptfunctionwrapper.h
new file mode 100644 (file)
index 0000000..48ff285
--- /dev/null
@@ -0,0 +1,192 @@
+/******************************************************************************
+ * 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 SCRIPTFUNCTIONWRAPPER_H
+#define SCRIPTFUNCTIONWRAPPER_H
+
+#include "base/i2-base.h"
+#include "base/value.h"
+#include <vector>
+#include <boost/function.hpp>
+#include <boost/bind.hpp>
+
+namespace icinga
+{
+
+Value ScriptFunctionWrapperVV(void (*function)(void), const std::vector<Value>& arguments);
+
+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)
+{
+       return function();
+}
+
+template<typename TR>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(TR (*function)(void))
+{
+       return boost::bind(&ScriptFunctionWrapperR<TR>, function, _1);
+}
+
+template<typename T0>
+Value ScriptFunctionWrapperV(void (*function)(T0), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       function(static_cast<T0>(arguments[0]));
+
+       return Empty;
+}
+
+template<typename T0>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(void (*function)(T0))
+{
+       return boost::bind(&ScriptFunctionWrapperV<T0>, function, _1);
+}
+
+template<typename TR, typename T0>
+Value ScriptFunctionWrapperR(TR (*function)(T0), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 1)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       return function(static_cast<T0>(arguments[0]));
+}
+
+template<typename TR, typename T0>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(TR (*function)(T0))
+{
+       return boost::bind(&ScriptFunctionWrapperR<TR, T0>, function, _1);
+}
+
+template<typename T0, typename T1>
+Value ScriptFunctionWrapperV(void (*function)(T0, T1), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 2)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]));
+
+       return Empty;
+}
+
+template<typename T0, typename T1>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(void (*function)(T0, T1))
+{
+       return boost::bind(&ScriptFunctionWrapperV<T0, T1>, function, _1);
+}
+
+template<typename TR, typename T0, typename T1>
+Value ScriptFunctionWrapperR(TR (*function)(T0, T1), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 2)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       return function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]));
+}
+
+template<typename TR, typename T0, typename T1>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(TR (*function)(T0, T1))
+{
+       return boost::bind(&ScriptFunctionWrapperR<TR, T0, T1>, function, _1);
+}
+
+template<typename T0, typename T1, typename T2>
+Value ScriptFunctionWrapperV(void (*function)(T0, T1, T2), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 3)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]),
+           static_cast<T2>(arguments[2]));
+
+       return Empty;
+}
+
+template<typename T0, typename T1, typename T2>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(void (*function)(T0, T1, T2))
+{
+       return boost::bind(&ScriptFunctionWrapperV<T0, T1, T2>, function, _1);
+}
+
+template<typename TR, typename T0, typename T1, typename T2>
+Value ScriptFunctionWrapperR(TR (*function)(T0, T1, T2), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 3)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       return function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]),
+           static_cast<T2>(arguments[2]));
+}
+
+template<typename TR, typename T0, typename T1, typename T2>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(TR (*function)(T0, T1, T2))
+{
+       return boost::bind(&ScriptFunctionWrapperR<TR, T0, T1, T2>, function, _1);
+}
+
+template<typename T0, typename T1, typename T2, typename T3>
+Value ScriptFunctionWrapperV(void (*function)(T0, T1, T2, T3), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 4)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]),
+           static_cast<T2>(arguments[2]),
+           static_cast<T3>(arguments[3]));
+
+       return Empty;
+}
+
+template<typename T0, typename T1, typename T2, typename T3>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(void (*function)(T0, T1, T2, T3))
+{
+       return boost::bind(&ScriptFunctionWrapperV<T0, T1, T2, T3>, function, _1);
+}
+
+template<typename TR, typename T0, typename T1, typename T2, typename T3>
+Value ScriptFunctionWrapperR(TR (*function)(T0, T1, T2, T3), const std::vector<Value>& arguments)
+{
+       if (arguments.size() < 4)
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function."));
+
+       return function(static_cast<T0>(arguments[0]),
+           static_cast<T1>(arguments[1]),
+           static_cast<T2>(arguments[2]),
+           static_cast<T3>(arguments[3]));
+}
+
+template<typename TR, typename T0, typename T1, typename T2, typename T3>
+boost::function<Value (const std::vector<Value>& arguments)> WrapScriptFunction(TR (*function)(T0, T1, T2, T3))
+{
+       return boost::bind(&ScriptFunctionWrapperR<TR, T0, T1, T2, T3>, function, _1);
+}
+
+boost::function<Value (const std::vector<Value>& arguments)> I2_BASE_API WrapScriptFunction(Value (*function)(const std::vector<Value>&));
+
+}
+
+#endif /* SCRIPTFUNCTION_H */
index 63a3886d598c79325d56ffd4214975cdc8701b35..62dcd1834cf34a5a8701523101451f1733079d09 100644 (file)
@@ -25,13 +25,8 @@ using namespace icinga;
 
 REGISTER_SCRIPTFUNCTION(GetAnswerToEverything, &API::GetAnswerToEverything);
 
-Value API::GetAnswerToEverything(const std::vector<Value>& arguments)
+int API::GetAnswerToEverything(const String& text)
 {
-       if (arguments.size() < 1)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Text argument required."));
-
-       String text = arguments[0];
-
        Log(LogInformation, "icinga", "Hello from the Icinga 2 API: " + text);
 
        return 42;
index b91c38c403c58093d068902fc9fd45864e39f09b..777da2240072414f8b19117bbbe80424d5a7e3d3 100644 (file)
@@ -35,7 +35,7 @@ namespace icinga
 class I2_ICINGA_API API
 {
 public:
-       static Value GetAnswerToEverything(const std::vector<Value>& arguments);
+       static int GetAnswerToEverything(const String& text);
 
 private:
        API(void);
index 6f14e3aa081761a469debf4f60b687f0e04b6110..e694146c747d54d26710e493cdbe425ecddeca3a 100644 (file)
@@ -352,16 +352,8 @@ void Host::RefreshServicesCache(void)
        l_ServicesCache.swap(newServicesCache);
 }
 
-Value Host::ValidateServiceDictionary(const std::vector<Value>& arguments)
+Value Host::ValidateServiceDictionary(const String& location, const Dictionary::Ptr& attrs)
 {
-       if (arguments.size() < 1)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Location must be specified."));
-
-       if (arguments.size() < 2)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Attribute dictionary must be specified."));
-
-       String location = arguments[0];
-       Dictionary::Ptr attrs = arguments[1];
        ObjectLock olock(attrs);
 
        String key;
index 4dd8f407546dd19fcd33261650c634479baaebba..5ca9931bc7bfc7770d0935a134f0dc7845802ddb 100644 (file)
@@ -103,7 +103,7 @@ public:
        std::set<shared_ptr<Service> > GetServices(void) const;
        static void InvalidateServicesCache(void);
 
-       static Value ValidateServiceDictionary(const std::vector<icinga::Value>& arguments);
+       static Value ValidateServiceDictionary(const String& location, const Dictionary::Ptr& attrs);
 
        static HostState CalculateState(ServiceState state, bool reachable);
 
index c79c7bedbffb4ef2b06f53cd0f28866d7bc5fc4a..e8849194af2d5e09d435781b35fbfbc8ed67e525 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "icinga/nullchecktask.h"
 #include "icinga/service.h"
-#include "base/dictionary.h"
 #include "base/scriptfunction.h"
 #include <boost/smart_ptr/make_shared.hpp>
 
@@ -27,11 +26,8 @@ using namespace icinga;
 
 REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc);
 
-Value NullCheckTask::ScriptFunc(const std::vector<Value>& arguments)
+Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&)
 {
-       if (arguments.size() < 1)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Service must be specified."));
-
        Dictionary::Ptr cr = boost::make_shared<Dictionary>();
        cr->Set("state", StateUnknown);
 
index 4a8eeb33d4f73fd081910fb57ac9465e7dc30f62..56bb6104ba7b76227b4ad658fcac5befc0c9fdf4 100644 (file)
@@ -21,7 +21,8 @@
 #define NULLCHECKTASK_H
 
 #include "icinga/i2-icinga.h"
-#include "base/value.h"
+#include "icinga/service.h"
+#include "base/dictionary.h"
 
 namespace icinga
 {
@@ -34,7 +35,7 @@ namespace icinga
 class I2_ICINGA_API NullCheckTask
 {
 public:
-       static Value ScriptFunc(const std::vector<Value>& arguments);
+       static Dictionary::Ptr ScriptFunc(const Service::Ptr& service);
 
 private:
        NullCheckTask(void);
index 52e00ef8e97af4ef26ebcc18327b336010038021..39b71922e6b670df67f11b9dd8cac2cf48dc587e 100644 (file)
@@ -24,6 +24,7 @@
 #include "base/logger_fwd.h"
 #include "base/scriptfunction.h"
 #include "base/utility.h"
+#include "base/process.h"
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/split.hpp>
 #include <boost/smart_ptr/make_shared.hpp>
@@ -33,13 +34,8 @@ using namespace icinga;
 
 REGISTER_SCRIPTFUNCTION(PluginCheck,  &PluginCheckTask::ScriptFunc);
 
-Value PluginCheckTask::ScriptFunc(const std::vector<Value>& arguments)
+Value PluginCheckTask::ScriptFunc(const Service::Ptr& service)
 {
-       if (arguments.size() < 1)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Service must be specified."));
-
-       Service::Ptr service = arguments[0];
-
        Value raw_command = service->GetCheckCommand();
 
        std::vector<MacroResolver::Ptr> resolvers;
index acf1bdd00edb20a2f77fb6c9f2b8b674c162f85b..8b312a099c168911574fe805ccd9572f888e5cff 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "icinga/i2-icinga.h"
 #include "icinga/service.h"
-#include "base/process.h"
 
 namespace icinga
 {
@@ -35,7 +34,7 @@ namespace icinga
 class I2_ICINGA_API PluginCheckTask
 {
 public:
-       static Value ScriptFunc(const std::vector<Value>& arguments);
+       static Value ScriptFunc(const Service::Ptr& service);
 
        static ServiceState ExitStatusToState(int exitStatus);
        static Dictionary::Ptr ParseCheckOutput(const String& output);
index 0ea2ec9d1e11625f17b90c79dbe8a2013dd04998..fedddabd4e309f9985cf210a76e01a29cc81ae09 100644 (file)
 #include "base/logger_fwd.h"
 #include "base/utility.h"
 #include "base/convert.h"
+#include "base/process.h"
 #include <boost/smart_ptr/make_shared.hpp>
 #include <boost/foreach.hpp>
 
 using namespace icinga;
 
-REGISTER_SCRIPTFUNCTION(PluginNotification,  &PluginNotificationTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION(PluginNotification, &PluginNotificationTask::ScriptFunc);
 
-Value PluginNotificationTask::ScriptFunc(const std::vector<Value>& arguments)
+void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, const User::Ptr& user, const Dictionary::Ptr& cr, int itype)
 {
-       if (arguments.size() < 1)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Notification target must be specified."));
-
-       if (arguments.size() < 2)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: User must be specified."));
-
-       if (arguments.size() < 3)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: CheckResult must be specified."));
-
-       if (arguments.size() < 4)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Notification type must be specified."));
-
-       Notification::Ptr notification = arguments[0];
-       User::Ptr user = arguments[1];
-       Dictionary::Ptr cr = arguments[2];
-       NotificationType type = static_cast<NotificationType>(static_cast<int>(arguments[3]));
+       NotificationType type = static_cast<NotificationType>(itype);
 
        Service::Ptr service = notification->GetService();
 
@@ -97,6 +83,4 @@ Value PluginNotificationTask::ScriptFunc(const std::vector<Value>& arguments)
                       << pr.ExitStatus << ", output: " << pr.Output;
                Log(LogWarning, "icinga", msgbuf.str());
        }
-
-       return Empty;
 }
index f7cef49d52febb6e2260f5253b2154f93bba15eb..5dcf61c764eaf0be4f313249946b049fcd6c135c 100644 (file)
@@ -21,7 +21,7 @@
 #define PLUGINNOTIFICATIONTASK_H
 
 #include "icinga/i2-icinga.h"
-#include "base/process.h"
+#include "icinga/notification.h"
 
 namespace icinga
 {
@@ -34,7 +34,8 @@ namespace icinga
 class I2_ICINGA_API PluginNotificationTask
 {
 public:
-       static Value ScriptFunc(const std::vector<Value>& arguments);
+       static void ScriptFunc(const Notification::Ptr& notification,
+           const User::Ptr& user, const Dictionary::Ptr& cr, int itype);
 
 private:
        PluginNotificationTask(void);
index 28308d40d918344001dce11f269dfade91d7f6d3..5a67322a45d046cf9e461b706634980d5ce08af9 100644 (file)
@@ -217,9 +217,11 @@ void TimePeriod::UpdateRegion(double begin, double end)
                ObjectLock olock(this);
                RemoveSegment(begin, end);
 
-               ObjectLock dlock(segments);
-               BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
-                       AddSegment(segment);
+               if (segments) {
+                       ObjectLock dlock(segments);
+                       BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
+                               AddSegment(segment);
+                       }
                }
        }
 }
@@ -291,28 +293,14 @@ void TimePeriod::UpdateTimerHandler(void)
        }
 }
 
-Value TimePeriod::EmptyTimePeriodUpdate(const std::vector<Value>& arguments)
+Array::Ptr TimePeriod::EmptyTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end)
 {
-       if (arguments.size() < 3)
-               BOOST_THROW_EXCEPTION(std::runtime_error("Expected 3 arguments."));
-
-//     TimePeriod::Ptr tp = arguments[0];
-//     double begin = arguments[1];
-//     double end = arguments[2];
-
        Array::Ptr segments = boost::make_shared<Array>();
        return segments;
 }
 
-Value TimePeriod::EvenMinutesTimePeriodUpdate(const std::vector<Value>& arguments)
+Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end)
 {
-       if (arguments.size() < 3)
-               BOOST_THROW_EXCEPTION(std::runtime_error("Expected 3 arguments."));
-
-       TimePeriod::Ptr tp = arguments[0];
-       double begin = arguments[1];
-       double end = arguments[2];
-
        Array::Ptr segments = boost::make_shared<Array>();
 
        for (long t = begin / 60 - 1; t * 60 < end; t++) {
index 69304204780f06600083ffb1c9c5c8e4b2166313..c9c29094e1e21850062c21d8bd227582defd6bb0 100644 (file)
@@ -49,8 +49,8 @@ public:
        bool IsInside(double ts) const;
        double FindNextTransition(double begin);
 
-       static Value EmptyTimePeriodUpdate(const std::vector<Value>& arguments);
-       static Value EvenMinutesTimePeriodUpdate(const std::vector<Value>& arguments);
+       static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end);
+       static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end);
 
 private:
        Attribute<double> m_ValidBegin;