daemon_application.h

00001 /*
00002  * daemon_application.h
00003  * This file is part of dbPager Classes Library (DCL)
00004  *
00005  * Copyright (c) 2008 Dennis Prochko <wolfsoft@mail.ru>
00006  *
00007  * DCL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation version 3.
00010  *
00011  * DCL is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with DCL; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00019  * Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _DAEMON_APPLICATION_H_
00023 #define _DAEMON_APPLICATION_H_
00024 
00025 #include <string>
00026 
00027 #include <dcl/application.h>
00028 
00029 namespace dbp {
00030 
00032 
00035 namespace log_level {
00036         enum log_level {
00038                 error,
00040                 warning,
00042                 info
00043         };
00044 }
00045 
00047 
00051 class daemon_application_int: public application_int {
00052 public:
00054         typedef delegate0<void> on_reload_configuration_handler;
00056         typedef delegate0<void> on_pause_handler;
00058         typedef delegate0<void> on_resume_handler;
00060         typedef delegate0<void> on_terminate_handler;
00062 
00070         virtual void log(const std::string &message,
00071           log_level::log_level level = log_level::info) = 0;
00073 
00081         virtual void on_reload_configuration(on_reload_configuration_handler handler) = 0;
00083 
00091         virtual void on_pause(on_pause_handler handler) = 0;
00093 
00101         virtual void on_resume(on_resume_handler handler) = 0;
00103 
00110         virtual void on_terminate(on_terminate_handler handler) = 0;
00111 };
00112 
00114 
00118 class daemon_application: public daemon_application_int,
00119   public singleton<daemon_application> {
00120         friend class singleton<daemon_application>;
00121 public:
00122         virtual void set_name(const std::string &name) {
00123                 pimpl->set_name(name);
00124         };
00125         virtual void set_description(const std::string &description) {
00126                 pimpl->set_description(description);
00127         };
00128         virtual void register_cmdline_parameter(const cmdline_parameter &param,
00129           cmdline_parameter_handler handler) {
00130                 pimpl->register_cmdline_parameter(param, handler);
00131         };
00132         virtual void on_execute(on_execute_handler handler) {
00133                 pimpl->on_execute(handler);
00134         };
00135         virtual void on_exception(on_exception_handler handler) {
00136                 pimpl->on_exception(handler);
00137         };
00138         virtual int run(int argc, char *argv[]) {
00139                 return pimpl->run(argc, argv);
00140         };
00141         virtual void log(const std::string &message,
00142           log_level::log_level level = log_level::info) {
00143                 pimpl->log(message, level);
00144         };
00145         virtual void on_reload_configuration(on_reload_configuration_handler handler) {
00146                 pimpl->on_reload_configuration(handler);
00147         };
00148         virtual void on_pause(on_pause_handler handler) {
00149                 pimpl->on_pause(handler);
00150         };
00151         virtual void on_resume(on_resume_handler handler) {
00152                 pimpl->on_resume(handler);
00153         };
00154         virtual void on_terminate(on_terminate_handler handler) {
00155                 pimpl->on_terminate(handler);
00156         };
00157 protected:
00158         daemon_application();
00159 private:
00160         daemon_application_int *pimpl;
00161 };
00162 /*
00163 class logstream: public std::ostream
00164 {
00165   friend class thread_local;
00166   class logstreambuf: public  std::streambuf
00167   {
00168     std::vector<char> buffer_;
00169   public:
00170     logstreambuf();
00171     ~logstreambuf();
00172     virtual std::streamsize xsputn(const char* p, std::streamsize n);
00173     virtual int sync();
00174     virtual int overflow(int);
00175   private:
00176     char* begin();
00177     char* end();
00178   };
00179   logstreambuf streambuf_;
00180 private:
00181   logstream();
00182   virtual ~logstream();
00183 };
00184 */
00185 } // namespace
00186 
00187 #endif /*_DAEMON_APPLICATION_H_*/

 
Support This Project
SourceForge.net Logo