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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
/*
(c) Copyright 2006-2007 directfb.org
All rights reserved.
Written by Denis Oliver Kropp <dok@directfb.org>.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <direct/interface.h>
#include <direct/memcpy.h>
#include <direct/messages.h>
#include <fusion/fusion.h>
#include <fusion/shmalloc.h>
#include <sawman.h>
#include <sawman_internal.h>
#include "isawman.h"
#include "isawmanmanager.h"
static ReactionResult ISaWMan_Tier_Update( const void *msg_data,
void *ctx );
/**********************************************************************************************************************/
static void
ISaWMan_Destruct( ISaWMan *thiz )
{
ISaWMan_data *data = thiz->priv;
fusion_reactor_detach( ((SaWManTier*) data->sawman->tiers)->reactor, &data->reaction );
pthread_mutex_destroy( &data->lock );
pthread_cond_destroy( &data->cond );
dfb_updates_deinit( &data->updates );
DIRECT_DEALLOCATE_INTERFACE( thiz );
}
/**********************************************************************************************************************/
static DirectResult
ISaWMan_AddRef( ISaWMan *thiz )
{
DIRECT_INTERFACE_GET_DATA( ISaWMan )
data->ref++;
return DFB_OK;
}
static DirectResult
ISaWMan_Release( ISaWMan *thiz )
{
DIRECT_INTERFACE_GET_DATA( ISaWMan )
if (--data->ref == 0)
ISaWMan_Destruct( thiz );
return DFB_OK;
}
/**********************************************************************************************************************/
static DirectResult
ISaWMan_Start( ISaWMan *thiz,
const char *name,
pid_t *ret_pid )
{
int ret;
char *tmp = NULL;
SaWMan *sawman;
DIRECT_INTERFACE_GET_DATA( ISaWMan )
if (!name)
return DFB_INVARG;
sawman = data->sawman;
D_MAGIC_ASSERT( sawman, SaWMan );
ret = sawman_lock( sawman );
if (ret)
goto out;
tmp = SHSTRDUP( sawman->shmpool, name );
if (!tmp) {
ret = D_OOSHM();
goto out;
}
ret = sawman_call( sawman, SWMCID_START, tmp );
if (ret < 0) {
if (ret_pid)
*ret_pid = -ret;
ret = DFB_OK;
}
out:
if (tmp)
SHFREE( sawman->shmpool, tmp );
sawman_unlock( sawman );
return ret;
}
static DirectResult
ISaWMan_Stop( ISaWMan *thiz,
pid_t pid )
{
DirectResult ret;
SaWMan *sawman;
DIRECT_INTERFACE_GET_DATA( ISaWMan )
sawman = data->sawman;
D_MAGIC_ASSERT( sawman, SaWMan );
ret = sawman_lock( sawman );
if (ret)
return ret;
ret = sawman_call( sawman, SWMCID_STOP, (void*)(long) pid );
sawman_unlock( sawman );
return ret;
}
static DirectResult
ISaWMan_ReturnKeyEvent( ISaWMan *thiz,
DFBWindowEvent *event )
{
DirectResult ret;
SaWMan *sawman;
DIRECT_INTERFACE_GET_DATA( ISaWManManager )
if (!event)
return DFB_INVARG;
/* Only key events! */
if (event->type != DWET_KEYDOWN && event->type != DWET_KEYUP)
return DFB_UNSUPPORTED;
/* Don't return same event twice! 'flags' is only valid for KEY events. */
if (event->flags & DWEF_RETURNED)
return DFB_LIMITEXCEEDED;
event->flags |= DWEF_RETURNED;
sawman = data->sawman;
D_MAGIC_ASSERT( sawman, SaWMan );
ret = sawman_lock( sawman );
if (ret)
return ret;
if (sawman->unselkeys_window)
ret = sawman_post_event( sawman, sawman->unselkeys_window, event );
sawman_unlock( sawman );
return ret;
}
static DirectResult
ISaWMan_CreateManager( ISaWMan *thiz,
const SaWManCallbacks *callbacks,
void *context,
ISaWManManager **ret_manager )
{
DirectResult ret;
ISaWManManager *manager;
SaWMan *sawman;
DIRECT_INTERFACE_GET_DATA( ISaWMan )
if (!callbacks || !ret_manager)
return DFB_INVARG;
sawman = data->sawman;
D_MAGIC_ASSERT( sawman, SaWMan );
ret = sawman_lock( sawman );
if (ret)
return ret;
ret = sawman_register( sawman, callbacks, context );
if (ret)
goto out;
DIRECT_ALLOCATE_INTERFACE( manager, ISaWManManager );
ret = ISaWManManager_Construct( manager, data->sawman, data->process );
if (ret) {
/* FIXME: sawman_unregister! */
goto out;
}
*ret_manager = manager;
/*
* Attach to existing entities.
*/
if (callbacks->ProcessAdded) {
SaWManProcess *process;
direct_list_foreach (process, sawman->processes) {
D_MAGIC_ASSERT( process, SaWManProcess );
callbacks->ProcessAdded( context, process );
}
}
if (callbacks->WindowAdded) {
SaWManWindow *window;
SaWManWindowInfo *info;
info = &sawman->callback.info;
direct_list_foreach (window, sawman->windows) {
D_MAGIC_ASSERT( window, SaWManWindow );
info->handle = (SaWManWindowHandle)window;
info->caps = window->caps;
SAWMANWINDOWCONFIG_COPY( &info->config, &window->window->config )
callbacks->WindowAdded( context, info );
}
}
out:
sawman_unlock( sawman );
return ret;
}
static DirectResult
ISaWMan_GetUpdates( ISaWMan *thiz,
DFBWindowStackingClass stacking_class,
DFBRegion *ret_updates,
unsigned int *ret_num )
{
DIRECT_INTERFACE_GET_DATA( ISaWMan )
if (!ret_updates || !ret_num)
return DFB_INVARG;
pthread_mutex_lock( &data->lock );
while (!data->updates.num_regions) {
pthread_cond_wait( &data->cond, &data->lock );
}
direct_memcpy( ret_updates, data->updates.regions, sizeof(DFBRegion) * data->updates.num_regions );
*ret_num = data->updates.num_regions;
dfb_updates_reset( &data->updates );
pthread_mutex_unlock( &data->lock );
return DFB_OK;
}
/**********************************************************************************************************************/
DirectResult
ISaWMan_Construct( ISaWMan *thiz,
SaWMan *sawman,
SaWManProcess *process )
{
DIRECT_ALLOCATE_INTERFACE_DATA( thiz, ISaWMan )
data->ref = 1;
data->sawman = sawman;
data->process = process;
pthread_mutex_init( &data->lock, NULL );
pthread_cond_init( &data->cond, NULL );
dfb_updates_init( &data->updates, data->updates_regions, D_ARRAY_SIZE(data->updates_regions) );
// fusion_reactor_attach_channel( ((SaWManTier*) sawman->tiers->next)->reactor,
// SAWMAN_TIER_UPDATE, ISaWMan_Tier_Update, data, &data->reaction );
thiz->AddRef = ISaWMan_AddRef;
thiz->Release = ISaWMan_Release;
thiz->Start = ISaWMan_Start;
thiz->Stop = ISaWMan_Stop;
thiz->ReturnKeyEvent = ISaWMan_ReturnKeyEvent;
thiz->CreateManager = ISaWMan_CreateManager;
thiz->GetUpdates = ISaWMan_GetUpdates;
return DFB_OK;
}
/**********************************************************************************************************************/
static ReactionResult
ISaWMan_Tier_Update( const void *msg_data,
void *ctx )
{
int i;
const SaWManTierUpdate *update = msg_data;
ISaWMan_data *data = ctx;
pthread_mutex_lock( &data->lock );
for (i=0; i<update->num_regions; i++) {
dfb_updates_add( &data->updates, &update->regions[i] );
}
pthread_mutex_unlock( &data->lock );
pthread_cond_broadcast( &data->cond );
return RS_OK;
}
|