My Project
nt_servc.h
Go to the documentation of this file.
00001 #ifndef NT_SERVC_INCLUDED
00002 #define NT_SERVC_INCLUDED
00003 
00014 // main application thread
00015 typedef void (*THREAD_FC)(void *);
00016 
00017 class NTService
00018 {
00019   public:
00020     NTService();
00021    ~NTService();
00022 
00023     BOOL    bOsNT;            
00024     //install optinos
00025     DWORD   dwDesiredAccess;
00026     DWORD   dwServiceType;
00027     DWORD   dwStartType;
00028     DWORD   dwErrorControl;
00029 
00030     LPSTR   szLoadOrderGroup;
00031     LPDWORD lpdwTagID;
00032     LPSTR   szDependencies;
00033     OSVERSIONINFO osVer;
00034 
00035     // time-out (in milisec)
00036     int     nStartTimeOut;
00037     int     nStopTimeOut;
00038     int     nPauseTimeOut;
00039     int     nResumeTimeOut;
00040 
00041     //
00042     DWORD   my_argc;
00043     LPTSTR *my_argv;
00044     HANDLE  hShutdownEvent;
00045     int     nError;
00046     DWORD   dwState;
00047 
00048     BOOL GetOS();             // returns TRUE if WinNT
00049     BOOL IsNT() { return bOsNT;}
00050     //init service entry point
00051     long Init(LPCSTR szInternName,void *ServiceThread);
00052 
00053     //application shutdown event
00054     void SetShutdownEvent(HANDLE hEvent){ hShutdownEvent=hEvent; }
00055 
00056 
00057     //service install / un-install
00058     BOOL Install(int startType,LPCSTR szInternName,LPCSTR szDisplayName,
00059                  LPCSTR szFullPath, LPCSTR szAccountName=NULL,
00060                  LPCSTR szPassword=NULL);
00061     BOOL SeekStatus(LPCSTR szInternName, int OperationType);
00062     BOOL Remove(LPCSTR szInternName);
00063     BOOL IsService(LPCSTR ServiceName);
00064     BOOL got_service_option(char **argv, char *service_option);
00065     BOOL is_super_user();
00066 
00067     /* 
00068       SetRunning() is to be called by the application 
00069       when initialization completes and it can accept
00070       stop request
00071     */
00072     void SetRunning(void);
00073 
00082     void SetSlowStarting(unsigned long timeout);
00083 
00084     /*
00085       Stop() is to be called by the application to stop 
00086       the service
00087     */
00088     void Stop(void); 
00089 
00090   protected:
00091     LPSTR                  ServiceName;
00092     HANDLE                 hExitEvent;
00093     SERVICE_STATUS_HANDLE  hServiceStatusHandle;
00094     BOOL                   bPause;
00095     BOOL                   bRunning;
00096     HANDLE                 hThreadHandle;
00097     THREAD_FC              fpServiceThread;
00098 
00099     void PauseService();
00100     void ResumeService();
00101     void StopService();
00102     BOOL StartService();
00103 
00104     static void ServiceMain(DWORD argc, LPTSTR *argv);
00105     static void ServiceCtrlHandler (DWORD ctrlCode);
00106 
00107     void Exit(DWORD error);
00108     BOOL SetStatus (DWORD dwCurrentState,DWORD dwWin32ExitCode,
00109                     DWORD dwServiceSpecificExitCode,
00110                     DWORD dwCheckPoint,DWORD dwWaitHint);
00111 
00112 };
00113 /* ------------------------- the end -------------------------------------- */
00114 
00115 #endif /* NT_SERVC_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines