DBusConnection *dbus_conn;
char *service_name;
char *base_path;
+ char *root_path;
guint watch;
guint added_watch;
guint removed_watch;
void *signal_data;
GDBusProxyFunction proxy_added;
GDBusProxyFunction proxy_removed;
+#if !defined TIZEN_EXT
GDBusClientFunction ready;
void *ready_data;
+#endif
GDBusPropertyFunction property_changed;
void *user_data;
GList *proxy_list;
return TRUE;
}
+#if !defined TIZEN_EXT
gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
const char *name, int type, const void *value,
size_t size, GDBusResultFunction function,
return TRUE;
}
+#endif
struct method_call_data {
GDBusReturnFunction function;
if (client == NULL)
return FALSE;
- data = g_try_new0(struct method_call_data, 1);
- if (data == NULL)
- return FALSE;
-
- data->function = function;
- data->user_data = user_data;
- data->destroy = destroy;
-
msg = dbus_message_new_method_call(client->service_name,
proxy->obj_path, proxy->interface, method);
- if (msg == NULL) {
- g_free(data);
+ if (msg == NULL)
return FALSE;
- }
if (setup) {
DBusMessageIter iter;
dbus_message_iter_init_append(msg, &iter);
- setup(&iter, data->user_data);
+ setup(&iter, user_data);
}
+ if (!function)
+ return g_dbus_send_message(client->dbus_conn, msg);
+
+ data = g_try_new0(struct method_call_data, 1);
+ if (data == NULL)
+ return FALSE;
+
+ data->function = function;
+ data->user_data = user_data;
+ data->destroy = destroy;
+
+
if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
&call, METHOD_CALL_TIMEOUT) == FALSE) {
dbus_message_unref(msg);
dbus_message_iter_next(&dict);
}
-
- if (client->ready)
- client->ready(client, client->ready_data);
}
static void get_managed_objects_reply(DBusPendingCall *call, void *user_data)
parse_managed_objects(client, reply);
done:
+#if !defined TIZEN_EXT
+ if (client->ready)
+ client->ready(client, client->ready_data);
+#endif
+
dbus_message_unref(reply);
dbus_pending_call_unref(client->get_objects_call);
{
DBusMessage *msg;
- if (!client->proxy_added && !client->proxy_removed) {
+ if (!client->connected)
+ return;
+
+ if ((!client->proxy_added && !client->proxy_removed) ||
+ !client->root_path) {
refresh_properties(client);
return;
}
if (client->get_objects_call != NULL)
return;
- msg = dbus_message_new_method_call(client->service_name, "/",
- DBUS_INTERFACE_DBUS ".ObjectManager",
- "GetManagedObjects");
+ msg = dbus_message_new_method_call(client->service_name,
+ client->root_path,
+ DBUS_INTERFACE_OBJECT_MANAGER,
+ "GetManagedObjects");
if (msg == NULL)
return;
g_dbus_client_ref(client);
+ client->connected = TRUE;
+
if (client->connect_func)
client->connect_func(conn, client->connect_data);
get_managed_objects(client);
- client->connected = TRUE;
-
g_dbus_client_unref(client);
}
{
GDBusClient *client = user_data;
+ client->connected = FALSE;
+
g_list_free_full(client->proxy_list, proxy_free);
client->proxy_list = NULL;
- if (client->disconn_func) {
+ if (client->disconn_func)
client->disconn_func(conn, client->disconn_data);
- client->connected = FALSE;
- }
}
static DBusHandlerResult message_filter(DBusConnection *connection,
GDBusClient *g_dbus_client_new(DBusConnection *connection,
const char *service, const char *path)
{
+ return g_dbus_client_new_full(connection, service, path, "/");
+}
+
+GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
+ const char *service,
+ const char *path,
+ const char *root_path)
+{
GDBusClient *client;
unsigned int i;
- if (connection == NULL)
+ if (!connection || !service)
return NULL;
client = g_try_new0(GDBusClient, 1);
client->dbus_conn = dbus_connection_ref(connection);
client->service_name = g_strdup(service);
client->base_path = g_strdup(path);
+ client->root_path = g_strdup(root_path);
client->connected = FALSE;
client->match_rules = g_ptr_array_sized_new(1);
service_connect,
service_disconnect,
client, NULL);
+
+ if (!root_path)
+ return g_dbus_client_ref(client);
+
client->added_watch = g_dbus_add_signal_watch(connection, service,
- "/",
+ client->root_path,
DBUS_INTERFACE_OBJECT_MANAGER,
"InterfacesAdded",
interfaces_added,
client, NULL);
client->removed_watch = g_dbus_add_signal_watch(connection, service,
- "/",
+ client->root_path,
DBUS_INTERFACE_OBJECT_MANAGER,
"InterfacesRemoved",
interfaces_removed,
g_free(client->service_name);
g_free(client->base_path);
+ g_free(client->root_path);
g_free(client);
}
return TRUE;
}
+#if !defined TIZEN_EXT
gboolean g_dbus_client_set_ready_watch(GDBusClient *client,
GDBusClientFunction ready, void *user_data)
{
return TRUE;
}
+#endif
gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
GDBusProxyFunction proxy_added,
client->property_changed = property_changed;
client->user_data = user_data;
- get_managed_objects(client);
+ if (proxy_added || proxy_removed || property_changed)
+ get_managed_objects(client);
return TRUE;
}