Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
mads_rust_plugin.h
Go to the documentation of this file.
1/*
2 MADS Rust Plugin ABI
3 ====================
4 C header defining the vtable that every Rust (or plain-C) plugin must export.
5
6 The sole exported symbol is:
7 const mads_rust_plugin_t *mads_rust_plugin_register(void);
8
9 It returns a pointer to a static vtable. Per-instance state lives in the
10 opaque void* returned by create() and freed by destroy().
11
12 Output buffers (output_json, output_blob, last_error, get_info) are owned by
13 the plugin instance and remain valid until the next call on that instance.
14 The loader never frees them directly.
15*/
16#pragma once
17#include <stddef.h>
18#include <stdint.h>
19
20#define MADS_RUST_PLUGIN_VERSION 1
21
22/* Return codes — mirror Mads::return_type */
23typedef int mads_return_t;
24#define MADS_SUCCESS 0
25#define MADS_RETRY 1
26#define MADS_WARNING 2
27#define MADS_ERROR 3
28#define MADS_CRITICAL 4
29
30typedef struct mads_rust_plugin_t {
31 /* Must equal MADS_RUST_PLUGIN_VERSION; loader rejects mismatches. */
33
34 /* Static null-terminated strings identifying the plugin. */
35 const char *name; /* e.g. "my_filter" */
36 const char *kind; /* "source" | "filter" | "sink" */
37
38 /* ── Lifecycle ─────────────────────────────────────────────────────────── */
39 void *(*create)(void);
40 void (*destroy)(void *self);
41
42 /* ── Configuration ─────────────────────────────────────────────────────── */
43 /* Called once after create() with a JSON settings object (UTF-8, not NUL-
44 terminated; use json_len). */
45 void (*set_params)(void *self, const char *json, size_t json_len);
46
47 /* ── Metadata ──────────────────────────────────────────────────────────── */
48 /* Returns a JSON object {"key":"value",...} in an internal buffer.
49 Valid until the next call on this instance. */
50 const char *(*get_info)(void *self);
51
52 /* ── Source-only ───────────────────────────────────────────────────────── */
53 /* Returns the blob MIME/format string, NUL-terminated, owned by the plugin
54 instance and valid until the next call on it. May be NULL or "".
55 Callers must tolerate NULL; implementations must never return a pointer to
56 a non-NUL-terminated buffer (e.g. a Rust &str). */
57 const char *(*blob_format)(void *self);
58
59 /* Produce one output frame. Output is accessed via output_json / output_blob
60 accessors below. NULL for filter and sink plugins. */
61 mads_return_t (*get_output)(void *self);
62
63 /* ── Filter + Sink ─────────────────────────────────────────────────────── */
64 /* Load an incoming frame.
65 - json_in : serialised JSON frame (UTF-8), length json_len
66 - topic : NUL-terminated pub-sub topic string
67 - blob_in : optional binary blob (NULL when none)
68 - blob_in_len : byte length of blob_in */
69 mads_return_t (*load_data)(void *self,
70 const char *json_in, size_t json_len,
71 const char *topic,
72 const uint8_t *blob_in, size_t blob_in_len);
73
74 /* ── Filter-only ───────────────────────────────────────────────────────── */
75 /* Transform the last loaded frame into an output frame.
76 Output is accessed via output_json / output_blob accessors.
77 NULL for source and sink plugins. */
78 mads_return_t (*process)(void *self);
79
80 /* ── Output accessors ──────────────────────────────────────────────────── */
81 /* Valid after a successful get_output() or process() call.
82 Buffers are owned by the plugin instance; do not free them. */
83 const char *(*output_json)(void *self);
84 size_t (*output_json_len)(void *self);
85 const uint8_t *(*output_blob)(void *self); /* NULL when no blob */
86 size_t (*output_blob_len)(void *self);
87
88 /* ── Error accessor ────────────────────────────────────────────────────── */
89 /* NUL-terminated string valid after any non-success return code. */
90 const char *(*last_error)(void *self);
91
92 /* ── Timing hint ───────────────────────────────────────────────────────── */
93 /* Milliseconds the loader should wait before the next iteration.
94 -1 : free-run (let the loop decide)
95 0 : as fast as possible
96 >0 : sleep this many ms */
97 long (*next_loop_ms)(void *self);
99
100/* ── Entry point ─────────────────────────────────────────────────────────── */
101/* Every Rust plugin .so must export exactly this symbol. */
102#ifdef __cplusplus
103extern "C"
104#endif
nlohmann::json json
Definition bridge.hpp:24
int mads_return_t
const mads_rust_plugin_t * mads_rust_plugin_register(void)
size_t(* output_blob_len)(void *self)
mads_return_t(* get_output)(void *self)
void(* destroy)(void *self)
mads_return_t(* load_data)(void *self, const char *json_in, size_t json_len, const char *topic, const uint8_t *blob_in, size_t blob_in_len)
void(* set_params)(void *self, const char *json, size_t json_len)
size_t(* output_json_len)(void *self)
long(* next_loop_ms)(void *self)
mads_return_t(* process)(void *self)