1 /* MManager - a Desktop wide manager for multimedia applications.
3 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #include <glib-object.h>
23 #include <dbus/dbus-glib.h>
24 #include <dbus/dbus-glib-lowlevel.h>
25 #include "mm-dbus-manager.h"
27 static DBusGConnection
*
28 get_session_bus (void)
32 DBusConnection
*connection
;
35 bus
= dbus_g_bus_get (DBUS_BUS_SESSION
, &error
);
37 g_warning ("Couldn't connect to session bus: %s",
43 connection
= dbus_g_connection_get_connection (bus
);
44 dbus_connection_set_exit_on_disconnect (connection
, FALSE
);
51 get_bus_proxy (DBusGConnection
*connection
)
53 DBusGProxy
*bus_proxy
;
55 bus_proxy
= dbus_g_proxy_new_for_name (connection
,
63 get_name_on_bus (DBusGProxy
*proxy
)
70 g_return_val_if_fail (proxy
!= NULL
, FALSE
);
72 res
= dbus_g_proxy_call (proxy
,
75 G_TYPE_STRING
, "org.gnome.MediaManager",
81 g_warning ("Failed to acquire the name on the bus: %s", error
->message
);
87 if (result
!= DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
) {
88 g_warning ("Failed to acquire the name on the bus: %s", error
->message
);
101 bus_proxy_destroyed_cb (DBusGProxy
*bus_proxy
,
104 g_main_loop_quit (mainloop
);
107 int main (int argc
, char **argv
)
109 MMDBusManager
*manager
;
111 DBusGConnection
*connection
;
112 DBusGProxy
*bus_proxy
;
115 if (!g_thread_supported ()) {
116 g_thread_init (NULL
);
118 dbus_g_thread_init ();
121 connection
= get_session_bus ();
126 bus_proxy
= get_bus_proxy (connection
);
128 g_warning ("Error creating the bus proxy, exiting");
132 if (!get_name_on_bus (bus_proxy
)) {
133 g_warning ("Error getting the name on the bus, exiting");
137 /* this creates the manager object and registers it on the session bus */
138 manager
= g_object_new (MM_TYPE_DBUS_MANAGER
, NULL
);
144 mainloop
= g_main_loop_new (NULL
, FALSE
);
146 g_signal_connect (bus_proxy
, "destroy",
147 G_CALLBACK (bus_proxy_destroyed_cb
),
150 g_main_loop_run (mainloop
);
152 if (manager
!= NULL
) {
153 g_object_unref (manager
);
156 g_main_loop_unref (mainloop
);