dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
PluginInterface.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 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
31
32#ifdef __cplusplus
33extern "C"
34{
35#endif
36
37// Standard includes
38#include <stdint.h>
39#include <stddef.h>
40
45
47#define DFX_LOG_LEVEL_TRACE 0
49#define DFX_LOG_LEVEL_DEBUG 1
51#define DFX_LOG_LEVEL_INFO 2
53#define DFX_LOG_LEVEL_WARN 3
55#define DFX_LOG_LEVEL_ERROR 4
57#define DFX_LOG_LEVEL_CRITICAL 5
58
60
64
67
69typedef void * dfx_node_handle_t;
70
72typedef void * dfx_node_api_handle_t;
73
75typedef void * dfx_env_handle_t;
76
78typedef void * dfx_poller_handle_t;
79
81typedef void * dfx_message_handle_t;
82
85
87typedef void * dfx_task_handle_t;
88
91
93
104
106typedef uint32_t dfx_event_interest_t;
107
109#define DFX_EVENT_READ 0x01u
111#define DFX_EVENT_WRITE 0x02u
113#define DFX_EVENT_READ_CLOSE 0x04u
114
116#define DFX_EVENT_MASK (DFX_EVENT_READ | DFX_EVENT_WRITE | DFX_EVENT_READ_CLOSE)
117
119
125
127typedef uint32_t dfx_event_trigger_t;
128
130#define DFX_EVENT_READABLE 0x01u
132#define DFX_EVENT_WRITABLE 0x02u
134#define DFX_EVENT_PEER_CLOSED 0x04u
136#define DFX_EVENT_HANGUP 0x08u
138#define DFX_EVENT_ERROR 0x10u
139
141
145
147typedef uint32_t dfx_port_kind_t;
148
150#define DFX_KIND_INVALID UINT32_MAX
152#define DFX_KIND_DATA 0u
154#define DFX_KIND_CONTROL 1u
155
157
159#define DFX_OK 0
161#define DFX_ERROR -1
163#define DFX_INVALID_PORT_ID UINT32_MAX
165#define DFX_INVALID_SIZE SIZE_MAX
166
172typedef void (*dfx_fd_callback_t)(int fd, dfx_event_trigger_t events, void * user_data);
173
177typedef void (*dfx_callback_t)(void * user_data);
178
186typedef int (*dfx_on_message_received_t)(uint8_t const * message, size_t size, void * host_ctx);
187
189typedef struct
190{
192
198 void (*log)(dfx_env_handle_t handle, int level, char const * msg);
199
203 char const * (*get_plugin_dir)(dfx_env_handle_t handle);
205
211typedef struct
212{
214
238 int (*register_fd)(dfx_poller_handle_t handle, int fd, dfx_event_interest_t interests, dfx_fd_callback_t cb, void * user_data);
239
260
277
301
336
344typedef struct
345{
350
355
373 int (*push_task)(dfx_task_executor_handle_t handle, dfx_task_api_t const * task_api, size_t task_api_size);
375
384typedef struct
385{
388
400
411 int (*get_uuid)(dfx_message_handle_t handle, uint8_t out_uuid[16]);
412
423 int (*get_parent_uuid)(dfx_message_handle_t handle, uint8_t out_uuid[16]);
424
440 size_t (*get_mime_type)(dfx_message_handle_t handle, char * out_buf, size_t buf_size);
441
452 int (*get_timestamp)(dfx_message_handle_t handle, struct timespec * tp);
453
465
483 size_t (*get_path_step)(dfx_message_handle_t handle, size_t index, char * out_buf, size_t buf_size);
484
499 int (*get_data)(dfx_message_handle_t handle, uint8_t const ** out_data, size_t * out_size);
500
517 size_t (*get_ctrl_cmd)(dfx_message_handle_t handle, char * out_buf, size_t buf_size);
518
535 size_t (*get_ctrl_params)(dfx_message_handle_t handle, char * out_buf, size_t buf_size);
536
549
555typedef struct
556{
559
574
592
606
621 uint32_t (*register_input_port)(dfx_node_api_handle_t handle, char const * name,
622 char const ** mimes, size_t mimes_count);
623
637 uint32_t (*register_output_port)(dfx_node_api_handle_t handle, char const * name,
638 char const * mime_type);
639
661 int (*send_data)(dfx_node_api_handle_t handle, uint32_t port_id,
662 uint8_t const * data, size_t size, char const * mime_type,
663 dfx_message_handle_t parent);
664
678
692
708 int (*send_control)(dfx_node_api_handle_t handle, uint32_t port_id,
709 char const * cmd, char const * params_json, int version);
711
718typedef struct
719{
733 dfx_node_handle_t (*build)(char const * type, uint32_t id, char const * name, char const * config,
734 dfx_node_api_t const * node_api, size_t node_api_size);
735
740
751 int (*start)(dfx_node_handle_t node, dfx_poller_api_t const * poller, size_t poller_size);
752
759 void (*stop)(dfx_node_handle_t node);
760
772 int (*on_message)(dfx_node_handle_t node, uint32_t port_id,
773 dfx_message_api_t const * msg_api, size_t msg_api_size);
775
780typedef struct
781{
785
799 dfx_transport_handle_t (*build_source)(char const * scheme, char const * address,
800 char const * node, char const * port, char const * config,
801 dfx_on_message_received_t on_message_received, void * host_ctx);
802
814 dfx_transport_handle_t (*build_destination)(char const * scheme, char const * address,
815 char const * node, char const * port, char const * config);
816
818
823
827
837 int (*start)(dfx_transport_handle_t handle, dfx_poller_api_t const * poller, size_t poller_size);
838
843
845
849
857 int (*transmit_message)(dfx_transport_handle_t handle, uint8_t const * message, size_t length);
858
868
871
881typedef struct
882{
885
903 dfx_transport_interface_t const * transport_interface, size_t transport_interface_size);
904
921 char const * node_metadata, char const * config_schema,
922 dfx_node_interface_t const * node_interface, size_t node_interface_size);
924
926#define DFX_PLUGIN_VISIBLE_ATTR __attribute__((visibility("default")))
927
929#define DFX_PLUGIN_METADATA(json_str) __attribute__((section(".dfx_metadata"), used)) \
930 char const _dfx_metadata_blob[] = json_str
931
935
952 dfx_registration_api_t const * reg, size_t reg_size,
953 char const * plugin_config, char const * base_path);
954
966DFX_PLUGIN_VISIBLE_ATTR void dfx_deinit_plugin(dfx_env_api_t const * env, size_t env_size);
967
969
970#ifdef __cplusplus
971} // !extern "C"
972#endif
DFX_PLUGIN_VISIBLE_ATTR int dfx_init_plugin(dfx_env_api_t const *env, size_t env_size, dfx_registration_api_t const *reg, size_t reg_size, char const *plugin_config, char const *base_path)
Main entry point to initialize the plugin.
DFX_PLUGIN_VISIBLE_ATTR void dfx_deinit_plugin(dfx_env_api_t const *env, size_t env_size)
Cleanup entry point called before the plugin is unloaded.
uint32_t dfx_event_trigger_t
C-compatible event triggers matching dfx::FdWatch::EventTriggers.
Definition PluginInterface.h:127
void(* dfx_fd_callback_t)(int fd, dfx_event_trigger_t events, void *user_data)
Callback signature for file descriptor events.
Definition PluginInterface.h:172
void * dfx_message_handle_t
Opaque handle representing a message instance created by the host.
Definition PluginInterface.h:81
void * dfx_env_handle_t
Opaque handle representing the env context created by the host.
Definition PluginInterface.h:75
void * dfx_task_handle_t
Opaque handle representing a task instance created by the host.
Definition PluginInterface.h:87
uint32_t dfx_event_interest_t
C-compatible event triggers matching dfx::FdWatch::EventInterests.
Definition PluginInterface.h:106
void * dfx_task_executor_handle_t
Opaque handle representing a custom node executor created by the plugin.
Definition PluginInterface.h:90
void(* dfx_callback_t)(void *user_data)
General purpose callback signature.
Definition PluginInterface.h:177
uint32_t dfx_port_kind_t
C-compatible kind matching dfx::Core::Kind.
Definition PluginInterface.h:147
void * dfx_node_api_handle_t
Opaque handle representing a node instance created by the host.
Definition PluginInterface.h:72
void * dfx_registration_handle_t
Opaque handle representing a registration instance created by the host.
Definition PluginInterface.h:84
void * dfx_poller_handle_t
Opaque handle representing the poller instance created by the host.
Definition PluginInterface.h:78
void * dfx_node_handle_t
Opaque handle representing a node instance created by the plugin.
Definition PluginInterface.h:69
#define DFX_PLUGIN_VISIBLE_ATTR
Used to mark a symbol as exported a.k.a. visible.
Definition PluginInterface.h:926
int(* dfx_on_message_received_t)(uint8_t const *message, size_t size, void *host_ctx)
Callback signature for Source transport plugins to push data to the host.
Definition PluginInterface.h:186
void * dfx_transport_handle_t
Opaque handle representing a transport instance created by the plugin.
Definition PluginInterface.h:66
Host environment services provided to the plugin.
Definition PluginInterface.h:190
void(* log)(dfx_env_handle_t handle, int level, char const *msg)
Log a message through the host's logging system.
Definition PluginInterface.h:198
dfx_env_handle_t handle
Host-specific context.
Definition PluginInterface.h:191
Host-provided API for interrogating message handles.
Definition PluginInterface.h:385
int(* get_timestamp)(dfx_message_handle_t handle, struct timespec *tp)
Gets the wall-clock timestamp of when the message was created.
Definition PluginInterface.h:452
size_t(* get_ctrl_cmd)(dfx_message_handle_t handle, char *out_buf, size_t buf_size)
Copies the dfx::Core::ControlMessage command string.
Definition PluginInterface.h:517
size_t(* get_mime_type)(dfx_message_handle_t handle, char *out_buf, size_t buf_size)
Copies the MIME type string into a plugin-provided buffer.
Definition PluginInterface.h:440
int(* get_parent_uuid)(dfx_message_handle_t handle, uint8_t out_uuid[16])
Gets the UUID of the message's parent (for lineage tracking).
Definition PluginInterface.h:423
int(* get_ctrl_version)(dfx_message_handle_t handle)
Provides the version used for this dfx::Core::ControlMessage.
Definition PluginInterface.h:547
size_t(* get_path_step)(dfx_message_handle_t handle, size_t index, char *out_buf, size_t buf_size)
Copies a specific step in the message's traversal path.
Definition PluginInterface.h:483
dfx_port_kind_t(* get_kind)(dfx_message_handle_t handle)
Query the kind of the message.
Definition PluginInterface.h:399
size_t(* get_path_count)(dfx_message_handle_t handle)
Get the number of endpoints this message has traversed.
Definition PluginInterface.h:464
int(* get_uuid)(dfx_message_handle_t handle, uint8_t out_uuid[16])
Gets the unique identifier (UUID) of the message.
Definition PluginInterface.h:411
int(* get_data)(dfx_message_handle_t handle, uint8_t const **out_data, size_t *out_size)
Provides a direct view into the raw data payload.
Definition PluginInterface.h:499
dfx_message_handle_t handle
The borrowed handle to the message being interrogated.
Definition PluginInterface.h:387
size_t(* get_ctrl_params)(dfx_message_handle_t handle, char *out_buf, size_t buf_size)
Provides a direct view into the dfx::Core::ControlMessage parameters (JSON).
Definition PluginInterface.h:535
Host-provided services for a node instance.
Definition PluginInterface.h:556
int(* send_control)(dfx_node_api_handle_t handle, uint32_t port_id, char const *cmd, char const *params_json, int version)
Produces and sends a ControlMessage.
Definition PluginInterface.h:708
int(* revoke_task_executor)(dfx_node_api_handle_t handle)
Revokes the current custom task executor.
Definition PluginInterface.h:605
int(* notify_stopped)(dfx_node_api_handle_t handle)
Notifies the host that the node has finished its internal cleanup.
Definition PluginInterface.h:573
uint32_t(* register_control_output_port)(dfx_node_api_handle_t handle, char const *name)
Registers a control-plane output port.
Definition PluginInterface.h:691
uint32_t(* register_input_port)(dfx_node_api_handle_t handle, char const *name, char const **mimes, size_t mimes_count)
Registers a data-plane input port.
Definition PluginInterface.h:621
dfx_node_api_handle_t handle
Opaque handle representing the host-side node context (CNode instance).
Definition PluginInterface.h:558
int(* send_data)(dfx_node_api_handle_t handle, uint32_t port_id, uint8_t const *data, size_t size, char const *mime_type, dfx_message_handle_t parent)
Produces and sends a dfx::Core::DataMessage.
Definition PluginInterface.h:661
int(* assign_task_executor)(dfx_node_api_handle_t handle, dfx_task_executor_interface_t const *executor, size_t executor_size)
Assigns a custom task executor to this node.
Definition PluginInterface.h:591
uint32_t(* register_control_input_port)(dfx_node_api_handle_t handle, char const *name)
Registers a control-plane input port.
Definition PluginInterface.h:677
uint32_t(* register_output_port)(dfx_node_api_handle_t handle, char const *name, char const *mime_type)
Registers a data-plane output port.
Definition PluginInterface.h:637
The vtable that a plugin must implement to define a Node.
Definition PluginInterface.h:719
void(* stop)(dfx_node_handle_t node)
Requests the node to stop processing.
Definition PluginInterface.h:759
void(* destroy)(dfx_node_handle_t node)
Destroys the node instance and frees associated plugin memory.
Definition PluginInterface.h:739
int(* start)(dfx_node_handle_t node, dfx_poller_api_t const *poller, size_t poller_size)
Requests the node to start processing.
Definition PluginInterface.h:751
int(* on_message)(dfx_node_handle_t node, uint32_t port_id, dfx_message_api_t const *msg_api, size_t msg_api_size)
Called by the host when a message arrives on an input port.
Definition PluginInterface.h:772
dfx_node_handle_t(* build)(char const *type, uint32_t id, char const *name, char const *config, dfx_node_api_t const *node_api, size_t node_api_size)
Instantiates a new node.
Definition PluginInterface.h:733
Interface to the host's event loop (Poller).
Definition PluginInterface.h:212
int(* register_fd)(dfx_poller_handle_t handle, int fd, dfx_event_interest_t interests, dfx_fd_callback_t cb, void *user_data)
Registers a file descriptor with the host's poller.
Definition PluginInterface.h:238
void(* deregister_fd)(dfx_poller_handle_t handle, int fd)
Deregisters a file descriptor from the host's poller.
Definition PluginInterface.h:276
int(* defer_call)(dfx_poller_handle_t handle, dfx_callback_t cb, void *user_data)
Defers a function call to the next iteration of the event loop.
Definition PluginInterface.h:299
int(* update_fd)(dfx_poller_handle_t handle, int fd, dfx_event_interest_t interests)
Updates the event interests for a previously registered file descriptor.
Definition PluginInterface.h:259
dfx_poller_handle_t handle
Internal host context. Must be passed as the first argument to all functions.
Definition PluginInterface.h:213
Transient registration context used during plugin discovery.
Definition PluginInterface.h:882
int(* register_node)(dfx_registration_handle_t handle, char const *type, char const *node_metadata, char const *config_schema, dfx_node_interface_t const *node_interface, size_t node_interface_size)
Registers a node type with the host.
Definition PluginInterface.h:920
dfx_registration_handle_t handle
Internal host context. Must be passed as the first argument to registration functions.
Definition PluginInterface.h:884
int(* register_transport)(dfx_registration_handle_t handle, char const *scheme, dfx_transport_interface_t const *transport_interface, size_t transport_interface_size)
Registers a transport scheme with the host.
Definition PluginInterface.h:902
Host-provided API for interacting with a scheduled task.
Definition PluginInterface.h:308
int(* get_priority)(dfx_task_handle_t handle)
Retrieves the execution priority of the task.
Definition PluginInterface.h:317
dfx_task_handle_t handle
Opaque handle to the host's internal task representation.
Definition PluginInterface.h:310
int(* run)(dfx_task_handle_t handle)
Executes the task's payload.
Definition PluginInterface.h:334
Interface for a plugin-defined task executor.
Definition PluginInterface.h:345
dfx_task_executor_handle_t(* build)(void)
Instantiates the plugin's internal executor state.
Definition PluginInterface.h:349
int(* push_task)(dfx_task_executor_handle_t handle, dfx_task_api_t const *task_api, size_t task_api_size)
Enqueues a task for execution within the plugin's context.
Definition PluginInterface.h:373
void(* destroy)(dfx_task_executor_handle_t handle)
Destroys the executor instance and frees associated memory.
Definition PluginInterface.h:354
The Transport Plugin Interface.
Definition PluginInterface.h:781
int(* start)(dfx_transport_handle_t handle, dfx_poller_api_t const *poller, size_t poller_size)
Activates the transport.
Definition PluginInterface.h:837
void(* stop)(dfx_transport_handle_t handle)
Deactivates the transport. Should unregister all FDs from the poller.
Definition PluginInterface.h:842
void(* destroy)(dfx_transport_handle_t handle)
Permanently destroys a transport and releases its memory.
Definition PluginInterface.h:822
dfx_transport_handle_t(* build_source)(char const *scheme, char const *address, char const *node, char const *port, char const *config, dfx_on_message_received_t on_message_received, void *host_ctx)
Creates a new Source transport instance.
Definition PluginInterface.h:799
dfx_transport_handle_t(* build_destination)(char const *scheme, char const *address, char const *node, char const *port, char const *config)
Creates a new Destination transport instance.
Definition PluginInterface.h:814
int(* transmit_message)(dfx_transport_handle_t handle, uint8_t const *message, size_t length)
Sends a message using a Destination transport.
Definition PluginInterface.h:857
int64_t(* pending_message_count)(dfx_transport_handle_t handle)
Returns the number of messages currently buffered in the transport.
Definition PluginInterface.h:867