TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
Loading...
Searching...
No Matches
tec::Daemon Class Referenceabstract

Abstract interface for a daemon that runs in a separate thread. More...

#include <tec_daemon.hpp>

Inheritance diagram for tec::Daemon:
tec::Worker< Params > tec::Worker< TParams > tec::ActorWorker< TParams, TActor >

Classes

struct  Builder
 Factory for creating daemon instances. More...
 

Public Member Functions

 Daemon ()=default
 Default constructor.
 
virtual ~Daemon ()=default
 Virtual destructor for safe polymorphic deletion.
 
 Daemon (const Daemon &)=delete
 Daemons are non-copyable to ensure unique ownership.
 
 Daemon (Daemon &&)=delete
 Daemons are non-movable to ensure unique ownership.
 
virtual Status run ()=0
 Starts the daemon's operation.
 
virtual Status terminate ()=0
 Terminates the daemon's operation.
 
virtual void send (Message &&msg)=0
 Sends a control message to the daemon.
 
virtual const Signalsig_terminated () const =0
 Retrieves the signal indicating the daemon is terminated.
 
virtual Status make_request (Request &&, Reply &&)=0
 Sends a request and waits for a reply in a daemon process.
 
template<typename TRequest , typename TReply >
Status request (const TRequest *req, TReply *rep)
 Helper: Sends a request and waits for a reply in a daemon process.
 
template<typename TRequest >
Status request (const TRequest *req)
 Helper: Sends a notification request – no reply required.
 

Detailed Description

Abstract interface for a daemon that runs in a separate thread.

A daemon is a process or thread that runs continuously in the background and handles periodic service messages and requests. This interface defines the minimum set of methods and signals that a derived class must implement, including starting, terminating, sending messages, requests, and signaling state changes.

Note
Daemons are non-copyable and non-movable to ensure unique ownership.
See also
Worker

Constructor & Destructor Documentation

◆ Daemon()

tec::Daemon::Daemon ( )
default

Default constructor.

Initializes a Daemon base class. Derived classes should provide specific initialization logic.

◆ ~Daemon()

virtual tec::Daemon::~Daemon ( )
virtualdefault

Virtual destructor for safe polymorphic deletion.

Ensures proper cleanup of derived classes.

Member Function Documentation

◆ make_request()

virtual Status tec::Daemon::make_request ( Request &&  ,
Reply &&   
)
pure virtual

Sends a request and waits for a reply in a daemon process.

This method sends a request of type Request to the daemon and waits for a corresponding reply of type TReply. It uses a signal to synchronize the operation and returns the status of the request processing.

Parameters
reqThe request object to be sent.
repThe reply object where the response will be stored.
Returns
Status The status of the request operation, indicating success or an error.
See also
Worker::make_request()

Implemented in tec::Worker< TParams >, and tec::Worker< Params >.

◆ request() [1/2]

template<typename TRequest >
Status tec::Daemon::request ( const TRequest req)
inline

Helper: Sends a notification request – no reply required.

See also
make_request()

◆ request() [2/2]

Status tec::Daemon::request ( const TRequest req,
TReply rep 
)
inline

Helper: Sends a request and waits for a reply in a daemon process.

This method sends a request of type TRequest to the daemon and waits for a corresponding reply of type TReply. It uses a signal to synchronize the operation and returns the status of the request processing. If the request cannot be sent, a runtime error status is returned.

Template Parameters
TRequestThe type of the request object.
TReplyThe type of the reply object.
Parameters
reqPointer to the request object to be sent.
repPointer to the reply object where the response will be stored.
Returns
Status The status of the request operation, indicating success or an error.
See also
make_request()

◆ run()

virtual Status tec::Daemon::run ( )
pure virtual

Starts the daemon's operation.

Initiates the daemon's background process or thread. Must be implemented by derived classes.

Returns
Status The result of the start operation.

Implemented in tec::Worker< TParams >, and tec::Worker< Params >.

◆ send()

virtual void tec::Daemon::send ( Message &&  msg)
pure virtual

Sends a control message to the daemon.

Allows external components to send a message to the daemon for processing. Must be implemented by derived classes.

Parameters
messageThe message to send.

Implemented in tec::Worker< TParams >, and tec::Worker< Params >.

◆ sig_terminated()

virtual const Signal & tec::Daemon::sig_terminated ( ) const
pure virtual

Retrieves the signal indicating the daemon is terminated.

Returns a reference to the signal that indicates the daemon has stopped. Must be implemented by derived classes.

Returns
const Signal& The termination signal.

Implemented in tec::Worker< TParams >, and tec::Worker< Params >.

◆ terminate()

virtual Status tec::Daemon::terminate ( )
pure virtual

Terminates the daemon's operation.

Stops the daemon's background process or thread. Must be implemented by derived classes.

Returns
Status The result of the termination operation.
See also
sig_terminated()

Implemented in tec::Worker< TParams >, and tec::Worker< Params >.


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