msgport-service.c \
msgport-manager.h \
msgport-manager.c \
+ msgport-factory.h \
+ msgport-factory.c \
$(NULL)
libmessage_port_la_includedir = $(includedir)/
#include "message-port.h"
+#include "msgport-factory.h"
#include "msgport-manager.h"
#include "msgport-utils.h"
#include "common/log.h"
{
int port_id = 0; /* id of the port created */
messageport_error_e res;
- MsgPortManager *manager = msgport_get_manager ();
+ MsgPortManager *manager = msgport_factory_get_manager ();
- g_assert (manager);
- g_assert (MSGPORT_IS_MANAGER (manager));
+ if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
res = msgport_manager_register_service (manager, name, is_trusted, cb, &port_id);
_messageport_check_remote_port (const char *app_id, const char *port, gboolean is_trusted, gboolean *exists)
{
messageport_error_e res;
- MsgPortManager *manager = msgport_get_manager ();
+ MsgPortManager *manager = msgport_factory_get_manager ();
+
+ if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
res = msgport_manager_check_remote_service (manager, app_id, port, is_trusted, NULL);
static messageport_error_e
_messageport_send_message (const char *app_id, const char *port, gboolean is_trusted, bundle *message)
{
- MsgPortManager *manager = msgport_get_manager ();
+ MsgPortManager *manager = msgport_factory_get_manager ();
+
+ if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
GVariant *v_data = bundle_to_variant_map (message);
messageport_error_e
_messageport_send_bidirectional_message (int id, const gchar *remote_app_id, const gchar *remote_port, gboolean is_trusted, bundle *message)
{
- MsgPortManager *manager = msgport_get_manager ();
+ MsgPortManager *manager = msgport_factory_get_manager ();
+
+ if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
GVariant *v_data = bundle_to_variant_map (message);
}
messageport_error_e
-messageport_get_local_port_name(int port_id, char **name_out)
+messageport_get_local_port_name(int id, char **name_out)
{
- MsgPortManager *manager = msgport_get_manager ();
+ MsgPortManager *manager = msgport_factory_get_manager ();
+
+ if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
- return msgport_manager_get_service_name (manager, port_id, name_out);
+ return msgport_manager_get_service_name (manager, id, name_out);
}
messageport_error_e
-messageport_check_trusted_local_port (int id, gboolean *trusted)
+messageport_check_trusted_local_port (int id, gboolean *is_trusted_out)
{
- (void) id;
+ MsgPortManager *manager = msgport_factory_get_manager ();
- if (trusted) *trusted = FALSE;
+ if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
- return MESSAGEPORT_ERROR_NONE;
+ return msgport_manager_get_service_is_trusted (manager, id, is_trusted_out);
}
--- /dev/null
+#include "msgport-factory.h"
+#include "msgport-manager.h"
+#include <glib.h>
+
+GHashTable *__managers ; /* GThread:MsgPortManager */
+G_LOCK_DEFINE(managers);
+
+static
+void msgport_factory_init ()
+{
+ G_LOCK(managers);
+
+ if (!__managers)
+ __managers = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL, (GDestroyNotify)g_object_unref);
+
+ G_UNLOCK(managers);
+}
+
+void msgport_factory_uninit ()
+{
+ G_LOCK(managers);
+
+ if (__managers) {
+ g_hash_table_destroy (__managers);
+ __managers = NULL;
+ }
+
+ G_UNLOCK(managers);
+}
+
+MsgPortManager * msgport_factory_get_manager ()
+{
+ MsgPortManager *manager = NULL;
+ GThread *self_thread = g_thread_self ();
+
+ if (!__managers) msgport_factory_init ();
+
+ G_LOCK(managers);
+
+ manager = MSGPORT_MANAGER (g_hash_table_lookup (__managers, self_thread));
+
+ if (!manager) {
+ manager = msgport_manager_new ();
+
+ if (manager)
+ g_hash_table_insert (__managers, (gpointer)self_thread, manager);
+ }
+
+ G_UNLOCK(managers);
+
+ return manager;
+}
+
--- /dev/null
+#ifndef __MSGPORT_FACTORY_H
+#define __MSGPORT_FACTORY_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _MsgPortManager MsgPortManager;
+
+MsgPortManager * msgport_factory_get_manager ();
+
+G_END_DECLS
+
+#endif /* __MSGPORT_FACTORY_H */
return g_object_new (MSGPORT_TYPE_MANAGER, NULL);
}
-static MsgPortManager *__manager;
-
-MsgPortManager * msgport_get_manager ()
-{
- if (!__manager) {
- __manager = msgport_manager_new ();
- }
-
- return __manager;
-}
-
static messageport_error_e
_create_and_cache_service (MsgPortManager *manager, gchar *object_path, messageport_message_cb cb, int *service_id)
{
if (!service) return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
*name_out = g_strdup (msgport_service_name (service));
- DBG ("PORT NAME : %s", *name_out);
+
+ return MESSAGEPORT_ERROR_NONE;
+}
+
+messageport_error_e
+msgport_manager_get_service_is_trusted (MsgPortManager *manager, int service_id, gboolean *is_trusted_out)
+{
+ MsgPortService *service = NULL;
+ g_return_val_if_fail (manager && MSGPORT_IS_MANAGER (manager), MESSAGEPORT_ERROR_IO_ERROR);
+ g_return_val_if_fail (manager->proxy, MESSAGEPORT_ERROR_IO_ERROR);
+ g_return_val_if_fail (service_id && is_trusted_out, MESSAGEPORT_ERROR_INVALID_PARAMETER);
+
+ service = _get_local_port (manager, service_id);
+ if (!service) return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
+
+ *is_trusted_out = msgport_service_is_trusted (service);
return MESSAGEPORT_ERROR_NONE;
}
GType msgport_manager_get_type (void);
MsgPortManager *
-msgport_get_manager ();
+msgport_manager_new ();
messageport_error_e
msgport_manager_register_service (MsgPortManager *manager, const gchar *port_name, gboolean is_trusted, messageport_message_cb cb, int *service_id_out);
msgport_manager_get_service_name (MsgPortManager *manager, int port_id, gchar **name_out);
messageport_error_e
+msgport_manager_get_service_is_trusted (MsgPortManager *manager, int port_id, gboolean *is_trusted_out);
+
+messageport_error_e
msgport_manager_unregister_service (MsgPortManager *manager, int service_id);
messageport_error_e