~leighman/ubuntu/raring/workrave/fix-desktop-file-2

« back to all changes in this revision

Viewing changes to backend/src/DBusWorkrave.cc

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2013-01-24 11:04:41 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: package-import@ubuntu.com-20130124110441-t06q3xlc7mp4406p
Tags: upstream-1.10
ImportĀ upstreamĀ versionĀ 1.10

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, 2011 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 <stdlib.h>
 
30
#include <gio/gio.h>
 
31
 
 
32
#include "DBus-gio.hh"
 
33
#include "DBusBinding-gio.hh"
 
34
#include "DBusException.hh"
 
35
#include "DBusWorkrave.hh"
 
36
 
 
37
using namespace std;
 
38
 
 
39
 
 
40
 
 
41
using namespace workrave;
 
42
 
 
43
#include "Core.hh"
 
44
 
 
45
class org_workrave_CoreInterface_Stub : public DBusBindingBase, public org_workrave_CoreInterface
 
46
{
 
47
private:
 
48
  typedef void (org_workrave_CoreInterface_Stub::*DBusMethodPointer)(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
49
 
 
50
  struct DBusMethod
 
51
  {
 
52
    const string name;
 
53
    DBusMethodPointer fn;
 
54
  };
 
55
 
 
56
  virtual void call(const std::string &method_name, void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
57
 
 
58
  virtual const char *get_interface_introspect()
 
59
  {
 
60
    return interface_introspect;
 
61
  }
 
62
 
 
63
public:
 
64
  org_workrave_CoreInterface_Stub(DBus *dbus);
 
65
  ~org_workrave_CoreInterface_Stub();
 
66
 
 
67
  void MicrobreakChanged(const string &path,        std::string progress  );
 
68
  void RestbreakChanged(const string &path,        std::string progress  );
 
69
  void DailylimitChanged(const string &path,        std::string progress  );
 
70
 
 
71
 
 
72
private:
 
73
  void SetOperationMode(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
74
  void GetOperationMode(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
75
  void SetUsageMode(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
76
  void GetUsageMode(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
77
  void ReportActivity(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
78
  void IsTimerRunning(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
79
  void GetTimerIdle(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
80
  void GetTimerElapsed(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
81
  void GetTimerOverdue(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
82
  void GetTime(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
83
  void IsActive(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
84
  void PostponeBreak(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
85
  void SkipBreak(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
86
 
 
87
  void get_operation_mode(GVariant *variant, OperationMode *result);
 
88
  GVariant *put_operation_mode(const OperationMode *result);
 
89
  void get_usage_mode(GVariant *variant, UsageMode *result);
 
90
  GVariant *put_usage_mode(const UsageMode *result);
 
91
  void get_break_id(GVariant *variant, BreakId *result);
 
92
  GVariant *put_break_id(const BreakId *result);
 
93
 
 
94
 
 
95
 
 
96
 
 
97
  static const DBusMethod method_table[];
 
98
  static const char *interface_introspect;
 
99
};
 
100
 
 
101
 
 
102
org_workrave_CoreInterface *org_workrave_CoreInterface::instance(const DBus *dbus)
 
103
{
 
104
  org_workrave_CoreInterface_Stub *iface = NULL;
 
105
  DBusBindingBase *binding = dbus->find_binding("org.workrave.CoreInterface");
 
106
 
 
107
  if (binding != NULL)
 
108
    {
 
109
      iface = dynamic_cast<org_workrave_CoreInterface_Stub *>(binding);
 
110
    }
 
111
 
 
112
  return iface;
 
113
}
 
114
 
 
115
org_workrave_CoreInterface_Stub::org_workrave_CoreInterface_Stub(DBus *dbus)
 
116
  : DBusBindingBase(dbus)
 
117
{
 
118
}
 
119
 
 
120
org_workrave_CoreInterface_Stub::~org_workrave_CoreInterface_Stub()
 
121
{
 
122
}
 
123
 
 
124
void
 
125
org_workrave_CoreInterface_Stub::call(const std::string &method_name, void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
126
{
 
127
  const DBusMethod *table = method_table;
 
128
  while (table->fn != NULL)
 
129
    {
 
130
      if (method_name == table->name)
 
131
        {
 
132
          DBusMethodPointer ptr = table->fn;
 
133
          if (ptr != NULL)
 
134
            {
 
135
              (this->*ptr)(object, invocation, sender, inargs);
 
136
            }
 
137
          return;
 
138
        }
 
139
      table++;
 
140
    }
 
141
  throw DBusUsageException(std::string("No such member:") + method_name );
 
142
}
 
143
 
 
144
 
 
145
void
 
146
org_workrave_CoreInterface_Stub::get_operation_mode(GVariant *variant, OperationMode *result)
 
147
{
 
148
  std::string value;
 
149
 
 
150
  get_string(variant, &value);
 
151
 
 
152
  if ("normal" == value)
 
153
    {
 
154
      *result = OPERATION_MODE_NORMAL;
 
155
    }
 
156
  else if ("suspended" == value)
 
157
    {
 
158
      *result = OPERATION_MODE_SUSPENDED;
 
159
    }
 
160
  else if ("quiet" == value)
 
161
    {
 
162
      *result = OPERATION_MODE_QUIET;
 
163
    }
 
164
  else
 
165
    {
 
166
      throw DBusTypeException("Illegal enum value");
 
167
    }
 
168
}
 
169
 
 
170
GVariant *
 
171
org_workrave_CoreInterface_Stub::put_operation_mode(const OperationMode *result)
 
172
{
 
173
  string value;
 
174
  switch (*result)
 
175
    {
 
176
    case OPERATION_MODE_NORMAL:
 
177
      value = "normal";
 
178
      break;
 
179
    case OPERATION_MODE_SUSPENDED:
 
180
      value = "suspended";
 
181
      break;
 
182
    case OPERATION_MODE_QUIET:
 
183
      value = "quiet";
 
184
      break;
 
185
    default:
 
186
      throw DBusTypeException("Illegal enum value");
 
187
    }
 
188
 
 
189
  return put_string(&value);
 
190
}
 
191
 
 
192
 
 
193
void
 
194
org_workrave_CoreInterface_Stub::get_usage_mode(GVariant *variant, UsageMode *result)
 
195
{
 
196
  std::string value;
 
197
 
 
198
  get_string(variant, &value);
 
199
 
 
200
  if ("normal" == value)
 
201
    {
 
202
      *result = USAGE_MODE_NORMAL;
 
203
    }
 
204
  else if ("reading" == value)
 
205
    {
 
206
      *result = USAGE_MODE_READING;
 
207
    }
 
208
  else
 
209
    {
 
210
      throw DBusTypeException("Illegal enum value");
 
211
    }
 
212
}
 
213
 
 
214
GVariant *
 
215
org_workrave_CoreInterface_Stub::put_usage_mode(const UsageMode *result)
 
216
{
 
217
  string value;
 
218
  switch (*result)
 
219
    {
 
220
    case USAGE_MODE_NORMAL:
 
221
      value = "normal";
 
222
      break;
 
223
    case USAGE_MODE_READING:
 
224
      value = "reading";
 
225
      break;
 
226
    default:
 
227
      throw DBusTypeException("Illegal enum value");
 
228
    }
 
229
 
 
230
  return put_string(&value);
 
231
}
 
232
 
 
233
 
 
234
void
 
235
org_workrave_CoreInterface_Stub::get_break_id(GVariant *variant, BreakId *result)
 
236
{
 
237
  std::string value;
 
238
 
 
239
  get_string(variant, &value);
 
240
 
 
241
  if ("microbreak" == value)
 
242
    {
 
243
      *result = BREAK_ID_MICRO_BREAK;
 
244
    }
 
245
  else if ("restbreak" == value)
 
246
    {
 
247
      *result = BREAK_ID_REST_BREAK;
 
248
    }
 
249
  else if ("dailylimit" == value)
 
250
    {
 
251
      *result = BREAK_ID_DAILY_LIMIT;
 
252
    }
 
253
  else
 
254
    {
 
255
      throw DBusTypeException("Illegal enum value");
 
256
    }
 
257
}
 
258
 
 
259
GVariant *
 
260
org_workrave_CoreInterface_Stub::put_break_id(const BreakId *result)
 
261
{
 
262
  string value;
 
263
  switch (*result)
 
264
    {
 
265
    case BREAK_ID_MICRO_BREAK:
 
266
      value = "microbreak";
 
267
      break;
 
268
    case BREAK_ID_REST_BREAK:
 
269
      value = "restbreak";
 
270
      break;
 
271
    case BREAK_ID_DAILY_LIMIT:
 
272
      value = "dailylimit";
 
273
      break;
 
274
    default:
 
275
      throw DBusTypeException("Illegal enum value");
 
276
    }
 
277
 
 
278
  return put_string(&value);
 
279
}
 
280
 
 
281
 
 
282
 
 
283
 
 
284
 
 
285
 
 
286
 
 
287
void
 
288
org_workrave_CoreInterface_Stub::SetOperationMode(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
289
{
 
290
  (void) sender;
 
291
 
 
292
  try
 
293
    {
 
294
      Core *dbus_object = (Core *) object;
 
295
 
 
296
      OperationMode p_mode       ;
 
297
 
 
298
      gsize num_in_args = g_variant_n_children(inargs);
 
299
      if (num_in_args != 1)
 
300
        {
 
301
          throw DBusSystemException("Incorrect numer of in-parameters");
 
302
        }
 
303
 
 
304
      GVariant *v_mode = g_variant_get_child_value(inargs, 0);
 
305
      get_operation_mode(v_mode, &p_mode);
 
306
 
 
307
      dbus_object->set_operation_mode( 
 
308
       p_mode      );
 
309
 
 
310
      GVariant *out = NULL;
 
311
 
 
312
      g_dbus_method_invocation_return_value(invocation, out);
 
313
    }
 
314
  catch (DBusException)
 
315
    {
 
316
      throw;
 
317
    }
 
318
 
 
319
}
 
320
 
 
321
 
 
322
 
 
323
void
 
324
org_workrave_CoreInterface_Stub::GetOperationMode(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
325
{
 
326
  (void) sender;
 
327
 
 
328
  try
 
329
    {
 
330
      Core *dbus_object = (Core *) object;
 
331
 
 
332
      OperationMode p_mode       ;
 
333
 
 
334
      gsize num_in_args = g_variant_n_children(inargs);
 
335
      if (num_in_args != 0)
 
336
        {
 
337
          throw DBusSystemException("Incorrect numer of in-parameters");
 
338
        }
 
339
 
 
340
 
 
341
      p_mode = dbus_object->get_operation_mode( 
 
342
      );
 
343
 
 
344
      GVariantBuilder builder;
 
345
      g_variant_builder_init(&builder, (GVariantType*)"(s)");
 
346
 
 
347
      GVariant *v_mode = put_operation_mode(&p_mode);
 
348
      g_variant_builder_add_value(&builder, v_mode);
 
349
 
 
350
      GVariant *out = g_variant_builder_end(&builder);
 
351
 
 
352
      g_dbus_method_invocation_return_value(invocation, out);
 
353
    }
 
354
  catch (DBusException)
 
355
    {
 
356
      throw;
 
357
    }
 
358
 
 
359
}
 
360
 
 
361
 
 
362
 
 
363
void
 
364
org_workrave_CoreInterface_Stub::SetUsageMode(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
365
{
 
366
  (void) sender;
 
367
 
 
368
  try
 
369
    {
 
370
      Core *dbus_object = (Core *) object;
 
371
 
 
372
      UsageMode p_mode       ;
 
373
 
 
374
      gsize num_in_args = g_variant_n_children(inargs);
 
375
      if (num_in_args != 1)
 
376
        {
 
377
          throw DBusSystemException("Incorrect numer of in-parameters");
 
378
        }
 
379
 
 
380
      GVariant *v_mode = g_variant_get_child_value(inargs, 0);
 
381
      get_usage_mode(v_mode, &p_mode);
 
382
 
 
383
      dbus_object->set_usage_mode( 
 
384
       p_mode      );
 
385
 
 
386
      GVariant *out = NULL;
 
387
 
 
388
      g_dbus_method_invocation_return_value(invocation, out);
 
389
    }
 
390
  catch (DBusException)
 
391
    {
 
392
      throw;
 
393
    }
 
394
 
 
395
}
 
396
 
 
397
 
 
398
 
 
399
void
 
400
org_workrave_CoreInterface_Stub::GetUsageMode(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
401
{
 
402
  (void) sender;
 
403
 
 
404
  try
 
405
    {
 
406
      Core *dbus_object = (Core *) object;
 
407
 
 
408
      UsageMode p_mode       ;
 
409
 
 
410
      gsize num_in_args = g_variant_n_children(inargs);
 
411
      if (num_in_args != 0)
 
412
        {
 
413
          throw DBusSystemException("Incorrect numer of in-parameters");
 
414
        }
 
415
 
 
416
 
 
417
      p_mode = dbus_object->get_usage_mode( 
 
418
      );
 
419
 
 
420
      GVariantBuilder builder;
 
421
      g_variant_builder_init(&builder, (GVariantType*)"(s)");
 
422
 
 
423
      GVariant *v_mode = put_usage_mode(&p_mode);
 
424
      g_variant_builder_add_value(&builder, v_mode);
 
425
 
 
426
      GVariant *out = g_variant_builder_end(&builder);
 
427
 
 
428
      g_dbus_method_invocation_return_value(invocation, out);
 
429
    }
 
430
  catch (DBusException)
 
431
    {
 
432
      throw;
 
433
    }
 
434
 
 
435
}
 
436
 
 
437
 
 
438
 
 
439
void
 
440
org_workrave_CoreInterface_Stub::ReportActivity(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
441
{
 
442
  (void) sender;
 
443
 
 
444
  try
 
445
    {
 
446
      Core *dbus_object = (Core *) object;
 
447
 
 
448
      std::string p_who       ;
 
449
      bool p_act       ;
 
450
 
 
451
      gsize num_in_args = g_variant_n_children(inargs);
 
452
      if (num_in_args != 2)
 
453
        {
 
454
          throw DBusSystemException("Incorrect numer of in-parameters");
 
455
        }
 
456
 
 
457
      GVariant *v_who = g_variant_get_child_value(inargs, 0);
 
458
      get_string(v_who, &p_who);
 
459
      GVariant *v_act = g_variant_get_child_value(inargs, 1);
 
460
      get_bool(v_act, &p_act);
 
461
 
 
462
      dbus_object->report_external_activity( 
 
463
       p_who      , p_act      );
 
464
 
 
465
      GVariant *out = NULL;
 
466
 
 
467
      g_dbus_method_invocation_return_value(invocation, out);
 
468
    }
 
469
  catch (DBusException)
 
470
    {
 
471
      throw;
 
472
    }
 
473
 
 
474
}
 
475
 
 
476
 
 
477
 
 
478
void
 
479
org_workrave_CoreInterface_Stub::IsTimerRunning(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
480
{
 
481
  (void) sender;
 
482
 
 
483
  try
 
484
    {
 
485
      Core *dbus_object = (Core *) object;
 
486
 
 
487
      BreakId p_timer_id       ;
 
488
      bool p_value       ;
 
489
 
 
490
      gsize num_in_args = g_variant_n_children(inargs);
 
491
      if (num_in_args != 1)
 
492
        {
 
493
          throw DBusSystemException("Incorrect numer of in-parameters");
 
494
        }
 
495
 
 
496
      GVariant *v_timer_id = g_variant_get_child_value(inargs, 0);
 
497
      get_break_id(v_timer_id, &p_timer_id);
 
498
 
 
499
      dbus_object->is_timer_running( 
 
500
       p_timer_id      , p_value      );
 
501
 
 
502
      GVariantBuilder builder;
 
503
      g_variant_builder_init(&builder, (GVariantType*)"(b)");
 
504
 
 
505
      GVariant *v_value = put_bool(&p_value);
 
506
      g_variant_builder_add_value(&builder, v_value);
 
507
 
 
508
      GVariant *out = g_variant_builder_end(&builder);
 
509
 
 
510
      g_dbus_method_invocation_return_value(invocation, out);
 
511
    }
 
512
  catch (DBusException)
 
513
    {
 
514
      throw;
 
515
    }
 
516
 
 
517
}
 
518
 
 
519
 
 
520
 
 
521
void
 
522
org_workrave_CoreInterface_Stub::GetTimerIdle(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
523
{
 
524
  (void) sender;
 
525
 
 
526
  try
 
527
    {
 
528
      Core *dbus_object = (Core *) object;
 
529
 
 
530
      BreakId p_timer_id       ;
 
531
      gint32 p_value       ;
 
532
 
 
533
      gsize num_in_args = g_variant_n_children(inargs);
 
534
      if (num_in_args != 1)
 
535
        {
 
536
          throw DBusSystemException("Incorrect numer of in-parameters");
 
537
        }
 
538
 
 
539
      GVariant *v_timer_id = g_variant_get_child_value(inargs, 0);
 
540
      get_break_id(v_timer_id, &p_timer_id);
 
541
 
 
542
      dbus_object->get_timer_idle( 
 
543
       p_timer_id      , &p_value      );
 
544
 
 
545
      GVariantBuilder builder;
 
546
      g_variant_builder_init(&builder, (GVariantType*)"(i)");
 
547
 
 
548
      GVariant *v_value = put_int32(&p_value);
 
549
      g_variant_builder_add_value(&builder, v_value);
 
550
 
 
551
      GVariant *out = g_variant_builder_end(&builder);
 
552
 
 
553
      g_dbus_method_invocation_return_value(invocation, out);
 
554
    }
 
555
  catch (DBusException)
 
556
    {
 
557
      throw;
 
558
    }
 
559
 
 
560
}
 
561
 
 
562
 
 
563
 
 
564
void
 
565
org_workrave_CoreInterface_Stub::GetTimerElapsed(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
566
{
 
567
  (void) sender;
 
568
 
 
569
  try
 
570
    {
 
571
      Core *dbus_object = (Core *) object;
 
572
 
 
573
      BreakId p_timer_id       ;
 
574
      gint32 p_value       ;
 
575
 
 
576
      gsize num_in_args = g_variant_n_children(inargs);
 
577
      if (num_in_args != 1)
 
578
        {
 
579
          throw DBusSystemException("Incorrect numer of in-parameters");
 
580
        }
 
581
 
 
582
      GVariant *v_timer_id = g_variant_get_child_value(inargs, 0);
 
583
      get_break_id(v_timer_id, &p_timer_id);
 
584
 
 
585
      dbus_object->get_timer_elapsed( 
 
586
       p_timer_id      , &p_value      );
 
587
 
 
588
      GVariantBuilder builder;
 
589
      g_variant_builder_init(&builder, (GVariantType*)"(i)");
 
590
 
 
591
      GVariant *v_value = put_int32(&p_value);
 
592
      g_variant_builder_add_value(&builder, v_value);
 
593
 
 
594
      GVariant *out = g_variant_builder_end(&builder);
 
595
 
 
596
      g_dbus_method_invocation_return_value(invocation, out);
 
597
    }
 
598
  catch (DBusException)
 
599
    {
 
600
      throw;
 
601
    }
 
602
 
 
603
}
 
604
 
 
605
 
 
606
 
 
607
void
 
608
org_workrave_CoreInterface_Stub::GetTimerOverdue(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
609
{
 
610
  (void) sender;
 
611
 
 
612
  try
 
613
    {
 
614
      Core *dbus_object = (Core *) object;
 
615
 
 
616
      BreakId p_timer_id       ;
 
617
      gint32 p_value       ;
 
618
 
 
619
      gsize num_in_args = g_variant_n_children(inargs);
 
620
      if (num_in_args != 1)
 
621
        {
 
622
          throw DBusSystemException("Incorrect numer of in-parameters");
 
623
        }
 
624
 
 
625
      GVariant *v_timer_id = g_variant_get_child_value(inargs, 0);
 
626
      get_break_id(v_timer_id, &p_timer_id);
 
627
 
 
628
      dbus_object->get_timer_overdue( 
 
629
       p_timer_id      , &p_value      );
 
630
 
 
631
      GVariantBuilder builder;
 
632
      g_variant_builder_init(&builder, (GVariantType*)"(i)");
 
633
 
 
634
      GVariant *v_value = put_int32(&p_value);
 
635
      g_variant_builder_add_value(&builder, v_value);
 
636
 
 
637
      GVariant *out = g_variant_builder_end(&builder);
 
638
 
 
639
      g_dbus_method_invocation_return_value(invocation, out);
 
640
    }
 
641
  catch (DBusException)
 
642
    {
 
643
      throw;
 
644
    }
 
645
 
 
646
}
 
647
 
 
648
 
 
649
 
 
650
void
 
651
org_workrave_CoreInterface_Stub::GetTime(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
652
{
 
653
  (void) sender;
 
654
 
 
655
  try
 
656
    {
 
657
      Core *dbus_object = (Core *) object;
 
658
 
 
659
      gint32 p_value       ;
 
660
 
 
661
      gsize num_in_args = g_variant_n_children(inargs);
 
662
      if (num_in_args != 0)
 
663
        {
 
664
          throw DBusSystemException("Incorrect numer of in-parameters");
 
665
        }
 
666
 
 
667
 
 
668
      p_value = dbus_object->get_time( 
 
669
      );
 
670
 
 
671
      GVariantBuilder builder;
 
672
      g_variant_builder_init(&builder, (GVariantType*)"(i)");
 
673
 
 
674
      GVariant *v_value = put_int32(&p_value);
 
675
      g_variant_builder_add_value(&builder, v_value);
 
676
 
 
677
      GVariant *out = g_variant_builder_end(&builder);
 
678
 
 
679
      g_dbus_method_invocation_return_value(invocation, out);
 
680
    }
 
681
  catch (DBusException)
 
682
    {
 
683
      throw;
 
684
    }
 
685
 
 
686
}
 
687
 
 
688
 
 
689
 
 
690
void
 
691
org_workrave_CoreInterface_Stub::IsActive(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
692
{
 
693
  (void) sender;
 
694
 
 
695
  try
 
696
    {
 
697
      Core *dbus_object = (Core *) object;
 
698
 
 
699
      bool p_value       ;
 
700
 
 
701
      gsize num_in_args = g_variant_n_children(inargs);
 
702
      if (num_in_args != 0)
 
703
        {
 
704
          throw DBusSystemException("Incorrect numer of in-parameters");
 
705
        }
 
706
 
 
707
 
 
708
      p_value = dbus_object->is_user_active( 
 
709
      );
 
710
 
 
711
      GVariantBuilder builder;
 
712
      g_variant_builder_init(&builder, (GVariantType*)"(b)");
 
713
 
 
714
      GVariant *v_value = put_bool(&p_value);
 
715
      g_variant_builder_add_value(&builder, v_value);
 
716
 
 
717
      GVariant *out = g_variant_builder_end(&builder);
 
718
 
 
719
      g_dbus_method_invocation_return_value(invocation, out);
 
720
    }
 
721
  catch (DBusException)
 
722
    {
 
723
      throw;
 
724
    }
 
725
 
 
726
}
 
727
 
 
728
 
 
729
 
 
730
void
 
731
org_workrave_CoreInterface_Stub::PostponeBreak(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
732
{
 
733
  (void) sender;
 
734
 
 
735
  try
 
736
    {
 
737
      Core *dbus_object = (Core *) object;
 
738
 
 
739
      BreakId p_timer_id       ;
 
740
 
 
741
      gsize num_in_args = g_variant_n_children(inargs);
 
742
      if (num_in_args != 1)
 
743
        {
 
744
          throw DBusSystemException("Incorrect numer of in-parameters");
 
745
        }
 
746
 
 
747
      GVariant *v_timer_id = g_variant_get_child_value(inargs, 0);
 
748
      get_break_id(v_timer_id, &p_timer_id);
 
749
 
 
750
      dbus_object->postpone_break( 
 
751
       p_timer_id      );
 
752
 
 
753
      GVariant *out = NULL;
 
754
 
 
755
      g_dbus_method_invocation_return_value(invocation, out);
 
756
    }
 
757
  catch (DBusException)
 
758
    {
 
759
      throw;
 
760
    }
 
761
 
 
762
}
 
763
 
 
764
 
 
765
 
 
766
void
 
767
org_workrave_CoreInterface_Stub::SkipBreak(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
768
{
 
769
  (void) sender;
 
770
 
 
771
  try
 
772
    {
 
773
      Core *dbus_object = (Core *) object;
 
774
 
 
775
      BreakId p_timer_id       ;
 
776
 
 
777
      gsize num_in_args = g_variant_n_children(inargs);
 
778
      if (num_in_args != 1)
 
779
        {
 
780
          throw DBusSystemException("Incorrect numer of in-parameters");
 
781
        }
 
782
 
 
783
      GVariant *v_timer_id = g_variant_get_child_value(inargs, 0);
 
784
      get_break_id(v_timer_id, &p_timer_id);
 
785
 
 
786
      dbus_object->skip_break( 
 
787
       p_timer_id      );
 
788
 
 
789
      GVariant *out = NULL;
 
790
 
 
791
      g_dbus_method_invocation_return_value(invocation, out);
 
792
    }
 
793
  catch (DBusException)
 
794
    {
 
795
      throw;
 
796
    }
 
797
 
 
798
}
 
799
 
 
800
 
 
801
 
 
802
void org_workrave_CoreInterface_Stub::MicrobreakChanged(const string &path,        std::string progress)
 
803
{
 
804
  GDBusConnection *connection = dbus->get_connection();
 
805
  if (connection == NULL)
 
806
    {
 
807
      return;
 
808
    }
 
809
 
 
810
  GVariantBuilder builder;
 
811
  g_variant_builder_init(&builder, (GVariantType*)"(s)");
 
812
 
 
813
  GVariant *v_progress = put_string(&progress);
 
814
  g_variant_builder_add_value(&builder, v_progress);
 
815
 
 
816
  GVariant *out = g_variant_builder_end(&builder);
 
817
 
 
818
  GError *error = NULL;
 
819
  g_dbus_connection_emit_signal(connection,
 
820
                                NULL,
 
821
                                path.c_str(),
 
822
                                "org.workrave.CoreInterface",
 
823
                                "MicrobreakChanged",
 
824
                                out,
 
825
                                &error);
 
826
 
 
827
  if (error != NULL)
 
828
    {
 
829
      g_error_free(error);
 
830
    }
 
831
}
 
832
 
 
833
void org_workrave_CoreInterface_Stub::RestbreakChanged(const string &path,        std::string progress)
 
834
{
 
835
  GDBusConnection *connection = dbus->get_connection();
 
836
  if (connection == NULL)
 
837
    {
 
838
      return;
 
839
    }
 
840
 
 
841
  GVariantBuilder builder;
 
842
  g_variant_builder_init(&builder, (GVariantType*)"(s)");
 
843
 
 
844
  GVariant *v_progress = put_string(&progress);
 
845
  g_variant_builder_add_value(&builder, v_progress);
 
846
 
 
847
  GVariant *out = g_variant_builder_end(&builder);
 
848
 
 
849
  GError *error = NULL;
 
850
  g_dbus_connection_emit_signal(connection,
 
851
                                NULL,
 
852
                                path.c_str(),
 
853
                                "org.workrave.CoreInterface",
 
854
                                "RestbreakChanged",
 
855
                                out,
 
856
                                &error);
 
857
 
 
858
  if (error != NULL)
 
859
    {
 
860
      g_error_free(error);
 
861
    }
 
862
}
 
863
 
 
864
void org_workrave_CoreInterface_Stub::DailylimitChanged(const string &path,        std::string progress)
 
865
{
 
866
  GDBusConnection *connection = dbus->get_connection();
 
867
  if (connection == NULL)
 
868
    {
 
869
      return;
 
870
    }
 
871
 
 
872
  GVariantBuilder builder;
 
873
  g_variant_builder_init(&builder, (GVariantType*)"(s)");
 
874
 
 
875
  GVariant *v_progress = put_string(&progress);
 
876
  g_variant_builder_add_value(&builder, v_progress);
 
877
 
 
878
  GVariant *out = g_variant_builder_end(&builder);
 
879
 
 
880
  GError *error = NULL;
 
881
  g_dbus_connection_emit_signal(connection,
 
882
                                NULL,
 
883
                                path.c_str(),
 
884
                                "org.workrave.CoreInterface",
 
885
                                "DailylimitChanged",
 
886
                                out,
 
887
                                &error);
 
888
 
 
889
  if (error != NULL)
 
890
    {
 
891
      g_error_free(error);
 
892
    }
 
893
}
 
894
 
 
895
 
 
896
const org_workrave_CoreInterface_Stub::DBusMethod org_workrave_CoreInterface_Stub::method_table[] = {
 
897
  { "SetOperationMode", &org_workrave_CoreInterface_Stub::SetOperationMode },
 
898
  { "GetOperationMode", &org_workrave_CoreInterface_Stub::GetOperationMode },
 
899
  { "SetUsageMode", &org_workrave_CoreInterface_Stub::SetUsageMode },
 
900
  { "GetUsageMode", &org_workrave_CoreInterface_Stub::GetUsageMode },
 
901
  { "ReportActivity", &org_workrave_CoreInterface_Stub::ReportActivity },
 
902
  { "IsTimerRunning", &org_workrave_CoreInterface_Stub::IsTimerRunning },
 
903
  { "GetTimerIdle", &org_workrave_CoreInterface_Stub::GetTimerIdle },
 
904
  { "GetTimerElapsed", &org_workrave_CoreInterface_Stub::GetTimerElapsed },
 
905
  { "GetTimerOverdue", &org_workrave_CoreInterface_Stub::GetTimerOverdue },
 
906
  { "GetTime", &org_workrave_CoreInterface_Stub::GetTime },
 
907
  { "IsActive", &org_workrave_CoreInterface_Stub::IsActive },
 
908
  { "PostponeBreak", &org_workrave_CoreInterface_Stub::PostponeBreak },
 
909
  { "SkipBreak", &org_workrave_CoreInterface_Stub::SkipBreak },
 
910
  { "", NULL }
 
911
};
 
912
 
 
913
const char *
 
914
org_workrave_CoreInterface_Stub::interface_introspect =
 
915
  "  <interface name=\"org.workrave.CoreInterface\">\n"
 
916
  "    <method name=\"SetOperationMode\">\n"
 
917
  "      <arg type=\"s\" name=\"mode\" direction=\"in\" />\n"
 
918
  "    </method>\n"
 
919
  "    <method name=\"GetOperationMode\">\n"
 
920
  "      <arg type=\"s\" name=\"mode\" direction=\"out\" />\n"
 
921
  "    </method>\n"
 
922
  "    <method name=\"SetUsageMode\">\n"
 
923
  "      <arg type=\"s\" name=\"mode\" direction=\"in\" />\n"
 
924
  "    </method>\n"
 
925
  "    <method name=\"GetUsageMode\">\n"
 
926
  "      <arg type=\"s\" name=\"mode\" direction=\"out\" />\n"
 
927
  "    </method>\n"
 
928
  "    <method name=\"ReportActivity\">\n"
 
929
  "      <arg type=\"s\" name=\"who\" direction=\"in\" />\n"
 
930
  "      <arg type=\"b\" name=\"act\" direction=\"in\" />\n"
 
931
  "    </method>\n"
 
932
  "    <method name=\"IsTimerRunning\">\n"
 
933
  "      <arg type=\"s\" name=\"timer_id\" direction=\"in\" />\n"
 
934
  "      <arg type=\"b\" name=\"value\" direction=\"out\" />\n"
 
935
  "    </method>\n"
 
936
  "    <method name=\"GetTimerIdle\">\n"
 
937
  "      <arg type=\"s\" name=\"timer_id\" direction=\"in\" />\n"
 
938
  "      <arg type=\"i\" name=\"value\" direction=\"out\" />\n"
 
939
  "    </method>\n"
 
940
  "    <method name=\"GetTimerElapsed\">\n"
 
941
  "      <arg type=\"s\" name=\"timer_id\" direction=\"in\" />\n"
 
942
  "      <arg type=\"i\" name=\"value\" direction=\"out\" />\n"
 
943
  "    </method>\n"
 
944
  "    <method name=\"GetTimerOverdue\">\n"
 
945
  "      <arg type=\"s\" name=\"timer_id\" direction=\"in\" />\n"
 
946
  "      <arg type=\"i\" name=\"value\" direction=\"out\" />\n"
 
947
  "    </method>\n"
 
948
  "    <method name=\"GetTime\">\n"
 
949
  "      <arg type=\"i\" name=\"value\" direction=\"out\" />\n"
 
950
  "    </method>\n"
 
951
  "    <method name=\"IsActive\">\n"
 
952
  "      <arg type=\"b\" name=\"value\" direction=\"out\" />\n"
 
953
  "    </method>\n"
 
954
  "    <method name=\"PostponeBreak\">\n"
 
955
  "      <arg type=\"s\" name=\"timer_id\" direction=\"in\" />\n"
 
956
  "    </method>\n"
 
957
  "    <method name=\"SkipBreak\">\n"
 
958
  "      <arg type=\"s\" name=\"timer_id\" direction=\"in\" />\n"
 
959
  "    </method>\n"
 
960
  "    <signal name=\"MicrobreakChanged\">\n"
 
961
  "      <arg type=\"s\" name=\"timer_id\" />\n"
 
962
  "    </signal>\n"
 
963
  "    <signal name=\"RestbreakChanged\">\n"
 
964
  "      <arg type=\"s\" name=\"timer_id\" />\n"
 
965
  "    </signal>\n"
 
966
  "    <signal name=\"DailylimitChanged\">\n"
 
967
  "      <arg type=\"s\" name=\"timer_id\" />\n"
 
968
  "    </signal>\n"
 
969
  "  </interface>\n";
 
970
 
 
971
 
 
972
 
 
973
#if defined(HAVE_TESTS)
 
974
 
 
975
using namespace workrave;
 
976
 
 
977
#include "Test.hh"
 
978
 
 
979
class org_workrave_DebugInterface_Stub : public DBusBindingBase, public org_workrave_DebugInterface
 
980
{
 
981
private:
 
982
  typedef void (org_workrave_DebugInterface_Stub::*DBusMethodPointer)(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
983
 
 
984
  struct DBusMethod
 
985
  {
 
986
    const string name;
 
987
    DBusMethodPointer fn;
 
988
  };
 
989
 
 
990
  virtual void call(const std::string &method_name, void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
991
 
 
992
  virtual const char *get_interface_introspect()
 
993
  {
 
994
    return interface_introspect;
 
995
  }
 
996
 
 
997
public:
 
998
  org_workrave_DebugInterface_Stub(DBus *dbus);
 
999
  ~org_workrave_DebugInterface_Stub();
 
1000
 
 
1001
 
 
1002
 
 
1003
private:
 
1004
  void Quit(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1005
 
 
1006
  void get_break_id(GVariant *variant, BreakId *result);
 
1007
  GVariant *put_break_id(const BreakId *result);
 
1008
 
 
1009
 
 
1010
 
 
1011
 
 
1012
  static const DBusMethod method_table[];
 
1013
  static const char *interface_introspect;
 
1014
};
 
1015
 
 
1016
 
 
1017
org_workrave_DebugInterface *org_workrave_DebugInterface::instance(const DBus *dbus)
 
1018
{
 
1019
  org_workrave_DebugInterface_Stub *iface = NULL;
 
1020
  DBusBindingBase *binding = dbus->find_binding("org.workrave.DebugInterface");
 
1021
 
 
1022
  if (binding != NULL)
 
1023
    {
 
1024
      iface = dynamic_cast<org_workrave_DebugInterface_Stub *>(binding);
 
1025
    }
 
1026
 
 
1027
  return iface;
 
1028
}
 
1029
 
 
1030
org_workrave_DebugInterface_Stub::org_workrave_DebugInterface_Stub(DBus *dbus)
 
1031
  : DBusBindingBase(dbus)
 
1032
{
 
1033
}
 
1034
 
 
1035
org_workrave_DebugInterface_Stub::~org_workrave_DebugInterface_Stub()
 
1036
{
 
1037
}
 
1038
 
 
1039
void
 
1040
org_workrave_DebugInterface_Stub::call(const std::string &method_name, void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1041
{
 
1042
  const DBusMethod *table = method_table;
 
1043
  while (table->fn != NULL)
 
1044
    {
 
1045
      if (method_name == table->name)
 
1046
        {
 
1047
          DBusMethodPointer ptr = table->fn;
 
1048
          if (ptr != NULL)
 
1049
            {
 
1050
              (this->*ptr)(object, invocation, sender, inargs);
 
1051
            }
 
1052
          return;
 
1053
        }
 
1054
      table++;
 
1055
    }
 
1056
  throw DBusUsageException(std::string("No such member:") + method_name );
 
1057
}
 
1058
 
 
1059
 
 
1060
void
 
1061
org_workrave_DebugInterface_Stub::get_break_id(GVariant *variant, BreakId *result)
 
1062
{
 
1063
  std::string value;
 
1064
 
 
1065
  get_string(variant, &value);
 
1066
 
 
1067
  if ("microbreak" == value)
 
1068
    {
 
1069
      *result = BREAK_ID_MICRO_BREAK;
 
1070
    }
 
1071
  else if ("restbreak" == value)
 
1072
    {
 
1073
      *result = BREAK_ID_REST_BREAK;
 
1074
    }
 
1075
  else if ("dailylimit" == value)
 
1076
    {
 
1077
      *result = BREAK_ID_DAILY_LIMIT;
 
1078
    }
 
1079
  else
 
1080
    {
 
1081
      throw DBusTypeException("Illegal enum value");
 
1082
    }
 
1083
}
 
1084
 
 
1085
GVariant *
 
1086
org_workrave_DebugInterface_Stub::put_break_id(const BreakId *result)
 
1087
{
 
1088
  string value;
 
1089
  switch (*result)
 
1090
    {
 
1091
    case BREAK_ID_MICRO_BREAK:
 
1092
      value = "microbreak";
 
1093
      break;
 
1094
    case BREAK_ID_REST_BREAK:
 
1095
      value = "restbreak";
 
1096
      break;
 
1097
    case BREAK_ID_DAILY_LIMIT:
 
1098
      value = "dailylimit";
 
1099
      break;
 
1100
    default:
 
1101
      throw DBusTypeException("Illegal enum value");
 
1102
    }
 
1103
 
 
1104
  return put_string(&value);
 
1105
}
 
1106
 
 
1107
 
 
1108
 
 
1109
 
 
1110
 
 
1111
 
 
1112
 
 
1113
void
 
1114
org_workrave_DebugInterface_Stub::Quit(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1115
{
 
1116
  (void) sender;
 
1117
 
 
1118
  try
 
1119
    {
 
1120
      Test *dbus_object = (Test *) object;
 
1121
 
 
1122
 
 
1123
      gsize num_in_args = g_variant_n_children(inargs);
 
1124
      if (num_in_args != 0)
 
1125
        {
 
1126
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1127
        }
 
1128
 
 
1129
 
 
1130
      dbus_object->quit( 
 
1131
      );
 
1132
 
 
1133
      GVariant *out = NULL;
 
1134
 
 
1135
      g_dbus_method_invocation_return_value(invocation, out);
 
1136
    }
 
1137
  catch (DBusException)
 
1138
    {
 
1139
      throw;
 
1140
    }
 
1141
 
 
1142
}
 
1143
 
 
1144
 
 
1145
 
 
1146
 
 
1147
const org_workrave_DebugInterface_Stub::DBusMethod org_workrave_DebugInterface_Stub::method_table[] = {
 
1148
  { "Quit", &org_workrave_DebugInterface_Stub::Quit },
 
1149
  { "", NULL }
 
1150
};
 
1151
 
 
1152
const char *
 
1153
org_workrave_DebugInterface_Stub::interface_introspect =
 
1154
  "  <interface name=\"org.workrave.DebugInterface\">\n"
 
1155
  "    <method name=\"Quit\">\n"
 
1156
  "    </method>\n"
 
1157
  "  </interface>\n";
 
1158
 
 
1159
 #endif // defined(HAVE_TESTS)
 
1160
 
 
1161
 
 
1162
 
 
1163
using namespace workrave;
 
1164
 
 
1165
#include "IConfigurator.hh"
 
1166
 
 
1167
class org_workrave_ConfigInterface_Stub : public DBusBindingBase, public org_workrave_ConfigInterface
 
1168
{
 
1169
private:
 
1170
  typedef void (org_workrave_ConfigInterface_Stub::*DBusMethodPointer)(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1171
 
 
1172
  struct DBusMethod
 
1173
  {
 
1174
    const string name;
 
1175
    DBusMethodPointer fn;
 
1176
  };
 
1177
 
 
1178
  virtual void call(const std::string &method_name, void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1179
 
 
1180
  virtual const char *get_interface_introspect()
 
1181
  {
 
1182
    return interface_introspect;
 
1183
  }
 
1184
 
 
1185
public:
 
1186
  org_workrave_ConfigInterface_Stub(DBus *dbus);
 
1187
  ~org_workrave_ConfigInterface_Stub();
 
1188
 
 
1189
 
 
1190
 
 
1191
private:
 
1192
  void SetString(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1193
  void SetInt(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1194
  void SetBool(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1195
  void SetDouble(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1196
  void GetString(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1197
  void GetInt(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1198
  void GetBool(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1199
  void GetDouble(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs);
 
1200
 
 
1201
 
 
1202
 
 
1203
 
 
1204
 
 
1205
  static const DBusMethod method_table[];
 
1206
  static const char *interface_introspect;
 
1207
};
 
1208
 
 
1209
 
 
1210
org_workrave_ConfigInterface *org_workrave_ConfigInterface::instance(const DBus *dbus)
 
1211
{
 
1212
  org_workrave_ConfigInterface_Stub *iface = NULL;
 
1213
  DBusBindingBase *binding = dbus->find_binding("org.workrave.ConfigInterface");
 
1214
 
 
1215
  if (binding != NULL)
 
1216
    {
 
1217
      iface = dynamic_cast<org_workrave_ConfigInterface_Stub *>(binding);
 
1218
    }
 
1219
 
 
1220
  return iface;
 
1221
}
 
1222
 
 
1223
org_workrave_ConfigInterface_Stub::org_workrave_ConfigInterface_Stub(DBus *dbus)
 
1224
  : DBusBindingBase(dbus)
 
1225
{
 
1226
}
 
1227
 
 
1228
org_workrave_ConfigInterface_Stub::~org_workrave_ConfigInterface_Stub()
 
1229
{
 
1230
}
 
1231
 
 
1232
void
 
1233
org_workrave_ConfigInterface_Stub::call(const std::string &method_name, void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1234
{
 
1235
  const DBusMethod *table = method_table;
 
1236
  while (table->fn != NULL)
 
1237
    {
 
1238
      if (method_name == table->name)
 
1239
        {
 
1240
          DBusMethodPointer ptr = table->fn;
 
1241
          if (ptr != NULL)
 
1242
            {
 
1243
              (this->*ptr)(object, invocation, sender, inargs);
 
1244
            }
 
1245
          return;
 
1246
        }
 
1247
      table++;
 
1248
    }
 
1249
  throw DBusUsageException(std::string("No such member:") + method_name );
 
1250
}
 
1251
 
 
1252
 
 
1253
 
 
1254
 
 
1255
 
 
1256
 
 
1257
 
 
1258
void
 
1259
org_workrave_ConfigInterface_Stub::SetString(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1260
{
 
1261
  (void) sender;
 
1262
 
 
1263
  try
 
1264
    {
 
1265
      IConfigurator *dbus_object = (IConfigurator *) object;
 
1266
 
 
1267
      std::string p_key       ;
 
1268
      std::string p_value       ;
 
1269
      bool p_success       ;
 
1270
 
 
1271
      gsize num_in_args = g_variant_n_children(inargs);
 
1272
      if (num_in_args != 2)
 
1273
        {
 
1274
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1275
        }
 
1276
 
 
1277
      GVariant *v_key = g_variant_get_child_value(inargs, 0);
 
1278
      get_string(v_key, &p_key);
 
1279
      GVariant *v_value = g_variant_get_child_value(inargs, 1);
 
1280
      get_string(v_value, &p_value);
 
1281
 
 
1282
      p_success = dbus_object->set_value( 
 
1283
       p_key      , p_value      );
 
1284
 
 
1285
      GVariantBuilder builder;
 
1286
      g_variant_builder_init(&builder, (GVariantType*)"(b)");
 
1287
 
 
1288
      GVariant *v_success = put_bool(&p_success);
 
1289
      g_variant_builder_add_value(&builder, v_success);
 
1290
 
 
1291
      GVariant *out = g_variant_builder_end(&builder);
 
1292
 
 
1293
      g_dbus_method_invocation_return_value(invocation, out);
 
1294
    }
 
1295
  catch (DBusException)
 
1296
    {
 
1297
      throw;
 
1298
    }
 
1299
 
 
1300
}
 
1301
 
 
1302
 
 
1303
 
 
1304
void
 
1305
org_workrave_ConfigInterface_Stub::SetInt(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1306
{
 
1307
  (void) sender;
 
1308
 
 
1309
  try
 
1310
    {
 
1311
      IConfigurator *dbus_object = (IConfigurator *) object;
 
1312
 
 
1313
      std::string p_key       ;
 
1314
      gint32 p_value       ;
 
1315
      bool p_success       ;
 
1316
 
 
1317
      gsize num_in_args = g_variant_n_children(inargs);
 
1318
      if (num_in_args != 2)
 
1319
        {
 
1320
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1321
        }
 
1322
 
 
1323
      GVariant *v_key = g_variant_get_child_value(inargs, 0);
 
1324
      get_string(v_key, &p_key);
 
1325
      GVariant *v_value = g_variant_get_child_value(inargs, 1);
 
1326
      get_int32(v_value, &p_value);
 
1327
 
 
1328
      p_success = dbus_object->set_value( 
 
1329
       p_key      , p_value      );
 
1330
 
 
1331
      GVariantBuilder builder;
 
1332
      g_variant_builder_init(&builder, (GVariantType*)"(b)");
 
1333
 
 
1334
      GVariant *v_success = put_bool(&p_success);
 
1335
      g_variant_builder_add_value(&builder, v_success);
 
1336
 
 
1337
      GVariant *out = g_variant_builder_end(&builder);
 
1338
 
 
1339
      g_dbus_method_invocation_return_value(invocation, out);
 
1340
    }
 
1341
  catch (DBusException)
 
1342
    {
 
1343
      throw;
 
1344
    }
 
1345
 
 
1346
}
 
1347
 
 
1348
 
 
1349
 
 
1350
void
 
1351
org_workrave_ConfigInterface_Stub::SetBool(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1352
{
 
1353
  (void) sender;
 
1354
 
 
1355
  try
 
1356
    {
 
1357
      IConfigurator *dbus_object = (IConfigurator *) object;
 
1358
 
 
1359
      std::string p_key       ;
 
1360
      bool p_value       ;
 
1361
      bool p_success       ;
 
1362
 
 
1363
      gsize num_in_args = g_variant_n_children(inargs);
 
1364
      if (num_in_args != 2)
 
1365
        {
 
1366
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1367
        }
 
1368
 
 
1369
      GVariant *v_key = g_variant_get_child_value(inargs, 0);
 
1370
      get_string(v_key, &p_key);
 
1371
      GVariant *v_value = g_variant_get_child_value(inargs, 1);
 
1372
      get_bool(v_value, &p_value);
 
1373
 
 
1374
      p_success = dbus_object->set_value( 
 
1375
       p_key      , p_value      );
 
1376
 
 
1377
      GVariantBuilder builder;
 
1378
      g_variant_builder_init(&builder, (GVariantType*)"(b)");
 
1379
 
 
1380
      GVariant *v_success = put_bool(&p_success);
 
1381
      g_variant_builder_add_value(&builder, v_success);
 
1382
 
 
1383
      GVariant *out = g_variant_builder_end(&builder);
 
1384
 
 
1385
      g_dbus_method_invocation_return_value(invocation, out);
 
1386
    }
 
1387
  catch (DBusException)
 
1388
    {
 
1389
      throw;
 
1390
    }
 
1391
 
 
1392
}
 
1393
 
 
1394
 
 
1395
 
 
1396
void
 
1397
org_workrave_ConfigInterface_Stub::SetDouble(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1398
{
 
1399
  (void) sender;
 
1400
 
 
1401
  try
 
1402
    {
 
1403
      IConfigurator *dbus_object = (IConfigurator *) object;
 
1404
 
 
1405
      std::string p_key       ;
 
1406
      double p_value       ;
 
1407
      bool p_success       ;
 
1408
 
 
1409
      gsize num_in_args = g_variant_n_children(inargs);
 
1410
      if (num_in_args != 2)
 
1411
        {
 
1412
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1413
        }
 
1414
 
 
1415
      GVariant *v_key = g_variant_get_child_value(inargs, 0);
 
1416
      get_string(v_key, &p_key);
 
1417
      GVariant *v_value = g_variant_get_child_value(inargs, 1);
 
1418
      get_double(v_value, &p_value);
 
1419
 
 
1420
      p_success = dbus_object->set_value( 
 
1421
       p_key      , p_value      );
 
1422
 
 
1423
      GVariantBuilder builder;
 
1424
      g_variant_builder_init(&builder, (GVariantType*)"(b)");
 
1425
 
 
1426
      GVariant *v_success = put_bool(&p_success);
 
1427
      g_variant_builder_add_value(&builder, v_success);
 
1428
 
 
1429
      GVariant *out = g_variant_builder_end(&builder);
 
1430
 
 
1431
      g_dbus_method_invocation_return_value(invocation, out);
 
1432
    }
 
1433
  catch (DBusException)
 
1434
    {
 
1435
      throw;
 
1436
    }
 
1437
 
 
1438
}
 
1439
 
 
1440
 
 
1441
 
 
1442
void
 
1443
org_workrave_ConfigInterface_Stub::GetString(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1444
{
 
1445
  (void) sender;
 
1446
 
 
1447
  try
 
1448
    {
 
1449
      IConfigurator *dbus_object = (IConfigurator *) object;
 
1450
 
 
1451
      std::string p_key       ;
 
1452
      bool p_found       ;
 
1453
      std::string p_value       ;
 
1454
 
 
1455
      gsize num_in_args = g_variant_n_children(inargs);
 
1456
      if (num_in_args != 1)
 
1457
        {
 
1458
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1459
        }
 
1460
 
 
1461
      GVariant *v_key = g_variant_get_child_value(inargs, 0);
 
1462
      get_string(v_key, &p_key);
 
1463
 
 
1464
      p_found = dbus_object->get_value( 
 
1465
       p_key      , p_value      );
 
1466
 
 
1467
      GVariantBuilder builder;
 
1468
      g_variant_builder_init(&builder, (GVariantType*)"(bs)");
 
1469
 
 
1470
      GVariant *v_found = put_bool(&p_found);
 
1471
      g_variant_builder_add_value(&builder, v_found);
 
1472
      GVariant *v_value = put_string(&p_value);
 
1473
      g_variant_builder_add_value(&builder, v_value);
 
1474
 
 
1475
      GVariant *out = g_variant_builder_end(&builder);
 
1476
 
 
1477
      g_dbus_method_invocation_return_value(invocation, out);
 
1478
    }
 
1479
  catch (DBusException)
 
1480
    {
 
1481
      throw;
 
1482
    }
 
1483
 
 
1484
}
 
1485
 
 
1486
 
 
1487
 
 
1488
void
 
1489
org_workrave_ConfigInterface_Stub::GetInt(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1490
{
 
1491
  (void) sender;
 
1492
 
 
1493
  try
 
1494
    {
 
1495
      IConfigurator *dbus_object = (IConfigurator *) object;
 
1496
 
 
1497
      std::string p_key       ;
 
1498
      gint32 p_value       ;
 
1499
      bool p_found       ;
 
1500
 
 
1501
      gsize num_in_args = g_variant_n_children(inargs);
 
1502
      if (num_in_args != 1)
 
1503
        {
 
1504
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1505
        }
 
1506
 
 
1507
      GVariant *v_key = g_variant_get_child_value(inargs, 0);
 
1508
      get_string(v_key, &p_key);
 
1509
 
 
1510
      p_found = dbus_object->get_value( 
 
1511
       p_key      , p_value      );
 
1512
 
 
1513
      GVariantBuilder builder;
 
1514
      g_variant_builder_init(&builder, (GVariantType*)"(ib)");
 
1515
 
 
1516
      GVariant *v_value = put_int32(&p_value);
 
1517
      g_variant_builder_add_value(&builder, v_value);
 
1518
      GVariant *v_found = put_bool(&p_found);
 
1519
      g_variant_builder_add_value(&builder, v_found);
 
1520
 
 
1521
      GVariant *out = g_variant_builder_end(&builder);
 
1522
 
 
1523
      g_dbus_method_invocation_return_value(invocation, out);
 
1524
    }
 
1525
  catch (DBusException)
 
1526
    {
 
1527
      throw;
 
1528
    }
 
1529
 
 
1530
}
 
1531
 
 
1532
 
 
1533
 
 
1534
void
 
1535
org_workrave_ConfigInterface_Stub::GetBool(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1536
{
 
1537
  (void) sender;
 
1538
 
 
1539
  try
 
1540
    {
 
1541
      IConfigurator *dbus_object = (IConfigurator *) object;
 
1542
 
 
1543
      std::string p_key       ;
 
1544
      bool p_value       ;
 
1545
      bool p_found       ;
 
1546
 
 
1547
      gsize num_in_args = g_variant_n_children(inargs);
 
1548
      if (num_in_args != 1)
 
1549
        {
 
1550
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1551
        }
 
1552
 
 
1553
      GVariant *v_key = g_variant_get_child_value(inargs, 0);
 
1554
      get_string(v_key, &p_key);
 
1555
 
 
1556
      p_found = dbus_object->get_value( 
 
1557
       p_key      , p_value      );
 
1558
 
 
1559
      GVariantBuilder builder;
 
1560
      g_variant_builder_init(&builder, (GVariantType*)"(bb)");
 
1561
 
 
1562
      GVariant *v_value = put_bool(&p_value);
 
1563
      g_variant_builder_add_value(&builder, v_value);
 
1564
      GVariant *v_found = put_bool(&p_found);
 
1565
      g_variant_builder_add_value(&builder, v_found);
 
1566
 
 
1567
      GVariant *out = g_variant_builder_end(&builder);
 
1568
 
 
1569
      g_dbus_method_invocation_return_value(invocation, out);
 
1570
    }
 
1571
  catch (DBusException)
 
1572
    {
 
1573
      throw;
 
1574
    }
 
1575
 
 
1576
}
 
1577
 
 
1578
 
 
1579
 
 
1580
void
 
1581
org_workrave_ConfigInterface_Stub::GetDouble(void *object, GDBusMethodInvocation *invocation, const std::string &sender, GVariant *inargs)
 
1582
{
 
1583
  (void) sender;
 
1584
 
 
1585
  try
 
1586
    {
 
1587
      IConfigurator *dbus_object = (IConfigurator *) object;
 
1588
 
 
1589
      std::string p_key       ;
 
1590
      double p_value       ;
 
1591
      bool p_found       ;
 
1592
 
 
1593
      gsize num_in_args = g_variant_n_children(inargs);
 
1594
      if (num_in_args != 1)
 
1595
        {
 
1596
          throw DBusSystemException("Incorrect numer of in-parameters");
 
1597
        }
 
1598
 
 
1599
      GVariant *v_key = g_variant_get_child_value(inargs, 0);
 
1600
      get_string(v_key, &p_key);
 
1601
 
 
1602
      p_found = dbus_object->get_value( 
 
1603
       p_key      , p_value      );
 
1604
 
 
1605
      GVariantBuilder builder;
 
1606
      g_variant_builder_init(&builder, (GVariantType*)"(db)");
 
1607
 
 
1608
      GVariant *v_value = put_double(&p_value);
 
1609
      g_variant_builder_add_value(&builder, v_value);
 
1610
      GVariant *v_found = put_bool(&p_found);
 
1611
      g_variant_builder_add_value(&builder, v_found);
 
1612
 
 
1613
      GVariant *out = g_variant_builder_end(&builder);
 
1614
 
 
1615
      g_dbus_method_invocation_return_value(invocation, out);
 
1616
    }
 
1617
  catch (DBusException)
 
1618
    {
 
1619
      throw;
 
1620
    }
 
1621
 
 
1622
}
 
1623
 
 
1624
 
 
1625
 
 
1626
 
 
1627
const org_workrave_ConfigInterface_Stub::DBusMethod org_workrave_ConfigInterface_Stub::method_table[] = {
 
1628
  { "SetString", &org_workrave_ConfigInterface_Stub::SetString },
 
1629
  { "SetInt", &org_workrave_ConfigInterface_Stub::SetInt },
 
1630
  { "SetBool", &org_workrave_ConfigInterface_Stub::SetBool },
 
1631
  { "SetDouble", &org_workrave_ConfigInterface_Stub::SetDouble },
 
1632
  { "GetString", &org_workrave_ConfigInterface_Stub::GetString },
 
1633
  { "GetInt", &org_workrave_ConfigInterface_Stub::GetInt },
 
1634
  { "GetBool", &org_workrave_ConfigInterface_Stub::GetBool },
 
1635
  { "GetDouble", &org_workrave_ConfigInterface_Stub::GetDouble },
 
1636
  { "", NULL }
 
1637
};
 
1638
 
 
1639
const char *
 
1640
org_workrave_ConfigInterface_Stub::interface_introspect =
 
1641
  "  <interface name=\"org.workrave.ConfigInterface\">\n"
 
1642
  "    <method name=\"SetString\">\n"
 
1643
  "      <arg type=\"s\" name=\"key\" direction=\"in\" />\n"
 
1644
  "      <arg type=\"s\" name=\"value\" direction=\"in\" />\n"
 
1645
  "      <arg type=\"b\" name=\"success\" direction=\"out\" />\n"
 
1646
  "    </method>\n"
 
1647
  "    <method name=\"SetInt\">\n"
 
1648
  "      <arg type=\"s\" name=\"key\" direction=\"in\" />\n"
 
1649
  "      <arg type=\"i\" name=\"value\" direction=\"in\" />\n"
 
1650
  "      <arg type=\"b\" name=\"success\" direction=\"out\" />\n"
 
1651
  "    </method>\n"
 
1652
  "    <method name=\"SetBool\">\n"
 
1653
  "      <arg type=\"s\" name=\"key\" direction=\"in\" />\n"
 
1654
  "      <arg type=\"b\" name=\"value\" direction=\"in\" />\n"
 
1655
  "      <arg type=\"b\" name=\"success\" direction=\"out\" />\n"
 
1656
  "    </method>\n"
 
1657
  "    <method name=\"SetDouble\">\n"
 
1658
  "      <arg type=\"s\" name=\"key\" direction=\"in\" />\n"
 
1659
  "      <arg type=\"d\" name=\"value\" direction=\"in\" />\n"
 
1660
  "      <arg type=\"b\" name=\"success\" direction=\"out\" />\n"
 
1661
  "    </method>\n"
 
1662
  "    <method name=\"GetString\">\n"
 
1663
  "      <arg type=\"s\" name=\"key\" direction=\"in\" />\n"
 
1664
  "      <arg type=\"b\" name=\"found\" direction=\"out\" />\n"
 
1665
  "      <arg type=\"s\" name=\"value\" direction=\"out\" />\n"
 
1666
  "    </method>\n"
 
1667
  "    <method name=\"GetInt\">\n"
 
1668
  "      <arg type=\"s\" name=\"key\" direction=\"in\" />\n"
 
1669
  "      <arg type=\"i\" name=\"value\" direction=\"out\" />\n"
 
1670
  "      <arg type=\"b\" name=\"found\" direction=\"out\" />\n"
 
1671
  "    </method>\n"
 
1672
  "    <method name=\"GetBool\">\n"
 
1673
  "      <arg type=\"s\" name=\"key\" direction=\"in\" />\n"
 
1674
  "      <arg type=\"b\" name=\"value\" direction=\"out\" />\n"
 
1675
  "      <arg type=\"b\" name=\"found\" direction=\"out\" />\n"
 
1676
  "    </method>\n"
 
1677
  "    <method name=\"GetDouble\">\n"
 
1678
  "      <arg type=\"s\" name=\"key\" direction=\"in\" />\n"
 
1679
  "      <arg type=\"d\" name=\"value\" direction=\"out\" />\n"
 
1680
  "      <arg type=\"b\" name=\"found\" direction=\"out\" />\n"
 
1681
  "    </method>\n"
 
1682
  "  </interface>\n";
 
1683
 
 
1684
 
 
1685
 
 
1686
void init_DBusWorkrave(DBus *dbus)
 
1687
{
 
1688
  dbus->register_binding("org.workrave.CoreInterface", new org_workrave_CoreInterface_Stub(dbus));
 
1689
#if defined(HAVE_TESTS)
 
1690
  dbus->register_binding("org.workrave.DebugInterface", new org_workrave_DebugInterface_Stub(dbus));
 
1691
#endif // defined(HAVE_TESTS)
 
1692
  dbus->register_binding("org.workrave.ConfigInterface", new org_workrave_ConfigInterface_Stub(dbus));
 
1693
}