15#include "FdListener.hpp"
16#include "ThreadPool.hpp"
17#include <dfx-fdwatch/BorrowedFd.hpp>
18#include <dfx-fdwatch/OwnedFd.hpp>
19#include <dfx-hooks/Delivery.hpp>
20#include <dfx-hooks/Graph.hpp>
21#include <dfx-runtime-api/NodeReactor.hpp>
23#include <dfx-utilities/SystemConfig.hpp>
104 using FdDatas = std::vector<FdData>;
130 { _threadPool.emplaceTask<T>(std::forward<Args>(args)...); }
134 { _threadPool.pushTask(std::move(task)); }
231 std::atomic_bool _isRunning =
false;
234 std::atomic_uint32_t _maxNesting = 0;
237 std::list<Core::NodeWPtr> _nodes;
238 std::mutex _nodeMutex;
242 mutable std::mutex _fdMutex;
Convenience macros to explicitly control copy and move semantics.
Outgoing message endpoint attached to a node.
Definition OutputPort.hpp:47
Non-owning wrapper around a file descriptor.
Definition BorrowedFd.hpp:37
Hook interface invoked around message enqueue in an dfx::Core::Channel.
Definition Delivery.hpp:50
HookResult
Result code controlling pushMessage() behavior.
Definition Delivery.hpp:74
Hooks related to the lifecycle of graph objects (nodes and channels).
Definition Graph.hpp:54
Node-aware reactor API for FD watching and deferred execution in the runtime.
Definition NodeReactor.hpp:59
Background FD event listener running its own polling thread.
Definition FdListener.hpp:50
void start()
Start all known nodes.
void onChannelCreated(Core::ChannelPtr channel) override
Graph hook invoked when a channel is created.
void deregisterNodeFd(FdWatch::BorrowedFd fd) noexcept override
Deregister a previously registered FD.
HookResult postDelivery(Core::NodePtr src, Core::OutputPort const &out, Core::NodePtr dst, Core::InputPort &in) override
Delivery hook executed after a message has been enqueued into a channel.
void onNodeCreated(Core::NodePtr node) override
Graph hook invoked when a node is created.
void stop()
Stop all known nodes.
void onNodeRemoved(Core::NodePtr node) override
Graph hook invoked when a node is removed.
~Scheduler() override
Destroy the scheduler and stop it if running.
void pushTask(TaskPtr task)
Submit an already-constructed task to the worker pool.
Definition Scheduler.hpp:133
void emplaceTask(Args &&... args)
Convenience helper to construct and submit a task directly to the worker pool.
Definition Scheduler.hpp:129
void registerNodeFd(FdWatch::BorrowedFd fd, FdWatch::EventInterests events, FdWatch::FdCallback cb, Core::NodeWPtr node) override
Register an FD watch on behalf of a node.
bool isRunning() const noexcept
Whether the runtime is currently started.
Definition Scheduler.hpp:150
HookResult preDelivery(Core::NodePtr src, Core::OutputPort const &out, Core::NodePtr dst, Core::InputPort &in, Core::MessagePtr &message) override
Delivery hook executed before a message is enqueued into a channel.
void deferNodeCall(FdWatch::Callback cb, Core::NodeWPtr node) override
Defer a callback to execute under the node lock on a worker thread.
void onChannelRemoved(Core::ChannelPtr channel) override
Graph hook invoked when a channel is removed.
Scheduler(Utils::SystemConfig &sysConfig)
Construct a scheduler and register runtime settings into sysConfig.
DISABLE_COPY_AND_MOVE(Scheduler)
Scheduler is neither copyable nor movable.
Runtime thread pool executing Task instances with priorities and FIFO ordering.
Definition ThreadPool.hpp:56
System configuration registry with typed values, entry metadata, and change callbacks.
Definition SystemConfig.hpp:81
Convenience concept for constraining templates to Task-derived types.
Definition Task.hpp:24
std::unique_ptr< Message > MessagePtr
Unique ownership handle for messages.
Definition Message.hpp:27
std::shared_ptr< Node > NodePtr
Shared ownership pointer type for Nodes..
Definition Node.hpp:61
std::weak_ptr< Node > NodeWPtr
Weak pointer type for Nodes.
Definition Node.hpp:63
std::shared_ptr< Channel > ChannelPtr
Shared ownership handle for channels.
Definition Channel.hpp:147
std::function< void(BorrowedFd, EventTriggers)> FdCallback
Invoked when events occur on a watched file descriptor.
Definition Callback.hpp:28
std::move_only_function< void()> Callback
Generic move-only callback with no arguments.
Definition Callback.hpp:31
std::unique_ptr< Task > TaskPtr
Unique ownership pointer for tasks.
Definition Task.hpp:102