2
* @file geis_grail_token.c
3
* @brief GEIS filter token for the grail-based back end
6
* Copyright 2011-2012 Canonical Ltd.
8
* This library is free software: you can redistribute it and/or modify it
9
* under the terms of the GNU Lesser General Public License version 3
10
* as published by the Free Software Foundation.
12
* This library is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranties of
14
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
* PURPOSE. See the GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with this library. If not, see <http://www.gnu.org/licenses/>.
20
#include "geis_config.h"
21
#include "geis_grail_token.h"
23
#include "geis_backend_token.h"
24
#include "geis_grail_backend.h"
25
#include "geis_logging.h"
30
/* The maximum nuimber of devices supported. */
31
#define MAX_NUM_DEVICES 10
33
/* The maximum nuimber of regions supported. */
34
#define MAX_NUM_WINDOWS 10
39
struct GeisBackendToken base;
42
int devices[MAX_NUM_DEVICES];
44
Window windows[MAX_NUM_WINDOWS];
49
* Converts from a GeisBackendToken to an XcbBackendToken.
51
static inline GeisGrailToken
52
_geis_grail_token_from_geis_token(GeisBackendToken gbt)
54
return (GeisGrailToken)gbt;
59
* Allocates memory for a token from a pool.
62
_geis_grail_token_allocate(void)
64
return calloc(1, sizeof(struct GeisGrailToken));
69
* Returns memory for a token to a pool.
72
_geis_grail_token_deallocate(GeisGrailToken gdt)
79
* Deep-copy-constructs a token.
81
static GeisBackendToken
82
_geis_grail_token_clone(GeisBackendToken original)
89
* Composes one token onto another.
95
_geis_grail_token_compose(GeisBackendToken lhs GEIS_UNUSED,
96
GeisBackendToken rhs GEIS_UNUSED)
102
* Activates a Grail back end token.
104
* @param[in] token A %GeisGrailToken.
105
* @param[in] subscription The subscrition the token will be activated on.
108
_geis_grail_token_activate(GeisBackendToken token, GeisSubscription sub)
110
GeisGrailToken gdt = _geis_grail_token_from_geis_token(token);
111
GeisStatus status = geis_grail_backend_activate_subscription(gdt->be, sub);
117
* Deactivates a Grail back end token.
119
* @param[in] token A %GeisGrailToken.
122
_geis_grail_token_deactivate(GeisBackendToken token, GeisSubscription sub)
124
GeisGrailToken gdt = _geis_grail_token_from_geis_token(token);
125
GeisStatus status = geis_grail_backend_deactivate_subscription(gdt->be, sub);
131
* Creates Grail-back-end-specific back end token.
134
geis_grail_token_new(GeisBackend be,
135
GeisBackendTokenInitState init_state GEIS_UNUSED)
137
static struct GeisBackendTokenVtable _token_vtbl = {
138
_geis_grail_token_clone,
139
geis_grail_token_delete,
140
_geis_grail_token_compose,
141
_geis_grail_token_activate,
142
_geis_grail_token_deactivate,
145
GeisGrailToken token = _geis_grail_token_allocate();
148
token->base.vtbl = &_token_vtbl;
149
token->be = (GeisGrailBackend)be;
151
return (GeisBackendToken)token;
156
* Releases resources for a token.
158
* @param[in] token A %GeisGrailToken.
161
geis_grail_token_delete(GeisBackendToken token)
163
GeisGrailToken gdt = _geis_grail_token_from_geis_token(token);
164
_geis_grail_token_deallocate(gdt);
169
geis_grail_token_add_class_term(GeisBackendToken gbtoken GEIS_UNUSED,
170
void *context GEIS_UNUSED,
171
GeisString name GEIS_UNUSED,
172
GeisFilterOperation op GEIS_UNUSED,
173
void *value GEIS_UNUSED)
175
GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
181
geis_grail_token_add_device_term(GeisBackendToken gbtoken GEIS_UNUSED,
182
void *context GEIS_UNUSED,
183
GeisString name GEIS_UNUSED,
184
GeisFilterOperation op GEIS_UNUSED,
185
void *value GEIS_UNUSED)
187
GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
193
geis_grail_token_add_feature_term(GeisBackendToken gbtoken GEIS_UNUSED,
194
void *context GEIS_UNUSED,
195
GeisString name GEIS_UNUSED,
196
GeisFilterOperation op GEIS_UNUSED,
197
void *value GEIS_UNUSED)
199
GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
205
geis_grail_token_add_region_term(GeisBackendToken gbtoken,
206
void *context GEIS_UNUSED,
208
GeisFilterOperation op,
211
GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
212
GeisGrailToken token = _geis_grail_token_from_geis_token(gbtoken);
213
if (0 == strcmp(name, GEIS_REGION_ATTRIBUTE_WINDOWID)
214
&& op == GEIS_FILTER_OP_EQ)
216
Window window = (Window)*(GeisInteger*)value;
217
geis_debug("attr name=\"%s\" windowid=0x%x", name, (unsigned int)window);
218
token->windows[token->window_count++] = window;
219
status = GEIS_STATUS_SUCCESS;