#ifndef _WATCHDOG_SERVICEHANDLE_HPP_ #define _WATCHDOG_SERVICEHANDLE_HPP_ #ifndef _COMMON_WINSVC_HPP_ #include #endif class ServiceHandle { public: enum Disposition{Assume,Delete}; ServiceHandle(); ServiceHandle(SC_HANDLE handle,Disposition disposition=Assume); virtual ~ServiceHandle(); SC_HANDLE getHandle(void)const; void setHandle(SC_HANDLE handle,Disposition disposition); Disposition getDisposition(void)const; void setDisposition(Disposition disposition); bool isOkay(void)const; private: void closeHandle(void); SC_HANDLE mSCHandle; Disposition mDisposition; }; inline ServiceHandle::ServiceHandle() : mSCHandle(0), mDisposition(Delete) { } inline ServiceHandle::ServiceHandle(SC_HANDLE handle,Disposition disposition) : mSCHandle(handle), mDisposition(disposition) { } inline ServiceHandle::~ServiceHandle() { } inline SC_HANDLE ServiceHandle::getHandle(void)const { return mSCHandle; } inline void ServiceHandle::setHandle(SC_HANDLE handle,Disposition disposition) { closeHandle(); mSCHandle=handle; mDisposition=disposition; } inline ServiceHandle::Disposition ServiceHandle::getDisposition(void)const { return mDisposition; } inline void ServiceHandle::setDisposition(Disposition disposition) { mDisposition=disposition; } inline bool ServiceHandle::isOkay(void)const { return mSCHandle?true:false; } inline void ServiceHandle::closeHandle() { if(!mSCHandle) { mDisposition=Delete; return; } if(Assume==mDisposition) { mSCHandle=0; mDisposition=Delete; return; } ::CloseServiceHandle(mSCHandle); mSCHandle=0; } #endif