## TpContactsMixin

TpContactsMixin — a mixin implementation of the contacts connection interface

## Synopsis

    #include <telepathy-glib/telepathy-glib.h>

                        TpContactsMixin;
    struct              TpContactsMixinClass;
    void                tp_contacts_mixin_add_contact_attributes_iface
                                                            (GObject *obj,
                                                             const gchar *interface,
                                                             TpContactsMixinFillContactAttributesFunc fill_contact_attributes);
    void                tp_contacts_mixin_class_init        (GObjectClass *obj_cls,
                                                             glong offset);
    void                tp_contacts_mixin_finalize          (GObject *obj);
    void                tp_contacts_mixin_iface_init        (gpointer g_iface,
                                                             gpointer iface_data);
    void                tp_contacts_mixin_init              (GObject *obj,
                                                             gsize offset);
    void                tp_contacts_mixin_set_contact_attribute
                                                            (GHashTable *contact_attributes,
                                                             TpHandle handle,
                                                             const gchar *attribute,
                                                             GValue *value);
    GHashTable *        tp_contacts_mixin_get_contact_attributes
                                                            (GObject *obj,
                                                             const GArray *handles,
                                                             const gchar **interfaces,
                                                             const gchar **assumed_interfaces,
                                                             const gchar *sender);
    void                (*TpContactsMixinFillContactAttributesFunc)
                                                            (GObject *obj,
                                                             const GArray *contacts,
                                                             GHashTable *attributes_hash);

## Description

This mixin can be added to a TpBaseConnection subclass to implement the Contacts interface in a generic way.

To use the contacts mixin, include a TpContactsMixinClass somewhere in your class structure and a TpContactsMixin somewhere in your instance structure, and call `tp_contacts_mixin_class_init()` from your class_init function, `tp_contacts_mixin_init()` from your init function or constructor, and `tp_contacts_mixin_finalize()` from your dispose or finalize function.

To use the contacts mixin as the implementation of TpSvcConnectionInterfaceContacts, in the function you pass to G_IMPLEMENT_INTERFACE, you should call tp_contacts_mixin_iface_init. TpContactsMixin implements all of the D-Bus methods and properties in the Contacts interface.

To add interfaces with contact attributes to this interface use tp_contacts_mixin_add_contact_attributes_iface:

## Details

### TpContactsMixin

    typedef struct _TpContactsMixin TpContactsMixin;

Structure to be included in the instance structure of objects that use this mixin. Initialize it with `tp_contacts_mixin_init()`.

There are no public fields.

### struct TpContactsMixinClass

    struct TpContactsMixinClass {
    };

Structure to be included in the class structure of objects that use this mixin. Initialize it with `tp_contacts_mixin_class_init()`.

There are no public fields.

### tp_contacts_mixin_add_contact_attributes_iface ()

    void                tp_contacts_mixin_add_contact_attributes_iface
                                                            (GObject *obj,
                                                             const gchar *interface,
                                                             TpContactsMixinFillContactAttributesFunc fill_contact_attributes);

Declare that the given interface has contact attributes which can be added to the attributes hash using the filler function. All the handles in the handle array passed to the filler function are guaranteed to be valid and referenced.

`obj` : | An instance of the implementation that uses this mixin
`interface` : | Name of the interface that has ContactAttributes
`fill_contact_attributes` : | Contact attribute filler function

Since 0.7.14

### tp_contacts_mixin_class_init ()

    void                tp_contacts_mixin_class_init        (GObjectClass *obj_cls,
                                                             glong offset);

Initialize the contacts mixin. Should be called from the implementation's class_init function like so:

    1
    2

    tp_contacts_mixin_class_init ((GObjectClass *) klass,
                             G_STRUCT_OFFSET (SomeObjectClass, contacts_mixin));

`obj_cls` : | The class of the implementation that uses this mixin
`offset` : | The byte offset of the TpContactsMixinClass within the class structure

Since 0.7.14

### tp_contacts_mixin_finalize ()

    void                tp_contacts_mixin_finalize          (GObject *obj);

Free resources held by the contacts mixin.

`obj` : | An object with this mixin.

Since 0.7.14

### tp_contacts_mixin_iface_init ()

    void                tp_contacts_mixin_iface_init        (gpointer g_iface,
                                                             gpointer iface_data);

Fill in the vtable entries needed to implement the contacts interface using this mixin. This function should usually be called via G_IMPLEMENT_INTERFACE.

`g_iface` : | A pointer to the TpSvcConnectionInterfaceContacts in an object class
`iface_data` : | Ignored

Since 0.7.14

### tp_contacts_mixin_init ()

    void                tp_contacts_mixin_init              (GObject *obj,
                                                             gsize offset);

Initialize the contacts mixin. Should be called from the implementation's instance init function like so:

    1
    2

    tp_contacts_mixin_init ((GObject *) self,
                        G_STRUCT_OFFSET (SomeObject, contacts_mixin));

`obj` : | An instance of the implementation that uses this mixin
`offset` : | The byte offset of the TpContactsMixin within the object structure

Since 0.7.14

### tp_contacts_mixin_set_contact_attribute ()

    void                tp_contacts_mixin_set_contact_attribute
                                                            (GHashTable *contact_attributes,
                                                             TpHandle handle,
                                                             const gchar *attribute,
                                                             GValue *value);

Utility function to set attribute for handle to value in the attributes hash as passed to a TpContactsMixinFillContactAttributesFunc.

`contact_attributes` : | contacts attribute hash as passed to TpContactsMixinFillContactAttributesFunc
`handle` : | Handle to set the attribute on
`attribute` : | attribute name
`value` : | slice allocated GValue containing the value of the attribute, for instance with tp_g_value_slice_new. Ownership of the GValue is taken over by the mixin

Since 0.7.14

### tp_contacts_mixin_get_contact_attributes ()

    GHashTable *        tp_contacts_mixin_get_contact_attributes
                                                            (GObject *obj,
                                                             const GArray *handles,
                                                             const gchar **interfaces,
                                                             const gchar **assumed_interfaces,
                                                             const gchar *sender);

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.

`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.
Returns : | A dictionary mapping the contact handles to contact attributes.

### TpContactsMixinFillContactAttributesFunc ()

    void                (*TpContactsMixinFillContactAttributesFunc)
                                                            (GObject *obj,
                                                             const GArray *contacts,
                                                             GHashTable *attributes_hash);

This function is called to supply contact attributes pertaining to a particular interface, for a list of contacts. All the handles in `contacts` are guaranteed to be valid and referenced.

`obj` : | An object implementing the Contacts interface with this mixin
`contacts` : | The contact handles for which attributes are requested
`attributes_hash` : | hash of handle => hash of attributes, containing all the contacts in the contacts array

## See Also

TpSvcConnectionInterfaceContacts