~ubuntu-branches/ubuntu/raring/workrave/raring

« back to all changes in this revision

Viewing changes to common/bin/DBus-template.cc

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Jordi Mallach
  • Date: 2012-05-28 11:29:40 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20120528112940-bbbsjkk30fom9s8x
Tags: 1.9.909+abc941eb70-1
[ Francois Marier ]
* New upstream snapshot
  - Drop leak-fix patch (applied upstream)
  - Document how the tarball is built in README.source
* Build GNOME applets and use gsettings
* Massive update of Build-Depends as per configure.ac

* Update README.source with snapshot instructions
* Switch to machine-readable copyright file
* Update alioth git repo links
* Bump debhelper version to 9
* Bump Standards-Version to 3.9.3

[ Jordi Mallach ]
* Avoid references to GNU/Linux in manpage.
* Drop build dependency on libgnet-dev, it's obsolete and unneeded.
* Add myself to Uploaders.
* Rewrite d/rules into dh style.
  - Move all install tweaks to .install files.
  - Install manpages using dh_installman.
* As a side effect, the package installs arch-dependant data in the
  arch triplet directory; add the required Pre-Depends for m-a-support.
* Bring back GNOME Panel applet (for GNOME 3 fallback mode) and ship the
  new GNOME Shell extension (closes: #642514, #666100).
* Add private_dirs.patch: move libworkrave-private and GObject
  Introspection files to a private dir, so they are really out of the
  way, but disable it for now as it breaks the Shell extension.
* Move typelib out of the triplet dir as gobject-introspection is not
  M-A ready yet.
* Enable dh_autoreconf for the above patches.
* Add lintian overrides.
* Add necessary Breaks/Replaces as the xpm icon has moved to workrave-data.
* Prefix all debhelper files with package name.
* Suggest gnome-shell and gnome-panel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// DBus-template.hh --- DBUS template
2
 
//
3
 
// Copyright (C) 2007, 2008, 2009 Rob Caelers <robc@krandor.nl>
4
 
// All rights reserved.
5
 
//
6
 
// This program is free software: you can redistribute it and/or modify
7
 
// it under the terms of the GNU General Public License as published by
8
 
// the Free Software Foundation, either version 3 of the License, or
9
 
// (at your option) any later version.
10
 
//
11
 
// This program is distributed in the hope that it will be useful,
12
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
// GNU General Public License for more details.
15
 
//
16
 
// You should have received a copy of the GNU General Public License
17
 
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
//
19
 
 
20
 
\#ifdef HAVE_CONFIG_H
21
 
\#include "config.h"
22
 
\#endif
23
 
 
24
 
\#include <string>
25
 
\#include <list>
26
 
\#include <map>
27
 
\#include <deque>
28
 
 
29
 
\#include "DBus.hh"
30
 
\#include "DBusBinding.hh"
31
 
\#include "DBusException.hh"
32
 
\#include "${model.include_filename}"
33
 
 
34
 
using namespace std;
35
 
 
36
 
#for interface in $model.interfaces
37
 
 
38
 
#if interface.condition != ''
39
 
\#if $interface.condition
40
 
#end if
41
 
 
42
 
#for imp in interface.imports
43
 
#for ns in imp.namespaces
44
 
using namespace $ns;
45
 
#end for
46
 
#end for
47
 
 
48
 
#for imp in interface.imports
49
 
#for include in imp.includes
50
 
\#include "${include}"
51
 
#end for
52
 
#end for
53
 
 
54
 
class ${interface.qname}_Stub : public DBusBindingBase, public ${interface.qname}
55
 
{
56
 
private:
57
 
  typedef DBusMessage * (${interface.qname}_Stub::*DBusMethod)(void *object, DBusMessage *message);
58
 
 
59
 
  virtual DBusMessage *call(int method_num, void *object, DBusMessage *message);
60
 
   
61
 
  virtual DBusIntrospect *get_method_introspect()
62
 
  {
63
 
    return method_introspect;
64
 
  }
65
 
 
66
 
  virtual DBusIntrospect *get_signal_introspect()
67
 
  {
68
 
    return signal_introspect;
69
 
  }
70
 
 
71
 
public:
72
 
  ${interface.qname}_Stub(DBus *dbus);
73
 
  ~${interface.qname}_Stub();
74
 
  
75
 
  #for $m in interface.signals
76
 
  void ${m.qname}(const string &path, #slurp
77
 
  #set comma = ''
78
 
  #for p in m.params
79
 
  $comma $interface.type2csymbol(p.type) $p.name#slurp
80
 
  #set comma = ','
81
 
  #end for
82
 
  );
83
 
  #end for
84
 
 
85
 
  
86
 
private:
87
 
  #for $m in interface.methods
88
 
  DBusMessage *${m.qname}(void *object, DBusMessage *message);
89
 
  #end for
90
 
 
91
 
  #for enum in $interface.enums
92
 
  void get_${enum.qname}(DBusMessageIter *reader, ${enum.csymbol} *result);
93
 
  void put_${enum.qname}(DBusMessageIter *writer, const ${enum.csymbol} *result);
94
 
  #end for
95
 
 
96
 
  #for struct in $interface.structs
97
 
  void get_${struct.qname}(DBusMessageIter *reader, ${struct.csymbol} *result);
98
 
  void put_${struct.qname}(DBusMessageIter *writer, const ${struct.csymbol} *result);
99
 
  #end for
100
 
 
101
 
  #for seq in $interface.sequences
102
 
  void get_${seq.qname}(DBusMessageIter *reader, ${seq.csymbol} *result);
103
 
  void put_${seq.qname}(DBusMessageIter *writer, const ${seq.csymbol} *result);
104
 
  #end for
105
 
 
106
 
  #for dict in $interface.dictionaries
107
 
  void get_${dict.qname}(DBusMessageIter *reader, ${dict.csymbol} *result);
108
 
  void put_${dict.qname}(DBusMessageIter *writer, const ${dict.csymbol} *result);
109
 
  #end for
110
 
  
111
 
  static DBusMethod method_table[];
112
 
  static DBusIntrospect method_introspect[];
113
 
  static DBusIntrospect signal_introspect[];
114
 
};
115
 
 
116
 
 
117
 
${interface.qname} *${interface.qname}::instance(const DBus *dbus)
118
 
{
119
 
  ${interface.qname}_Stub *iface = NULL;
120
 
  DBusBindingBase *binding = dbus->find_binding("${interface.name}");
121
 
  
122
 
  if (binding != NULL)
123
 
    {
124
 
      iface = dynamic_cast<${interface.qname}_Stub *>(binding);
125
 
    }
126
 
 
127
 
  return iface;
128
 
}
129
 
 
130
 
${interface.qname}_Stub::${interface.qname}_Stub(DBus *dbus)
131
 
  : DBusBindingBase(dbus)
132
 
{
133
 
}
134
 
 
135
 
 
136
 
${interface.qname}_Stub::~${interface.qname}_Stub()
137
 
{
138
 
}
139
 
 
140
 
DBusMessage *
141
 
${interface.qname}_Stub::call(int method_num, void *object, DBusMessage *message)
142
 
{
143
 
  DBusMessage *ret = NULL;
144
 
  
145
 
  if (method_num >=0 && method_num < $len(interface.methods) )
146
 
    {
147
 
      DBusMethod m = method_table[method_num];
148
 
      if (m != NULL)
149
 
        {
150
 
          ret = (this->*m)(object, message);
151
 
        }
152
 
    }
153
 
  
154
 
  return ret;
155
 
}
156
 
 
157
 
#for enum in $interface.enums
158
 
 
159
 
void
160
 
${interface.qname}_Stub::get_${enum.qname}(DBusMessageIter *reader, ${enum.csymbol} *result)
161
 
{
162
 
  std::string value;
163
 
        int argtype = dbus_message_iter_get_arg_type(reader);
164
 
 
165
 
  if (argtype != DBUS_TYPE_STRING)
166
 
                throw DBusTypeException("Type mismatch. Excepted string");
167
 
 
168
 
  get_string(reader, &value);
169
 
  
170
 
  #set ifs = 'if'
171
 
  #for e in enum.values
172
 
  $ifs ("$e.name" == value)
173
 
    {
174
 
      *result = $e.csymbol;
175
 
    }
176
 
  #set $ifs = 'else if'
177
 
  #end for
178
 
  else
179
 
    {
180
 
      throw DBusTypeException("Illegal enum value");
181
 
    }
182
 
}
183
 
 
184
 
void
185
 
${interface.qname}_Stub::put_${enum.qname}(DBusMessageIter *writer, const ${enum.csymbol} *result)
186
 
{
187
 
  string value;
188
 
  switch (*result)
189
 
    {
190
 
    #for e in enum.values
191
 
    case $e.csymbol:
192
 
      value = "$e.name";
193
 
      break;
194
 
    #end for
195
 
    default:
196
 
      throw DBusTypeException("Illegal enum value");
197
 
    }
198
 
                
199
 
  put_string(writer, &value);
200
 
}
201
 
 
202
 
#end for
203
 
 
204
 
#for struct in $interface.structs
205
 
 
206
 
void
207
 
${interface.qname}_Stub::get_${struct.qname}(DBusMessageIter *reader, ${struct.csymbol} *result)
208
 
{
209
 
  DBusMessageIter it;
210
 
  dbus_message_iter_recurse(reader, &it);
211
 
 
212
 
  #for p in struct.fields
213
 
  #if p.type != p.ext_type
214
 
  $interface.type2csymbol(p.ext_type) _${p.name};
215
 
  #end if
216
 
  #end for
217
 
  
218
 
  #for p in struct.fields
219
 
  #if p.type != p.ext_type
220
 
  get_${p.ext_type}(&it, &_${p.name});
221
 
  #else
222
 
  get_${p.ext_type}(&it, ($interface.type2csymbol(p.ext_type) *) &(result->${p.name}));
223
 
  #end if
224
 
  #end for
225
 
 
226
 
  #for p in struct.fields
227
 
  #if p.type != p.ext_type
228
 
  result->${p.name} = ($interface.type2csymbol(p.type)) _${p.name};
229
 
  #end if
230
 
  #end for
231
 
    
232
 
  dbus_message_iter_next(reader);
233
 
}
234
 
 
235
 
void
236
 
${interface.qname}_Stub::put_${struct.qname}(DBusMessageIter *writer, const ${struct.csymbol} *result)
237
 
{
238
 
  DBusMessageIter it;
239
 
  dbus_bool_t ok;
240
 
  
241
 
  ok = dbus_message_iter_open_container(writer, DBUS_TYPE_STRUCT, NULL, &it);
242
 
  if (!ok)
243
 
    {
244
 
      throw DBusSystemException("Internal error");
245
 
    }
246
 
 
247
 
  #for p in struct.fields
248
 
  #if p.type != p.ext_type
249
 
  $interface.type2csymbol(p.ext_type) _${p.name} = ($interface.type2csymbol(p.ext_type))result->${p.name};
250
 
  #end if
251
 
  #end for
252
 
 
253
 
  #for p in struct.fields
254
 
  #if p.type != p.ext_type
255
 
  put_${p.ext_type}(&it, &_${p.name});
256
 
  #else
257
 
  put_${p.ext_type}(&it, ($interface.type2csymbol(p.type) *) &(result->${p.name}));
258
 
  #end if
259
 
  #end for
260
 
 
261
 
  ok = dbus_message_iter_close_container(writer, &it);
262
 
  if (!ok)
263
 
    {
264
 
      throw DBusSystemException("Internal error");
265
 
    }
266
 
}
267
 
 
268
 
#end for
269
 
 
270
 
#for seq in $interface.sequences
271
 
 
272
 
void
273
 
${interface.qname}_Stub::get_${seq.qname}(DBusMessageIter *reader, ${seq.csymbol} *result)
274
 
{
275
 
  DBusMessageIter it;
276
 
 
277
 
  dbus_message_iter_recurse(reader, &it);
278
 
  while (dbus_message_iter_has_next(&it))
279
 
  {
280
 
    $interface.type2csymbol(seq.data_type) tmp;
281
 
    get_${seq.data_type}(&it, &tmp);
282
 
    result->push_back(tmp);
283
 
  }
284
 
 
285
 
  dbus_message_iter_next(reader);
286
 
}
287
 
 
288
 
void
289
 
${interface.qname}_Stub::put_${seq.qname}(DBusMessageIter *writer, const ${seq.csymbol} *result)
290
 
{
291
 
  DBusMessageIter arr;
292
 
  ${seq.csymbol}::const_iterator it;
293
 
  dbus_bool_t ok;
294
 
  
295
 
  ok = dbus_message_iter_open_container(writer, DBUS_TYPE_ARRAY, "$interface.type2sig(seq.data_type)", &arr);
296
 
  if (!ok)
297
 
    {
298
 
      throw DBusSystemException("Internal error");
299
 
    }
300
 
 
301
 
  for(it = result->begin(); it != result->end(); it++)
302
 
  {
303
 
    put_${seq.data_type}(&arr, &(*it));
304
 
  }
305
 
  
306
 
  ok = dbus_message_iter_close_container(writer, &arr);
307
 
  if (!ok)
308
 
    {
309
 
      throw DBusSystemException("Internal error");
310
 
    }
311
 
}
312
 
#end for
313
 
 
314
 
 
315
 
#for dict in $interface.dictionaries
316
 
 
317
 
void
318
 
${interface.qname}_Stub::get_${dict.qname}(DBusMessageIter *reader, ${dict.csymbol} *result)
319
 
{
320
 
  DBusMessageIter arr_it;
321
 
  DBusMessageIter dict_it;
322
 
 
323
 
  dbus_message_iter_recurse(reader, &arr_it);
324
 
  while (dbus_message_iter_has_next(&arr_it))
325
 
  {
326
 
    $interface.type2csymbol(dict.key_type) key;
327
 
    $interface.type2csymbol(dict.value_type) value;
328
 
 
329
 
    dbus_message_iter_recurse(&arr_it, &dict_it);
330
 
    
331
 
    get_${dict.key_type}(&dict_it, &key);
332
 
    get_${dict.value_type}(&dict_it, &value);
333
 
 
334
 
    (*result)[key] = value;
335
 
 
336
 
    dbus_message_iter_next(&arr_it);
337
 
  }
338
 
 
339
 
  dbus_message_iter_next(reader);
340
 
}
341
 
 
342
 
 
343
 
void
344
 
${interface.qname}_Stub::put_${dict.qname}(DBusMessageIter *writer, const ${dict.csymbol} *result)
345
 
{
346
 
  DBusMessageIter arr_it;
347
 
  DBusMessageIter dict_it;
348
 
  ${dict.csymbol}::const_iterator it;
349
 
  dbus_bool_t ok;
350
 
  
351
 
  ok = dbus_message_iter_open_container(writer, DBUS_TYPE_ARRAY,
352
 
                                        "$interface.type2sig(dict.value_type)", &arr_it);
353
 
  if (!ok)
354
 
    {
355
 
      throw DBusSystemException("Internal error");
356
 
    }
357
 
 
358
 
  for (it = result->begin(); it != result->end(); it++)
359
 
    {
360
 
      ok = dbus_message_iter_open_container(&arr_it, DBUS_TYPE_DICT_ENTRY, NULL, &dict_it);
361
 
      if (!ok)
362
 
        {
363
 
          throw DBusSystemException("Internal error");
364
 
        }
365
 
    
366
 
      put_${dict.key_type}(&dict_it, &(it->first));
367
 
      put_${dict.value_type}(&dict_it, &(it->second));
368
 
 
369
 
      ok = dbus_message_iter_close_container(&arr_it, &dict_it);
370
 
      if (!ok)
371
 
        {
372
 
          throw DBusSystemException("Internal error");
373
 
        }
374
 
    }
375
 
  
376
 
  ok = dbus_message_iter_close_container(writer, &arr_it);
377
 
  if (!ok)
378
 
    {
379
 
      throw DBusSystemException("Internal error");
380
 
    }
381
 
}
382
 
 
383
 
 
384
 
#end for
385
 
 
386
 
#for method in $interface.methods
387
 
 
388
 
DBusMessage *
389
 
${interface.qname}_Stub::${method.name}(void *object, DBusMessage *message)
390
 
{
391
 
  DBusMessage *reply = NULL;
392
 
 
393
 
#if method.condition != ''
394
 
\#if $method.condition
395
 
#end if
396
 
  DBusMessageIter reader;
397
 
  DBusMessageIter writer;
398
 
  dbus_bool_t ok;
399
 
 
400
 
  try
401
 
    {
402
 
      #if method.csymbol != ""
403
 
      ${interface.csymbol} *dbus_object = (${interface.csymbol} *) object;
404
 
      #else
405
 
      (void) object;
406
 
      #end if
407
 
      
408
 
      #set have_in_args = False
409
 
      #for p in method.params
410
 
      #if p.direction == 'in'
411
 
      #set have_in_args = True
412
 
      #end if
413
 
      #if 'ptrptr' in p.hint
414
 
      $interface.type2csymbol(p.type) *${p.name} #slurp
415
 
      #else
416
 
      $interface.type2csymbol(p.type) ${p.name} #slurp
417
 
      #end if
418
 
      #if p.direction == 'bind'
419
 
      = ${p.bind} #slurp
420
 
      #end if
421
 
      ;
422
 
      #end for
423
 
      
424
 
      ok = dbus_message_iter_init(message, &reader);
425
 
      #if have_in_args
426
 
      if (!ok)
427
 
        {
428
 
          throw DBusSystemException("No parameters");
429
 
        }
430
 
      #end if
431
 
        
432
 
      #for arg in method.params:
433
 
      #if $arg.direction == 'in'
434
 
      get_${arg.type}(&reader, &${arg.name});
435
 
      #end if
436
 
      #end for
437
 
 
438
 
      #if method.csymbol != ""
439
 
      #if method.return_type() != 'void'
440
 
      $method.return_name() = dbus_object->${method.csymbol}( #slurp
441
 
      #else
442
 
      dbus_object->${method.csymbol}( #slurp
443
 
      #end if
444
 
      #set comma = ''
445
 
      #for p in method.params
446
 
      #if p.hint == [] or 'ref' in p.hint
447
 
      $comma $p.name#slurp
448
 
      #else if 'ptr' in p.hint
449
 
      $comma &$p.name#slurp
450
 
      #else if 'ptrptr' in p.hint
451
 
      $comma &$p.name#slurp
452
 
      #end if
453
 
      #set comma = ','
454
 
      #end for
455
 
      );
456
 
      #end if
457
 
                                                              
458
 
      reply = dbus_message_new_method_return(message);
459
 
      if (reply == NULL)
460
 
        {
461
 
          throw DBusSystemException("Internal error");
462
 
        }
463
 
                                                              
464
 
      dbus_message_iter_init_append(reply, &writer);
465
 
      
466
 
      #for arg in method.params:
467
 
      #if arg.direction == 'out'
468
 
      #if 'ptrptr' in p.hint
469
 
      put_${arg.type}(&writer, ${arg.name});
470
 
      #else                                                        
471
 
      put_${arg.type}(&writer, &${arg.name});
472
 
      #end if                                                         
473
 
      #end if
474
 
      #end for
475
 
  }
476
 
  catch (DBusException)
477
 
    {
478
 
      if (reply != NULL)
479
 
        {
480
 
          dbus_message_unref(reply);
481
 
        }
482
 
 
483
 
      throw;
484
 
    }
485
 
                                                          
486
 
#if method.condition != ''
487
 
\#else
488
 
 (void) object;
489
 
 
490
 
 reply = dbus_message_new_error(message,
491
 
                                "org.workrave.NotImplemented",
492
 
                                "This method is unavailable in current configuration");
493
 
\#endif
494
 
#end if                                                          
495
 
  return reply;
496
 
 
497
 
}
498
 
 
499
 
  
500
 
#end for
501
 
 
502
 
#for signal in interface.signals
503
 
void ${interface.qname}_Stub::${signal.qname}(const string &path, #slurp
504
 
#set comma = ''
505
 
#for p in signal.params
506
 
$comma $interface.type2csymbol(p.type) $p.name#slurp
507
 
#set comma = ','
508
 
#end for
509
 
)
510
 
{
511
 
  DBusMessage *msg = NULL;
512
 
  DBusMessageIter writer;
513
 
 
514
 
  msg = dbus_message_new_signal(path.c_str(),
515
 
                                "$interface.name",
516
 
                                "$signal.qname");
517
 
  if (msg == NULL)
518
 
    {
519
 
      throw DBusSystemException("Unable to send signal");
520
 
    }
521
 
 
522
 
  dbus_message_iter_init_append(msg, &writer);
523
 
 
524
 
  try
525
 
    {
526
 
      #for arg in signal.params:
527
 
      put_${arg.type}(&writer, &${arg.name});
528
 
      #end for
529
 
    }
530
 
  catch (DBusException &e)
531
 
    {
532
 
      dbus_message_unref(msg);
533
 
      throw;
534
 
    }
535
 
 
536
 
  send(msg);
537
 
}
538
 
 
539
 
#end for
540
 
  
541
 
${interface.qname}_Stub::DBusMethod ${interface.qname}_Stub::method_table[] = {
542
 
#for method in $interface.methods
543
 
  &${interface.qname}_Stub::$method.qname,
544
 
#end for
545
 
};
546
 
 
547
 
DBusIntrospect ${interface.qname}_Stub::method_introspect[] = {
548
 
#for method in $interface.methods
549
 
  { "$method.qname",
550
 
    "$method.sig()"
551
 
  },
552
 
#end for
553
 
  { NULL,
554
 
    NULL
555
 
  }
556
 
};
557
 
  
558
 
DBusIntrospect ${interface.qname}_Stub::signal_introspect[] = {
559
 
#for signal in $interface.signals
560
 
  { "$signal.qname",
561
 
    "$signal.sig()"
562
 
  },
563
 
#end for
564
 
  { NULL,
565
 
    NULL
566
 
  }
567
 
};
568
 
 
569
 
#if interface.condition != ''
570
 
 \#endif // $interface.condition
571
 
#end if
572
 
 
573
 
#end for
574
 
 
575
 
void init_${model.name}(DBus *dbus)
576
 
{
577
 
  #for interface in $model.interfaces
578
 
  #if interface.condition != ''
579
 
\#if $interface.condition
580
 
  #end if
581
 
  dbus->register_binding("$interface.name", new ${interface.qname}_Stub(dbus));
582
 
  #if interface.condition != ''
583
 
\#endif // $interface.condition
584
 
  #end if
585
 
  #end for
586
 
}