- Added `RpcError` enum for comprehensive error handling in RPC operations. - Introduced `HealthReporter` and `HealthService` for managing service health statuses. - Implemented health check and watch functionality in the health service. - Created integration tests for health check service, covering various scenarios. - Added unit tests for client options validation and stream functionality. - Established logging infrastructure for terminal and registry components. - Implemented logging lifecycle management and conflict resolution in tests.
152 lines
5.6 KiB
C
152 lines
5.6 KiB
C
#ifndef FLYSIM_TERMINAL_H
|
|
#define FLYSIM_TERMINAL_H
|
|
|
|
#pragma once
|
|
|
|
#include <stdarg.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
|
|
#define TERMINAL_OK 0
|
|
|
|
#define TERMINAL_ERROR_NULL -1
|
|
|
|
#define TERMINAL_ERROR_INVALID_ARGUMENT -2
|
|
|
|
#define TERMINAL_ERROR_INVALID_STATE -3
|
|
|
|
#define TERMINAL_ERROR_DECODE -4
|
|
|
|
#define TERMINAL_ERROR_INTERNAL -5
|
|
|
|
#define TERMINAL_ERROR_BUFFER_TOO_SMALL -6
|
|
|
|
typedef int32_t (*TerminalResponseSink)(void *context, const uint8_t *response, size_t response_len);
|
|
|
|
typedef int32_t (*TerminalCommandCallback)(void *user_data,
|
|
const uint8_t *command,
|
|
size_t command_len,
|
|
TerminalResponseSink sink,
|
|
void *sink_context);
|
|
|
|
typedef int32_t (*TerminalEventCallback)(void *user_data,
|
|
const uint8_t *event,
|
|
size_t event_len,
|
|
uint64_t instance_id,
|
|
TerminalResponseSink sink,
|
|
void *sink_context);
|
|
|
|
void *terminal_service_create(void);
|
|
|
|
/**
|
|
* Initializes module-wide console and daily rolling file logging once, before starting terminals.
|
|
* `handle` is used only for error reporting. Does not replace an existing logger/subscriber.
|
|
* # Safety
|
|
* `handle` must be live; both non-null input pointers must reference their declared readable
|
|
* UTF-8 byte lengths. Serialize logging initialization with other process logging setup.
|
|
*/
|
|
int32_t terminal_logging_init(void *handle,
|
|
const uint8_t *log_level,
|
|
size_t log_level_len,
|
|
const uint8_t *log_dir,
|
|
size_t log_dir_len,
|
|
uint32_t max_log_files);
|
|
|
|
/**
|
|
* Flushes and closes the module-owned log worker. Repeated shutdown is harmless.
|
|
* Does not uninstall global logging or permit reinitialization after shutdown.
|
|
* # Safety
|
|
* `handle` must be live. Stop all terminals and callbacks first, serialize logging lifecycle
|
|
* calls, and keep the library loaded until process exit. Do not call from a callback.
|
|
*/
|
|
int32_t terminal_logging_shutdown(void *handle);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be a live pointer returned by `terminal_service_create` and must not be used
|
|
* after this function succeeds.
|
|
*/
|
|
int32_t terminal_service_destroy(void *handle);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be live, and `terminal_info` must reference `terminal_info_len` readable bytes.
|
|
*/
|
|
int32_t terminal_service_configure(void *handle,
|
|
const uint8_t *terminal_info,
|
|
size_t terminal_info_len);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be live; `command_id` must reference `command_id_len` readable UTF-8 bytes.
|
|
* The callback and `user_data` must remain valid until the service is destroyed.
|
|
*/
|
|
int32_t terminal_service_register_command(void *handle,
|
|
const uint8_t *command_id,
|
|
size_t command_id_len,
|
|
TerminalCommandCallback callback,
|
|
void *user_data);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be live; `event_info` must reference `event_info_len` readable bytes. The
|
|
* callback and `user_data` must remain valid until the event is unregistered or service destroyed.
|
|
*/
|
|
int32_t terminal_service_register_event(void *handle,
|
|
const uint8_t *event_info,
|
|
size_t event_info_len,
|
|
TerminalEventCallback callback,
|
|
void *user_data);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be live, and `event_id` must reference `event_id_len` readable UTF-8 bytes.
|
|
*/
|
|
int32_t terminal_service_unregister_event(void *handle,
|
|
const uint8_t *event_id,
|
|
size_t event_id_len);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be live, and `status` must reference `status_len` readable bytes.
|
|
*/
|
|
int32_t terminal_service_push_status(void *handle, const uint8_t *status, size_t status_len);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be live. Both protobuf pointers must reference their declared readable lengths.
|
|
*/
|
|
int32_t terminal_service_complete_event(void *handle,
|
|
const uint8_t *event_handle,
|
|
size_t event_handle_len,
|
|
const uint8_t *response,
|
|
size_t response_len);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be live; `center_host` must reference `center_host_len` readable UTF-8 bytes;
|
|
* `bound_port` must be writable.
|
|
*/
|
|
int32_t terminal_service_start(void *handle,
|
|
const uint8_t *center_host,
|
|
size_t center_host_len,
|
|
uint16_t center_port,
|
|
uint16_t *bound_port);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be a live pointer returned by `terminal_service_create`.
|
|
*/
|
|
int32_t terminal_service_stop(void *handle);
|
|
|
|
/**
|
|
* # Safety
|
|
* `handle` must be live and `buffer_len` writable. A non-null `buffer` must reference at least
|
|
* the input value of `*buffer_len` writable bytes.
|
|
*/
|
|
int32_t terminal_service_last_error(void *handle, uint8_t *buffer, size_t *buffer_len);
|
|
|
|
#endif /* FLYSIM_TERMINAL_H */
|