00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef SCALESTACK_KERNEL_CORE_H
00025 #define SCALESTACK_KERNEL_CORE_H
00026
00027 #include <map>
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 log;
00040 class module;
00041 class service;
00042
00049 class SCALESTACK_API core: private logger
00050 {
00051 public:
00052
00057 core(void);
00058
00063 ~core();
00064
00065
00066 using logger::get_threshold;
00067
00068
00069 using logger::set_threshold;
00070
00077 void parse_arguments(int argument_count, const char** arguments);
00078
00086 void parse_file(const std::string& filename);
00087
00100 void add_module_option_value(const std::string& module_name,
00101 const std::string& option_name,
00102 const std::string& value);
00103
00112 void set_signal_handlers(void);
00113
00121 void handle_signal(int signal_number);
00122
00131 module& get_or_add_module(const std::string& name);
00132
00140 module& get_module(const std::string& name) const;
00141
00145 size_t get_module_count(void) const;
00146
00163 module* begin_module(void);
00164
00171 module* next_module(void);
00172
00180 void add_service(const std::string& name, service* service);
00181
00188 service* remove_service(const std::string& name);
00189
00196 service& get_service(const std::string& name) const;
00197
00201 size_t get_service_count(void) const;
00202
00210 void add_log(const std::string& name, log* log);
00211
00218 log* remove_log(const std::string& name);
00219
00226 log& get_log(const std::string& name) const;
00227
00231 size_t get_log_count(void) const;
00232
00237 void run(void);
00238
00244 void shutdown(void);
00245
00246 private:
00247
00251 SCALESTACK_LOCAL
00252 core(const core&);
00253
00257 SCALESTACK_LOCAL
00258 core& operator=(const core&);
00259
00267 SCALESTACK_LOCAL
00268 void _parse_argument(std::string argument);
00269
00276 SCALESTACK_LOCAL
00277 const std::string& _get_alias(const std::string& name) const;
00278
00284 SCALESTACK_LOCAL
00285 module* _get_module(const std::string& name) const;
00286
00290 SCALESTACK_LOCAL
00291 void _notify(void);
00292
00300 SCALESTACK_LOCAL
00301 void _set_fatal_message(const char* format, std::va_list arguments) const;
00302
00311 SCALESTACK_LOCAL
00312 void _log_message(log::level log_level,
00313 const char* format,
00314 std::va_list arguments) const;
00315
00325 SCALESTACK_LOCAL
00326 void _log(log::level log_level,
00327 const char* context,
00328 const char* format,
00329 std::va_list arguments) const;
00330
00334 SCALESTACK_LOCAL
00335 void _print_help(void);
00336
00340 SCALESTACK_LOCAL
00341 void _print_config(void);
00342
00343 typedef std::vector<std::string> files;
00344 typedef std::vector<std::string> paths;
00345 typedef std::vector<module*> modules;
00346 typedef std::map<std::string, std::string> aliases;
00347 typedef std::map<std::string, service*> services;
00348 typedef std::map<std::string, log*> logs;
00349
00350 bool _need_help;
00351 bool _need_config;
00352 bool _shutdown_request;
00353 bool _iterator_on_modules;
00354 int _notify_pipe[2];
00355 files _open_files;
00356 paths _paths;
00357 modules _modules;
00358 modules _new_modules;
00359 modules::iterator _module_iterator;
00360 aliases _aliases;
00361 services _services;
00362 logs _logs;
00363
00364 friend class module;
00365 };
00366
00367 }
00368 }
00369
00370 #endif