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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2