summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_reply.c
blob: f27f3b0860bf4641fc504b9b019b466e7ed7600e (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * 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 Ecore_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 ()
{
   _ecore_xcb_cookies = ecore_list_new();
   if (!_ecore_xcb_cookies)
     return 0;

   if (!ecore_list_init(_ecore_xcb_cookies))
     {
        ecore_list_destroy(_ecore_xcb_cookies);
        return 0;
     }

   if (!ecore_list_free_cb_set(_ecore_xcb_cookies, ECORE_FREE_CB(free)))
     {
        ecore_list_destroy(_ecore_xcb_cookies);
        return 0;
     }

   return 1;
}

void
_ecore_x_reply_shutdown ()
{
  if (_ecore_xcb_reply)
    free(_ecore_xcb_reply);

   if (!_ecore_xcb_cookies)
     return;

   ecore_list_destroy(_ecore_xcb_cookies);
}

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;

   if (!ecore_list_append(_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 = ecore_list_first_remove(_ecore_xcb_cookies);
   if (data)
     {
        cookie = data->cookie;
        free(data);

        return cookie;
     }

   return 0;
}

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; */
/*     } */
}