1. add comments for app lib
2. fix bug of sensor_config_with_attr
This commit is contained in:
@ -101,7 +101,7 @@ static void transaction_remove(transaction_t *trans)
|
||||
}
|
||||
}
|
||||
|
||||
bool is_event_type(request_t * req)
|
||||
static bool is_event_type(request_t * req)
|
||||
{
|
||||
return req->action == COAP_EVENT;
|
||||
}
|
||||
|
||||
@ -24,22 +24,108 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool is_event_type(request_t * req);
|
||||
/**
|
||||
* @typedef request_handler_f
|
||||
*
|
||||
* @brief Define the signature of callback function for API
|
||||
* api_register_resource_handler() to handle request or for API
|
||||
* api_subscribe_event() to handle event.
|
||||
*
|
||||
* @param request pointer of the request to be handled
|
||||
*
|
||||
* @see api_register_resource_handler
|
||||
* @see api_subscribe_event
|
||||
*/
|
||||
typedef void (*request_handler_f)(request_t *request);
|
||||
|
||||
typedef void (*request_handler_f)(request_t *);
|
||||
typedef void (*response_handler_f)(response_t *, void *);
|
||||
/**
|
||||
* @typedef response_handler_f
|
||||
*
|
||||
* @brief Define the signature of callback function for API
|
||||
* api_send_request() to handle response of a request.
|
||||
*
|
||||
* @param response pointer of the response to be handled
|
||||
* @param user_data user data associated with the request which is set when
|
||||
* calling api_send_request().
|
||||
*
|
||||
* @see api_send_request
|
||||
*/
|
||||
typedef void (*response_handler_f)(response_t *response, void *user_data);
|
||||
|
||||
// Request APIs
|
||||
bool api_register_resource_handler(const char *url, request_handler_f);
|
||||
|
||||
/*
|
||||
*****************
|
||||
* Request APIs
|
||||
*****************
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Register resource.
|
||||
*
|
||||
* @param url url of the resource
|
||||
* @param handler callback function to handle the request to the resource
|
||||
*
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
bool api_register_resource_handler(const char *url, request_handler_f handler);
|
||||
|
||||
/**
|
||||
* @brief Send request asynchronously.
|
||||
*
|
||||
* @param request pointer of the request to be sent
|
||||
* @param response_handler callback function to handle the response
|
||||
* @param user_data user data
|
||||
*/
|
||||
void api_send_request(request_t * request, response_handler_f response_handler,
|
||||
void * user_data);
|
||||
|
||||
/**
|
||||
* @brief Send response.
|
||||
*
|
||||
* @param response pointer of the response to be sent
|
||||
*
|
||||
* @par
|
||||
* @code
|
||||
* void res1_handler(request_t *request)
|
||||
* {
|
||||
* response_t response[1];
|
||||
* make_response_for_request(request, response);
|
||||
* set_response(response, DELETED_2_02, 0, NULL, 0);
|
||||
* api_response_send(response);
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
void api_response_send(response_t *response);
|
||||
|
||||
// event API
|
||||
|
||||
/*
|
||||
*****************
|
||||
* Event APIs
|
||||
*****************
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Publish an event.
|
||||
*
|
||||
* @param url url of the event
|
||||
* @param fmt format of the event payload
|
||||
* @param payload payload of the event
|
||||
* @param payload_len length in bytes of the event payload
|
||||
*
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
bool api_publish_event(const char *url, int fmt, void *payload,
|
||||
int payload_len);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Subscribe an event.
|
||||
*
|
||||
* @param url url of the event
|
||||
* @param handler callback function to handle the event.
|
||||
*
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
bool api_subscribe_event(const char * url, request_handler_f handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -35,7 +35,7 @@ struct user_timer {
|
||||
struct user_timer * g_timers = NULL;
|
||||
|
||||
user_timer_t api_timer_create(int interval, bool is_period, bool auto_start,
|
||||
void (*on_timer_update)(user_timer_t))
|
||||
on_user_timer_update_f on_timer_update)
|
||||
{
|
||||
|
||||
int timer_id = wasm_create_timer(interval, is_period, auto_start);
|
||||
|
||||
@ -23,17 +23,53 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//TODO:
|
||||
#define bh_queue_t void
|
||||
|
||||
/* board producer define user_timer */
|
||||
struct user_timer;
|
||||
typedef struct user_timer * user_timer_t;
|
||||
|
||||
// Timer APIs
|
||||
/**
|
||||
* @typedef on_user_timer_update_f
|
||||
*
|
||||
* @brief Define the signature of callback function for API api_timer_create().
|
||||
*
|
||||
* @param timer the timer
|
||||
*
|
||||
* @see api_timer_create
|
||||
*/
|
||||
typedef void (*on_user_timer_update_f)(user_timer_t timer);
|
||||
|
||||
/*
|
||||
*****************
|
||||
* Timer APIs
|
||||
*****************
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Create timer.
|
||||
*
|
||||
* @param interval timer interval
|
||||
* @param is_period whether the timer is periodic
|
||||
* @param auto_start whether start the timer immediately after created
|
||||
* @param on_timer_update callback function called when timer expired
|
||||
*
|
||||
* @return the timer created if success, NULL otherwise
|
||||
*/
|
||||
user_timer_t api_timer_create(int interval, bool is_period, bool auto_start,
|
||||
void (*on_user_timer_update)(user_timer_t));
|
||||
on_user_timer_update_f on_timer_update);
|
||||
|
||||
/**
|
||||
* @brief Cancel timer.
|
||||
*
|
||||
* @param timer the timer to cancel
|
||||
*/
|
||||
void api_timer_cancel(user_timer_t timer);
|
||||
|
||||
/**
|
||||
* @brief Restart timer.
|
||||
*
|
||||
* @param timer the timer to cancel
|
||||
* @param interval the timer interval
|
||||
*/
|
||||
void api_timer_restart(user_timer_t timer, int interval);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user