dbus_object_handle_s * _dbus_handle_lookup_object(GList *list_obj, const char *obj_path);
dbus_interface_s * _dbus_handle_lookup_interface(GList *list_iface, const char *iface_name);
dbus_method_s * _dbus_handle_lookup_method(GList *list_methods, const char *method_name);
-static GVariant* _append_variant(const char *signature, const char *param[]);
dbus_interface_s *_iface_u_to_s(const dbus_interface_u *iface_u)
{
return TRUE;
}
-/* todo: looks like garbage... */
-static GVariant* _append_variant(const char *signature, const char *param[])
-{
- char *ch;
- int i;
- int pi;
- int int_type;
- gboolean bool_type;
- unsigned long long int64_type;
- GVariant *ret;
- int len;
- char container[255];// The maximum length of a signature is 255.
- const char *sig = signature;
- GVariantBuilder *builder = NULL;
-
- if (!signature || !param)
- return 0;
-
- /* workaround for user fault "(i) != i" but we treat this as same signature */
- /* G_VARIANT_TYPE("si") return NULL */
- /* todo: actually user have to use correct signature */
- if (!_check_type_string_is_container(signature)) {
- snprintf(container, sizeof(container) - 1, "(%s)", signature);
- sig = container;
- }
- if (!g_variant_type_is_container(G_VARIANT_TYPE(sig)))
- _E("signature (%s) is not container type", signature);
-
- builder = g_variant_builder_new(G_VARIANT_TYPE(sig));
- len = strlen(sig);
- pi = 0;
- for (ch = (char *)sig, i = 0; i < len; ++i, ++ch) {
- switch (*ch) {
- case '(':
- case ')':
- continue;
- case 'b':
- bool_type = (atoi(param[pi++]) == 0 ? FALSE : TRUE);
- g_variant_builder_add(builder, "b", bool_type);
- break;
- case 'i':
- int_type = atoi(param[pi++]);
- g_variant_builder_add(builder, "i", int_type);
- break;
- case 'u':
- int_type = strtoul(param[pi++], NULL, 10);
- g_variant_builder_add(builder, "u", int_type);
- break;
- case 't':
- int64_type = atoll(param[pi++]);
- g_variant_builder_add(builder, "t", int64_type);
- break;
- case 's':
- g_variant_builder_add(builder, "s", param[pi++]);
- break;
- case 'a':
- ++ch;
- switch (*ch) {
- case 'y':
- g_variant_builder_add(builder, "^ay", param[pi++]);
- ++i;
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- }
- ret = g_variant_builder_end(builder);
- g_variant_builder_clear(builder);
- g_variant_builder_unref(builder);
-
- return ret;
-}
-
int dbus_handle_emit_dbus_signal(const char *dest,
const char *path,
const char *iface,
return g_unix_fd_list_steal_fds(fd_list, NULL);
}
-GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest,
- const char *path,
- const char *iface,
- const char *method,
- const char *signature,
- const char *param[],
- int *in_fdlist,
- int in_size,
- int **out_fdlist,
- int *out_size)
-{
- GError *err = NULL;
- GVariant * var = NULL;
- GVariant * ret = NULL;
- dbus_handle_s *dh = NULL;
- GUnixFDList *g_infdlist = NULL;
- GUnixFDList *g_outfdlist = NULL;
-
- if (!dest || !path || !iface || !method) {
- _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
- return NULL;
- }
- if (in_fdlist && in_size == 0) {
- _E("wrong in_fdlist is not null but in_size is 0");
- return NULL;
- }
-
- dh = _dbus_handle_get_default_connection();
- if (!dh) {
- _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
- return NULL;
- }
-
- if (signature && param)
- var = _append_variant(signature, param);
-
- /* append fd */
- if (in_fdlist) {
- g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size);
- if (!g_infdlist) {
- _E("failed to g_unix_fd_list_new_from_array\n");
- goto out;
- }
- //g_infdlist = g_unix_fd_list_new();
- //if (g_unix_fd_list_append(g_infdlist, in_fdlist[0], &err) < 0) {
- }
-
- ret = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn,
- dest, path, iface, method,
- var, NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- g_infdlist, &g_outfdlist,
- NULL,
- &err);
- if (!ret || err) {
- if (err) {
- _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:%s", err->message);
- g_error_free(err);
- } else {
- _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:");
- if (var)
- g_variant_unref(var);
- if (g_infdlist)
- g_object_unref(g_infdlist);
- }
- goto out;
- }
-
- /* fds to out array */
- if (g_outfdlist) {
- *out_size = g_unix_fd_list_get_length(g_outfdlist);
- if (*out_size == 0)
- goto out;
-
- *out_fdlist = g_unix_fd_list_steal_fds(g_outfdlist, NULL);
- }
-
-out:
- if (g_outfdlist)
- g_object_unref(g_outfdlist);
-
- return ret;
-}
-
GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest,
const char *path,
const char *iface,
return ret;
}
-int dbus_handle_method_sync(const char *dest,
- const char *path,
- const char *iface,
- const char *method,
- const char *signature,
- const char *param[])
-{
- int result;
- gboolean result_bool;
- GVariant *reply = NULL;
- GVariant * var = NULL;
- GError *err = NULL;
- dbus_handle_s *dh = NULL;
-
- if (!dest || !path || !iface || !method) {
- _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
- return -1;
- }
-
- dh = _dbus_handle_get_default_connection();
- if (!dh) {
- _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
- return -ECOMM;
- }
-
- if (signature && param)
- var = _append_variant(signature, param);
-
- reply = g_dbus_connection_call_sync(dh->conn,
- dest, path, iface, method,
- var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err);
- if (!reply || err) {
- if (err) {
- _E("failed to g_dbus_connection_call_sync:%s", err->message);
- g_error_free(err);
- } else {
- _E("failed to g_dbus_connection_call_sync");
- g_variant_unref(var);
- }
- return -ECOMM;
- }
-
- if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) {
- g_variant_get(reply, "(i)", &result);
- } else if (g_strcmp0("(b)", g_variant_get_type_string(reply)) == 0) {
- g_variant_get(reply, "(b)", &result_bool);
- result = (int)result_bool;
- } else {
- result = -ENOMSG;
- }
-
- g_variant_unref(reply);
-
- return result;
-}
-
int dbus_handle_method_sync_var(const char *dest,
const char *path,
const char *iface,
return result;
}
-int dbus_handle_method_sync_timeout(const char *dest,
- const char *path,
- const char *iface,
- const char *method,
- const char *signature,
- const char *param[],
- int timeout)
-{
- dbus_handle_s *dh = NULL;
- GError *err = NULL;
- GVariant * var = NULL;
- GVariant * reply = NULL;
- int result = 0;
-
- if (!dest || !path || !iface || !method) {
- _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
- return -1;
- }
-
- dh = _dbus_handle_get_default_connection();
- if (!dh) {
- _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
- return -EPERM;
- }
-
- if (signature && param)
- var = _append_variant(signature, param);
-
- reply = g_dbus_connection_call_sync(dh->conn,
- dest, path, iface, method,
- var, NULL,
- G_DBUS_CALL_FLAGS_NONE,
- timeout,
- NULL,
- &err);
- if (!reply || err) {
- _E("failed to g_dbus_connection_call_sync:%s", err->message);
- g_error_free(err);
- return -1;
- }
-
- if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0)
- g_variant_get(reply, "(i)", &result);
- else
- result = -ENOMSG;
-
- g_variant_unref(reply);
-
- return result;
-}
-
-int dbus_handle_method_async(const char *dest,
- const char *path,
- const char *iface,
- const char *method,
- const char *signature,
- const char *param[])
-{
- GVariant * var = NULL;
- dbus_handle_s *dh = NULL;
-
- if (!dest || !path || !iface || !method) {
- _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
- return -1;
- }
-
- dh = _dbus_handle_get_default_connection();
- if (!dh) {
- _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
- return -1;
- }
-
- if (signature && param)
- var = _append_variant(signature, param);
-
- g_dbus_connection_call(dh->conn,
- dest, path, iface, method,
- var, NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL,
- NULL);
-
- return 0;
-}
-
int dbus_handle_method_async_var(const char *dest,
const char *path,
const char *iface,
free(data);
}
-int dbus_handle_method_async_with_reply(const char *dest,
- const char *path,
- const char *iface,
- const char *method,
- const char *signature,
- const char *param[],
- dbus_pending_cb cb,
- int timeout_msec,
- void *data)
-{
- dbus_handle_s *dh = NULL;
- pending_call_data *pdata = NULL;
- GVariant * var = NULL;
- int ret = 0;
-
- if (!dest || !path || !iface || !method) {
- _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
- return -1;
- }
-
- if (timeout_msec < -1) {
- _E("wrong timeout %d", timeout_msec);
- return -1;
- }
-
- dh = _dbus_handle_get_default_connection();
- if (!dh) {
- _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
- return -EPERM;
- }
-
- if (signature && param)
- var = _append_variant(signature, param);
-
- if (cb) {
- pdata = (pending_call_data*)malloc(sizeof(pending_call_data));
- if (!pdata) {
- ret = -ENOMEM;
- goto err;
- }
-
- pdata->func = cb;
- pdata->data = data;
- }
- g_dbus_connection_call(dh->conn,
- dest, path, iface, method,
- var, NULL,
- G_DBUS_CALL_FLAGS_NONE,
- timeout_msec,
- NULL,
- (GAsyncReadyCallback)_cb_pending,
- pdata);
-
- return ret;
-err:
- if (var)
- g_variant_unref(var);
- return ret;
-}
-
int dbus_handle_method_async_with_reply_var(const char *dest,
const char *path,
const char *iface,