Initial
This commit is contained in:
103
service/GenericService.hpp
Normal file
103
service/GenericService.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#ifndef _SERVICE_GENERICSERVICE_HPP_
|
||||
#define _SERVICE_GENERICSERVICE_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_WINSVC_HPP_
|
||||
#include <common/winsvc.hpp>
|
||||
#endif
|
||||
#ifndef _SERVICE_SERVICEHOOK_HPP_
|
||||
#include <service/ServiceHook.hpp>
|
||||
#endif
|
||||
#ifndef _SERVICE_SERVICESTATUS_HPP_
|
||||
#include <service/ServiceStatus.hpp>
|
||||
#endif
|
||||
#ifndef _SERVICE_EVENTLOG_HPP_
|
||||
#include <service/EventLog.hpp>
|
||||
#endif
|
||||
|
||||
class GenericService : private ServiceHook
|
||||
{
|
||||
public:
|
||||
enum State{Paused,Running,Stopped};
|
||||
GenericService(void);
|
||||
virtual ~GenericService();
|
||||
bool setServiceStatus(const ServiceStatus &serviceStatus);
|
||||
bool startService(const String &strServiceName);
|
||||
bool isOkay(void)const;
|
||||
bool isPaused(void)const;
|
||||
bool isRunning(void)const;
|
||||
bool isStopped(void)const;
|
||||
State state(void)const;
|
||||
bool reportEvent(const String &strMessage,EventLog::EventType eventType,DWORD eventID=0,DWORD category=0,PSID userSID=0);
|
||||
protected:
|
||||
virtual void serviceMain(DWORD dwArgc,LPTSTR *lpszArg);
|
||||
virtual void ctrlStop(void);
|
||||
virtual void ctrlPause(void);
|
||||
virtual void ctrlContinue(void);
|
||||
virtual void ctrlInterrogate(void);
|
||||
virtual void ctrlShutdown(void);
|
||||
private:
|
||||
enum{WaitHint=5000};
|
||||
GenericService(const GenericService &someGenericService);
|
||||
GenericService &operator=(const GenericService &someGenericService);
|
||||
virtual void svcMain(DWORD dwArg,LPTSTR *lpszArg);
|
||||
virtual void svcHandler(DWORD dwControl);
|
||||
void state(State state);
|
||||
|
||||
SERVICE_STATUS_HANDLE mhServiceHandle;
|
||||
String mServiceName;
|
||||
EventLog mEventLog;
|
||||
State mState;
|
||||
};
|
||||
|
||||
inline
|
||||
bool GenericService::isOkay(void)const
|
||||
{
|
||||
return mhServiceHandle?true:false;
|
||||
}
|
||||
|
||||
inline
|
||||
GenericService::State GenericService::state(void)const
|
||||
{
|
||||
return mState;
|
||||
}
|
||||
|
||||
inline
|
||||
void GenericService::state(State state)
|
||||
{
|
||||
mState=state;
|
||||
}
|
||||
|
||||
inline
|
||||
bool GenericService::isPaused(void)const
|
||||
{
|
||||
return Paused==state();
|
||||
}
|
||||
|
||||
inline
|
||||
bool GenericService::isRunning(void)const
|
||||
{
|
||||
return Running==state();
|
||||
}
|
||||
|
||||
inline
|
||||
bool GenericService::isStopped(void)const
|
||||
{
|
||||
return Stopped==state();
|
||||
}
|
||||
|
||||
inline
|
||||
bool GenericService::setServiceStatus(const ServiceStatus &serviceStatus)
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
state(State(serviceStatus.currentState()));
|
||||
return ::SetServiceStatus(mhServiceHandle,&((ServiceStatus&)serviceStatus).getSERVICESTATUS())?true:false;
|
||||
}
|
||||
|
||||
inline
|
||||
bool GenericService::reportEvent(const String &strMessage,EventLog::EventType eventType,DWORD eventID,DWORD category,PSID userSID)
|
||||
{
|
||||
return mEventLog.reportEvent(strMessage,eventType,eventID,category,userSID);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user