(file) Return to service.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Server

  1 karl  1.5 //%2004////////////////////////////////////////////////////////////////////////
  2 tony  1.1 //
  3 karl  1.5 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.4 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.5 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 tony  1.1 //
 10           // Permission is hereby granted, free of charge, to any person obtaining a copy
 11           // of this software and associated documentation files (the "Software"), to
 12           // deal in the Software without restriction, including without limitation the
 13           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 14           // sell copies of the Software, and to permit persons to whom the Software is
 15           // furnished to do so, subject to the following conditions:
 16           // 
 17           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 18           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 19           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 20           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 21           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 23           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 24           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25           //
 26           //==============================================================================
 27           //
 28           // Author: Tony Fiorentino (fiorentino_tony@emc.com)
 29           //
 30 tony  1.1 //%/////////////////////////////////////////////////////////////////////////////
 31           #ifndef SERVICE_H
 32           #define SERVICE_H
 33           
 34           typedef int (*SERVICE_MAIN_T)(int flag, int argc, char **argv);
 35           
 36           class Service
 37           {
 38           public:
 39             // default ctor
 40             Service(void);
 41           
 42             // ctor using service name
 43             Service(char *service_name);
 44           
 45             // ctor using service name and event source
 46             Service(char *service_name, char *event_source);
 47           
 48             // dtor
 49             ~Service(void);
 50           
 51 tony  1.1   // State
 52             enum State
 53               {
 54                 SERVICE_STATE_STOPPED            = SERVICE_STOPPED,
 55                 SERVICE_STATE_START_PENDING      = SERVICE_START_PENDING,
 56                 SERVICE_STATE_STOP_PENDING       = SERVICE_STOP_PENDING,
 57                 SERVICE_STATE_RUNNING            = SERVICE_RUNNING,
 58                 SERVICE_STATE_CONTINUE_PENDING   = SERVICE_CONTINUE_PENDING,
 59                 SERVICE_STATE_PAUSE_PENDING      = SERVICE_PAUSE_PENDING,
 60                 SERVICE_STATE_PAUSED             = SERVICE_PAUSED
 61               };
 62           
 63             // Return Codes
 64             enum ReturnCode
 65               {
 66                 SERVICE_RETURN_SUCCESS           = 0,
 67                 SERVICE_ERROR_MARKED_FOR_DELETE  = ERROR_SERVICE_MARKED_FOR_DELETE,
 68                 SERVICE_ERROR_DOES_NOT_EXIST     = ERROR_SERVICE_DOES_NOT_EXIST,
 69                 SERVICE_ERROR_REQUEST_TIMEOUT    = ERROR_SERVICE_REQUEST_TIMEOUT,
 70                 SERVICE_ERROR_NO_THREAD          = ERROR_SERVICE_NO_THREAD,
 71                 SERVICE_ERROR_DATABASE_LOCKED    = ERROR_SERVICE_DATABASE_LOCKED,
 72 tony  1.1       SERVICE_ERROR_ALREADY_RUNNING    = ERROR_SERVICE_ALREADY_RUNNING,
 73                 SERVICE_ERROR_DISABLED           = ERROR_SERVICE_DISABLED,
 74                 SERVICE_ERROR_CANNOT_ACCEPT_CTRL = ERROR_SERVICE_CANNOT_ACCEPT_CTRL,
 75                 SERVICE_ERROR_NOT_ACTIVE         = ERROR_SERVICE_NOT_ACTIVE,
 76                 SERVICE_ERROR_SPECIFIC_ERROR     = ERROR_SERVICE_SPECIFIC_ERROR,
 77                 SERVICE_ERROR_DEPENDENCY_FAIL    = ERROR_SERVICE_DEPENDENCY_FAIL,
 78                 SERVICE_ERROR_LOGON_FAILED       = ERROR_SERVICE_LOGON_FAILED,
 79                 SERVICE_ERROR_START_HANG         = ERROR_SERVICE_START_HANG,
 80                 SERVICE_ERROR_DOES_EXISTS        = ERROR_SERVICE_EXISTS,
 81                 SERVICE_ERROR_DEPENDENCY_DELETED = ERROR_SERVICE_DEPENDENCY_DELETED,
 82                 SERVICE_ERROR_NEVER_STARTED      = ERROR_SERVICE_NEVER_STARTED,
 83                 SERVICE_ERROR_NOT_FOUND          = ERROR_SERVICE_NOT_FOUND,
 84                 SERVICE_ERROR_CONTROLLER_CONNECT = ERROR_FAILED_SERVICE_CONTROLLER_CONNECT,
 85                 SERVICE_ERROR_INVALID_CONTROL    = ERROR_INVALID_SERVICE_CONTROL,
 86                 SERVICE_ERROR_INVALID_ACCOUNT    = ERROR_INVALID_SERVICE_ACCOUNT,
 87                 SERVICE_ERROR_INVALID_LOCK       = ERROR_INVALID_SERVICE_LOCK,
 88                 SERVICE_ERROR_DUPLICATE_NAME     = ERROR_DUPLICATE_SERVICE_NAME,
 89                 SERVICE_ERROR_DIFFERENT_ACCOUNT  = ERROR_DIFFERENT_SERVICE_ACCOUNT,
 90                 SERVICE_ERROR_UNKNOWN            = -999
 91               };
 92           
 93 tony  1.1   // Flag
 94             enum Flag
 95               {
 96                 STARTUP_FLAG,
 97                 SHUTDOWN_FLAG
 98               };
 99           
100             // Methods
101             ReturnCode Install(char  *display_name, char  *description, char  *exe_name);
102             ReturnCode Remove(void);
103           
104             ReturnCode Start(int wait_time);
105             ReturnCode Stop(int wait_time);
106 s.hills 1.3   static bool report_status(DWORD current_state, DWORD exit_code, DWORD check_point, DWORD wait_hint);
107 tony    1.1 
108               static ReturnCode Run(SERVICE_MAIN_T service_main, DWORD flags = 0);
109               ReturnCode GetState(State *state);
110               static bool LogEvent(WORD event_type, DWORD event_id, const char *string);
111 tony    1.2   static void SetServiceName(char *service_name)
112                 {
113                   g_service_name = service_name;
114                 }
115               static char *GetServiceName(void)
116                 {
117                   return g_service_name;
118                 }
119 tony    1.1 
120             private:
121               static int                    g_argc;
122               static char                 **g_argv;
123               static char                  *g_service_name;
124               static char                  *g_event_source;
125               static DWORD                  g_flags;
126               static DWORD                  g_current_state;
127               static SERVICE_STATUS_HANDLE  g_service_status_handle;
128               static SERVICE_MAIN_T         g_service_main;
129             
130               static bool show_error(const char *action, const char *object, DWORD hr);
131               static void WINAPI service_control_handler(DWORD control);
132               static bool check_args_for_string(char *string);
133               static void __stdcall real_service_main(DWORD argc, LPTSTR *argv);
134               static void change_service_description(SC_HANDLE service, char *description);
135               State get_state(DWORD scm_state);
136               static ReturnCode get_error(DWORD error_status, const char action[] = "cimserver");
137             };
138             
139             #endif // SERVICE_H
140 tony    1.1 

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2