Skip to content

Commit

Permalink
win32: Change service files structure, keep the logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kumajaya committed May 7, 2024
1 parent 76d45d7 commit c12d573
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/arch/win32/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
\***************************************************************************/

#pragma region Includes
#include "SampleService.h"
#include "ForteService.h"
#include "ThreadPool.h"
#pragma endregion

Expand All @@ -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,
Expand All @@ -55,7 +55,7 @@ CSampleService::CSampleService(PWSTR pszServiceName,
}


CSampleService::~CSampleService(void)
CForteService::~CForteService(void)
{
if (m_hStoppedEvent)
{
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <windows.h>
#include "ServiceInstaller.h"
#include "ServiceBase.h"
#include "SampleService.h"
#include "ForteService.h"
#pragma endregion


Expand Down Expand Up @@ -151,7 +151,7 @@ int wmain(int argc, wchar_t *argv[])
EnableLogRedirection(logfile, stderr);
}

CSampleService service(SERVICE_DISPLAY_NAME, static_cast<int>(l_argv.size() - 1), l_argv.data());
CForteService service(SERVICE_DISPLAY_NAME, static_cast<int>(l_argv.size() - 1), l_argv.data());
if (!CServiceBase::Run(service))
{
DEVLOG_ERROR("Service failed to run w/err 0x%08lx\n", GetLastError());
Expand Down

0 comments on commit c12d573

Please sign in to comment.