#ifndef NET_MESHOS_H
#define NET_MESHOS_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define NET_MESHOS_OK 0
#define NET_MESHOS_ERR_NULL -1
#define NET_MESHOS_ERR_CALL_FAILED -2
#define NET_MESHOS_ERR_INVALID_ARG -3
#define NET_MESHOS_ERR_ALREADY_SHUTDOWN -4
#define NET_MESHOS_CONTROL_NONE 0
#define NET_MESHOS_CONTROL_SHUTDOWN 1
#define NET_MESHOS_CONTROL_DRAIN_START 2
#define NET_MESHOS_CONTROL_DRAIN_FINISH 3
#define NET_MESHOS_CONTROL_BACKPRESSURE_ON 4
#define NET_MESHOS_CONTROL_BACKPRESSURE_OFF 5
#define NET_MESHOS_CONTROL_UNKNOWN 99
typedef struct {
int kind;
uint64_t grace_period_ms;
float level;
} NetMeshOsDaemonControl;
#define NET_MESHOS_LOG_TRACE 0
#define NET_MESHOS_LOG_DEBUG 1
#define NET_MESHOS_LOG_INFO 2
#define NET_MESHOS_LOG_WARN 3
#define NET_MESHOS_LOG_ERROR 4
typedef struct NetMeshOsSdk NetMeshOsSdk;
typedef struct NetMeshOsHandle NetMeshOsHandle;
int net_meshos_sdk_start(
uint64_t this_node,
uint64_t tick_interval_ms,
size_t event_queue_capacity,
size_t action_queue_capacity,
size_t control_capacity,
NetMeshOsSdk** out
);
void net_meshos_sdk_free(NetMeshOsSdk* sdk);
int net_meshos_sdk_shutdown(NetMeshOsSdk* sdk);
uint64_t net_meshos_sdk_dropped_control_events(NetMeshOsSdk* sdk);
#define NET_MESHOS_HEALTH_HEALTHY 0
#define NET_MESHOS_HEALTH_DEGRADED 1
#define NET_MESHOS_HEALTH_UNHEALTHY 2
typedef struct NetMeshOsProcessEmitCtx NetMeshOsProcessEmitCtx;
typedef struct NetMeshOsSnapshotEmitCtx NetMeshOsSnapshotEmitCtx;
typedef struct {
int (*process)(
void* user_ctx,
NetMeshOsProcessEmitCtx* emit_ctx,
uint64_t origin_hash,
uint64_t sequence,
const uint8_t* payload_ptr,
size_t payload_len
);
void (*snapshot)(
void* user_ctx,
NetMeshOsSnapshotEmitCtx* emit_ctx
);
int (*restore)(
void* user_ctx,
const uint8_t* payload_ptr,
size_t payload_len
);
void (*on_control)(
void* user_ctx,
int kind,
uint64_t grace_period_ms,
float level
);
int (*health)(void* user_ctx);
float (*saturation)(void* user_ctx);
} NetMeshOsDaemonVtable;
void net_meshos_process_emit(
NetMeshOsProcessEmitCtx* ctx,
const uint8_t* payload_ptr,
size_t payload_len
);
void net_meshos_snapshot_emit(
NetMeshOsSnapshotEmitCtx* ctx,
const uint8_t* payload_ptr,
size_t payload_len
);
int net_meshos_register_daemon_with_vtable(
NetMeshOsSdk* sdk,
const char* name_ptr,
size_t name_len,
const uint8_t* seed_ptr,
const NetMeshOsDaemonVtable* vtable_ptr,
void* user_ctx,
NetMeshOsHandle** out
);
int net_meshos_register_daemon(
NetMeshOsSdk* sdk,
const char* name_ptr,
size_t name_len,
const uint8_t* seed_ptr,
NetMeshOsHandle** out
);
void net_meshos_handle_free(NetMeshOsHandle* handle);
uint64_t net_meshos_handle_daemon_id(const NetMeshOsHandle* handle);
const char* net_meshos_handle_daemon_name(const NetMeshOsHandle* handle);
int net_meshos_try_next_control(
NetMeshOsHandle* handle,
NetMeshOsDaemonControl* out
);
int net_meshos_next_control(
NetMeshOsHandle* handle,
uint64_t timeout_ms,
NetMeshOsDaemonControl* out
);
int net_meshos_publish_log(
NetMeshOsHandle* handle,
int level,
const char* message_ptr,
size_t message_len
);
int net_meshos_graceful_shutdown(
NetMeshOsHandle* handle,
uint64_t grace_ms
);
char* net_meshos_metadata(const NetMeshOsHandle* handle);
char* net_meshos_refresh_metadata(NetMeshOsHandle* handle);
void net_meshos_free_string(char* s);
int net_meshos_publish_capabilities(
NetMeshOsHandle* handle,
const char* tags_json_ptr,
size_t tags_json_len
);
const char* net_meshos_last_error_message(void);
const char* net_meshos_last_error_kind(void);
void net_meshos_clear_last_error(void);
#ifdef __cplusplus
}
#endif
#endif