1 #include "message-port.h"
2 #include "msgport-factory.h"
3 #include "msgport-manager.h"
4 #include "msgport-utils.h"
5 #include "common/log.h"
8 _messageport_register_port (const char *name, gboolean is_trusted, messageport_message_cb cb)
10 int port_id = 0; /* id of the port created */
11 messageport_error_e res;
12 MsgPortManager *manager = msgport_factory_get_manager ();
14 if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
16 res = msgport_manager_register_service (manager, name, is_trusted, cb, &port_id);
18 return port_id > 0 ? port_id : (int)res;
21 static messageport_error_e
22 _messageport_check_remote_port (const char *app_id, const char *port, gboolean is_trusted, gboolean *exists)
24 messageport_error_e res;
25 MsgPortManager *manager = msgport_factory_get_manager ();
27 if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
29 res = msgport_manager_check_remote_service (manager, app_id, port, is_trusted, NULL);
31 if (exists) *exists = (res == MESSAGEPORT_ERROR_NONE);
36 static messageport_error_e
37 _messageport_send_message (const char *app_id, const char *port, gboolean is_trusted, bundle *message)
39 MsgPortManager *manager = msgport_factory_get_manager ();
41 if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
43 GVariant *v_data = bundle_to_variant_map (message);
45 return msgport_manager_send_message (manager, app_id, port, is_trusted, v_data);
49 _messageport_send_bidirectional_message (int id, const gchar *remote_app_id, const gchar *remote_port, gboolean is_trusted, bundle *message)
51 MsgPortManager *manager = msgport_factory_get_manager ();
53 if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
55 GVariant *v_data = bundle_to_variant_map (message);
57 return msgport_manager_send_bidirectional_message (manager, id, remote_app_id, remote_port, is_trusted, v_data);
65 messageport_register_local_port(const char* local_port, messageport_message_cb callback)
67 return _messageport_register_port (local_port, FALSE, callback);
71 messageport_register_trusted_local_port (const char *local_port, messageport_message_cb callback)
73 return _messageport_register_port (local_port, TRUE, callback);
77 messageport_check_remote_port (const char *remote_app_id, const char *port_name, gboolean *exists)
79 return _messageport_check_remote_port (remote_app_id, port_name, FALSE, exists);
83 messageport_check_trusted_remote_port (const char *remote_app_id, const char *port_name, gboolean *exists)
85 return _messageport_check_remote_port (remote_app_id, port_name, TRUE, exists);
89 messageport_send_message (const char* remote_app_id, const char* remote_port, bundle* message)
91 return _messageport_send_message (remote_app_id, remote_port, FALSE, message);
95 messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message)
97 return _messageport_send_message (remote_app_id, remote_port, TRUE, message);
101 messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* data)
103 return _messageport_send_bidirectional_message (id, remote_app_id, remote_port, FALSE, data);
107 messageport_send_bidirectional_trusted_message (int id, const char *remote_app_id, const char *remote_port, bundle *data)
109 return _messageport_send_bidirectional_message (id, remote_app_id, remote_port, TRUE, data);
113 messageport_get_local_port_name(int id, char **name_out)
115 MsgPortManager *manager = msgport_factory_get_manager ();
117 if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
119 return msgport_manager_get_service_name (manager, id, name_out);
123 messageport_check_trusted_local_port (int id, gboolean *is_trusted_out)
125 MsgPortManager *manager = msgport_factory_get_manager ();
127 if (!manager) return MESSAGEPORT_ERROR_IO_ERROR;
129 return msgport_manager_get_service_is_trusted (manager, id, is_trusted_out);