2 * Copyright (c) 2018 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __TIZEN_APPFW_RPC_PORT_INCLUDE_H__
18 #define __TIZEN_APPFW_RPC_PORT_INCLUDE_H__
25 #include <tizen_error.h>
28 * @addtogroup CAPI_RPC_PORT_MODULE
34 * @brief Enumeration for error codes of a rpc port.
35 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
38 RPC_PORT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
39 RPC_PORT_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< Internal I/O error */
40 RPC_PORT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
41 RPC_PORT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
42 RPC_PORT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
46 * @brief Enumeration for types of communication channels.
47 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
50 RPC_PORT_PORT_MAIN, /**< Main channel */
51 RPC_PORT_PORT_CALLBACK, /**< The channel for callbacks */
52 } rpc_port_port_type_e;
57 * @brief The rpc port handle.
58 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
60 typedef void *rpc_port_h;
63 * @brief Reads data from an RPC port.
64 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
66 * @param[in] h The rpc port handle
67 * @param[out] buf Buffer for reading data
68 * @param[in] size Size for reading data
70 * @return @c 0 on success,
71 * otherwise a negative error value
72 * @retval #RPC_PORT_ERROR_NONE Successful
73 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
74 * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error
75 * @see rpc_port_write()
77 int rpc_port_read(rpc_port_h h, void *buf, unsigned int size);
80 * @brief Writes data to an RPC port.
81 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
83 * @param[in] h The rpc port handle
84 * @param[in] buf Buffer for writing data
85 * @param[in] size Size for writing data
87 * @return @c 0 on success,
88 * otherwise a negative error value
89 * @retval #RPC_PORT_ERROR_NONE Successful
90 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
91 * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error
92 * @see rpc_port_read()
94 int rpc_port_write(rpc_port_h h, const void *buf, unsigned int size);
100 * @brief Called when the proxy is connected.
101 * @details The function is called when the proxy is connected with stub by port.
102 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
103 * @param[in] receiver The target stub app id
104 * @param[in] port_name The name of the port
105 * @param[in] port The rpc port handle for reading and writing
106 * @param[in] user_data The user data passed from the register function
108 typedef void (*rpc_port_proxy_connected_event_cb)(const char *receiver,
109 const char *port_name, rpc_port_h port, void *user_data);
112 * @brief Called when the proxy is disconnected.
113 * @details The function is called when the proxy is disconnected from stub.
114 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
115 * @param[in] receiver The target stub app id
116 * @param[in] port_name The name of the port
117 * @param[in] user_data The user data passed from the register function
119 typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *receiver,
120 const char *port_name, void *user_data);
123 * @brief Called when the proxy is rejected.
124 * @details The function is called when the proxy is rejected to connect stub.
125 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
126 * @param[in] receiver The target stub app id
127 * @param[in] port_name The name of the port
128 * @param[in] user_data The user data passed from the register function
130 typedef void (*rpc_port_proxy_rejected_event_cb)(const char *receiver,
131 const char *port_name, void *user_data);
134 * @brief Called when the proxy received data.
135 * @details The function is called when the proxy received data from stub.
136 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
137 * @param[in] receiver The target stub app id
138 * @param[in] port_name The name of the port
139 * @param[in] user_data The user data passed from the register function
141 typedef void (*rpc_port_proxy_received_event_cb)(const char *receiver,
142 const char *port_name, void *user_data);
145 * @brief The rpc port proxy handle.
146 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
148 typedef void *rpc_port_proxy_h;
151 * @brief Creates a rpc port proxy handle.
152 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
153 * @remarks You must release @a h using rpc_port_proxy_destroy().
154 * @param[out] h The rpc port proxy handle that is newly created
155 * @return @c 0 on success,
156 * otherwise a negative error value
157 * @retval #RPC_PORT_ERROR_NONE Successful
158 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
159 * @see rpc_port_proxy_destroy()
161 int rpc_port_proxy_create(rpc_port_proxy_h *h);
164 * @brief Destroys a rpc port proxy handle.
165 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
166 * @param[in] h The rpc port proxy handle
167 * @return @c 0 on success,
168 * otherwise a negative error value
169 * @retval #RPC_PORT_ERROR_NONE Successful
170 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
171 * @see rpc_port_proxy_create()
173 int rpc_port_proxy_destroy(rpc_port_proxy_h h);
176 * @brief Connects to @a port of @a appid.
177 * @details To send and receive data, the proxy should connect to port of stub
178 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
180 * @privilege %http://tizen.org/privilege/appmanager.launch \n
181 * %http://tizen.org/privilege/datasharing
182 * @remarks If you want to use this function, you must add privileges.
183 * @param[in] h The rpc port proxy handle
184 * @param[in] appid The target stub appid
185 * @param[in] port The name of rpc port
186 * @return @c 0 on success,
187 * otherwise a negative error value
188 * @retval #RPC_PORT_ERROR_NONE Successful
189 * @retval #RPC_PORT_ERROR_PERMISSION_DENIED Permission denied
190 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
191 * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error
193 int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid,
197 * @brief Adds a proxy connected callback.
198 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
199 * @param[in] h The rpc port proxy handle
200 * @param[in] cb The callback function to be called when proxy is connected
201 * @param[in] user_data The user data to be passed to
202 * the rpc_port_proxy_connected_event_cb() function
203 * @return @c 0 on success,
204 * otherwise a negative error value
205 * @retval #RPC_PORT_ERROR_NONE Successful
206 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
208 int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h,
209 rpc_port_proxy_connected_event_cb cb, void *user_data);
212 * @brief Adds a proxy disconnected callback.
213 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
214 * @param[in] h The rpc port proxy handle
215 * @param[in] cb The callback function to be called when proxy is disconnected
216 * @param[in] user_data The user data to be passed to
217 * the rpc_port_proxy_disconnected_event_cb() function
218 * @return @c 0 on success,
219 * otherwise a negative error value
220 * @retval #RPC_PORT_ERROR_NONE Successful
221 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
223 int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h,
224 rpc_port_proxy_disconnected_event_cb cb, void *user_data);
227 * @brief Adds a proxy rejected callback.
228 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
229 * @param[in] h The rpc port proxy handle
230 * @param[in] cb The callback function to be called when proxy is rejected
231 * @param[in] user_data The user data to be passed to
232 * the rpc_port_proxy_rejected_event_cb() function
233 * @return @c 0 on success,
234 * otherwise a negative error value
235 * @retval #RPC_PORT_ERROR_NONE Successful
236 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
238 int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h,
239 rpc_port_proxy_rejected_event_cb cb, void *user_data);
242 * @brief Adds a proxy received callback.
243 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
244 * @param[in] h The rpc port proxy handle
245 * @param[in] cb The callback function to be called when proxy received data
246 * @param[in] user_data The user data to be passed to
247 * the rpc_port_proxy_received_event_cb() function
248 * @return @c 0 on success,
249 * otherwise a negative error value
250 * @retval #RPC_PORT_ERROR_NONE Successful
251 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
253 int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h,
254 rpc_port_proxy_received_event_cb cb, void *user_data);
257 * @brief Gets a port from proxy handle.
258 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
259 * @remarks This handle @a port will not be valid if the proxy was disconnected or destroyed.
260 * @param[in] h The rpc port proxy handle
261 * @param[in] type The type of port
262 * @param[out] port The port to communicate
263 * @return @c 0 on success,
264 * otherwise a negative error value
265 * @retval #RPC_PORT_ERROR_NONE Successful
266 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
267 * @retval #RPC_PORT_ERROR_IO_ERROR No available ports
268 * @see rpc_port_write()
269 * @see rpc_port_read()
270 * @see rpc_port_parcel_create_from_port()
271 * @see rpc_port_parcel_send();
273 int rpc_port_proxy_get_port(rpc_port_proxy_h h, rpc_port_port_type_e type,
279 * @brief The rpc port stub handle.
280 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
282 typedef void *rpc_port_stub_h;
285 * @brief Called when the proxy is connected with stub.
286 * @details The function is called when the proxy is connected with stub.
287 * When a proxy connects to stub several times with new port,
288 * you can handle each request by using @a instance.
289 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
290 * @param[in] sender The target proxy app id
291 * @param[in] instance The information of the request
292 * @param[in] user_data The user data passed from the register function
294 typedef void (*rpc_port_stub_connected_event_cb)(const char *sender,
295 const char *instance, void *user_data);
298 * @brief Called when the proxy is disconnected from stub.
299 * @details The function is called when the proxy is disconnected from stub.
300 * When a proxy is disconnected, you can check the request
301 * by using @a instance.
302 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
303 * @param[in] sender The target proxy app id
304 * @param[in] instance The information of the request
305 * @param[in] user_data The user data passed from the register function
307 typedef void (*rpc_port_stub_disconnected_event_cb)(const char *sender,
308 const char *instance, void *user_data);
311 * @brief Called when the stub received data from proxy.
312 * @details The function is called when the stub received data from stub.
313 * When a stub received data from several ports, you can handle
314 * each request by using @a instance. If the function returns non zero
315 * value, the stub is disconnected.
316 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
317 * @param[in] sender The target proxy app id
318 * @param[in] instance The information of the request
319 * @param[in] port The rpc port handle for reading and writing
320 * @param[in] user_data The user data passed from the register function
321 * @return @c zero to continue receive data with the sender,
322 * otherwise @c nonzero to disconnect from the port
324 typedef int (*rpc_port_stub_received_event_cb)(const char *sender,
325 const char *instance, rpc_port_h port, void *user_data);
328 * @brief Creates a rpc port stub handle.
329 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
330 * @remarks You must release @a h using rpc_port_stub_destroy().
331 * @param[out] h The rpc port stub handle that is newly created
332 * @param[in] port_name The name of the port which want to listen
333 * @return @c 0 on success,
334 * otherwise a negative error value
335 * @retval #RPC_PORT_ERROR_NONE Successful
336 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
337 * @see rpc_port_stub_destroy()
339 int rpc_port_stub_create(rpc_port_stub_h *h, const char *port_name);
342 * @brief Destroys a rpc port stub handle.
343 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
344 * @param[in] h The rpc port stub handle
345 * @return @c 0 on success,
346 * otherwise a negative error value
347 * @retval #RPC_PORT_ERROR_NONE Successful
348 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
349 * @see rpc_port_stub_create()
351 int rpc_port_stub_destroy(rpc_port_stub_h h);
354 * @brief Listens to the requests for connections.
355 * @details The stub listens requests to connect by port
356 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
357 * @param[in] h The rpc port stub handle
358 * @return @c 0 on success,
359 * otherwise a negative error value
360 * @retval #RPC_PORT_ERROR_NONE Successful
361 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
362 * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error
364 int rpc_port_stub_listen(rpc_port_stub_h h);
367 * @brief Adds a privilege to the stub.
368 * @details The stub can control access to the port using tizen privilege.
369 * It allows connections only if the proxy which have the privileges.
370 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
371 * @param[in] h The rpc port stub handle
372 * @param[in] privilege The privilege to access this stub
373 * @return @c 0 on success,
374 * otherwise a negative error value
375 * @retval #RPC_PORT_ERROR_NONE Successful
376 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
378 int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege);
381 * @brief Sets trusted to the stub.
382 * @details The stub can control access to the port using tizen certificate.
383 * It allows connections only if the proxy is signed with the same
385 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
386 * @param[in] h The rpc port stub handle
387 * @param[in] trusted Whether stub allows only trusted proxy or not
388 * @return @c 0 on success,
389 * otherwise a negative error value
390 * @retval #RPC_PORT_ERROR_NONE Successful
391 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
393 int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted);
396 * @brief Adds a stub connected callback.
397 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
398 * @param[in] h The rpc stub stub handle
399 * @param[in] cb The callback function to be called when proxy is connected
401 * @param[in] user_data The user data to be passed to
402 * the rpc_port_stub_connected_event_cb() function
403 * @return @c 0 on success,
404 * otherwise a negative error value
405 * @retval #RPC_PORT_ERROR_NONE Successful
406 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
408 int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h,
409 rpc_port_stub_connected_event_cb cb, void *user_data);
412 * @brief Adds a stub disconnected callback.
413 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
414 * @param[in] h The rpc port stub handle
415 * @param[in] cb The callback function to be called when proxy is disconnected
417 * @param[in] user_data The user data to be passed to
418 * the rpc_port_stub_disconnected_event_cb() function
419 * @return @c 0 on success,
420 * otherwise a negative error value
421 * @retval #RPC_PORT_ERROR_NONE Successful
422 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
424 int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h,
425 rpc_port_stub_disconnected_event_cb cb, void *user_data);
428 * @brief Adds a stub received callback.
429 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
430 * @param[in] h The rpc port stub handle
431 * @param[in] cb The callback function to be called when stub received data
432 * @param[in] user_data The user data to be passed to
433 * the rpc_port_stub_received_event_cb() function
434 * @return @c 0 on success,
435 * otherwise a negative error value
436 * @retval #RPC_PORT_ERROR_NONE Successful
437 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
439 int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h,
440 rpc_port_stub_received_event_cb cb, void *user_data);
443 * @brief Gets a port from stub handle.
444 * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif
445 * @remarks This handle @a port will not be valid if the instance of the stub was disconnected or destroyed.
446 * @param[in] h The rpc port stub handle
447 * @param[in] type The type of port
448 * @param[in] instance The ID of the instance which is connected
449 * @param[out] port The port to communicate
450 * @return @c 0 on success,
451 * otherwise a negative error value
452 * @retval #RPC_PORT_ERROR_NONE Successful
453 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL
454 * @retval #RPC_PORT_ERROR_IO_ERROR No available ports
455 * @see rpc_port_write()
456 * @see rpc_port_read()
457 * @see rpc_port_parcel_create_from_port()
458 * @see rpc_port_parcel_send();
460 int rpc_port_stub_get_port(rpc_port_stub_h h, rpc_port_port_type_e type,
461 const char *instance, rpc_port_h *port);
464 * @brief Connects to @a port_name of @a appid synchronously.
465 * @details To send and receive data, the proxy should connect to port of stub.
468 * @privilege %http://tizen.org/privilege/appmanager.launch \n
469 * %http://tizen.org/privilege/datasharing
470 * @param[in] h The rpc port proxy handle
471 * @param[in] appid The application ID of the target stub
472 * @param[in] port_name The name of rpc port
473 * @return @c 0 on success,
474 * otherwise a negative error value
475 * @retval #RPC_PORT_ERROR_NONE Successful
476 * @retval #RPC_PORT_ERROR_PERMISSION_DENIED Permission denied
477 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
478 * @retval #RPC_PORT_ERROR_IO_ERROR I/O error
480 int rpc_port_proxy_connect_sync(rpc_port_proxy_h h, const char *appid,
481 const char *port_name);
484 * @brief Sets the paths of private sharing files.
485 * @details If all added paths are under the caller application's data path which can be obtained by calling app_get_data_path() function,
486 * those will be shared to the target application. Platform will grant a temporary permission to the target application for those files and revoke it when the target application is terminated or rpc_port_unset_private_sharing() is called.
487 * Paths should be regular files. The target application can just read them.
488 * Note that the target application doesn't have read permission of the directory that is obtained by caller's app_get_data_path(),
489 * You should open the file path with read only mode directly. For example, access() call to the file path will return error because access() needs the read permission of the directory.
490 * The target application can call open() with O_RDONLY mode for the passed file path, because platform grants read permission to the passed file path.
492 * @param[in] port The rpc port handle
493 * @param[in] paths The array of paths of files
494 * @param[in] size The size of the array of the paths
495 * @return @c 0 on success,
496 * otherwise a negative error value
497 * @retval #RPC_PORT_ERROR_NONE Successful
498 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
499 * @retval #RPC_PORT_ERROR_IO_ERROR I/O error
501 * @see rpc_port_unset_private_sharing()
503 int rpc_port_set_private_sharing_array(rpc_port_h port, const char *paths[],
507 * @brief Sets the path of the private sharing file.
508 * @details See the description of rpc_port_set_private_sharing_array() for details.
510 * @param[in] port The rpc port handle
511 * @param[in] path The path of the file
512 * @return @c 0 on success,
513 * otherwise a negative error value
514 * @retval #RPC_PORT_ERROR_NONE Successful
515 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
516 * @retval #RPC_PORT_ERROR_IO_ERROR I/O error
518 * @see rpc_port_set_private_sharing_array()
519 * @see rpc_port_unset_private_sharing()
521 int rpc_port_set_private_sharing(rpc_port_h port, const char *path);
524 * @brief Unsets the private sharing.
526 * @param[in] port The rpc port handle
527 * @return @c 0 on success,
528 * otherwise a negative error value
529 * @retval #RPC_PORT_ERROR_NONE Successful
530 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
531 * @retval #RPC_PORT_ERROR_IO_ERROR I/O error
533 * @see rpc_port_set_private_sharing_array()
534 * @see rpc_port_set_private_sharing()
536 int rpc_port_unset_private_sharing(rpc_port_h port);
539 * @brief Disconnects the port.
541 * @param[in] port The rpc port handle
542 * @return @c 0 on success,
543 * otherwise a negative error value
544 * @retval #RPC_PORT_ERROR_NONE Successful
545 * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
547 int rpc_port_disconnect(rpc_port_h port);
557 #endif /* __TIZEN_APPFW_RPC_PORT_INCLUDE_H__ */