net-snmp 5.7
winservice.h
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 (LPCTSTR 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    * Service Main function,  Which will spawn a thread, and calls the
00099    * Service run part
00100    */
00101   VOID WINAPI ServiceMain (DWORD argc, LPTSTR argv[]);
00102 
00103   /*
00104    * To start Service 
00105    */
00106 
00107   BOOL RunAsService (INT (*ServiceFunction) (INT, LPTSTR *));
00108 
00109   /*
00110    * Call back function to process SCM Requests 
00111    */
00112   VOID WINAPI ControlHandler (DWORD dwControl);
00113 
00114   /*
00115    * To Stop the service 
00116    */
00117   VOID ProcessServiceStop (VOID);
00118 
00119   /*
00120    * To Pause service 
00121    */
00122   VOID ProcessServicePause (VOID);
00123 
00124   /*
00125    * To Continue paused service 
00126    */
00127   VOID ProcessServiceContinue (VOID);
00128 
00129   /*
00130    * To send Current Service status to SCM when INTERROGATE command is sent 
00131    */
00132   VOID ProcessServiceInterrogate (VOID);
00133 
00134   /*
00135    * To allocate and Set security descriptor 
00136    */
00137   BOOL SetSimpleSecurityAttributes (SECURITY_ATTRIBUTES * pSecurityAttr);
00138 
00139   /*
00140    * To free Security Descriptor 
00141    */
00142   VOID FreeSecurityAttributes (SECURITY_ATTRIBUTES * pSecurityAttr);
00143 
00144   /*
00145    * TheadFunction - To spawan as thread - Invokes registered service function 
00146    */
00147   unsigned WINAPI ThreadFunction (LPVOID lpParam);
00148 
00149   /*
00150    * Service STOP function registration with this framewrok
00151    * * this function must be invoked before calling RunAsService
00152    */
00153   VOID RegisterStopFunction (VOID (*StopFunc) (VOID));
00154 
00155 #ifdef __cplusplus
00156 }
00157 #endif                          /*  */
00158 #endif                          /* WINSERVICE_H */
00159