Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
agent_c.h
Go to the documentation of this file.
1/*
2 _ _
3 / \ __ _ ___ _ __ | |_
4 / _ \ / _` |/ _ \ '_ \| __|
5 / ___ \ (_| | __/ | | | |_
6 /_/ \_\__, |\___|_| |_|\__|
7 |___/
8 ____ __ __
9 / ___| \ \ / / __ __ _ _ __ _ __ ___ _ __
10 | | ____\ \ /\ / / '__/ _` | '_ \| '_ \ / _ \ '__|
11 | |__|_____\ V V /| | | (_| | |_) | |_) | __/ |
12 \____| \_/\_/ |_| \__,_| .__/| .__/ \___|_|
13 |_| |_|
14
15Wrapper for Agent class in pure C
16Author(s): Paolo Bosetti
17*/
18#ifndef AGENT_C_WRAPPER_HPP
19#define AGENT_C_WRAPPER_HPP
20#ifdef __cplusplus
21extern "C" {
22#endif
23#include <stdbool.h>
24#include <stdlib.h>
25
26#ifdef _WIN32
27#define MADS_EXPORT __declspec(dllexport)
28#else
29#define MADS_EXPORT
30#endif
31
32/*
33 _ _ _
34 | | (_) |__ _ __ __ _ _ __ _ _
35 | | | | '_ \| '__/ _` | '__| | | |
36 | |___| | |_) | | | (_| | | | |_| |
37 |_____|_|_.__/|_| \__,_|_| \__, |
38 |___/
39*/
46
53
62MADS_EXPORT void mads_free(void *ptr);
63
64/*
65 ____ _
66 / ___| | __ _ ___ ___
67 | | | |/ _` / __/ __|
68 | |___| | (_| \__ \__ \
69 \____|_|\__,_|___/___/
70
71Class-like opaque struct
72*/
73typedef void *agent_t;
74
81
90
91/*
92 _ _ __ _
93 | | (_)/ _| ___ ___ _ _ ___| | ___
94 | | | | |_ / _ \/ __| | | |/ __| |/ _ \
95 | |___| | _| __/ (__| |_| | (__| | __/
96 |_____|_|_| \___|\___|\__, |\___|_|\___|
97 |___/
98*/
106MADS_EXPORT agent_t agent_create(const char *name, const char *settings_uri);
107
134MADS_EXPORT int agent_init(agent_t agent, bool crypto);
135
144
151MADS_EXPORT void agent_set_id(agent_t agent, const char *id);
152
159MADS_EXPORT const char *agent_id(agent_t agent);
160
167
168/*
169 ___ _ _
170 / _ \ _ __ ___ _ __ __ _| |_(_) ___ _ __ ___
171 | | | | '_ \ / _ \ '__/ _` | __| |/ _ \| '_ \/ __|
172 | |_| | |_) | __/ | | (_| | |_| | (_) | | | \__ \
173 \___/| .__/ \___|_| \__,_|\__|_|\___/|_| |_|___/
174 |_|
175*/
176
177// Crypto
184MADS_EXPORT void agent_set_key_dir(agent_t agent, const char *key_dir);
185
192MADS_EXPORT void agent_set_client_key_name(agent_t agent, const char *client_key_name);
193
200MADS_EXPORT void agent_set_server_key_name(agent_t agent, const char *server_key_name);
201
209
221
234
246
259MADS_EXPORT int agent_setup_crypto(agent_t agent, bool verbose);
260
261// Std ops
271MADS_EXPORT int agent_connect(agent_t agent, int delay_ms);
272
284 const char *info_json);
285
295
307
321
328
336
344
352
359
360// Settings
368MADS_EXPORT const char *agent_get_settings(agent_t agent, int n);
369
378
386MADS_EXPORT void agent_set_pub_topic(agent_t agent, const char *topic);
387
396MADS_EXPORT void agent_set_sub_topics(agent_t agent, const char **topics, int n_topics);
397
405
416MADS_EXPORT int agent_sub_topics(agent_t agent, char **topics, size_t *n_topics);
417
418
419MADS_EXPORT char *agent_topics(agent_t agent, int tab);
420
428
446MADS_EXPORT int discover_broker_settings(const char *room, char **url,
447 size_t url_size);
448
456MADS_EXPORT bool agent_setting_bool(agent_t agent, const char *key);
457
465MADS_EXPORT int agent_setting_int(agent_t agent, const char *key);
466
474MADS_EXPORT double agent_setting_dbl(agent_t agent, const char *key);
475
484MADS_EXPORT const char *agent_setting_str(agent_t agent, const char *key);
485
493
501
510
518
527
535
543MADS_EXPORT int agent_set_compression(agent_t agent, int compression);
544
552
553// Messaging
564MADS_EXPORT int agent_publish(agent_t agent, const char *message, const char *topic);
565
575
586MADS_EXPORT void agent_last_message(agent_t agent, char **topic, char **message);
587
588#ifdef __cplusplus
589}
590#endif
591#endif // AGENT_C_WRAPPER_HPP
MADS_EXPORT bool mads_process_running(void)
Whether a process-wide stop has been requested.
MADS_EXPORT void agent_set_client_key_name(agent_t agent, const char *client_key_name)
Sets the client key filename.
MADS_EXPORT int agent_set_settings_timeout(agent_t agent, int to_ms)
Sets the timeout used when fetching settings.
MADS_EXPORT void mads_free(void *ptr)
Releases memory allocated by the MADS C API.
MADS_EXPORT void agent_set_receive_timeout(agent_t agent, int timeout)
Sets the receive timeout in milliseconds.
MADS_EXPORT int agent_sub_topics(agent_t agent, char **topics, size_t *n_topics)
Return subscription topics for the agent.
MADS_EXPORT void agent_destroy(agent_t agent)
Destroys an agent instance.
MADS_EXPORT int agent_set_server_public_key(agent_t agent, const char *key)
Sets the server public key.
MADS_EXPORT const char * mads_default_settings_uri()
Returns the default settings URI compiled into the library.
MADS_EXPORT void agent_print_settings(agent_t agent, int tab)
Prints the current settings JSON to standard output.
MADS_EXPORT double agent_setting_dbl(agent_t agent, const char *key)
Reads a floating-point setting.
MADS_EXPORT bool agent_setting_bool(agent_t agent, const char *key)
Reads a boolean setting.
MADS_EXPORT const char * agent_settings_uri(agent_t agent)
Returns the current settings URI.
event_type_t
Definition agent_c.h:82
@ mads_shutdown
Definition agent_c.h:87
@ mads_message
Definition agent_c.h:88
@ mads_marker_out
Definition agent_c.h:85
@ mads_startup
Definition agent_c.h:86
@ mads_marker
Definition agent_c.h:83
@ mads_marker_in
Definition agent_c.h:84
MADS_EXPORT int agent_set_compression(agent_t agent, int compression)
Sets the outgoing compression policy.
MADS_EXPORT bool agent_running(agent_t agent)
Whether this agent's loops should keep going.
MADS_EXPORT int agent_set_wire_format(agent_t agent, int format)
Sets the outgoing wire format.
MADS_EXPORT const char * agent_setting_str(agent_t agent, const char *key)
Reads a string setting.
MADS_EXPORT int agent_settings_timeout(agent_t agent)
Returns the current settings timeout.
MADS_EXPORT const char * agent_id(agent_t agent)
Returns the current agent identifier.
#define MADS_EXPORT
Definition agent_c.h:29
MADS_EXPORT void agent_set_pub_topic(agent_t agent, const char *topic)
Sets the publish topic for the agent.
MADS_EXPORT int agent_set_client_public_key(agent_t agent, const char *key)
Sets the client public key.
MADS_EXPORT agent_t agent_create(const char *name, const char *settings_uri)
Creates a new agent instance.
MADS_EXPORT void agent_set_auth_verbose(agent_t agent, bool verbose)
Enables or disables verbose authentication logging.
MADS_EXPORT int agent_set_client_secret_key(agent_t agent, const char *key)
Sets the client secret key.
message_type_t
Definition agent_c.h:75
@ mads_none
Definition agent_c.h:76
@ mads_json
Definition agent_c.h:77
@ mads_blob
Definition agent_c.h:78
@ mads_error
Definition agent_c.h:79
MADS_EXPORT const char * agent_last_error()
Returns the last error message produced by the wrapper.
MADS_EXPORT int agent_setup_crypto(agent_t agent, bool verbose)
Enables CURVE encryption and sets up authentication.
MADS_EXPORT int agent_init(agent_t agent, bool crypto)
Initializes an agent before connecting it.
MADS_EXPORT char * agent_topics(agent_t agent, int tab)
MADS_EXPORT const char * agent_pub_topic(agent_t agent)
Return publishing topic for the agent.
MADS_EXPORT int agent_wire_format(agent_t agent)
Returns the outgoing wire format.
MADS_EXPORT void agent_install_loop_watchdog(agent_t agent)
Installs the internal loop watchdog for the agent.
MADS_EXPORT int agent_compression(agent_t agent)
Returns the outgoing compression policy.
MADS_EXPORT int agent_setting_int(agent_t agent, const char *key)
Reads an integer setting.
MADS_EXPORT void agent_last_message(agent_t agent, char **topic, char **message)
Returns the topic and payload of the last received message.
MADS_EXPORT void mads_stop_process(void)
Requests a process-wide stop.
MADS_EXPORT void agent_set_key_dir(agent_t agent, const char *key_dir)
Sets the directory containing authentication keys.
void * agent_t
Definition agent_c.h:73
MADS_EXPORT int agent_connect(agent_t agent, int delay_ms)
Connects the agent to the MADS infrastructure.
MADS_EXPORT int agent_publish(agent_t agent, const char *message, const char *topic)
Publishes a JSON message on a topic.
MADS_EXPORT int agent_set_high_watermark(agent_t agent, int n)
Sets the outgoing message high watermark.
MADS_EXPORT void agent_set_server_key_name(agent_t agent, const char *server_key_name)
Sets the server key filename.
MADS_EXPORT int agent_receive_timeout(agent_t agent)
Returns the current receive timeout.
MADS_EXPORT void agent_set_id(agent_t agent, const char *id)
Sets the agent identifier.
MADS_EXPORT const char * agent_get_settings(agent_t agent, int n)
Serializes the current settings to JSON.
MADS_EXPORT int agent_disconnect(agent_t agent)
Disconnects the agent if it is connected.
MADS_EXPORT const char * mads_version()
Returns the MADS library version string.
MADS_EXPORT int agent_stop(agent_t agent)
Requests this agent's loops to stop.
MADS_EXPORT int discover_broker_settings(const char *room, char **url, size_t url_size)
Discovers the broker settings URI advertised in a service room.
MADS_EXPORT int agent_high_watermark(agent_t agent)
Returns the outgoing message high watermark.
MADS_EXPORT void agent_set_sub_topics(agent_t agent, const char **topics, int n_topics)
Sets the subscribe topics for the agent.
MADS_EXPORT message_type_t agent_receive(agent_t agent, bool dont_block)
Receives the next incoming message.
MADS_EXPORT int agent_register_event(agent_t agent, event_type_t event, const char *info_json)
Registers an event for the connected agent.