Skip to content

Commit

Permalink
refactor!: design new simplified C API
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jul 2, 2024
1 parent dfaff6b commit 5d28c22
Show file tree
Hide file tree
Showing 3 changed files with 299 additions and 1,659 deletions.
51 changes: 32 additions & 19 deletions src/jsonrpc-machine-c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
extern "C" {
#endif

/// \brief Semantic version
typedef struct { // NOLINT(modernize-use-using)
uint32_t major;
uint32_t minor;
uint32_t patch;
const char *pre_release;
const char *build;
} cm_semantic_version;

/// \brief Deletes semantic version instance
/// \param m Valid pointer to the existing semantic version instance
CM_API void cm_delete_semantic_version(const cm_semantic_version *version);

/// \brief Handle of the jsonrpc connection manager
typedef struct cm_jsonrpc_mgr_tag cm_jsonrpc_mgr; // NOLINT(modernize-use-using)

Expand All @@ -53,8 +66,8 @@ CM_API void cm_delete_jsonrpc_mgr(const cm_jsonrpc_mgr *mgr);
/// or NULL in case of successful function execution. In case of failure error_msg
/// must be deleted by the function caller using cm_delete_cstring
/// \returns 0 for success, non zero code for error
CM_API int cm_create_jsonrpc_machine(const cm_jsonrpc_mgr *mgr, const cm_machine_config *config,
const cm_machine_runtime_config *runtime_config, cm_machine **new_machine, char **err_msg);
CM_API int cm_create_jsonrpc_machine(const cm_jsonrpc_mgr *mgr, const char *config,
const char *runtime_config, cm_machine **new_machine, char **err_msg);

/// \brief Create remote machine instance from previously serialized directory
/// \param mgr Cartesi jsonrpc connection manager. Must be pointer to valid object
Expand All @@ -66,7 +79,7 @@ CM_API int cm_create_jsonrpc_machine(const cm_jsonrpc_mgr *mgr, const cm_machine
/// must be deleted by the function caller using cm_delete_cstring
/// \returns 0 for success, non zero code for error
CM_API int cm_load_jsonrpc_machine(const cm_jsonrpc_mgr *mgr, const char *dir,
const cm_machine_runtime_config *runtime_config, cm_machine **new_machine, char **err_msg);
const char *runtime_config, cm_machine **new_machine, char **err_msg);

/// \brief Get remote machine instance that was previously created in the server
/// \param mgr Cartesi jsonrpc connection manager. Must be pointer to valid object
Expand All @@ -84,36 +97,36 @@ CM_API int cm_get_jsonrpc_machine(const cm_jsonrpc_mgr *mgr, cm_machine **new_ma
/// or NULL in case of successful function execution. In case of failure error_msg
/// must be deleted by the function caller using cm_delete_cstring
/// \returns 0 for success, non zero code for error
CM_API int cm_jsonrpc_get_default_config(const cm_jsonrpc_mgr *mgr, const cm_machine_config **config, char **err_msg);
CM_API int cm_jsonrpc_get_default_config(const cm_jsonrpc_mgr *mgr, const char **config, char **err_msg);

/// \brief Checks the internal consistency of an access log
/// \param mgr Cartesi jsonrpc connection manager. Must be pointer to valid object
/// \param log State access log to be verified.
/// \param access_log State access log to be verified.
/// \param runtime_config Runtime config to be used
/// \param one_based Use 1-based indices when reporting errors.
/// \param err_msg Receives the error message if function execution fails
/// or NULL in case of successful function execution. In case of failure error_msg
/// must be deleted by the function caller using cm_7_error_message
/// \returns 0 for success, non zero code for error
CM_API int cm_jsonrpc_verify_uarch_step_log(const cm_jsonrpc_mgr *mgr, const cm_access_log *log,
const cm_machine_runtime_config *runtime_config, bool one_based, char **err_msg);
CM_API int cm_jsonrpc_verify_uarch_step_log(const cm_jsonrpc_mgr *mgr, const char *access_log,
const char *runtime_config, bool one_based, char **err_msg);

/// \brief Checks the internal consistency of an access log produced by cm_jsonrpc_log_uarch_reset
/// \param mgr Cartesi jsonrpc connection manager. Must be pointer to valid object
/// \param log State access log to be verified.
/// \param access_log State access log to be verified.
/// \param runtime_config Runtime config to be used
/// \param one_based Use 1-based indices when reporting errors.
/// \param err_msg Receives the error message if function execution fails
/// or NULL in case of successful function execution. In case of failure error_msg
/// must be deleted by the function caller using cm_7_error_message
/// \returns 0 for success, non zero code for error
CM_API int cm_jsonrpc_verify_uarch_reset_log(const cm_jsonrpc_mgr *mgr, const cm_access_log *log,
const cm_machine_runtime_config *runtime_config, bool one_based, char **err_msg);
CM_API int cm_jsonrpc_verify_uarch_reset_log(const cm_jsonrpc_mgr *mgr, const char *access_log,
const char *runtime_config, bool one_based, char **err_msg);

/// \brief Checks the validity of a state transition caused by uarch state reset
/// \param mgr Cartesi jsonrpc connection manager. Must be pointer to valid object
/// \param root_hash_before State hash before step
/// \param log Step state access log created by cm_jsonrpc_log_uarch_reset
/// \param access_log Step state access log created by cm_jsonrpc_log_uarch_reset
/// \param root_hash_after State hash after step
/// \param runtime_config Runtime config to be used
/// \param one_based Use 1-based indices when reporting errors
Expand All @@ -122,13 +135,13 @@ CM_API int cm_jsonrpc_verify_uarch_reset_log(const cm_jsonrpc_mgr *mgr, const cm
/// must be deleted by the function caller using cm_delete_cstring
/// \returns 0 for successful verification, non zero code for error
CM_API int cm_jsonrpc_verify_uarch_reset_state_transition(const cm_jsonrpc_mgr *mgr, const cm_hash *root_hash_before,
const cm_access_log *log, const cm_hash *root_hash_after, const cm_machine_runtime_config *runtime_config,
const char *access_log, const cm_hash *root_hash_after, const char *runtime_config,
bool one_based, char **err_msg);

/// \brief Checks the validity of a state transition
/// \param mgr Cartesi jsonrpc connection manager. Must be pointer to valid object
/// \param root_hash_before State hash before step
/// \param log Step state access log
/// \param access_log Step state access log
/// \param root_hash_after State hash after step
/// \param runtime_config Runtime config to be used
/// \param one_based Use 1-based indices when reporting errors
Expand All @@ -137,7 +150,7 @@ CM_API int cm_jsonrpc_verify_uarch_reset_state_transition(const cm_jsonrpc_mgr *
/// must be deleted by the function caller using cm_delete_cstring
/// \returns 0 for successful verification, non zero code for error
CM_API int cm_jsonrpc_verify_uarch_step_state_transition(const cm_jsonrpc_mgr *mgr, const cm_hash *root_hash_before,
const cm_access_log *log, const cm_hash *root_hash_after, const cm_machine_runtime_config *runtime_config,
const char *access_log, const cm_hash *root_hash_after, const char *runtime_config,
bool one_based, char **err_msg);

/// \brief Forks the server
Expand Down Expand Up @@ -223,15 +236,15 @@ CM_API int cm_jsonrpc_shutdown(const cm_jsonrpc_mgr *mgr, char **err_msg);
/// \param reason Reason for sending response
/// \param data Response data to send.
/// \param length Length of data response data.
/// \param log State access log to be verified.
/// \param access_log State access log to be verified.
/// \param runtime_config Runtime config to be used
/// \param one_based Use 1-based indices when reporting errors.
/// \param err_msg Receives the error message if function execution fails
/// or NULL in case of successfull function execution. In case of failure error_msg
/// must be deleted by the function caller using cm_7_error_message
/// \returns 0 for success, non zero code for error
CM_API int cm_jsonrpc_verify_send_cmio_response_log(const cm_jsonrpc_mgr *mgr, uint16_t reason,
const unsigned char *data, size_t length, const cm_access_log *log, const cm_machine_runtime_config *runtime_config,
const unsigned char *data, size_t length, const char *access_log, const char *runtime_config,
bool one_based, char **err_msg);

/// \brief Checks the validity of a state transition caused by send_cmio_response
Expand All @@ -240,7 +253,7 @@ CM_API int cm_jsonrpc_verify_send_cmio_response_log(const cm_jsonrpc_mgr *mgr, u
/// \param data Response data to send.
/// \param length Length of data response data.
/// \param root_hash_before State hash before load.
/// \param log State access log to be verified.
/// \param access_log State access log to be verified.
/// \param root_hash_after State hash after load.
/// \param runtime_config Runtime config to be used
/// \param one_based Use 1-based indices when reporting errors
Expand All @@ -249,8 +262,8 @@ CM_API int cm_jsonrpc_verify_send_cmio_response_log(const cm_jsonrpc_mgr *mgr, u
/// must be deleted by the function caller using cm_delete_cstring
/// \returns 0 for successfull verification, non zero code for error
CM_API int cm_jsonrpc_verify_send_cmio_response_state_transition(const cm_jsonrpc_mgr *mgr, uint16_t reason,
const unsigned char *data, size_t length, const cm_hash *root_hash_before, const cm_access_log *log,
const cm_hash *root_hash_after, const cm_machine_runtime_config *runtime_config, bool one_based, char **err_msg);
const unsigned char *data, size_t length, const cm_hash *root_hash_before, const char *access_log,
const cm_hash *root_hash_after, const char *runtime_config, bool one_based, char **err_msg);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 5d28c22

Please sign in to comment.