Deskflow 1.24.0.365
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
ArchDaemonWindows Class Reference

Win32 implementation of IArchDaemon. More...

#include <ArchDaemonWindows.h>

Inheritance diagram for ArchDaemonWindows:
Collaboration diagram for ArchDaemonWindows:

Public Types

using RunFunc = std::function<int()>
Public Types inherited from IArchDaemon
using DaemonFunc = std::function<int()>

Public Member Functions

 ArchDaemonWindows ()
 ~ArchDaemonWindows () override=default
int daemonize (DaemonFunc const &func) override
 Daemonize the process.
QString commandLine () const override
 Get the command line.
Public Member Functions inherited from IArchDaemon
virtual ~IArchDaemon ()=default

Static Public Member Functions

static int runDaemon (RunFunc runFunc)
 Run the daemon.
static void daemonRunning (bool running)
 Indicate daemon is in main loop.
static void daemonFailed (int result)
 Indicate failure of running daemon.
static UINT getDaemonQuitMessage ()
 Get daemon quit message.

Detailed Description

Win32 implementation of IArchDaemon.

Member Typedef Documentation

◆ RunFunc

using ArchDaemonWindows::RunFunc = std::function<int()>

Constructor & Destructor Documentation

◆ ArchDaemonWindows()

ArchDaemonWindows::ArchDaemonWindows ( )

◆ ~ArchDaemonWindows()

ArchDaemonWindows::~ArchDaemonWindows ( )
overridedefault

Member Function Documentation

◆ commandLine()

QString ArchDaemonWindows::commandLine ( ) const
inlineoverridevirtual

Get the command line.

Gets the command line with which the application was started.

Implements IArchDaemon.

◆ daemonFailed()

void ArchDaemonWindows::daemonFailed ( int result)
static

Indicate failure of running daemon.

The runFunc passed to runDaemon() should call this function to indicate failure. result is returned by daemonize().

◆ daemonize()

int ArchDaemonWindows::daemonize ( DaemonFunc const & func)
overridevirtual

Daemonize the process.

Daemonize. Throw ArchDaemonFailedException on error. name is the name of the daemon. Once daemonized, func is invoked and daemonize returns when and what it does.

Exactly what happens when daemonizing depends on the platform.

  • unix: Detaches from terminal. func gets passed one argument, the name passed to daemonize().
  • win32: Becomes a service. Argument 0 is the name of the service and the rest are the arguments passed to StartService(). func is only called when the service is actually started. func must call ArchMiscWindows::runDaemon() to finally becoming a service. The runFunc function passed to runDaemon() must call ArchMiscWindows::daemonRunning(true) when it enters the main loop (i.e. after initialization) and ArchMiscWindows::daemonRunning(false) when it leaves the main loop. The stopFunc function passed to runDaemon() is called when the daemon must exit the main loop and it must cause runFunc to return. func should return what runDaemon() returns. func or runFunc can call ArchMiscWindows::daemonFailed() to indicate startup failure.

Implements IArchDaemon.

◆ daemonRunning()

void ArchDaemonWindows::daemonRunning ( bool running)
static

Indicate daemon is in main loop.

The runFunc passed to runDaemon() should call this function to indicate when it has entered (running is true) or exited (running is false) the main loop.

◆ getDaemonQuitMessage()

UINT ArchDaemonWindows::getDaemonQuitMessage ( )
static

Get daemon quit message.

The windows NT daemon tells daemon thread to exit by posting this message to it. The thread must, of course, have a message queue for this to work.

◆ runDaemon()

int ArchDaemonWindows::runDaemon ( RunFunc runFunc)
static

Run the daemon.

When the client calls daemonize(), the DaemonFunc should call this function after initialization and argument parsing to perform the daemon processing. The runFunc should perform the daemon's main loop, calling daemonRunning(true) when it enters the main loop (i.e. after initialization) and daemonRunning(false) when it leaves the main loop. The runFunc is called in a new thread and when the daemon must exit the main loop due to some external control the getDaemonQuitMessage() is posted to the thread. This function returns what runFunc returns. runFunc should call daemonFailed() if the daemon fails.


The documentation for this class was generated from the following files: