]> git.0d.be Git - empathy.git/blob - libempathy/gossip-avatar.c
Fix indentation Fix not returning the contact in tp_contact_list_find()
[empathy.git] / libempathy / gossip-avatar.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2002-2007 Imendio AB
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Authors: Martyn Russell <martyn@imendio.com>
21  *          Xavier Claessens <xclaesse@gmail.com>
22  */
23
24 #include "config.h"
25
26 #include "gossip-avatar.h"
27
28 #define DEBUG_DOMAIN "Avatar"
29
30 GType
31 gossip_avatar_get_gtype (void)
32 {
33         static GType type_id = 0;
34
35         if (!type_id) {
36                 type_id = g_boxed_type_register_static ("GossipAvatar",
37                                                         (GBoxedCopyFunc) gossip_avatar_ref,
38                                                         (GBoxedFreeFunc) gossip_avatar_unref);
39         }
40
41         return type_id;
42 }
43
44 GossipAvatar *
45 gossip_avatar_new (guchar *data,
46                    gsize   len,
47                    gchar  *format)
48 {
49         GossipAvatar *avatar;
50
51         g_return_val_if_fail (data != NULL, NULL);
52         g_return_val_if_fail (len > 0, NULL);
53         g_return_val_if_fail (format != NULL, NULL);
54
55         avatar = g_slice_new0 (GossipAvatar);
56         avatar->data = g_memdup (data, len);
57         avatar->len = len;
58         avatar->format = g_strdup (format);
59         avatar->refcount = 1;
60
61         return avatar;
62 }
63
64 void
65 gossip_avatar_unref (GossipAvatar *avatar)
66 {
67         g_return_if_fail (avatar != NULL);
68
69         avatar->refcount--;
70         if (avatar->refcount == 0) {
71                 g_free (avatar->data);
72                 g_free (avatar->format);
73                 g_slice_free (GossipAvatar, avatar);
74         }
75 }
76
77 GossipAvatar *
78 gossip_avatar_ref (GossipAvatar *avatar)
79 {
80         g_return_val_if_fail (avatar != NULL, NULL);
81
82         avatar->refcount++;
83
84         return avatar;
85 }
86