dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
FileSink.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 <fstream>
13
14// Project includes
15#include <dfx-core/Node.hpp>
17#include <dfx-utilities/FileSystem.hpp>
18
19namespace dfx::Node
20{
21class FileSink : public Core::Node
22{
23 DFX_NODE("FileSink")
24
25public:
26 enum class Mode
27 {
28 Append,
29 Truncate,
30 };
31
32public:
33 FileSink(Id id, std::string name);
34
35protected:
36 void startImpl() override;
37
38 void initializeImpl(nlohmann::json config) override;
39 void handleMessage(Core::InputPort const & port, Core::MessagePtr message) override;
40
41private:
42 fs::path _path;
43 Mode _mode = Mode::Append;
44 bool _flushAfterWrite = false;
45 bool _appendNewline = false;
46
47private:
48 std::ofstream _ofs;
49};
50} // !namespace dfx::Node
51
52DECLARE_ENUM_STRING_FUNCTIONS(dfx::Node::FileSink::Mode);
Macro-based enum <-> string utilities for dfx.
#define DECLARE_ENUM_STRING_FUNCTIONS(E)
Declare the enum string API (and std::formatter) for enum type E.
Definition EnumString.hpp:327
Base class for all runtime-executed nodes in a dfx dataflow graph.
#define DFX_NODE(typeName)
Convenience macro to declare the node type string and metadata/schema hooks.
Definition Node.hpp:501
Incoming message endpoint attached to a node.
Definition InputPort.hpp:55
Abstract base class for all nodes in the dfx runtime.
Definition Node.hpp:91
uint32_t Id
Node identifier type (unique and stable within a graph instance).
Definition Node.hpp:113
nlohmann::json const & config() const noexcept
Get the node configuration.
Definition Node.hpp:138
std::string const & name() const noexcept
Get the node name.
Definition Node.hpp:134
void startImpl() override
Called by start before the node is marked running.
void initializeImpl(nlohmann::json config) override
Called by initialize; derived nodes must parse config here.
void handleMessage(Core::InputPort const &port, Core::MessagePtr message) override
Handle an incoming message on an input port.
std::unique_ptr< Message > MessagePtr
Unique ownership handle for messages.
Definition Message.hpp:27
Definition MimeTypeRouter.hpp:18