summaryrefslogtreecommitdiff
path: root/Source/DirectFB/lib/voodoo/ivoodooplayer_dispatcher.c
blob: bcf4711a83cfaf542a577909d4a75d4b2f70129c (plain)
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
   (c) Copyright 2000-2004  Convergence (integrated media) GmbH

   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>,
              Andreas Hundt <andi@fischlustig.de>,
              Sven Neumann <neo@directfb.org>,
              Ville Syrjälä <syrjala@sci.fi> and
              Claudio Ciccani <klan@users.sf.net>.

   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/debug.h>
#include <direct/interface.h>
#include <direct/messages.h>

#include <voodoo/ivoodooplayer.h>

#include <voodoo/interface.h>
#include <voodoo/manager.h>
#include <voodoo/message.h>

#include "ivoodooplayer_dispatcher.h"

static DirectResult Probe( void );
static DirectResult Construct( IVoodooPlayer    *thiz,
                               VoodooManager    *manager,
                               VoodooInstanceID *ret_instance );

#include <direct/interface_implementation.h>

DIRECT_INTERFACE_IMPLEMENTATION( IVoodooPlayer, Dispatcher )


/**************************************************************************************************/

/*
 * private data struct of IVoodooPlayer_Dispatcher
 */
typedef struct {
     int                    ref;          /* reference counter */

     IVoodooPlayer         *real;

     VoodooInstanceID       self;         /* The instance of this dispatcher itself. */
} IVoodooPlayer_Dispatcher_data;

/**************************************************************************************************/

static void
IVoodooPlayer_Dispatcher_Destruct( IVoodooPlayer *thiz )
{
     D_DEBUG( "%s (%p)\n", __FUNCTION__, thiz );

     DIRECT_DEALLOCATE_INTERFACE( thiz );
}

/**************************************************************************************************/

static DirectResult
IVoodooPlayer_Dispatcher_AddRef( IVoodooPlayer *thiz )
{
     DIRECT_INTERFACE_GET_DATA(IVoodooPlayer_Dispatcher)

     data->ref++;

     return DR_OK;
}

static DirectResult
IVoodooPlayer_Dispatcher_Release( IVoodooPlayer *thiz )
{
     DIRECT_INTERFACE_GET_DATA(IVoodooPlayer_Dispatcher)

     if (--data->ref == 0)
          IVoodooPlayer_Dispatcher_Destruct( thiz );

     return DR_OK;
}

static DirectResult
IVoodooPlayer_Dispatcher_GetApps( IVoodooPlayer        *thiz,
                                  unsigned int          max_num,
                                  unsigned int         *ret_num,
                                  VoodooAppDescription *ret_applications )
{
     return DR_UNIMPLEMENTED;
}

static DirectResult
IVoodooPlayer_Dispatcher_LaunchApp( IVoodooPlayer *thiz,
                                    const u8       app_uuid[16],
                                    const u8       player_uuid[16],
                                    u8             ret_instance_uuid[16] )
{
     return DR_UNIMPLEMENTED;
}

static DirectResult
IVoodooPlayer_Dispatcher_StopInstance( IVoodooPlayer *thiz,
                                       const u8       instance_uuid[16] )
{
     return DR_UNIMPLEMENTED;
}

/**************************************************************************************************/

static DirectResult
Dispatch_GetApps( IVoodooPlayer *thiz, IVoodooPlayer *real,
                  VoodooManager *manager, VoodooRequestMessage *msg )
{
     DirectResult          ret;
     unsigned int          max_num;
     VoodooMessageParser   parser;
     unsigned int          num;
     VoodooAppDescription *apps;

     DIRECT_INTERFACE_GET_DATA(IVoodooPlayer_Dispatcher)

     VOODOO_PARSER_BEGIN( parser, msg );
     VOODOO_PARSER_GET_UINT( parser, max_num );
     VOODOO_PARSER_END( parser );

     if (max_num > 1000)
          return DR_LIMITEXCEEDED;

     apps = D_MALLOC( max_num * sizeof(VoodooAppDescription) );
     if (!apps)
          return D_OOM();

     ret = real->GetApps( real, max_num, &num, apps );
     if (ret == DR_OK) {
          if (num > 0) {
               ret = voodoo_manager_respond( manager, true, msg->header.serial,
                                             ret, VOODOO_INSTANCE_NONE,
                                             VMBT_UINT, num,
                                             VMBT_DATA, num * sizeof(VoodooAppDescription), apps,
                                             VMBT_NONE );
          }
          else {
               ret = voodoo_manager_respond( manager, true, msg->header.serial,
                                             ret, VOODOO_INSTANCE_NONE,
                                             VMBT_UINT, num,
                                             VMBT_NONE );
          }
     }

     D_FREE( apps );

     return ret;
}

static DirectResult
Dispatch_LaunchApp( IVoodooPlayer *thiz, IVoodooPlayer *real,
                    VoodooManager *manager, VoodooRequestMessage *msg )
{
     DirectResult             ret;
     VoodooMessageParser      parser;
     const u8                *app_uuid;
     const u8                *player_uuid;
     u8                       instance_uuid[16];

     DIRECT_INTERFACE_GET_DATA(IVoodooPlayer_Dispatcher)

     VOODOO_PARSER_BEGIN( parser, msg );
     VOODOO_PARSER_GET_DATA( parser, app_uuid );
     VOODOO_PARSER_GET_DATA( parser, player_uuid );
     VOODOO_PARSER_END( parser );

     ret = real->LaunchApp( real, app_uuid, player_uuid, instance_uuid );

     return voodoo_manager_respond( manager, true, msg->header.serial,
                                    ret, VOODOO_INSTANCE_NONE,
                                    VMBT_DATA, 16, instance_uuid,
                                    VMBT_NONE );
}

static DirectResult
Dispatch_StopInstance( IVoodooPlayer *thiz, IVoodooPlayer *real,
                       VoodooManager *manager, VoodooRequestMessage *msg )
{
     DirectResult         ret;
     VoodooMessageParser  parser;
     const u8            *instance_uuid;

     DIRECT_INTERFACE_GET_DATA(IVoodooPlayer_Dispatcher)

     VOODOO_PARSER_BEGIN( parser, msg );
     VOODOO_PARSER_GET_DATA( parser, instance_uuid );
     VOODOO_PARSER_END( parser );

     ret = real->StopInstance( real, instance_uuid );

     return voodoo_manager_respond( manager, true, msg->header.serial,
                                    ret, VOODOO_INSTANCE_NONE,
                                    VMBT_NONE );
}

static DirectResult
Dispatch_WaitInstance( IVoodooPlayer *thiz, IVoodooPlayer *real,
                       VoodooManager *manager, VoodooRequestMessage *msg )
{
     DirectResult         ret;
     VoodooMessageParser  parser;
     const u8            *instance_uuid;

     DIRECT_INTERFACE_GET_DATA(IVoodooPlayer_Dispatcher)

     VOODOO_PARSER_BEGIN( parser, msg );
     VOODOO_PARSER_GET_DATA( parser, instance_uuid );
     VOODOO_PARSER_END( parser );

     ret = real->WaitInstance( real, instance_uuid );

     return voodoo_manager_respond( manager, true, msg->header.serial,
                                    ret, VOODOO_INSTANCE_NONE,
                                    VMBT_NONE );
}

static DirectResult
Dispatch_GetInstances( IVoodooPlayer *thiz, IVoodooPlayer *real,
                       VoodooManager *manager, VoodooRequestMessage *msg )
{
     DirectResult                  ret;
     unsigned int                  max_num;
     VoodooMessageParser           parser;
     unsigned int                  num;
     VoodooAppInstanceDescription *instances;

     DIRECT_INTERFACE_GET_DATA(IVoodooPlayer_Dispatcher)

     VOODOO_PARSER_BEGIN( parser, msg );
     VOODOO_PARSER_GET_UINT( parser, max_num );
     VOODOO_PARSER_END( parser );

     if (max_num > 1000)
          return DR_LIMITEXCEEDED;

     instances = D_MALLOC( max_num * sizeof(VoodooAppInstanceDescription) );
     if (!instances)
          return D_OOM();

     ret = real->GetInstances( real, max_num, &num, instances );
     if (ret == DR_OK) {
          if (num > 0) {
               ret = voodoo_manager_respond( manager, true, msg->header.serial,
                                             ret, VOODOO_INSTANCE_NONE,
                                             VMBT_UINT, num,
                                             VMBT_DATA, num * sizeof(VoodooAppInstanceDescription), instances,
                                             VMBT_NONE );
          }
          else {
               ret = voodoo_manager_respond( manager, true, msg->header.serial,
                                             ret, VOODOO_INSTANCE_NONE,
                                             VMBT_UINT, num,
                                             VMBT_NONE );
          }
     }

     D_FREE( instances );

     return ret;
}

static DirectResult
Dispatch( void *dispatcher, void *real, VoodooManager *manager, VoodooRequestMessage *msg )
{
     D_DEBUG( "IVoodooPlayer/Dispatcher: "
              "Handling request for instance %u with method %u...\n", msg->instance, msg->method );

     switch (msg->method) {
          case IVOODOOPLAYER_METHOD_ID_GetApps:
               return Dispatch_GetApps( dispatcher, real, manager, msg );

          case IVOODOOPLAYER_METHOD_ID_LaunchApp:
               return Dispatch_LaunchApp( dispatcher, real, manager, msg );

          case IVOODOOPLAYER_METHOD_ID_StopInstance:
               return Dispatch_StopInstance( dispatcher, real, manager, msg );

          case IVOODOOPLAYER_METHOD_ID_WaitInstance:
               return Dispatch_WaitInstance( dispatcher, real, manager, msg );

          case IVOODOOPLAYER_METHOD_ID_GetInstances:
               return Dispatch_GetInstances( dispatcher, real, manager, msg );
     }

     return DR_NOSUCHMETHOD;
}

/**************************************************************************************************/

static DirectResult
Probe()
{
     /* This implementation has to be loaded explicitly. */
     return DR_UNSUPPORTED;
}

/*
 * Constructor
 *
 * Fills in function pointers and intializes data structure.
 */
static DirectResult
Construct( IVoodooPlayer *thiz, VoodooManager *manager, VoodooInstanceID *ret_instance )
{
     DirectResult      ret;
     IVoodooPlayer    *real;
     VoodooInstanceID  instance;

     DIRECT_ALLOCATE_INTERFACE_DATA(thiz, IVoodooPlayer_Dispatcher)

     ret = VoodooPlayerCreate( &real );
     if (ret) {
          DIRECT_DEALLOCATE_INTERFACE( thiz );
          return ret;
     }

     ret = voodoo_manager_register_local( manager, VOODOO_INSTANCE_NONE, thiz, real, Dispatch, &instance );
     if (ret) {
          real->Release( real );
          DIRECT_DEALLOCATE_INTERFACE( thiz );
          return ret;
     }

     *ret_instance = instance;

     data->ref  = 1;
     data->real = real;
     data->self = instance;

     thiz->AddRef       = IVoodooPlayer_Dispatcher_AddRef;
     thiz->Release      = IVoodooPlayer_Dispatcher_Release;
     thiz->GetApps      = IVoodooPlayer_Dispatcher_GetApps;
     thiz->LaunchApp    = IVoodooPlayer_Dispatcher_LaunchApp;
     thiz->StopInstance = IVoodooPlayer_Dispatcher_StopInstance;

     return DR_OK;
}