~ubuntu-branches/ubuntu/precise/gcompris/precise

« back to all changes in this revision

Viewing changes to src/gcompris/dbus.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-01-10 01:37:41 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20120110013741-onkb9zctwvt8gnl8
Tags: 12.01-0ubuntu1
* New upstream release (LP: #914137)
  - New Braille activities
  - Fixes missing English finland.ogg (LP: #228672)
  - Added Thai translation
* Drop all patches since they've been applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* gcompris - timer.c
2
 
 *
3
 
 * Copyright (C) 2007, 2008 Bruno coudoin
4
 
 *
5
 
 *   This program is free software; you can redistribute it and/or modify
6
 
 *   it under the terms of the GNU General Public License as published by
7
 
 *   the Free Software Foundation; either version 3 of the License, or
8
 
 *   (at your option) any later version.
9
 
 *
10
 
 *   This program is distributed in the hope that it will be useful,
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *   GNU General Public License for more details.
14
 
 *
15
 
 *   You should have received a copy of the GNU General Public License
16
 
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
/*
20
 
 * To test it:
21
 
 * run GCompris with  --sugarBundleId a --sugarActivityId a
22
 
 * dbus-send --dest='org.laptop.Activitya'
23
 
 *           /org/laptop/Activity/a org.laptop.Activity.SetActive boolean:true
24
 
 *
25
 
 */
26
 
#include "gcompris.h"
27
 
#include <gc_core.h>
28
 
#include "gc-marshal.h"
29
 
 
30
 
#if USE_DBUS
31
 
#include <dbus/dbus-glib.h>
32
 
#include <glib-object.h>
33
 
#include <dbus/dbus.h>
34
 
#define SUPPORT_OR_RETURN(rv)   {}
35
 
#else
36
 
#define SUPPORT_OR_RETURN(rv)   { return rv; }
37
 
#endif
38
 
 
39
 
#define _ACTIVITY_SERVICE_NAME  "org.laptop.Activity"
40
 
#define _ACTIVITY_SERVICE_PATH  "/org/laptop/Activity"
41
 
#define _ACTIVITY_INTERFACE     "org.laptop.Activity"
42
 
 
43
 
#if USE_DBUS
44
 
void _SetActive(DBusGProxy *proxy, gint active, void *dummy)
45
 
{
46
 
  printf("_SetActive %d\n", active);
47
 
  if(active)
48
 
    gc_sound_close();
49
 
  else
50
 
    gc_sound_reopen();
51
 
 
52
 
}
53
 
#endif
54
 
 
55
 
void
56
 
gc_dbus_init(gchar *sugarActivityId)
57
 
{
58
 
  SUPPORT_OR_RETURN();
59
 
 
60
 
#ifdef USE_DBUS
61
 
  DBusGConnection *connection;
62
 
  GError *error;
63
 
  DBusGProxy *proxy;
64
 
 
65
 
  g_type_init ();
66
 
 
67
 
  if (!g_thread_supported ()) g_thread_init (NULL);
68
 
 
69
 
  dbus_g_thread_init ();
70
 
 
71
 
  error = NULL;
72
 
  connection = dbus_g_bus_get (DBUS_BUS_SESSION,
73
 
                               &error);
74
 
  if (connection == NULL)
75
 
    {
76
 
      g_printerr ("Failed to open connection to bus: %s\n",
77
 
                  error->message);
78
 
      g_error_free (error);
79
 
      exit (1);
80
 
    }
81
 
 
82
 
  gchar *service_name = g_strdup_printf("%s%s",
83
 
                                        _ACTIVITY_SERVICE_NAME,
84
 
                                        sugarActivityId);
85
 
  gchar *object_path  = g_strdup_printf("%s/%s",
86
 
                                        _ACTIVITY_SERVICE_PATH,
87
 
                                        sugarActivityId);
88
 
 
89
 
  dbus_g_object_register_marshaller (gc_marshal_VOID__BOOLEAN,
90
 
                                     G_TYPE_NONE, G_TYPE_BOOLEAN, G_TYPE_INVALID);
91
 
 
92
 
  proxy = dbus_g_proxy_new_for_name (connection,
93
 
                                     service_name,
94
 
                                     object_path,
95
 
                                     _ACTIVITY_INTERFACE);
96
 
 
97
 
  dbus_g_proxy_add_signal(proxy, "SetActive", G_TYPE_BOOLEAN, G_TYPE_INVALID);
98
 
  dbus_g_proxy_connect_signal(proxy, "SetActive",
99
 
                              G_CALLBACK(_SetActive), NULL, NULL);
100
 
#endif
101
 
}