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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2