net-snmp
5.4.1
|
00001 #ifndef WINSERVICE_H 00002 #define WINSERVICE_H 00003 00004 /* 00005 * 00006 * Windows Service related functions declaration 00007 * By Raju Krishanppa(raju_krishnappa@yahoo.com) 00008 * 00009 */ 00010 00011 #ifdef __cplusplus 00012 extern "C" 00013 { 00014 00015 #endif /* */ 00016 00017 /* 00018 * Define Constants for Register, De-register , Run As service or Console mode 00019 */ 00020 #define REGISTER_SERVICE 0 00021 #define UN_REGISTER_SERVICE 1 00022 #define RUN_AS_SERVICE 2 00023 #define RUN_AS_CONSOLE 3 00024 00025 00026 /* 00027 * Error levels returned when registering or unregistering the service 00028 */ 00029 #define SERVICE_ERROR_NONE 0 00030 #define SERVICE_ERROR_SCM_OPEN 1 /* Can not open SCM */ 00031 #define SERVICE_ERROR_CREATE_SERVICE 2 /* Can not create service */ 00032 #define SERVICE_ERROR_CREATE_REGISTRY_ENTRIES 3 /* Can not create registry entries */ 00033 #define SERVICE_ERROR_OPEN_SERVICE 4 /* Can not open service (service does not exist) */ 00034 00035 /* 00036 * Define Message catalog ID 00037 * MessageId: DISPLAY_MSG 00038 * MessageText: %1. 00039 */ 00040 #define DISPLAY_MSG 0x00000064L 00041 00042 /* 00043 * Hint Value to SCM to wait before sending successive commands to service 00044 */ 00045 #define SCM_WAIT_INTERVAL 7000 00046 00047 /* 00048 * Define Generic String Size, to hold Error or Information 00049 */ 00050 #define MAX_STR_SIZE 1024 00051 00052 /* 00053 * Delcare Global variables, which are visible to other modules 00054 */ 00055 extern BOOL g_fRunningAsService; 00056 00057 /* 00058 * Input parameter structure to thread 00059 */ 00060 typedef struct _InputParams 00061 { 00062 DWORD Argc; 00063 LPTSTR *Argv; 00064 } InputParams; 00065 00066 /* 00067 * Define Service Related functions 00068 */ 00069 00070 /* 00071 * To register application as windows service with SCM 00072 */ 00073 int RegisterService (LPCTSTR lpszServiceName, 00074 LPCTSTR lpszServiceDisplayName, 00075 LPCTSTR lpszServiceDescription, InputParams * StartUpArg, int quiet); 00076 00077 /* 00078 * To unregister service 00079 */ 00080 int UnregisterService (LPCSTR lpszServiceName, int quiet); 00081 00082 /* 00083 * To parse command line for startup option 00084 */ 00085 INT ParseCmdLineForServiceOption (INT argc, TCHAR * argv[], int *quiet); 00086 00087 /* 00088 * To write to windows event log 00089 */ 00090 VOID WriteToEventLog (WORD wType, LPCTSTR pszFormat, ...); 00091 00092 /* 00093 * To display generic windows error 00094 */ 00095 VOID DisplayError (LPCTSTR pszTitle, int quite); 00096 00097 /* 00098 * To update windows service status to SCM 00099 */ 00100 static BOOL UpdateServiceStatus (DWORD dwStatus, DWORD dwErrorCode, 00101 DWORD dwWaitHint); 00102 00103 /* 00104 * To Report current service status to SCM 00105 */ 00106 static BOOL ReportCurrentServiceStatus (VOID); 00107 00108 /* 00109 * Service Main function, Which will spawn a thread, and calls the 00110 * Service run part 00111 */ 00112 VOID WINAPI ServiceMain (DWORD argc, LPTSTR argv[]); 00113 00114 /* 00115 * To start Service 00116 */ 00117 00118 BOOL RunAsService (INT (*ServiceFunction) (INT, LPTSTR *)); 00119 00120 /* 00121 * Call back function to process SCM Requests 00122 */ 00123 VOID WINAPI ControlHandler (DWORD dwControl); 00124 00125 /* 00126 * To Stop the service 00127 */ 00128 VOID ProcessServiceStop (VOID); 00129 00130 /* 00131 * To Pause service 00132 */ 00133 VOID ProcessServicePause (VOID); 00134 00135 /* 00136 * To Continue paused service 00137 */ 00138 VOID ProcessServiceContinue (VOID); 00139 00140 /* 00141 * To send Current Service status to SCM when INTERROGATE command is sent 00142 */ 00143 VOID ProcessServiceInterrogate (VOID); 00144 00145 /* 00146 * To allocate and Set security descriptor 00147 */ 00148 BOOL SetSimpleSecurityAttributes (SECURITY_ATTRIBUTES * pSecurityAttr); 00149 00150 /* 00151 * To free Security Descriptor 00152 */ 00153 VOID FreeSecurityAttributes (SECURITY_ATTRIBUTES * pSecurityAttr); 00154 00155 /* 00156 * TheadFunction - To spawan as thread - Invokes registered service function 00157 */ 00158 DWORD WINAPI ThreadFunction (LPVOID lpParam); 00159 00160 /* 00161 * Service STOP function registration with this framewrok 00162 * * this function must be invoked before calling RunAsService 00163 */ 00164 VOID RegisterStopFunction (VOID (*StopFunc) (VOID)); 00165 00166 #ifdef __cplusplus 00167 } 00168 #endif /* */ 00169 #endif /* WINSERVICE_H */ 00170