1 #ifndef __MESSAGE_PORT_H
2 #define __MESSAGE_PORT_H
6 # define EXPORT_API __attribute__((visibility("default")))
18 * @brief Enumerations of error code for Application.
20 typedef enum _messageport_error_e
22 MESSAGEPORT_ERROR_NONE = 0, /**< Successful */
23 MESSAGEPORT_ERROR_IO_ERROR = -1, /**< Internal I/O error */
24 MESSAGEPORT_ERROR_OUT_OF_MEMORY = -2, /**< Out of memory */
25 MESSAGEPORT_ERROR_INVALID_PARAMETER = -3, /**< Invalid parameter */
26 MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND = -4, /**< The message port of the remote application is not found */
27 MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH = -5, /**< The remote application is not signed with the same certificate */
28 MESSAGEPORT_ERROR_MAX_EXCEEDED = -6, /**< The size of message has exceeded the maximum limit */
29 } messageport_error_e;
32 * @brief Called when a message is received from the remote application.
34 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
35 * @param [in] remote_app_id The ID of the remote application which has sent this message
36 * @param [in] remote_port The name of the remote message port
37 * @param [in] trusted_message @c true if the trusted remote message port is ready to receive the response data
38 * @param [in] data the data passed from the remote application
39 * @remarks @a data must be released with bundle_free() by you
40 * @remark @a remote_app_id and @a remote_port will be set if the remote application sends a bidirectional message, otherwise they are NULL.
42 typedef void (*messageport_message_cb)(int id, const char* remote_app_id, const char* remote_port, gboolean trusted_message, bundle* data);
45 * @brief Registers the local message port. @n
46 * If the message port name is already registered, the previous message port id returns and the callback function is changed.
48 * @param [in] local_port the name of the local message port
49 * @param [in] callback The callback function to be called when a message is received
50 * @return A message port id on success, otherwise a negative error value.
51 * @retval #MESSAGEPORT_ERROR_NONE Successful
52 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
53 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
54 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
57 messageport_register_local_port(const char* local_port, messageport_message_cb callback);
60 * @brief Registers the trusted local message port. @n
61 * If the message port name is already registered, the previous message port id returns and the callback function is changed. @n
62 * This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
64 * @param [in] local_port the name of the local message port
65 * @param [in] callback The callback function to be called when a message is received
66 * @return A message port id on success, otherwise a negative error value.
67 * @retval #MESSAGEPORT_ERROR_NONE Successful
68 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
69 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
70 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
73 messageport_register_trusted_local_port(const char* local_port, messageport_message_cb callback);
76 * @brief Checks if the message port of a remote application is registered.
78 * @param [in] remote_app_id The ID of the remote application
79 * @param [in] remote_port the name of the remote message port
80 * @param [out] exist @c true if the message port of the remote application exists, otherwise @c false
81 * @return 0 on success, otherwise a negative error value.
82 * @retval #MESSAGEPORT_ERROR_NONE Successful
83 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
84 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
85 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
87 EXPORT_API messageport_error_e
88 messageport_check_remote_port(const char* remote_app_id, const char *remote_port, gboolean *exist);
91 * @brief Checks if the trusted message port of a remote application is registered.
93 * @param [in] remote_app_id The ID of the remote application
94 * @param [in] remote_port the name of the remote message port
95 * @param [out] exist @c true if the message port of the remote application exists, otherwise @c false
96 * @return 0 on success, otherwise a negative error value.
97 * @retval #MESSAGEPORT_ERROR_NONE Successful
98 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
99 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
100 * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
101 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
103 EXPORT_API messageport_error_e
104 messageport_check_trusted_remote_port(const char* remote_app_id, const char *remote_port, gboolean *exist);
107 * @brief Sends a message to the message port of a remote application.
109 * @param [in] remote_app_id The ID of the remote application
110 * @param [in] remote_port the name of the remote message port
111 * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
112 * @return 0 on success, otherwise a negative error value.
113 * @retval #MESSAGEPORT_ERROR_NONE Successful
114 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
115 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
116 * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
117 * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
118 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
121 * #include <message-port.h>
123 * bundle *b = bundle_create();
124 * bundle_add(b, "key1", "value1");
125 * bundle_add(b, "key2", "value2");
127 * int ret = messageport_send_message("0123456789.BasicApp", "BasicAppPort", b);
132 EXPORT_API messageport_error_e
133 messageport_send_message(const char* remote_app_id, const char* remote_port, bundle* message);
136 * @brief Sends a trusted message to the message port of a remote application. @n
137 * This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
139 * @param [in] remote_app_id The ID of the remote application
140 * @param [in] remote_port the name of the remote message port
141 * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
142 * @return 0 on success, otherwise a negative error value.
143 * @retval #MESSAGEPORT_ERROR_NONE Successful
144 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
145 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
146 * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
147 * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
148 * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
149 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
151 EXPORT_API messageport_error_e
152 messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message);
155 * @brief Sends a message to the message port of a remote application. This method is used for the bidirectional communication.
157 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
158 * @param [in] remote_app_id The ID of the remote application
159 * @param [in] remote_port the name of the remote message port
160 * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
161 * @return 0 on success, otherwise a negative error value.
162 * @retval #MESSAGEPORT_ERROR_NONE Successful
163 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
164 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
165 * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
166 * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
167 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
170 * #include <message-port.h>
173 * OnMessageReceived(int id, const char* remote_app_id, const char* remote_port, bool trusted_port, bundle* data)
177 * int main(int argc, char *argv[])
179 * bundle *b = bundle_create();
180 * bundle_add(b, "key1", "value1");
181 * bundle_add(b, "key2", "value2");
183 * int id = messageport_register_local_port("HelloPort", OnMessageReceived);
185 * int ret = messageport_send_bidirectional_message(id, "0123456789.BasicApp", "BasicAppPort", b);
190 EXPORT_API messageport_error_e
191 messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* data);
194 * @brief Sends a trusted message to the message port of a remote application. This method is used for the bidirectional communication.
195 * This allows communications only if the applications are signed with the same certificate which is uniquely assigned to the developer.
197 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
198 * @param [in] remote_app_id The ID of the remote application
199 * @param [in] remote_port the name of the remote message port
200 * @param [in] message the message to be passed to the remote application, the recommended message size is under 4KB
201 * @return 0 on success, otherwise a negative error value.
202 * @retval #MESSAGEPORT_ERROR_NONE Successful
203 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
204 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
205 * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
206 * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
207 * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
208 * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
210 EXPORT_API messageport_error_e
211 messageport_send_bidirectional_trusted_message(int id, const char* remote_app_id, const char* remote_port, bundle* data);
214 * @brief Gets the name of the local message port.
216 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
217 * @param [out] name The name of the local message port
218 * @return 0 on success, otherwise a negative error value.
219 * @retval #MESSAGEPORT_ERROR_NONE Successful
220 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
221 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
222 * @remarks @a name must be released with free() by you
224 EXPORT_API messageport_error_e
225 messageport_get_local_port_name(int id, char **name);
228 * @brief Checks if the local message port is trusted.
230 * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
231 * @param [out] is_trusted true if the local message port is trusted
232 * @return 0 on success, otherwise a negative error value.
233 * @retval #MESSAGEPORT_ERROR_NONE Successful
234 * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
235 * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
237 EXPORT_API messageport_error_e
238 messageport_check_trusted_local_port(int id, gboolean *is_trusted);
242 #endif /* __MESSAGE_PORT_H */