Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: new async status api #261

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions ecsact/runtime/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ typedef enum {
ECSACT_ASYNC_ERR_CUSTOM_END = 200,
} ecsact_async_error;

typedef enum {
/**
* No status. Not connected.
*/
ECSACT_ASYNC_STATUS_NONE = 0,

/**
* Connected. No issues.
*/
ECSACT_ASYNC_STATUS_CONNECTED = 1,

/**
* Connection in progress.
*/
ECSACT_ASYNC_STATUS_PENDING = 1,
} ecsact_async_status;

/**
* When an error occurs due to an async request this callback is invoked.
*
Expand Down Expand Up @@ -109,6 +126,14 @@ typedef void (*ecsact_async_request_done_callback)( //
void* callback_user_data
);

/**
* Callback for a status change event
*/
typedef void (*ecsact_async_status_change_callback)( //
ecsact_async_status new_status,
void* callback_user_data
);

typedef struct ecsact_async_events_collector {
/**
* invoked when an async request failed.
Expand Down Expand Up @@ -145,6 +170,16 @@ typedef struct ecsact_async_events_collector {
* `callback_user_data` passed to `async_request_done_callback`
*/
void* async_request_done_callback_user_data;

/**
* invoked when the async status has changed
*/
ecsact_async_status_change_callback async_status_change_callback;

/**
* `callback_user_data` passed to `ecsact_async_status_change_callback`
*/
void* async_status_change_callback_user_data;
} ecsact_async_events_collector;

/**
Expand Down Expand Up @@ -194,6 +229,11 @@ ECSACT_ASYNC_API_FN(ecsact_async_request_id, ecsact_async_connect)
*/
ECSACT_ASYNC_API_FN(void, ecsact_async_disconnect)(void);

/**
* Get the current async status.
*/
ECSACT_ASYNC_API_FN(ecsact_async_status, ecsact_async_get_status)(void);

/**
* Gets the current tick
*/
Expand All @@ -204,6 +244,7 @@ ECSACT_ASYNC_API_FN(int32_t, ecsact_async_get_current_tick)(void);
fn(ecsact_async_flush_events, __VA_ARGS__); \
fn(ecsact_async_connect, __VA_ARGS__); \
fn(ecsact_async_disconnect, __VA_ARGS__); \
fn(ecsact_async_get_status, __VA_ARGS__); \
fn(ecsact_async_get_current_tick, __VA_ARGS__);

#undef ECSACT_ASYNC_API
Expand Down
Loading