Apply tizen coding rules.
[platform/core/appfw/message-port.git] / src / message_port.c
index 827c446..3107b09 100644 (file)
@@ -34,13 +34,10 @@ static pthread_mutex_t __mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static void do_callback(message_port_message_cb callback, int local_port_id, const char *remote_app_id, const char *remote_port, bool trusted_remote_port, bundle *message, void *user_data)
 {
-       if (callback)
-       {
+       if (callback) {
                callback(local_port_id, remote_app_id, remote_port, trusted_remote_port, message, user_data);
                bundle_free(message);
-       }
-       else
-       {
+       } else {
                _LOGI("Ignored");
        }
 }
@@ -61,67 +58,62 @@ static void trusted_message_dispatcher(int trusted_local_port_id, const char *re
 
 int message_port_register_local_port(const char *local_port, message_port_message_cb callback, void *user_data)
 {
-       if (local_port == NULL || callback == NULL)
-       {
+       if (local_port == NULL || callback == NULL) {
                _LOGE("[MESSAGE_PORT_ERROR_INVALID_PARAMETER] NULL value is not allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
        }
 
        int local_port_id = messageport_register_local_port(local_port, message_dispatcher);
-       if (local_port_id > 0)
-       {
+       if (local_port_id > 0) {
                _SECURE_LOGI("Register local port ID (%d).", local_port_id);
 
-               if (__listeners == NULL) {
+               if (__listeners == NULL)
                        __listeners = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
-               }
+
                pthread_mutex_lock(&__mutex);
                message_port_callback_item *item =
                        (message_port_callback_item *)g_hash_table_lookup(__listeners, GINT_TO_POINTER(local_port_id));
                if (item == NULL) {
                        item = (message_port_callback_item *)calloc(1, sizeof(message_port_callback_item));
-                       if (item == NULL) {
+                       if (item == NULL)
                                return MESSAGE_PORT_ERROR_OUT_OF_MEMORY;
-                       }
+
                        g_hash_table_insert(__listeners, GINT_TO_POINTER(local_port_id), item);
                }
 
-
                item->callback = callback;
                item->user_data = user_data;
                pthread_mutex_unlock(&__mutex);
 
        } else {
                _SECURE_LOGI("Register local port fail (%d).", local_port_id);
-
        }
+
        return convert_to_tizen_error((messageport_error_e)local_port_id);
 }
 
 int message_port_register_trusted_local_port(const char *local_port, message_port_trusted_message_cb callback, void *user_data)
 {
-       if (local_port == NULL || callback == NULL)
-       {
+       if (local_port == NULL || callback == NULL) {
                _LOGE("[MESSAGE_PORT_ERROR_INVALID_PARAMETER] NULL value is not allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
        }
 
        int trusted_local_port_id = messageport_register_trusted_local_port(local_port, trusted_message_dispatcher);
-       if (trusted_local_port_id > 0)
-       {
+       if (trusted_local_port_id > 0) {
                _SECURE_LOGI("Register trusted local port ID (%d).", trusted_local_port_id);
 
-               if (__trusted_listeners == NULL) {
+               if (__trusted_listeners == NULL)
                        __trusted_listeners = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
-               }
+
                pthread_mutex_lock(&__mutex);
                message_port_callback_item *item =
                        (message_port_callback_item *)g_hash_table_lookup(__trusted_listeners, GINT_TO_POINTER(trusted_local_port_id));
                if (item == NULL) {
                        item = (message_port_callback_item *)calloc(1, sizeof(message_port_callback_item));
-                       if (item == NULL) {
+                       if (item == NULL)
                                return MESSAGE_PORT_ERROR_OUT_OF_MEMORY;
-                       }
+
                        g_hash_table_insert(__trusted_listeners, GINT_TO_POINTER(trusted_local_port_id), item);
                }
 
@@ -130,7 +122,6 @@ int message_port_register_trusted_local_port(const char *local_port, message_por
                pthread_mutex_unlock(&__mutex);
        } else {
                _SECURE_LOGI("Register trusted local port fail (%d).", trusted_local_port_id);
-
        }
 
        return convert_to_tizen_error((messageport_error_e)trusted_local_port_id);
@@ -139,12 +130,10 @@ int message_port_register_trusted_local_port(const char *local_port, message_por
 int message_port_unregister_local_port(int local_port_id)
 {
        int res = MESSAGE_PORT_ERROR_NONE;
-       if (local_port_id <= 0)
-       {
+       if (local_port_id <= 0) {
                _LOGE("[MESSAGEPORT_ERROR_INVALID_PARAMETER] Neither 0 nor negative value is allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
-       }
-       else {
+       } else {
                res = messageport_unregister_local_port(local_port_id, false);
                g_hash_table_remove(__listeners, GINT_TO_POINTER(local_port_id));
        }
@@ -155,12 +144,10 @@ int message_port_unregister_trusted_local_port(int trusted_local_port_id)
 {
 
        int res = MESSAGE_PORT_ERROR_NONE;
-       if (trusted_local_port_id <= 0)
-       {
+       if (trusted_local_port_id <= 0) {
                _LOGE("[MESSAGEPORT_ERROR_INVALID_PARAMETER] Neither 0 nor negative value is allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
-       }
-       else {
+       } else {
                res = messageport_unregister_local_port(trusted_local_port_id, true);
                g_hash_table_remove(__trusted_listeners, GINT_TO_POINTER(trusted_local_port_id));
        }
@@ -170,8 +157,7 @@ int message_port_unregister_trusted_local_port(int trusted_local_port_id)
 
 int message_port_check_remote_port(const char* remote_app_id, const char *remote_port, bool* exist)
 {
-       if (remote_app_id == NULL || remote_port == NULL)
-       {
+       if (remote_app_id == NULL || remote_port == NULL) {
                _LOGE("[MESSAGE_PORT_ERROR_INVALID_PARAMETER] NULL value is not allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
        }
@@ -181,8 +167,7 @@ int message_port_check_remote_port(const char* remote_app_id, const char *remote
 
 int message_port_check_trusted_remote_port(const char* remote_app_id, const char *remote_port, bool *exist)
 {
-       if (remote_app_id == NULL || remote_port == NULL)
-       {
+       if (remote_app_id == NULL || remote_port == NULL) {
                _LOGE("[MESSAGE_PORT_ERROR_INVALID_PARAMETER] NULL value is not allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
        }
@@ -192,8 +177,7 @@ int message_port_check_trusted_remote_port(const char* remote_app_id, const char
 
 int message_port_send_message(const char *remote_app_id, const char *remote_port, bundle *message)
 {
-       if (remote_app_id == NULL || remote_port == NULL || message == NULL)
-       {
+       if (remote_app_id == NULL || remote_port == NULL || message == NULL) {
                _LOGE("[MESSAGE_PORT_ERROR_INVALID_PARAMETER] NULL value is not allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
        }
@@ -202,8 +186,7 @@ int message_port_send_message(const char *remote_app_id, const char *remote_port
 
 int message_port_send_trusted_message(const char *remote_app_id, const char *remote_port, bundle *message)
 {
-       if (remote_app_id == NULL || remote_port == NULL || message == NULL)
-       {
+       if (remote_app_id == NULL || remote_port == NULL || message == NULL) {
                _LOGE("[MESSAGE_PORT_ERROR_INVALID_PARAMETER] NULL value is not allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
        }
@@ -212,31 +195,25 @@ int message_port_send_trusted_message(const char *remote_app_id, const char *rem
 
 int message_port_send_message_with_local_port(const char *remote_app_id, const char *remote_port, bundle *message, int local_port_id)
 {
-       if (remote_app_id == NULL || remote_port == NULL || message == NULL)
-       {
+       if (remote_app_id == NULL || remote_port == NULL || message == NULL) {
                _LOGE("[MESSAGE_PORT_ERROR_INVALID_PARAMETER] NULL value is not allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
-       }
-       else if (local_port_id <= 0)
-       {
+       } else if (local_port_id <= 0) {
                _LOGE("[MESSAGEPORT_ERROR_INVALID_PARAMETER] Neither 0 nor negative value is allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
-       }
-       else {
+       } else {
 
                message_port_callback_item *item = NULL;
                message_port_callback_item *trusted_item = NULL;
 
-               if (__listeners != NULL) {
+               if (__listeners != NULL)
                        item = (message_port_callback_item *)g_hash_table_lookup(__listeners, GINT_TO_POINTER(local_port_id));
-               }
-               if (item == NULL && __trusted_listeners != NULL) {
+
+               if (item == NULL && __trusted_listeners != NULL)
                        trusted_item = (message_port_callback_item *)g_hash_table_lookup(__trusted_listeners, GINT_TO_POINTER(local_port_id));
 
-               }
 
-               if (item == NULL && trusted_item == NULL)
-               {
+               if (item == NULL && trusted_item == NULL) {
                        _LOGE("[MESSAGE_PORT_ERROR_PORT_NOT_FOUND] The local port ID (%d) is not registered.", local_port_id);
                        return MESSAGE_PORT_ERROR_PORT_NOT_FOUND;
                }
@@ -248,30 +225,23 @@ int message_port_send_message_with_local_port(const char *remote_app_id, const c
 
 int message_port_send_trusted_message_with_local_port(const char* remote_app_id, const char *remote_port, bundle* message, int local_port_id)
 {
-       if (remote_app_id == NULL || remote_port == NULL || message == NULL)
-       {
+       if (remote_app_id == NULL || remote_port == NULL || message == NULL) {
                _LOGE("[MESSAGE_PORT_ERROR_INVALID_PARAMETER] NULL value is not allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
-       }
-       else if (local_port_id <= 0)
-       {
+       } else if (local_port_id <= 0) {
                _LOGE("[MESSAGEPORT_ERROR_INVALID_PARAMETER] Neither 0 nor negative value is allowed.");
                return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
-       }
-       else {
+       } else {
                message_port_callback_item *item = NULL;
                message_port_callback_item *trusted_item = NULL;
 
-               if (__listeners != NULL) {
+               if (__listeners != NULL)
                        item = (message_port_callback_item *)g_hash_table_lookup(__listeners, GINT_TO_POINTER(local_port_id));
-               }
-               if (item == NULL && __trusted_listeners != NULL) {
-                       trusted_item = (message_port_callback_item *)g_hash_table_lookup(__trusted_listeners, GINT_TO_POINTER(local_port_id));
 
-               }
+               if (item == NULL && __trusted_listeners != NULL)
+                       trusted_item = (message_port_callback_item *)g_hash_table_lookup(__trusted_listeners, GINT_TO_POINTER(local_port_id));
 
-               if (item == NULL && trusted_item == NULL)
-               {
+               if (item == NULL && trusted_item == NULL) {
                        _LOGE("[MESSAGE_PORT_ERROR_PORT_NOT_FOUND] The local port ID (%d) is not registered.", local_port_id);
                        return MESSAGE_PORT_ERROR_PORT_NOT_FOUND;
                }