} while (0)
static bool _initialized = false;
-static GDBusConnection *__gdbus_conn = NULL;
+static GDBusConnection *__gdbus_conn;
static char *__app_id;
-static GHashTable *__local_port_info = NULL;
-static GHashTable *__remote_app_info = NULL;
-static GHashTable *__sender_appid_hash = NULL;
-static GHashTable *__trusted_app_list_hash = NULL;
+static GHashTable *__local_port_info;
+static GHashTable *__remote_app_info;
+static GHashTable *__sender_appid_hash;
+static GHashTable *__trusted_app_list_hash;
+static GHashTable *__callback_info_hash;
static const int MAX_MESSAGE_SIZE = 16 * 1024;
enum __certificate_info_type {
bool exist;
} port_list_info_s;
-static void __callback_info_free(message_port_callback_info_s *callback_info)
+static void __callback_info_free(gpointer data)
{
+ message_port_callback_info_s *callback_info = (message_port_callback_info_s *)data;
GError *error = NULL;
if (callback_info == NULL)
return;
free(callback_info);
}
+static void __callback_info_free_by_info(message_port_callback_info_s *callback_info)
+{
+
+ GList *callback_info_list = g_hash_table_lookup(__callback_info_hash, GUINT_TO_POINTER(callback_info->local_id));
+ GList *find_list;
+
+ if (callback_info_list == NULL)
+ return;
+
+ find_list = g_list_find(callback_info_list, callback_info);
+ if (find_list == NULL)
+ return;
+
+ callback_info_list = g_list_remove_link(callback_info_list, find_list);
+ __callback_info_free(callback_info);
+}
+
+static void __hash_destroy_callback_info(gpointer data)
+{
+
+ GList *callback_list = (GList *)data;
+ if (callback_list != NULL)
+ g_list_free_full(callback_list, __callback_info_free);
+}
+
static char *__get_encoded_name(const char *remote_app_id, const char *port_name, bool is_trusted)
{
if (cond == G_IO_HUP) {
_LOGI("socket G_IO_HUP");
- __callback_info_free(mi);
+ __callback_info_free_by_info(mi);
return FALSE;
} else {
if ((fd = g_io_channel_unix_get_fd(gio)) < 0) {
_LOGE("fail to get fd from io channel");
- __callback_info_free(mi);
+ __callback_info_free_by_info(mi);
return FALSE;
}
if ((pkt = __message_port_recv_raw(fd)) == NULL) {
_LOGE("recv error on SOCKET");
- __callback_info_free(mi);
+ __callback_info_free_by_info(mi);
return FALSE;
}
message_port_local_port_info_s *mi;
int local_reg_id = 0;
message_port_callback_info_s *callback_info;
+ GList *callback_info_list = NULL;
char buf[1024];
GDBusMessage *msg;
return -1;
}
+ callback_info_list = g_hash_table_lookup(__callback_info_hash, GUINT_TO_POINTER(mi->local_id));
+ if (callback_info_list == NULL) {
+ callback_info_list = g_list_append(callback_info_list, callback_info);
+ g_hash_table_insert(__callback_info_hash, GUINT_TO_POINTER(mi->local_id), callback_info_list);
+ } else {
+ callback_info_list = g_list_append(callback_info_list, callback_info);
+ }
}
}
retvm_if(!__trusted_app_list_hash, false, "fail to create __trusted_app_list_hash");
}
+ if (__callback_info_hash == NULL) {
+ __callback_info_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __hash_destroy_callback_info);
+ retvm_if(!__trusted_app_list_hash, false, "fail to create __trusted_app_list_hash");
+ }
+
if (!__dbus_init())
return false;
_initialized = true;
if (mi->is_trusted != trusted_port)
return MESSAGEPORT_ERROR_INVALID_PARAMETER;
+ g_hash_table_remove(__callback_info_hash, GUINT_TO_POINTER(local_port_id));
+
bus_name = __get_encoded_name(__app_id, mi->port_name, mi->is_trusted);
if (bus_name == NULL)
return MESSAGEPORT_ERROR_OUT_OF_MEMORY;