~audio-recorder/audio-recorder/trunk

« back to all changes in this revision

Viewing changes to src/dbus-skype.c

  • Committer: Osmo Antero
  • Date: 2012-04-18 19:22:01 UTC
  • Revision ID: osmoma@gmail.com-20120418192201-ejjs6ikv7o4aznbi
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <dbus/dbus-glib.h>
26
26
 
27
27
#include "dbus-player.h"
28
 
#include "dbus-mpris.h"
 
28
#include "dbus-mpris2.h"
29
29
#include "dbus-skype.h"
30
30
 
31
31
#include "utility.h"
55
55
static gint g_connect_count = 0;
56
56
GMutex *g_skype_mutex = NULL;
57
57
 
 
58
static DBusGConnection *g_skype_dbus_conn = NULL;
58
59
static DBusGProxy *g_proxy_main = NULL;
59
60
static DBusGProxy *g_proxy_send = NULL;
60
61
static SkypeService *g_service_object = NULL;
100
101
void skype_module_exit() {
101
102
    LOG_DEBUG("Clean up dbus-skype.c.\n");
102
103
 
103
 
    // Disconnect from Skype  (if connected)
 
104
    // Disconnect from Skype (if connected)
104
105
    skype_disconnect();
105
106
 
106
107
    if (G_IS_OBJECT(g_proxy_main))
119
120
    g_skype_mutex = NULL;
120
121
}
121
122
 
 
123
DBusGConnection *skype_connect_to_dbus() {
 
124
    // Connect to glib/DBus
 
125
    GError *error = NULL;
 
126
 
 
127
    if (!g_skype_dbus_conn) {
 
128
        g_skype_dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
 
129
 
 
130
        if (!g_skype_dbus_conn) {
 
131
            LOG_ERROR("dbus_player_connect_to_dbus: Cannot connect to DBus: %s\n", error ? error->message : "");
 
132
 
 
133
            if (error)
 
134
                g_error_free(error);
 
135
 
 
136
            return NULL;
 
137
        }
 
138
    }
 
139
    return g_skype_dbus_conn;
 
140
}
 
141
 
 
142
void skype_disconnect_from_dbus() {
 
143
    // Disconnect from glib/DBus
 
144
    if (g_skype_dbus_conn)
 
145
        dbus_g_connection_unref(g_skype_dbus_conn);
 
146
 
 
147
    g_skype_dbus_conn = NULL;
 
148
}
 
149
 
122
150
void skype_set_record_ringing_sound(gboolean yes_no) {
123
151
    conf_save_boolean_value("skype/record-ringing-sound", yes_no);
124
152
    g_skype.record_ringing_sound = yes_no;
144
172
}
145
173
 
146
174
gboolean skype_is_running(gchar *service_name) {
147
 
    DBusGConnection *dbus_conn = dbus_player_connect_to_dbus();
 
175
    DBusGConnection *dbus_conn = skype_connect_to_dbus();
148
176
 
149
177
    // Set lock (avoid overheating the DBus)
150
178
    g_mutex_lock(g_skype_mutex);
229
257
}
230
258
 
231
259
void skype_disconnect() {
232
 
    // Disconnect this app from teh Skype
 
260
    // Disconnect this app from the Skype
233
261
 
234
262
    g_connect_count = -1;
235
263
    g_skype.call_no = 0;
236
264
 
237
265
    // Unregister notify methods
238
266
    skype_setup_notify_methods(FALSE/*unregister*/);
 
267
 
 
268
    // Disconnct from DBus
 
269
    skype_disconnect_from_dbus();
239
270
}
240
271
 
241
272
void skype_start_app(gpointer player_rec) {
455
486
    g_mutex_lock(g_skype_mutex);
456
487
 
457
488
    // Connection
458
 
    DBusGConnection *dbus_conn = dbus_player_connect_to_dbus();
 
489
    DBusGConnection *dbus_conn = skype_connect_to_dbus();
459
490
 
460
491
    // Create proxy
461
492
    GError *error = NULL;
514
545
    // Register/unregister Skype signals
515
546
 
516
547
    // Connect to DBus
517
 
    DBusGConnection *dbus_conn = dbus_player_connect_to_dbus();
 
548
    DBusGConnection *dbus_conn = skype_connect_to_dbus();
518
549
 
519
550
    /* Some debug info from the dbus_monitor.
520
551
    $ dbus_monitor
548
579
 
549
580
        // Register
550
581
        dbus_g_object_type_install_info(G_TYPE_FROM_INSTANCE(g_service_object), &dbus_glib_server_object_object_info);
 
582
        
551
583
        dbus_g_connection_register_g_object(dbus_conn, SKYPE_SERVICE_PATH/*/com/Skype/Client*/, (GObject*)g_service_object);
552
584
 
553
585
        LOG_SKYPE("Setup of service object OK. Notification methods activated & OK.\n");
881
913
    // Call dbus-player and rec-manager.
882
914
    // We simply create a MediaPlayer record and send it to the dbus-player.c (it passes this further to rec-manager.c and gst-recorder.c)
883
915
 
884
 
    MediaPlayerRec *player = mpris_player_new(NULL);
 
916
    MediaPlayerRec *player = mpris2_player_new(NULL);
885
917
    // This record must be active
886
918
    player->active = TRUE;
887
919
    TrackInfo *track = &player->track;
931
963
 
932
964
    // Call dbus-player and rec-manager.
933
965
    // We simply create a MediaPlayer record and send it to the dbus-player.c (it passes this further to rec-manager.c and gst-recorder.c)
934
 
    MediaPlayerRec *player = mpris_player_new(NULL);
 
966
    MediaPlayerRec *player = mpris2_player_new(NULL);
935
967
    player->active = TRUE;
936
968
    str_copy(player->track.track, g_skype.filename, MPRIS_STRLEN-1);
937
969
    player->track.status = PLAYER_STATUS_STOPPED;
971
1003
 
972
1004
    // Call dbus-player and rec-manager.
973
1005
    // We simply create a MediaPlayer record and send it to the dbus-player.c (it passes this further to rec-manager.c and gst-recorder.c)
974
 
    MediaPlayerRec *player = mpris_player_new(NULL);
 
1006
    MediaPlayerRec *player = mpris2_player_new(NULL);
975
1007
    player->active = TRUE;
976
1008
    player->track.status = PLAYER_STATUS_PAUSED;
977
1009