LINUX.ORG.RU

История изменений

Исправление UVV, (текущая версия) :

lol, ну в тех тредах я тоже был. В общем, если кому надо, можете использовать:

#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"

using DeviceList = std::vector<std::string>;

DeviceList getServiceList()
{
   DeviceList deviceList;
   GError* pError = 0;
   GDBusConnection* pDbusConnection =
      g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &pError);
   g_clear_error(&pError);

   GDBusMessage* pRequestMessage =
      g_dbus_message_new_method_call(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
                                     DBUS_INTERFACE_DBUS, "ListNames");
   GDBusMessage* pResponseMessage =
      g_dbus_connection_send_message_with_reply_sync(pDbusConnection, pRequestMessage,
                                                     G_DBUS_SEND_MESSAGE_FLAGS_NONE,
                                                     -1, NULL, NULL, &pError);
   g_object_unref(pRequestMessage);

   GVariant* pVariantResponse = g_dbus_message_get_body(pResponseMessage);

   if (!pVariantResponse) return deviceList;

   GVariant* pChildVariant = g_variant_get_child_value(pVariantResponse, 0);
   GVariantIter* iter = g_variant_iter_new(pChildVariant);
   gchar* serviceName;
   
   while (g_variant_iter_loop (iter, "&s", &serviceName)) {
      deviceList.push_back(serviceName);
   }

   return deviceList;
}

Исходная версия UVV, :

lol, ну в тех тредах я тоже был. В общем, если кому надо, можете использовать:

#define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
#define DBUS_PATH_DBUS "/org/freedesktop/DBus"
#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"

using DeviceList = std::vector<std::string>;

DeviceList getServiceList()
{
   DeviceList deviceList;
   GError* pError = 0;
   GDBusConnection* pDbusConnection =
      g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &pError);
   g_clear_error(&pError);

   GDBusMessage* pRequestMessage =
      g_dbus_message_new_method_call(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
                                     DBUS_INTERFACE_DBUS, "ListNames");
   GDBusMessage* pResponseMessage =
      g_dbus_connection_send_message_with_reply_sync(pDbusConnection, pRequestMessage,
                                                     G_DBUS_SEND_MESSAGE_FLAGS_NONE,
                                                     -1, NULL, NULL, &pError);

   GVariant* pVariantResponse = g_dbus_message_get_body(pResponseMessage);

   if (!pVariantResponse) return deviceList;

   GVariant* pChildVariant = g_variant_get_child_value(pVariantResponse, 0);
   GVariantIter* iter = g_variant_iter_new(pChildVariant);
   gchar* serviceName;
   
   while (g_variant_iter_loop (iter, "&s", &serviceName)) {
      deviceList.push_back(serviceName);
   }

   return deviceList;
}