[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [win-pv-devel] [PATCH 10/20] Add ServiceInstall
> -----Original Message----- > From: win-pv-devel [mailto:win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx] On > Behalf Of Owen Smith > Sent: 24 May 2016 15:21 > To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx > Cc: Owen Smith > Subject: [win-pv-devel] [PATCH 10/20] Add ServiceInstall > > Adds events for shutdown and suspend handlers > > Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx> Acked-by: Paul Durrant <paul.durrant@xxxxxxxxxx> > --- > src/liteagent/LiteAgent.cpp | 60 > ++++++++++++++++++++++++++++++++++++++++++--- > src/liteagent/LiteAgent.h | 3 +++ > 2 files changed, 60 insertions(+), 3 deletions(-) > > diff --git a/src/liteagent/LiteAgent.cpp b/src/liteagent/LiteAgent.cpp > index ba48fc0..a887925 100644 > --- a/src/liteagent/LiteAgent.cpp > +++ b/src/liteagent/LiteAgent.cpp > @@ -63,7 +63,31 @@ static CLiteAgent s_service; > > /*static*/ int CLiteAgent::ServiceInstall() > { > - return -1; > + SC_HANDLE svc, mgr; > + char path[MAX_PATH+1]; > + > + mgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); > + if (mgr == NULL) > + return -1; > + > + if (GetModuleFileNameA(NULL, path, MAX_PATH) == 0) { > + CloseServiceHandle(mgr); > + return GetLastError(); > + } > + path[MAX_PATH] = 0; > + > + svc = CreateServiceA(mgr, SVC_NAME, SVC_DISPLAYNAME, > SERVICE_ALL_ACCESS, > + SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, > + SERVICE_ERROR_NORMAL, path, > + NULL, NULL, NULL, NULL, NULL); > + if (svc == NULL) { > + CloseServiceHandle(mgr); > + return -2; > + } > + > + CloseServiceHandle(svc); > + CloseServiceHandle(mgr); > + return 0; > } > > /*static*/ int CLiteAgent::ServiceUninstall() > @@ -192,8 +216,38 @@ void CLiteAgent::OnDeviceEvent(DWORD evt, > LPVOID data) > > bool CLiteAgent::ServiceMainLoop() > { > - WaitForSingleObject(m_svc_stop, INFINITE); > - return false; > + HANDLE evts[3] = { m_svc_stop, m_shutdown, m_suspend }; > + DWORD wait = WaitForMultipleObjects(3, evts, FALSE, INFINITE); > + switch (wait) { > + case WAIT_OBJECT_0: > + return false; // service stop event > + > + case WAIT_OBJECT_0+1: > + OnShutdown(); > + break; > + > + case WAIT_OBJECT_0+2: > + OnSuspend(); > + break; > + > + default: > + break; > + } > + return true; // keep looping > +} > + > +void CLiteAgent::OnShutdown() > +{ > + if (m_dev == NULL) > + return; > + CLiteAgent::Log("OnShutdown(%ws)\n", m_dev->Path()); > +} > + > +void CLiteAgent::OnSuspend() > +{ > + if (m_dev == NULL) > + return; > + CLiteAgent::Log("OnSuspend(%ws)\n", m_dev->Path()); > } > > void CLiteAgent::SetServiceStatus(DWORD state, DWORD exit /*= 0*/, > DWORD hint /*= 0*/) > diff --git a/src/liteagent/LiteAgent.h b/src/liteagent/LiteAgent.h > index 2ec1f55..b19d8e2 100644 > --- a/src/liteagent/LiteAgent.h > +++ b/src/liteagent/LiteAgent.h > @@ -68,6 +68,9 @@ private: // service events > void OnDeviceEvent(DWORD, LPVOID); > bool ServiceMainLoop(); > > + void OnShutdown(); > + void OnSuspend(); > + > private: // service support > void SetServiceStatus(DWORD state, DWORD exit = 0, DWORD hint = 0); > void WINAPI __ServiceMain(int argc, char** argv); > -- > 1.9.4.msysgit.1 > > > _______________________________________________ > win-pv-devel mailing list > win-pv-devel@xxxxxxxxxxxxxxxxxxxx > http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |