~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to libgeis/backend/grail/geis_grail_token.c

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file geis_grail_token.c
 
3
 * @brief GEIS filter token for the grail-based back end
 
4
 */
 
5
/*
 
6
 * Copyright 2011-2012 Canonical Ltd.
 
7
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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/>.
 
19
 */
 
20
#include "geis_config.h"
 
21
#include "geis_grail_token.h"
 
22
 
 
23
#include "geis_backend_token.h"
 
24
#include "geis_grail_backend.h"
 
25
#include "geis_logging.h"
 
26
#include <string.h>
 
27
#include <X11/Xlib.h>
 
28
 
 
29
 
 
30
/* The maximum nuimber of devices supported. */
 
31
#define MAX_NUM_DEVICES 10
 
32
 
 
33
/* The maximum nuimber of regions supported. */
 
34
#define MAX_NUM_WINDOWS 10
 
35
 
 
36
 
 
37
struct GeisGrailToken
 
38
{
 
39
  struct GeisBackendToken base;
 
40
  GeisGrailBackend        be;
 
41
  int                     device_count;
 
42
  int                     devices[MAX_NUM_DEVICES];
 
43
  int                     window_count;
 
44
  Window                  windows[MAX_NUM_WINDOWS];
 
45
};
 
46
 
 
47
 
 
48
/**
 
49
 * Converts from a GeisBackendToken to an XcbBackendToken.
 
50
 */
 
51
static inline GeisGrailToken
 
52
_geis_grail_token_from_geis_token(GeisBackendToken gbt)
 
53
{
 
54
  return (GeisGrailToken)gbt;
 
55
}
 
56
 
 
57
 
 
58
/**
 
59
 * Allocates memory for a token from a pool.
 
60
 */
 
61
static GeisGrailToken
 
62
_geis_grail_token_allocate(void)
 
63
{
 
64
  return calloc(1, sizeof(struct GeisGrailToken));
 
65
}
 
66
 
 
67
 
 
68
/**
 
69
 * Returns memory for a token to a pool.
 
70
 */
 
71
static void
 
72
_geis_grail_token_deallocate(GeisGrailToken gdt)
 
73
{
 
74
  free(gdt);
 
75
}
 
76
 
 
77
 
 
78
/**
 
79
 * Deep-copy-constructs a token.
 
80
 */
 
81
static GeisBackendToken
 
82
_geis_grail_token_clone(GeisBackendToken original)
 
83
{
 
84
  return original;
 
85
}
 
86
 
 
87
 
 
88
/**
 
89
 * Composes one token onto another.
 
90
 *
 
91
 * @param[in,out] lhs
 
92
 * @param[in]     rhs
 
93
 */
 
94
static void             
 
95
_geis_grail_token_compose(GeisBackendToken lhs GEIS_UNUSED,
 
96
                          GeisBackendToken rhs GEIS_UNUSED)
 
97
{
 
98
}
 
99
 
 
100
 
 
101
/**
 
102
 * Activates a Grail back end token.
 
103
 *
 
104
 * @param[in] token        A %GeisGrailToken.
 
105
 * @param[in] subscription The subscrition the token will be activated on.
 
106
 */
 
107
static GeisStatus       
 
108
_geis_grail_token_activate(GeisBackendToken token, GeisSubscription sub)
 
109
{
 
110
  GeisGrailToken gdt = _geis_grail_token_from_geis_token(token);
 
111
  GeisStatus status = geis_grail_backend_activate_subscription(gdt->be, sub);
 
112
  return status;
 
113
}
 
114
 
 
115
 
 
116
/**
 
117
 * Deactivates a Grail back end token.
 
118
 *
 
119
 * @param[in] token        A %GeisGrailToken.
 
120
 */
 
121
static GeisStatus       
 
122
_geis_grail_token_deactivate(GeisBackendToken token, GeisSubscription sub)
 
123
{
 
124
  GeisGrailToken gdt = _geis_grail_token_from_geis_token(token);
 
125
  GeisStatus status = geis_grail_backend_deactivate_subscription(gdt->be, sub);
 
126
  return status;
 
127
}
 
128
 
 
129
 
 
130
/**
 
131
 * Creates Grail-back-end-specific back end token.
 
132
 */
 
133
GeisBackendToken
 
134
geis_grail_token_new(GeisBackend be,
 
135
                     GeisBackendTokenInitState init_state GEIS_UNUSED)
 
136
{
 
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,
 
143
  };
 
144
 
 
145
  GeisGrailToken token = _geis_grail_token_allocate();
 
146
  if (token)
 
147
  {
 
148
    token->base.vtbl = &_token_vtbl;
 
149
    token->be = (GeisGrailBackend)be;
 
150
  }
 
151
  return (GeisBackendToken)token;
 
152
}
 
153
 
 
154
 
 
155
/**
 
156
 * Releases resources for a token.
 
157
 *
 
158
 * @param[in] token  A %GeisGrailToken.
 
159
 */
 
160
void             
 
161
geis_grail_token_delete(GeisBackendToken token)
 
162
{
 
163
  GeisGrailToken gdt = _geis_grail_token_from_geis_token(token);
 
164
  _geis_grail_token_deallocate(gdt);
 
165
}
 
166
 
 
167
 
 
168
GeisStatus
 
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)
 
174
{
 
175
  GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
 
176
  return status;
 
177
}
 
178
 
 
179
 
 
180
GeisStatus
 
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)
 
186
{
 
187
  GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
 
188
  return status;
 
189
}
 
190
 
 
191
 
 
192
GeisStatus
 
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)
 
198
{
 
199
  GeisStatus status = GEIS_STATUS_UNKNOWN_ERROR;
 
200
  return status;
 
201
}
 
202
 
 
203
 
 
204
GeisStatus
 
205
geis_grail_token_add_region_term(GeisBackendToken     gbtoken,
 
206
                                 void                *context GEIS_UNUSED,
 
207
                                 GeisString           name,
 
208
                                 GeisFilterOperation  op,
 
209
                                 void                *value)
 
210
{
 
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)
 
215
  {
 
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;
 
220
  }
 
221
  return status;
 
222
}
 
223
 
 
224