Apply clang format for samples files (#833)

Apply clang format for c source files under samples folder
This commit is contained in:
Wenyong Huang
2021-11-15 12:48:35 +08:00
committed by GitHub
parent 37a14c9825
commit 3ded9ece83
58 changed files with 1261 additions and 957 deletions

View File

@ -13,33 +13,35 @@ static int num = 0;
static user_timer_t g_timer;
static connection_t *g_conn = NULL;
void on_data1(connection_t *conn,
conn_event_type_t type,
const char *data,
uint32 len,
void *user_data)
void
on_data1(connection_t *conn, conn_event_type_t type, const char *data,
uint32 len, void *user_data)
{
if (type == CONN_EVENT_TYPE_DATA) {
char message[64] = {0};
char message[64] = { 0 };
memcpy(message, data, len);
printf("Client got a message from server -> %s\n", message);
} else if (type == CONN_EVENT_TYPE_DISCONNECT) {
}
else if (type == CONN_EVENT_TYPE_DISCONNECT) {
printf("connection is close by server!\n");
} else {
}
else {
printf("error: got unknown event type!!!\n");
}
}
/* Timer callback */
void timer1_update(user_timer_t timer)
void
timer1_update(user_timer_t timer)
{
char message[64] = {0};
char message[64] = { 0 };
/* Reply to server */
snprintf(message, sizeof(message), "Hello %d", num++);
api_send_on_connection(g_conn, message, strlen(message));
}
void my_close_handler(request_t * request)
void
my_close_handler(request_t *request)
{
response_t response[1];
@ -53,7 +55,8 @@ void my_close_handler(request_t * request)
api_response_send(response);
}
void on_init()
void
on_init()
{
user_timer_t timer;
attr_container_t *args;
@ -78,7 +81,8 @@ void on_init()
api_timer_restart(timer, 1000);
}
void on_destroy()
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */

View File

@ -9,7 +9,8 @@
int num = 0;
void publish_overheat_event()
void
publish_overheat_event()
{
attr_container_t *event;
@ -17,18 +18,20 @@ void publish_overheat_event()
attr_container_set_string(&event, "warning", "temperature is over high");
api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event,
attr_container_get_serialize_length(event));
attr_container_get_serialize_length(event));
attr_container_destroy(event);
}
/* Timer callback */
void timer1_update(user_timer_t timer)
void
timer1_update(user_timer_t timer)
{
publish_overheat_event();
}
void start_timer()
void
start_timer()
{
user_timer_t timer;
@ -37,12 +40,15 @@ void start_timer()
api_timer_restart(timer, 1000);
}
void on_init()
void
on_init()
{
start_timer();
}
void on_destroy()
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */
}

View File

@ -6,20 +6,23 @@
#include "wasm_app.h"
#include "wa-inc/request.h"
void over_heat_event_handler(request_t *request)
void
over_heat_event_handler(request_t *request)
{
printf("### user over heat event handler called\n");
if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
attr_container_dump((attr_container_t *) request->payload);
attr_container_dump((attr_container_t *)request->payload);
}
void on_init()
void
on_init()
{
api_subscribe_event("alert/overheat", over_heat_event_handler);
}
void on_destroy()
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */

View File

@ -6,7 +6,8 @@
#include "wasm_app.h"
#include "wa-inc/request.h"
static void url1_request_handler(request_t *request)
static void
url1_request_handler(request_t *request)
{
response_t response[1];
attr_container_t *payload;
@ -14,7 +15,7 @@ static void url1_request_handler(request_t *request)
printf("[resp] ### user resource 1 handler called\n");
if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
attr_container_dump((attr_container_t *) request->payload);
attr_container_dump((attr_container_t *)request->payload);
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
@ -24,16 +25,15 @@ static void url1_request_handler(request_t *request)
attr_container_set_string(&payload, "key2", "value2");
make_response_for_request(request, response);
set_response(response, CONTENT_2_05,
FMT_ATTR_CONTAINER,
(void *)payload,
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, (void *)payload,
attr_container_get_serialize_length(payload));
api_response_send(response);
attr_container_destroy(payload);
}
static void url2_request_handler(request_t *request)
static void
url2_request_handler(request_t *request)
{
response_t response[1];
make_response_for_request(request, response);
@ -43,14 +43,16 @@ static void url2_request_handler(request_t *request)
printf("### user resource 2 handler called\n");
}
void on_init()
void
on_init()
{
/* register resource uri */
api_register_resource_handler("/url1", url1_request_handler);
api_register_resource_handler("/url2", url2_request_handler);
}
void on_destroy()
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */

View File

@ -6,28 +6,30 @@
#include "wasm_app.h"
#include "wa-inc/request.h"
static void my_response_handler(response_t *response, void *user_data)
static void
my_response_handler(response_t *response, void *user_data)
{
char *tag = (char *) user_data;
char *tag = (char *)user_data;
if (response == NULL) {
printf("[req] request timeout!\n");
return;
}
printf("[req] response handler called mid:%d, status:%d, fmt:%d, payload:%p, len:%d, tag:%s\n",
printf("[req] response handler called mid:%d, status:%d, fmt:%d, "
"payload:%p, len:%d, tag:%s\n",
response->mid, response->status, response->fmt, response->payload,
response->payload_len, tag);
if (response->payload != NULL
&& response->payload_len > 0
if (response->payload != NULL && response->payload_len > 0
&& response->fmt == FMT_ATTR_CONTAINER) {
printf("[req] dump the response payload:\n");
attr_container_dump((attr_container_t *) response->payload);
attr_container_dump((attr_container_t *)response->payload);
}
}
static void test_send_request(char *url, char *tag)
static void
test_send_request(char *url, char *tag)
{
request_t request[1];
@ -35,13 +37,15 @@ static void test_send_request(char *url, char *tag)
api_send_request(request, my_response_handler, tag);
}
void on_init()
void
on_init()
{
test_send_request("/app/request_handler/url1", "a request to target app");
test_send_request("url1", "a general request");
}
void on_destroy()
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */

View File

@ -9,14 +9,15 @@
static sensor_t sensor = NULL;
/* Sensor event callback*/
void sensor_event_handler(sensor_t sensor, attr_container_t *event,
void *user_data)
void
sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data)
{
printf("### app get sensor event\n");
attr_container_dump(event);
}
void on_init()
void
on_init()
{
char *user_data;
attr_container_t *config;
@ -39,7 +40,8 @@ void on_init()
*/
}
void on_destroy()
void
on_destroy()
{
if (NULL != sensor) {
sensor_config(sensor, 0, 0, 0);

View File

@ -10,12 +10,14 @@
static int num = 0;
/* Timer callback */
void timer1_update(user_timer_t timer)
void
timer1_update(user_timer_t timer)
{
printf("Timer update %d\n", num++);
}
void on_init()
void
on_init()
{
user_timer_t timer;
@ -24,7 +26,8 @@ void on_init()
api_timer_restart(timer, 1000);
}
void on_destroy()
void
on_destroy()
{
/* real destroy work including killing timer and closing sensor is
accomplished in wasm app library version of on_destroy() */