1 #include "msgport-manager.h"
2 #include "message-port.h"
3 #include "common/log.h"
4 #include "dbus-manager-glue.h"
9 MsgPortGlueManagerPorxy *proxy;
10 GHashTable *services; /* {gchar*:MsgPortService*} */
11 GList *local_service_list;
15 static MsgPortManager __manager;
17 MsgPortManager * msgport_manager_new ()
20 GDBusConnection *connection = NULL;
21 MsgPortManager *manager = g_slice_new0(MsgPortManager);
22 gchar *bus_address = g_strdup_printf (MESSAGEPORT_BUS_ADDRESS, g_get_user_runtime_dir());
28 connection = g_dbus_connection_new_for_address_sync (bus_address,
29 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
33 ERR ("Unable to get bus connection for address %s: %s", bus_address, error->message);
38 manager->services = g_hash_table_new_full (g_str_hash, g_str_equal,
39 g_free, (GDestroyNotify)g_object_unref);
40 manager->local_servcie_list = NULL;
41 manager->n_local_services = 0;
42 manager->proxy = msgport_dbus_glue_manager_proxy_new_sync (
43 connection, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, "/", NULL, &error);
45 if (!manager->proxy) {
46 ERR ("Unable to get manager proxy : %s", error->message);
54 if (manager) msgport_manager_unref (manager);
58 MsgPortManager * msgport_get_manager () {
60 __manager = magport_manager_new ();
65 int msgport_manager_register_service (MsgPortManager *manger, const gchar *port_name, gboolean is_trusted)
68 g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), MESSAGEPORT_ERROR_IO_ERROR);
70 if (!port_name) return MESSAGEPORT_ERROR_INVALID_PARAMETER;
72 msgport_dbus_glue_manager_call_register_service_sync (manager->proxy,
73 port_name, is_trusted, &object_path, NULL, &error);
76 WARN ("unable to register service (%s): %s", port_name, error->message);
78 return MESSAGEPORT_ERROR_IO_ERROR;
81 MsgPortService *service = msgport_service_new (
82 g_dbus_proxy_get_connection (G_DBUS_PROXY(manager->proxy)),
85 WARN ("unable to get service proxy for path %s: %s", object_path, error->message);
88 return MESSAGEPORT_ERROR_IO_ERROR;
91 g_hash_table_insert (manager->services, object_path, service);
92 manager->local_service_list = g_list_append (manager->local_service_list, object_path);
93 manager->n_local_services++;
95 return manager->n_local_services;
99 msgport_service_new (GDBusConnection *connection, const gchar *path, GError **error)
101 MsgPortService *service = g_object_new (MSGPORT_TYPE_SERVICE, NULL);
104 /* FIXME: return no merory error */
108 service->proxy = msgport_dbus_glue_service_proxy_new_sync (connection,
109 g_dbus_proxy_get_connection (G_DBUS_PROXY(manager->proxy)),
110 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, object_path, NULL, error);
111 if (!service->proxy) {
112 g_object_unref (service);