Events Model
When application allocates new AislInstance, it shall provide a callback that will handle events triggered by AISL.
/* @file aisl/types.h */
#define AISL_CALLBACK(x) ((AislCallback) x)
typedef void
(* AislCallback) (const struct aisl_evt *evt, void *p_ctx);
First argument const struct aisl_evt *evt
contains all necessary data for event
handling.
Second argument is a user-defined pointer, that AISL will pass through form configuration structure.
struct aisl_evt {
void *source;
AislEvent code;
AislStatus status;
};
Application should check code
value and cast source
pointer as an
appropriate type. Property status
let application to
know the status of operation that
triggered the event.
Server events
Events that has AislServer as their source.
AISL_EVENT_SERVER_READY
- server started at defined interface and portAISL_EVENT_SERVER_ERROR
- error occured during server workflow
Client events
Events that has AislClient as their source.
AISL_EVENT_CLIENT_CONNECT
- client connectedAISL_EVENT_CLIENT_DISCONNECT
- client disconnected
Stream events
Events that has AislStream as their source.
AISL_EVENT_STREAM_OPEN
- HTTP request initiated by clientAISL_EVENT_STREAM_HEADER
- HTTP header received from clientAISL_EVENT_STREAM_INPUT
- A chunk of HTTP request body received from clientAISL_EVENT_STREAM_REQUEST
- HTTP request has been received, clients awaits for responseAISL_EVENT_STREAM_OUTPUT
- AISL is ready to send next amount of dataAISL_EVENT_STREAM_CLOSE
- resources allocated for stream are about to be releasedAISL_EVENT_STREAM_ERROR
- error occured during communication
Event payload received in a callback can be also type casted in several cases for additional data:
struct aisl_evt_open *
forAISL_EVENT_STREAM_OPEN
event
struct aisl_evt_open {
struct aisl_evt evt; /**< generic #aisl_evt structure */
const char *path; /**< HTTP request path */
const char *query; /**< HTTP request query (GET params) */
AislHttpMethod http_method; /**< HTTP request method */
};
struct aisl_evt_header *
forAISL_EVENT_STREAM_HEADER
event
struct aisl_evt_header {
struct aisl_evt evt; /**< generic #aisl_evt structure */
const char *key; /**< low case HTTP header name */
const char *value; /**< HTTP header string */
};
struct aisl_evt_input *
forAISL_EVENT_STREAM_INPUT
event
struct aisl_evt_input {
struct aisl_evt evt; /**< generic #aisl_evt structure */
const char *data; /**< a pointer to received data array */
int32_t size; /**< data array size */
};
Functions
Function aisl_event_to_string
Converts AislEvent
constant to a NULL-terminated string representation.
const char *
aisl_event_to_string(AislEvent evt);
Arguments
- evt — `AislEvent’ constant
Return value
A NULL-terminated string representation of AislEvent