From: ChulHo Song Date: Mon, 15 Feb 2016 06:10:29 +0000 (+0900) Subject: ecs: apply code conventions X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~65 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=56b99df22c358c52d5bc8cf25c04d7fabb929675;p=sdk%2Femulator%2Fqemu.git ecs: apply code conventions Change-Id: I93f9cd75492f33259adeaa2ca5f237648f5e0312 Signed-off-by: ChulHo Song --- diff --git a/tizen/src/ecs/ecs-json-streamer.h b/tizen/src/ecs/ecs-json-streamer.h index 7b86247ffa..e7fa6dae62 100644 --- a/tizen/src/ecs/ecs-json-streamer.h +++ b/tizen/src/ecs/ecs-json-streamer.h @@ -23,15 +23,14 @@ typedef struct JSONToken { char str[]; } JSONToken; -typedef struct JSONMessageParser -{ +typedef struct JSONMessageParser { void (*emit)(struct JSONMessageParser *parser, GQueue *tokens, void *); JSONLexer lexer; int brace_count; int bracket_count; GQueue *tokens; uint64_t token_size; - void *opaque; + void *opaque; } JSONMessageParser; void ecs_json_message_parser_init(JSONMessageParser *parser, diff --git a/tizen/src/ecs/ecs.c b/tizen/src/ecs/ecs.c index 32ddd68d8b..f83ea961c2 100644 --- a/tizen/src/ecs/ecs.c +++ b/tizen/src/ecs/ecs.c @@ -4,6 +4,7 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: + * Chulho Song * Jinhyung Choi * MunKyu Im * Daiyoung Kim @@ -56,7 +57,7 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); #define DEBUG #ifndef min -#define min(a,b) ((a)<(b)?(a):(b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) #endif static QTAILQ_HEAD(ECS_ClientHead, ECS_Client) @@ -64,7 +65,7 @@ clients = QTAILQ_HEAD_INITIALIZER(clients); static ECS_State *current_ecs; -static void* keepalive_buf; +static void *keepalive_buf; static int payloadsize; static int g_client_id = 1; @@ -86,8 +87,9 @@ int ecs_get_suspend_state(void) return suspend_state; } -int ecs_write(int fd, const uint8_t *buf, int len) { - LOG_TRACE("write buflen : %d, buf : %s\n", len, (char*)buf); +int ecs_write(int fd, const uint8_t *buf, int len) +{ + LOG_TRACE("write buflen : %d, buf : %s\n", len, (char *)buf); if (fd < 0) { return -1; } @@ -95,9 +97,11 @@ int ecs_write(int fd, const uint8_t *buf, int len) { return send_all(fd, buf, len); } -void ecs_client_close(ECS_Client* clii) { - if (clii == NULL) +void ecs_client_close(ECS_Client *clii) +{ + if (clii == NULL) { return; + } qemu_mutex_lock(&mutex_clilist); @@ -118,11 +122,12 @@ void ecs_client_close(ECS_Client* clii) { qemu_mutex_unlock(&mutex_clilist); } -bool send_to_all_client(const char* data, const int len) { +bool send_to_all_client(const char *data, const int len) +{ LOG_TRACE("data len: %d, data: %s\n", len, data); qemu_mutex_lock(&mutex_clilist); - ECS_Client *clii,*next; + ECS_Client *clii, *next; QTAILQ_FOREACH_SAFE(clii, &clients, next, next) { @@ -133,43 +138,49 @@ bool send_to_all_client(const char* data, const int len) { return true; } -void send_to_single_client(ECS_Client *clii, const char* data, const int len) +void send_to_single_client(ECS_Client *clii, const char *data, const int len) { qemu_mutex_lock(&mutex_clilist); send_to_client(clii->client_fd, data, len); qemu_mutex_unlock(&mutex_clilist); } -void send_to_client(int fd, const char* data, const int len) +void send_to_client(int fd, const char *data, const int len) { - ecs_write(fd, (const uint8_t*) data, len); + ecs_write(fd, (const uint8_t *) data, len); } -void read_val_short(const char* data, unsigned short* ret_val) { +void read_val_short(const char *data, unsigned short *ret_val) +{ memcpy(ret_val, data, sizeof(unsigned short)); } -void read_val_char(const char* data, unsigned char* ret_val) { +void read_val_char(const char *data, unsigned char *ret_val) +{ memcpy(ret_val, data, sizeof(unsigned char)); } -void read_val_str(const char* data, char* ret_val, int len) { +void read_val_str(const char *data, char *ret_val, int len) +{ memcpy(ret_val, data, len); } -bool ntf_to_control(const char* data, const int len) { +bool ntf_to_control(const char *data, const int len) +{ return true; } -bool ntf_to_monitor(const char* data, const int len) { +bool ntf_to_monitor(const char *data, const int len) +{ return true; } -void print_binary(const char* data, const int len) { +void print_binary(const char *data, const int len) +{ int i; printf("[DATA: "); - for(i = 0; i < len; i++) { - if(i == len - 1) { + for (i = 0; i < len; i++) { + if (i == len - 1) { printf("%02x]\n", data[i]); } else { printf("%02x,", data[i]); @@ -177,14 +188,16 @@ void print_binary(const char* data, const int len) { } } -void ecs_make_header(QDict* obj, type_length length, type_group group, - type_action action) { - qdict_put(obj, "length", qint_from_int((int64_t )length)); - qdict_put(obj, "group", qint_from_int((int64_t )group)); - qdict_put(obj, "action", qint_from_int((int64_t )action)); +void ecs_make_header(QDict *obj, type_length length, type_group group, + type_action action) +{ + qdict_put(obj, "length", qint_from_int((int64_t)length)); + qdict_put(obj, "group", qint_from_int((int64_t)group)); + qdict_put(obj, "action", qint_from_int((int64_t)action)); } -static Monitor *monitor_create(void) { +static Monitor *monitor_create(void) +{ Monitor *mon; mon = g_malloc0(sizeof(*mon)); @@ -196,12 +209,14 @@ static Monitor *monitor_create(void) { return mon; } -static void ecs_close(ECS_State *cs) { +static void ecs_close(ECS_State *cs) +{ ECS_Client *clii, *next; LOG_INFO("### Good bye! ECS ###\n"); - if (cs == NULL) + if (cs == NULL) { return; + } if (0 <= cs->listen_fd) { LOG_INFO("close listen_fd: %d\n", cs->listen_fd); @@ -209,14 +224,11 @@ static void ecs_close(ECS_State *cs) { cs->listen_fd = -1; } - if (cs->mon != NULL) { - g_free(cs->mon); - cs->mon = NULL; - } + g_free(cs->mon); + cs->mon = NULL; - if (keepalive_buf) { - g_free(keepalive_buf); - } + g_free(keepalive_buf); + keepalive_buf = NULL; if (cs->alive_timer != NULL) { timer_del(cs->alive_timer); @@ -238,7 +250,8 @@ static void ecs_close(ECS_State *cs) { } #ifndef _WIN32 -static ssize_t ecs_recv(int fd, char *buf, size_t len) { +static ssize_t ecs_recv(int fd, char *buf, size_t len) +{ struct msghdr msg = { NULL, }; struct iovec iov[1]; union { @@ -268,47 +281,50 @@ static ssize_t ecs_recv(int fd, char *buf, size_t len) } #endif - -static void reset_sbuf(sbuf* sbuf) +static void reset_sbuf(sbuf *sbuf) { memset(sbuf->_buf, 0, 4096); sbuf->_use = 0; sbuf->_netlen = 0; } -static bool handle_protobuf_msg(ECS_Client* cli, char* data, int len) +static bool handle_protobuf_msg(ECS_Client *cli, char *data, int len) { - ECS__Master* master = ecs__master__unpack(NULL, (size_t)len, (const uint8_t*)data); - if (!master) + ECS__Master *master = ecs__master__unpack(NULL, (size_t)len, (const uint8_t *)data); + if (!master) { return false; + } if (master->type == ECS__MASTER__TYPE__INJECTOR_REQ) { - ECS__InjectorReq* msg = master->injector_req; - if (!msg) + ECS__InjectorReq *msg = master->injector_req; + if (!msg) { goto fail; + } msgproc_injector_req(cli, msg); } else if (master->type == ECS__MASTER__TYPE__MONITOR_REQ) { - ECS__MonitorReq* msg = master->monitor_req; - if (!msg) + ECS__MonitorReq *msg = master->monitor_req; + if (!msg) { goto fail; + } msgproc_monitor_req(cli, msg); } else if (master->type == ECS__MASTER__TYPE__DEVICE_REQ) { cli->client_type = TYPE_ECP; - ECS__DeviceReq* msg = master->device_req; - if (!msg) + ECS__DeviceReq *msg = master->device_req; + if (!msg) { goto fail; + } msgproc_device_req(cli, msg); } else if (master->type == ECS__MASTER__TYPE__NFC_REQ) { - ECS__NfcReq* msg = master->nfc_req; - if (!msg) + ECS__NfcReq *msg = master->nfc_req; + if (!msg) { goto fail; - + } qemu_mutex_lock(&mutex_clilist); - if(cli->client_type == TYPE_NONE) { + if (cli->client_type == TYPE_NONE) { if (!strncmp(msg->category, MSG_TYPE_NFC, 3)) { QTAILQ_REMOVE(&clients, cli, next); cli->client_type = TYPE_ECP; - if(g_client_id > 255) { + if (g_client_id > 255) { g_client_id = 1; } cli->client_id = g_client_id++; @@ -317,7 +333,7 @@ static bool handle_protobuf_msg(ECS_Client* cli, char* data, int len) } else if (!strncmp(msg->category, MSG_TYPE_SIMUL_NFC, 9)) { QTAILQ_REMOVE(&clients, cli, next); cli->client_type = TYPE_SIMUL_NFC; - if(g_client_id > 255) { + if (g_client_id > 255) { g_client_id = 1; } cli->client_id = g_client_id++; @@ -332,14 +348,16 @@ static bool handle_protobuf_msg(ECS_Client* cli, char* data, int len) msgproc_nfc_req(cli, msg); } else if (master->type == ECS__MASTER__TYPE__KEEPALIVE_ANS) { - ECS__KeepAliveAns* msg = master->keepalive_ans; - if (!msg) + ECS__KeepAliveAns *msg = master->keepalive_ans; + if (!msg) { goto fail; + } msgproc_keepalive_ans(cli, msg); } else if (master->type == ECS__MASTER__TYPE__EVENTCAST_REQ) { - ECS__EventCastReq* msg = master->eventcast_req; - if (!msg) + ECS__EventCastReq *msg = master->eventcast_req; + if (!msg) { goto fail; + } msgproc_eventcast_req(cli, msg); } else { goto fail; @@ -353,26 +371,24 @@ fail: return false; } -static void ecs_read(ECS_Client *cli) { +static void ecs_read(ECS_Client *cli) +{ int read = 0; int to_read_bytes = 0; - if (cli == NULL) - { + if (cli == NULL) { LOG_SEVERE("client is null.\n"); return; } #ifndef __WIN32 - if (ioctl(cli->client_fd, FIONREAD, &to_read_bytes) < 0) - { + if (ioctl(cli->client_fd, FIONREAD, &to_read_bytes) < 0) { LOG_SEVERE("ioctl failed\n"); return; } #else unsigned long to_read_bytes_long = 0; - if (ioctlsocket(cli->client_fd, FIONREAD, &to_read_bytes_long) < 0) - { + if (ioctlsocket(cli->client_fd, FIONREAD, &to_read_bytes_long) < 0) { LOG_SEVERE("ioctl failed\n"); return; } @@ -384,19 +400,15 @@ static void ecs_read(ECS_Client *cli) { goto fail; } - if (cli->sbuf._netlen == 0) - { - if (to_read_bytes < 4) - { - //LOG("insufficient data size to read\n"); + if (cli->sbuf._netlen == 0) { + if (to_read_bytes < 4) { return; } long payloadsize = 0; - read = ecs_recv(cli->client_fd, (char*) &payloadsize, 4); + read = ecs_recv(cli->client_fd, (char *) &payloadsize, 4); - if (read < 4) - { + if (read < 4) { LOG_SEVERE("insufficient header size\n"); goto fail; } @@ -410,23 +422,21 @@ static void ecs_read(ECS_Client *cli) { to_read_bytes -= 4; } - if (to_read_bytes == 0) + if (to_read_bytes == 0) { return; - + } to_read_bytes = min(to_read_bytes, cli->sbuf._netlen - cli->sbuf._use); - read = ecs_recv(cli->client_fd, (char*)(cli->sbuf._buf + cli->sbuf._use), to_read_bytes); - if (read == 0) + read = ecs_recv(cli->client_fd, (char *)(cli->sbuf._buf + cli->sbuf._use), to_read_bytes); + if (read == 0) { goto fail; - + } cli->sbuf._use += read; - - if (cli->sbuf._netlen == cli->sbuf._use) - { - handle_protobuf_msg(cli, (char*)cli->sbuf._buf, cli->sbuf._use); + if (cli->sbuf._netlen == cli->sbuf._use) { + handle_protobuf_msg(cli, (char *)cli->sbuf._buf, cli->sbuf._use); reset_sbuf(&cli->sbuf); } @@ -436,7 +446,8 @@ fail: } #ifdef CONFIG_LINUX -static void epoll_cli_add(ECS_State *cs, int fd) { +static void epoll_cli_add(ECS_State *cs, int fd) +{ struct epoll_event events; /* event control set for read event */ @@ -449,30 +460,34 @@ static void epoll_cli_add(ECS_State *cs, int fd) { } #endif -static ECS_Client *ecs_find_client(int fd) { +static ECS_Client *ecs_find_client(int fd) +{ ECS_Client *clii, *next; QTAILQ_FOREACH_SAFE(clii, &clients, next, next) { - if (clii->client_fd == fd) + if (clii->client_fd == fd) { return clii; + } } return NULL; } -ECS_Client *find_client(unsigned char id, unsigned char type) { +ECS_Client *find_client(unsigned char id, unsigned char type) +{ ECS_Client *clii, *next; QTAILQ_FOREACH_SAFE(clii, &clients, next, next) { - if (clii->client_id == id && clii->client_type == type) + if (clii->client_id == id && clii->client_type == type) { return clii; + } } return NULL; } -static int ecs_add_client(ECS_State *cs, int fd) { - +static int ecs_add_client(ECS_State *cs, int fd) +{ ECS_Client *clii = g_malloc0(sizeof(ECS_Client)); if (NULL == clii) { LOG_SEVERE("ECS_Client allocation failed.\n"); @@ -503,12 +518,15 @@ static int ecs_add_client(ECS_State *cs, int fd) { qemu_mutex_unlock(&mutex_clilist); -// send_ecs_version_check(clii); +#if 0 + send_ecs_version_check(clii); +#endif return 0; } -static void ecs_accept(ECS_State *cs) { +static void ecs_accept(ECS_State *cs) +{ struct sockaddr_in saddr; #ifndef _WIN32 struct sockaddr_un uaddr; @@ -541,7 +559,8 @@ static void ecs_accept(ECS_State *cs) { } #ifdef CONFIG_LINUX -static void epoll_init(ECS_State *cs) { +static void epoll_init(ECS_State *cs) +{ struct epoll_event events; cs->epoll_fd = epoll_create(MAX_EVENTS); @@ -559,18 +578,20 @@ static void epoll_init(ECS_State *cs) { } #endif -static void send_keep_alive_msg(ECS_Client *clii) { +static void send_keep_alive_msg(ECS_Client *clii) +{ send_to_single_client(clii, keepalive_buf, payloadsize); } -static void make_keep_alive_msg(void) { +static void make_keep_alive_msg(void) +{ int len_pack = 0; - char msg [5] = {'s','e','l','f'}; + char msg[5] = {'s', 'e', 'l', 'f'}; ECS__Master master = ECS__MASTER__INIT; ECS__KeepAliveReq req = ECS__KEEP_ALIVE_REQ__INIT; - req.time_str = (char*) g_malloc(5); + req.time_str = (char *) g_malloc(5); strncpy(req.time_str, msg, 4); @@ -592,8 +613,8 @@ static void make_keep_alive_msg(void) { memcpy(keepalive_buf, &len_pack, 4); } -static void alive_checker(void *opaque) { - +static void alive_checker(void *opaque) +{ ECS_Client *clii, *next; if (NULL != current_ecs && !current_ecs->ecs_running) { @@ -623,7 +644,8 @@ static void alive_checker(void *opaque) { } #ifdef CONFIG_LINUX -static int ecs_loop(ECS_State *cs) { +static int ecs_loop(ECS_State *cs) +{ int i, nfds; nfds = epoll_wait(cs->epoll_fd, cs->events, MAX_EVENTS, 100); @@ -632,8 +654,9 @@ static int ecs_loop(ECS_State *cs) { } if (0 > nfds) { - if (errno == EINTR) + if (errno == EINTR) { return 0; + } perror("epoll wait error"); return -1; } @@ -664,8 +687,9 @@ static int ecs_loop(ECS_State *cs) } for (index = 0; index < cs->reads.fd_count; index++) { - if (cs->reads.fd_array == NULL) + if (cs->reads.fd_array == NULL) { continue; + } if (FD_ISSET(cs->reads.fd_array[index], &temps)) { if (cs->reads.fd_array[index] == cs->listen_fd) { ecs_accept(cs); @@ -687,12 +711,13 @@ static int ecs_loop(ECS_State *cs) timeout.tv_sec = 5; timeout.tv_usec = 0; - if ((res = select(MAX_FD_NUM + 1, &temps, NULL, NULL, &timeout)) < 0) { + res = select(MAX_FD_NUM + 1, &temps, NULL, NULL, &timeout); + if (res < 0) { LOG_SEVERE("select failed..\n"); return -1; } - for (index = 0; index < MAX_FD_NUM; index ++) { + for (index = 0; index < MAX_FD_NUM; index++) { if (FD_ISSET(index, &temps)) { if (index == cs->listen_fd) { ecs_accept(cs); @@ -705,10 +730,10 @@ static int ecs_loop(ECS_State *cs) return 0; } - #endif -static int socket_initialize(ECS_State *cs) { +static int socket_initialize(ECS_State *cs) +{ LOG_INFO("Listen fd is %d\n", emul_vm_base_socket); g_assert(emul_vm_base_socket >= 0); @@ -731,10 +756,11 @@ static int socket_initialize(ECS_State *cs) { return 0; } -static void* ecs_initialize(void* args) { +static void *ecs_initialize(void *args) +{ int ret = 1; ECS_State *cs = NULL; - Monitor* mon = NULL; + Monitor *mon = NULL; LOG_INFO("ecs starts initializing.\n"); @@ -780,7 +806,8 @@ static void* ecs_initialize(void* args) { return NULL; } -bool is_ecs_running(void) { +bool is_ecs_running(void) +{ if (current_ecs != NULL) { return current_ecs->ecs_running; } @@ -788,7 +815,8 @@ bool is_ecs_running(void) { return false; } -static int stop_ecs(void) { +static int stop_ecs(void) +{ void *ret = NULL; LOG_INFO("ecs is closing.\n"); @@ -805,16 +833,17 @@ static int stop_ecs(void) { return 0; } -static void ecs_notify_exit(Notifier *notifier, void *data) { +static void ecs_notify_exit(Notifier *notifier, void *data) +{ stop_ecs(); } static Notifier ecs_exit = { .notify = ecs_notify_exit }; -int start_ecs(void) { +int start_ecs(void) +{ qemu_thread_create(&ecs_thread_id, "ecs", ecs_initialize, NULL, QEMU_THREAD_JOINABLE); emulator_add_exit_notifier(&ecs_exit); return 0; } - diff --git a/tizen/src/ecs/ecs.h b/tizen/src/ecs/ecs.h index 19e43d4046..028c2f0675 100644 --- a/tizen/src/ecs/ecs.h +++ b/tizen/src/ecs/ecs.h @@ -4,6 +4,7 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: + * Chulho Song * Jinhyung Choi * MunKyu Im * Daiyoung Kim @@ -64,14 +65,13 @@ typedef struct nfc_msg_info { unsigned char client_type; uint32_t use; unsigned char buf[NFC_MAX_BUF_SIZE]; - -}nfc_msg_info; +} nfc_msg_info; int start_ecs(void); bool is_ecs_running(void); -bool send_msg_to_guest(const char* cmd, int group, int action, - char* data, int data_len); +bool send_msg_to_guest(const char *cmd, int group, int action, + char *data, int data_len); /* System request */ enum ecs_system_action { @@ -81,11 +81,11 @@ enum ecs_system_action { void send_shutdown_request(int action); -void make_send_device_ntf (char* cmd, int group, int action, char* data); +void make_send_device_ntf(char *cmd, int group, int action, char *data); -bool send_injector_ntf(const char* data, const int len); -bool send_monitor_ntf(const char* data, const int len); -bool send_device_ntf(const char* data, const int len); +bool send_injector_ntf(const char *data, const int len); +bool send_monitor_ntf(const char *data, const int len); +bool send_device_ntf(const char *data, const int len); bool send_nfc_ntf(struct nfc_msg_info *msg); /* Suspend-resume */ diff --git a/tizen/src/ecs/ecs_eventcast.c b/tizen/src/ecs/ecs_eventcast.c index a922399a1c..d17e626dbe 100644 --- a/tizen/src/ecs/ecs_eventcast.c +++ b/tizen/src/ecs/ecs_eventcast.c @@ -51,7 +51,7 @@ DECLARE_DEBUG_CHANNEL(ecs); static bool send_eventcast_ntf(const char *data); static void send_eventcast_status_ntf(type_group group, type_action action); -static int eventcast_port = 0; +static int eventcast_port; void send_eventcast_sensor_status_ecp(void) { @@ -102,9 +102,7 @@ static void send_eventcast_port_ecp(void) send_eventcast_ntf((const char *)msg); - if (msg) { - g_free(msg); - } + g_free(msg); } #endif @@ -164,20 +162,20 @@ static void send_eventcast_status_ntf(type_group group, type_action action) gchar data[2]; switch (action) { - case ECS_EVENTCAST_MSG_ACTION_CONNECTION_STATUS: - status = get_eventcast_connection_status(); - if (status == CONNECTED) { - send_eventcast_connection_info(); - } - break; - case ECS_EVENTCAST_MSG_ACTION_SENSOR_STATUS: - status = get_eventcast_sensor_status(); - break; - case ECS_EVENTCAST_MSG_ACTION_TOUCH_STATUS: - status = get_eventcast_touch_status(); - break; - default: - break; + case ECS_EVENTCAST_MSG_ACTION_CONNECTION_STATUS: + status = get_eventcast_connection_status(); + if (status == CONNECTED) { + send_eventcast_connection_info(); + } + break; + case ECS_EVENTCAST_MSG_ACTION_SENSOR_STATUS: + status = get_eventcast_sensor_status(); + break; + case ECS_EVENTCAST_MSG_ACTION_TOUCH_STATUS: + status = get_eventcast_touch_status(); + break; + default: + break; } msg = g_malloc(MSG_BUF_SIZE); @@ -198,9 +196,7 @@ static void send_eventcast_status_ntf(type_group group, type_action action) send_eventcast_ntf((const char *)msg); - if (msg) { - g_free(msg); - } + g_free(msg); } static bool send_eventcast_ntf(const char *data) @@ -218,14 +214,14 @@ static bool send_eventcast_ntf(const char *data) read_val_char(data + catsize + 2, &group); read_val_char(data + catsize + 2 + 1, &action); - const char* ijdata = (data + catsize + 2 + 1 + 1); + const char *ijdata = (data + catsize + 2 + 1 + 1); - LOG_TRACE("header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); + LOG_TRACE("header cat = %s, length = %d, action=%d, group=%d\n", cat, length, action, group); ECS__Master master = ECS__MASTER__INIT; ECS__EventCastNtf ntf = ECS__EVENT_CAST_NTF__INIT; - ntf.category = (char*) g_malloc(catsize + 1); + ntf.category = (char *) g_malloc(catsize + 1); strncpy(ntf.category, cat, 10); ntf.length = length; @@ -251,9 +247,7 @@ static bool send_eventcast_ntf(const char *data) g_free(ntf.data.data); } - if (ntf.category) { - g_free(ntf.category); - } + g_free(ntf.category); return true; } @@ -274,8 +268,8 @@ void send_eventcast_hwkey_data(int keycode) maru_hwkey_event(RELEASED, keycode); } -// handle eventcast_req message -bool msgproc_eventcast_req(ECS_Client* ccli, ECS__EventCastReq* msg) +/* handle eventcast_req message */ +bool msgproc_eventcast_req(ECS_Client *ccli, ECS__EventCastReq *msg) { gchar cmd[10] = {0}; gchar **server_addr = NULL; @@ -290,57 +284,57 @@ bool msgproc_eventcast_req(ECS_Client* ccli, ECS__EventCastReq* msg) LOG_TRACE("<< header = cmd = %s, length = %d, action=%d, group=%d\n", cmd, length, action, group); - switch(action) { - case ECS_EVENTCAST_MSG_ACTION_CONNECT: - LOG_TRACE("MSG_ACTION_CONNECT\n"); - - if (msg->data.data && msg->data.len > 0) { - const gchar *data = (const gchar *)msg->data.data; - gchar *ip_address = NULL; - guint64 port = 0; + switch (action) { + case ECS_EVENTCAST_MSG_ACTION_CONNECT: + LOG_TRACE("MSG_ACTION_CONNECT\n"); - server_addr = g_strsplit(data, ":", 0); - if (server_addr && server_addr[0]) { - int len = strlen(server_addr[0]); + if (msg->data.data && msg->data.len > 0) { + const gchar *data = (const gchar *)msg->data.data; + gchar *ip_address = NULL; + guint64 port = 0; - if (len) { - ip_address = g_malloc(len + 1); - g_strlcpy(ip_address, server_addr[0], len + 1); - } - LOG_INFO("IP address: %s, length: %d\n", ip_address, len); - } + server_addr = g_strsplit(data, ":", 0); + if (server_addr && server_addr[0]) { + int len = strlen(server_addr[0]); - if (server_addr && server_addr[1]) { - port = g_ascii_strtoull(server_addr[1], NULL, 10); - LOG_INFO("port number: %d\n", port); - } else { - LOG_SEVERE("failed to parse port number\n"); + if (len) { + ip_address = g_malloc(len + 1); + g_strlcpy(ip_address, server_addr[0], len + 1); } - LOG_TRACE("len = %zd, data\" %s\"", strlen(data), data); - - connect_eventcast_app(ip_address, port); - eventcast_port = port; + LOG_INFO("IP address: %s, length: %d\n", ip_address, len); + } - LOG_TRACE("port_num: %d, %d\n", port, eventcast_port); - g_free(ip_address); - g_strfreev(server_addr); + if (server_addr && server_addr[1]) { + port = g_ascii_strtoull(server_addr[1], NULL, 10); + LOG_INFO("port number: %d\n", port); } else { - LOG_SEVERE("ip address and port value are null\n"); + LOG_SEVERE("failed to parse port number\n"); } - break; - case ECS_EVENTCAST_MSG_ACTION_DISCONNECT: - LOG_TRACE("MSG_ACTION_DISCONNECT\n"); - disconnect_eventcast_app(); - eventcast_port = 0; - break; - case ECS_EVENTCAST_MSG_ACTION_CONNECTION_STATUS: - case ECS_EVENTCAST_MSG_ACTION_SENSOR_STATUS: - case ECS_EVENTCAST_MSG_ACTION_TOUCH_STATUS: - LOG_TRACE("get_status_action\n"); - send_eventcast_status_ntf(group, action); - break; - default: - break; + LOG_TRACE("len = %zd, data\" %s\"", strlen(data), data); + + connect_eventcast_app(ip_address, port); + eventcast_port = port; + + LOG_TRACE("port_num: %d, %d\n", port, eventcast_port); + g_free(ip_address); + g_strfreev(server_addr); + } else { + LOG_SEVERE("ip address and port value are null\n"); + } + break; + case ECS_EVENTCAST_MSG_ACTION_DISCONNECT: + LOG_TRACE("MSG_ACTION_DISCONNECT\n"); + disconnect_eventcast_app(); + eventcast_port = 0; + break; + case ECS_EVENTCAST_MSG_ACTION_CONNECTION_STATUS: + case ECS_EVENTCAST_MSG_ACTION_SENSOR_STATUS: + case ECS_EVENTCAST_MSG_ACTION_TOUCH_STATUS: + LOG_TRACE("get_status_action\n"); + send_eventcast_status_ntf(group, action); + break; + default: + break; } LOG_TRACE("leave %s\n", __func__); diff --git a/tizen/src/ecs/ecs_hds.c b/tizen/src/ecs/ecs_hds.c index c7c4d39049..5a145b3e47 100644 --- a/tizen/src/ecs/ecs_hds.c +++ b/tizen/src/ecs/ecs_hds.c @@ -4,7 +4,8 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * Jinhyung choi + * Chulho Song + * Jinhyung Choi * Sangho Park * * This program is free software; you can redistribute it and/or @@ -39,13 +40,13 @@ MULTI_DEBUG_CHANNEL(qemu, hds); -// send # of available PCI slot -static void ecs_hds_send_available_pci(char* cmd) +/* send # of available PCI slot */ +static void ecs_hds_send_available_pci(char *cmd) { int n_possible; int n_hidden; int n_available = 0; - char slot_data [OUT_BUF_SIZE]; + char slot_data[OUT_BUF_SIZE]; n_possible = hds_get_pci_available_slot_num(); if (n_possible > 0) { @@ -58,7 +59,7 @@ static void ecs_hds_send_available_pci(char* cmd) } n_available = n_possible - n_hidden; - if (n_available < 0){ + if (n_available < 0) { n_available = 0; } } @@ -89,7 +90,7 @@ static bool check_pci_slot(enum hds_level level) n_hidden = ECS_HDS_HIDDEN_RESERVED - n_hidden; n_possible = n_possible - n_hidden; - if (n_possible <= 0){ + if (n_possible <= 0) { return false; } } @@ -97,22 +98,22 @@ static bool check_pci_slot(enum hds_level level) return true; } -static void ecs_hds_do_status(char* cmd, type_group group) +static void ecs_hds_do_status(char *cmd, type_group group) { - char* data = get_hds_lists(); + char *data = get_hds_lists(); LOG_INFO("hds status: %s\n", data); make_send_device_ntf(cmd, group, ECS_HDS_ACTION_STATE, data); ecs_hds_send_available_pci(cmd); } -static void ecs_hds_do_mount(char* cmd, type_group group, char *data) +static void ecs_hds_do_mount(char *cmd, type_group group, char *data) { char token[] = "\n"; - char* host; - char* level_token; - char* hds_id; - char* guest; + char *host; + char *level_token; + char *hds_id; + char *guest; int level = 0; if (data == NULL) { @@ -126,7 +127,7 @@ static void ecs_hds_do_mount(char* cmd, type_group group, char *data) LOG_WARNING("ecs_hds_do_mount host token is empty.\n"); make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_FAIL, NULL); return; - } else if (hds_is_host_path_used((const char*)host)) { + } else if (hds_is_host_path_used((const char *)host)) { LOG_WARNING("host path '%s' is already taken.\n", host); make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_DUP_HOST_PATH, NULL); return; @@ -137,7 +138,7 @@ static void ecs_hds_do_mount(char* cmd, type_group group, char *data) LOG_WARNING("ecs_hds_do_mount guest token is empty.\n"); make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_FAIL, NULL); return; - } else if (hds_is_guest_path_used((const char*)guest)) { + } else if (hds_is_guest_path_used((const char *)guest)) { LOG_WARNING("guest path '%s' is already taken.\n", guest); make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_DUP_GUEST_PATH, NULL); return; @@ -148,7 +149,7 @@ static void ecs_hds_do_mount(char* cmd, type_group group, char *data) level = atoi(level_token); } - // check available PCI slot num + /* check available PCI slot num */ if (!check_pci_slot(level)) { LOG_WARNING("No available pci slot.\n"); make_send_device_ntf(cmd, group, ECS_HDS_ACT_MOUNT_NO_SPACE, NULL); @@ -165,16 +166,16 @@ static void ecs_hds_do_mount(char* cmd, type_group group, char *data) } } -static void ecs_hds_do_umount(char* cmd, type_group group, type_action action, char *data) +static void ecs_hds_do_umount(char *cmd, type_group group, type_action action, char *data) { int level = 0; int len = 0; enum hds_level tag_level = 0; char token[] = "\n"; - char* tag; - char* level_token; - char* guest_path; - char emuld_data [OUT_BUF_SIZE]; + char *tag; + char *level_token; + char *guest_path; + char emuld_data[OUT_BUF_SIZE]; if (data == NULL) { LOG_WARNING("ecs_hds_do_umount data is empty.\n"); @@ -223,15 +224,14 @@ static void ecs_hds_do_umount(char* cmd, type_group group, type_action action, c send_msg_to_guest(cmd, group, action, emuld_data, len + 1); } -void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char * cmd) +void msgproc_device_req_hds(ECS_Client *ccli, ECS__DeviceReq *msg, char * cmd) { - char* data = NULL; + char *data = NULL; type_group group = (type_group) (msg->group & 0xff); type_action action = (type_action) (msg->action & 0xff); - if (msg->has_data && msg->data.len > 0) - { - data = (char*) g_malloc0(msg->data.len + 1); + if (msg->has_data && msg->data.len > 0) { + data = (char *) g_malloc0(msg->data.len + 1); memcpy(data, msg->data.data, msg->data.len); } @@ -246,19 +246,17 @@ void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char * cmd) LOG_WARNING("hds unknown command: group %d action %d\n", group, action); } - if (data) { - g_free(data); - } + g_free(data); } -static void send_hds_mount_request(char* list) +static void send_hds_mount_request(char *list) { int len = 0; char token[] = ","; - char emuld_data [OUT_BUF_SIZE]; - char* id; - char* host; - char* guest; + char emuld_data[OUT_BUF_SIZE]; + char *id; + char *host; + char *guest; LOG_INFO("handling mount request: %s\n", list); @@ -285,11 +283,11 @@ static void send_hds_mount_request(char* list) ECS_HDS_ACTION_MOUNT, emuld_data, len + 1); } -static void* hds_mount_request_thread(void* args) +static void *hds_mount_request_thread(void *args) { - char* list = (char*)args; + char *list = (char *)args; char token[] = "\n"; - char* hds_list; + char *hds_list; hds_list = strtok(list, token); if (hds_list == NULL) { @@ -300,7 +298,7 @@ static void* hds_mount_request_thread(void* args) send_hds_mount_request(hds_list); - while((hds_list = strtok(NULL, token)) != NULL) { + while ((hds_list = strtok(NULL, token)) != NULL) { send_hds_mount_request(hds_list); } @@ -310,7 +308,7 @@ static void* hds_mount_request_thread(void* args) static void ecs_hds_do_get_list(void) { - char* list; + char *list; QemuThread hds_thread_id; list = get_hds_lists(); @@ -319,86 +317,86 @@ static void ecs_hds_do_get_list(void) return; } qemu_thread_create(&hds_thread_id, "hds_mount", hds_mount_request_thread, - (void*)list, QEMU_THREAD_DETACHED); + (void *)list, QEMU_THREAD_DETACHED); } -void msgproc_injector_do_hds(char* cat, type_action action, const char* data) +void msgproc_injector_do_hds(char *cat, type_action action, const char *data) { FsDriverEntry *entry; - char msg [OUT_BUF_SIZE]; + char msg[OUT_BUF_SIZE]; char *host; char *guest; enum hds_level level; LOG_INFO("hds status is %d, %s\n", action, data); switch (action) { - case ECS_HDS_ACT_GET_LIST: - ecs_hds_do_get_list(); + case ECS_HDS_ACT_GET_LIST: + ecs_hds_do_get_list(); + break; + case ECS_HDS_ACT_ADD_LIST_FOR_DEFAULT: + entry = get_fsdev_fsentry((char *)DEFAULT_STATIC_HDS_ID); + if (entry == NULL) { + LOG_WARNING("cannot find fsdev entry.\n"); break; - case ECS_HDS_ACT_ADD_LIST_FOR_DEFAULT: - entry = get_fsdev_fsentry((char*)DEFAULT_STATIC_HDS_ID); - if (entry == NULL) { - LOG_WARNING("cannot find fsdev entry.\n"); - break; - } - - if (!add_hds_list(DEFAULT_STATIC_HDS_ID, entry->path, DEFAULT_HDS_GUEST_PATH, hds_level_normal)) { - LOG_WARNING("cannot add into hds list.\n"); - break; - } - - set_hds_attached(DEFAULT_STATIC_HDS_ID, true); - data = DEFAULT_STATIC_HDS_ID; - - // pass-through - case ECS_HDS_ACT_MOUNT_SUCCESS: - if (data == NULL) { - LOG_WARNING("error: hds data is null.\n"); - break; - } - host = get_host_path_by_id(data); - if (host == NULL) { - LOG_WARNING("get_host_path_by_id failed with %s\n", data); - break; - } - guest = get_guest_path_by_id(data); - if (guest == NULL) { - LOG_WARNING("get_guest_path_by_id failed with %s\n", data); - break; - } - - level = get_hds_level_by_id(data); - snprintf(msg, sizeof(msg), "%s,%s,%s,%d,", data, host, guest, level); - make_send_device_ntf(cat, ECS_HDS_MSG_GROUP, action, msg); + } + + if (!add_hds_list(DEFAULT_STATIC_HDS_ID, entry->path, DEFAULT_HDS_GUEST_PATH, hds_level_normal)) { + LOG_WARNING("cannot add into hds list.\n"); break; - case ECS_HDS_ACT_MOUNT_FAIL: - case ECS_HDS_ACT_MOUNT_NOT_PERMITTED: // not exist on the possible path - case ECS_HDS_ACT_MOUNT_NOT_VALID_PATH: // not a vaild path - if (data == NULL) { - LOG_WARNING("error: hds data is null.\n"); - break; - } - remove_hds_list((char*)data); - do_hotplug(DETACH_HDS, (char*)data, strlen(data) + 1); - make_send_device_ntf(cat, ECS_HDS_MSG_GROUP, action, (char*)data); + } + + set_hds_attached(DEFAULT_STATIC_HDS_ID, true); + data = DEFAULT_STATIC_HDS_ID; + /* pass-through */ + + case ECS_HDS_ACT_MOUNT_SUCCESS: + if (data == NULL) { + LOG_WARNING("error: hds data is null.\n"); break; - case ECS_HDS_ACT_UMOUNT_SUCCESS: - if (data == NULL) { - LOG_WARNING("error: hds data is null.\n"); - break; - } - do_hotplug(DETACH_HDS, (char*)data, strlen(data) + 1); - make_send_device_ntf(cat, ECS_HDS_MSG_GROUP, action, (char*)data); + } + host = get_host_path_by_id(data); + if (host == NULL) { + LOG_WARNING("get_host_path_by_id failed with %s\n", data); break; - case ECS_HDS_ACT_UMOUNT_FAIL: - if (data == NULL) { - LOG_WARNING("error: hds data is null.\n"); - break; - } - make_send_device_ntf(cat, ECS_HDS_MSG_GROUP, action, (char*)data); + } + guest = get_guest_path_by_id(data); + if (guest == NULL) { + LOG_WARNING("get_guest_path_by_id failed with %s\n", data); break; - default: - LOG_WARNING("unknown action: %s.\n", action); + } + + level = get_hds_level_by_id(data); + snprintf(msg, sizeof(msg), "%s,%s,%s,%d,", data, host, guest, level); + make_send_device_ntf(cat, ECS_HDS_MSG_GROUP, action, msg); + break; + case ECS_HDS_ACT_MOUNT_FAIL: + case ECS_HDS_ACT_MOUNT_NOT_PERMITTED: /* not exist on the possible path */ + case ECS_HDS_ACT_MOUNT_NOT_VALID_PATH: /* not a vaild path */ + if (data == NULL) { + LOG_WARNING("error: hds data is null.\n"); break; + } + remove_hds_list((char *)data); + do_hotplug(DETACH_HDS, (char *)data, strlen(data) + 1); + make_send_device_ntf(cat, ECS_HDS_MSG_GROUP, action, (char *)data); + break; + case ECS_HDS_ACT_UMOUNT_SUCCESS: + if (data == NULL) { + LOG_WARNING("error: hds data is null.\n"); + break; + } + do_hotplug(DETACH_HDS, (char *)data, strlen(data) + 1); + make_send_device_ntf(cat, ECS_HDS_MSG_GROUP, action, (char *)data); + break; + case ECS_HDS_ACT_UMOUNT_FAIL: + if (data == NULL) { + LOG_WARNING("error: hds data is null.\n"); + break; + } + make_send_device_ntf(cat, ECS_HDS_MSG_GROUP, action, (char *)data); + break; + default: + LOG_WARNING("unknown action: %s.\n", action); + break; } } diff --git a/tizen/src/ecs/ecs_hds.h b/tizen/src/ecs/ecs_hds.h index de8a13070a..c76468c86d 100644 --- a/tizen/src/ecs/ecs_hds.h +++ b/tizen/src/ecs/ecs_hds.h @@ -4,7 +4,8 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * Jinhyung choi + * Chulho Song + * Jinhyung Choi * Sangho Park * * This program is free software; you can redistribute it and/or @@ -41,7 +42,7 @@ #define ECS_HDS_ACTION_STATE 99 enum hds_act_result { - //FIXME: numbering & ordering + /* FIXME: numbering & ordering */ ECS_HDS_ACT_GET_LIST = 0, ECS_HDS_ACT_MOUNT_SUCCESS = 1, ECS_HDS_ACT_MOUNT_FAIL = 2, @@ -57,7 +58,7 @@ enum hds_act_result { ECS_HDS_ACT_ADD_LIST_FOR_DEFAULT = 99 }; -void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char * cmd); -void msgproc_injector_do_hds(char* cat, type_action action, const char* data); +void msgproc_device_req_hds(ECS_Client *ccli, ECS__DeviceReq *msg, char *cmd); +void msgproc_injector_do_hds(char *cat, type_action action, const char *data); #endif /* __ECS_HDS_H__ */ diff --git a/tizen/src/ecs/ecs_internal.h b/tizen/src/ecs/ecs_internal.h index 02da13bfd6..fbd2b09467 100644 --- a/tizen/src/ecs/ecs_internal.h +++ b/tizen/src/ecs/ecs_internal.h @@ -4,6 +4,7 @@ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: + * Chulho Song * Jinhyung Choi * SeokYeon Hwang * Sangho Park @@ -68,8 +69,7 @@ enum message_action { MSG_ACT_NETBRIDGE = 123 }; -typedef struct sbuf -{ +typedef struct sbuf { int _netlen; int _use; char _buf[OUT_BUF_SIZE]; @@ -81,7 +81,7 @@ struct Monitor { int outbuf_index; void *password_opaque; Error *error; - QLIST_HEAD(,mon_fd_t) fds; + QLIST_HEAD(, mon_fd_t) fds; QLIST_ENTRY(Monitor) entry; }; @@ -110,7 +110,7 @@ typedef struct ECS_Client { unsigned char client_id; unsigned char client_type; int keep_alive; - const char* type; + const char *type; sbuf sbuf; @@ -125,35 +125,35 @@ typedef unsigned char type_group; typedef unsigned char type_action; -void read_val_short(const char* data, unsigned short* ret_val); -void read_val_char(const char* data, unsigned char* ret_val); -void read_val_str(const char* data, char* ret_val, int len); -void print_binary(const char* data, const int len); +void read_val_short(const char *data, unsigned short *ret_val); +void read_val_char(const char *data, unsigned char *ret_val); +void read_val_str(const char *data, char *ret_val, int len); +void print_binary(const char *data, const int len); -bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg); -bool msgproc_monitor_req(ECS_Client *ccli, ECS__MonitorReq* msg); -bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg); -bool msgproc_device_req_ext(ECS_Client* ccli, ECS__DeviceReq* msg); -bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg); -void msgproc_keepalive_ans(ECS_Client* ccli, ECS__KeepAliveAns* msg); -bool msgproc_eventcast_req(ECS_Client* ccli, ECS__EventCastReq* msg); +bool msgproc_injector_req(ECS_Client *ccli, ECS__InjectorReq *msg); +bool msgproc_monitor_req(ECS_Client *ccli, ECS__MonitorReq *msg); +bool msgproc_device_req(ECS_Client *ccli, ECS__DeviceReq *msg); +bool msgproc_device_req_ext(ECS_Client *ccli, ECS__DeviceReq *msg); +bool msgproc_nfc_req(ECS_Client *ccli, ECS__NfcReq *msg); +void msgproc_keepalive_ans(ECS_Client *ccli, ECS__KeepAliveAns *msg); +bool msgproc_eventcast_req(ECS_Client *ccli, ECS__EventCastReq *msg); ECS_Client *find_client(unsigned char id, unsigned char type); -bool ntf_to_injector(const char* data, const int len); -bool ntf_to_control(const char* data, const int len); -bool ntf_to_monitor(const char* data, const int len); +bool ntf_to_injector(const char *data, const int len); +bool ntf_to_control(const char *data, const int len); +bool ntf_to_monitor(const char *data, const int len); -bool pb_to_all_clients(ECS__Master* master); -bool pb_to_single_client(ECS__Master* master, ECS_Client *clii); +bool pb_to_all_clients(ECS__Master *master); +bool pb_to_single_client(ECS__Master *master, ECS_Client *clii); -void send_to_single_client(ECS_Client *clii, const char* data, const int len); -bool send_to_all_client(const char* data, const int len); -void send_to_client(int fd, const char* data, const int len); +void send_to_single_client(ECS_Client *clii, const char *data, const int len); +bool send_to_all_client(const char *data, const int len); +void send_to_client(int fd, const char *data, const int len); -void ecs_client_close(ECS_Client* clii); +void ecs_client_close(ECS_Client *clii); int ecs_write(int fd, const uint8_t *buf, int len); -void ecs_make_header(QDict* obj, type_length length, type_group group, type_action action); +void ecs_make_header(QDict *obj, type_length length, type_group group, type_action action); /* Monitor */ diff --git a/tizen/src/ecs/ecs_mon.c b/tizen/src/ecs/ecs_mon.c index 48a12e599d..46e615825c 100644 --- a/tizen/src/ecs/ecs_mon.c +++ b/tizen/src/ecs/ecs_mon.c @@ -4,7 +4,8 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * Jinhyung choi + * Chulho Song + * Jinhyung Choi * MunKyu Im * Daiyoung Kim * YeongKyoon Lee @@ -73,7 +74,7 @@ typedef struct mon_cmd_t { } mon_cmd_t; /* -void send_to_client(int fd, const char* data, const int len) +void send_to_client(int fd, const char *data, const int len) { char c; uint8_t outbuf[OUT_BUF_SIZE]; @@ -101,14 +102,14 @@ void send_to_client(int fd, const char* data, const int len) #define QMP_ACCEPT_UNKNOWNS 1 -bool send_monitor_ntf(const char* data, int size) +bool send_monitor_ntf(const char *data, int size) { ECS__Master master = ECS__MASTER__INIT; ECS__MonitorNtf ntf = ECS__MONITOR_NTF__INIT; TRACE("data size : %d, data : %s\n", size, data); - ntf.command = (char*) g_malloc(size + 1); + ntf.command = (char *) g_malloc(size + 1); memcpy(ntf.command, data, size); master.type = ECS__MASTER__TYPE__MONITOR_NTF; @@ -116,18 +117,20 @@ bool send_monitor_ntf(const char* data, int size) pb_to_all_clients(&master); - if (ntf.command) - g_free(ntf.command); + g_free(ntf.command); return true; } -static void ecs_monitor_flush(ECS_Client *clii, Monitor *mon) { +static void ecs_monitor_flush(ECS_Client *clii, Monitor *mon) +{ int ret; if (clii && 0 < clii->client_fd && mon && mon->outbuf_index != 0) { - //ret = ecs_write(clii->client_fd, mon->outbuf, mon->outbuf_index); - ret = send_monitor_ntf((char*)mon->outbuf, mon->outbuf_index); +#if 0 + ret = ecs_write(clii->client_fd, mon->outbuf, mon->outbuf_index); +#endif + ret = send_monitor_ntf((char *)mon->outbuf, mon->outbuf_index); memset(mon->outbuf, 0, sizeof(mon->outbuf)); mon->outbuf_index = 0; if (ret < -1) { @@ -136,7 +139,8 @@ static void ecs_monitor_flush(ECS_Client *clii, Monitor *mon) { } } -static void ecs_monitor_puts(ECS_Client *clii, Monitor *mon, const char *str) { +static void ecs_monitor_puts(ECS_Client *clii, Monitor *mon, const char *str) +{ char c; if (!clii || !mon) { @@ -145,11 +149,13 @@ static void ecs_monitor_puts(ECS_Client *clii, Monitor *mon, const char *str) { for (;;) { c = *str++; - if (c == '\0') + if (c == '\0') { break; + } #ifndef _WIN32 - if (c == '\n') + if (c == '\n') { mon->outbuf[mon->outbuf_index++] = '\r'; + } #endif mon->outbuf[mon->outbuf_index++] = c; if (mon->outbuf_index >= (sizeof(mon->outbuf) - 2) || c == '\n') { @@ -159,7 +165,8 @@ static void ecs_monitor_puts(ECS_Client *clii, Monitor *mon, const char *str) { } } -static QDict *build_qmp_error_dict(Error *err) { +static QDict *build_qmp_error_dict(Error *err) +{ QObject *obj = qobject_from_jsonf( "{ 'error': { 'class': %s, 'desc': %s } }", ErrorClass_lookup[error_get_class(err)], error_get_pretty(err)); @@ -167,7 +174,8 @@ static QDict *build_qmp_error_dict(Error *err) { return qobject_to_qdict(obj); } -static void ecs_json_emitter(ECS_Client *clii, const QObject *data) { +static void ecs_json_emitter(ECS_Client *clii, const QObject *data) +{ QString *json; json = qobject_to_json(data); @@ -180,13 +188,16 @@ static void ecs_json_emitter(ECS_Client *clii, const QObject *data) { QDECREF(json); } -static void ecs_protocol_emitter(ECS_Client *clii, const char* type, - QObject *data, Error *err) { +static void ecs_protocol_emitter(ECS_Client *clii, const char *type, + QObject *data, Error *err) +{ QDict *qmp; QObject *obj; TRACE("ecs_protocol_emitter called.\n"); - //trace_monitor_protocol_emitter(clii->cs->mon); +#if 0 + trace_monitor_protocol_emitter(clii->cs->mon); +#endif if (!err) { /* success response */ @@ -215,8 +226,9 @@ static void ecs_protocol_emitter(ECS_Client *clii, const char* type, QDECREF(qmp); } -static void ecs_qmp_call_cmd(ECS_Client *clii, Monitor *mon, const char* type, - const mon_cmd_t *cmd, QDict *params) { +static void ecs_qmp_call_cmd(ECS_Client *clii, Monitor *mon, const char *type, + const mon_cmd_t *cmd, QDict *params) +{ QObject *data = NULL; Error *local_err = NULL; @@ -225,10 +237,12 @@ static void ecs_qmp_call_cmd(ECS_Client *clii, Monitor *mon, const char* type, qobject_decref(data); } -static void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) { +static void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) +{ } -static void qmp_capabilities(QDict *params, QObject **ret_data, Error **errp) { +static void qmp_capabilities(QDict *params, QObject **ret_data, Error **errp) +{ } static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, @@ -336,7 +350,8 @@ static void check_client_args_type(const QDict *client_args, } } -static QDict *qdict_from_args_type(const char *args_type) { +static QDict *qdict_from_args_type(const char *args_type) +{ int i; QDict *qdict; QString *key, *type, *cur_qs; @@ -399,7 +414,8 @@ out: QDECREF(cmd_args); } -static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp) { +static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp) +{ const QDictEntry *ent; int has_exec_key = 0; QDict *input_dict; @@ -446,7 +462,8 @@ static QDict *qmp_check_input_obj(QObject *input_obj, Error **errp) { return input_dict; } -static int compare_cmd(const char *name, const char *list) { +static int compare_cmd(const char *name, const char *list) +{ const char *p, *pstart; int len; len = strlen(name); @@ -454,19 +471,23 @@ static int compare_cmd(const char *name, const char *list) { for (;;) { pstart = p; p = strchr(p, '|'); - if (!p) + if (!p) { p = pstart + strlen(pstart); - if ((p - pstart) == len && !memcmp(pstart, name, len)) + } + if ((p - pstart) == len && !memcmp(pstart, name, len)) { return 1; - if (*p == '\0') + } + if (*p == '\0') { break; + } p++; } return 0; } static const mon_cmd_t *search_dispatch_table(const mon_cmd_t *disp_table, - const char *cmdname) { + const char *cmdname) +{ const mon_cmd_t *cmd; for (cmd = disp_table; cmd->name != NULL; cmd++) { @@ -478,7 +499,8 @@ static const mon_cmd_t *search_dispatch_table(const mon_cmd_t *disp_table, return NULL; } -static const mon_cmd_t *qmp_find_cmd(const char *cmdname) { +static const mon_cmd_t *qmp_find_cmd(const char *cmdname) +{ return search_dispatch_table(qmp_cmds, cmdname); } @@ -498,7 +520,7 @@ void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens, obj = json_parser_parse(tokens, NULL); if (!obj) { - // FIXME: should be triggered in json_parser_parse() + /* FIXME: should be triggered in json_parser_parse() */ error_setg(&local_err, QERR_JSON_PARSING); goto err_out; } @@ -510,7 +532,9 @@ void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens, } cmd_name = qdict_get_str(input, "execute"); - //trace_handle_qmp_command(mon, cmd_name); +#if 0 + trace_handle_qmp_command(mon, cmd_name); +#endif cmd = qmp_find_cmd(cmd_name); if (!cmd) { @@ -546,7 +570,7 @@ out: QDECREF(args); } -bool msgproc_monitor_req(ECS_Client *ccli, ECS__MonitorReq* msg) +bool msgproc_monitor_req(ECS_Client *ccli, ECS__MonitorReq *msg) { TRACE(">> monitor req: data = %s\n", msg->command); ecs_json_message_parser_feed(&(ccli->parser), (const char *) msg->command, strlen(msg->command)); diff --git a/tizen/src/ecs/ecs_msg.c b/tizen/src/ecs/ecs_msg.c index b8fb4281c6..81c162f02e 100644 --- a/tizen/src/ecs/ecs_msg.c +++ b/tizen/src/ecs/ecs_msg.c @@ -3,7 +3,8 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * Jinhyung choi + * Chulho Song + * Jinhyung Choi * MunKyu Im * Daiyoung Kim * YeongKyoon Lee @@ -65,14 +66,15 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); -static void* build_master(ECS__Master* master, int* payloadsize) +static void *build_master(ECS__Master *master, int *payloadsize) { int len_pack = ecs__master__get_packed_size(master); *payloadsize = len_pack + 4; LOG_TRACE("pack size=%d\n", len_pack); - void* buf = g_malloc(len_pack + 4); - if (!buf) + void *buf = g_malloc(len_pack + 4); + if (!buf) { return NULL; + } ecs__master__pack(master, buf + 4); @@ -82,51 +84,44 @@ static void* build_master(ECS__Master* master, int* payloadsize) return buf; } -bool pb_to_all_clients(ECS__Master* master) +bool pb_to_all_clients(ECS__Master *master) { int payloadsize = 0; - void* buf = build_master(master, &payloadsize); - if (!buf) - { + void *buf = build_master(master, &payloadsize); + if (!buf) { LOG_SEVERE("invalid buf\n"); return false; } - if (!send_to_all_client(buf, payloadsize)) + if (!send_to_all_client(buf, payloadsize)) { return false; - - if (buf) - { - g_free(buf); } + + g_free(buf); return true; } -bool pb_to_single_client(ECS__Master* master, ECS_Client *clii) +bool pb_to_single_client(ECS__Master *master, ECS_Client *clii) { int payloadsize = 0; - void* buf = build_master(master, &payloadsize); - if (!buf) - { + void *buf = build_master(master, &payloadsize); + if (!buf) { LOG_SEVERE("invalid buf\n"); return false; } send_to_single_client(clii, buf, payloadsize); - if (buf) - { - g_free(buf); - } + g_free(buf); return true; } -void msgproc_keepalive_ans (ECS_Client* ccli, ECS__KeepAliveAns* msg) +void msgproc_keepalive_ans(ECS_Client *ccli, ECS__KeepAliveAns *msg) { ccli->keep_alive = 0; } -void make_send_device_ntf (char* cmd, int group, int action, char* data) +void make_send_device_ntf(char *cmd, int group, int action, char *data) { int msg_length = 15; type_length length = 0; @@ -136,9 +131,10 @@ void make_send_device_ntf (char* cmd, int group, int action, char* data) msg_length += length; - char* send_msg = (char*) malloc(msg_length); - if(!send_msg) + char *send_msg = (char *) malloc(msg_length); + if (!send_msg) { return; + } memcpy(send_msg, cmd, 10); memcpy(send_msg + 10, &length, sizeof(unsigned short)); @@ -153,16 +149,17 @@ void make_send_device_ntf (char* cmd, int group, int action, char* data) free(send_msg); } -bool send_msg_to_guest(const char* cmd, int group, int action, char* data, int data_len) +bool send_msg_to_guest(const char *cmd, int group, int action, char *data, int data_len) { - int sndlen = 15; // HEADER(CMD + LENGTH + GROUP + ACTION) + 1 - char* sndbuf; + int sndlen = 15; /* HEADER(CMD + LENGTH + GROUP + ACTION) + 1 */ + char *sndbuf; bool ret = false; - if (data != NULL) + if (data != NULL) { sndlen += data_len; + } - sndbuf = (char*) g_malloc0(sndlen); + sndbuf = (char *) g_malloc0(sndlen); if (!sndbuf) { return false; } @@ -176,7 +173,7 @@ bool send_msg_to_guest(const char* cmd, int group, int action, char* data, int d memcpy(sndbuf + 14, data, data_len); } - if(strcmp(cmd, "telephony") == 0) { + if (strcmp(cmd, "telephony") == 0) { LOG_TRACE("telephony msg >>"); ret = send_to_vmodem(route_ij, sndbuf, sndlen); } else { @@ -201,7 +198,8 @@ void send_shutdown_request(int action) } } -bool ntf_to_injector(const char* data, const int len) { +bool ntf_to_injector(const char *data, const int len) +{ type_length length = 0; type_group group = 0; type_action action = 0; @@ -216,27 +214,27 @@ bool ntf_to_injector(const char* data, const int len) { read_val_char(data + catsize + 2 + 1, &action); - const char* ijdata = (data + catsize + 2 + 1 + 1); + const char *ijdata = (data + catsize + 2 + 1 + 1); const char *encoded_ijdata = ""; LOG_TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length, action, group); - QDict* obj_header = qdict_new(); + QDict *obj_header = qdict_new(); ecs_make_header(obj_header, length, group, action); - QDict* objData = qdict_new(); + QDict *objData = qdict_new(); qobject_incref(QOBJECT(obj_header)); qdict_put(objData, "cat", qstring_from_str(cat)); qdict_put(objData, "header", obj_header); - if(!strcmp(cat, "telephony")) { + if (!strcmp(cat, "telephony")) { qdict_put(objData, "ijdata", qstring_from_str(encoded_ijdata)); } else { qdict_put(objData, "ijdata", qstring_from_str(ijdata)); } - QDict* objMsg = qdict_new(); + QDict *objMsg = qdict_new(); qobject_incref(QOBJECT(objData)); qdict_put(objMsg, "type", qstring_from_str("injector")); @@ -249,7 +247,7 @@ bool ntf_to_injector(const char* data, const int len) { assert(json != NULL); qstring_append_chr(json, '\n'); - const char* snddata = qstring_get_str(json); + const char *snddata = qstring_get_str(json); LOG_TRACE("<< json str = %s", snddata); diff --git a/tizen/src/ecs/ecs_msg_device.c b/tizen/src/ecs/ecs_msg_device.c index dfc2a793ed..3a682741c9 100644 --- a/tizen/src/ecs/ecs_msg_device.c +++ b/tizen/src/ecs/ecs_msg_device.c @@ -3,6 +3,7 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: + * Chulho Song * Jinhyung Choi * MunKyu Im * Daiyoung Kim @@ -48,7 +49,7 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); -static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succeed, const char* data) +static void msgproc_device_ans(ECS_Client *ccli, const char *category, bool succeed, const char *data) { if (ccli == NULL) { return; @@ -60,7 +61,7 @@ static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succ LOG_TRACE("device ans - category : %s, succed : %d\n", category, succeed); catlen = strlen(category); - ans.category = (char*) g_malloc0(catlen + 1); + ans.category = (char *) g_malloc0(catlen + 1); memcpy(ans.category, category, catlen); ans.errcode = !succeed; @@ -82,17 +83,17 @@ static void msgproc_device_ans(ECS_Client* ccli, const char* category, bool succ pb_to_all_clients(&master); - if (ans.category) - g_free(ans.category); + g_free(ans.category); } -static void send_target_image_information(ECS_Client* ccli) { +static void send_target_image_information(ECS_Client *ccli) +{ ECS__Master master = ECS__MASTER__INIT; ECS__DeviceAns ans = ECS__DEVICE_ANS__INIT; const char *drive_image_file = get_drive_image_file(); - int length = strlen(drive_image_file); // ?? + int length = strlen(drive_image_file); - ans.category = (char*) g_malloc(10 + 1); + ans.category = (char *) g_malloc(10 + 1); strncpy(ans.category, "info", 10); ans.errcode = 0; @@ -100,8 +101,7 @@ static void send_target_image_information(ECS_Client* ccli) { ans.group = 1; ans.action = 1; - if (length > 0) - { + if (length > 0) { ans.has_data = 1; ans.data.data = g_malloc(length); @@ -116,23 +116,21 @@ static void send_target_image_information(ECS_Client* ccli) { pb_to_single_client(&master, ccli); - if (ans.data.len > 0) - { + if (ans.data.len > 0) { g_free(ans.data.data); } g_free(ans.category); } -static void msgproc_device_req_sensor(ECS_Client* ccli, ECS__DeviceReq* msg, char* cmd) +static void msgproc_device_req_sensor(ECS_Client *ccli, ECS__DeviceReq *msg, char *cmd) { - char* data = NULL; + char *data = NULL; type_group group = (type_group) (msg->group & 0xff); type_action action = (type_action) (msg->action & 0xff); - if (msg->has_data && msg->data.len > 0) - { - data = (char*) g_malloc0(msg->data.len + 1); + if (msg->has_data && msg->data.len > 0) { + data = (char *) g_malloc0(msg->data.len + 1); memcpy(data, msg->data.data, msg->data.len); } @@ -163,27 +161,24 @@ static void msgproc_device_req_sensor(ECS_Client* ccli, ECS__DeviceReq* msg, cha } } - if (data) { - g_free(data); - } + g_free(data); } #define MSG_NET_GROUP 0 #define MSG_NET_ACTION 123 -static void msgproc_device_req_network(ECS_Client* ccli, ECS__DeviceReq* msg, char* cmd) +static void msgproc_device_req_network(ECS_Client *ccli, ECS__DeviceReq *msg, char *cmd) { - char* data = NULL; + char *data = NULL; char ret[2] = {'1', 0}; - if (msg->has_data && msg->data.len > 0) - { - data = (char*) g_malloc0(msg->data.len + 1); + if (msg->has_data && msg->data.len > 0) { + data = (char *) g_malloc0(msg->data.len + 1); memcpy(data, msg->data.data, msg->data.len); } if (data != NULL) { LOG_TRACE(">>> Network msg: '%s'\n", data); - if(net_slirp_redir(data) < 0) { - LOG_SEVERE( "redirect [%s] fail\n", data); + if (net_slirp_redir(data) < 0) { + LOG_SEVERE("redirect [%s] fail\n", data); make_send_device_ntf(cmd, MSG_NET_GROUP, MSG_NET_ACTION, ret); } else { LOG_TRACE("redirect [%s] success\n", data); @@ -192,24 +187,21 @@ static void msgproc_device_req_network(ECS_Client* ccli, ECS__DeviceReq* msg, ch LOG_SEVERE("Network redirection data is null.\n"); } - if (data) { - g_free(data); - } + g_free(data); } -static void msgproc_device_req_tgesture(ECS_Client* ccli, ECS__DeviceReq* msg) +static void msgproc_device_req_tgesture(ECS_Client *ccli, ECS__DeviceReq *msg) { - char* data = NULL; + char *data = NULL; type_group group = (type_group) (msg->group & 0xff); - if (msg->has_data && msg->data.len > 0) - { - data = (char*) g_malloc0(msg->data.len + 1); + if (msg->has_data && msg->data.len > 0) { + data = (char *) g_malloc0(msg->data.len + 1); memcpy(data, msg->data.data, msg->data.len); } /* release multi-touch */ - // TODO: + /* TODO: */ if (data == NULL) { LOG_SEVERE("touch gesture data is NULL\n"); @@ -244,24 +236,21 @@ static void msgproc_device_req_tgesture(ECS_Client* ccli, ECS__DeviceReq* msg) do_mouse_event(1/* LEFT */, event_type, 0, 0, xx, yy, zz); } - if (data) { - g_free(data); - } + g_free(data); } -static void msgproc_device_req_input(ECS_Client* ccli, ECS__DeviceReq* msg, char* cmd) +static void msgproc_device_req_input(ECS_Client *ccli, ECS__DeviceReq *msg, char *cmd) { - char* data = NULL; + char *data = NULL; type_group group = (type_group) (msg->group & 0xff); type_action action = (type_action) (msg->action & 0xff); - if (msg->has_data && msg->data.len > 0) - { - data = (char*) g_malloc0(msg->data.len + 1); + if (msg->has_data && msg->data.len > 0) { + data = (char *) g_malloc0(msg->data.len + 1); memcpy(data, msg->data.data, msg->data.len); } - // cli input + /* cli input */ LOG_TRACE("receive input message [%s]\n", data); if (group == 0) { @@ -271,37 +260,34 @@ static void msgproc_device_req_input(ECS_Client* ccli, ECS__DeviceReq* msg, char char *section = strtok(data, token); int keycode = atoi(section); if (action == 1) { - //action 1 press + /* action 1 press */ do_hw_key_event(KEY_PRESSED, keycode); } else if (action == 2) { - //action 2 released + /* action 2 released */ do_hw_key_event(KEY_RELEASED, keycode); } else { LOG_SEVERE("unknown action : [%d]\n", (int)action); } } else if (group == 1) { - //spec out + /* spec out */ LOG_TRACE("input category's group 1 is spec out\n"); } else { LOG_SEVERE("unknown group [%d]\n", (int)group); } msgproc_device_ans(ccli, cmd, true, NULL); - if (data) { - g_free(data); - } + g_free(data); } -static void msgproc_device_req_nfc(ECS_Client* ccli, ECS__DeviceReq* msg) +static void msgproc_device_req_nfc(ECS_Client *ccli, ECS__DeviceReq *msg) { - char* data = NULL; + char *data = NULL; type_group group = (type_group) (msg->group & 0xff); - if (msg->has_data && msg->data.len > 0) - { - data = (char*) g_malloc0(msg->data.len + 1); + if (msg->has_data && msg->data.len > 0) { + data = (char *) g_malloc0(msg->data.len + 1); memcpy(data, msg->data.data, msg->data.len); } @@ -315,19 +301,17 @@ static void msgproc_device_req_nfc(ECS_Client* ccli, ECS__DeviceReq* msg) } } - if (data) { - g_free(data); - } + g_free(data); } #ifndef CONFIG_EXTENSION_PATH -bool msgproc_device_req_ext(ECS_Client* ccli, ECS__DeviceReq* msg) +bool msgproc_device_req_ext(ECS_Client *ccli, ECS__DeviceReq *msg) { return false; } #endif -bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) +bool msgproc_device_req(ECS_Client *ccli, ECS__DeviceReq *msg) { char cmd[10]; memset(cmd, 0, 10); @@ -348,19 +332,19 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) } else if (!strcmp(cmd, "TGesture")) { msgproc_device_req_tgesture(ccli, msg); } else if (!strcmp(cmd, "info")) { - // check to emulator target image path + /* check to emulator target image path */ send_target_image_information(ccli); } else if (!strcmp(cmd, "hds")) { msgproc_device_req_hds(ccli, msg, cmd); } else if (!strcmp(cmd, "input")) { msgproc_device_req_input(ccli, msg, cmd); } else if (!strcmp(cmd, "vmname")) { - const char* vmname = get_vm_name(); + const char *vmname = get_vm_name(); msgproc_device_ans(ccli, cmd, true, vmname); } else if (!strcmp(cmd, "nfc")) { msgproc_device_req_nfc(ccli, msg); } else if (!strcmp(cmd, "sdcard")) { - handle_sdcard((char*)msg->data.data, msg->data.len); + handle_sdcard((char *)msg->data.data, msg->data.len); } else if (msgproc_device_req_ext(ccli, msg)) { LOG_INFO("Extension request. cmd [%s]\n", cmd); } else { @@ -370,7 +354,7 @@ bool msgproc_device_req(ECS_Client* ccli, ECS__DeviceReq* msg) return true; } -bool send_device_ntf(const char* data, const int len) +bool send_device_ntf(const char *data, const int len) { type_length length = 0; type_group group = 0; @@ -385,14 +369,14 @@ bool send_device_ntf(const char* data, const int len) read_val_char(data + catsize + 2, &group); read_val_char(data + catsize + 2 + 1, &action); - const char* ijdata = (data + catsize + 2 + 1 + 1); + const char *ijdata = (data + catsize + 2 + 1 + 1); - LOG_TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); + LOG_TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length, action, group); ECS__Master master = ECS__MASTER__INIT; ECS__DeviceNtf ntf = ECS__DEVICE_NTF__INIT; - ntf.category = (char*) g_malloc(catsize + 1); + ntf.category = (char *) g_malloc(catsize + 1); strncpy(ntf.category, cat, 10); @@ -400,8 +384,7 @@ bool send_device_ntf(const char* data, const int len) ntf.group = group; ntf.action = action; - if (length > 0) - { + if (length > 0) { ntf.has_data = 1; ntf.data.data = g_malloc(length); @@ -416,13 +399,11 @@ bool send_device_ntf(const char* data, const int len) pb_to_all_clients(&master); - if (ntf.data.data && ntf.data.len > 0) - { + if (ntf.data.data && ntf.data.len > 0) { g_free(ntf.data.data); } - if (ntf.category) - g_free(ntf.category); + g_free(ntf.category); return true; } diff --git a/tizen/src/ecs/ecs_msg_injector.c b/tizen/src/ecs/ecs_msg_injector.c index 6f1a3bfbc2..cc552af120 100644 --- a/tizen/src/ecs/ecs_msg_injector.c +++ b/tizen/src/ecs/ecs_msg_injector.c @@ -3,6 +3,7 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: + * Chulho Song * Jinhyung Choi * MunKyu Im * Daiyoung Kim @@ -49,15 +50,15 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); #define MAX_PKGS_LIST 1024 #define MAX_SDB_TRIAL 10 -#define SLEEP_WAIT_SDB 500 // ms -#define SLEEP_CONNECT_SDB 1000 // ms +#define SLEEP_WAIT_SDB 500 /* ms */ +#define SLEEP_CONNECT_SDB 1000 /* ms */ static QemuThread sdb_thread_id; extern QemuMutex mutex_location_data; static char location_data[MAX_INJECTOR_REQ_DATA]; -static void msgproc_injector_ans(ECS_Client* ccli, const char* category, bool succeed) +static void msgproc_injector_ans(ECS_Client *ccli, const char *category, bool succeed) { if (ccli == NULL) { return; @@ -69,7 +70,7 @@ static void msgproc_injector_ans(ECS_Client* ccli, const char* category, bool su LOG_TRACE("injector ans - category : %s, succed : %d\n", category, succeed); catlen = strlen(category); - ans.category = (char*) g_malloc0(catlen + 1); + ans.category = (char *) g_malloc0(catlen + 1); memcpy(ans.category, category, catlen); ans.errcode = !succeed; @@ -78,24 +79,24 @@ static void msgproc_injector_ans(ECS_Client* ccli, const char* category, bool su pb_to_all_clients(&master); - if (ans.category) - g_free(ans.category); + g_free(ans.category); } -static bool injector_send(ECS_Client* ccli, ECS__InjectorReq* msg, char* cmd) +static bool injector_send(ECS_Client *ccli, ECS__InjectorReq *msg, char *cmd) { - int sndlen = 15; // HEADER(CMD + LENGTH + GROUP + ACTION) + 1 - const char* msg_data; - char* sndbuf; + int sndlen = 15; /* HEADER(CMD + LENGTH + GROUP + ACTION) + 1 */ + const char *msg_data; + char *sndbuf; bool ret = false; type_group group; group = (type_group) (msg->group & 0xff); - if (msg->has_data && msg->data.data && msg->data.len > 0) + if (msg->has_data && msg->data.data && msg->data.len > 0) { sndlen += msg->data.len; + } - sndbuf = (char*) g_malloc0(sndlen); + sndbuf = (char *) g_malloc0(sndlen); if (!sndbuf) { msgproc_injector_ans(ccli, cmd, false); return false; @@ -107,12 +108,12 @@ static bool injector_send(ECS_Client* ccli, ECS__InjectorReq* msg, char* cmd) memcpy(sndbuf + 13, &msg->action, 1); if (msg->has_data && msg->data.data && msg->data.len > 0) { - msg_data = (const char*)msg->data.data; + msg_data = (const char *)msg->data.data; memcpy(sndbuf + 14, msg_data, msg->data.len); LOG_TRACE(">> print len = %zd, data\" %s\"\n", msg->data.len, msg_data); } - if(strcmp(cmd, "telephony") == 0) { + if (strcmp(cmd, "telephony") == 0) { LOG_TRACE("telephony msg >>"); ret = send_to_vmodem(route_ij, sndbuf, sndlen); } else { @@ -133,15 +134,16 @@ static bool injector_send(ECS_Client* ccli, ECS__InjectorReq* msg, char* cmd) return true; } -static void send_status_injector_ntf(const char* cmd, int cmdlen, int act, char* on) +static void send_status_injector_ntf(const char *cmd, int cmdlen, int act, char *on) { int msglen = 0, datalen = 0; type_length length = 0; type_group group = MSG_GROUP_STATUS; type_action action = act; - if (cmd == NULL || cmdlen > 10) + if (cmd == NULL || cmdlen > 10) { return; + } if (on == NULL) { msglen = 14; @@ -152,9 +154,10 @@ static void send_status_injector_ntf(const char* cmd, int cmdlen, int act, char* msglen = datalen + 15; } - char* status_msg = (char*) malloc(msglen); - if(!status_msg) + char *status_msg = (char *) malloc(msglen); + if (!status_msg) { return; + } memset(status_msg, 0, msglen); @@ -172,7 +175,7 @@ static void send_status_injector_ntf(const char* cmd, int cmdlen, int act, char* free(status_msg); } -static bool injector_req_sensor(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) +static bool injector_req_sensor(ECS_Client *ccli, ECS__InjectorReq *msg, char *cmd) { char data[MAX_INJECTOR_REQ_DATA]; type_group group; @@ -208,7 +211,7 @@ static bool injector_req_sensor(ECS_Client* ccli, ECS__InjectorReq* msg, char *c send_status_injector_ntf(MSG_TYPE_SENSOR, 6, action, data); return true; } else if (msg->data.data && msg->data.len > 0) { - ecs_sensor_set_injector_data((char*) msg->data.data); + ecs_sensor_set_injector_data((char *) msg->data.data); return injector_send(ccli, msg, cmd); } @@ -221,11 +224,11 @@ static bool injector_req_guest(void) return true; } -static bool injector_req_location(ECS_Client* ccli, ECS__InjectorReq* msg, char *cmd) +static bool injector_req_location(ECS_Client *ccli, ECS__InjectorReq *msg, char *cmd) { if (msg->data.data != NULL && msg->data.len > 0) { qemu_mutex_lock(&mutex_location_data); - snprintf(location_data, msg->data.len + 1, "%s", (char*)msg->data.data); + snprintf(location_data, msg->data.len + 1, "%s", (char *)msg->data.data); qemu_mutex_unlock(&mutex_location_data); return injector_send(ccli, msg, cmd); } @@ -233,7 +236,7 @@ static bool injector_req_location(ECS_Client* ccli, ECS__InjectorReq* msg, char return false; } -bool msgproc_injector_req(ECS_Client* ccli, ECS__InjectorReq* msg) +bool msgproc_injector_req(ECS_Client *ccli, ECS__InjectorReq *msg) { char cmd[11]; bool ret = false; @@ -258,10 +261,10 @@ void ecs_suspend_lock_state(int state) int catlen; ECS__InjectorReq msg = ECS__INJECTOR_REQ__INIT; - const char* category = "suspend"; + const char *category = "suspend"; catlen = strlen(category); - msg.category = (char*) g_malloc0(catlen + 1); + msg.category = (char *) g_malloc0(catlen + 1); memcpy(msg.category, category, catlen); msg.group = 5; @@ -270,19 +273,19 @@ void ecs_suspend_lock_state(int state) msgproc_injector_req(NULL, &msg); } -static bool do_push_package(char* cmd) +static bool do_push_package(char *cmd) { char buf[MAX_PKGS_LIST]; - FILE* fp = popen(cmd, "r"); + FILE *fp = popen(cmd, "r"); if (fp == NULL) { LOG_SEVERE("Failed to popen push packages\n"); return false; } memset(buf, 0, sizeof(buf)); - while(fgets(buf, sizeof(buf), fp) != NULL) { + while (fgets(buf, sizeof(buf), fp) != NULL) { LOG_INFO("[pkgs]%s\n", buf); - if (!strncmp(buf, "error", 5)){ + if (!strncmp(buf, "error", 5)) { pclose(fp); return false; } @@ -293,26 +296,26 @@ static bool do_push_package(char* cmd) return true; } -static bool push_package(const char* data) +static bool push_package(const char *data) { int index = 0; int ret = 0; char cmd[MAX_PKGS_LIST]; char token[] = ", "; #ifndef CONFIG_WIN32 - const char* sdb_path = "../../../../../tools/sdb"; - const char* platform_path = "../../../"; - const char* addon_path = "/emulator-images/add-ons/"; + const char *sdb_path = "../../../../../tools/sdb"; + const char *platform_path = "../../../"; + const char *addon_path = "/emulator-images/add-ons/"; #else - const char* sdb_path = "..\\..\\..\\..\\..\\tools\\sdb.exe"; - const char* platform_path = "..\\..\\..\\"; - const char* addon_path = "\\emulator-images\\add-ons\\"; + const char *sdb_path = "..\\..\\..\\..\\..\\tools\\sdb.exe"; + const char *platform_path = "..\\..\\..\\"; + const char *addon_path = "\\emulator-images\\add-ons\\"; #endif - const char* bin_dir = get_bin_path(); + const char *bin_dir = get_bin_path(); memset(cmd, 0, sizeof(cmd)); - char* addon = strtok((char*)data, token); + char *addon = strtok((char *)data, token); #ifndef CONFIG_WIN32 ret = sprintf(cmd, "\"%s%s\" -s emulator-%d push \"%s%s%s%s%s\" /opt/usr/apps/tmp/sdk_tools/%s 2>&1", #else @@ -337,7 +340,7 @@ static bool push_package(const char* data) * FIXME: unnecessary sdb connection waiting sleep. * If SDB runs faster, it should be changed/removed. */ - while(!get_sdb_connection() && index != MAX_SDB_TRIAL) { + while (!get_sdb_connection() && index != MAX_SDB_TRIAL) { LOG_INFO("[pkgs] Waiting SDB connection...%d\n", index + 1); #ifdef CONFIG_WIN32 Sleep(SLEEP_WAIT_SDB); @@ -354,7 +357,7 @@ static bool push_package(const char* data) usleep(SLEEP_WAIT_SDB * 1000); #endif - while(index != MAX_SDB_TRIAL) { + while (index != MAX_SDB_TRIAL) { if (do_push_package(cmd)) { LOG_INFO("[pkgs] SDB push SUCCESS.\n"); return true; @@ -371,11 +374,11 @@ static bool push_package(const char* data) return false; } -static void show_error_popup(char* data) +static void show_error_popup(char *data) { char fail_msg[MAX_PKGS_LIST]; char token[] = ", "; - char* addon = strtok(data, token); + char *addon = strtok(data, token); memset(fail_msg, 0, sizeof(fail_msg)); strcpy(fail_msg, FAILED_TO_INSTALL_EXTRAPACKAGE_1); @@ -385,10 +388,10 @@ static void show_error_popup(char* data) error_report("%s", fail_msg); } -static void* push_pkgs_thread(void* args) +static void *push_pkgs_thread(void *args) { - char* pkg_data = (char*)args; - char* data = strdup(pkg_data); + char *pkg_data = (char *)args; + char *data = strdup(pkg_data); if (pkg_data == NULL || data == NULL) { LOG_SEVERE("pkg data strdup is failed.\n"); return NULL; @@ -402,7 +405,7 @@ static void* push_pkgs_thread(void* args) return NULL; } - // request to install rpms + /* request to install rpms */ LOG_INFO("[pkgs] Request to install : %s\n", data); send_msg_to_guest(MSG_TYPE_PACKAGE, 0, 2, data, strlen(data) + 1); @@ -412,7 +415,7 @@ static void* push_pkgs_thread(void* args) return NULL; } -static void do_package(char* cat, type_action action, const char* data) +static void do_package(char *cat, type_action action, const char *data) { if (data == NULL || strlen(data) <= 0) { LOG_SEVERE("data is corrupted.\n"); @@ -423,20 +426,20 @@ static void do_package(char* cat, type_action action, const char* data) LOG_INFO("[pkgs] Already installed: %s\n", data); } else if (action == 2) { LOG_INFO("[pkgs] Needed to install: %s\n", data); - char* pkgs = g_malloc0(MAX_PKGS_LIST); + char *pkgs = g_malloc0(MAX_PKGS_LIST); strncpy(pkgs, data, MAX_PKGS_LIST - 1); - qemu_thread_create(&sdb_thread_id, "sdb_push", push_pkgs_thread, (void*)pkgs, QEMU_THREAD_DETACHED); + qemu_thread_create(&sdb_thread_id, "sdb_push", push_pkgs_thread, (void *)pkgs, QEMU_THREAD_DETACHED); } else if (action == 3) { LOG_INFO("[pkgs] Package Installation Success: %s\n", data); } else if (action == 4) { LOG_INFO("[pkgs] Package Installation Failed: %s\n", data); - show_error_popup((char*)data); + show_error_popup((char *)data); } else { LOG_SEVERE("unknown pkgs action: %d\n", action); } } -static bool injector_req_handle(char* cat, type_action action, const char* data) +static bool injector_req_handle(char *cat, type_action action, const char *data) { int state = 0; if (!strcmp(cat, "suspend")) { @@ -460,7 +463,7 @@ static bool injector_req_handle(char* cat, type_action action, const char* data) } else if (!strcmp(cat, MSG_TYPE_GUESTIP)) { if (data != NULL && strlen(data) > 0) { LOG_INFO("guest ip: %s\n", data); - set_guest_ip((char*)data); + set_guest_ip((char *)data); } else { LOG_SEVERE("guest ip is null!\n"); } @@ -469,7 +472,7 @@ static bool injector_req_handle(char* cat, type_action action, const char* data) return false; } -bool send_injector_ntf(const char* data, const int len) +bool send_injector_ntf(const char *data, const int len) { type_length length = 0; type_group group = 0; @@ -484,7 +487,7 @@ bool send_injector_ntf(const char* data, const int len) read_val_char(data + catsize + 2, &group); read_val_char(data + catsize + 2 + 1, &action); - const char* ijdata = (data + catsize + 2 + 1 + 1); + const char *ijdata = (data + catsize + 2 + 1 + 1); if (!is_ecs_running()) { LOG_SEVERE("ECS is not running.\n"); @@ -495,20 +498,19 @@ bool send_injector_ntf(const char* data, const int len) return true; } - LOG_TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length,action, group); + LOG_TRACE("<< header cat = %s, length = %d, action=%d, group=%d\n", cat, length, action, group); ECS__Master master = ECS__MASTER__INIT; ECS__InjectorNtf ntf = ECS__INJECTOR_NTF__INIT; - ntf.category = (char*) g_malloc(catsize + 1); + ntf.category = (char *) g_malloc(catsize + 1); strncpy(ntf.category, cat, 10); ntf.length = length; ntf.group = group; ntf.action = action; - if (length > 0) - { + if (length > 0) { ntf.has_data = 1; ntf.data.data = g_malloc(length); @@ -521,8 +523,7 @@ bool send_injector_ntf(const char* data, const int len) pb_to_all_clients(&master); - if (ntf.data.len > 0) - { + if (ntf.data.len > 0) { g_free(ntf.data.data); } diff --git a/tizen/src/ecs/ecs_nfc.c b/tizen/src/ecs/ecs_nfc.c index dcc1e4c5d5..5ae6afb813 100644 --- a/tizen/src/ecs/ecs_nfc.c +++ b/tizen/src/ecs/ecs_nfc.c @@ -37,11 +37,11 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); -bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg) +bool msgproc_nfc_req(ECS_Client *ccli, ECS__NfcReq *msg) { int datalen = msg->data.len; - void* data = (void*)g_malloc(datalen); - if(!data) { + void *data = (void *)g_malloc(datalen); + if (!data) { ERR("g_malloc failed!\n"); return false; } @@ -49,8 +49,7 @@ bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg) memset(data, 0, datalen); memcpy(data, msg->data.data, msg->data.len); - if (msg->has_data && msg->data.len > 0) - { + if (msg->has_data && msg->data.len > 0) { TRACE("recv from nfc injector: %s, %z\n", msg->has_data, msg->data.len); print_binary(data, datalen); } @@ -60,34 +59,33 @@ bool msgproc_nfc_req(ECS_Client* ccli, ECS__NfcReq* msg) return true; } -bool send_nfc_ntf(struct nfc_msg_info* msg) +bool send_nfc_ntf(struct nfc_msg_info *msg) { const int catsize = 10; char cat[catsize + 1]; ECS_Client *clii; memset(cat, 0, catsize + 1); - print_binary((char*)msg->buf, msg->use); + print_binary((char *)msg->buf, msg->use); TRACE("id: %02x, type: %02x, use: %d\n", msg->client_id, msg->client_type, msg->use); clii = find_client(msg->client_id, msg->client_type); if (clii) { - if(clii->client_type == TYPE_SIMUL_NFC) { + if (clii->client_type == TYPE_SIMUL_NFC) { strncpy(cat, MSG_TYPE_NFC, 3); } else if (clii->client_type == TYPE_ECP) { strncpy(cat, MSG_TYPE_SIMUL_NFC, 9); - }else { + } else { ERR("cannot find type! : %d\n", clii->client_type); } TRACE("header category = %s\n", cat); - } - else { + } else { ERR("cannot find client!\n"); } ECS__Master master = ECS__MASTER__INIT; ECS__NfcNtf ntf = ECS__NFC_NTF__INIT; - ntf.category = (char*) g_malloc(catsize + 1); + ntf.category = (char *) g_malloc(catsize + 1); strncpy(ntf.category, cat, 10); ntf.has_data = 1; @@ -96,19 +94,17 @@ bool send_nfc_ntf(struct nfc_msg_info* msg) ntf.data.len = NFC_MAX_BUF_SIZE; memcpy(ntf.data.data, msg->buf, NFC_MAX_BUF_SIZE); - TRACE("send to nfc injector: \n"); + TRACE("send to nfc injector\n"); master.type = ECS__MASTER__TYPE__NFC_NTF; master.nfc_ntf = &ntf; pb_to_all_clients(&master); - if (ntf.data.data && ntf.data.len > 0) - { + if (ntf.data.data && ntf.data.len > 0) { g_free(ntf.data.data); } - if (ntf.category) - g_free(ntf.category); + g_free(ntf.category); return true; } diff --git a/tizen/src/ecs/ecs_sdcard.c b/tizen/src/ecs/ecs_sdcard.c index e249510285..7348bdb3a3 100644 --- a/tizen/src/ecs/ecs_sdcard.c +++ b/tizen/src/ecs/ecs_sdcard.c @@ -4,8 +4,9 @@ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Chulho Song * MunKyu Im - * SeokYeon Hwang + * SeokYeon Hwang * Sangho Park * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -36,9 +37,10 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); -static char* get_sdcard_full_path(char* sdcard_img_name, size_t dataLen) { - char* sdcard_img_path = NULL; - const char* sdcard_path = NULL; +static char *get_sdcard_full_path(char *sdcard_img_name, size_t dataLen) +{ + char *sdcard_img_path = NULL; + const char *sdcard_path = NULL; if (sdcard_img_name == NULL || dataLen < 3) { return NULL; } @@ -57,7 +59,7 @@ static char* get_sdcard_full_path(char* sdcard_img_name, size_t dataLen) { g_strlcpy(sdcard_img_path, sdcard_path, MAXBUFLEN); g_strlcat(sdcard_img_path, sdcard_img_name, MAXBUFLEN); LOG_TRACE("sdcard img path: [%s] length: %d\n", sdcard_img_path, strlen(sdcard_img_path)); - g_free((void*)sdcard_path); + g_free((void *)sdcard_path); return sdcard_img_path; } return NULL; @@ -137,40 +139,40 @@ static void send_sdcard_status(void) qapi_free_BlockInfoList(block_list); LOG_INFO("sdcard data: %s\n", data); if (is_sdcard_attached() && data[0] != 0) { - make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, ACT_SDCARD_ATTACH_STATUS, data); + make_send_device_ntf((char *)MSG_TYPE_SDCARD, GROUP_SDCARD, ACT_SDCARD_ATTACH_STATUS, data); } else { - make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, ACT_SDCARD_DETACH_STATUS, NULL); + make_send_device_ntf((char *)MSG_TYPE_SDCARD, GROUP_SDCARD, ACT_SDCARD_DETACH_STATUS, NULL); } } -void handle_sdcard(char* dataBuf, size_t dataLen) +void handle_sdcard(char *dataBuf, size_t dataLen) { int err_no = 0; char ret = 0; if (dataBuf != NULL && strlen(dataBuf) > 0) { ret = dataBuf[0]; - if (ret == '0' ) { + if (ret == '0') { /* detach sdcard */ - char* sdcard_full_path = get_sdcard_full_path(dataBuf + 2, dataLen); + char *sdcard_full_path = get_sdcard_full_path(dataBuf + 2, dataLen); LOG_TRACE("sdcard_full_path: %s\n", sdcard_full_path); err_no = remove_sdcard_lock_os(sdcard_full_path); if (err_no == 0 && is_sdcard_attached()) { do_hotplug(DETACH_SDCARD, sdcard_full_path, strlen(sdcard_full_path) + 1); } else { LOG_SEVERE("failed to umount: %s, err_no: %d\n", sdcard_full_path, err_no); - make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, + make_send_device_ntf((char *)MSG_TYPE_SDCARD, GROUP_SDCARD, err_no, g_path_get_basename(sdcard_full_path)); } g_free(sdcard_full_path); } else if (ret == '1') { /* attach sdcard */ - char* sdcard_full_path = get_sdcard_full_path(dataBuf + 2, dataLen); + char *sdcard_full_path = get_sdcard_full_path(dataBuf + 2, dataLen); LOG_TRACE("sdcard_full_path: %s\n", sdcard_full_path); if (!is_sdcard_attached() && make_sdcard_lock_os(sdcard_full_path)) { do_hotplug(ATTACH_SDCARD, sdcard_full_path, strlen(sdcard_full_path) + 1); } else { - make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, + make_send_device_ntf((char *)MSG_TYPE_SDCARD, GROUP_SDCARD, ACT_SDCARD_ATTACH_FAIL, g_path_get_basename(sdcard_full_path)); } g_free(sdcard_full_path); diff --git a/tizen/src/ecs/ecs_sdcard.h b/tizen/src/ecs/ecs_sdcard.h index 337c16e0ae..385c186bde 100644 --- a/tizen/src/ecs/ecs_sdcard.h +++ b/tizen/src/ecs/ecs_sdcard.h @@ -4,8 +4,9 @@ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: + * Chulho Song * MunKyu Im - * SeokYeon Hwang + * SeokYeon Hwang * Sangho Park * * This program is free software; you can redistribute it and/or @@ -27,6 +28,7 @@ * - S-Core Co., Ltd * */ + #ifndef __SDCARD_H__ #define __SDCARD_H__ @@ -49,6 +51,6 @@ #define ACT_SDCARD_ATTACH_FAIL 5 /* Already sdcard attached */ #define ACT_SDCARD_NO_ATTACH_FOUND 6 /* Other sdcard attached */ #define MAXBUFLEN 1024 -void handle_sdcard(char* dataBuf, size_t dataLen); +void handle_sdcard(char *dataBuf, size_t dataLen); -#endif //__SDCARD_H__ +#endif /*__SDCARD_H__ */ diff --git a/tizen/src/ecs/ecs_sensor.c b/tizen/src/ecs/ecs_sensor.c index 35ad486e4a..f3094ece2a 100644 --- a/tizen/src/ecs/ecs_sensor.c +++ b/tizen/src/ecs/ecs_sensor.c @@ -4,6 +4,7 @@ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: + * Chulho Song * Jinhyung Choi * MunKyu Im * Daiyoung Kim @@ -51,14 +52,13 @@ MULTI_DEBUG_CHANNEL(qemu, ecs); static int parse_val(const char *buff, unsigned char data, char *parsbuf) { - int count=0; + int count = 0; - while(1) - { - if(count > MAX_VAL_LENGTH) + while (1) { + if (count > MAX_VAL_LENGTH) { return -1; - if(buff[count] == data) - { + } + if (buff[count] == data) { count++; strncpy(parsbuf, buff, count); return count; @@ -69,7 +69,7 @@ static int parse_val(const char *buff, unsigned char data, char *parsbuf) return 0; } -static int get_parse_val (const char* buf, char* tmp) +static int get_parse_val(const char *buf, char *tmp) { int index = 0; @@ -85,16 +85,18 @@ int accel_min_max(double value) { int result = (int)value; - if (result > ACCEL_MAX) + if (result > ACCEL_MAX) { result = ACCEL_MAX; + } - if (result < -ACCEL_MAX) + if (result < -ACCEL_MAX) { result = -ACCEL_MAX; + } return result; } -static int _accel_min_max(char* tmp) +static int _accel_min_max(char *tmp) { return accel_min_max(atof(tmp)); } @@ -111,7 +113,8 @@ void req_set_sensor_accel(int x, int y, int z) #endif #if defined(CONFIG_QT) -static int convert_abs_angle(int angle) { +static int convert_abs_angle(int angle) +{ if (angle < SENSOR_ANGLE_MIN) { return convert_abs_angle(angle + SENSOR_ANGLE_MAX); } else if (angle > SENSOR_ANGLE_MAX) { @@ -149,7 +152,7 @@ void req_set_sensor_accel_angle(int angle) int degree; int accel_x = 0; int accel_y = 0; - char accel [TEMP_BUF_SIZE]; + char accel[TEMP_BUF_SIZE]; if (angle < SENSOR_ANGLE_MAX * -3 || angle > SENSOR_ANGLE_MAX * 3) { LOG_SEVERE("wrong input degree : %d.\n", angle); @@ -174,23 +177,23 @@ void req_set_sensor_accel_angle(int angle) } #endif -static void _req_set_sensor_accel(int len, const char* data) +static void _req_set_sensor_accel(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; int x, y, z; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // x + /* x */ len += get_parse_val(data + len, tmp); x = _accel_min_max(tmp); - // y + /* y */ len += get_parse_val(data + len, tmp); y = _accel_min_max(tmp); - // z + /* z */ len += get_parse_val(data + len, tmp); z = _accel_min_max(tmp); @@ -201,52 +204,52 @@ static void _req_set_sensor_accel(int len, const char* data) set_sensor_accel(tmp, strlen(tmp)); } -static void _req_set_sensor_proxi(int len, const char* data) +static void _req_set_sensor_proxi(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // vo + /* vo */ len += get_parse_val(data + len, tmp); set_sensor_proxi(tmp, strlen(tmp)); } -static void _req_set_sensor_light(int len, const char* data) +static void _req_set_sensor_light(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; int x; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // x + /* x */ len += get_parse_val(data + len, tmp); x = atoi(tmp); if (x == 2) { - // y + /* y */ len += get_parse_val(data + len, tmp); set_sensor_light(tmp, strlen(tmp)); } } -static void _req_set_sensor_pressure(int len, const char* data) +static void _req_set_sensor_pressure(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; int pressure, temperature; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // pressure + /* pressure */ len += get_parse_val(data + len, tmp); pressure = atoi(tmp); - // temperature + /* temperature */ len += get_parse_val(data + len, tmp); temperature = atoi(tmp); @@ -257,39 +260,39 @@ static void _req_set_sensor_pressure(int len, const char* data) set_sensor_pressure(tmp, strlen(tmp)); } -static void _req_set_sensor_uv(int len, const char* data) +static void _req_set_sensor_uv(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // value + /* value */ len += get_parse_val(data + len, tmp); set_sensor_uv(tmp, strlen(tmp)); } -static void _req_set_sensor_hrm(int len, const char* data) +static void _req_set_sensor_hrm(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; int hrm = 0, rri = 0, index = 0; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // get index + /* get index */ len += get_parse_val(data + len, tmp); index = atoi(tmp); if (index == 1 || index == 0) { - // heart rate + /* heart rate */ len += get_parse_val(data + len, tmp); hrm = atoi(tmp); } if (index == 2 || index == 0) { - // RRI + /* RRI */ len += get_parse_val(data + len, tmp); rri = atoi(tmp); } @@ -310,23 +313,23 @@ static void _req_set_sensor_hrm(int len, const char* data) } } -static void _req_set_sensor_gyro(int len, const char* data) +static void _req_set_sensor_gyro(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; int x, y, z; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // x + /* x */ len += get_parse_val(data + len, tmp); x = (int)atoi(tmp); - // y + /* y */ len += get_parse_val(data + len, tmp); y = (int)atoi(tmp); - // z + /* z */ len += get_parse_val(data + len, tmp); z = (int)atoi(tmp); @@ -337,23 +340,23 @@ static void _req_set_sensor_gyro(int len, const char* data) set_sensor_gyro(tmp, strlen(tmp)); } -static void _req_set_sensor_geo(int len, const char* data) +static void _req_set_sensor_geo(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; int x, y, z, accuracy, t_north, t_east, t_vertical; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // x + /* x */ len += get_parse_val(data + len, tmp); x = atoi(tmp); - // y + /* y */ len += get_parse_val(data + len, tmp); y = atoi(tmp); - // z + /* z */ len += get_parse_val(data + len, tmp); z = atoi(tmp); @@ -366,15 +369,15 @@ static void _req_set_sensor_geo(int len, const char* data) set_sensor_tilt(tmp, strlen(tmp)); - // tesla_north + /* tesla_north */ len += get_parse_val(data + len, tmp); t_north = atoi(tmp); - // tesla_east + /* tesla_east */ len += get_parse_val(data + len, tmp); t_east = atoi(tmp); - // tesla_vertical + /* tesla_vertical */ len += get_parse_val(data + len, tmp); t_vertical = atoi(tmp); @@ -385,23 +388,23 @@ static void _req_set_sensor_geo(int len, const char* data) set_sensor_mag(tmp, strlen(tmp)); } -static void _req_set_sensor_tilt(int len, const char* data) +static void _req_set_sensor_tilt(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; int x, y, z, accuracy = 3; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // x + /* x */ len += get_parse_val(data + len, tmp); x = atoi(tmp); - // y + /* y */ len += get_parse_val(data + len, tmp); y = atoi(tmp); - // z + /* z */ len += get_parse_val(data + len, tmp); z = atoi(tmp); @@ -412,23 +415,23 @@ static void _req_set_sensor_tilt(int len, const char* data) set_sensor_tilt(tmp, strlen(tmp)); } -static void _req_set_sensor_mag(int len, const char* data) +static void _req_set_sensor_mag(int len, const char *data) { char tmp[TEMP_BUF_SIZE]; int x, y, z; - // get sensor level + /* get sensor level */ len += get_parse_val(data + len, tmp); - // x + /* x */ len += get_parse_val(data + len, tmp); x = atoi(tmp); - // y + /* y */ len += get_parse_val(data + len, tmp); y = atoi(tmp); - // z + /* z */ len += get_parse_val(data + len, tmp); z = atoi(tmp); @@ -439,18 +442,19 @@ static void _req_set_sensor_mag(int len, const char* data) set_sensor_mag(tmp, strlen(tmp)); } -static void set_battery_data(int len, const char* data) { +static void set_battery_data(int len, const char *data) +{ char tmp[TEMP_BUF_SIZE]; int id = 0, status = 0, level = 0; - // remove item size + /* remove item size */ len += get_parse_val(data + len, tmp); - // id + /* id */ len += get_parse_val(data + len, tmp); id = atoi(tmp); - // status + /* status */ len += get_parse_val(data + len, tmp); status = atoi(tmp); @@ -472,47 +476,47 @@ static void set_battery_data(int len, const char* data) { } } -void ecs_sensor_set_injector_data(const char* data) +void ecs_sensor_set_injector_data(const char *data) { char tmpbuf[TEMP_BUF_SIZE]; int len = get_parse_val(data, tmpbuf); - switch(atoi(tmpbuf)) { - case level_accel: - _req_set_sensor_accel(len, data); - break; - case level_proxi: - _req_set_sensor_proxi(len, data); - break; - case level_light: - _req_set_sensor_light(len, data); - break; - case level_gyro: - _req_set_sensor_gyro(len, data); - break; - case level_geo: - _req_set_sensor_geo(len, data); - break; - case level_battery: - set_battery_data(len, data); - break; - case level_tilt: - _req_set_sensor_tilt(len, data); - break; - case level_magnetic: - _req_set_sensor_mag(len, data); - break; - case level_pressure: - _req_set_sensor_pressure(len, data); - break; - case level_uv: - _req_set_sensor_uv(len, data); - break; - case level_hrm: - _req_set_sensor_hrm(len, data); - break; - default: - break; + switch (atoi(tmpbuf)) { + case level_accel: + _req_set_sensor_accel(len, data); + break; + case level_proxi: + _req_set_sensor_proxi(len, data); + break; + case level_light: + _req_set_sensor_light(len, data); + break; + case level_gyro: + _req_set_sensor_gyro(len, data); + break; + case level_geo: + _req_set_sensor_geo(len, data); + break; + case level_battery: + set_battery_data(len, data); + break; + case level_tilt: + _req_set_sensor_tilt(len, data); + break; + case level_magnetic: + _req_set_sensor_mag(len, data); + break; + case level_pressure: + _req_set_sensor_pressure(len, data); + break; + case level_uv: + _req_set_sensor_uv(len, data); + break; + case level_hrm: + _req_set_sensor_hrm(len, data); + break; + default: + break; } } diff --git a/tizen/src/ecs/ecs_sensor.h b/tizen/src/ecs/ecs_sensor.h index f8df3d8c29..042d431bcd 100644 --- a/tizen/src/ecs/ecs_sensor.h +++ b/tizen/src/ecs/ecs_sensor.h @@ -4,6 +4,7 @@ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: + * Chulho Song * Jinhyung Choi * SeokYeon Hwang * Sangho Park @@ -52,6 +53,6 @@ void req_set_sensor_accel_angle(int angle); void req_set_sensor_accel(int x, int y, int z); #endif -void ecs_sensor_set_injector_data(const char* data); +void ecs_sensor_set_injector_data(const char *data); -#endif // __ECS_SENSOR_H__ +#endif /* __ECS_SENSOR_H__ */ diff --git a/tizen/src/hw/virtio/maru_virtio_evdi.c b/tizen/src/hw/virtio/maru_virtio_evdi.c index 81032901a9..a76c088449 100644 --- a/tizen/src/hw/virtio/maru_virtio_evdi.c +++ b/tizen/src/hw/virtio/maru_virtio_evdi.c @@ -44,27 +44,20 @@ enum { IOTYPE_OUTPUT = 1 }; - #ifndef min -#define min(a,b) ((a)<(b)?(a):(b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) #endif +VirtIOEVDI *vio_evdi; -VirtIOEVDI* vio_evdi; - -// - -typedef struct MsgInfo -{ +typedef struct MsgInfo { msg_info info; QTAILQ_ENTRY(MsgInfo) next; -}MsgInfo; +} MsgInfo; static QTAILQ_HEAD(MsgInfoRecvHead , MsgInfo) evdi_recv_msg_queue = QTAILQ_HEAD_INITIALIZER(evdi_recv_msg_queue); -// - typedef struct EvdiBuf { VirtQueueElement elem; @@ -74,17 +67,16 @@ typedef struct EvdiBuf { static QTAILQ_HEAD(EvdiMsgHead , EvdiBuf) evdi_in_queue = QTAILQ_HEAD_INITIALIZER(evdi_in_queue); - static QemuMutex recv_buf_mutex; -bool send_to_evdi(const uint32_t route, char* data, const uint32_t len) +bool send_to_evdi(const uint32_t route, char *data, const uint32_t len) { int size; int left = len; int count = 0; - char* readptr = data; + char *readptr = data; - if(vio_evdi == NULL) { + if (vio_evdi == NULL) { ERR("EVDI is not initialized\n"); return false; } @@ -93,11 +85,11 @@ bool send_to_evdi(const uint32_t route, char* data, const uint32_t len) ERR("virtio queue is not ready\n"); } - while (left > 0) - { - MsgInfo* _msg = (MsgInfo*) malloc(sizeof(MsgInfo)); - if (!_msg) + while (left > 0) { + MsgInfo *_msg = (MsgInfo *) malloc(sizeof(MsgInfo)); + if (!_msg) { return false; + } memset(&_msg->info, 0, sizeof(msg_info)); @@ -114,7 +106,7 @@ bool send_to_evdi(const uint32_t route, char* data, const uint32_t len) qemu_mutex_unlock(&recv_buf_mutex); left -= size; - count ++; + count++; } qemu_bh_schedule(vio_evdi->bh); @@ -140,41 +132,40 @@ static void flush_evdi_recv_queue(void) qemu_mutex_lock(&recv_buf_mutex); - while (!QTAILQ_EMPTY(&evdi_recv_msg_queue)) - { - MsgInfo* msginfo = QTAILQ_FIRST(&evdi_recv_msg_queue); - if (!msginfo) - break; + while (!QTAILQ_EMPTY(&evdi_recv_msg_queue)) { + MsgInfo *msginfo = QTAILQ_FIRST(&evdi_recv_msg_queue); + if (!msginfo) { + break; + } - VirtQueueElement elem; - index = virtqueue_pop(vio_evdi->rvq, &elem); - if (index == 0) - { - //ERR("unexpected empty queue"); - break; - } + VirtQueueElement elem; + index = virtqueue_pop(vio_evdi->rvq, &elem); + if (index == 0) { + /* ERR("unexpected empty queue"); */ + break; + } - //INFO(">> virtqueue_pop. index: %d, out_num : %d, in_num : %d\n", index, elem.out_num, elem.in_num); + /* INFO(">> virtqueue_pop. index: %d, out_num : %d, in_num : %d\n", index, elem.out_num, elem.in_num); */ - memset(elem.in_sg[0].iov_base, 0, elem.in_sg[0].iov_len); - memcpy(elem.in_sg[0].iov_base, &msginfo->info, sizeof(struct msg_info)); + memset(elem.in_sg[0].iov_base, 0, elem.in_sg[0].iov_len); + memcpy(elem.in_sg[0].iov_base, &msginfo->info, sizeof(struct msg_info)); - //INFO(">> send to guest use = %d, msg = %s, iov_len = %d \n", - //msginfo->info.use, msginfo->info.buf, elem.in_sg[0].iov_len); + /* INFO(">> send to guest use = %d, msg = %s, iov_len = %d \n", + //msginfo->info.use, msginfo->info.buf, elem.in_sg[0].iov_len); */ - virtqueue_push(vio_evdi->rvq, &elem, sizeof(msg_info)); - virtio_notify(&vio_evdi->vdev, vio_evdi->rvq); + virtqueue_push(vio_evdi->rvq, &elem, sizeof(msg_info)); + virtio_notify(&vio_evdi->vdev, vio_evdi->rvq); - QTAILQ_REMOVE(&evdi_recv_msg_queue, msginfo, next); - if (msginfo) - free(msginfo); + QTAILQ_REMOVE(&evdi_recv_msg_queue, msginfo, next); + if (msginfo) { + free(msginfo); + } } qemu_mutex_unlock(&recv_buf_mutex); } - static void virtio_evdi_recv(VirtIODevice *vdev, VirtQueue *vq) { flush_evdi_recv_queue(); @@ -195,14 +186,14 @@ static void virtio_evdi_send(VirtIODevice *vdev, VirtQueue *vq) while ((index = virtqueue_pop(vq, &elem))) { - //INFO("<< virtqueue pop. index: %d, out_num : %d, in_num : %d\n", index, elem.out_num, elem.in_num); + /* INFO("<< virtqueue pop. index: %d, out_num : %d, in_num : %d\n", index, elem.out_num, elem.in_num); */ - //INFO("<< use=%d, iov_len = %d\n", _msg.use, elem.out_sg[0].iov_len); + /* INFO("<< use=%d, iov_len = %d\n", _msg.use, elem.out_sg[0].iov_len); */ memset(&_msg, 0x00, sizeof(_msg)); memcpy(&_msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len); - //INFO("<< recv from guest len = %d, msg = %s \n", _msg.use, _msg.buf); + /* INFO("<< recv from guest len = %d, msg = %s \n", _msg.use, _msg.buf); */ send_injector_ntf(_msg.buf, _msg.use); } @@ -234,7 +225,7 @@ static void virtio_evdi_realize(DeviceState *dev, Error **errp) INFO("initialize evdi device\n"); - virtio_init(vdev, TYPE_VIRTIO_MARU_EVDI, VIRTIO_ID_MARU_EVDI, 0); //EVDI_DEVICE_NAME + virtio_init(vdev, TYPE_VIRTIO_MARU_EVDI, VIRTIO_ID_MARU_EVDI, 0); /* EVDI_DEVICE_NAME */ vio_evdi->rvq = virtio_add_queue(&vio_evdi->vdev, 256, virtio_evdi_recv); vio_evdi->svq = virtio_add_queue(&vio_evdi->vdev, 256, virtio_evdi_send); diff --git a/tizen/src/hw/virtio/maru_virtio_evdi.h b/tizen/src/hw/virtio/maru_virtio_evdi.h index 5e320a279d..0bba4524ac 100644 --- a/tizen/src/hw/virtio/maru_virtio_evdi.h +++ b/tizen/src/hw/virtio/maru_virtio_evdi.h @@ -18,8 +18,7 @@ extern "C" { #define __MAX_BUF_SIZE 1024 -enum -{ +enum { route_qemu = 0, route_control_server = 1, route_monitor = 2, @@ -37,11 +36,11 @@ typedef struct msg_info { uint16_t index; CSCliSN cclisn; -}msg_info; +} msg_info; /* device protocol */ -typedef struct VirtIOEVDI{ +typedef struct VirtIOEVDI { VirtIODevice vdev; VirtQueue *rvq; VirtQueue *svq; @@ -56,10 +55,10 @@ extern VirtIOEVDI *vio_evdi; #define VIRTIO_MARU_EVDI(obj) \ OBJECT_CHECK(VirtIOEVDI, (obj), TYPE_VIRTIO_MARU_EVDI) -//VirtIODevice *virtio_evdi_init(DeviceState *dev); +/* VirtIODevice *virtio_evdi_init(DeviceState *dev); */ -//void virtio_evdi_exit(VirtIODevice *vdev); -bool send_to_evdi(const uint32_t route, char* data, const uint32_t len); +/* void virtio_evdi_exit(VirtIODevice *vdev); */ +bool send_to_evdi(const uint32_t route, char *data, const uint32_t len); #ifdef __cplusplus } diff --git a/tizen/src/hw/virtio/maru_virtio_jack.c b/tizen/src/hw/virtio/maru_virtio_jack.c index 26251a3cb5..299b9b5466 100644 --- a/tizen/src/hw/virtio/maru_virtio_jack.c +++ b/tizen/src/hw/virtio/maru_virtio_jack.c @@ -42,14 +42,14 @@ MULTI_DEBUG_CHANNEL(qemu, jack); #define _MAX_BUF 1024 #define __MAX_BUF_JACK 32 -static int charger_online = 0; -static int earjack_online = 0; -static int earkey_online = 0; -static int hdmi_online = 0; -static int usb_online = 0; +static int charger_online; +static int earjack_online; +static int earkey_online; +static int hdmi_online; +static int usb_online; -VirtIOJACK* vjack; -static int jack_capability = 0; +VirtIOJACK *vjack; +static int jack_capability; typedef struct msg_info { char buf[_MAX_BUF]; @@ -64,31 +64,37 @@ enum request_cmd { request_answer }; -void set_jack_charger(int online){ +void set_jack_charger(int online) +{ charger_online = online; } -int get_jack_charger(void) { +int get_jack_charger(void) +{ return charger_online; } -void set_jack_usb(int online){ +void set_jack_usb(int online) +{ usb_online = online; } -int get_jack_usb(void) { +int get_jack_usb(void) +{ return usb_online; } -void set_jack_earjack(int online){ +void set_jack_earjack(int online) +{ earjack_online = online; } -int get_jack_earjack(void) { +int get_jack_earjack(void) +{ return earjack_online; } -static void set_jack_data (enum jack_types type, char* data, int len) +static void set_jack_data(enum jack_types type, char *data, int len) { if (len < 0 || len > __MAX_BUF_JACK) { ERR("jack data size is wrong.\n"); @@ -101,59 +107,59 @@ static void set_jack_data (enum jack_types type, char* data, int len) } switch (type) { - case jack_type_charger: - sscanf(data, "%d", &charger_online); - break; - case jack_type_earjack: - sscanf(data, "%d", &earjack_online); - break; - case jack_type_earkey: - sscanf(data, "%d", &earkey_online); - break; - case jack_type_hdmi: - sscanf(data, "%d", &hdmi_online); - break; - case jack_type_usb: - sscanf(data, "%d", &usb_online); - break; - default: - return; + case jack_type_charger: + sscanf(data, "%d", &charger_online); + break; + case jack_type_earjack: + sscanf(data, "%d", &earjack_online); + break; + case jack_type_earkey: + sscanf(data, "%d", &earkey_online); + break; + case jack_type_hdmi: + sscanf(data, "%d", &hdmi_online); + break; + case jack_type_usb: + sscanf(data, "%d", &usb_online); + break; + default: + return; } } -static void get_jack_data(enum jack_types type, char* msg_info) +static void get_jack_data(enum jack_types type, char *msg_info) { if (msg_info == NULL) { return; } switch (type) { - case jack_type_list: - sprintf(msg_info, "%d", jack_capability); - break; - case jack_type_charger: - sprintf(msg_info, "%d", charger_online); - break; - case jack_type_earjack: - sprintf(msg_info, "%d", earjack_online); - break; - case jack_type_earkey: - sprintf(msg_info, "%d", earkey_online); - break; - case jack_type_hdmi: - sprintf(msg_info, "%d", hdmi_online); - break; - case jack_type_usb: - sprintf(msg_info, "%d", usb_online); - break; - default: - return; + case jack_type_list: + sprintf(msg_info, "%d", jack_capability); + break; + case jack_type_charger: + sprintf(msg_info, "%d", charger_online); + break; + case jack_type_earjack: + sprintf(msg_info, "%d", earjack_online); + break; + case jack_type_earkey: + sprintf(msg_info, "%d", earkey_online); + break; + case jack_type_hdmi: + sprintf(msg_info, "%d", hdmi_online); + break; + case jack_type_usb: + sprintf(msg_info, "%d", usb_online); + break; + default: + return; } } -static void answer_jack_data_request(int type, char* data, VirtQueueElement *elem) +static void answer_jack_data_request(int type, char *data, VirtQueueElement *elem) { - msg_info* msginfo = (msg_info*) malloc(sizeof(msg_info)); + msg_info *msginfo = (msg_info *) malloc(sizeof(msg_info)); if (!msginfo) { ERR("msginfo is NULL!\n"); return; @@ -168,8 +174,9 @@ static void answer_jack_data_request(int type, char* data, VirtQueueElement *ele memset(elem->in_sg[0].iov_base, 0, elem->in_sg[0].iov_len); memcpy(elem->in_sg[0].iov_base, msginfo, sizeof(struct msg_info)); - if (msginfo) + if (msginfo) { free(msginfo); + } } static void handle_msg(struct msg_info *msg, VirtQueueElement *elem) @@ -182,7 +189,7 @@ static void handle_msg(struct msg_info *msg, VirtQueueElement *elem) } if (msg->req == request_set) { - set_jack_data (msg->type, msg->buf, strlen(msg->buf)); + set_jack_data(msg->type, msg->buf, strlen(msg->buf)); } else if (msg->req == request_get) { answer_jack_data_request(msg->type, msg->buf, elem); len = sizeof(msg_info); @@ -194,7 +201,7 @@ static void handle_msg(struct msg_info *msg, VirtQueueElement *elem) static void virtio_jack_vq(VirtIODevice *vdev, VirtQueue *vq) { - VirtIOJACK *vjack = (VirtIOJACK*)vdev; + VirtIOJACK *vjack = (VirtIOJACK *)vdev; struct msg_info msg; VirtQueueElement elem; int index = 0; @@ -224,7 +231,7 @@ static void virtio_jack_vq(VirtIODevice *vdev, VirtQueue *vq) } } -static int set_capability(char* jack) +static int set_capability(char *jack) { if (!strncmp(jack, JACK_NAME_CHARGER, 7)) { return jack_cap_charger; @@ -241,13 +248,14 @@ static int set_capability(char* jack) return 0; } -static void parse_jack_capability(char* lists) +static void parse_jack_capability(char *lists) { char token[] = JACK_CAP_TOKEN; - char* data = NULL; + char *data = NULL; - if (lists == NULL) + if (lists == NULL) { return; + } data = strtok(lists, token); if (data != NULL) { diff --git a/tizen/src/hw/virtio/maru_virtio_nfc.c b/tizen/src/hw/virtio/maru_virtio_nfc.c index d7976afc88..3b1ec0a522 100644 --- a/tizen/src/hw/virtio/maru_virtio_nfc.c +++ b/tizen/src/hw/virtio/maru_virtio_nfc.c @@ -44,16 +44,15 @@ enum { #ifndef min -#define min(a,b) ((a)<(b)?(a):(b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) #endif -VirtIONFC* vio_nfc; +VirtIONFC *vio_nfc; -typedef struct MsgInfo -{ +typedef struct MsgInfo { nfc_msg_info info; QTAILQ_ENTRY(MsgInfo) next; -}MsgInfo; +} MsgInfo; static QTAILQ_HEAD(MsgInfoRecvHead , MsgInfo) nfc_recv_msg_queue = QTAILQ_HEAD_INITIALIZER(nfc_recv_msg_queue); @@ -64,10 +63,10 @@ typedef struct NFCBuf { } NFCBuf; -static char nfc_data [NFC_MAX_BUF_SIZE] = {'0',}; +static char nfc_data[NFC_MAX_BUF_SIZE] = {'0',}; static QemuMutex recv_buf_mutex; -static void send_nfc_data_to_ecs(const char* data) +static void send_nfc_data_to_ecs(const char *data) { type_length length = 0; type_group group = 15; @@ -75,9 +74,10 @@ static void send_nfc_data_to_ecs(const char* data) int buf_len = strlen(data); int message_len = buf_len + 14; - char* ecs_message = (char*) malloc(message_len + 1); - if (!ecs_message) + char *ecs_message = (char *) malloc(message_len + 1); + if (!ecs_message) { return; + } memset(ecs_message, 0, message_len + 1); @@ -90,12 +90,14 @@ static void send_nfc_data_to_ecs(const char* data) memcpy(ecs_message + 13, &action, sizeof(unsigned char)); memcpy(ecs_message + 14, data, buf_len); - TRACE("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", length, group, action, data); + TRACE("ntf_to_injector- len: %d, group: %d, action: %d, data: %s\n", + length, group, action, data); send_device_ntf(ecs_message, message_len); - if (ecs_message) + if (ecs_message) { free(ecs_message); + } } void get_nfc_data(void) @@ -103,9 +105,10 @@ void get_nfc_data(void) send_nfc_data_to_ecs(nfc_data); } -bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const uint32_t len) +bool send_to_nfc(unsigned char id, unsigned char type, const char *data, + const uint32_t len) { - if(vio_nfc == NULL) { + if (vio_nfc == NULL) { ERR("NFC is not initialized\n"); return false; } @@ -115,12 +118,12 @@ bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const u return false; } - MsgInfo* _msg = (MsgInfo*) malloc(sizeof(MsgInfo)); + MsgInfo *_msg = (MsgInfo *) malloc(sizeof(MsgInfo)); if (!_msg) { return false; } - if(len > NFC_MAX_BUF_SIZE) { + if (len > NFC_MAX_BUF_SIZE) { ERR("the length of data is longer than max buffer size"); free(_msg); return false; @@ -161,34 +164,35 @@ static void flush_nfc_recv_queue(void) qemu_mutex_lock(&recv_buf_mutex); - while (!QTAILQ_EMPTY(&nfc_recv_msg_queue)) - { - MsgInfo* msginfo = QTAILQ_FIRST(&nfc_recv_msg_queue); + while (!QTAILQ_EMPTY(&nfc_recv_msg_queue)) { + MsgInfo *msginfo = QTAILQ_FIRST(&nfc_recv_msg_queue); if (!msginfo) { break; } VirtQueueElement elem; index = virtqueue_pop(vio_nfc->rvq, &elem); - if (index == 0) - { - //ERR("unexpected empty queue"); + if (index == 0) { + /* ERR("unexpected empty queue"); */ break; } - INFO(">> virtqueue_pop. index: %d, out_num : %d, in_num : %d\n", index, elem.out_num, elem.in_num); + INFO(">> virtqueue_pop. index: %d, out_num : %d, in_num : %d\n", + index, elem.out_num, elem.in_num); - memcpy(elem.in_sg[0].iov_base, &msginfo->info, sizeof(struct nfc_msg_info)); + memcpy(elem.in_sg[0].iov_base, &msginfo->info, + sizeof(struct nfc_msg_info)); - INFO(">> send to guest use = %d, msg = %s, iov_len = %d \n", + INFO(">> send to guest use = %d, msg = %s, iov_len = %d\n", msginfo->info.use, msginfo->info.buf, elem.in_sg[0].iov_len); virtqueue_push(vio_nfc->rvq, &elem, sizeof(nfc_msg_info)); virtio_notify(&vio_nfc->vdev, vio_nfc->rvq); QTAILQ_REMOVE(&nfc_recv_msg_queue, msginfo, next); - if (msginfo) + if (msginfo) { free(msginfo); + } } qemu_mutex_unlock(&recv_buf_mutex); @@ -216,14 +220,15 @@ static void virtio_nfc_send(VirtIODevice *vdev, VirtQueue *vq) while ((index = virtqueue_pop(vq, &elem))) { - INFO("<< virtqueue pop. index: %d, out_num : %d, in_num : %d\n", index, elem.out_num, elem.in_num); + INFO("<< virtqueue pop. index: %d, out_num : %d, in_num : %d\n", + index, elem.out_num, elem.in_num); INFO("<< iov_len = %d\n", elem.out_sg[0].iov_len); memset(&_msg, 0x00, sizeof(_msg)); memcpy(&_msg, elem.out_sg[0].iov_base, elem.out_sg[0].iov_len); - INFO("<< recv from guest len = %d, msg = %s \n", _msg.use, _msg.buf); + INFO("<< recv from guest len = %d, msg = %s\n", _msg.use, _msg.buf); send_nfc_ntf(&_msg); } @@ -244,7 +249,7 @@ static void maru_nfc_bh(void *opaque) flush_nfc_recv_queue(); } -static void virtio_nfc_realize(DeviceState* dev, Error **errp) +static void virtio_nfc_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); vio_nfc = VIRTIO_MARU_NFC(vdev); @@ -265,7 +270,7 @@ static void virtio_nfc_realize(DeviceState* dev, Error **errp) qemu_mutex_init(&recv_buf_mutex); } -static void virtio_nfc_unrealize(DeviceState* dev, Error **errp) +static void virtio_nfc_unrealize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); diff --git a/tizen/src/hw/virtio/maru_virtio_nfc.h b/tizen/src/hw/virtio/maru_virtio_nfc.h index a8269c60bd..56ac1b5f97 100644 --- a/tizen/src/hw/virtio/maru_virtio_nfc.h +++ b/tizen/src/hw/virtio/maru_virtio_nfc.h @@ -36,23 +36,22 @@ extern "C" { #include "hw/virtio/virtio.h" enum request_cmd_nfc { - request_nfc_get = 0, - request_nfc_set, - request_nfc_answer + request_nfc_get = 0, + request_nfc_set, + request_nfc_answer }; /* device protocol */ -#define __MAX_BUF_SIZE 1024 +#define __MAX_BUF_SIZE 1024 #define MESSAGE_TYPE_NFC "nfc" -typedef struct VirtIONFC{ +typedef struct VirtIONFC { VirtIODevice vdev; VirtQueue *rvq; - VirtQueue *svq; + VirtQueue *svq; DeviceState *qdev; - QEMUBH *bh; } VirtIONFC; @@ -62,7 +61,7 @@ typedef struct VirtIONFC{ OBJECT_CHECK(VirtIONFC, (obj), TYPE_VIRTIO_MARU_NFC) -bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const uint32_t len); +bool send_to_nfc(unsigned char id, unsigned char type, const char *data, const uint32_t len); void get_nfc_data(void); #ifdef __cplusplus diff --git a/tizen/src/hw/virtio/maru_virtio_sensor.c b/tizen/src/hw/virtio/maru_virtio_sensor.c index d8f70c7b4a..612aceec6c 100644 --- a/tizen/src/hw/virtio/maru_virtio_sensor.c +++ b/tizen/src/hw/virtio/maru_virtio_sensor.c @@ -50,49 +50,51 @@ static QemuMutex pressure_mutex; static QemuMutex uv_mutex; static QemuMutex hrm_mutex; -static char accel_xyz [__MAX_BUF_SENSOR] = {'1','0','0',',','9','8','0','6','6','5',',','1','0','0'}; -static int accel_enable = 0; +static char accel_xyz[__MAX_BUF_SENSOR] = {'1', '0', '0', ',', '9', '8', '0', '6', + '6', '5', ',', '1', '0', '0'}; +static int accel_enable; static int accel_delay = 200000000; -static char geo_raw [__MAX_BUF_SENSOR] = {'0',' ','-','9','0',' ','0',' ','3'}; -static char geo_tesla [__MAX_BUF_SENSOR] = {'1',' ','0',' ','-','1','0'}; -static int geo_enable = 0; +static char geo_raw[__MAX_BUF_SENSOR] = {'0', ' ', '-', '9', '0', ' ', '0', ' ', '3'}; +static char geo_tesla[__MAX_BUF_SENSOR] = {'1', ' ', '0', ' ', '-', '1', '0'}; +static int geo_enable; static int geo_delay = 200000000; -static int gyro_x_raw = 0; -static int gyro_y_raw = 0; +static int gyro_x_raw; +static int gyro_y_raw; static int gyro_z_raw = 1; -static int gyro_enable = 0; +static int gyro_enable; static int gyro_delay = 200000000; static int light_adc = 65535; static int light_level = 10; -static int light_enable = 0; +static int light_enable; static int light_delay = 200000000; static int proxi_vo = 8; -static int proxi_enable = 0; +static int proxi_enable; static int proxi_delay = 200000000; -static char rot_quad [__MAX_BUF_SENSOR] = {'2','3','6','2',',','-','1','4','0',',','-','8','4','7','0',',','9','9','9','9','6','1',',','4', 0}; -static int rot_enable = 0; +static char rot_quad[__MAX_BUF_SENSOR] = {'2', '3', '6', '2', ',', '-', '1', '4', '0', ',', '-', '8', '4', + '7', '0', ',', '9', '9', '9', '9', '6', '1', ',', '4', 0}; +static int rot_enable; static int rot_delay = 200000000; -static char pressure_data [__MAX_BUF_SENSOR] = {'7','6','0',',',' ','4','2','5', 0}; -static int pressure_enable = 0; +static char pressure_data[__MAX_BUF_SENSOR] = {'7', '6', '0', ',', ' ', '4', '2', '5', 0}; +static int pressure_enable; static int pressure_delay = 200000000; -static int uv_level = 0; -static int uv_enable = 0; +static int uv_level; +static int uv_enable; static int uv_delay = 200000000; static int hrm_heart = 1000; static int hrm_rri = 600; -static int hrm_enable = 0; +static int hrm_enable; static int hrm_delay = 200000000; -VirtIOSENSOR* vsensor; -static int sensor_capability = 0; +VirtIOSENSOR *vsensor; +static int sensor_capability; typedef struct msg_info { char buf[_MAX_BUF]; @@ -140,7 +142,7 @@ static type_action get_action(enum sensor_types type) return action; } -static void send_sensor_to_ecs(const char* data, enum sensor_types type) +static void send_sensor_to_ecs(const char *data, enum sensor_types type) { type_length length = 0; type_group group = GROUP_STATUS; @@ -148,9 +150,10 @@ static void send_sensor_to_ecs(const char* data, enum sensor_types type) int buf_len = strlen(data); int message_len = buf_len + 14; - char* ecs_message = (char*) malloc(message_len + 1); - if (!ecs_message) + char *ecs_message = (char *) malloc(message_len + 1); + if (!ecs_message) { return; + } memset(ecs_message, 0, message_len + 1); @@ -167,11 +170,12 @@ static void send_sensor_to_ecs(const char* data, enum sensor_types type) send_device_ntf(ecs_message, message_len); - if (ecs_message) + if (ecs_message) { free(ecs_message); + } } -static void __set_sensor_data (enum sensor_types type, char* data, int len) +static void __set_sensor_data(enum sensor_types type, char *data, int len) { if (len < 0 || len > __MAX_BUF_SENSOR) { LOG_SEVERE("sensor data size is wrong.\n"); @@ -186,362 +190,362 @@ static void __set_sensor_data (enum sensor_types type, char* data, int len) LOG_TRACE("set_sensor_data with type '%d' with data '%s'", type, data); switch (type) { - case sensor_type_accel: - qemu_mutex_lock(&accel_mutex); - strcpy(accel_xyz, data); - qemu_mutex_unlock(&accel_mutex); - break; - case sensor_type_accel_enable: - qemu_mutex_lock(&accel_mutex); - sscanf(data, "%d", &accel_enable); - qemu_mutex_unlock(&accel_mutex); - break; - case sensor_type_accel_delay: - qemu_mutex_lock(&accel_mutex); - sscanf(data, "%d", &accel_delay); - qemu_mutex_unlock(&accel_mutex); - break; - case sensor_type_gyro_enable: - qemu_mutex_lock(&gyro_mutex); - sscanf(data, "%d", &gyro_enable); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_delay: - qemu_mutex_lock(&gyro_mutex); - sscanf(data, "%d", &gyro_delay); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_x: - qemu_mutex_lock(&gyro_mutex); - sscanf(data, "%d", &gyro_x_raw); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_y: - qemu_mutex_lock(&gyro_mutex); - sscanf(data, "%d", &gyro_y_raw); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_z: - qemu_mutex_lock(&gyro_mutex); - sscanf(data, "%d", &gyro_z_raw); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro: - qemu_mutex_lock(&gyro_mutex); - sscanf(data, "%d %d %d", &gyro_x_raw, &gyro_y_raw, &gyro_z_raw); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_light_adc: - qemu_mutex_lock(&light_mutex); - sscanf(data, "%d", &light_adc); - light_level = (light_adc / 6554) % 10 + 1; - qemu_mutex_unlock(&light_mutex); - break; - case sensor_type_light_level: - qemu_mutex_lock(&light_mutex); - sscanf(data, "%d", &light_level); - qemu_mutex_unlock(&light_mutex); - break; - case sensor_type_light_enable: - qemu_mutex_lock(&light_mutex); - sscanf(data, "%d", &light_enable); - qemu_mutex_unlock(&light_mutex); - break; - case sensor_type_light_delay: - qemu_mutex_lock(&light_mutex); - sscanf(data, "%d", &light_delay); - qemu_mutex_unlock(&light_mutex); - break; - case sensor_type_proxi: - qemu_mutex_lock(&proxi_mutex); - sscanf(data, "%d", &proxi_vo); - qemu_mutex_unlock(&proxi_mutex); - break; - case sensor_type_proxi_enable: - qemu_mutex_lock(&proxi_mutex); - sscanf(data, "%d", &proxi_enable); - qemu_mutex_unlock(&proxi_mutex); - break; - case sensor_type_proxi_delay: - qemu_mutex_lock(&proxi_mutex); - sscanf(data, "%d", &proxi_delay); - qemu_mutex_unlock(&proxi_mutex); - break; - case sensor_type_rotation_vector: - qemu_mutex_lock(&rot_mutex); - strcpy(rot_quad, data); - qemu_mutex_unlock(&rot_mutex); - break; - case sensor_type_rotation_vector_enable: - qemu_mutex_lock(&rot_mutex); - sscanf(data, "%d", &rot_enable); - qemu_mutex_unlock(&rot_mutex); - break; - case sensor_type_rotation_vector_delay: - qemu_mutex_lock(&rot_mutex); - sscanf(data, "%d", &rot_delay); - qemu_mutex_unlock(&rot_mutex); - break; - case sensor_type_mag: - qemu_mutex_lock(&geo_mutex); - strcpy(geo_tesla, data); - qemu_mutex_unlock(&geo_mutex); - break; - case sensor_type_tilt: - qemu_mutex_lock(&geo_mutex); - strcpy(geo_raw, data); - qemu_mutex_unlock(&geo_mutex); - break; - case sensor_type_geo_enable: - qemu_mutex_lock(&geo_mutex); - sscanf(data, "%d", &geo_enable); - qemu_mutex_unlock(&geo_mutex); - break; - case sensor_type_geo_delay: - qemu_mutex_lock(&geo_mutex); - sscanf(data, "%d", &geo_delay); - qemu_mutex_unlock(&geo_mutex); - break; - case sensor_type_pressure: - qemu_mutex_lock(&pressure_mutex); - strcpy(pressure_data, data); - qemu_mutex_unlock(&pressure_mutex); - break; - case sensor_type_pressure_enable: - qemu_mutex_lock(&pressure_mutex); - sscanf(data, "%d", &pressure_enable); - qemu_mutex_unlock(&pressure_mutex); - break; - case sensor_type_pressure_delay: - qemu_mutex_lock(&pressure_mutex); - sscanf(data, "%d", &pressure_delay); - qemu_mutex_unlock(&pressure_mutex); - break; - case sensor_type_uv: - qemu_mutex_lock(&uv_mutex); - sscanf(data, "%d", &uv_level); - qemu_mutex_unlock(&uv_mutex); - break; - case sensor_type_uv_enable: - qemu_mutex_lock(&uv_mutex); - sscanf(data, "%d", &uv_enable); - qemu_mutex_unlock(&uv_mutex); - break; - case sensor_type_uv_delay: - qemu_mutex_lock(&uv_mutex); - sscanf(data, "%d", &uv_delay); - qemu_mutex_unlock(&uv_mutex); - break; - case sensor_type_hrm: - qemu_mutex_lock(&hrm_mutex); - sscanf(data, "%d, %d", &hrm_heart, &hrm_rri); - qemu_mutex_unlock(&hrm_mutex); - break; - case sensor_type_hrm_heart: - qemu_mutex_lock(&hrm_mutex); - sscanf(data, "%d", &hrm_heart); - qemu_mutex_unlock(&hrm_mutex); - break; - case sensor_type_hrm_rri: - qemu_mutex_lock(&hrm_mutex); - sscanf(data, "%d", &hrm_rri); - qemu_mutex_unlock(&hrm_mutex); - break; - case sensor_type_hrm_enable: - qemu_mutex_lock(&hrm_mutex); - sscanf(data, "%d", &hrm_enable); - qemu_mutex_unlock(&hrm_mutex); - break; - case sensor_type_hrm_delay: - qemu_mutex_lock(&hrm_mutex); - sscanf(data, "%d", &hrm_delay); - qemu_mutex_unlock(&hrm_mutex); - break; - default: - return; + case sensor_type_accel: + qemu_mutex_lock(&accel_mutex); + strcpy(accel_xyz, data); + qemu_mutex_unlock(&accel_mutex); + break; + case sensor_type_accel_enable: + qemu_mutex_lock(&accel_mutex); + sscanf(data, "%d", &accel_enable); + qemu_mutex_unlock(&accel_mutex); + break; + case sensor_type_accel_delay: + qemu_mutex_lock(&accel_mutex); + sscanf(data, "%d", &accel_delay); + qemu_mutex_unlock(&accel_mutex); + break; + case sensor_type_gyro_enable: + qemu_mutex_lock(&gyro_mutex); + sscanf(data, "%d", &gyro_enable); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_delay: + qemu_mutex_lock(&gyro_mutex); + sscanf(data, "%d", &gyro_delay); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_x: + qemu_mutex_lock(&gyro_mutex); + sscanf(data, "%d", &gyro_x_raw); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_y: + qemu_mutex_lock(&gyro_mutex); + sscanf(data, "%d", &gyro_y_raw); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_z: + qemu_mutex_lock(&gyro_mutex); + sscanf(data, "%d", &gyro_z_raw); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro: + qemu_mutex_lock(&gyro_mutex); + sscanf(data, "%d %d %d", &gyro_x_raw, &gyro_y_raw, &gyro_z_raw); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_light_adc: + qemu_mutex_lock(&light_mutex); + sscanf(data, "%d", &light_adc); + light_level = (light_adc / 6554) % 10 + 1; + qemu_mutex_unlock(&light_mutex); + break; + case sensor_type_light_level: + qemu_mutex_lock(&light_mutex); + sscanf(data, "%d", &light_level); + qemu_mutex_unlock(&light_mutex); + break; + case sensor_type_light_enable: + qemu_mutex_lock(&light_mutex); + sscanf(data, "%d", &light_enable); + qemu_mutex_unlock(&light_mutex); + break; + case sensor_type_light_delay: + qemu_mutex_lock(&light_mutex); + sscanf(data, "%d", &light_delay); + qemu_mutex_unlock(&light_mutex); + break; + case sensor_type_proxi: + qemu_mutex_lock(&proxi_mutex); + sscanf(data, "%d", &proxi_vo); + qemu_mutex_unlock(&proxi_mutex); + break; + case sensor_type_proxi_enable: + qemu_mutex_lock(&proxi_mutex); + sscanf(data, "%d", &proxi_enable); + qemu_mutex_unlock(&proxi_mutex); + break; + case sensor_type_proxi_delay: + qemu_mutex_lock(&proxi_mutex); + sscanf(data, "%d", &proxi_delay); + qemu_mutex_unlock(&proxi_mutex); + break; + case sensor_type_rotation_vector: + qemu_mutex_lock(&rot_mutex); + strcpy(rot_quad, data); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_rotation_vector_enable: + qemu_mutex_lock(&rot_mutex); + sscanf(data, "%d", &rot_enable); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_rotation_vector_delay: + qemu_mutex_lock(&rot_mutex); + sscanf(data, "%d", &rot_delay); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_mag: + qemu_mutex_lock(&geo_mutex); + strcpy(geo_tesla, data); + qemu_mutex_unlock(&geo_mutex); + break; + case sensor_type_tilt: + qemu_mutex_lock(&geo_mutex); + strcpy(geo_raw, data); + qemu_mutex_unlock(&geo_mutex); + break; + case sensor_type_geo_enable: + qemu_mutex_lock(&geo_mutex); + sscanf(data, "%d", &geo_enable); + qemu_mutex_unlock(&geo_mutex); + break; + case sensor_type_geo_delay: + qemu_mutex_lock(&geo_mutex); + sscanf(data, "%d", &geo_delay); + qemu_mutex_unlock(&geo_mutex); + break; + case sensor_type_pressure: + qemu_mutex_lock(&pressure_mutex); + strcpy(pressure_data, data); + qemu_mutex_unlock(&pressure_mutex); + break; + case sensor_type_pressure_enable: + qemu_mutex_lock(&pressure_mutex); + sscanf(data, "%d", &pressure_enable); + qemu_mutex_unlock(&pressure_mutex); + break; + case sensor_type_pressure_delay: + qemu_mutex_lock(&pressure_mutex); + sscanf(data, "%d", &pressure_delay); + qemu_mutex_unlock(&pressure_mutex); + break; + case sensor_type_uv: + qemu_mutex_lock(&uv_mutex); + sscanf(data, "%d", &uv_level); + qemu_mutex_unlock(&uv_mutex); + break; + case sensor_type_uv_enable: + qemu_mutex_lock(&uv_mutex); + sscanf(data, "%d", &uv_enable); + qemu_mutex_unlock(&uv_mutex); + break; + case sensor_type_uv_delay: + qemu_mutex_lock(&uv_mutex); + sscanf(data, "%d", &uv_delay); + qemu_mutex_unlock(&uv_mutex); + break; + case sensor_type_hrm: + qemu_mutex_lock(&hrm_mutex); + sscanf(data, "%d, %d", &hrm_heart, &hrm_rri); + qemu_mutex_unlock(&hrm_mutex); + break; + case sensor_type_hrm_heart: + qemu_mutex_lock(&hrm_mutex); + sscanf(data, "%d", &hrm_heart); + qemu_mutex_unlock(&hrm_mutex); + break; + case sensor_type_hrm_rri: + qemu_mutex_lock(&hrm_mutex); + sscanf(data, "%d", &hrm_rri); + qemu_mutex_unlock(&hrm_mutex); + break; + case sensor_type_hrm_enable: + qemu_mutex_lock(&hrm_mutex); + sscanf(data, "%d", &hrm_enable); + qemu_mutex_unlock(&hrm_mutex); + break; + case sensor_type_hrm_delay: + qemu_mutex_lock(&hrm_mutex); + sscanf(data, "%d", &hrm_delay); + qemu_mutex_unlock(&hrm_mutex); + break; + default: + return; } } -static void __get_sensor_data(enum sensor_types type, char* msg_info) +static void __get_sensor_data(enum sensor_types type, char *msg_info) { if (msg_info == NULL) { return; } switch (type) { - case sensor_type_list: - sprintf(msg_info, "%d", sensor_capability); - LOG_INFO("sensor device capabilty sending %02x\n", sensor_capability); - break; - case sensor_type_accel: - qemu_mutex_lock(&accel_mutex); - strcpy(msg_info, accel_xyz); - qemu_mutex_unlock(&accel_mutex); - break; - case sensor_type_accel_enable: - qemu_mutex_lock(&accel_mutex); - sprintf(msg_info, "%d", accel_enable); - qemu_mutex_unlock(&accel_mutex); - break; - case sensor_type_accel_delay: - qemu_mutex_lock(&accel_mutex); - sprintf(msg_info, "%d", accel_delay); - qemu_mutex_unlock(&accel_mutex); - break; - case sensor_type_mag: - qemu_mutex_lock(&geo_mutex); - strcpy(msg_info, geo_tesla); - qemu_mutex_unlock(&geo_mutex); - break; - case sensor_type_tilt: - qemu_mutex_lock(&geo_mutex); - strcpy(msg_info, geo_raw); - qemu_mutex_unlock(&geo_mutex); - break; - case sensor_type_geo_enable: - qemu_mutex_lock(&geo_mutex); - sprintf(msg_info, "%d", geo_enable); - qemu_mutex_unlock(&geo_mutex); - break; - case sensor_type_geo_delay: - qemu_mutex_lock(&geo_mutex); - sprintf(msg_info, "%d", geo_delay); - qemu_mutex_unlock(&geo_mutex); - break; - case sensor_type_gyro: - qemu_mutex_lock(&gyro_mutex); - sprintf(msg_info, "%d,%d,%d", gyro_x_raw, gyro_y_raw, gyro_z_raw); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_enable: - qemu_mutex_lock(&gyro_mutex); - sprintf(msg_info, "%d", gyro_enable); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_delay: - qemu_mutex_lock(&gyro_mutex); - sprintf(msg_info, "%d", gyro_delay); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_x: - qemu_mutex_lock(&gyro_mutex); - sprintf(msg_info, "%d", gyro_x_raw); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_y: - qemu_mutex_lock(&gyro_mutex); - sprintf(msg_info, "%d", gyro_y_raw); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_gyro_z: - qemu_mutex_lock(&gyro_mutex); - sprintf(msg_info, "%d", gyro_z_raw); - qemu_mutex_unlock(&gyro_mutex); - break; - case sensor_type_light: - case sensor_type_light_adc: - qemu_mutex_lock(&light_mutex); - sprintf(msg_info, "%d", light_adc); - qemu_mutex_unlock(&light_mutex); - break; - case sensor_type_light_level: - qemu_mutex_lock(&light_mutex); - sprintf(msg_info, "%d", light_level); - qemu_mutex_unlock(&light_mutex); - break; - case sensor_type_light_enable: - qemu_mutex_lock(&light_mutex); - sprintf(msg_info, "%d", light_enable); - qemu_mutex_unlock(&light_mutex); - break; - case sensor_type_light_delay: - qemu_mutex_lock(&light_mutex); - sprintf(msg_info, "%d", light_delay); - qemu_mutex_unlock(&light_mutex); - break; - case sensor_type_proxi: - qemu_mutex_lock(&proxi_mutex); - sprintf(msg_info, "%d", proxi_vo); - qemu_mutex_unlock(&proxi_mutex); - break; - case sensor_type_proxi_enable: - qemu_mutex_lock(&proxi_mutex); - sprintf(msg_info, "%d", proxi_enable); - qemu_mutex_unlock(&proxi_mutex); - break; - case sensor_type_proxi_delay: - qemu_mutex_lock(&proxi_mutex); - sprintf(msg_info, "%d", proxi_delay); - qemu_mutex_unlock(&proxi_mutex); - break; - case sensor_type_rotation_vector: - qemu_mutex_lock(&rot_mutex); - strcpy(msg_info, rot_quad); - qemu_mutex_unlock(&rot_mutex); - break; - case sensor_type_rotation_vector_enable: - qemu_mutex_lock(&rot_mutex); - sprintf(msg_info, "%d", rot_enable); - qemu_mutex_unlock(&rot_mutex); - break; - case sensor_type_rotation_vector_delay: - qemu_mutex_lock(&rot_mutex); - sprintf(msg_info, "%d", rot_delay); - qemu_mutex_unlock(&rot_mutex); - break; - case sensor_type_pressure: - qemu_mutex_lock(&pressure_mutex); - strcpy(msg_info, pressure_data); - qemu_mutex_unlock(&pressure_mutex); - break; - case sensor_type_pressure_enable: - qemu_mutex_lock(&pressure_mutex); - sprintf(msg_info, "%d", pressure_enable); - qemu_mutex_unlock(&pressure_mutex); - break; - case sensor_type_pressure_delay: - qemu_mutex_lock(&pressure_mutex); - sprintf(msg_info, "%d", pressure_delay); - qemu_mutex_unlock(&pressure_mutex); - break; - case sensor_type_uv: - qemu_mutex_lock(&uv_mutex); - sprintf(msg_info, "%d", uv_level); - qemu_mutex_unlock(&uv_mutex); - break; - case sensor_type_uv_enable: - qemu_mutex_lock(&uv_mutex); - sprintf(msg_info, "%d", uv_enable); - qemu_mutex_unlock(&uv_mutex); - break; - case sensor_type_uv_delay: - qemu_mutex_lock(&uv_mutex); - sprintf(msg_info, "%d", uv_delay); - qemu_mutex_unlock(&uv_mutex); - break; - case sensor_type_hrm: - qemu_mutex_lock(&hrm_mutex); - sprintf(msg_info, "%d, %d", hrm_heart, hrm_rri); - qemu_mutex_unlock(&hrm_mutex); - break; - case sensor_type_hrm_enable: - qemu_mutex_lock(&hrm_mutex); - sprintf(msg_info, "%d", hrm_enable); - qemu_mutex_unlock(&hrm_mutex); - break; - case sensor_type_hrm_delay: - qemu_mutex_lock(&hrm_mutex); - sprintf(msg_info, "%d", hrm_delay); - qemu_mutex_unlock(&hrm_mutex); - break; - default: - return; + case sensor_type_list: + sprintf(msg_info, "%d", sensor_capability); + LOG_INFO("sensor device capabilty sending %02x\n", sensor_capability); + break; + case sensor_type_accel: + qemu_mutex_lock(&accel_mutex); + strcpy(msg_info, accel_xyz); + qemu_mutex_unlock(&accel_mutex); + break; + case sensor_type_accel_enable: + qemu_mutex_lock(&accel_mutex); + sprintf(msg_info, "%d", accel_enable); + qemu_mutex_unlock(&accel_mutex); + break; + case sensor_type_accel_delay: + qemu_mutex_lock(&accel_mutex); + sprintf(msg_info, "%d", accel_delay); + qemu_mutex_unlock(&accel_mutex); + break; + case sensor_type_mag: + qemu_mutex_lock(&geo_mutex); + strcpy(msg_info, geo_tesla); + qemu_mutex_unlock(&geo_mutex); + break; + case sensor_type_tilt: + qemu_mutex_lock(&geo_mutex); + strcpy(msg_info, geo_raw); + qemu_mutex_unlock(&geo_mutex); + break; + case sensor_type_geo_enable: + qemu_mutex_lock(&geo_mutex); + sprintf(msg_info, "%d", geo_enable); + qemu_mutex_unlock(&geo_mutex); + break; + case sensor_type_geo_delay: + qemu_mutex_lock(&geo_mutex); + sprintf(msg_info, "%d", geo_delay); + qemu_mutex_unlock(&geo_mutex); + break; + case sensor_type_gyro: + qemu_mutex_lock(&gyro_mutex); + sprintf(msg_info, "%d,%d,%d", gyro_x_raw, gyro_y_raw, gyro_z_raw); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_enable: + qemu_mutex_lock(&gyro_mutex); + sprintf(msg_info, "%d", gyro_enable); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_delay: + qemu_mutex_lock(&gyro_mutex); + sprintf(msg_info, "%d", gyro_delay); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_x: + qemu_mutex_lock(&gyro_mutex); + sprintf(msg_info, "%d", gyro_x_raw); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_y: + qemu_mutex_lock(&gyro_mutex); + sprintf(msg_info, "%d", gyro_y_raw); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_gyro_z: + qemu_mutex_lock(&gyro_mutex); + sprintf(msg_info, "%d", gyro_z_raw); + qemu_mutex_unlock(&gyro_mutex); + break; + case sensor_type_light: + case sensor_type_light_adc: + qemu_mutex_lock(&light_mutex); + sprintf(msg_info, "%d", light_adc); + qemu_mutex_unlock(&light_mutex); + break; + case sensor_type_light_level: + qemu_mutex_lock(&light_mutex); + sprintf(msg_info, "%d", light_level); + qemu_mutex_unlock(&light_mutex); + break; + case sensor_type_light_enable: + qemu_mutex_lock(&light_mutex); + sprintf(msg_info, "%d", light_enable); + qemu_mutex_unlock(&light_mutex); + break; + case sensor_type_light_delay: + qemu_mutex_lock(&light_mutex); + sprintf(msg_info, "%d", light_delay); + qemu_mutex_unlock(&light_mutex); + break; + case sensor_type_proxi: + qemu_mutex_lock(&proxi_mutex); + sprintf(msg_info, "%d", proxi_vo); + qemu_mutex_unlock(&proxi_mutex); + break; + case sensor_type_proxi_enable: + qemu_mutex_lock(&proxi_mutex); + sprintf(msg_info, "%d", proxi_enable); + qemu_mutex_unlock(&proxi_mutex); + break; + case sensor_type_proxi_delay: + qemu_mutex_lock(&proxi_mutex); + sprintf(msg_info, "%d", proxi_delay); + qemu_mutex_unlock(&proxi_mutex); + break; + case sensor_type_rotation_vector: + qemu_mutex_lock(&rot_mutex); + strcpy(msg_info, rot_quad); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_rotation_vector_enable: + qemu_mutex_lock(&rot_mutex); + sprintf(msg_info, "%d", rot_enable); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_rotation_vector_delay: + qemu_mutex_lock(&rot_mutex); + sprintf(msg_info, "%d", rot_delay); + qemu_mutex_unlock(&rot_mutex); + break; + case sensor_type_pressure: + qemu_mutex_lock(&pressure_mutex); + strcpy(msg_info, pressure_data); + qemu_mutex_unlock(&pressure_mutex); + break; + case sensor_type_pressure_enable: + qemu_mutex_lock(&pressure_mutex); + sprintf(msg_info, "%d", pressure_enable); + qemu_mutex_unlock(&pressure_mutex); + break; + case sensor_type_pressure_delay: + qemu_mutex_lock(&pressure_mutex); + sprintf(msg_info, "%d", pressure_delay); + qemu_mutex_unlock(&pressure_mutex); + break; + case sensor_type_uv: + qemu_mutex_lock(&uv_mutex); + sprintf(msg_info, "%d", uv_level); + qemu_mutex_unlock(&uv_mutex); + break; + case sensor_type_uv_enable: + qemu_mutex_lock(&uv_mutex); + sprintf(msg_info, "%d", uv_enable); + qemu_mutex_unlock(&uv_mutex); + break; + case sensor_type_uv_delay: + qemu_mutex_lock(&uv_mutex); + sprintf(msg_info, "%d", uv_delay); + qemu_mutex_unlock(&uv_mutex); + break; + case sensor_type_hrm: + qemu_mutex_lock(&hrm_mutex); + sprintf(msg_info, "%d, %d", hrm_heart, hrm_rri); + qemu_mutex_unlock(&hrm_mutex); + break; + case sensor_type_hrm_enable: + qemu_mutex_lock(&hrm_mutex); + sprintf(msg_info, "%d", hrm_enable); + qemu_mutex_unlock(&hrm_mutex); + break; + case sensor_type_hrm_delay: + qemu_mutex_lock(&hrm_mutex); + sprintf(msg_info, "%d", hrm_delay); + qemu_mutex_unlock(&hrm_mutex); + break; + default: + return; } } -void req_sensor_data (enum sensor_types type, enum request_cmd req, char* data, int len) +void req_sensor_data(enum sensor_types type, enum request_cmd req, char *data, int len) { - char msg_info [__MAX_BUF_SENSOR]; + char msg_info[__MAX_BUF_SENSOR]; memset(msg_info, 0, sizeof(msg_info)); if (type >= sensor_type_max @@ -552,16 +556,16 @@ void req_sensor_data (enum sensor_types type, enum request_cmd req, char* data, } if (req == request_set) { - __set_sensor_data (type, data, len); + __set_sensor_data(type, data, len); } else if (req == request_get) { __get_sensor_data(type, msg_info); send_sensor_to_ecs(msg_info, type); } } -static void answer_sensor_data_request(int type, char* data, VirtQueueElement *elem) +static void answer_sensor_data_request(int type, char *data, VirtQueueElement *elem) { - msg_info* msginfo = (msg_info*) malloc(sizeof(msg_info)); + msg_info *msginfo = (msg_info *) malloc(sizeof(msg_info)); if (!msginfo) { LOG_SEVERE("msginfo is NULL!\n"); return; @@ -576,8 +580,9 @@ static void answer_sensor_data_request(int type, char* data, VirtQueueElement *e memset(elem->in_sg[0].iov_base, 0, elem->in_sg[0].iov_len); memcpy(elem->in_sg[0].iov_base, msginfo, sizeof(struct msg_info)); - if (msginfo) + if (msginfo) { free(msginfo); + } } static void handle_msg(struct msg_info *msg, VirtQueueElement *elem) @@ -590,7 +595,7 @@ static void handle_msg(struct msg_info *msg, VirtQueueElement *elem) } if (msg->req == request_set) { - __set_sensor_data (msg->type, msg->buf, strlen(msg->buf)); + __set_sensor_data(msg->type, msg->buf, strlen(msg->buf)); } else if (msg->req == request_get) { answer_sensor_data_request(msg->type, msg->buf, elem); len = sizeof(msg_info); @@ -602,7 +607,7 @@ static void handle_msg(struct msg_info *msg, VirtQueueElement *elem) static void virtio_sensor_vq(VirtIODevice *vdev, VirtQueue *vq) { - VirtIOSENSOR *vsensor = (VirtIOSENSOR*)vdev; + VirtIOSENSOR *vsensor = (VirtIOSENSOR *)vdev; struct msg_info msg; VirtQueueElement elem; int index = 0; @@ -632,7 +637,7 @@ static void virtio_sensor_vq(VirtIODevice *vdev, VirtQueue *vq) } } -static int set_capability(char* sensor) +static int set_capability(char *sensor) { if (!strncmp(sensor, SENSOR_NAME_ACCEL, 5)) { return sensor_cap_accel; @@ -661,13 +666,14 @@ static int set_capability(char* sensor) return 0; } -static void parse_sensor_capability(char* lists) +static void parse_sensor_capability(char *lists) { char token[] = SENSOR_CAP_TOKEN; - char* data = NULL; + char *data = NULL; - if (lists == NULL) + if (lists == NULL) { return; + } data = strtok(lists, token); if (data != NULL) { @@ -691,7 +697,7 @@ static void virtio_sensor_realize(DeviceState *dev, Error **errp) if (vsensor == NULL) { LOG_SEVERE("failed to initialize sensor device\n"); - //error_set(errp, QERR_DEVICE_INIT_FAILED, SENSOR_DEVICE_NAME); + /* error_set(errp, QERR_DEVICE_INIT_FAILED, SENSOR_DEVICE_NAME); */ error_setg(errp, "Failed to initialize sensor device\n"); return; } @@ -756,7 +762,7 @@ static void virtio_sensor_class_init(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); dc->props = virtio_sensor_properties; VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); - vdc->unrealize= virtio_sensor_unrealize; + vdc->unrealize = virtio_sensor_unrealize; vdc->realize = virtio_sensor_realize; vdc->get_features = virtio_sensor_get_features; vdc->reset = virtio_sensor_reset; diff --git a/tizen/src/hw/virtio/maru_virtio_sensor.h b/tizen/src/hw/virtio/maru_virtio_sensor.h index a7b7be7a9d..f7f14b42e1 100644 --- a/tizen/src/hw/virtio/maru_virtio_sensor.h +++ b/tizen/src/hw/virtio/maru_virtio_sensor.h @@ -137,7 +137,7 @@ typedef struct VirtIOSENSOR { char *sensors; } VirtIOSENSOR; -void req_sensor_data(enum sensor_types type, enum request_cmd req, char* data, int len); +void req_sensor_data(enum sensor_types type, enum request_cmd req, char *data, int len); #define get_sensor_accel() \ req_sensor_data(sensor_type_accel, request_get, NULL, 0); @@ -178,21 +178,18 @@ void req_sensor_data(enum sensor_types type, enum request_cmd req, char* data, i #define set_sensor_rotation_vector(data, len) \ req_sensor_data(sensor_type_rotation_vector, request_set, data, len); -// Pressure #define get_sensor_pressure() \ req_sensor_data(sensor_type_pressure, request_get, NULL, 0); #define set_sensor_pressure(data, len) \ req_sensor_data(sensor_type_pressure, request_set, data, len); -// UV #define get_sensor_uv() \ req_sensor_data(sensor_type_uv, request_get, NULL, 0); #define set_sensor_uv(data, len) \ req_sensor_data(sensor_type_uv, request_set, data, len); -// HRM #define get_sensor_hrm() \ req_sensor_data(sensor_type_hrm, request_get, NULL, 0); diff --git a/tizen/src/hw/virtio/maru_virtio_vmodem.c b/tizen/src/hw/virtio/maru_virtio_vmodem.c index a6c9e752a8..8ddfa9721c 100644 --- a/tizen/src/hw/virtio/maru_virtio_vmodem.c +++ b/tizen/src/hw/virtio/maru_virtio_vmodem.c @@ -39,17 +39,16 @@ DECLARE_DEBUG_CHANNEL(vmodem); #define VMODEM_DEVICE_NAME "virtio-vmodem" #ifndef min -#define min(a,b) ((a)<(b)?(a):(b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) #endif VirtIOVModem *vio_vmodem; -static bool boolVmodemInitialized = false; +static bool boolVmodemInitialized; -typedef struct MsgInfo -{ +typedef struct MsgInfo { msg_info info; QTAILQ_ENTRY(MsgInfo) next; -}MsgInfo; +} MsgInfo; static QTAILQ_HEAD(MsgInfoRecvHead , MsgInfo) vmodem_recv_msg_queue = QTAILQ_HEAD_INITIALIZER(vmodem_recv_msg_queue); @@ -67,7 +66,7 @@ bool send_to_vmodem(const uint32_t route, char *data, const uint32_t len) } while (left > 0) { - MsgInfo *_msg = (MsgInfo*) malloc(sizeof(MsgInfo)); + MsgInfo *_msg = (MsgInfo *) malloc(sizeof(MsgInfo)); if (!_msg) { LOG_SEVERE("malloc failed on %s\n", __func__); return false; @@ -88,7 +87,7 @@ bool send_to_vmodem(const uint32_t route, char *data, const uint32_t len) qemu_mutex_unlock(&vio_vmodem->mutex); left -= size; - count ++; + count++; } qemu_bh_schedule(vio_vmodem->bh); @@ -112,11 +111,11 @@ static void flush_vmodem_recv_queue(void) qemu_mutex_lock(&vio_vmodem->mutex); - while (!QTAILQ_EMPTY(&vmodem_recv_msg_queue)) - { + while (!QTAILQ_EMPTY(&vmodem_recv_msg_queue)) { MsgInfo *msginfo = QTAILQ_FIRST(&vmodem_recv_msg_queue); - if (!msginfo) + if (!msginfo) { break; + } VirtQueueElement elem; index = virtqueue_pop(vio_vmodem->rvq, &elem); @@ -131,8 +130,9 @@ static void flush_vmodem_recv_queue(void) virtio_notify(&vio_vmodem->vdev, vio_vmodem->rvq); QTAILQ_REMOVE(&vmodem_recv_msg_queue, msginfo, next); - if (msginfo) + if (msginfo) { free(msginfo); + } } qemu_mutex_unlock(&vio_vmodem->mutex); } @@ -191,7 +191,7 @@ static void virtio_vmodem_realize(DeviceState *dev, Error **errp) return; } - virtio_init(vdev, TYPE_VIRTIO_MARU_VMODEM, VIRTIO_ID_MARU_VMODEM, 0); //VMODEM_DEVICE_NAME + virtio_init(vdev, TYPE_VIRTIO_MARU_VMODEM, VIRTIO_ID_MARU_VMODEM, 0); /* VMODEM_DEVICE_NAME */ qemu_mutex_init(&vio_vmodem->mutex); vio_vmodem->rvq = virtio_add_queue(&vio_vmodem->vdev, 256, virtio_vmodem_recv); diff --git a/tizen/src/hw/virtio/maru_virtio_vmodem.h b/tizen/src/hw/virtio/maru_virtio_vmodem.h index 438e32fc38..64cc11e0e0 100644 --- a/tizen/src/hw/virtio/maru_virtio_vmodem.h +++ b/tizen/src/hw/virtio/maru_virtio_vmodem.h @@ -37,7 +37,7 @@ extern "C" { #include "hw/virtio/virtio.h" -typedef struct VirtIOVirtualModem{ +typedef struct VirtIOVirtualModem { VirtIODevice vdev; VirtQueue *rvq; VirtQueue *svq; diff --git a/tizen/src/util/device_hotplug.c b/tizen/src/util/device_hotplug.c index 2965169f31..55436e4be6 100644 --- a/tizen/src/util/device_hotplug.c +++ b/tizen/src/util/device_hotplug.c @@ -55,7 +55,7 @@ struct maru_device_hotplug { char *opaque; int command; - // FIXME: Should we query device every time ?? + /* FIXME: Should we query device every time ?? */ bool host_keyboard_attached; bool sdcard_attached; }; @@ -99,7 +99,7 @@ static bool do_sdcard_attach(const char * const file) gchar *sdcard_img = g_path_get_basename(file); gchar *sdcard_device_id = g_strdup_printf("device_id_%s", sdcard_img); gchar *sdcard_drive_id = g_strdup_printf("drive_id_%s", sdcard_img); - DriveInfo* dinfo = NULL; + DriveInfo *dinfo = NULL; g_free(sdcard_img); @@ -130,7 +130,7 @@ static bool do_sdcard_attach(const char * const file) g_free(sdcard_device_id); g_free(sdcard_drive_id); state->sdcard_attached = true; - make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, + make_send_device_ntf((char *)MSG_TYPE_SDCARD, GROUP_SDCARD, ACT_SDCARD_ATTACH, g_path_get_basename(file)); return true; } @@ -145,7 +145,7 @@ static bool do_sdcard_detach(const char * const file) QDECREF(qdict); state->sdcard_attached = false; - make_send_device_ntf((char*)MSG_TYPE_SDCARD, GROUP_SDCARD, + make_send_device_ntf((char *)MSG_TYPE_SDCARD, GROUP_SDCARD, ACT_SDCARD_DETACH, g_path_get_basename(file)); g_free(sdcard_drive_id); @@ -157,10 +157,10 @@ static bool do_hds_attach(const char * const id) QemuOpts *fsdev; int ret; QDict *qdict; - char* host; + char *host; int len = 0; - char* guest = NULL; - char emuld_data [OUT_BUF_SIZE]; + char *guest = NULL; + char emuld_data[OUT_BUF_SIZE]; fsdev = qemu_opts_create(qemu_find_opts("fsdev"), id, 0, NULL); @@ -170,7 +170,7 @@ static bool do_hds_attach(const char * const id) LOG_INFO("do_hds_attach - id: %s\n", id); - host = get_host_path_by_id((char*)id); + host = get_host_path_by_id((char *)id); if (host == NULL) { LOG_SEVERE("host path is null\n"); return false; @@ -197,9 +197,9 @@ static bool do_hds_attach(const char * const id) QDECREF(qdict); - // send mount message to emuld + /* send mount message to emuld */ - guest = get_guest_path_by_id((char*)id); + guest = get_guest_path_by_id((char *)id); if (guest == NULL) { LOG_SEVERE("guest path is null\n"); return false; @@ -244,7 +244,7 @@ static void device_hotplug_handler(EventNotifier *e) { event_notifier_test_and_clear(e); - switch(state->command) { + switch (state->command) { case ATTACH_HOST_KEYBOARD: do_host_keyboard_attach(); break; @@ -299,6 +299,6 @@ bool is_host_keyboard_attached(void) bool is_sdcard_attached(void) { - //TODO: support checking multi sdcard attached + /* TODO: support checking multi sdcard attached */ return state->sdcard_attached; } diff --git a/tizen/src/util/device_hotplug.h b/tizen/src/util/device_hotplug.h index 6001ee3b81..538c4013b5 100644 --- a/tizen/src/util/device_hotplug.h +++ b/tizen/src/util/device_hotplug.h @@ -45,4 +45,4 @@ void do_hotplug(int command, void *opaque, size_t size); bool is_host_keyboard_attached(void); bool is_sdcard_attached(void); -#endif // _MARU_DEVICE_HOTPLUG_H_ +#endif /* _MARU_DEVICE_HOTPLUG_H_ */ diff --git a/tizen/src/util/extra_pkgs_install.c b/tizen/src/util/extra_pkgs_install.c index 3ffb0bfb23..8c3a3df00c 100644 --- a/tizen/src/util/extra_pkgs_install.c +++ b/tizen/src/util/extra_pkgs_install.c @@ -43,8 +43,8 @@ MULTI_DEBUG_CHANNEL(qemu, pkgs); -// FIXME: getting add-on path -static char* get_addon_path(void) +/* FIXME: getting add-on path */ +static char *get_addon_path(void) { #ifndef CONFIG_WIN32 const char *parent = "../../../"; @@ -61,7 +61,7 @@ static char* get_addon_path(void) return NULL; } - char *extra_path = (char*)malloc(MAX_PKG_LIST); + char *extra_path = (char *)malloc(MAX_PKG_LIST); if (!extra_path) { LOG_SEVERE("cannot alloc extra_path.\n"); return NULL; @@ -79,7 +79,7 @@ static char* get_addon_path(void) return extra_path; } -static void add_addon_pkgs_name(char *pkgs, char* name) +static void add_addon_pkgs_name(char *pkgs, char *name) { if (strlen(pkgs) == 0) { strcpy(pkgs, name); @@ -88,7 +88,7 @@ static void add_addon_pkgs_name(char *pkgs, char* name) } } -static void send_to_emuld(char* addon, char* pkgs) +static void send_to_emuld(char *addon, char *pkgs) { int ret = 0; int data_len = 0; @@ -100,7 +100,7 @@ static void send_to_emuld(char* addon, char* pkgs) data_len = strlen(data) + 1; int sndlen = 14 + data_len; - char *sndbuf = (char*) g_malloc0(sndlen); + char *sndbuf = (char *) g_malloc0(sndlen); if (!sndbuf) { LOG_SEVERE("Failed to alloc emuld message\n"); return; @@ -126,24 +126,24 @@ static char *strcasestr(const char *haystack, const char *needle) size_t length_haystack; size_t i; - if (!haystack || !needle) + if (!haystack || !needle) { return NULL; + } length_needle = strnlen(needle, MAX_PKG_LIST); length_haystack = strnlen(haystack, MAX_PKG_LIST); - for (i = 0; i < length_haystack; i++) - { + for (i = 0; i < length_haystack; i++) { size_t j; - for (j = 0; j < length_needle; j++) - { + for (j = 0; j < length_needle; j++) { unsigned char c1; unsigned char c2; c1 = haystack[i+j]; c2 = needle[j]; - if (toupper(c1) != toupper(c2)) - goto next; + if (toupper(c1) != toupper(c2)) { + goto next; + } } return (char *) haystack + i; next: @@ -152,7 +152,7 @@ static char *strcasestr(const char *haystack, const char *needle) return NULL; } -#endif // CONFIG_WIN32 +#endif /* CONFIG_WIN32 */ void epi_init(void) { @@ -181,8 +181,8 @@ void epi_init(void) memset(pkg_list, 0, sizeof(pkg_list)); while ((dir_entry = readdir(main_dir))) { - if ((strncasecmp(dir_entry->d_name ,".", 1) != 0) && - (strncasecmp(dir_entry->d_name ,"..", 2) != 0)) { + if ((strncasecmp(dir_entry->d_name, ".", 1) != 0) && + (strncasecmp(dir_entry->d_name, "..", 2) != 0)) { LOG_TRACE("reading addon directory: %s\n", dir_entry->d_name); memset(sub_addon_path, 0, 512); @@ -201,17 +201,20 @@ void epi_init(void) LOG_SEVERE("Add-on sub Directory open failed."); continue; } - while((sub_dir_entry = readdir(sub_dir))) { - if ((strncasecmp(sub_dir_entry->d_name ,".", 1) != 0) && - (strncasecmp(sub_dir_entry->d_name ,"..", 2) != 0)) { - if (strlen(sub_dir_entry->d_name) <= 4) + while ((sub_dir_entry = readdir(sub_dir))) { + if ((strncasecmp(sub_dir_entry->d_name, ".", 1) != 0) && + (strncasecmp(sub_dir_entry->d_name, "..", 2) != 0)) { + if (strlen(sub_dir_entry->d_name) <= 4) { continue; + } ext = &sub_dir_entry->d_name[strlen(sub_dir_entry->d_name) - 4]; - if (strcmp(EXT_RPM, ext)) + if (strcmp(EXT_RPM, ext)) { continue; - if (strcasestr(pkg_list, sub_dir_entry->d_name)) + } + if (strcasestr(pkg_list, sub_dir_entry->d_name)) { continue; + } pkg_count++; add_addon_pkgs_name(pkgs, sub_dir_entry->d_name); @@ -225,7 +228,7 @@ void epi_init(void) if (pkg_count == 0) { LOG_INFO("pkgs addon %s is empty. skip!\n", addon); } else { - // send to emuld + /* send to emuld */ send_to_emuld(addon, pkgs); } diff --git a/tizen/src/util/extra_pkgs_install.h b/tizen/src/util/extra_pkgs_install.h index 8b02e4bb61..95db8f896f 100644 --- a/tizen/src/util/extra_pkgs_install.h +++ b/tizen/src/util/extra_pkgs_install.h @@ -44,4 +44,4 @@ void epi_init(void); -#endif // _EXTRA_PKGS_INSTALL_ +#endif /* _EXTRA_PKGS_INSTALL_ */ diff --git a/tizen/src/util/hds.c b/tizen/src/util/hds.c index 0e457484b0..ede3150e17 100644 --- a/tizen/src/util/hds.c +++ b/tizen/src/util/hds.c @@ -34,8 +34,10 @@ MULTI_DEBUG_CHANNEL(qemu, hds); -// TODO: currently it is used as a single operation. -// But, it is needed to add mutex for future +/* + * TODO: currently it is used as a single operation. + * But, it is needed to add mutex for future + */ typedef struct hds_list { bool attached; char *id; @@ -49,12 +51,13 @@ typedef struct hds_list { static QTAILQ_HEAD(hds_listHead, hds_list) lists = QTAILQ_HEAD_INITIALIZER(lists); -static hds_list* find_list(const char* id) +static hds_list *find_list(const char *id) { hds_list *list, *next; - if (id == NULL) + if (id == NULL) { return NULL; + } QTAILQ_FOREACH_SAFE(list, &lists, next, next) { @@ -67,11 +70,11 @@ static hds_list* find_list(const char* id) return NULL; } -static char* find_new_id(void) +static char *find_new_id(void) { int i = 0; hds_list *list; - char id_candidate [MAX_HDS_ID_LEN]; + char id_candidate[MAX_HDS_ID_LEN]; for (i = 0; i < LIMIT_HDS_COUNT ; i++) { snprintf(id_candidate, sizeof(id_candidate), "%s%d", DEFAULT_HDS_TAG_ID, i); @@ -87,9 +90,9 @@ static char* find_new_id(void) return NULL; } -bool add_hds_list(const char* id, const char* host, const char* guest, enum hds_level level) +bool add_hds_list(const char *id, const char *host, const char *guest, enum hds_level level) { - hds_list* list; + hds_list *list; if (id == NULL || host == NULL || guest == NULL) { LOG_SEVERE("wrong param id:%s, host:%s, guest:%s\n", host, guest); @@ -119,9 +122,9 @@ bool add_hds_list(const char* id, const char* host, const char* guest, enum hds_ return true; } -char* new_hds_list(const char* host, const char* guest, enum hds_level level) +char *new_hds_list(const char *host, const char *guest, enum hds_level level) { - char* id = find_new_id(); + char *id = find_new_id(); if (id == NULL) { LOG_SEVERE("over the max number of hds count to add hds list.\n"); return NULL; @@ -136,7 +139,7 @@ char* new_hds_list(const char* host, const char* guest, enum hds_level level) return id; } -void remove_hds_list(const char* id) +void remove_hds_list(const char *id) { LOG_INFO("remove hds list request: %s\n", id); hds_list *list = find_list(id); @@ -159,7 +162,7 @@ void remove_hds_list(const char* id) g_free(list); } -char* get_host_path_by_id(const char* id) +char *get_host_path_by_id(const char *id) { LOG_TRACE("get_host_path_by_id request: %s\n", id); hds_list *list = find_list(id); @@ -169,7 +172,7 @@ char* get_host_path_by_id(const char* id) return NULL; } -char* get_guest_path_by_id(const char* id) +char *get_guest_path_by_id(const char *id) { LOG_TRACE("get_guest_path_by_id request: %s\n", id); hds_list *list = find_list(id); @@ -179,7 +182,7 @@ char* get_guest_path_by_id(const char* id) return NULL; } -enum hds_level get_hds_level_by_id(const char* id) +enum hds_level get_hds_level_by_id(const char *id) { LOG_TRACE("get_hds_level_by_id request: %s\n", id); hds_list *list = find_list(id); @@ -189,7 +192,7 @@ enum hds_level get_hds_level_by_id(const char* id) return hds_level_normal; } -bool is_hds_attached(const char* id) +bool is_hds_attached(const char *id) { hds_list *list = find_list(id); if (list == NULL) { @@ -199,7 +202,7 @@ bool is_hds_attached(const char* id) return list->attached; } -void set_hds_attached(const char* id, bool attached) +void set_hds_attached(const char *id, bool attached) { hds_list *list = find_list(id); if (list == NULL) { @@ -210,7 +213,7 @@ void set_hds_attached(const char* id, bool attached) list->attached = attached; } -bool hds_is_host_path_used(const char* path) +bool hds_is_host_path_used(const char *path) { hds_list *list, *next; @@ -225,7 +228,7 @@ bool hds_is_host_path_used(const char* path) return false; } -bool hds_is_guest_path_used(const char* path) +bool hds_is_guest_path_used(const char *path) { hds_list *list, *next; @@ -240,10 +243,10 @@ bool hds_is_guest_path_used(const char* path) return false; } -char* get_hds_lists(void) +char *get_hds_lists(void) { hds_list *list, *next; - char hds [MAX_HDS_LIST_LEN]; + char hds[MAX_HDS_LIST_LEN]; int hds_size = 0; int list_len = MAX_HDS_LIST_LEN; char *list_hds = g_malloc0(list_len); diff --git a/tizen/src/util/hds.h b/tizen/src/util/hds.h index e2e21f6069..1424489b12 100644 --- a/tizen/src/util/hds.h +++ b/tizen/src/util/hds.h @@ -44,23 +44,23 @@ enum hds_level { hds_level_hidden }; -bool add_hds_list(const char* id, const char* host, const char* guest, enum hds_level level); -char* new_hds_list(const char* host, const char* guest, enum hds_level level); -void remove_hds_list(const char* id); +bool add_hds_list(const char *id, const char *host, const char *guest, enum hds_level level); +char *new_hds_list(const char *host, const char *guest, enum hds_level level); +void remove_hds_list(const char *id); -char* get_host_path_by_id(const char* id); -char* get_guest_path_by_id(const char* id); -enum hds_level get_hds_level_by_id(const char* id); +char *get_host_path_by_id(const char *id); +char *get_guest_path_by_id(const char *id); +enum hds_level get_hds_level_by_id(const char *id); -bool is_hds_attached(const char* id); -void set_hds_attached(const char* id, bool attached); +bool is_hds_attached(const char *id); +void set_hds_attached(const char *id, bool attached); -bool hds_is_host_path_used(const char* path); -bool hds_is_guest_path_used(const char* path); +bool hds_is_host_path_used(const char *path); +bool hds_is_guest_path_used(const char *path); -char* get_hds_lists(void); +char *get_hds_lists(void); int hds_get_pci_available_slot_num(void); int hds_get_num_hidden_conn(void); -#endif // _HDS_ +#endif /* _HDS_ */