Add terminal service implementation and integration tests

- Introduced terminal.h header file defining the terminal service API.
- Implemented integration tests for terminal service registration and health checks.
- Added unit tests for FFI layer, health checks, and terminal service functionality.
- Created a mock center for testing terminal registration and deregistration.
- Ensured proper error handling and response validation in tests.
This commit is contained in:
2026-09-20 10:55:38 +08:00
parent 3bef0e4ef2
commit 7f331565c7
90 changed files with 7807 additions and 14 deletions
+128
View File
@@ -0,0 +1,128 @@
#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);
/**
* # 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 */