3
* @brief internal GEIS back end base class implementation
5
* Copyright 2010 Canonical Ltd.
7
* This library is free software; you can redistribute it and/or modify it under
8
* the terms of the GNU Lesser General Public License as published by the Free
9
* Software Foundation; either version 3 of the License, or (at your option) any
12
* This library is distributed in the hope that it will be useful, but WITHOUT
13
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "geis_config.h"
21
#include "geis_backend.h"
22
#include "geis_backend_protected.h"
24
#include "geis_logging.h"
29
typedef struct GeisBackendClass
33
GeisBackendVtable vtbl;
39
GeisBackendClass be_class;
44
struct GeisBackendRegistry
51
static struct GeisBackendRegistry _be_registry = { NULL, 0, 0 };
55
* Gets the child part of the back end instance.
58
_data_from_be(GeisBackend be)
60
return (void *)be->be_data;
65
* Initializes a new back end class object.
68
_backend_class_init(GeisBackendClass self,
71
GeisBackendVtable vtbl)
73
self->name = strdup(name);
80
* Registers back ends with the API.
83
geis_register_backend(GeisString name, GeisSize size, GeisBackendVtable vtbl)
85
GeisSize new_size = _be_registry.size + 1;
86
GeisBackendClass new_be = realloc(_be_registry.be,
87
new_size * sizeof(struct GeisBackendClass));
90
geis_error("error reallocating back end registry");
94
_backend_class_init(&new_be[_be_registry.size], name, size, vtbl);
95
geis_debug("back end %zu registered as '%s'", _be_registry.count, name);
97
_be_registry.be = new_be;
107
geis_backend_create_token(GeisBackend be, GeisBackendTokenInitState init_state)
109
return be->be_class->vtbl->create_token(_data_from_be(be), init_state);
114
* Creates a back end by name.
117
geis_backend_by_name(Geis geis, GeisString name)
119
GeisBackend backend = NULL;
121
extern void geis_include_backend_test_fixture(void);
122
extern void geis_include_dbus_backend(void);
123
extern void geis_include_grail_backend(void);
125
geis_debug("creating back end of class \"%s\"", name);
126
/* temporary references to force symbol inclusion, replace with dlopen */
127
geis_include_backend_test_fixture();
128
geis_include_dbus_backend();
129
geis_include_grail_backend();
131
for (i = 0; i < _be_registry.count; ++i)
133
if (0 == strcmp(_be_registry.be[i].name, name))
135
size_t obj_size = sizeof(GeisBackend) + _be_registry.be[i].size;
136
backend = malloc(obj_size);
139
*(GeisBackendClass *)(backend) = &_be_registry.be[i];
140
_be_registry.be[i].vtbl->construct(_data_from_be(backend), geis);
141
if (geis_error_count(geis))
155
* Destroys the back end.
158
geis_backend_delete(GeisBackend be)
162
geis_debug("destroying back end %s", geis_backend_name(be));
163
be->be_class->vtbl->finalize(_data_from_be(be));
170
* Gets the name of the back end (RTTI).
173
geis_backend_name(GeisBackend be)
175
return be->be_class->name;
180
geis_backend_gesture_accept(GeisBackend be,
182
GeisGestureId gesture_id)
184
GeisStatus status = be->be_class->vtbl->accept_gesture(_data_from_be(be),
192
geis_backend_gesture_reject(GeisBackend be,
194
GeisGestureId gesture_id)
196
GeisStatus status = be->be_class->vtbl->reject_gesture(_data_from_be(be),
204
* Gets a back end configuration value.
207
geis_backend_get_configuration(GeisBackend be,
208
GeisSubscription subscription,
209
GeisString configuration_item_name,
210
GeisPointer configuration_item_value)
212
return be->be_class->vtbl->get_configuration(be,
214
configuration_item_name,
215
configuration_item_value);
220
* Sets a back end configuration value.
223
geis_backend_set_configuration(GeisBackend be,
224
GeisSubscription subscription,
225
GeisString configuration_item_name,
226
GeisPointer configuration_item_value)
228
return be->be_class->vtbl->set_configuration(be,
230
configuration_item_name,
231
configuration_item_value);