Ejemplo n.º 1
0
static void
_setup_nfc_adapters(GTlmNfc *self)
{
    GList* objects = g_dbus_object_manager_get_objects(self->neard_manager);
    GList* objects_iter = objects;
    
    while (objects_iter != NULL) {
        GList* interfaces = g_dbus_object_get_interfaces(objects_iter->data);
        GList* interfaces_iter = interfaces;
        while (interfaces_iter != NULL) {
            g_debug("Checking managed object %s, interface %s", 
                    g_dbus_object_get_object_path (objects_iter->data),
                    g_dbus_proxy_get_interface_name (interfaces_iter->data));
            if (g_strcmp0(g_dbus_proxy_get_interface_name (interfaces_iter->data),
                "org.neard.Adapter") == 0) {
                _setup_nfc_adapter(self, interfaces_iter->data);
            }
            g_object_unref(interfaces_iter->data);
            interfaces_iter = interfaces_iter->next;
        }
        g_list_free(interfaces);
        g_object_unref(objects_iter->data);
        objects_iter = objects_iter->next;
    }
    g_list_free(objects);
    
}
Ejemplo n.º 2
0
gpointer
storage_daemon_find_thing (StorageDaemon *daemon,
                           const gchar *object_path,
                           GType type_of_thing)
{
  GDBusObject *object;
  GList *interfaces, *l;
  gpointer ret = NULL;

  object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (daemon->object_manager), object_path);
  if (object == NULL ||
      type_of_thing == G_TYPE_INVALID ||
      G_TYPE_CHECK_INSTANCE_TYPE (object, type_of_thing))
    {
      return object;
    }

  interfaces = g_dbus_object_get_interfaces (object);
  for (l = interfaces; ret == NULL && l != NULL; l = g_list_next (l))
    {
      if (G_TYPE_CHECK_INSTANCE_TYPE (l->data, type_of_thing))
        ret = g_object_ref (l->data);
    }

  g_list_free_full (interfaces, g_object_unref);
  g_object_unref (object);
  return ret;
}
Ejemplo n.º 3
0
void
storage_daemon_unpublish (StorageDaemon *self,
                          const gchar *path,
                          gpointer thing)
{
  GDBusObject *object;
  gboolean unexport = FALSE;
  GList *interfaces, *l;

  g_return_if_fail (STORAGE_IS_DAEMON (self));
  g_return_if_fail (path != NULL);

  object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (self->object_manager), path);
  if (object == NULL)
    return;

  path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object));

  if (G_IS_DBUS_INTERFACE (thing))
    {
      g_debug ("unpublishing interface: %s %s", path,
               g_dbus_interface_get_info(thing)->name);

      unexport = TRUE;

      interfaces = g_dbus_object_get_interfaces (object);
      for (l = interfaces; l != NULL; l = g_list_next (l))
        {
          if (G_DBUS_INTERFACE (l->data) != G_DBUS_INTERFACE (thing))
            unexport = FALSE;
        }
      g_list_free_full (interfaces, g_object_unref);

      /*
       * HACK: GDBusObjectManagerServer is broken ... and sends InterfaceRemoved
       * too many times, if you remove all interfaces manually, and then unexport
       * a GDBusObject. So only do it here if we're not unexporting the object.
       */
      if (!unexport)
        g_dbus_object_skeleton_remove_interface (G_DBUS_OBJECT_SKELETON (object), thing);
      else
        g_debug ("(unpublishing object, too)");

    }
  else if (thing == NULL)
    {
      unexport = TRUE;
    }
  else
    {
      g_critical ("Unsupported type to unpublish: %s", G_OBJECT_TYPE_NAME (thing));
    }

  if (unexport)
    g_dbus_object_manager_server_unexport (self->object_manager, path);

  g_object_unref (object);
}
Ejemplo n.º 4
0
static void
on_object_added (GDBusObjectManager *manager,
                 GDBusObject *object,
                 gpointer user_data)
{
        GList *interfaces, *l;

        interfaces = g_dbus_object_get_interfaces (object);
        for (l = interfaces; l != NULL; l = g_list_next (l))
                on_interface_added (manager, object, l->data);
        g_list_free_full (interfaces, g_object_unref);

        if (is_realm_with_kerberos_and_membership (object)) {
                g_debug ("Saw realm: %s", g_dbus_object_get_object_path (object));
                g_signal_emit (user_data, signals[REALM_ADDED], 0, object);
        }
}
static GString* get_characteristic_uuid(GDBusObject* object)
{
    // 'object' is a GATT characteristic if one of the interfaces
    // that this object supports is 'org.bluez.GattCharacteristic1'

    GString* result;
    GList* interfaces = g_dbus_object_get_interfaces(object);
    if (interfaces != NULL)
    {
        GList* characteristic_item = g_list_find_custom(
            interfaces,
            (gconstpointer)"org.bluez.GattCharacteristic1",
            is_interface_type
        );
        if (characteristic_item != NULL)
        {
            GVariant* var = g_dbus_proxy_get_cached_property(
                (GDBusProxy*)(characteristic_item->data),
                "UUID"
            );
            if (var != NULL)
            {
                result = g_string_new(g_variant_get_string(var, NULL));
                g_variant_unref(var);
            }
            else
            {
                result = NULL;
            }
        }
        else
        {
            result = NULL;
        }

        g_list_foreach(interfaces, unref_list_object, NULL);
        g_list_free(interfaces);
    }
    else
    {
        result = NULL;
    }

    return result;
}
Ejemplo n.º 6
0
void _on_object_removed(GDBusObjectManager *manager,
                         GDBusObject        *object,
                         gpointer            user_data)
{
    //GTlmNfc* self = GTLM_NFC(user_data);
    g_debug("Object %s removed", 
                    g_dbus_object_get_object_path (object));

    GList* interfaces = g_dbus_object_get_interfaces(object);
    GList* interfaces_iter = interfaces;
    while (interfaces_iter != NULL) {
        _on_interface_removed(manager, object, interfaces_iter->data, user_data);
        g_object_unref(interfaces_iter->data);
        interfaces_iter = interfaces_iter->next;
    }
    g_list_free(interfaces);
    g_debug("Finished checking interfaces");       
}
Ejemplo n.º 7
0
static void
on_object_added (GDBusObjectManager  *manager,
                 GDBusObject         *object,
                 gpointer             user_data)
{
  UDisksClient *client = UDISKS_CLIENT (user_data);
  GList *interfaces, *l;

  interfaces = g_dbus_object_get_interfaces (object);
  for (l = interfaces; l != NULL; l = l->next)
    {
      init_interface_proxy (client, G_DBUS_PROXY (l->data));
    }
  g_list_foreach (interfaces, (GFunc) g_object_unref, NULL);
  g_list_free (interfaces);

  udisks_client_queue_changed (client);
}
static void
print_objects (GDBusObjectManager *manager)
{
    GList *objects;
    GList *l;

    g_print ("Object manager at %s\n", g_dbus_object_manager_get_object_path (manager));
    objects = g_dbus_object_manager_get_objects (manager);
    for (l = objects; l != NULL; l = l->next)
    {
        ExampleObject *object = EXAMPLE_OBJECT (l->data);
        GList *interfaces;
        GList *ll;
        g_print (" - Object at %s\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));

        interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (object));
        for (ll = interfaces; ll != NULL; ll = ll->next)
        {
            GDBusInterface *interface = G_DBUS_INTERFACE (ll->data);
            g_print ("   - Interface %s\n", g_dbus_interface_get_info (interface)->name);

            /* Note that @interface is really a GDBusProxy instance - and additionally also
             * an ExampleAnimal or ExampleCat instance - either of these can be used to
             * invoke methods on the remote object. For example, the generated function
             *
             *  void example_animal_call_poke_sync (ExampleAnimal  *proxy,
             *                                      gboolean        make_sad,
             *                                      gboolean        make_happy,
             *                                      GCancellable   *cancellable,
             *                                      GError        **error);
             *
             * can be used to call the Poke() D-Bus method on the .Animal interface.
             * Additionally, the generated function
             *
             *  const gchar *example_animal_get_mood (ExampleAnimal *object);
             *
             * can be used to get the value of the :Mood property.
             */
        }
        g_list_free_full (interfaces, g_object_unref);
    }
    g_list_free_full (objects, g_object_unref);
}
Ejemplo n.º 9
0
static void
add_object (JsonBuilder *builder,
            GDBusObject *object)
{
  GList *interfaces;
  GList *l;

  json_builder_set_member_name (builder, "objpath");
  json_builder_add_string_value (builder, g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));

  json_builder_set_member_name (builder, "ifaces");
  json_builder_begin_object (builder);

  interfaces = g_dbus_object_get_interfaces (object);
  for (l = interfaces; l != NULL; l = l->next)
    {
      GDBusInterface *interface = G_DBUS_INTERFACE (l->data);
      add_interface (builder, interface, NULL);
    }
  g_list_foreach (interfaces, (GFunc)g_object_unref, NULL);
  g_list_free (interfaces);

  json_builder_end_object (builder);
}
Ejemplo n.º 10
0
static gboolean
initable_init (GInitable     *initable,
               GCancellable  *cancellable,
               GError       **error)
{
  UDisksClient *client = UDISKS_CLIENT (initable);
  gboolean ret;
  GList *objects, *l;
  GList *interfaces, *ll;

  ret = FALSE;

  /* This method needs to be idempotent to work with the singleton
   * pattern. See the docs for g_initable_init(). We implement this by
   * locking.
   */
  G_LOCK (init_lock);
  if (client->is_initialized)
    {
      if (client->object_manager != NULL)
        ret = TRUE;
      else
        g_assert (client->initialization_error != NULL);
      goto out;
    }
  g_assert (client->initialization_error == NULL);

  client->context = g_main_context_get_thread_default ();
  if (client->context != NULL)
    g_main_context_ref (client->context);

  client->object_manager = udisks_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                                                          G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
                                                                          "org.freedesktop.UDisks2",
                                                                          "/org/freedesktop/UDisks2",
                                                                          cancellable,
                                                                          &client->initialization_error);
  if (client->object_manager == NULL)
    goto out;

  /* init all proxies */
  objects = g_dbus_object_manager_get_objects (client->object_manager);
  for (l = objects; l != NULL; l = l->next)
    {
      interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (l->data));
      for (ll = interfaces; ll != NULL; ll = ll->next)
        {
          init_interface_proxy (client, G_DBUS_PROXY (ll->data));
        }
      g_list_foreach (interfaces, (GFunc) g_object_unref, NULL);
      g_list_free (interfaces);
    }
  g_list_foreach (objects, (GFunc) g_object_unref, NULL);
  g_list_free (objects);

  g_signal_connect (client->object_manager,
                    "object-added",
                    G_CALLBACK (on_object_added),
                    client);
  g_signal_connect (client->object_manager,
                    "object-removed",
                    G_CALLBACK (on_object_removed),
                    client);
  g_signal_connect (client->object_manager,
                    "interface-added",
                    G_CALLBACK (on_interface_added),
                    client);
  g_signal_connect (client->object_manager,
                    "interface-removed",
                    G_CALLBACK (on_interface_removed),
                    client);
  g_signal_connect (client->object_manager,
                    "interface-proxy-properties-changed",
                    G_CALLBACK (on_interface_proxy_properties_changed),
                    client);

  ret = TRUE;

out:
  client->is_initialized = TRUE;
  if (!ret)
    {
      g_assert (client->initialization_error != NULL);
      g_propagate_error (error, g_error_copy (client->initialization_error));
    }
  G_UNLOCK (init_lock);
  return ret;
}
/**
 * g_dbus_object_manager_server_export:
 * @manager: A #GDBusObjectManagerServer.
 * @object: A #GDBusObjectSkeleton.
 *
 * Exports @object on @manager.
 *
 * If there is already a #GDBusObject exported at the object path,
 * then the old object is removed.
 *
 * The object path for @object must be in the hierarchy rooted by the
 * object path for @manager.
 *
 * Note that @manager will take a reference on @object for as long as
 * it is exported.
 *
 * Since: 2.30
 */
void
g_dbus_object_manager_server_export (GDBusObjectManagerServer  *manager,
                                     GDBusObjectSkeleton       *object)
{
  RegistrationData *data;
  GList *existing_interfaces;
  GList *l;
  GPtrArray *interface_names;
  const gchar *object_path;

  object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object));

  g_return_if_fail (G_IS_DBUS_OBJECT_MANAGER_SERVER (manager));
  g_return_if_fail (G_IS_DBUS_OBJECT (object));
  g_return_if_fail (g_str_has_prefix (object_path, manager->priv->object_path_ending_in_slash));

  interface_names = g_ptr_array_new ();

  data = g_hash_table_lookup (manager->priv->map_object_path_to_data, object_path);
  if (data != NULL)
    g_dbus_object_manager_server_unexport (manager, object_path);

  data = g_new0 (RegistrationData, 1);
  data->object = g_object_ref (object);
  data->manager = manager;
  data->map_iface_name_to_iface = g_hash_table_new_full (g_str_hash,
                                                         g_str_equal,
                                                         NULL,
                                                         (GDestroyNotify) g_object_unref);

  g_signal_connect (object,
                    "interface-added",
                    G_CALLBACK (on_interface_added),
                    data);
  g_signal_connect (object,
                    "interface-removed",
                    G_CALLBACK (on_interface_removed),
                    data);

  /* Register all known interfaces - note that data->exported is FALSE so
   * we don't emit any InterfacesAdded signals.
   */
  existing_interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (object));
  for (l = existing_interfaces; l != NULL; l = l->next)
    {
      GDBusInterfaceSkeleton *interface_skeleton = G_DBUS_INTERFACE_SKELETON (l->data);
      registration_data_export_interface (data, interface_skeleton);
      g_ptr_array_add (interface_names, g_dbus_interface_skeleton_get_info (interface_skeleton)->name);
    }
  g_list_foreach (existing_interfaces, (GFunc) g_object_unref, NULL);
  g_list_free (existing_interfaces);
  g_ptr_array_add (interface_names, NULL);

  data->exported = TRUE;

  /* now emit InterfacesAdded() for all the interfaces */
  g_dbus_object_manager_server_emit_interfaces_added (manager, data, (const gchar *const *) interface_names->pdata);
  g_ptr_array_unref (interface_names);

  g_hash_table_insert (manager->priv->map_object_path_to_data,
                       g_strdup (object_path),
                       data);
}