diff options
author | Taesoo Jun <steve.jun@samsung.com> | 2017-09-12 18:04:07 +0900 |
---|---|---|
committer | Taesoo Jun <steve.jun@samsung.com> | 2017-09-12 18:04:07 +0900 |
commit | e3f424e3dbf8df1e567f200e7eeca8c0a43184cc (patch) | |
tree | 03eae457a3d070aeb83e10a928935a4a1db876df | |
parent | 15a9f8c467c782ff29f2864f031833e2a517f0d1 (diff) | |
download | serial-e3f424e3dbf8df1e567f200e7eeca8c0a43184cc.tar.gz serial-e3f424e3dbf8df1e567f200e7eeca8c0a43184cc.tar.bz2 serial-e3f424e3dbf8df1e567f200e7eeca8c0a43184cc.zip |
[Fix] Coding Rule - src/serial.csubmit/tizen/20170913.231011accepted/tizen/unified/20170914.065547
Change-Id: I4854834043a52a4ab1a06d3693592afcd7371980
-rw-r--r-- | src/serial.c | 100 |
1 files changed, 37 insertions, 63 deletions
diff --git a/src/serial.c b/src/serial.c index 08d63d6..1772bcc 100644 --- a/src/serial.c +++ b/src/serial.c @@ -46,14 +46,13 @@ DBusConnection *dbus_connection = NULL; - /* * Internal Functions */ -static gboolean __g_io_client_handler(GIOChannel *io, GIOCondition cond, void *data) +static gboolean __g_io_client_handler(GIOChannel * io, GIOCondition cond, void *data) { int fd; - serial_s *pHandle = (serial_s *)data; + serial_s *pHandle = (serial_s *) data; if (pHandle == NULL) return FALSE; @@ -62,16 +61,14 @@ static gboolean __g_io_client_handler(GIOChannel *io, GIOCondition cond, void *d int len = 0; fd = g_io_channel_unix_get_fd(io); len = recv(fd, buffer, SERIAL_BUF_SIZE, 0); - if(len <= 0) { + if (len <= 0) { ERR("Error occured or the peer is shutdownd. [%d]\n", len); - ((serial_state_changed_cb)pHandle->state_handler.callback) - (SERIAL_ERROR_NONE, - SERIAL_STATE_CLOSED, - pHandle->state_handler.user_data); + ((serial_state_changed_cb) pHandle->state_handler.callback) + (SERIAL_ERROR_NONE, SERIAL_STATE_CLOSED, pHandle->state_handler.user_data); return FALSE; } - ((serial_data_received_cb)pHandle->data_handler.callback) + ((serial_data_received_cb) pHandle->data_handler.callback) (buffer, len, pHandle->data_handler.user_data); } return TRUE; @@ -80,15 +77,13 @@ static gboolean __g_io_client_handler(GIOChannel *io, GIOCondition cond, void *d static void __init_client_giochannel(void *data) { GIOChannel *io; - serial_s *pHandle = (serial_s *)data; + serial_s *pHandle = (serial_s *) data; if (pHandle == NULL) return; io = g_io_channel_unix_new(pHandle->client_socket); g_io_channel_set_close_on_unref(io, TRUE); - pHandle->g_watch_id = g_io_add_watch(io, - G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, - __g_io_client_handler, pHandle); + pHandle->g_watch_id = g_io_add_watch(io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, __g_io_client_handler, pHandle); g_io_channel_unref(io); return; } @@ -96,8 +91,8 @@ static void __init_client_giochannel(void *data) static int __connect_to_serial_server(void *data) { int client_socket = -1; - struct sockaddr_un server_addr; - serial_s *pHandle = (serial_s *)data; + struct sockaddr_un server_addr; + serial_s *pHandle = (serial_s *) data; if (pHandle == NULL) return -1; @@ -111,7 +106,7 @@ static int __connect_to_serial_server(void *data) server_addr.sun_family = AF_UNIX; g_strlcpy(server_addr.sun_path, SERIAL_SOCKET_PATH, sizeof(server_addr.sun_path)); - if (connect(client_socket, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) { + if (connect(client_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { ERR("Connect failed\n"); close(client_socket); return -1; @@ -123,9 +118,7 @@ static int __connect_to_serial_server(void *data) return client_socket; } - -static DBusHandlerResult __dbus_event_filter(DBusConnection *sys_conn, - DBusMessage *msg, void *data) +static DBusHandlerResult __dbus_event_filter(DBusConnection * sys_conn, DBusMessage * msg, void *data) { static int socket = -1; const char *path = dbus_message_get_path(msg); @@ -138,33 +131,25 @@ static DBusHandlerResult __dbus_event_filter(DBusConnection *sys_conn, if (dbus_message_is_signal(msg, SERIAL_INTERFACE, "serial_status")) { int res = 0; - dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &res, - DBUS_TYPE_INVALID); + dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &res, DBUS_TYPE_INVALID); - serial_s *pHandle = (serial_s *)data; + serial_s *pHandle = (serial_s *) data; if (res == SERIAL_OPENED) { socket = __connect_to_serial_server(pHandle); if (socket < 0) { - ((serial_state_changed_cb)pHandle->state_handler.callback) - (SERIAL_ERROR_OPERATION_FAILED, - SERIAL_STATE_OPENED, - pHandle->state_handler.user_data); + ((serial_state_changed_cb) pHandle->state_handler.callback) + (SERIAL_ERROR_OPERATION_FAILED, SERIAL_STATE_OPENED, pHandle->state_handler.user_data); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - ((serial_state_changed_cb)pHandle->state_handler.callback) - (SERIAL_ERROR_NONE, - SERIAL_STATE_OPENED, - pHandle->state_handler.user_data); + ((serial_state_changed_cb) pHandle->state_handler.callback) + (SERIAL_ERROR_NONE, SERIAL_STATE_OPENED, pHandle->state_handler.user_data); } else if (res == SERIAL_CLOSED) { if (socket < 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - ((serial_state_changed_cb)pHandle->state_handler.callback) - (SERIAL_ERROR_NONE, - SERIAL_STATE_CLOSED, - pHandle->state_handler.user_data); + ((serial_state_changed_cb) pHandle->state_handler.callback) + (SERIAL_ERROR_NONE, SERIAL_STATE_CLOSED, pHandle->state_handler.user_data); } } else { return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -178,20 +163,16 @@ int __send_serial_ready_done_signal(void) DBusMessage *msg = NULL; const char *res = "OK"; - if(dbus_connection == NULL) + if (dbus_connection == NULL) return SERIAL_ERROR_INVALID_OPERATION; - msg = dbus_message_new_signal("/Network/Serial", - "Capi.Network.Serial", - "ready_for_serial"); + msg = dbus_message_new_signal("/Network/Serial", "Capi.Network.Serial", "ready_for_serial"); if (!msg) { ERR("Unable to allocate D-Bus signal\n"); return SERIAL_ERROR_OPERATION_FAILED; } - if (!dbus_message_append_args(msg, - DBUS_TYPE_STRING, &res, - DBUS_TYPE_INVALID)) { + if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &res, DBUS_TYPE_INVALID)) { ERR("Event sending failed\n"); dbus_message_unref(msg); return SERIAL_ERROR_OPERATION_FAILED; @@ -202,7 +183,6 @@ int __send_serial_ready_done_signal(void) return SERIAL_ERROR_NONE; } - static int __serial_set_state_changed_cb(serial_h serial, void *callback, void *user_data) { if (!serial) { @@ -210,7 +190,7 @@ static int __serial_set_state_changed_cb(serial_h serial, void *callback, void * return SERIAL_ERROR_INVALID_PARAMETER; } - serial_s *pHandle = (serial_s *)serial; + serial_s *pHandle = (serial_s *) serial; if (callback) { pHandle->state_handler.callback = callback; @@ -230,7 +210,7 @@ static int __serial_set_data_received_cb(serial_h serial, void *callback, void * return SERIAL_ERROR_INVALID_PARAMETER; } - serial_s *pHandle = (serial_s *)serial; + serial_s *pHandle = (serial_s *) serial; if (callback) { pHandle->data_handler.callback = callback; @@ -243,13 +223,11 @@ static int __serial_set_data_received_cb(serial_h serial, void *callback, void * return SERIAL_ERROR_NONE; } - - /* * Public Functions */ -int serial_create(serial_h *serial) +int serial_create(serial_h * serial) { DBG("%s\n", __FUNCTION__); @@ -260,17 +238,16 @@ int serial_create(serial_h *serial) if (serial == NULL) return SERIAL_ERROR_INVALID_PARAMETER; - pHandle = (serial_s *)g_try_malloc0(sizeof(serial_s)); + pHandle = (serial_s *) g_try_malloc0(sizeof(serial_s)); if (pHandle == NULL) return SERIAL_ERROR_OUT_OF_MEMORY; -#if !GLIB_CHECK_VERSION (2, 35, 3) - g_type_init (); +#if !GLIB_CHECK_VERSION(2, 35, 3) + g_type_init(); #endif pHandle->client_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (error) { - ERR("Couldn't connect to the System bus[%s]", - error->message); + ERR("Couldn't connect to the System bus[%s]", error->message); g_error_free(error); g_free(pHandle); return SERIAL_ERROR_OPERATION_FAILED; @@ -280,9 +257,7 @@ int serial_create(serial_h *serial) /* Add the filter for network client functions */ dbus_error_init(&dbus_error); dbus_connection_add_filter(dbus_connection, __dbus_event_filter, pHandle, NULL); - dbus_bus_add_match(dbus_connection, - "type=signal,interface=" SERIAL_INTERFACE - ",member=serial_status", &dbus_error); + dbus_bus_add_match(dbus_connection, "type=signal,interface=" SERIAL_INTERFACE ",member=serial_status", &dbus_error); if (dbus_error_is_set(&dbus_error)) { ERR("Fail to add dbus filter signal\n"); dbus_error_free(&dbus_error); @@ -290,12 +265,11 @@ int serial_create(serial_h *serial) return SERIAL_ERROR_OPERATION_FAILED; } - *serial = (serial_h)pHandle; + *serial = (serial_h) pHandle; return SERIAL_ERROR_NONE; } - int serial_open(serial_h serial) { DBG("%s\n", __FUNCTION__); @@ -317,7 +291,7 @@ int serial_close(serial_h serial) return SERIAL_ERROR_INVALID_PARAMETER; } - serial_s *pHandle = (serial_s *)serial; + serial_s *pHandle = (serial_s *) serial; if (pHandle->client_socket > 0) { if (close(pHandle->client_socket) < 0) @@ -340,7 +314,7 @@ int serial_destroy(serial_h serial) return SERIAL_ERROR_INVALID_PARAMETER; } - serial_s *pHandle = (serial_s *)serial; + serial_s *pHandle = (serial_s *) serial; if (dbus_connection != NULL) { dbus_connection_remove_filter(dbus_connection, __dbus_event_filter, pHandle); @@ -375,12 +349,12 @@ int serial_write(serial_h serial, const char *data, int data_length) return SERIAL_ERROR_INVALID_PARAMETER; } int ret; - serial_s *pHandle = (serial_s *)serial; + serial_s *pHandle = (serial_s *) serial; ret = send(pHandle->client_socket, data, data_length, MSG_EOR); if (ret == -1) { - ERR("Send failed. "); - return SERIAL_ERROR_OPERATION_FAILED; + ERR("Send failed. "); + return SERIAL_ERROR_OPERATION_FAILED; } return ret; |