2
* @file geis_dbus_proxy_box.c
3
* @brief Implementation of a storage facility for GEIS DBus server client
8
* Copyright 2011 Canonical Ltd.
10
* This library is free software; you can redistribute it and/or modify it under
11
* the terms of the GNU Lesser General Public License as published by the Free
12
* Software Foundation; either version 3 of the License, or (at your option) any
15
* This library is distributed in the hope that it will be useful, but WITHOUT
16
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "geis_config.h"
24
#include "geis_dbus_proxy_box.h"
27
#include "geis_logging.h"
30
typedef struct GeisDBusProxyBoxNode *GeisDBusProxyBoxNode;
32
struct GeisDBusProxyBoxNode
34
GeisDBusClientProxy proxy;
35
GeisDBusProxyBoxNode next;
40
* The box is represented using a circular linked list with a free pool.
42
struct GeisDBusProxyBox
44
GeisDBusProxyBoxNode head;
45
GeisDBusProxyBoxNode avail;
50
* Constructs a %GeisDBusProxyBox.
53
geis_dbus_proxy_box_new()
55
GeisDBusProxyBox box = calloc(1, sizeof(struct GeisDBusProxyBox));
58
geis_error("error allocating GeisDBusProxyBox");
66
* Destroys a %GeisDBusProxyBox.
68
* Assumes all contained client proxies have already been freed, otherwise there
69
* will be resource leaks because this container does not know how to free them.
72
geis_dbus_proxy_box_delete(GeisDBusProxyBox box)
74
GeisDBusProxyBoxNode p = box->avail;
86
* Inserts a %GeisDBusClientProxy in to a %GeisDBusProxyBox.
89
geis_dbus_proxy_box_insert(GeisDBusProxyBox box,
90
GeisDBusClientProxy proxy)
92
if (box->avail == NULL)
94
box->avail = calloc(1, sizeof(struct GeisDBusProxyBoxNode));
97
geis_error("error allocating proxy box node");
102
GeisDBusProxyBoxNode p = box->avail;
104
box->avail = p->next;
106
if (box->head == NULL)
112
p->next = box->head->next;
119
* Removes a %GeisDBusClientProxy from a %GeisDBusProxyBox.
122
geis_dbus_proxy_box_remove(GeisDBusProxyBox box,
123
GeisDBusClientProxy proxy)
125
assert(box->head != NULL);
127
GeisDBusProxyBoxNode ptr = box->head;
128
GeisDBusProxyBoxNode p = box->head->next;
131
if (p->proxy == proxy)
143
p->next = box->avail;
149
} while (ptr != box->head);
154
* Gets an iterator initialized to the first client proxy in a box.
156
GeisDBusProxyBoxIterator
157
geis_dbus_proxy_box_begin(GeisDBusProxyBox box)
160
return box->head->next;
166
* Gets an iterator initialized to one-past-the-end of a client proxy box.
168
GeisDBusProxyBoxIterator
169
geis_dbus_proxy_box_end(GeisDBusProxyBox box GEIS_UNUSED)
176
* Gets the current client proxy from a client proxy box iterator.
179
geis_dbus_proxy_box_iter_value(GeisDBusProxyBoxIterator iter)
186
* Advances a client proxy box iterator.
188
GeisDBusProxyBoxIterator
189
geis_dbus_proxy_box_iter_next(GeisDBusProxyBox box,
190
GeisDBusProxyBoxIterator iter)
192
if (iter == box->head)
193
return geis_dbus_proxy_box_end(box);