00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef SCALESTACK_KERNEL_MODULE_H
00025 #define SCALESTACK_KERNEL_MODULE_H
00026
00027 #include <stdint.h>
00028 #include <string>
00029 #include <vector>
00030
00031 #include <scalestack/kernel/logger.h>
00032 #include <scalestack/kernel/macros.h>
00033
00034 namespace scalestack
00035 {
00036 namespace kernel
00037 {
00038
00039 class core;
00040 class option;
00041
00046 class SCALESTACK_API module: public logger
00047 {
00048 public:
00049
00055 typedef struct
00056 {
00057 uint32_t api_version;
00058 const char* name;
00059 const char* version;
00060 const char* author;
00061 const char* title;
00062 const char* license;
00063 const char* dependencies;
00064 void (*options)(module&);
00065 void (*start)(module&);
00066 void (*stop)(module&);
00067 void (*run)(module&);
00068 void (*reconfigure)(module&);
00069 } definition;
00070
00071 ~module();
00072
00073
00074 using logger::get_threshold;
00075
00076
00077 using logger::set_threshold;
00078
00082 core& get_core(void) const;
00083
00087 const std::string& get_name(void) const;
00088
00092 std::string get_normalized_name(void) const;
00093
00097 const std::string& get_pathname(void) const;
00098
00102 const std::string& get_version(void) const;
00103
00107 const std::string& get_author(void) const;
00108
00112 const std::string& get_title(void) const;
00113
00117 const std::string& get_license(void) const;
00118
00123 const std::string& get_dependencies(void) const;
00124
00128 size_t get_parent_count(void) const;
00129
00134 module* begin_parent(void);
00135
00140 module* next_parent(void);
00141
00145 size_t get_child_count(void) const;
00146
00151 module* begin_child(void);
00152
00157 module* next_child(void);
00158
00162 bool is_loaded(void) const;
00163
00186 option& add_option(const std::string& name,
00187 const std::string& help,
00188 const std::string& value_name,
00189 const std::string& default_value);
00190
00197 option& get_option(const std::string& name) const;
00198
00202 size_t get_option_count(void) const;
00203
00208 option* begin_option(void);
00209
00214 option* next_option(void);
00215
00219 void run(void);
00220
00228 static std::string normalize_name(const std::string& name);
00229
00230 private:
00231
00240 SCALESTACK_LOCAL
00241 module(core& core, const std::string& name, size_t threshold);
00242
00246 SCALESTACK_LOCAL
00247 module(const module&);
00248
00252 SCALESTACK_LOCAL
00253 module& operator=(const module&);
00254
00261 SCALESTACK_LOCAL
00262 void _load(void);
00263
00268 SCALESTACK_LOCAL
00269 void _load_dependencies(void);
00270
00274 SCALESTACK_LOCAL
00275 void _unload(void);
00276
00281 SCALESTACK_LOCAL
00282 void _start(void);
00283
00287 SCALESTACK_LOCAL
00288 void _run(void);
00289
00293 SCALESTACK_LOCAL
00294 void _reconfigure(void);
00295
00301 SCALESTACK_LOCAL
00302 void _open_object(int flags);
00303
00307 SCALESTACK_LOCAL
00308 void _close_object(void);
00309
00315 SCALESTACK_LOCAL
00316 option* _get_option(const std::string& name) const;
00317
00325 SCALESTACK_LOCAL
00326 option& _get_or_add_option(const std::string& name);
00327
00335 SCALESTACK_LOCAL
00336 void _set_option_value(const std::string& name, const std::string& value);
00337
00341 SCALESTACK_LOCAL
00342 void _check_options(void) const;
00343
00350 SCALESTACK_LOCAL
00351 void _set_fatal_message(const char* format, std::va_list arguments) const;
00352
00360 SCALESTACK_LOCAL
00361 void _log_message(log::level log_level,
00362 const char* format,
00363 std::va_list arguments) const;
00364
00368 SCALESTACK_LOCAL
00369 void _print_help(void);
00370
00374 SCALESTACK_LOCAL
00375 void _print_config(void);
00376
00377 typedef std::vector<module*> modules;
00378 typedef std::vector<option*> options;
00379
00380 bool _is_loading;
00381 bool _is_loaded;
00382 bool _is_started;
00383 bool _need_run;
00384 bool _need_reconfigure;
00385 core& _core;
00386 void* _handle;
00387 definition* _definition;
00388 std::string _name;
00389 std::string _pathname;
00390 std::string _version;
00391 std::string _author;
00392 std::string _title;
00393 std::string _license;
00394 std::string _dependencies;
00395 modules _parents;
00396 modules::iterator _parent_iterator;
00397 modules _children;
00398 modules::iterator _child_iterator;
00399 options _options;
00400 options::iterator _option_iterator;
00401
00402 friend class core;
00403 };
00404
00405 }
00406 }
00407
00412 #define SCALESTACK_KERNEL_MODULE(options, start, stop, run, reconfigure) \
00413 SCALESTACK_API scalestack::kernel::module::definition \
00414 _scalestack_kernel_module_definition = \
00415 { \
00416 SCALESTACK_CURRENT_API_VERSION, \
00417 SCALESTACK_QUOTE_VALUE(PANDORA_MODULE_NAME), \
00418 PANDORA_MODULE_VERSION, \
00419 PANDORA_MODULE_AUTHOR, \
00420 PANDORA_MODULE_TITLE, \
00421 SCALESTACK_QUOTE_VALUE(PANDORA_MODULE_LICENSE), \
00422 PANDORA_MODULE_DEPENDENCIES, \
00423 options, \
00424 start, \
00425 stop, \
00426 run, \
00427 reconfigure \
00428 }
00429
00430 #endif