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.
23 #include <glib-object.h>
24 #include <dbus/dbus-glib.h>
25 #include <dbus/dbus-glib-bindings.h>
26 #include "mm-dbus-manager.h"
27 #include "mm-dbus-manager-type-builtins.h"
29 gboolean
mm_dbus_manager_register_app (MMDBusManager
*manager
, char *path
, GError
**error
);
30 gboolean
mm_dbus_manager_get_registered_apps (MMDBusManager
*manager
, char ***app_paths
,
33 #include "mm-dbus-manager-server-bindings.h"
35 #define MM_DBUS_MANAGER_GET_PRIVATE(o) \
36 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_DBUS_MANAGER, MMDBusManagerDetails))
38 struct _MMDBusManagerDetails
{
39 GPtrArray
*application_paths
;
40 DBusGProxy
*bus_proxy
;
41 DBusGConnection
*connection
;
44 G_DEFINE_TYPE (MMDBusManager
, mm_dbus_manager
, G_TYPE_OBJECT
);
47 mm_dbus_manager_finalize (GObject
*o
)
49 MMDBusManager
*m
= MM_DBUS_MANAGER (o
);
51 g_ptr_array_foreach (m
->details
->application_paths
,
54 g_ptr_array_free (m
->details
->application_paths
, TRUE
);
56 G_OBJECT_CLASS (mm_dbus_manager_parent_class
)->finalize (o
);
60 mm_dbus_manager_class_init (MMDBusManagerClass
*klass
)
62 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
64 object_class
->finalize
= mm_dbus_manager_finalize
;
66 dbus_g_object_type_install_info (MM_TYPE_DBUS_MANAGER
,
67 &dbus_glib_mm_dbus_manager_object_info
);
68 dbus_g_error_domain_register (MM_DBUS_ERROR_QUARK
, NULL
, MM_TYPE_MD_BUS_ERROR_ENUM
);
70 g_type_class_add_private (klass
, sizeof (MMDBusManagerDetails
));
74 register_on_the_bus (MMDBusManager
*manager
)
77 MMDBusManagerDetails
*details
= manager
->details
;
79 details
->connection
= dbus_g_bus_get (DBUS_BUS_SESSION
, &error
);
80 if (!details
->connection
) {
81 g_critical ("Error getting a connection to the session bus: %s",
87 details
->bus_proxy
= dbus_g_proxy_new_for_name (details
->connection
,
92 /* register the object */
93 dbus_g_connection_register_g_object (details
->connection
,
99 mm_dbus_manager_init (MMDBusManager
*manager
)
101 MMDBusManagerDetails
*details
= manager
->details
= MM_DBUS_MANAGER_GET_PRIVATE (manager
);
103 details
->application_paths
= g_ptr_array_new ();
104 register_on_the_bus (manager
);
107 /* implementation of dbus methods */
110 mm_dbus_manager_register_app (MMDBusManager
*manager
, char *path
, GError
**error
)
112 g_return_val_if_fail (MM_IS_DBUS_MANAGER (manager
), FALSE
);
115 /* set the error, the path can't be NULL */
116 g_set_error (error
, MM_DBUS_ERROR_QUARK
,
117 MM_DBUS_ERROR_NULL_PATH
,
118 "Error: can't register an app with NULL path");
122 g_ptr_array_add (manager
->details
->application_paths
,
128 mm_dbus_manager_get_registered_apps (MMDBusManager
*manager
,
133 int size
= manager
->details
->application_paths
->len
;
134 g_return_val_if_fail (MM_IS_DBUS_MANAGER (manager
), FALSE
);
136 if (app_paths
== NULL
) {
140 *app_paths
= g_new (gchar
*, size
+ 1);
141 (*app_paths
) [size
] = NULL
;
143 for (index
= 0; index
< size
; index
++) {
144 (*app_paths
) [index
] =
145 g_strdup (g_ptr_array_index (manager
->details
->application_paths
, index
));