|
TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
|
Abstract interface for a daemon that runs in a separate thread. More...
#include <tec_daemon.hpp>
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 Signal & | sig_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. | |
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.
|
default |
Default constructor.
Initializes a Daemon base class. Derived classes should provide specific initialization logic.
|
virtualdefault |
Virtual destructor for safe polymorphic deletion.
Ensures proper cleanup of derived classes.
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.
| req | The request object to be sent. |
| rep | The reply object where the response will be stored. |
Implemented in tec::Worker< TParams >, and tec::Worker< Params >.
Helper: Sends a notification request – no reply required.
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.
| TRequest | The type of the request object. |
| TReply | The type of the reply object. |
| req | Pointer to the request object to be sent. |
| rep | Pointer to the reply object where the response will be stored. |
Starts the daemon's operation.
Initiates the daemon's background process or thread. Must be implemented by derived classes.
Implemented in tec::Worker< TParams >, and tec::Worker< Params >.
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.
| message | The message to send. |
Implemented in tec::Worker< TParams >, and tec::Worker< Params >.
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.
Implemented in tec::Worker< TParams >, and tec::Worker< Params >.
Terminates the daemon's operation.
Stops the daemon's background process or thread. Must be implemented by derived classes.
Implemented in tec::Worker< TParams >, and tec::Worker< Params >.