//关闭各服务 bool CServiceIniter::StopService(void) { SetSvcStatus(SERVICE_STOP_PENDING, 10000); m_GsccsSvr.Destroy(); EventLog("门径系统服务关闭!"); SetSvcStatus(SERVICE_STOPPED, 0); return true; }
//启动各服务 bool CServiceIniter::StartService(void) { //初始化运行参数 SetSvcStatus(SERVICE_START_PENDING, 10000); if (m_GsccsSvr.Init()) { EventLog("门禁系统服务启动成功"); SetSvcStatus(SERVICE_RUNNING, 0); return true; }else{ EventLog("门禁系统服务启动失败"); SetSvcStatus(SERVICE_STOPPED, 0); return false; } }
//////////////////////////////////////////////////////////////////////// // ServiceControl // // Service control handler which is registered with NT (using // RegisterServiceCtrlHandler) as the callback for the service events. // Right now the service does not support PAUSE/CONTINUE functionality, // but this could be added here if required. // // void WINAPI CServiceModule::ServiceControl(DWORD dwCode) { switch (dwCode) { case SERVICE_CONTROL_STOP: // If it can take us a long time to stop our service as we wait for operations to complete, // the SCM doesn't like the ServiceControl() function to take a long time, so we spin up another // thread to terminate us. SetSvcStatus(SERVICE_STOP_PENDING, 0); StartServerTerminateThread(); break; case SERVICE_CONTROL_PAUSE: FedSrv_Pause(); SetSvcStatus(SERVICE_PAUSED, 0); break; case SERVICE_CONTROL_CONTINUE: FedSrv_Continue(); SetSvcStatus(SERVICE_RUNNING, 0); break; case SERVICE_CONTROL_SHUTDOWN: // System is shutting down. Memory and resources should *not* // be freed in this case due to limited time available for // shutdown. Instead, only urgent non-volatile (i.e. disk) // structures should be flushed. break; case SERVICE_CONTROL_INTERROGATE: break; } }
void WINAPI CServiceModule::ServiceMain( DWORD dwArgc, LPSTR *lpszArgv) { HRESULT hr; g.ssh = RegisterServiceCtrlHandlerA(c_szSvcName, ServiceControl); if (!g.ssh) { SetSvcStatus(SERVICE_STOPPED, GetLastError()); return; } SetSvcStatus(SERVICE_START_PENDING, NO_ERROR); hr = FedSrv_Init(); if (SUCCEEDED(hr)) SetSvcStatus(SERVICE_RUNNING, NO_ERROR); else SetSvcStatus(SERVICE_STOPPED, GetLastError()); }
DWORD WINAPI CServiceModule::ServerTerminateThread(DWORD dwUnused) { FedSrv_Terminate(); SetSvcStatus(SERVICE_STOPPED, 0); return 0; }