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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2