如何通过 gdbus 发送字典数据类型( a{ias} )?
How to send Dictionary datatype( a{ias} ) through gdbus?
我试图使用 gdbus 通过 dbus 发送不同的数据类型。我坚持发送以下数据类型:a{ias}
。有没有人给我发送一个片段或任何方法来解决这个问题?
我这里有一个片段,只需替换下面代码中的总线名、路径、接口、方法名即可。
GDBusProxy *proxy;
GDBusConnection *connection;
GError *error;
GVariantBuilder* builder;
error = NULL;
**//Acquire bus connection**
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
NULL,
&error);
g_assert_no_error (error);
error = NULL;
**//Create proxy of remote object**
proxy= g_dbus_proxy_new_sync(connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo */
"org.busname", /* Services */
"/org/buspath", /* Path */
"org.interface", /* Interface */
NULL, /* GCancellable */
error);
GVariant *result;
GVariant *value;
GError *error;
error = NULL;
int i;
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
**//Sending dictionary datatype start**
for (i = 0; i < 2; i++)
{
GVariantBuilder* builderAs = g_variant_builder_new(G_VARIANT_TYPE("as"));
for (int j = 0; j < 2; j++) {
g_variant_builder_add(builderAs, "s", "SomeString");
}
g_variant_builder_add(&builder, "{ias}",i,builderAs);
}
**//Sending dictionary end**
GVariant *v1 = g_variant_builder_end(&builder);
result = g_dbus_proxy_call_sync(proxy,
"MethodName",
g_variant_new_tuple(&v1, 1),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
我试图使用 gdbus 通过 dbus 发送不同的数据类型。我坚持发送以下数据类型:a{ias}
。有没有人给我发送一个片段或任何方法来解决这个问题?
我这里有一个片段,只需替换下面代码中的总线名、路径、接口、方法名即可。
GDBusProxy *proxy;
GDBusConnection *connection;
GError *error;
GVariantBuilder* builder;
error = NULL;
**//Acquire bus connection**
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
NULL,
&error);
g_assert_no_error (error);
error = NULL;
**//Create proxy of remote object**
proxy= g_dbus_proxy_new_sync(connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo */
"org.busname", /* Services */
"/org/buspath", /* Path */
"org.interface", /* Interface */
NULL, /* GCancellable */
error);
GVariant *result;
GVariant *value;
GError *error;
error = NULL;
int i;
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
**//Sending dictionary datatype start**
for (i = 0; i < 2; i++)
{
GVariantBuilder* builderAs = g_variant_builder_new(G_VARIANT_TYPE("as"));
for (int j = 0; j < 2; j++) {
g_variant_builder_add(builderAs, "s", "SomeString");
}
g_variant_builder_add(&builder, "{ias}",i,builderAs);
}
**//Sending dictionary end**
GVariant *v1 = g_variant_builder_end(&builder);
result = g_dbus_proxy_call_sync(proxy,
"MethodName",
g_variant_new_tuple(&v1, 1),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);