1 #include "message-port.h"
2 #include "msgport-manager.h"
3 #include "msgport-utils.h"
4 #include "common/log.h"
7 _messageport_register_port (const char *name, gboolean is_trusted, messageport_message_cb cb)
9 int port_id = 0; /* id of the port created */
10 messageport_error_e res;
11 MsgPortManager *manager = msgport_get_manager ();
14 g_assert (MSGPORT_IS_MANAGER (manager));
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_get_manager ();
27 res = msgport_manager_check_remote_service (manager, app_id, port, is_trusted, NULL);
29 if (exists) *exists = (res == MESSAGEPORT_ERROR_NONE);
34 static messageport_error_e
35 _messageport_send_message (const char *app_id, const char *port, gboolean is_trusted, bundle *message)
37 MsgPortManager *manager = msgport_get_manager ();
39 GVariant *v_data = bundle_to_variant_map (message);
41 return msgport_manager_send_message (manager, app_id, port, is_trusted, v_data);
45 _messageport_send_bidirectional_message (int id, const gchar *remote_app_id, const gchar *remote_port, gboolean is_trusted, bundle *message)
47 MsgPortManager *manager = msgport_get_manager ();
49 GVariant *v_data = bundle_to_variant_map (message);
51 return msgport_manager_send_bidirectional_message (manager, id, remote_app_id, remote_port, is_trusted, v_data);
59 messageport_register_local_port(const char* local_port, messageport_message_cb callback)
61 return _messageport_register_port (local_port, FALSE, callback);
65 messageport_register_trusted_local_port (const char *local_port, messageport_message_cb callback)
67 return _messageport_register_port (local_port, TRUE, callback);
71 messageport_check_remote_port (const char *remote_app_id, const char *port_name, gboolean *exists)
73 return _messageport_check_remote_port (remote_app_id, port_name, FALSE, exists);
77 messageport_check_trusted_remote_port (const char *remote_app_id, const char *port_name, gboolean *exists)
79 return _messageport_check_remote_port (remote_app_id, port_name, TRUE, exists);
83 messageport_send_message (const char* remote_app_id, const char* remote_port, bundle* message)
85 return _messageport_send_message (remote_app_id, remote_port, FALSE, message);
89 messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message)
91 return _messageport_send_message (remote_app_id, remote_port, TRUE, message);
95 messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* data)
97 return _messageport_send_bidirectional_message (id, remote_app_id, remote_port, FALSE, data);
101 messageport_send_bidirectional_trusted_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, TRUE, data);
107 messageport_get_local_port_name(int port_id, char **name_out)
109 MsgPortManager *manager = msgport_get_manager ();
111 return msgport_manager_get_service_name (manager, port_id, name_out);
115 messageport_check_trusted_local_port (int id, gboolean *trusted)
119 if (trusted) *trusted = FALSE;
121 return MESSAGEPORT_ERROR_NONE;