TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
Loading...
Searching...
No Matches
tec_actor.hpp
Go to the documentation of this file.
1// Time-stamp: <Last changed 2026-02-20 15:51:29 by magnolia>
2/*----------------------------------------------------------------------
3------------------------------------------------------------------------
4Copyright (c) 2020-2026 The Emacs Cat (https://github.com/olddeuteronomy/tec).
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17------------------------------------------------------------------------
18----------------------------------------------------------------------*/
39#pragma once
40
41#include "tec/tec_def.hpp" // IWYU pragma: keep
42#include "tec/tec_status.hpp"
43#include "tec/tec_signal.hpp"
44#include "tec/tec_message.hpp"
45
46
47namespace tec {
48
63class Actor {
64 public:
71 Actor() = default;
72
78 Actor(const Actor&) = delete;
79
85 Actor(Actor&&) = delete;
86
90 Actor& operator=(const Actor&) = delete;
91
95 Actor& operator=(Actor&&) = delete;
96
103 virtual ~Actor() = default;
104
128 virtual void start(Signal* sig_started, Status* status) = 0;
129
142 virtual void shutdown(Signal* sig_stopped) = 0;
143
166 virtual Status process_request(Request request, Reply reply) = 0;
167
168
172 virtual Status run() {
173 Status status;
174 Signal sig;
175 start(&sig, &status);
176 sig.wait();
177 return status;
178 }
179
183 virtual Status terminate() {
184 Signal sig;
185 shutdown(&sig);
186 sig.wait();
187 return {};
188 }
189
190
191 }; // class Actor
192
193} // namespace tec
Abstract base class defining the actor lifecycle and request handling interface.
Definition tec_actor.hpp:63
virtual void start(Signal *sig_started, Status *status)=0
Starts the actor's operation.
Actor & operator=(Actor &&)=delete
Deleted move assignment operator.
virtual ~Actor()=default
Virtual destructor.
Actor(const Actor &)=delete
Deleted copy constructor.
Actor & operator=(const Actor &)=delete
Deleted copy assignment operator.
virtual Status run()
Mimics Daemon's behavior.
Definition tec_actor.hpp:172
Actor()=default
Default constructor.
virtual void shutdown(Signal *sig_stopped)=0
Initiates graceful shutdown of the actor.
virtual Status process_request(Request request, Reply reply)=0
Processes a single request and produces a reply.
Actor(Actor &&)=delete
Deleted move constructor.
virtual Status terminate()
Mimics Daemon's behavior.
Definition tec_actor.hpp:183
A thread-safe signal mechanism for inter-thread synchronization.
Definition tec_signal.hpp:44
void wait() const
Waits indefinitely until the signal is set.
Definition tec_signal.hpp:85
Common definitions and utilities for the tec namespace.
Defines a flexible message type and helper functions for the tec namespace.
std::any Reply
Type alias for a reply object that can hold any object.
Definition tec_message.hpp:55
std::any Request
Type alias for a request object that can hold any object.
Definition tec_message.hpp:49
Defines a thread-safe signal implementation using mutex and condition variable.
Defines error handling types and utilities for the tec namespace.