source: buddy.c @ 7ff3907

release-1.10
Last change on this file since 7ff3907 was 7dcef03, checked in by Anders Kaseorg <andersk@mit.edu>, 10 years ago
Use the Glib slice allocator for fixed-size objects The slice allocator, available since GLib 2.10, is more space-efficient than [g_]malloc. Since BarnOwl is obviously at the leading edge of space-efficient technology, this seems like a natural fit. Use it for every fixed-size object except owl_viewwin_search_data (which would need an extra destroy_cbdata function to g_slice_free it). Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include "owl.h"
2
3void owl_buddy_create(owl_buddy *b, int proto, const char *name)
4{
5  b->proto=proto;
6  b->name=g_strdup(name);
7  b->idlesince=0;
8}
9
10const char *owl_buddy_get_name(const owl_buddy *b)
11{
12  if (b->name) return(b->name);
13  return("");
14}
15
16int owl_buddy_is_idle(const owl_buddy *b)
17{
18  if (b->isidle) return(1);
19  return(0);
20}
21
22void owl_buddy_set_idle(owl_buddy *b)
23{
24  b->isidle=1;
25}
26
27void owl_buddy_set_unidle(owl_buddy *b)
28{
29  b->isidle=0;
30}
31
32int owl_buddy_get_proto(const owl_buddy *b)
33{
34  return(b->proto);
35}
36
37int owl_buddy_is_proto_aim(const owl_buddy *b)
38{
39  if (b->proto==OWL_PROTOCOL_AIM) return(1);
40  return(0);
41}
42
43/* Set the buddy to have been idle since 'diff' minutes ago
44 */
45void owl_buddy_set_idle_since(owl_buddy *b, int diff)
46{
47  time_t now;
48
49  now=time(NULL);
50  b->idlesince=now-(diff*60);
51}
52
53/* return the number of minutes the buddy has been idle
54 */
55int owl_buddy_get_idle_time(const owl_buddy *b)
56{
57  time_t now;
58
59  if (b->isidle) {
60    now=time(NULL);
61    return((now - b->idlesince)/60);
62  }
63  return(0);
64}
65
66void owl_buddy_cleanup(owl_buddy *b)
67{
68  if (b->name) g_free(b->name);
69}
70
71void owl_buddy_delete(owl_buddy *b)
72{
73  owl_buddy_cleanup(b);
74  g_slice_free(owl_buddy, b);
75}
Note: See TracBrowser for help on using the repository browser.