service_root.h

Go to the documentation of this file.
00001 #ifndef SERVICE_ROOT_CLASS
00002 #define SERVICE_ROOT_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : service_root                                                      *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include <basis/convert_utf.h>
00019 #include <basis/object_base.h>
00020 
00021 // forward.
00022 class internal_service_status;
00023 class log_base;
00024 class rendezvous;
00025 
00026 #ifndef __WIN32__
00027   // definitions needed by derived services.
00028   enum surrogate_service_markers {
00029     // service statuses used in report_status.
00030     SERVICE_START_PENDING = 2000,
00031     SERVICE_RUNNING,
00032     SERVICE_STOPPED,
00033     SERVICE_STOP_PENDING,
00034 
00035     NO_ERROR = 0  // an extra definition of a commonly used win32 id.
00036   };
00037 
00038   #define __stdcall 
00039 #endif
00040 
00042 
00057 class service_root : public virtual object_base
00058 {
00059 public:
00060   service_root(const istring &service_name, const istring &display_name,
00061           const string_array &dependencies);
00063 
00069   virtual ~service_root();
00070 
00071   IMPLEMENT_CLASS_NAME("service_root");
00072 
00073   int initialize(int argc, char **argv, const istring &program_name);
00075 
00083   virtual void perform_service(int argc, char **argv) = 0;
00085 
00092   bool should_exit() const { return _leave_now; }
00094 
00098   void stop_service();
00100 
00102   // accessor functions for our info.
00103   const istring &service_name() const;
00104   const istring &display_name() const;
00105   const string_array &dependencies() const;
00106 
00107   bool normal_app() const { return _normal_app; }
00109 
00110   int error_code() const { return _error_code; }
00112   void error_code(int new_code) { _error_code = new_code; }
00114 
00115   int instruct(int argc, char **argv);
00117 
00118   u_int current_status();
00120 
00121 //interpretations of these values exist where...?
00122 
00123   bool report_status(u_int current_state, u_int exit_code, u_int wait_hint);
00125 
00129   void log_event(const istring &message) const;
00131 
00132   static service_root &get_root();
00134 
00136   // this set of operations is invoked by our static methods; normal users
00137   // shouldn't need these.
00138   void install(bool set_auto, const istring &user, const istring &password);
00140 
00144   void remove();
00146   void standalone(int argc, char **argv);
00148 
00151 private:
00152   bool _leave_now;  
00153   istring *_service_name;  
00154   istring *_display_name;  
00155   string_array *_dependencies;  
00156   int _error_code;  
00157   bool _normal_app;  
00158   int _checkpoint;  
00159   internal_service_status *_service_status;  
00160   void *_control_handle;  
00161   static service_root *_last_root;  
00162   rendezvous *_app_lock;  
00163   bool _got_lock;  
00164 
00165   static void stop_service_handler(int sig_num);
00167 
00168   static void __stdcall control_service(u_long control_code);
00170 
00171   static int __stdcall standalone_controller(u_long control_code);
00173 
00174   static void __stdcall setup(int argc, char **argv);
00176 
00178   flexichar *compute_dependency_string();
00180 
00182   bool already_running(const istring &program_name);
00184 };
00185 
00186 #endif
00187 

Generated on Fri Nov 21 04:29:58 2008 for HOOPLE Libraries by  doxygen 1.5.1