Apply clang format for samples files (#833)
Apply clang format for c source files under samples folder
This commit is contained in:
@ -45,11 +45,16 @@ static char *uart_device = "/dev/ttyS2";
|
||||
static int baudrate = B115200;
|
||||
#endif
|
||||
|
||||
extern void init_sensor_framework();
|
||||
extern void exit_sensor_framework();
|
||||
extern void exit_connection_framework();
|
||||
extern int aee_host_msg_callback(void *msg, uint32_t msg_len);
|
||||
extern bool init_connection_framework();
|
||||
extern void
|
||||
init_sensor_framework();
|
||||
extern void
|
||||
exit_sensor_framework();
|
||||
extern void
|
||||
exit_connection_framework();
|
||||
extern int
|
||||
aee_host_msg_callback(void *msg, uint32_t msg_len);
|
||||
extern bool
|
||||
init_connection_framework();
|
||||
|
||||
#ifndef CONNECTION_UART
|
||||
int listenfd = -1;
|
||||
@ -63,7 +68,8 @@ int uartfd = -1;
|
||||
static bool server_mode = false;
|
||||
|
||||
// Function designed for chat between client and server.
|
||||
void* func(void* arg)
|
||||
void *
|
||||
func(void *arg)
|
||||
{
|
||||
char buff[MAX];
|
||||
int n;
|
||||
@ -77,7 +83,8 @@ void* func(void* arg)
|
||||
if (sockfd == -1) {
|
||||
printf("socket creation failed...\n");
|
||||
return NULL;
|
||||
} else
|
||||
}
|
||||
else
|
||||
printf("Socket successfully created..\n");
|
||||
bzero(&servaddr, sizeof(servaddr));
|
||||
// assign IP, PORT
|
||||
@ -86,11 +93,12 @@ void* func(void* arg)
|
||||
servaddr.sin_port = htons(port);
|
||||
|
||||
// connect the client socket to server socket
|
||||
if (connect(sockfd, (SA*) &servaddr, sizeof(servaddr)) != 0) {
|
||||
if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0) {
|
||||
printf("connection with the server failed...\n");
|
||||
sleep(10);
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("connected to the server..\n");
|
||||
}
|
||||
|
||||
@ -101,7 +109,7 @@ void* func(void* arg)
|
||||
// read the message from client and copy it in buffer
|
||||
n = read(sockfd, buff, sizeof(buff));
|
||||
// print buffer which contains the client contents
|
||||
//fprintf(stderr, "recieved %d bytes from host: %s", n, buff);
|
||||
// fprintf(stderr, "recieved %d bytes from host: %s", n, buff);
|
||||
|
||||
// socket disconnected
|
||||
if (n <= 0)
|
||||
@ -115,12 +123,14 @@ void* func(void* arg)
|
||||
close(sockfd);
|
||||
}
|
||||
|
||||
static bool host_init()
|
||||
static bool
|
||||
host_init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int host_send(void * ctx, const char *buf, int size)
|
||||
int
|
||||
host_send(void *ctx, const char *buf, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -139,7 +149,8 @@ int host_send(void * ctx, const char *buf, int size)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void host_destroy()
|
||||
void
|
||||
host_destroy()
|
||||
{
|
||||
if (server_mode)
|
||||
close(listenfd);
|
||||
@ -149,16 +160,19 @@ void host_destroy()
|
||||
pthread_mutex_unlock(&sock_lock);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
host_interface interface = {
|
||||
.init = host_init,
|
||||
.send = host_send,
|
||||
.destroy = host_destroy
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* Change it to 1 when fuzzing test */
|
||||
#define WASM_ENABLE_FUZZ_TEST 0
|
||||
|
||||
void* func_server_mode(void* arg)
|
||||
void *
|
||||
func_server_mode(void *arg)
|
||||
{
|
||||
int clilent;
|
||||
struct sockaddr_in serv_addr, cli_addr;
|
||||
@ -178,14 +192,14 @@ void* func_server_mode(void* arg)
|
||||
}
|
||||
|
||||
/* Initialize socket structure */
|
||||
bzero((char *) &serv_addr, sizeof(serv_addr));
|
||||
bzero((char *)&serv_addr, sizeof(serv_addr));
|
||||
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
serv_addr.sin_port = htons(port);
|
||||
|
||||
/* Now bind the host address using bind() call.*/
|
||||
if (bind(listenfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
|
||||
if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
|
||||
perror("ERROR on binding");
|
||||
exit(1);
|
||||
}
|
||||
@ -196,7 +210,7 @@ void* func_server_mode(void* arg)
|
||||
while (1) {
|
||||
pthread_mutex_lock(&sock_lock);
|
||||
|
||||
sockfd = accept(listenfd, (struct sockaddr *) &cli_addr, &clilent);
|
||||
sockfd = accept(listenfd, (struct sockaddr *)&cli_addr, &clilent);
|
||||
|
||||
pthread_mutex_unlock(&sock_lock);
|
||||
|
||||
@ -228,7 +242,7 @@ void* func_server_mode(void* arg)
|
||||
}
|
||||
#if WASM_ENABLE_FUZZ_TEST != 0
|
||||
/* Exit the process when host disconnect.
|
||||
* This is helpful for reproducing failure case. */
|
||||
This is helpful for reproducing failure case. */
|
||||
close(sockfd);
|
||||
exit(1);
|
||||
#endif
|
||||
@ -236,7 +250,8 @@ void* func_server_mode(void* arg)
|
||||
}
|
||||
|
||||
#else
|
||||
static int parse_baudrate(int baud)
|
||||
static int
|
||||
parse_baudrate(int baud)
|
||||
{
|
||||
switch (baud) {
|
||||
case 9600:
|
||||
@ -279,7 +294,8 @@ static int parse_baudrate(int baud)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
static bool uart_init(const char *device, int baudrate, int *fd)
|
||||
static bool
|
||||
uart_init(const char *device, int baudrate, int *fd)
|
||||
{
|
||||
int uart_fd;
|
||||
struct termios uart_term;
|
||||
@ -310,7 +326,8 @@ static bool uart_init(const char *device, int baudrate, int *fd)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void *func_uart_mode(void *arg)
|
||||
static void *
|
||||
func_uart_mode(void *arg)
|
||||
{
|
||||
int n;
|
||||
char buff[MAX];
|
||||
@ -337,7 +354,8 @@ static void *func_uart_mode(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int uart_send(void * ctx, const char *buf, int size)
|
||||
static int
|
||||
uart_send(void *ctx, const char *buf, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -346,23 +364,28 @@ static int uart_send(void * ctx, const char *buf, int size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void uart_destroy()
|
||||
static void
|
||||
uart_destroy()
|
||||
{
|
||||
close(uartfd);
|
||||
}
|
||||
|
||||
static host_interface interface = { .send = uart_send, .destroy = uart_destroy };
|
||||
/* clang-format off */
|
||||
static host_interface interface = {
|
||||
.send = uart_send,
|
||||
.destroy = uart_destroy
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static attr_container_t * read_test_sensor(void * sensor)
|
||||
static attr_container_t *
|
||||
read_test_sensor(void *sensor)
|
||||
{
|
||||
//luc: for test
|
||||
attr_container_t *attr_obj = attr_container_create("read test sensor data");
|
||||
if (attr_obj) {
|
||||
bool ret = attr_container_set_string(&attr_obj, "name", "read test sensor");
|
||||
bool ret =
|
||||
attr_container_set_string(&attr_obj, "name", "read test sensor");
|
||||
if (!ret) {
|
||||
attr_container_destroy(attr_obj);
|
||||
return NULL;
|
||||
@ -372,15 +395,17 @@ static attr_container_t * read_test_sensor(void * sensor)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool config_test_sensor(void * s, void * config)
|
||||
static bool
|
||||
config_test_sensor(void *s, void *config)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static char global_heap_buf[1024 * 1024] = { 0 };
|
||||
|
||||
static void showUsage()
|
||||
/* clang-format off */
|
||||
static void
|
||||
showUsage()
|
||||
{
|
||||
#ifndef CONNECTION_UART
|
||||
printf("Usage:\n");
|
||||
@ -401,8 +426,10 @@ static void showUsage()
|
||||
printf("\t<Baudrate> represents the UART device baudrate and the default is 115200\n");
|
||||
#endif
|
||||
}
|
||||
/* clang-format on */
|
||||
|
||||
static bool parse_args(int argc, char *argv[])
|
||||
static bool
|
||||
parse_args(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
|
||||
@ -410,14 +437,14 @@ static bool parse_args(int argc, char *argv[])
|
||||
int optIndex = 0;
|
||||
static struct option longOpts[] = {
|
||||
#ifndef CONNECTION_UART
|
||||
{ "server_mode", no_argument, NULL, 's' },
|
||||
{ "host_address", required_argument, NULL, 'a' },
|
||||
{ "port", required_argument, NULL, 'p' },
|
||||
{ "server_mode", no_argument, NULL, 's' },
|
||||
{ "host_address", required_argument, NULL, 'a' },
|
||||
{ "port", required_argument, NULL, 'p' },
|
||||
#else
|
||||
{ "uart", required_argument, NULL, 'u' },
|
||||
{ "baudrate", required_argument, NULL, 'b' },
|
||||
{ "uart", required_argument, NULL, 'u' },
|
||||
{ "baudrate", required_argument, NULL, 'b' },
|
||||
#endif
|
||||
{ "help", required_argument, NULL, 'h' },
|
||||
{ "help", required_argument, NULL, 'h' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@ -461,7 +488,8 @@ static bool parse_args(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Driver function
|
||||
int iwasm_main(int argc, char *argv[])
|
||||
int
|
||||
iwasm_main(int argc, char *argv[])
|
||||
{
|
||||
RuntimeInitArgs init_args;
|
||||
korp_tid tid;
|
||||
@ -499,22 +527,19 @@ int iwasm_main(int argc, char *argv[])
|
||||
/* sensor framework */
|
||||
init_sensor_framework();
|
||||
// add the sys sensor objects
|
||||
add_sys_sensor("sensor_test",
|
||||
"This is a sensor for test",
|
||||
0,
|
||||
1000,
|
||||
read_test_sensor,
|
||||
config_test_sensor);
|
||||
add_sys_sensor("sensor_test", "This is a sensor for test", 0, 1000,
|
||||
read_test_sensor, config_test_sensor);
|
||||
start_sensor_framework();
|
||||
|
||||
#ifndef CONNECTION_UART
|
||||
if (server_mode)
|
||||
os_thread_create(&tid, func_server_mode, NULL,
|
||||
BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
else
|
||||
os_thread_create(&tid, func, NULL, BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
#else
|
||||
os_thread_create(&tid, func_uart_mode, NULL, BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
os_thread_create(&tid, func_uart_mode, NULL,
|
||||
BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
#endif
|
||||
|
||||
app_manager_startup(&interface);
|
||||
|
||||
@ -3,8 +3,11 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
extern void iwasm_main();
|
||||
int main(int argc, char *argv[])
|
||||
extern void
|
||||
iwasm_main();
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
iwasm_main(argc, argv);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user