summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_reply.c
blob: 13402b66e5398eac9ef8cd1c1a0ee88315302d8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */

#include <stdlib.h>

#include <Ecore_Data.h>


/* 
 * FIXME:
 * - in ecore_xcb_cookie_cache, should provide better error management
 *   when memory allocation fails
 * - Use an array instead of a list
 * - Is ecore_xcb_reply_free really needed ?
 *   _ecore_xcb_reply_cache frees the current reply and
 *   _ecore_x_reply_shutdown frees the last reply to free.
 *   I keep it in case it is need for memory improvements,
 *   but its code is commented.
 */

static Eina_List  *_ecore_xcb_cookies = NULL;
static void       *_ecore_xcb_reply = NULL;

typedef struct _Ecore_Xcb_Data Ecore_Xcb_Data;

struct _Ecore_Xcb_Data
{
  unsigned int         cookie;
};


int
_ecore_x_reply_init ()
{
   return 1;
}

void
_ecore_x_reply_shutdown ()
{
  Ecore_Xcb_Data *data;

  if (_ecore_xcb_reply)
    free(_ecore_xcb_reply);

   if (!_ecore_xcb_cookies)
     return;

   EINA_LIST_FREE(_ecore_xcb_cookies, data)
     free(data);
}

void
_ecore_xcb_cookie_cache (unsigned int cookie)
{
   Ecore_Xcb_Data *data;

   if (!_ecore_xcb_cookies)
     return;

   data = (Ecore_Xcb_Data *)malloc(sizeof(Ecore_Xcb_Data));
   if (!data)
     return;

   data->cookie = cookie;

   _ecore_xcb_cookies = eina_list_append(_ecore_xcb_cookies, data);
   if (!eina_list_data_find(_ecore_xcb_cookies, data))
     {
        free(data);
        return;
     }
}

unsigned int
_ecore_xcb_cookie_get (void)
{
   Ecore_Xcb_Data *data;
   unsigned int    cookie;

   if (!_ecore_xcb_cookies)
     return 0;

   data = eina_list_data_get(_ecore_xcb_cookies);
   if (!data) return 0;

   _ecore_xcb_cookies = eina_list_remove_list(_ecore_xcb_cookies, _ecore_xcb_cookies);
        cookie = data->cookie;
        free(data);

        return cookie;
}

void
_ecore_xcb_reply_cache (void *reply)
{
   if (_ecore_xcb_reply)
     free(_ecore_xcb_reply);
   _ecore_xcb_reply = reply;
}

void *
_ecore_xcb_reply_get (void)
{
   return _ecore_xcb_reply;
}

EAPI void
ecore_xcb_reply_free()
{
/*   if (_ecore_xcb_reply) */
/*     { */
/*        free(_ecore_xcb_reply); */
/*        _ecore_xcb_reply = NULL; */
/*     } */
}