How to send Dictionary datatype( a{ias} ) through gdbus?

264 views Asked by At

I was trying to send different datatypes over dbus using gdbus. I am stuck at sending the following datatype : a{ias}. Does anyone send me a snippet or any ways to approach this problem?

1

There are 1 answers

1
Suraj Kottayi On BEST ANSWER

I have got a snippet here,just replace the busname,path,interface,methodname in the below code.

  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);