1 #ifndef __MESSAGE_PORT_H
2 #define __MESSAGE_PORT_H
6 # define EXPORT_API __attribute__((visibility("default")))
16 typedef gboolean bool;
22 * @brief Enumerations of error code for Application.
24 typedef enum _messageport_error_e
26 MESSAGEPORT_ERROR_NONE = 0, /**< Successful */
27 MESSAGEPORT_ERROR_IO_ERROR = -1, /**< Internal I/O error */
28 MESSAGEPORT_ERROR_OUT_OF_MEMORY = -2, /**< Out of memory */
29 MESSAGEPORT_ERROR_INVALID_PARAMETER = -3, /**< Invalid parameter */
30 MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND = -4, /**< The message port of the remote application is not found */
31 MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH = -5, /**< The remote application is not signed with the same certificate */
32 MESSAGEPORT_ERROR_MAX_EXCEEDED = -6, /**< The size of message has exceeded the maximum limit */
33 } messageport_error_e;
36 * @brief Called when a message is received from the remote application.
38 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
39 * @param [in] remote_app_id The ID of the remote application which has sent this message
40 * @param [in] remote_port The name of the remote message port
41 * @param [in] trusted_message @c true if the trusted remote message port is ready to receive the response data
42 * @param [in] data the data passed from the remote application
43 * @remarks @a data must be released with bundle_free() by you
44 * @remark @a remote_app_id and @a remote_port will be set if the remote application sends a bidirectional message, otherwise they are NULL.
46 typedef void (*messageport_message_cb)(int id, const char* remote_app_id, const char* remote_port, bool trusted_message, bundle* data);
49 * @brief Registers the local message port. @n
50 * If the message port name is already registered, the previous message port id returns and the callback function is changed.
52 * @param [in] local_port the name of the local message port
53 * @param [in] callback The callback function to be called when a message is received
54 * @return A message port id on success, otherwise a negative error value.
55 * @retval #MESSAGEPORT_ERROR_NONE Successful
56 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
57 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
58 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
61 messageport_register_local_port(const char* local_port, messageport_message_cb callback);
64 * @brief Registers the trusted local message port. @n
65 * If the message port name is already registered, the previous message port id returns and the callback function is changed. @n
66 * This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
68 * @param [in] local_port the name of the local message port
69 * @param [in] callback The callback function to be called when a message is received
70 * @return A message port id on success, otherwise a negative error value.
71 * @retval #MESSAGEPORT_ERROR_NONE Successful
72 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
73 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
74 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
77 messageport_register_trusted_local_port(const char* local_port, messageport_message_cb callback);
80 * @brief Checks if the message port of a remote application is registered.
82 * @param [in] remote_app_id The ID of the remote application
83 * @param [in] remote_port the name of the remote message port
84 * @param [out] exist @c true if the message port of the remote application exists, otherwise @c false
85 * @return 0 on success, otherwise a negative error value.
86 * @retval #MESSAGEPORT_ERROR_NONE Successful
87 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
88 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
89 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
91 EXPORT_API messageport_error_e
92 messageport_check_remote_port(const char* remote_app_id, const char *remote_port, bool *exist);
95 * @brief Checks if the trusted message port of a remote application is registered.
97 * @param [in] remote_app_id The ID of the remote application
98 * @param [in] remote_port the name of the remote message port
99 * @param [out] exist @c true if the message port of the remote application exists, otherwise @c false
100 * @return 0 on success, otherwise a negative error value.
101 * @retval #MESSAGEPORT_ERROR_NONE Successful
102 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
103 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
104 * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
105 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
107 EXPORT_API messageport_error_e
108 messageport_check_trusted_remote_port(const char* remote_app_id, const char *remote_port, bool *exist);
111 * @brief Sends a message to the message port of a remote application.
113 * @param [in] remote_app_id The ID of the remote application
114 * @param [in] remote_port the name of the remote message port
115 * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
116 * @return 0 on success, otherwise a negative error value.
117 * @retval #MESSAGEPORT_ERROR_NONE Successful
118 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
119 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
120 * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
121 * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
122 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
125 * #include <message-port.h>
127 * bundle *b = bundle_create();
128 * bundle_add(b, "key1", "value1");
129 * bundle_add(b, "key2", "value2");
131 * int ret = messageport_send_message("0123456789.BasicApp", "BasicAppPort", b);
136 EXPORT_API messageport_error_e
137 messageport_send_message(const char* remote_app_id, const char* remote_port, bundle* message);
140 * @brief Sends a trusted message to the message port of a remote application. @n
141 * This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
143 * @param [in] remote_app_id The ID of the remote application
144 * @param [in] remote_port the name of the remote message port
145 * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
146 * @return 0 on success, otherwise a negative error value.
147 * @retval #MESSAGEPORT_ERROR_NONE Successful
148 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
149 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
150 * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
151 * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
152 * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
153 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
155 EXPORT_API messageport_error_e
156 messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message);
159 * @brief Sends a message to the message port of a remote application. This method is used for the bidirectional communication.
161 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
162 * @param [in] remote_app_id The ID of the remote application
163 * @param [in] remote_port the name of the remote message port
164 * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
165 * @return 0 on success, otherwise a negative error value.
166 * @retval #MESSAGEPORT_ERROR_NONE Successful
167 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
168 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
169 * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
170 * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
171 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
174 * #include <message-port.h>
177 * OnMessageReceived(int id, const char* remote_app_id, const char* remote_port, bool trusted_port, bundle* data)
181 * int main(int argc, char *argv[])
183 * bundle *b = bundle_create();
184 * bundle_add(b, "key1", "value1");
185 * bundle_add(b, "key2", "value2");
187 * int id = messageport_register_local_port("HelloPort", OnMessageReceived);
189 * int ret = messageport_send_bidirectional_message(id, "0123456789.BasicApp", "BasicAppPort", b);
194 EXPORT_API messageport_error_e
195 messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* data);
198 * @brief Sends a trusted message to the message port of a remote application. This method is used for the bidirectional communication.
199 * This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
201 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
202 * @param [in] remote_app_id The ID of the remote application
203 * @param [in] remote_port the name of the remote message port
204 * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
205 * @return 0 on success, otherwise a negative error value.
206 * @retval #MESSAGEPORT_ERROR_NONE Successful
207 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
208 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
209 * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
210 * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
211 * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
212 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
214 EXPORT_API messageport_error_e
215 messageport_send_bidirectional_trusted_message(int id, const char* remote_app_id, const char* remote_port, bundle* data);
218 * @brief Gets the name of the local message port.
220 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
221 * @param [out] name The name of the local message port
222 * @return 0 on success, otherwise a negative error value.
223 * @retval #MESSAGEPORT_ERROR_NONE Successful
224 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
225 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
226 * @remarks @a name must be released with free() by you
228 EXPORT_API messageport_error_e
229 messageport_get_local_port_name(int id, char **name);
232 * @brief Checks if the local message port is trusted.
234 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
235 * @param [out] is_trusted true if the local message port is trusted
236 * @return 0 on success, otherwise a negative error value.
237 * @retval #MESSAGEPORT_ERROR_NONE Successful
238 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
239 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
241 EXPORT_API messageport_error_e
242 messageport_check_trusted_local_port(int id, bool *is_trusted);
246 #endif /* __MESSAGE_PORT_H */