~cjcurran/indicator-sound/graceful-crashing

« back to all changes in this revision

Viewing changes to src/sound-service-dbus.c

  • Committer: Conor Curran
  • Date: 2010-01-27 13:21:02 UTC
  • Revision ID: conor.curran@canonical.com-20100127132102-xc5w5ob5kei1iblb
copied contents from lp:~cjcurran/wasilla/soundmenu without the noise

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Canonical Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *     Conor Curran <conor.curran@canonical.com>
 
6
 *     Cody Russell <crussell@canonical.com>
 
7
 *
 
8
 * This program is free software: you can redistribute it and/or modify it
 
9
 * under the terms of the GNU General Public License version 3, as published
 
10
 * by the Free Software Foundation.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
14
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
15
 * PURPOSE.  See the GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License along
 
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include "config.h"
 
23
#endif
 
24
 
 
25
#include <dbus/dbus-glib.h>
 
26
#include "dbus-shared-names.h"
 
27
#include "sound-service-dbus.h"
 
28
#include "sound-service-client.h"
 
29
#include "sound-service-server.h"
 
30
#include "common-defs.h"
 
31
#include "sound-service-marshal.h"
 
32
 
 
33
 
 
34
typedef struct _SoundServiceDbusPrivate SoundServiceDbusPrivate;
 
35
 
 
36
struct _SoundServiceDbusPrivate
 
37
{
 
38
    DBusGConnection *system_bus;
 
39
    DBusGConnection *connection;
 
40
};
 
41
 
 
42
/* Signals */
 
43
enum {
 
44
  SINK_INPUT_WHILE_MUTED,  
 
45
  LAST_SIGNAL
 
46
};
 
47
 
 
48
static guint signals[LAST_SIGNAL] = { 0 };
 
49
 
 
50
#define SOUND_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_SERVICE_DBUS_TYPE, SoundServiceDbusPrivate))
 
51
 
 
52
 
 
53
static void sound_service_dbus_class_init (SoundServiceDbusClass *klass);
 
54
static void sound_service_dbus_init       (SoundServiceDbus *self);
 
55
static void sound_service_dbus_dispose    (GObject *object);
 
56
static void sound_service_dbus_finalize   (GObject *object);
 
57
 
 
58
 
 
59
/* GObject Boilerplate */
 
60
G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT);
 
61
 
 
62
static void
 
63
sound_service_dbus_class_init (SoundServiceDbusClass *klass)
 
64
{
 
65
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
66
 
 
67
    g_type_class_add_private (object_class, sizeof(SoundServiceDbusPrivate));
 
68
 
 
69
    object_class->dispose = sound_service_dbus_dispose;
 
70
    object_class->finalize = sound_service_dbus_finalize;
 
71
 
 
72
    g_assert(klass != NULL);
 
73
    dbus_g_object_type_install_info(SOUND_SERVICE_DBUS_TYPE,
 
74
                                 &dbus_glib__sound_service_server_object_info);
 
75
  
 
76
    signals[SINK_INPUT_WHILE_MUTED] =  g_signal_new(SIGNAL_SINK_INPUT_WHILE_MUTED,
 
77
                                            G_TYPE_FROM_CLASS (klass),
 
78
                                            G_SIGNAL_RUN_LAST,
 
79
                                            0,
 
80
                                            NULL, NULL,
 
81
                                            _sound_service_marshal_VOID__INT_BOOLEAN,
 
82
                                            G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_BOOLEAN);
 
83
}
 
84
 
 
85
 
 
86
/**
 
87
Utility methods to emit signals from the service into the ether.
 
88
**/
 
89
void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_index, gboolean value){
 
90
/*    g_assert((num < LAST_SIGNAL) && (num >= 0));*/
 
91
    g_debug("Emitting signal: SINK_INPUT_WHILE_MUTED, with sink_index %i and value %i", sink_index, value);
 
92
    g_signal_emit(obj,
 
93
                signals[SINK_INPUT_WHILE_MUTED],
 
94
                0,
 
95
                sink_index,
 
96
                value);
 
97
}
 
98
 
 
99
    
 
100
 
 
101
 
 
102
static void
 
103
sound_service_dbus_init (SoundServiceDbus *self)
 
104
{
 
105
    GError *error = NULL;
 
106
    SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self);
 
107
 
 
108
        priv->system_bus = NULL;
 
109
        priv->connection = NULL;
 
110
 
 
111
    /* Get the system bus */
 
112
    priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
 
113
        /* Put the object on DBus */
 
114
        priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
 
115
 
 
116
        if (error != NULL) {
 
117
                g_error("Unable to connect to the session bus when creating application indicator: %s", error->message);
 
118
                g_error_free(error);
 
119
                return;
 
120
        }
 
121
        dbus_g_connection_register_g_object(priv->connection,
 
122
                                            "/org/ayatana/indicator/sound/service",
 
123
                                            G_OBJECT(self));
 
124
 
 
125
    return;
 
126
}
 
127
 
 
128
static void
 
129
sound_service_dbus_dispose (GObject *object)
 
130
{
 
131
        G_OBJECT_CLASS (sound_service_dbus_parent_class)->dispose (object);
 
132
        return;
 
133
}
 
134
 
 
135
static void
 
136
sound_service_dbus_finalize (GObject *object)
 
137
{
 
138
        G_OBJECT_CLASS (sound_service_dbus_parent_class)->finalize (object);
 
139
        return;
 
140
}
 
141