NULL
};
-static int __register_dbus_interface(const char *port_name, bool is_trusted)
+static bool __message_port_register_port(const int local_id, const char *local_port, bool is_trusted, message_port_message_cb callback, void *user_data)
+{
+ message_port_local_port_info_s *mi = (message_port_local_port_info_s *)calloc(1, sizeof(message_port_local_port_info_s));
+ retvm_if(!mi, false, "Malloc failed");
+
+ mi->callback = callback;
+ mi->is_trusted = is_trusted;
+ mi->port_name = strdup(local_port);
+ if (mi->port_name == NULL) {
+/* LCOV_EXCL_START */
+ _LOGE("Malloc failed (%s)", local_port);
+ free(mi);
+ return false;
+/* LCOV_EXCL_STOP */
+ }
+ mi->local_id = local_id;
+ mi->user_data = user_data;
+
+ g_hash_table_insert(__local_port_info, GINT_TO_POINTER(mi->local_id), mi);
+ return true;
+}
+
+static int __register_dbus_interface(const char *port_name,
+ bool is_trusted, message_port_message_cb callback, void *user_data)
{
GDBusNodeInfo *introspection_data = NULL;
int registration_id = 0;
+ int ret = MESSAGE_PORT_ERROR_NONE;
static gchar introspection_prefix[] =
"<node>"
char *introspection_xml = NULL;
int introspection_xml_len = 0;
-
int owner_id = 0;
GError *error = NULL;
char *bus_name = NULL;
/* LCOV_EXCL_STOP */
}
+ snprintf(introspection_xml, introspection_xml_len, "%s%s%s", introspection_prefix, interface_name, introspection_postfix);
+
+ introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
+ if (!introspection_data) {
+ ret = MESSAGE_PORT_ERROR_IO_ERROR;
+ _LOGE("g_dbus_node_info_new_for_xml() is failed.");
+ goto out;
+ }
+
+ registration_id = g_dbus_connection_register_object(gdbus_conn,
+ MESSAGEPORT_OBJECT_PATH, introspection_data->interfaces[0],
+ &interface_vtable, NULL, NULL, NULL);
+
+ _LOGD("registration_id %d", registration_id);
+
+ if (registration_id == 0) {
+ ret = MESSAGE_PORT_ERROR_IO_ERROR;
+ _LOGE("Failed to g_dbus_connection_register_object");
+ goto out;
+ }
+
+ if (!__message_port_register_port(registration_id, port_name, is_trusted,
+ callback, user_data)) {
+ ret = MESSAGE_PORT_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
result = g_dbus_connection_call_sync(
gdbus_conn,
&error);
if (error) {
_LOGE("RequestName fail : %s", error->message);
+ ret = MESSAGE_PORT_ERROR_IO_ERROR;
g_error_free(error);
goto out;
}
if (result == NULL) {
+ ret = MESSAGE_PORT_ERROR_IO_ERROR;
_LOGE("fail to get name NULL");
goto out;
}
g_variant_get(result, "(u)", &owner_id);
if (owner_id == 0) {
+ ret = MESSAGE_PORT_ERROR_IO_ERROR;
_LOGE("Acquiring the own name is failed");
goto out;
}
- _LOGD("Acquiring the own name : %d", owner_id);
-
- snprintf(introspection_xml, introspection_xml_len, "%s%s%s", introspection_prefix, interface_name, introspection_postfix);
-
- introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
- if (!introspection_data) {
- _LOGE("g_dbus_node_info_new_for_xml() is failed.");
- goto out;
- }
-
- registration_id = g_dbus_connection_register_object(gdbus_conn,
- MESSAGEPORT_OBJECT_PATH, introspection_data->interfaces[0],
- &interface_vtable, NULL, NULL, NULL);
-
- _LOGD("registration_id %d", registration_id);
-
- if (registration_id == 0) {
- _LOGE("Failed to g_dbus_connection_register_object");
- goto out;
- }
+ _LOGI("Acquiring the own name : %d", owner_id);
out:
if (introspection_data)
if (result)
g_variant_unref(result);
-
- return registration_id;
-}
-
-static bool __message_port_register_port(const int local_id, const char *local_port, bool is_trusted, message_port_message_cb callback, void *user_data)
-{
- message_port_local_port_info_s *mi = (message_port_local_port_info_s *)calloc(1, sizeof(message_port_local_port_info_s));
- retvm_if(!mi, false, "Malloc failed");
-
- mi->callback = callback;
- mi->is_trusted = is_trusted;
- mi->port_name = strdup(local_port);
- if (mi->port_name == NULL) {
-/* LCOV_EXCL_START */
- _LOGE("Malloc failed (%s)", local_port);
- free(mi);
- return false;
-/* LCOV_EXCL_STOP */
+ if (ret != MESSAGE_PORT_ERROR_NONE) {
+ if (registration_id != 0)
+ g_hash_table_remove(__local_port_info, GINT_TO_POINTER(registration_id));
+ registration_id = ret;
}
- mi->local_id = local_id;
- mi->user_data = user_data;
- g_hash_table_insert(__local_port_info, GINT_TO_POINTER(mi->local_id), mi);
- return true;
+ return registration_id;
}
int get_local_port_info(int id, message_port_local_port_info_s **info)
return local_id;
}
- local_id = __register_dbus_interface(local_port, is_trusted);
+ local_id = __register_dbus_interface(local_port, is_trusted, callback, user_data);
if (local_id < 1) {
_LOGE("register_dbus_interface fail !!");
- return MESSAGE_PORT_ERROR_OUT_OF_MEMORY;
}
- if (!__message_port_register_port(local_id, local_port, is_trusted, callback, user_data))
- return MESSAGE_PORT_ERROR_OUT_OF_MEMORY;
-
return local_id;
}