Exemplo n.º 1
0
static void
constructed (GObject *object)
{
  ExampleContactListBase *self = EXAMPLE_CONTACT_LIST_BASE (object);
  void (*chain_up) (GObject *) =
    ((GObjectClass *) example_contact_list_base_parent_class)->constructed;
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles
      (self->priv->conn, TP_HANDLE_TYPE_CONTACT);
  TpHandle self_handle = self->priv->conn->self_handle;
  TpHandleRepoIface *handle_repo = tp_base_connection_get_handles
      (self->priv->conn, self->priv->handle_type);

  if (chain_up != NULL)
    chain_up (object);

  g_assert (TP_IS_BASE_CONNECTION (self->priv->conn));
  g_assert (EXAMPLE_IS_CONTACT_LIST_MANAGER (self->priv->manager));

  tp_dbus_daemon_register_object (
      tp_base_connection_get_dbus_daemon (self->priv->conn),
      self->priv->object_path, self);

  tp_handle_ref (handle_repo, self->priv->handle);
  tp_group_mixin_init (object, G_STRUCT_OFFSET (ExampleContactListBase, group),
      contact_repo, self_handle);
  /* Both the subclasses have full support for telepathy-spec 0.17.6. */
  tp_group_mixin_change_flags (object,
      TP_CHANNEL_GROUP_FLAG_PROPERTIES, 0);
}
Exemplo n.º 2
0
/**
 * tp_contacts_mixin_get_contact_attributes: (skip)
 * @obj: A connection instance that uses this mixin. The connection must be connected.
 * @handles: List of handles to retrieve contacts for. Any invalid handles will be
 * dropped from the returned mapping.
 * @interfaces: A list of interfaces to retrieve attributes from.
 * @assumed_interfaces: A list of additional interfaces to retrieve attributes
 *  from. This can be used for interfaces documented as automatically included,
 *  like %TP_IFACE_CONNECTION for GetContactAttributes,
 *  or %TP_IFACE_CONNECTION and %TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST for
 *  GetContactListAttributes.
 * @sender: The DBus client's unique name. If this is not NULL, the requested handles
 * will be held on behalf of this client.
 *
 * Get contact attributes for the given contacts. Provide attributes for all requested
 * interfaces. If contact attributes are not immediately known, the behaviour is defined
 * by the interface; the attribute should either be omitted from the result or replaced
 * with a default value.
 *
 * Returns: A dictionary mapping the contact handles to contact attributes.
 *
 */
GHashTable *
tp_contacts_mixin_get_contact_attributes (GObject *obj,
    const GArray *handles,
    const gchar **interfaces,
    const gchar **assumed_interfaces,
    const gchar *sender)
{
  GHashTable *result;
  guint i;
  TpBaseConnection *conn = TP_BASE_CONNECTION (obj);
  TpContactsMixin *self = TP_CONTACTS_MIXIN (obj);
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
        TP_HANDLE_TYPE_CONTACT);
  GArray *valid_handles;
  TpContactsMixinFillContactAttributesFunc func;

  g_return_val_if_fail (TP_IS_BASE_CONNECTION (obj), NULL);
  g_return_val_if_fail (TP_CONTACTS_MIXIN_OFFSET (obj) != 0, NULL);
  g_return_val_if_fail (tp_base_connection_check_connected (conn, NULL), NULL);

  /* Setup handle array and hash with valid handles, optionally holding them */
  valid_handles = g_array_sized_new (TRUE, TRUE, sizeof (TpHandle),
      handles->len);
  result = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
      (GDestroyNotify) g_hash_table_unref);

  for (i = 0 ; i < handles->len ; i++)
    {
      TpHandle h;
      h = g_array_index (handles, TpHandle, i);
      if (tp_handle_is_valid (contact_repo, h, NULL))
        {
          GHashTable *attr_hash = g_hash_table_new_full (g_str_hash,
              g_str_equal, g_free, (GDestroyNotify) tp_g_value_slice_free);
          g_array_append_val (valid_handles, h);
          g_hash_table_insert (result, GUINT_TO_POINTER(h), attr_hash);
        }
    }

  for (i = 0; assumed_interfaces != NULL && assumed_interfaces[i] != NULL; i++)
    {
      func = g_hash_table_lookup (self->priv->interfaces, assumed_interfaces[i]);

      if (func == NULL)
        DEBUG ("non-inspectable assumed interface %s given; ignoring",
            assumed_interfaces[i]);
      else
        func (obj, valid_handles, result);
    }

  for (i = 0; interfaces != NULL && interfaces[i] != NULL; i++)
    {

      func = g_hash_table_lookup (self->priv->interfaces, interfaces[i]);

      if (func == NULL)
        DEBUG ("non-inspectable interface %s given; ignoring", interfaces[i]);
      else
        func (obj, valid_handles, result);
    }

  g_array_unref (valid_handles);

  return result;
}