Changeset 76540c3 in nscp
- Timestamp:
- 02/12/12 18:16:53 (16 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 2906cda
- Parents:
- 0f7b655
- Files:
-
- 2 added
- 11 edited
-
changelog (modified) (1 diff)
-
include/nscapi/settings_object.hpp (added)
-
include/nscapi/targets.hpp (modified) (9 diffs)
-
include/settings/client/settings_client.cpp (modified) (1 diff)
-
include/settings/client/settings_client.hpp (modified) (11 diffs)
-
modules/PythonScript/PythonScript.cpp (modified) (1 diff)
-
modules/Scheduler/Scheduler.cpp (modified) (7 diffs)
-
modules/Scheduler/Scheduler.h (modified) (2 diffs)
-
modules/Scheduler/schedules.hpp (added)
-
modules/Scheduler/simple_scheduler.cpp (modified) (4 diffs)
-
modules/Scheduler/simple_scheduler.hpp (modified) (6 diffs)
-
version.hpp (modified) (1 diff)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r0f7b655 r76540c3 5 5 * Fixa dependonservice LanManWorkStation (old win) 6 6 * Fix RtlStringFromGUID problem on NT4 7 8 2012-02-12 MickeM 9 * Added support for specifying targets on schedules: 10 [/settings/scheduler/schedules/foo] 11 target = foo-host 12 Will re-target the NSCA (or whatever you use) towards a given target. 13 * Fixed is schedule manager uses new standard object reader 14 * Fixed some issues with reading schedule 7 15 8 16 2012-02-05 MickeM -
include/nscapi/targets.hpp
re396b2f r76540c3 10 10 #include <settings/client/settings_client.hpp> 11 11 #include <nscapi/settings_proxy.hpp> 12 #include <nscapi/settings_object.hpp> 12 13 #include <nscapi/functions.hpp> 13 14 … … 15 16 16 17 namespace nscapi { 17 18 namespace settings_object_helper {19 class default_object_type {20 std::wstring path;21 std::wstring alias;22 std::wstring value;23 std::wstring parent;24 };25 26 template<class object_type>27 class default_object_reader {28 static void read_target(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) {}29 static void apply_parent(object_type &object, object_type &parent) {}30 static void post_process_object(object_type &object) {}31 static void init_default(object_type &object) {}32 };33 34 35 template<class object_type = default_object_type, class object_reader = default_object_reader<default_object_type> >36 struct target_handler : boost::noncopyable {37 typedef boost::optional<object_type> optional_object;38 typedef optional_object optarget;39 typedef object_type target;40 typedef std::map<std::wstring, object_type> object_list_type;41 typedef target_handler<object_type, object_reader> my_type;42 43 object_list_type object_list;44 object_list_type template_list;45 46 void add_missing(boost::shared_ptr<nscapi::settings_proxy> proxy, std::wstring path, std::wstring alias, std::wstring value, bool is_template = false) {47 if (has_object(alias))48 return;49 add(proxy, path, alias, value, is_template);50 }51 52 object_type add(boost::shared_ptr<nscapi::settings_proxy> proxy, std::wstring path, std::wstring alias, std::wstring value, bool is_template = false) {53 object_type object;54 object.alias = alias;55 object.value = value;56 object.path = path + _T("/") + alias;57 object.parent = _T("default");58 59 object_reader::read_target(proxy, object);60 61 if (!object.parent.empty() && object.parent != alias & object.parent != object.alias) {62 object_type parent;63 optional_object tmp = find_object(object.parent);64 if (!tmp) {65 parent = add(proxy, path, object.parent, _T(""));66 add_template(parent);67 } else {68 parent = *tmp;69 }70 object_reader::apply_parent(object, parent);71 }72 if (is_template)73 add_template(object);74 else75 add_object(object);76 return object;77 }78 79 void rebuild(boost::shared_ptr<nscapi::settings_proxy> proxy) {80 std::list<object_type> tmp;81 BOOST_FOREACH(object_list_type::value_type t, object_list) {82 tmp.push_back(t.second);83 }84 object_list.clear();85 BOOST_FOREACH(const &object_item o, tmp) {86 std::wstring::size_type pos = o.path.find_last_of(_T("/"));87 if (pos == std::wstring::npos)88 continue;89 add(proxy, o.path.substr(0, pos-1), o.path.substr(pos), o.host);90 }91 }92 93 94 optional_object find_object(std::wstring alias) {95 object_list_type::const_iterator cit = object_list.find(alias);96 if (cit != object_list.end())97 return optional_object(cit->second);98 cit = template_list.find(alias);99 if (cit != template_list.end())100 return optional_object(cit->second);101 return optional_object();102 }103 104 bool has_object(std::wstring alias) {105 object_list_type::const_iterator cit = object_list.find(alias);106 if (cit != object_list.end())107 return true;108 cit = template_list.find(alias);109 if (cit != template_list.end())110 return true;111 return false;112 }113 114 115 std::wstring to_wstring() {116 std::wstringstream ss;117 ss << _T("Objects: ");118 BOOST_FOREACH(object_list_type::value_type t, object_list) {119 ss << _T(", ") << t.first << _T(" = {") << t.second.to_wstring() + _T("} ");120 }121 ss << _T("Templates: ");122 BOOST_FOREACH(object_list_type::value_type t, template_list) {123 ss << _T(", ") << t.first << _T(" = {") << t.second.to_wstring() + _T("} ");124 }125 return ss.str();126 }127 128 void add_object(object_type object) {129 object_reader::post_process_object(object);130 object_list_type::iterator cit = template_list.find(object.alias);131 if (cit != template_list.end())132 template_list.erase(cit);133 object_list[object.alias] = object;134 }135 void add_template(object_type object) {136 object_list_type::const_iterator cit = object_list.find(object.alias);137 if (cit != object_list.end())138 return;139 object_reader::post_process_object(object);140 template_list[object.alias] = object;141 }142 };143 }144 145 146 18 namespace targets { 147 19 struct target_object { … … 151 23 std::wstring value; 152 24 std::wstring parent; 25 bool is_template; 153 26 154 27 net::wurl address; … … 161 34 ss << _T(", address: ") << get_address(); 162 35 ss << _T(", parent: ") << parent; 36 ss << _T(", is_template: ") << is_template; 163 37 BOOST_FOREACH(options_type::value_type o, options) { 164 38 ss << _T(", option[") << o.first << _T("]: ") << o.second; … … 177 51 } 178 52 void set_port(int value) { 179 address. host = strEx::itos(value);53 address.port = value; 180 54 } 181 55 bool has_option(std::wstring key) const { … … 218 92 struct target_object_reader { 219 93 typedef target_object object_type; 220 static void read_ target(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object);94 static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object); 221 95 static void apply_parent(object_type &object, object_type &parent); 222 96 }; … … 236 110 } 237 111 238 static void read_ target(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) {112 static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { 239 113 object.address = net::parse(object.value, 0); 240 114 if (object.alias == _T("default")) … … 267 141 _T("TARGET PARENT"), _T("The parent the target inherits from")) 268 142 143 (_T("is template"), nscapi::settings_helper::bool_key(&object.is_template, false), 144 _T("IS TEMPLATE"), _T("Declare this object as a template (this means it will not be avalible as a separate object)")) 145 269 146 ; 270 147 custom_reader::add_custom_keys(settings, proxy, object); … … 290 167 }; 291 168 template<class custom_reader> 292 struct handler : public nscapi::settings_object_helper::target_handler<target_object, split_object_reader<custom_reader > > {}; 293 294 /* 295 template<class custom_reader> 296 */ 297 //typedef nscapi::settings_object_helper::target_handler<target_object, split_object_reader<dummy_custom_reader > > handler; 298 169 struct handler : public nscapi::settings_objects::object_handler<target_object, split_object_reader<custom_reader > > {}; 299 170 } 300 171 } -
include/settings/client/settings_client.cpp
r8013c0c r76540c3 12 12 */ 13 13 boost::shared_ptr<wstring_key_type> wstring_key(std::wstring *val, std::wstring def) { 14 boost::shared_ptr<wstring_key_type> r(new wstring_key_type(val, def)); 14 boost::shared_ptr<wstring_key_type> r(new wstring_key_type(val, def, true)); 15 return r; 16 } 17 boost::shared_ptr<wstring_key_type> wstring_key(std::wstring *val) { 18 boost::shared_ptr<wstring_key_type> r(new wstring_key_type(val, _T(""), false)); 15 19 return r; 16 20 } 17 21 boost::shared_ptr<wpath_key_type> wpath_key(std::wstring *val, std::wstring def) { 18 boost::shared_ptr<wpath_key_type> r(new wpath_key_type(val, def)); 22 boost::shared_ptr<wpath_key_type> r(new wpath_key_type(val, def, true)); 23 return r; 24 } 25 boost::shared_ptr<wpath_key_type> wpath_key(std::wstring *val) { 26 boost::shared_ptr<wpath_key_type> r(new wpath_key_type(val, _T(""), false)); 19 27 return r; 20 28 } 21 29 boost::shared_ptr<string_key_type> string_key(std::string *val, std::string def) { 22 boost::shared_ptr<string_key_type> r(new string_key_type(val, def)); 30 boost::shared_ptr<string_key_type> r(new string_key_type(val, def, true)); 31 return r; 32 } 33 boost::shared_ptr<string_key_type> string_key(std::string *val) { 34 boost::shared_ptr<string_key_type> r(new string_key_type(val, "", false)); 23 35 return r; 24 36 } 25 37 boost::shared_ptr<int_key_type> int_key(int *val, int def) { 26 boost::shared_ptr<int_key_type> r(new int_key_type(val, def)); 38 boost::shared_ptr<int_key_type> r(new int_key_type(val, def, true)); 39 return r; 40 } 41 boost::shared_ptr<int_key_type> int_key(int *val) { 42 boost::shared_ptr<int_key_type> r(new int_key_type(val, 0, false)); 27 43 return r; 28 44 } 29 45 boost::shared_ptr<uint_key_type> uint_key(unsigned int *val, unsigned int def) { 30 boost::shared_ptr<uint_key_type> r(new uint_key_type(val, def ));46 boost::shared_ptr<uint_key_type> r(new uint_key_type(val, def, true)); 31 47 return r; 32 48 } 33 49 boost::shared_ptr<bool_key_type> bool_key(bool *val, bool def) { 34 boost::shared_ptr<bool_key_type> r(new bool_key_type(val, def)); 50 boost::shared_ptr<bool_key_type> r(new bool_key_type(val, def, true)); 51 return r; 52 } 53 boost::shared_ptr<bool_key_type> bool_key(bool *val) { 54 boost::shared_ptr<bool_key_type> r(new bool_key_type(val, false, false)); 35 55 return r; 36 56 } -
include/settings/client/settings_client.hpp
re396b2f r76540c3 32 32 class typed_key : public key_interface { 33 33 public: 34 typed_key(const T& v) : default_value_(boost::any(v)), default_value_as_text_(boost::lexical_cast<std::wstring>(v)) {} 34 typed_key(const T& v, bool has_default) : has_default_(has_default), default_value_(boost::any(v)), default_value_as_text_(boost::lexical_cast<std::wstring>(v)) {} 35 typed_key(bool has_default) : has_default_(has_default) {} 35 36 36 37 virtual typed_key* default_value(const T& v) { … … 45 46 virtual void update_target(T *value) const = 0; 46 47 protected: 48 bool has_default_; 47 49 boost::any default_value_; 48 50 std::wstring default_value_as_text_; … … 52 54 class typed_string_value : public typed_key<T> { 53 55 public: 54 typed_string_value(const T& v) : typed_key<T>(v) {} 56 typed_string_value(const T& v, bool has_default) : typed_key<T>(v, has_default) {} 57 //typed_string_value() : typed_key<T>() {} 55 58 virtual NSCAPI::settings_type get_type() const { 56 59 return NSCAPI::key_string; 57 60 } 58 61 virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const { 59 T value = boost::lexical_cast<T>(core_->get_string(path, key, typed_key<T>::default_value_as_text_)); 60 update_target(&value); 62 std::wstring dummy(_T("$$DUMMY_VALUE_DO_NOT_USE$$")); 63 if (typed_key<T>::has_default_) 64 dummy = typed_key<T>::default_value_as_text_; 65 std::wstring data = core_->get_string(path, key, dummy); 66 if (typed_key<T>::has_default_ || data != dummy) { 67 T value = boost::lexical_cast<T>(data); 68 update_target(&value); 69 } 61 70 } 62 71 virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const { 63 std::wstring default_value = core_->get_string(parent, key, typed_key<T>::default_value_as_text_); 64 T value = boost::lexical_cast<T>(core_->get_string(path, key, default_value)); 65 update_target(&value); 66 } 67 }; 68 template<class T> 69 class typed_string_value_no_default : public typed_key<T> { 70 public: 71 typed_string_value_no_default(const T& v) : typed_key<T>(v) {} 72 std::wstring dummy(_T("$$DUMMY_VALUE_DO_NOT_USE$$")); 73 if (typed_key<T>::has_default_) 74 dummy = typed_key<T>::default_value_as_text_; 75 std::wstring data = core_->get_string(parent, key, dummy); 76 if (typed_key<T>::has_default_ || data != dummy) 77 dummy = data; 78 data = core_->get_string(path, key, dummy); 79 if (typed_key<T>::has_default_ || data != dummy) { 80 T value = boost::lexical_cast<T>(data); 81 update_target(&value); 82 } 83 } 84 }; 85 template<class T> 86 class typed_path_value : public typed_key<T> { 87 public: 88 typed_path_value(const T& v, bool has_default) : typed_key<T>(v, has_default) {} 72 89 virtual NSCAPI::settings_type get_type() const { 73 90 return NSCAPI::key_string; 74 91 } 75 92 virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const { 76 std::wstring dummy = _T("$$DUMMY_VALUE_DO_NOT_USE$$"); 93 std::wstring dummy(_T("$$DUMMY_VALUE_DO_NOT_USE$$")); 94 if (typed_key<T>::has_default_) 95 dummy = typed_key<T>::default_value_as_text_; 77 96 std::wstring data = core_->get_string(path, key, dummy); 78 if ( data != dummy) {79 T value = boost::lexical_cast<T>( data);97 if (typed_key<T>::has_default_ || data != dummy) { 98 T value = boost::lexical_cast<T>(core_->expand_path(data)); 80 99 update_target(&value); 81 100 } 82 101 } 83 102 virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const { 84 std::wstring dummy = _T("$$DUMMY_VALUE_DO_NOT_USE$$"); 103 std::wstring dummy(_T("$$DUMMY_VALUE_DO_NOT_USE$$")); 104 if (typed_key<T>::has_default_) 105 dummy = typed_key<T>::default_value_as_text_; 85 106 std::wstring data = core_->get_string(parent, key, dummy); 86 if ( data != dummy)107 if (typed_key<T>::has_default_ || data != dummy) 87 108 dummy = data; 88 109 data = core_->get_string(path, key, dummy); 89 if ( data != dummy) {90 T value = boost::lexical_cast<T>( data);110 if (typed_key<T>::has_default_ || data != dummy) { 111 T value = boost::lexical_cast<T>(core_->expand_path(data)); 91 112 update_target(&value); 92 113 } 93 114 } 94 115 }; 95 template<class T>96 class typed_path_value : public typed_key<T> {97 public:98 typed_path_value(const T& v) : typed_key<T>(v) {}99 virtual NSCAPI::settings_type get_type() const {100 return NSCAPI::key_string;101 }102 virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const {103 std::wstring val = core_->get_string(path, key, typed_key<T>::default_value_as_text_);104 T value = boost::lexical_cast<T>(core_->expand_path(val));105 update_target(&value);106 }107 virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const {108 std::wstring def_val = core_->get_string(parent, key, typed_key<T>::default_value_as_text_);109 std::wstring val = core_->get_string(path, key, def_val);110 T value = boost::lexical_cast<T>(core_->expand_path(val));111 update_target(&value);112 }113 };114 116 115 117 template<class T> 116 118 class typed_int_value : public typed_key<T> { 117 119 public: 118 typed_int_value(const T& v ) : typed_key<T>(v), default_value_as_int_(boost::lexical_cast<int>(v)) {}120 typed_int_value(const T& v, bool has_default) : typed_key<T>(v, has_default), default_value_as_int_(boost::lexical_cast<int>(v)) {} 119 121 typed_key<T>* default_value(const T& v) { 120 122 typed_key<T>::default_value(v); … … 126 128 } 127 129 virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const { 128 T value = static_cast<T>(core_->get_int(path, key, default_value_as_int_));129 update_target(&value);130 }131 virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const {132 T default_value = static_cast<T>(core_->get_int(parent, key, default_value_as_int_));133 T value = static_cast<T>(core_->get_int(path, key, default_value));134 update_target(&value);135 }136 protected:137 int default_value_as_int_;138 };139 template<class T>140 class typed_int_value_no_default : public typed_key<T> {141 public:142 typed_int_value_no_default(const T& v) : typed_key<T>(v), default_value_as_int_(0) {}143 typed_key<T>* default_value(const T& v) {144 typed_key<T>::default_value(v);145 default_value_as_int_ = boost::lexical_cast<int>(v);146 return this;147 }148 virtual NSCAPI::settings_type get_type() const {149 return NSCAPI::key_integer;150 }151 virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const {152 130 int dummy = -1; 131 if (typed_key<T>::has_default_) 132 dummy = default_value_as_int_; 153 133 int val = core_->get_int(path, key, dummy); 154 if ( val == dummy) {134 if (!typed_key<T>::has_default_ && val == dummy) { 155 135 dummy = -2; 156 136 val = core_->get_int(path, key, dummy); … … 162 142 } 163 143 virtual void notify(settings_impl_interface_ptr core_, std::wstring parent, std::wstring path, std::wstring key) const { 164 int dummy = -1; 165 int defval = core_->get_int(path, key, dummy); 166 if (defval == dummy) { 167 dummy = -2; 168 defval = core_->get_int(path, key, dummy); 169 } 170 if (defval != dummy) { 171 T value = static_cast<T>(core_->get_int(path, key, defval)); 144 if (typed_key<T>::has_default_) { 145 T default_value = static_cast<T>(core_->get_int(parent, key, default_value_as_int_)); 146 T value = static_cast<T>(core_->get_int(path, key, default_value)); 172 147 update_target(&value); 173 } 174 dummy = -1; 175 int val = core_->get_int(path, key, dummy); 176 if (val == dummy) { 177 dummy = -2; 178 val = core_->get_int(path, key, dummy); 179 if (val == dummy) 180 return; 181 } 182 T value = static_cast<T>(val); 183 update_target(&value); 148 } else { 149 int dummy = -1; 150 int defval = core_->get_int(path, key, dummy); 151 if (defval == dummy) { 152 dummy = -2; 153 defval = core_->get_int(path, key, dummy); 154 } 155 if (defval != dummy) { 156 T value = static_cast<T>(core_->get_int(path, key, defval)); 157 update_target(&value); 158 } 159 dummy = -1; 160 int val = core_->get_int(path, key, dummy); 161 if (val == dummy) { 162 dummy = -2; 163 val = core_->get_int(path, key, dummy); 164 if (val == dummy) 165 return; 166 } 167 T value = static_cast<T>(val); 168 update_target(&value); 169 } 184 170 } 185 171 protected: … … 189 175 class typed_bool_value : public typed_int_value<T> { 190 176 public: 191 typed_bool_value(const T& v ) : typed_int_value<T>(v) {}177 typed_bool_value(const T& v, bool has_default) : typed_int_value<T>(v, has_default) {} 192 178 virtual NSCAPI::settings_type get_type() const { 193 179 return NSCAPI::key_bool; 194 180 } 181 // TODO: FIXME: Add support for has_default 195 182 virtual void notify(settings_impl_interface_ptr core_, std::wstring path, std::wstring key) const { 196 183 T value = static_cast<T>(core_->get_bool(path, key, typed_int_value<T>::default_value_as_int_==1)); … … 207 194 class typed_key_value : public TBase { 208 195 public: 209 typed_key_value(T* store_to, const T& v ) : TBase(v), store_to_(store_to) {}196 typed_key_value(T* store_to, const T& v, bool has_default) : TBase(v, has_default), store_to_(store_to) {} 210 197 211 198 virtual void update_target(T *value) const { … … 220 207 class typed_key_entry_in_vector : public TBase { 221 208 public: 222 typed_key_entry_in_vector(V* store_to, typename V::key_type key, const T& v ) : TBase(v), store_to_(store_to), key_(key) {}209 typed_key_entry_in_vector(V* store_to, typename V::key_type key, const T& v, bool has_default) : TBase(v, has_default), store_to_(store_to), key_(key) {} 223 210 224 211 virtual void update_target(T *value) const { … … 234 221 class typed_key_fun : public TBase { 235 222 public: 236 typed_key_fun(boost::function<void (T)> callback, const T& v ): TBase(v), callback_(callback) {}223 typed_key_fun(boost::function<void (T)> callback, const T& v, bool has_default): TBase(v, has_default), callback_(callback) {} 237 224 238 225 virtual void update_target(T *value) const { … … 245 232 template<typename T> 246 233 boost::shared_ptr<typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> > > wstring_vector_key(T *val, typename T::key_type key, std::wstring def) { 247 boost::shared_ptr<typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> > > r(new typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> >(val, key, def ));234 boost::shared_ptr<typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> > > r(new typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> >(val, key, def, true)); 248 235 return r; 249 236 } … … 260 247 typed_key_entry_in_vector<std::wstring, T, typed_string_value<std::wstring> >* wstring_vector_key(T *val, typename T::key_type key, std::wstring def); 261 248 */ 262 boost::shared_ptr<wstring_key_type> wstring_key(std::wstring *val, std::wstring def = _T("")); 263 boost::shared_ptr<string_key_type> string_key(std::string *val, std::string def = ""); 249 boost::shared_ptr<wstring_key_type> wstring_key(std::wstring *val, std::wstring def); 250 boost::shared_ptr<wstring_key_type> wstring_key(std::wstring *val); 251 boost::shared_ptr<string_key_type> string_key(std::string *val, std::string def); 252 boost::shared_ptr<string_key_type> string_key(std::string *val); 264 253 boost::shared_ptr<int_key_type> int_key(int *val, int def = 0); 265 boost::shared_ptr<uint_key_type> uint_key(unsigned int *val, unsigned int def = 0); 266 boost::shared_ptr<bool_key_type> bool_key(bool *val, bool def = false); 267 boost::shared_ptr<wpath_key_type> wpath_key(std::wstring *val, std::wstring def = _T("")); 254 boost::shared_ptr<uint_key_type> uint_key(unsigned int *val, unsigned int def); 255 boost::shared_ptr<bool_key_type> bool_key(bool *val, bool def); 256 boost::shared_ptr<bool_key_type> bool_key(bool *val); 257 boost::shared_ptr<wpath_key_type> wpath_key(std::wstring *val, std::wstring def); 258 boost::shared_ptr<wpath_key_type> wpath_key(std::wstring *val); 268 259 269 260 template<class T> 270 261 boost::shared_ptr<typed_key_fun<T, typed_int_value<T> > > int_fun_key(boost::function<void (T)> fun, T def) { 271 boost::shared_ptr<typed_key_fun<T, typed_int_value<T> > > r(new typed_key_fun<T, typed_int_value<T> >(fun, def ));262 boost::shared_ptr<typed_key_fun<T, typed_int_value<T> > > r(new typed_key_fun<T, typed_int_value<T> >(fun, def, true)); 272 263 return r; 273 264 } 274 265 template<class T> 275 boost::shared_ptr<typed_key_fun<T, typed_int_value _no_default<T> > > int_fun_key(boost::function<void (T)> fun) {276 boost::shared_ptr<typed_key_fun<T, typed_int_value _no_default<T> > > r(new typed_key_fun<T, typed_int_value_no_default<T> >(fun, 0));266 boost::shared_ptr<typed_key_fun<T, typed_int_value<T> > > int_fun_key(boost::function<void (T)> fun) { 267 boost::shared_ptr<typed_key_fun<T, typed_int_value<T> > > r(new typed_key_fun<T, typed_int_value<T> >(fun, 0, false)); 277 268 return r; 278 269 } 279 270 template<class T> 280 271 boost::shared_ptr<typed_key_fun<T, typed_bool_value<T> > > bool_fun_key(boost::function<void (T)> fun, T def) { 281 boost::shared_ptr<typed_key_fun<T, typed_bool_value<T> > > r(new typed_key_fun<T, typed_bool_value<T> >(fun, def ));272 boost::shared_ptr<typed_key_fun<T, typed_bool_value<T> > > r(new typed_key_fun<T, typed_bool_value<T> >(fun, def, true)); 282 273 return r; 283 274 } 284 275 template<class T> 285 276 boost::shared_ptr<typed_key_fun<T, typed_string_value<T> > > string_fun_key(boost::function<void (T)> fun, T def) { 286 boost::shared_ptr<typed_key_fun<T, typed_string_value<T> > > r(new typed_key_fun<T, typed_string_value<T> >(fun, def ));277 boost::shared_ptr<typed_key_fun<T, typed_string_value<T> > > r(new typed_key_fun<T, typed_string_value<T> >(fun, def, true)); 287 278 return r; 288 279 } 289 280 template<class T> 290 boost::shared_ptr<typed_key_fun<T, typed_string_value _no_default<T> > > string_fun_key(boost::function<void (T)> fun) {291 boost::shared_ptr<typed_key_fun<T, typed_string_value _no_default<T> > > r(new typed_key_fun<T, typed_string_value_no_default<T> >(fun, T()));281 boost::shared_ptr<typed_key_fun<T, typed_string_value<T> > > string_fun_key(boost::function<void (T)> fun) { 282 boost::shared_ptr<typed_key_fun<T, typed_string_value<T> > > r(new typed_key_fun<T, typed_string_value<T> >(fun, T(), false)); 292 283 return r; 293 284 } -
modules/PythonScript/PythonScript.cpp
r441a022 r76540c3 211 211 //PyEval_ReleaseLock(); 212 212 213 PyThreadState *state; 214 state = PyEval_SaveThread(); 215 //PyThreadState *mainThreadState = PyThreadState_Get(); 216 //PyThreadState_Clear 217 //PyThreadState_(mainThreadState); 218 213 PyThreadState *state = PyEval_SaveThread(); 219 214 do_init = true; 220 215 } -
modules/Scheduler/Scheduler.cpp
re396b2f r76540c3 38 38 try { 39 39 40 typedef std::map<std::wstring,std::wstring> schedule_map;41 schedule_map schedules;42 40 sh::settings_registry settings(get_settings_proxy()); 43 41 settings.set_alias(alias, _T("scheduler")); 42 schedule_path = settings.alias().get_settings_path(_T("schedules")); 44 43 45 44 settings.alias().add_path_to_settings() … … 53 52 ; 54 53 55 scheduler::target def = read_schedule(settings.alias().get_settings_path(_T("default")), _T("Default schedule"));56 57 std::wstring sch_path = settings.alias().get_settings_path(_T("schedules"));58 59 54 settings.alias().add_path_to_settings() 60 (_T("schedules"), sh::fun_values_path(boost::bind(&Scheduler::add_schedule, this, sch_path, _1, _2, def)),55 (_T("schedules"), sh::fun_values_path(boost::bind(&Scheduler::add_schedule, this, _1, _2)), 61 56 _T("SCHEDULER SECTION"), _T("Section for the Scheduler module.")) 62 57 ; … … 64 59 settings.register_all(); 65 60 settings.notify(); 61 62 BOOST_FOREACH(const schedules::schedule_handler::object_list_type::value_type &o, schedules_.object_list) { 63 NSC_DEBUG_MSG(_T("Adding scheduled item: ") + o.second.to_wstring()); 64 scheduler_.add_task(o.second); 65 } 66 66 67 67 } catch (nscapi::nscapi_exception &e) { … … 94 94 } 95 95 96 scheduler::target Scheduler::read_schedule(std::wstring path, std::wstring schedule_name, scheduler::target *def) { 97 98 scheduler::target item; 99 std::wstring report, duration; 100 101 sh::settings_registry settings(get_settings_proxy()); 102 103 settings.path(path).add_path() 104 (_T("SCHEDULE DEFENITION"), _T("Schedule defenition for: ") + schedule_name) 105 ; 106 107 settings.path(path).add_key() 108 (_T("channel"), sh::wstring_key(&item.channel, def==NULL?_T("NSCA"):def->channel), 109 _T("SCHEDULE CHANNEL"), _T("Channel to send results on")) 110 111 (_T("command"), sh::wstring_key(&item.command, def==NULL?_T("check_ok"):def->command), 112 _T("SCHEDULE COMMAND"), _T("Command to execute")) 113 114 (_T("alias"), sh::wstring_key(&item.alias, def==NULL?_T(""):def->alias), 115 _T("SCHEDULE ALIAS"), _T("The alias (service name) to report to server")) 116 117 (_T("report"), sh::wstring_key(&report, def==NULL?_T("all"):nscapi::report::to_string(def->report)), 118 _T("REPORT MODE"), _T("What to report to the server (any of the following: all, critical, warning, unknown, ok)")) 119 120 (_T("target"), sh::wstring_key(&item.target_id, def==NULL?_T(""):def->target_id), 121 _T("TARGET"), _T("")) 122 123 // TODO: get the proper default value here! 124 (_T("interval"), sh::wstring_key(&duration, _T("5s")), 125 _T("SCHEDULE INTERAVAL"), _T("Time in seconds between each check")) 126 127 ; 128 129 settings.register_all(); 130 settings.notify(); 131 132 item.report = nscapi::report::parse(report); 133 item.duration = boost::posix_time::seconds(strEx::stoui_as_time_sec(duration, 1)); 134 return item; 135 } 136 void Scheduler::add_schedule(std::wstring path, std::wstring alias, std::wstring command, scheduler::target def) { 96 void Scheduler::add_schedule(std::wstring key, std::wstring arg) { 137 97 try { 138 def.alias = alias; 139 def.command = command; 140 scheduler::target item = read_schedule(path + _T("/") + alias, alias, &def); 141 strEx::parse_command(item.command, item.command, item.arguments); 142 NSC_DEBUG_MSG_STD(_T("Adding scheduled task: ") + alias); 143 scheduler_.add_task(item); 98 schedules_.add(get_settings_proxy(), schedule_path, key, arg, key == _T("default")); 99 } catch (const std::exception &e) { 100 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key + _T(", ") + utf8::to_unicode(e.what())); 144 101 } catch (...) { 145 NSC_LOG_ERROR_STD(_T("Failed to add schedule: ") + alias);102 NSC_LOG_ERROR_STD(_T("Failed to add target: ") + key); 146 103 } 147 104 } … … 157 114 } 158 115 #include <nscapi/functions.hpp> 159 void Scheduler::handle_schedule(schedule r::target item) {116 void Scheduler::handle_schedule(schedules::schedule_object item) { 160 117 try { 161 118 std::string response; 162 NSCAPI::nagiosReturn code = GET_CORE()->simple_query(item.command.c_str(), item.arguments, response);119 NSCAPI::nagiosReturn code = get_core()->simple_query(item.command.c_str(), item.arguments, response); 163 120 if (code == NSCAPI::returnIgnored) { 164 121 NSC_LOG_ERROR_STD(_T("Command was not found: ") + item.command.c_str()); … … 166 123 nscapi::functions::create_simple_submit_request(item.channel, item.command, NSCAPI::returnUNKNOWN, _T("Command was not found: ") + item.command, _T(""), response); 167 124 std::string result; 168 GET_CORE()->submit_message(item.channel, response, result);125 get_core()->submit_message(item.channel, response, result); 169 126 } else if (nscapi::report::matches(item.report, code)) { 170 127 // @todo: allow renaming of commands here item.alias, … … 172 129 nscapi::functions::make_submit_from_query(response, item.channel, item.alias, item.target_id); 173 130 std::string result; 174 GET_CORE()->submit_message(item.channel, response, result);131 get_core()->submit_message(item.channel, response, result); 175 132 } 176 133 } catch (nscapi::nscapi_exception &e) { -
modules/Scheduler/Scheduler.h
rf085f9b r76540c3 24 24 25 25 #include "simple_scheduler.hpp" 26 #include "schedules.hpp" 26 27 27 28 28 29 class Scheduler : public scheduler::schedule_handler, public nscapi::impl::simple_plugin { 29 30 private: 31 std::wstring schedule_path; 30 32 scheduler::simple_scheduler scheduler_; 33 schedules::schedule_handler schedules_; 31 34 32 35 33 36 public: 34 Scheduler() {} 37 Scheduler() { 38 scheduler_.set_handler(this); 39 } 35 40 virtual ~Scheduler() {} 36 41 // Module calls … … 40 45 41 46 42 void add_schedule(std::wstring path, std::wstring alias, std::wstring command, scheduler::target def);43 scheduler::target read_schedule(std::wstring path, std::wstring comment, scheduler::target *def = NULL);44 void handle_schedule(schedule r::target item);47 void add_schedule(std::wstring alias, std::wstring command); 48 //scheduler::target read_schedule(std::wstring path, std::wstring comment, scheduler::target *def = NULL); 49 void handle_schedule(schedules::schedule_object item); 45 50 void on_error(std::wstring error); 46 51 -
modules/Scheduler/simple_scheduler.cpp
r8013c0c r76540c3 5 5 #include <unicode_char.hpp> 6 6 7 #include <nscapi/macros.hpp> 8 7 9 using namespace nscp::helpers; 8 10 9 11 namespace scheduler { 10 12 11 int simple_scheduler::add_task( target item) {13 int simple_scheduler::add_task(schedules::schedule_object item) { 12 14 { 13 15 boost::mutex::scoped_lock l(mutex_); 14 item.id = ++ target_id_;16 item.id = ++schedule_id_; 15 17 targets_[item.id] = item; 16 18 } … … 23 25 targets_.erase(it); 24 26 } 25 boost::optional< target> simple_scheduler::get_task(int id) {27 boost::optional<schedules::schedule_object> simple_scheduler::get_task(int id) { 26 28 boost::mutex::scoped_lock l(mutex_); 27 29 target_list_type::iterator it = targets_.find(id); 28 30 if (it == targets_.end()) 29 return boost::optional< target>();30 return boost::optional< target>((*it).second);31 return boost::optional<schedules::schedule_object>(); 32 return boost::optional<schedules::schedule_object>((*it).second); 31 33 } 32 34 … … 110 112 111 113 boost::posix_time::ptime now_time = now(); 112 boost::optional< target> item = get_task((*instance).schedule_id);114 boost::optional<schedules::schedule_object> item = get_task((*instance).schedule_id); 113 115 if (item) { 114 116 try { … … 132 134 } 133 135 134 void simple_scheduler::reschedule(target item) { 135 reschedule_wnext(item, now() + boost::posix_time::seconds(rand()%item.duration.total_seconds())); 136 void simple_scheduler::reschedule(const schedules::schedule_object &item) { 137 if (item.duration.total_seconds() == 0) 138 log_error(_T("Not scheduling since duration is 0: ") + item.to_wstring()); 139 else 140 reschedule_wnext(item.id, now() + boost::posix_time::seconds(rand()%item.duration.total_seconds())); 136 141 } 137 void simple_scheduler::reschedule( targetitem, boost::posix_time::ptime now) {138 reschedule_wnext(item , now + item.duration);142 void simple_scheduler::reschedule(const schedules::schedule_object &item, boost::posix_time::ptime now) { 143 reschedule_wnext(item.id, now + item.duration); 139 144 } 140 void simple_scheduler::reschedule_wnext( target item, boost::posix_time::ptime next) {145 void simple_scheduler::reschedule_wnext(int id, boost::posix_time::ptime next) { 141 146 schedule_instance instance; 142 instance.schedule_id = i tem.id;147 instance.schedule_id = id; 143 148 instance.time = next; 144 149 if (!queue_.push(instance)) { -
modules/Scheduler/simple_scheduler.hpp
re396b2f r76540c3 14 14 #include <unicode_char.hpp> 15 15 16 #include "schedules.hpp" 17 16 18 namespace scheduler { 17 18 19 class task_not_found { 20 int id_; 21 public: 22 task_not_found(int id) : id_(id) {} 23 int get_id() {return id_; } 24 }; 19 /* 25 20 class target { 26 21 public: … … 69 64 } 70 65 }; 66 */ 71 67 class schedule_handler { 72 68 public: 73 virtual void handle_schedule( target item) = 0;69 virtual void handle_schedule(schedules::schedule_object item) = 0; 74 70 virtual void on_error(std::wstring error) = 0; 75 71 }; … … 126 122 class simple_scheduler : public boost::noncopyable { 127 123 private: 128 typedef std::map<int, target> target_list_type;124 typedef std::map<int,schedules::schedule_object> target_list_type; 129 125 typedef safe_schedule_queue<schedule_instance> schedule_queue_type; 130 126 target_list_type targets_; 131 unsigned int target_id_;127 unsigned int schedule_id_; 132 128 schedule_queue_type queue_; 133 129 unsigned int thread_count_; … … 146 142 public: 147 143 148 simple_scheduler() : target_id_(0), stop_requested_(false), running_(false), thread_count_(10), handler_(NULL), error_threshold_(5) {}144 simple_scheduler() : schedule_id_(0), stop_requested_(false), running_(false), thread_count_(10), handler_(NULL), error_threshold_(5) {} 149 145 ~simple_scheduler() {} 150 146 … … 157 153 } 158 154 159 int add_task( target item);155 int add_task(schedules::schedule_object item); 160 156 void remove_task(int id); 161 boost::optional< target> get_task(int id);157 boost::optional<schedules::schedule_object> get_task(int id); 162 158 163 159 void start(); … … 175 171 void watch_dog(int id); 176 172 177 void reschedule( targetitem);178 void reschedule( targetitem, boost::posix_time::ptime now);179 void reschedule_wnext( target item, boost::posix_time::ptime next);173 void reschedule(const schedules::schedule_object &item); 174 void reschedule(const schedules::schedule_object &item, boost::posix_time::ptime now); 175 void reschedule_wnext(int id, boost::posix_time::ptime next); 180 176 void start_thread(); 181 177 -
version.hpp
ra06e6af r76540c3 1 1 #ifndef VERSION_HPP 2 2 #define VERSION_HPP 3 #define PRODUCTVER 0,4,0,13 14 #define STRPRODUCTVER "0,4,0,13 1"5 #define STRPRODUCTDATE "2012-0 1-31"3 #define PRODUCTVER 0,4,0,132 4 #define STRPRODUCTVER "0,4,0,132" 5 #define STRPRODUCTDATE "2012-02-12" 6 6 #endif // VERSION_HPP -
version.txt
ra06e6af r76540c3 1 1 version=0.4.0 2 build=13 13 date=2012-0 1-312 build=132 3 date=2012-02-12
Note: See TracChangeset
for help on using the changeset viewer.








