dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
Capture.hpp
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <memory>
13
14// Project includes
15#include "sinks/FileSink.hpp"
16#include "sinks/PipeSink.hpp"
17#include "sinks/TcpSink.hpp"
18#include <dfx-hooks/Graph.hpp>
19#include <dfx-hooks/Port.hpp>
20
21namespace dfx::Core
22{
23using NodeWPtr = std::weak_ptr<Node>;
24}
25
26namespace dfx::Pcapng
27{
28class Worker;
29
65class Capture : public Hooks::Port, public Hooks::Graph
66{
67public:
72 Capture(bool getHwAndOsInfo = true);
73
80
88 template<typename ... Args>
89 void setFileSink(Args && ... args)
90 { _setFileSinkImpl(std::make_unique<FileSink>(std::forward<Args>(args)...)); }
91
94
102 template<typename ... Args>
103 void setPipeSink(Args && ... args)
104 { _setPipeSinkImpl(std::make_unique<PipeSink>(std::forward<Args>(args)...)); }
105
108
116 template<typename ... Args>
117 void setTcpSink(Args && ... args)
118 { _setTcpSinkImpl(std::make_unique<TcpSink>(std::forward<Args>(args)...)); }
119
122
123public:
131 void setUserAppInfo(std::string info);
132
133public:
141 void onMessageSent(Core::OutputPort const & port, Core::Message const & message) override;
142
150 void onMessageReceived(Core::InputPort const & port, Core::Message const & message) override;
151
158 void onNodeCreated(Core::NodePtr node) override;
159
165 void onNodeRemoved(Core::NodePtr node) override;
166
171
172private:
173 void _setFileSinkImpl(SinkPtr sink);
174 void _setPipeSinkImpl(SinkPtr sink);
175 void _setTcpSinkImpl(SinkPtr sink);
176
177private:
178 std::unique_ptr<Worker> _worker;
179 std::vector<Core::NodeWPtr> _nodes;
180};
181} // !namespace dfx::Pcapng
Incoming message endpoint attached to a node.
Definition InputPort.hpp:55
Abstract base class for messages exchanged between nodes.
Definition Message.hpp:76
Outgoing message endpoint attached to a node.
Definition OutputPort.hpp:47
Hooks related to the lifecycle of graph objects (nodes and channels).
Definition Graph.hpp:54
Port-level message observation hook.
Definition Port.hpp:44
void setPipeSink(Args &&... args)
Enable pipe output using a PipeSink.
Definition Capture.hpp:103
void onChannelRemoved(Core::ChannelPtr) override
Graph hook: channel removal is currently ignored for capture.
Definition Capture.hpp:170
void setUserAppInfo(std::string info)
Set application-specific information to embed in the capture.
Capture(bool getHwAndOsInfo=true)
Construct a capture hook.
void unsetTcpSink()
Disable the TCP sink if enabled.
void onMessageSent(Core::OutputPort const &port, Core::Message const &message) override
Port hook: called when a message is sent from an output port.
void unsetPipeSink()
Disable the pipe sink if enabled.
void onChannelCreated(Core::ChannelPtr) override
Graph hook: channel creation is currently ignored for capture.
Definition Capture.hpp:168
void setFileSink(Args &&... args)
Enable file output using a FileSink.
Definition Capture.hpp:89
void onNodeRemoved(Core::NodePtr node) override
Graph hook: called when a node is removed.
void onNodeCreated(Core::NodePtr node) override
Graph hook: called when a node is created.
void setTcpSink(Args &&... args)
Enable TCP output using a TcpSink.
Definition Capture.hpp:117
void onMessageReceived(Core::InputPort const &port, Core::Message const &message) override
Port hook: called when a message is received by an input port.
void unsetFileSink()
Disable the file sink if enabled.
~Capture()
Destroy the capture hook and stop background capture work.
Background capture worker responsible for PCAPNG serialization and sink I/O.
Definition Worker.hpp:74
Definition Channel.hpp:22
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
Definition Capture.hpp:27
std::unique_ptr< Sink > SinkPtr
Owning pointer type for sinks.
Definition Sink.hpp:122