From c12d5736fc440c8704fb3aba765a20794e11d1e9 Mon Sep 17 00:00:00 2001 From: Ketut Kumajaya Date: Sun, 5 May 2024 14:05:52 +0700 Subject: [PATCH] win32: Change service files structure, keep the logic --- src/arch/win32/service/CMakeLists.txt | 4 ++-- .../{SampleService.cpp => ForteService.cpp} | 20 +++++++++---------- .../{SampleService.h => ForteService.h} | 6 +++--- .../{CppWindowsService.cpp => wmain.cpp} | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) rename src/arch/win32/service/{SampleService.cpp => ForteService.cpp} (91%) rename src/arch/win32/service/{SampleService.h => ForteService.h} (92%) rename src/arch/win32/service/{CppWindowsService.cpp => wmain.cpp} (97%) diff --git a/src/arch/win32/service/CMakeLists.txt b/src/arch/win32/service/CMakeLists.txt index 7b221ea05..bc5b94bdc 100644 --- a/src/arch/win32/service/CMakeLists.txt +++ b/src/arch/win32/service/CMakeLists.txt @@ -10,6 +10,6 @@ # Ketut Kumajaya - initial API and implementation and/or initial documentation # *******************************************************************************/ if(FORTE_WINDOWS_SERVICE) - forte_add_to_executable_h(SampleService ServiceBase ServiceInstaller ThreadPool) - forte_add_to_executable_cpp(CppWindowsService SampleService ServiceBase ServiceInstaller) + forte_add_to_executable_h(ForteService ServiceBase ServiceInstaller ThreadPool) + forte_add_to_executable_cpp(wmain ForteService ServiceBase ServiceInstaller) endif() diff --git a/src/arch/win32/service/SampleService.cpp b/src/arch/win32/service/ForteService.cpp similarity index 91% rename from src/arch/win32/service/SampleService.cpp rename to src/arch/win32/service/ForteService.cpp index ca2a5ca16..391f0d100 100644 --- a/src/arch/win32/service/SampleService.cpp +++ b/src/arch/win32/service/ForteService.cpp @@ -20,7 +20,7 @@ \***************************************************************************/ #pragma region Includes -#include "SampleService.h" +#include "ForteService.h" #include "ThreadPool.h" #pragma endregion @@ -33,7 +33,7 @@ void endForte(int paSig); int _main(int argc, char *arg[]); -CSampleService::CSampleService(PWSTR pszServiceName, +CForteService::CForteService(PWSTR pszServiceName, int argc, char *argv[], BOOL fCanStop, @@ -55,7 +55,7 @@ CSampleService::CSampleService(PWSTR pszServiceName, } -CSampleService::~CSampleService(void) +CForteService::~CForteService(void) { if (m_hStoppedEvent) { @@ -66,7 +66,7 @@ CSampleService::~CSampleService(void) // -// FUNCTION: CSampleService::OnStart(DWORD, LPWSTR *) +// FUNCTION: CForteService::OnStart(DWORD, LPWSTR *) // // PURPOSE: The function is executed when a Start command is sent to the // service by the SCM or when the operating system starts (for a service @@ -90,7 +90,7 @@ CSampleService::~CSampleService(void) // other solution is to spawn a new thread to perform the main service // functions, which is demonstrated in this code sample. // -void CSampleService::OnStart(DWORD, LPWSTR*) +void CForteService::OnStart(DWORD, LPWSTR*) { // Log command line arguments std::ostringstream stream; @@ -104,17 +104,17 @@ void CSampleService::OnStart(DWORD, LPWSTR*) EVENTLOG_INFORMATION_TYPE); // Queue the main service function for execution in a worker thread. - CThreadPool::QueueUserWorkItem(&CSampleService::ServiceWorkerThread, this); + CThreadPool::QueueUserWorkItem(&CForteService::ServiceWorkerThread, this); } // -// FUNCTION: CSampleService::ServiceWorkerThread(void) +// FUNCTION: CForteService::ServiceWorkerThread(void) // // PURPOSE: The method performs the main function of the service. It runs // on a thread pool worker thread. // -void CSampleService::ServiceWorkerThread(void) +void CForteService::ServiceWorkerThread(void) { // Periodically check if the service is stopping. while (!m_fStopping) @@ -137,7 +137,7 @@ void CSampleService::ServiceWorkerThread(void) // -// FUNCTION: CSampleService::OnStop(void) +// FUNCTION: CForteService::OnStop(void) // // PURPOSE: The function is executed when a Stop command is sent to the // service by SCM. It specifies actions to take when a service stops @@ -148,7 +148,7 @@ void CSampleService::ServiceWorkerThread(void) // Be sure to periodically call ReportServiceStatus() with // SERVICE_STOP_PENDING if the procedure is going to take long time. // -void CSampleService::OnStop() +void CForteService::OnStop() { // Log a service stop message to the Application log. WriteEventLogEntry((PWSTR)L"FORTE service stopped", diff --git a/src/arch/win32/service/SampleService.h b/src/arch/win32/service/ForteService.h similarity index 92% rename from src/arch/win32/service/SampleService.h rename to src/arch/win32/service/ForteService.h index 231d99721..0312184dd 100644 --- a/src/arch/win32/service/SampleService.h +++ b/src/arch/win32/service/ForteService.h @@ -24,17 +24,17 @@ #include "ServiceBase.h" -class CSampleService : public CServiceBase +class CForteService : public CServiceBase { public: - CSampleService(PWSTR pszServiceName, + CForteService(PWSTR pszServiceName, int argc, char *argv[], BOOL fCanStop = TRUE, BOOL fCanShutdown = TRUE, BOOL fCanPauseContinue = FALSE); - virtual ~CSampleService(void); + virtual ~CForteService(void); protected: diff --git a/src/arch/win32/service/CppWindowsService.cpp b/src/arch/win32/service/wmain.cpp similarity index 97% rename from src/arch/win32/service/CppWindowsService.cpp rename to src/arch/win32/service/wmain.cpp index 788190727..2b1403034 100644 --- a/src/arch/win32/service/CppWindowsService.cpp +++ b/src/arch/win32/service/wmain.cpp @@ -23,7 +23,7 @@ #include #include "ServiceInstaller.h" #include "ServiceBase.h" -#include "SampleService.h" +#include "ForteService.h" #pragma endregion @@ -151,7 +151,7 @@ int wmain(int argc, wchar_t *argv[]) EnableLogRedirection(logfile, stderr); } - CSampleService service(SERVICE_DISPLAY_NAME, static_cast(l_argv.size() - 1), l_argv.data()); + CForteService service(SERVICE_DISPLAY_NAME, static_cast(l_argv.size() - 1), l_argv.data()); if (!CServiceBase::Run(service)) { DEVLOG_ERROR("Service failed to run w/err 0x%08lx\n", GetLastError());