static void message_dispatcher(int local_port_id, const char *remote_app_id, const char *remote_port, bool trusted_remote_port, bundle *message, void *user_data)
{
- message_port_callback_item *item =
- (message_port_callback_item *)g_hash_table_lookup(__listeners, GINT_TO_POINTER(local_port_id));
- do_callback(item->callback, local_port_id, remote_app_id, remote_port, trusted_remote_port, message, item->user_data);
+ message_port_callback_item *item = NULL;
+ if (__listeners == NULL)
+ return;
+ item = (message_port_callback_item *)g_hash_table_lookup(__listeners, GINT_TO_POINTER(local_port_id));
+ if (item != NULL)
+ do_callback(item->callback, local_port_id, remote_app_id, remote_port, trusted_remote_port, message, item->user_data);
}
static void trusted_message_dispatcher(int trusted_local_port_id, const char *remote_app_id, const char *remote_port, bool trusted_remote_port, bundle *message, void *user_data)
{
- message_port_callback_item *item =
- (message_port_callback_item *)g_hash_table_lookup(__trusted_listeners, GINT_TO_POINTER(trusted_local_port_id));
- do_callback(item->callback, trusted_local_port_id, remote_app_id, remote_port, trusted_remote_port, message, item->user_data);
+ message_port_callback_item *item = NULL;
+
+ if (__trusted_listeners == NULL)
+ return;
+ item = (message_port_callback_item *)g_hash_table_lookup(__trusted_listeners, GINT_TO_POINTER(trusted_local_port_id));
+ if (item != NULL)
+ do_callback(item->callback, trusted_local_port_id, remote_app_id, remote_port, trusted_remote_port, message, item->user_data);
}
int message_port_register_local_port(const char *local_port, message_port_message_cb callback, void *user_data)
int message_port_send_message(const char *remote_app_id, const char *remote_port, bundle *message)
{
+ int ret;
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;
}
- return convert_to_tizen_error((messageport_error_e)messageport_send_message(remote_app_id, remote_port, message));
+
+ _SECURE_LOGI("Send a message to (%s):(%s).", remote_app_id, remote_port);
+ pthread_mutex_lock(&__mutex);
+ ret = messageport_send_message(remote_app_id, remote_port, message);
+ pthread_mutex_unlock(&__mutex);
+
+ return convert_to_tizen_error((messageport_error_e)ret);
}
int message_port_send_trusted_message(const char *remote_app_id, const char *remote_port, bundle *message)
{
+ int ret;
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;
}
- return convert_to_tizen_error((messageport_error_e)messageport_send_trusted_message(remote_app_id, remote_port, message));
+ _SECURE_LOGI("Send a trusted message to (%s):(%s).", remote_app_id, remote_port);
+
+ pthread_mutex_lock(&__mutex);
+ ret = messageport_send_trusted_message(remote_app_id, remote_port, message);
+ pthread_mutex_unlock(&__mutex);
+
+ return convert_to_tizen_error((messageport_error_e)ret);
}
int message_port_send_message_with_local_port(const char *remote_app_id, const char *remote_port, bundle *message, int local_port_id)
{
+ int ret;
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;
}
_SECURE_LOGI("Send a message to (%s):(%s) and listen at the local port ID (%d).", remote_app_id, remote_port, local_port_id);
- return convert_to_tizen_error((messageport_error_e)messageport_send_bidirectional_message(local_port_id, remote_app_id, remote_port, message));
+ pthread_mutex_lock(&__mutex);
+ ret = messageport_send_bidirectional_message(local_port_id, remote_app_id, remote_port, message);
+ pthread_mutex_unlock(&__mutex);
+
+ return convert_to_tizen_error((messageport_error_e)ret);
}
int message_port_send_trusted_message_with_local_port(const char *remote_app_id, const char *remote_port, bundle *message, int local_port_id)
{
+ int ret;
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;
}
_SECURE_LOGI("Send a trusted message to (%s):(%s) and listen at the local port ID (%d).", remote_app_id, remote_port, local_port_id);
- return convert_to_tizen_error((messageport_error_e)messageport_send_bidirectional_trusted_message(local_port_id, remote_app_id, remote_port, message));
+ pthread_mutex_lock(&__mutex);
+ ret = messageport_send_bidirectional_trusted_message(local_port_id, remote_app_id, remote_port, message);
+ pthread_mutex_unlock(&__mutex);
+
+ return convert_to_tizen_error((messageport_error_e)ret);
}