From b5bf78a0ec364515f95f3ad0af1a0030f5fb8308 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 11 Jun 2018 14:31:10 +0900 Subject: [PATCH 01/16] Release version 1.0.11 Changes: - Fix overflowing for calling nanosleep() Change-Id: I1cd6eefc8dbba570bfcd0dfff164f337bca28ddc Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 31e6f14..fdb5140 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.10 +Version: 1.0.11 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 828bdffd053327e1b798e1fd2bf37ef41949e02a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 15 Jun 2018 15:35:56 +0900 Subject: [PATCH 02/16] Fix disconnected event handling - Sets IEventListener to nullptr before calling event callback function. Change-Id: Ibe6c7c1fb9f676167770a2f2cf6d3dae81f58c98 Signed-off-by: Hwankyu Jhun --- src/proxy-internal.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 84038eb..593ca7e 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -53,11 +53,12 @@ Proxy::~Proxy() { gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, gpointer data) { Proxy* proxy = static_cast(data); + IEventListener* listener = proxy->listener_; LOGW("Socket was disconnected"); - proxy->listener_->OnDisconnected(proxy->target_appid_); + proxy->listener_ = nullptr; proxy->disconn_src_ = 0; - + listener->OnDisconnected(proxy->target_appid_); return FALSE; } @@ -69,8 +70,10 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond, if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { LOGW("Socket was disconnected by stub"); - proxy->listener_->OnDisconnected(proxy->target_appid_); + IEventListener* listener = proxy->listener_; + proxy->listener_ = nullptr; proxy->src_ = 0; + listener->OnDisconnected(proxy->target_appid_); return FALSE; } @@ -116,8 +119,10 @@ int Proxy::Watch(int fd) { void Proxy::OnPortRejected(const std::string& appid) { if (listener_ == nullptr) return; - listener_->OnRejected(appid); + + IEventListener* listener = listener_; listener_ = nullptr; + listener->OnRejected(appid); } void Proxy::OnPortAppeared(const std::string& appid, @@ -129,8 +134,9 @@ void Proxy::OnPortAppeared(const std::string& appid, int fd = fd_broker_.Send(appid, port_name); if (fd <= 0) { - listener_->OnRejected(appid); + IEventListener* listener = listener_; listener_ = nullptr; + listener->OnRejected(appid); return; } -- 2.7.4 From a158358c2943219dd7228635039a7cf2cbbd593e Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 15 Jun 2018 16:57:00 +0900 Subject: [PATCH 03/16] Release version 1.0.12 Changes: - Fix disconnected event handling Change-Id: I362d7d327b9d768a7ab6978fa66dc2ab1cd22ae7 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index fdb5140..3972e70 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.11 +Version: 1.0.12 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From d3cea025129ed5a75f3118f48445312e348e30f9 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Mon, 4 Jun 2018 09:13:46 +0900 Subject: [PATCH 04/16] Modify doxygen comments - Add new APIs to fix performance issue and multi-thread issue Change-Id: I56deab83f106f10746bc9fbb33883fef271a9fcf Signed-off-by: Inkyun Kil Signed-off-by: Junghoon Park --- include/rpc-port-parcel.h | 85 ++++++++++++------- include/rpc-port.h | 106 ++++++++++++++++------- src/fdbroker-internal.cc | 38 +++++---- src/fdbroker-internal.h | 7 +- src/parcel-internal.cc | 9 ++ src/parcel-internal.h | 2 + src/proxy-internal.cc | 148 ++++++++++++++++++++------------- src/proxy-internal.h | 30 +++++-- src/rpc-port-parcel.cc | 24 ++++++ src/rpc-port.cc | 55 ++++++++++++ src/stub-internal.cc | 50 ++++++++--- src/stub-internal.h | 12 ++- unit_tests/src/rpc_port_parcel_test.cc | 13 +++ 13 files changed, 424 insertions(+), 155 deletions(-) diff --git a/include/rpc-port-parcel.h b/include/rpc-port-parcel.h index 715d020..4ba9f9f 100644 --- a/include/rpc-port-parcel.h +++ b/include/rpc-port-parcel.h @@ -32,13 +32,13 @@ extern "C" { /** * @brief The rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 */ typedef void *rpc_port_parcel_h; /** * @brief The interface for converting data to/from a parcel. - * @since_tizen 5.0 + * @since_tizen 4.0 */ typedef struct __rpc_port_parcelable { void (*to)(rpc_port_parcel_h h, void *data); @@ -47,7 +47,7 @@ typedef struct __rpc_port_parcelable { /** * @brief Creates a rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @remarks You must release @a h using rpc_port_parcel_destroy(). * @param[out] h The rpc port parcel handle that is newly created * @return @c 0 on success, @@ -61,7 +61,7 @@ int rpc_port_parcel_create(rpc_port_parcel_h *h); * @brief Creates a rpc port parcel handle from port. * @details Creates a rpc port parcel handle using read data from the port. * It calls rpc_port_read() internally. - * @since_tizen 5.0 + * @since_tizen 4.0 * @remarks You must release @a h using rpc_port_parcel_destroy(). * @param[out] h The rpc port parcel handle that is newly created * @param[in] port The rpc port handle for creating handle @@ -79,7 +79,7 @@ int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h, rpc_port_h port); * @brief Sends parcel data through the port. * @details Sends parcel data through the port. It calls rpc_port_write() * internally. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle that is newly created * @param[in] port The rpc port handle for writing data * @return @c 0 on success, @@ -93,7 +93,7 @@ int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port); /** * @brief Destroys a rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @return @c 0 on success, * otherwise a negative error value @@ -105,7 +105,7 @@ int rpc_port_parcel_destroy(rpc_port_parcel_h h); /** * @brief Writes a byte value into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] b Byte data * @return @c 0 on success, @@ -118,7 +118,7 @@ int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b); /** * @brief Writes a short value into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] i short data * @return @c 0 on success, @@ -131,7 +131,7 @@ int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i); /** * @brief Writes a integer value into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] i int data * @return @c 0 on success, @@ -144,7 +144,7 @@ int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i); /** * @brief Writes a long long integer value into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] i long long data * @return @c 0 on success, @@ -157,7 +157,7 @@ int rpc_port_parcel_write_int64(rpc_port_parcel_h h, long long i); /** * @brief Writes a floating point value into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] f float data * @return @c 0 on success, @@ -170,7 +170,7 @@ int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f); /** * @brief Writes a double precision floating point value into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] d double data * @return @c 0 on success, @@ -183,7 +183,7 @@ int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d); /** * @brief Writes a string value into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] str string data * @return @c 0 on success, @@ -196,7 +196,7 @@ int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char *str); /** * @brief Writes a boolean value into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] b boolean data * @return @c 0 on success, @@ -209,7 +209,7 @@ int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b); /** * @brief Writes a bundle data into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] b Bundle data * @return @c 0 on success, @@ -222,7 +222,7 @@ int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle *b); /** * @brief Writes a count for array into rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] count Array count * @return @c 0 on success, @@ -235,7 +235,7 @@ int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count); /** * @brief Writes the data into parcel handle using @a parcelable. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] parcelable The interface to write the data into parcel handle * @param[in] data Data which write into parcel @@ -249,7 +249,7 @@ int rpc_port_parcel_write(rpc_port_parcel_h h, rpc_port_parcelable_t *parcelable /** * @brief Reads a byte value from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[out] b Byte data * @return @c 0 on success, @@ -262,7 +262,7 @@ int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char *b); /** * @brief Reads a short value from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[out] i short data * @return @c 0 on success, @@ -275,7 +275,7 @@ int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i); /** * @brief Reads a integer value from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[out] i int data * @return @c 0 on success, @@ -288,7 +288,7 @@ int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int *i); /** * @brief Reads a long long integer value from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[out] i long long data * @return @c 0 on success, @@ -301,7 +301,7 @@ int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long *i); /** * @brief Reads a floating point value from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[out] f float data * @return @c 0 on success, @@ -314,7 +314,7 @@ int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f); /** * @brief Reads a double precision floating point value from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[out] d double data * @return @c 0 on success, @@ -327,7 +327,7 @@ int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d); /** * @brief Reads a string value from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @remarks The @a str should be released using free(). * @param[in] h The rpc port parcel handle * @param[out] str string data @@ -341,7 +341,7 @@ int rpc_port_parcel_read_string(rpc_port_parcel_h h, char **str); /** * @brief Reads a boolean value from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[out] b boolean data * @return @c 0 on success, @@ -354,7 +354,7 @@ int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b); /** * @brief Reads a bundle data from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @remarks The @a b should be released using bundle_free(). * @param[in] h The rpc port parcel handle * @param[out] b Bundle data @@ -368,7 +368,7 @@ int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle **b); /** * @brief Reads a count for array from rpc port parcel handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[out] count Array count * @return @c 0 on success, @@ -381,7 +381,7 @@ int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count); /** * @brief Reads a parcel from the data using @a parcelable. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port parcel handle * @param[in] parcelable The interface to get data from parcel handle * @param[in] data Data which get from parcel @@ -393,6 +393,35 @@ int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count); */ int rpc_port_parcel_read(rpc_port_parcel_h h, rpc_port_parcelable_t *parcelable, void *data); + +/** + * @brief Reads bytes from rpc port parcel handle. + * @since_tizen 4.0 + * @param[in] h The rpc port parcel handle + * @param[out] buf The array buffer to read + * @param[in] size Bytes to read + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_bool() + */ +int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf, unsigned int size); + +/** + * @brief Write bytes to rpc port parcel handle. + * @since_tizen 4.0 + * @param[in] h The rpc port parcel handle + * @param[in] buf The array buffer to write + * @param[in] size Bytes to write + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @see rpc_port_parcel_write_bool() + */ +int rpc_port_parcel_burst_write(rpc_port_parcel_h h, const unsigned char *buf, unsigned int size); + /** * @} */ diff --git a/include/rpc-port.h b/include/rpc-port.h index d4f3de0..f14aac0 100755 --- a/include/rpc-port.h +++ b/include/rpc-port.h @@ -32,7 +32,7 @@ extern "C" { /** * @brief Enumeration for error codes of a rpc port. - * @since_tizen 5.0 + * @since_tizen 4.0 */ typedef enum { RPC_PORT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ @@ -42,17 +42,26 @@ typedef enum { RPC_PORT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ } rpc_port_error_e; +/** + * @brief Enumeration for types of communication channels. + * @since_tizen 4.0 + */ +typedef enum { + RPC_PORT_PORT_MAIN, /**< Main channel */ + RPC_PORT_PORT_CALLBACK, /**< The channel for callbacks */ +} rpc_port_port_type_e; + /* Common */ /** * @brief The rpc port handle. - * @since_tizen 5.0 + * @since_tizen 4.0 */ typedef void *rpc_port_h; /** * @brief Reads data from an RPC port. - * @since_tizen 5.0 + * @since_tizen 4.0 * * @param[in] h The rpc port handle * @param[out] buf Buffer for reading data @@ -69,7 +78,7 @@ int rpc_port_read(rpc_port_h h, void *buf, unsigned int size); /** * @brief Writes data to an RPC port. - * @since_tizen 5.0 + * @since_tizen 4.0 * * @param[in] h The rpc port handle * @param[in] buf Buffer for writing data @@ -90,7 +99,7 @@ int rpc_port_write(rpc_port_h h, const void *buf, unsigned int size); /** * @brief Called when the proxy is connected. * @details The function is called when the proxy is connected with stub by port. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] receiver The target stub app id * @param[in] port_name The name of the port * @param[in] port The rpc port handle for reading and writing @@ -102,7 +111,7 @@ typedef void (*rpc_port_proxy_connected_event_cb)(const char *receiver, /** * @brief Called when the proxy is disconnected. * @details The function is called when the proxy is disconnected from stub. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] receiver The target stub app id * @param[in] port_name The name of the port * @param[in] user_data The user data passed from the register function @@ -113,7 +122,7 @@ typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *receiver, /** * @brief Called when the proxy is rejected. * @details The function is called when the proxy is rejected to connect stub. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] receiver The target stub app id * @param[in] port_name The name of the port * @param[in] user_data The user data passed from the register function @@ -124,7 +133,7 @@ typedef void (*rpc_port_proxy_rejected_event_cb)(const char *receiver, /** * @brief Called when the proxy received data. * @details The function is called when the proxy received data from stub. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] receiver The target stub app id * @param[in] port_name The name of the port * @param[in] user_data The user data passed from the register function @@ -134,13 +143,13 @@ typedef void (*rpc_port_proxy_received_event_cb)(const char *receiver, /** * @brief The rpc port proxy handle. - * @since_tizen 5.0 + * @since_tizen 4.0 */ typedef void *rpc_port_proxy_h; /** * @brief Creates a rpc port proxy handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @remarks You must release @a h using rpc_port_proxy_destroy(). * @param[out] h The rpc port proxy handle that is newly created * @return @c 0 on success, @@ -153,7 +162,7 @@ int rpc_port_proxy_create(rpc_port_proxy_h *h); /** * @brief Destroys a rpc port proxy handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port proxy handle * @return @c 0 on success, * otherwise a negative error value @@ -166,7 +175,7 @@ int rpc_port_proxy_destroy(rpc_port_proxy_h h); /** * @brief Connects to @a port of @a appid. * @details To send and receive data, the proxy should connect to port of stub - * @since_tizen 5.0 + * @since_tizen 4.0 * @privlevel public * @privilege %http://tizen.org/privilege/appmanager.launch \n * %http://tizen.org/privilege/datasharing @@ -186,7 +195,7 @@ int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid, /** * @brief Adds a proxy connected callback. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port proxy handle * @param[in] cb The callback function to be called when proxy is connected * @param[in] user_data The user data to be passed to @@ -201,7 +210,7 @@ int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, /** * @brief Adds a proxy disconnected callback. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port proxy handle * @param[in] cb The callback function to be called when proxy is disconnected * @param[in] user_data The user data to be passed to @@ -216,7 +225,7 @@ int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, /** * @brief Adds a proxy rejected callback. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port proxy handle * @param[in] cb The callback function to be called when proxy is rejected * @param[in] user_data The user data to be passed to @@ -231,7 +240,7 @@ int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, /** * @brief Adds a proxy received callback. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port proxy handle * @param[in] cb The callback function to be called when proxy received data * @param[in] user_data The user data to be passed to @@ -244,11 +253,31 @@ int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, rpc_port_proxy_received_event_cb cb, void *user_data); +/** + * @brief Gets a port from proxy handle. + * @since_tizen 4.0 + * @remarks This handle @a port will not be valid if the proxy was disconnected or destroyed. + * @param[in] h The rpc port proxy handle + * @param[in] type The type of port + * @param[out] port The port to communicate + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_IO_ERROR No available ports + * @see rpc_port_write() + * @see rpc_port_read() + * @see rpc_port_parcel_create_from_port() + * @see rpc_port_parcel_send(); + */ +int rpc_port_proxy_get_port(rpc_port_proxy_h h, rpc_port_port_type_e type, + rpc_port_h *port); + /* Stub */ /** * @brief The rpc port stub handle. - * @since_tizen 5.0 + * @since_tizen 4.0 */ typedef void *rpc_port_stub_h; @@ -257,7 +286,7 @@ typedef void *rpc_port_stub_h; * @details The function is called when the proxy is connected with stub. * When a proxy connects to stub several times with new port, * you can handle each request by using @a instance. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] sender The target proxy app id * @param[in] instance The information of the request * @param[in] user_data The user data passed from the register function @@ -270,7 +299,7 @@ typedef void (*rpc_port_stub_connected_event_cb)(const char *sender, * @details The function is called when the proxy is disconnected from stub. * When a proxy is disconnected, you can check the request * by using @a instance. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] sender The target proxy app id * @param[in] instance The information of the request * @param[in] user_data The user data passed from the register function @@ -284,7 +313,7 @@ typedef void (*rpc_port_stub_disconnected_event_cb)(const char *sender, * When a stub received data from several ports, you can handle * each request by using @a instance. If the function returns non zero * value, the stub is disconnected. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] sender The target proxy app id * @param[in] instance The information of the request * @param[in] port The rpc port handle for reading and writing @@ -297,7 +326,7 @@ typedef int (*rpc_port_stub_received_event_cb)(const char *sender, /** * @brief Creates a rpc port stub handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @remarks You must release @a h using rpc_port_stub_destroy(). * @param[out] h The rpc port stub handle that is newly created * @param[in] port_name The name of the port which want to listen @@ -311,7 +340,7 @@ int rpc_port_stub_create(rpc_port_stub_h *h, const char *port_name); /** * @brief Destroys a rpc port stub handle. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port stub handle * @return @c 0 on success, * otherwise a negative error value @@ -324,7 +353,7 @@ int rpc_port_stub_destroy(rpc_port_stub_h h); /** * @brief Listens to the requests for connections. * @details The stub listens requests to connect by port - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port stub handle * @return @c 0 on success, * otherwise a negative error value @@ -338,7 +367,7 @@ int rpc_port_stub_listen(rpc_port_stub_h h); * @brief Adds a privilege to the stub. * @details The stub can control access to the port using tizen privilege. * It allows connections only if the proxy which have the privileges. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port stub handle * @param[in] privilege The privilege to access this stub * @return @c 0 on success, @@ -353,7 +382,7 @@ int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege); * @details The stub can control access to the port using tizen certificate. * It allows connections only if the proxy is signed with the same * certificate. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port stub handle * @param[in] trusted Whether stub allows only trusted proxy or not * @return @c 0 on success, @@ -365,7 +394,7 @@ int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted); /** * @brief Adds a stub connected callback. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc stub stub handle * @param[in] cb The callback function to be called when proxy is connected * with the stub @@ -381,7 +410,7 @@ int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, /** * @brief Adds a stub disconnected callback. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port stub handle * @param[in] cb The callback function to be called when proxy is disconnected * with the stub @@ -397,7 +426,7 @@ int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, /** * @brief Adds a stub received callback. - * @since_tizen 5.0 + * @since_tizen 4.0 * @param[in] h The rpc port stub handle * @param[in] cb The callback function to be called when stub received data * @param[in] user_data The user data to be passed to @@ -411,6 +440,27 @@ int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, rpc_port_stub_received_event_cb cb, void *user_data); /** + * @brief Gets a port from stub handle. + * @since_tizen 4.0 + * @remarks This handle @a port will not be valid if the instance of the stub was disconnected or destroyed. + * @param[in] h The rpc port stub handle + * @param[in] type The type of port + * @param[in] instance The ID of the instance which is connected + * @param[out] port The port to communicate + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER The specified @a h is NULL + * @retval #RPC_PORT_ERROR_IO_ERROR No available ports + * @see rpc_port_write() + * @see rpc_port_read() + * @see rpc_port_parcel_create_from_port() + * @see rpc_port_parcel_send(); + */ +int rpc_port_stub_get_port(rpc_port_stub_h h, rpc_port_port_type_e type, + const char *instance, rpc_port_h *port); + +/** * @} */ diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 0dce2cf..36df52d 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -99,11 +99,11 @@ FdBroker::DBusMock& FdBroker::DBusMock::GetInst() { } int FdBroker::DBusMock::Send(const std::string& sender, - const std::string& port, int fd) { + const std::string& port, int fds[2]) { if (ports_.find(port) == ports_.end()) return -1; - ports_[port]->OnFdReceived(sender, fd); + ports_[port]->OnFdReceived(sender, fds); return 0; } @@ -221,13 +221,15 @@ std::string FdBroker::GetInterfaceName(const std::string& target_appid, } int FdBroker::Send(const std::string& target_appid, - const std::string& port_name) { + const std::string& port_name, + int (*fds)[2]) { std::string interface_name = GetInterfaceName(target_appid, port_name); GDBusMessage *msg; GDBusMessage *reply; GError *err = nullptr; GVariant *reply_body; - SocketPair sock_pair(mock_); + SocketPair main_sock_pair(mock_); + SocketPair delegate_sock_pair(mock_); FdList fd_list; char sender_appid[255]; int ret; @@ -238,19 +240,24 @@ int FdBroker::Send(const std::string& target_appid, return -1; } - if (sock_pair.Request() != 0) + if (main_sock_pair.Request() != 0) + return -1; + if (delegate_sock_pair.Request() != 0) return -1; if (mock_) { - int ret = DBusMock::GetInst().Send("TestApp", port_name, - sock_pair.Detach(SocketPair::RECEIVER)); + (*fds)[0] = main_sock_pair.Detach(SocketPair::RECEIVER); + (*fds)[1] = delegate_sock_pair.Detach(SocketPair::RECEIVER); + int ret = DBusMock::GetInst().Send("TestApp", port_name, *fds); if (ret < 0) return ret; - return sock_pair.Detach(SocketPair::SENDER); + return main_sock_pair.Detach(SocketPair::SENDER); } - if (fd_list.Add(sock_pair.Detach(SocketPair::RECEIVER)) != 0) + if (fd_list.Add(main_sock_pair.Detach(SocketPair::RECEIVER)) != 0) + return -1; + if (fd_list.Add(delegate_sock_pair.Detach(SocketPair::RECEIVER)) != 0) return -1; msg = g_dbus_message_new_method_call(interface_name.c_str(), @@ -290,17 +297,18 @@ int FdBroker::Send(const std::string& target_appid, LOGD("[Reply : %d]", ret); - int fd = sock_pair.Detach(SocketPair::SENDER); + (*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER); + (*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER); g_object_unref(msg); - return fd; + return (*fds)[0]; } void FdBroker::ReceiveMessage(const char* sender_appid, GDBusMethodInvocation* invocation) { GDBusMessage* msg; GUnixFDList* fd_list; - int fd_len; + int fd_len = 0; int* returned_fds = nullptr; msg = g_dbus_method_invocation_get_message(invocation); @@ -310,12 +318,12 @@ void FdBroker::ReceiveMessage(const char* sender_appid, return; returned_fds = g_unix_fd_list_steal_fds(fd_list, &fd_len); - if (returned_fds == nullptr) { - LOGE("fail to get fds"); + if (returned_fds == nullptr || fd_len != 2) { + LOGE("fail to get fds. fd_len(%d)", fd_len); return; } - listener_->OnFdReceived(sender_appid, returned_fds[0]); + listener_->OnFdReceived(sender_appid, returned_fds); free(returned_fds); } diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index 3dd43d6..e9b15b8 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -36,7 +36,7 @@ class FdBroker { public: class IEventListener { public: - virtual void OnFdReceived(const std::string& sender, int fd) = 0; + virtual void OnFdReceived(const std::string& sender, int fds[2]) = 0; }; class IEventWatcher { @@ -55,7 +55,8 @@ class FdBroker { DBusConnectionManager::GetInst().Dispose(); } - int Send(const std::string& target_appid, const std::string& port_name); + int Send(const std::string& target_appid, const std::string& port_name, + int (*fds)[2]); int Listen(IEventListener* ev, const std::string& port_name); AccessController& GetAccessController(); int Watch(IEventWatcher* ev, const std::string& target_appid, @@ -89,7 +90,7 @@ class FdBroker { DBusMock& operator = (const DBusMock&) = delete; static DBusMock& GetInst(); - int Send(const std::string& sender, const std::string& port, int fd); + int Send(const std::string& sender, const std::string& port, int fds[2]); int AddListener(const std::string& port, FdBroker::IEventListener* listener); int Watch(FdBroker::IEventWatcher* watcher, const std::string& target_appid, diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index e568f90..cae8988 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -128,4 +128,13 @@ const std::vector& Parcel::GetRaw() { return data_; } +void Parcel::Write(const unsigned char* buf, unsigned int size) { + std::copy(buf, buf + size, std::back_inserter(data_)); +} + +void Parcel::Read(unsigned char* buf, unsigned int size) { + std::copy(&data_[reader_], &data_[reader_] + size, buf); + reader_ += size; +} + } // namespace rpc_port diff --git a/src/parcel-internal.h b/src/parcel-internal.h index 6fc314a..3b491d0 100644 --- a/src/parcel-internal.h +++ b/src/parcel-internal.h @@ -31,6 +31,8 @@ class Parcel { Parcel() = default; Parcel(const unsigned char* buf, unsigned int size); + void Write(const unsigned char* buf, unsigned int size); + void Read(unsigned char* buf, unsigned int size); void WriteByte(char b); void WriteInt16(short i); void WriteInt32(int i); diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 593ca7e..f5bd629 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -40,25 +40,24 @@ Proxy::Proxy(bool mock) Proxy::~Proxy() { LOGD("Proxy::~Proxy"); - if (src_ > 0) - g_source_remove(src_); - - if (disconn_src_ > 0) - g_source_remove(disconn_src_); - - if (gioc_ != nullptr) - g_io_channel_unref(gioc_); } gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, gpointer data) { Proxy* proxy = static_cast(data); IEventListener* listener = proxy->listener_; + int fd = g_io_channel_unix_get_fd(gio); + + LOGW("Socket was disconnected. fd(%d)", fd); + + if (proxy->main_port_.get()->GetFd() == fd) { + proxy->listener_ = nullptr; + proxy->main_port_.get()->SetDisconnectedSource(0); + listener->OnDisconnected(proxy->target_appid_); + } else if (proxy->delegate_port_.get()->GetFd() == fd) { + proxy->delegate_port_.get()->SetDisconnectedSource(0); + } - LOGW("Socket was disconnected"); - proxy->listener_ = nullptr; - proxy->disconn_src_ = 0; - listener->OnDisconnected(proxy->target_appid_); return FALSE; } @@ -68,54 +67,22 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond, int fd = g_io_channel_unix_get_fd(gio); char buffer[4]; - if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { - LOGW("Socket was disconnected by stub"); - IEventListener* listener = proxy->listener_; - proxy->listener_ = nullptr; - proxy->src_ = 0; - listener->OnDisconnected(proxy->target_appid_); - return FALSE; + if (proxy->main_port_.get()->GetFd() == fd) { + if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { + LOGW("Socket was disconnected by stub. fd(%d)", fd); + IEventListener* listener = proxy->listener_; + proxy->listener_ = nullptr; + proxy->main_port_.get()->SetSource(0); + listener->OnDisconnected(proxy->target_appid_); + return FALSE; + } + + proxy->listener_->OnReceived(proxy->target_appid_); } - proxy->listener_->OnReceived(proxy->target_appid_); - return TRUE; } -int Proxy::Watch(int fd) { - char buf[1024]; - - gioc_ = g_io_channel_unix_new(fd); - if (!gioc_) { - LOGE("Error is %s\n", strerror_r(errno, buf, sizeof(buf))); - return -1; - } - - disconn_src_ = g_io_add_watch(gioc_, - (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_NVAL), - OnSocketDisconnected, this); - if (disconn_src_ == 0) { - LOGE("fail to add watch on socket"); - g_io_channel_unref(gioc_); - gioc_ = nullptr; - return -1; - } - - src_ = g_io_add_watch(gioc_, - (GIOCondition)(G_IO_IN), - OnDataReceived, this); - if (src_ == 0) { - LOGE("fail to add watch on socket"); - g_source_remove(disconn_src_); - disconn_src_ = 0; - g_io_channel_unref(gioc_); - gioc_ = nullptr; - return -1; - } - - return 0; -} - void Proxy::OnPortRejected(const std::string& appid) { if (listener_ == nullptr) return; @@ -132,17 +99,19 @@ void Proxy::OnPortAppeared(const std::string& appid, if (listener_ == nullptr) return; - int fd = fd_broker_.Send(appid, port_name); - if (fd <= 0) { + int fds[2] = { 0, }; + int r = fd_broker_.Send(appid, port_name, &fds); + if (r <= 0 || fds[0] <= 0 || fds[1] <= 0) { IEventListener* listener = listener_; listener_ = nullptr; listener->OnRejected(appid); return; } - port_.reset(new Port(fd, port_name)); - listener_->OnConnected(appid, port_.get()); - Watch(fd); + LOGW("[__OnPortAppeared__] fds[0]: %d, fds[1]: %d", fds[0], fds[1]); + main_port_.reset(new ProxyPort(this, fds[0], appid)); + delegate_port_.reset(new ProxyPort(this, fds[1], appid)); + listener_->OnConnected(appid, main_port_.get()); } void Proxy::OnPortVanished(const std::string& appid, @@ -175,5 +144,64 @@ int Proxy::Connect(const std::string appid, const std::string& port_name, return RPC_PORT_ERROR_NONE; } +Proxy::ProxyPort::ProxyPort(Proxy* parent, int fd, const std::string& id) + : Port(fd, id), parent_(parent) { + Watch(); +} + +Proxy::ProxyPort::~ProxyPort() { + if (disconn_src_ > 0) + g_source_remove(disconn_src_); + + if (src_ > 0) + g_source_remove(src_); + + if (gioc_ != nullptr) + g_io_channel_unref(gioc_); +} + +int Proxy::ProxyPort::Watch() { + char buf[1024]; + int fd = GetFd(); + + gioc_ = g_io_channel_unix_new(fd); + if (!gioc_) { + LOGE("Error is %s", strerror_r(errno, buf, sizeof(buf))); + return -1; + } + + disconn_src_ = g_io_add_watch(gioc_, + (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_NVAL), + Proxy::OnSocketDisconnected, parent_); + if (disconn_src_ == 0) { + LOGE("Failed to add watch on socket"); + g_io_channel_unref(gioc_); + gioc_ = nullptr; + return -1; + } + + src_ = g_io_add_watch(gioc_, + (GIOCondition)(G_IO_IN), + Proxy::OnDataReceived, parent_); + if (src_ == 0) { + LOGE("Failed to add watch on socket"); + g_source_remove(disconn_src_); + disconn_src_ = 0; + g_io_channel_unref(gioc_); + gioc_ = nullptr; + return -1; + } + + return 0; +} + +void Proxy::ProxyPort::SetDisconnectedSource(int sourceId) { + disconn_src_ = sourceId; +} + +void Proxy::ProxyPort::SetSource(int sourceId) { + disconn_src_ = sourceId; +} + } // namespace internal } // namespace rpc_port diff --git a/src/proxy-internal.h b/src/proxy-internal.h index 876bc43..b053d84 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -46,7 +46,10 @@ class Proxy : public FdBroker::IEventWatcher { int Connect(const std::string appid, const std::string& port_name, IEventListener* ev); std::shared_ptr GetPort() const { - return port_; + return main_port_; + } + std::shared_ptr GetDelegatePort() const { + return delegate_port_; } const std::string& GetPortName() { @@ -54,11 +57,28 @@ class Proxy : public FdBroker::IEventWatcher { } private: + class ProxyPort : public Port { + public: + ProxyPort(Proxy* parent, int fd, const std::string& id); + virtual ~ProxyPort(); + void SetDisconnectedSource(int sourceId); + void SetSource(int sourceId); + + private: + int Watch(); + + private: + GIOChannel* gioc_ = nullptr; + int disconn_src_ = 0; + int src_ = 0; + Proxy* parent_ = nullptr; + }; + + private: static gboolean OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, gpointer data); static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond, gpointer data); - int Watch(int fd); void OnPortAppeared(const std::string& appid, const std::string& port_name) override; void OnPortVanished(const std::string& appid, @@ -67,13 +87,11 @@ class Proxy : public FdBroker::IEventWatcher { private: std::string port_name_; - std::shared_ptr port_; + std::shared_ptr main_port_; + std::shared_ptr delegate_port_; IEventListener* listener_ = nullptr; FdBroker fd_broker_; std::string target_appid_; - GIOChannel* gioc_ = nullptr; - int disconn_src_ = 0; - int src_ = 0; }; } // namespace internal diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 8888579..307808a 100755 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -348,3 +348,27 @@ RPC_API int rpc_port_parcel_read(rpc_port_parcel_h h, return RPC_PORT_ERROR_NONE; } + +RPC_API int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf, + unsigned int size) { + if (h == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + Parcel* p = static_cast(h); + + p->Read(buf, size); + + return RPC_PORT_ERROR_NONE; +} + +RPC_API int rpc_port_parcel_burst_write(rpc_port_parcel_h h, + const unsigned char *buf, unsigned int size) { + if (h == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + Parcel* p = static_cast(h); + + p->Write(buf, size); + + return RPC_PORT_ERROR_NONE; +} diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 958e378..48d7518 100755 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -280,6 +280,33 @@ RPC_API int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, return RPC_PORT_ERROR_NONE; } +RPC_API int rpc_port_proxy_get_port(rpc_port_proxy_h h, + rpc_port_port_type_e type, rpc_port_h* port) { + if (h == nullptr || port == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + auto p = static_cast<::ProxyExt*>(h); + std::lock_guard lock(p->GetMutex()); + rpc_port_h ret_port; + + switch (type) { + case RPC_PORT_PORT_MAIN: + ret_port = static_cast(p->GetPort().get()); + if (ret_port == nullptr) + return RPC_PORT_ERROR_IO_ERROR; + *port = ret_port; + break; + case RPC_PORT_PORT_CALLBACK: + ret_port = static_cast(p->GetDelegatePort().get()); + if (ret_port == nullptr) + return RPC_PORT_ERROR_IO_ERROR; + *port = ret_port; + break; + } + + return RPC_PORT_ERROR_NONE; +} + RPC_API int rpc_port_stub_create(rpc_port_stub_h* h, const char* port_name) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; @@ -381,3 +408,31 @@ RPC_API int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, p->AddReceivedEventListener(cb, user_data); return RPC_PORT_ERROR_NONE; } + +RPC_API int rpc_port_stub_get_port(rpc_port_stub_h h, + rpc_port_port_type_e type, const char *instance, rpc_port_h* port) { + if (h == nullptr || port == nullptr || instance == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + auto p = static_cast<::StubExt*>(h); + std::lock_guard lock(p->GetMutex()); + rpc_port_h ret_port; + + switch (type) { + case RPC_PORT_PORT_MAIN: + ret_port = static_cast(p->FindPort(instance).get()); + if (ret_port == nullptr) + return RPC_PORT_ERROR_IO_ERROR; + *port = ret_port; + break; + case RPC_PORT_PORT_CALLBACK: + ret_port = static_cast(p->FindDelegatePort(instance).get()); + if (ret_port == nullptr) + return RPC_PORT_ERROR_IO_ERROR; + *port = ret_port; + break; + } + + return RPC_PORT_ERROR_NONE; +} + diff --git a/src/stub-internal.cc b/src/stub-internal.cc index a20d125..b866b45 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -60,6 +60,28 @@ void Stub::SetTrusted(const bool trusted) { ac.SetTrusted(trusted); } +std::shared_ptr Stub::FindPort(const std::string& instance) const { + for (auto& p : ports_) { + if (p->GetInstance() == instance && !p->IsDelegate()) { + return p; + } + } + + return {}; +} + +std::shared_ptr Stub::FindDelegatePort( + const std::string& instance) const { + for (auto& p : ports_) { + if (p->GetInstance() == instance && p->IsDelegate()) { + return p; + } + } + + return {}; +} + + gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, gpointer data) { Stub* stub = static_cast(data); @@ -67,9 +89,9 @@ gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, char buffer[4]; for (auto& p : stub->ports_) { - if (p->GetFd() == fd) { + if (p->GetFd() == fd && !p->IsDelegate()) { if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { - LOGW("Socket was disconnected from proxy"); + LOGW("Socket was disconnected from proxy. fd(%d)", fd); stub->listener_->OnDisconnected(p->GetId(), p->GetInstance()); stub->ports_.remove(p); @@ -105,33 +127,37 @@ gboolean Stub::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, Stub* stub = static_cast(data); int fd = g_io_channel_unix_get_fd(gio); - LOGW("Socket was disconnected"); + LOGW("Socket was disconnected. fd(%d)", fd); for (auto& p : stub->ports_) { if (p->GetFd() == fd) { - stub->listener_->OnDisconnected(p->GetId(), p->GetInstance()); + if (!p->IsDelegate()) { + stub->listener_->OnDisconnected(p->GetId(), p->GetInstance()); + if (aul_rpc_port_notify_rpc_finished() != AUL_R_OK) + LOGW("Failed to notify rpc finished"); + } stub->ports_.remove(p); break; } } - if (aul_rpc_port_notify_rpc_finished() != AUL_R_OK) - LOGW("Failed to notify rpc finished"); - return FALSE; } -void Stub::OnFdReceived(const std::string& sender, int fd) { - ports_.emplace_back(new AcceptedPort(this, fd, sender)); +void Stub::OnFdReceived(const std::string& sender, int fds[2]) { + LOGW("[__OnFdReceived__] fds[0]: %d, fds[1]: %d", fds[0], fds[1]); + ports_.emplace_back(new AcceptedPort(this, false, fds[0], sender)); + ports_.emplace_back(new AcceptedPort(this, true, fds[1], sender)); for (auto& p : ports_) { - if (p->GetFd() == fd) { + if (p->GetFd() == fds[0]) { listener_->OnConnected(p->GetId(), p->GetInstance()); break; } } } -Stub::AcceptedPort::AcceptedPort(Stub* parent, int fd, const std::string& id) - : Port(fd, id), parent_(parent) { +Stub::AcceptedPort::AcceptedPort(Stub* parent, bool isDelegate, + int fd, const std::string& id) + : Port(fd, id), parent_(parent), is_delegate_(isDelegate) { Watch(); } diff --git a/src/stub-internal.h b/src/stub-internal.h index 8883805..05ff1b2 100644 --- a/src/stub-internal.h +++ b/src/stub-internal.h @@ -49,12 +49,17 @@ class Stub : private FdBroker::IEventListener { int Listen(IEventListener* ev); void AddPrivilege(const std::string& privilege); void SetTrusted(const bool trusted); + std::shared_ptr FindPort(const std::string& instance) const; + std::shared_ptr FindDelegatePort(const std::string& instance) const; private: class AcceptedPort : public Port { public: - AcceptedPort(Stub* parent, int fd, const std::string& id); + AcceptedPort(Stub* parent, bool isDelegate, int fd, const std::string& id); virtual ~AcceptedPort(); + bool IsDelegate() const { + return is_delegate_; + } private: int Watch(); @@ -64,6 +69,7 @@ class Stub : private FdBroker::IEventListener { int disconn_src_ = 0; int src_ = 0; Stub* parent_; + bool is_delegate_ = false; }; static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond, @@ -71,10 +77,10 @@ class Stub : private FdBroker::IEventListener { static gboolean OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, gpointer data); - void OnFdReceived(const std::string& sender, int fd) override; + void OnFdReceived(const std::string& sender, int fds[2]) override; private: - std::list> ports_; + std::list> ports_; IEventListener* listener_ = nullptr; FdBroker fd_broker_; std::string port_name_; diff --git a/unit_tests/src/rpc_port_parcel_test.cc b/unit_tests/src/rpc_port_parcel_test.cc index 1057292..21e11c4 100644 --- a/unit_tests/src/rpc_port_parcel_test.cc +++ b/unit_tests/src/rpc_port_parcel_test.cc @@ -242,3 +242,16 @@ TEST_F(ParcelTest, read_write) { ASSERT_EQ(ret, 0); ASSERT_TRUE(touch_from_); } + +TEST_F(ParcelTest, burst_read_write) { + unsigned char buf[] = { 0, 1, 2, 3, 4 }; + int ret = rpc_port_parcel_burst_write(handle_, buf, sizeof(buf)); + ASSERT_EQ(ret, 0); + + unsigned char buf2[5] = { 0, }; + ret = rpc_port_parcel_burst_read(handle_, buf2, sizeof(buf)); + ASSERT_EQ(ret, 0); + for (int i = 0; i < 5; i++) { + ASSERT_EQ(buf[i], buf2[i]); + } +} -- 2.7.4 From ca10cec77d3ef8382c13ce9284e045638adc377c Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Mon, 18 Jun 2018 16:05:56 +0900 Subject: [PATCH 05/16] Release version 1.1.0 - Add new APIs to fix performance issue and multi-thread issue - Modify doxygen Change-Id: If7a510023ef11ea9c6fdbb331f9a3506144d9cc8 Signed-off-by: Inkyun Kil --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 3972e70..577de83 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.0.12 +Version: 1.1.0 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From df8b97ea1587bb155d28d6afeac99f68c6d3b403 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 20 Jun 2018 17:50:29 +0900 Subject: [PATCH 06/16] Fix bugs about port Change-Id: I27dcf6553b5496255e2e87b379ba7f61b3b029c6 Signed-off-by: Junghoon Park --- src/fdbroker-internal.cc | 11 +++++++---- src/proxy-internal.cc | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 36df52d..d0b53ee 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -246,13 +246,16 @@ int FdBroker::Send(const std::string& target_appid, return -1; if (mock_) { - (*fds)[0] = main_sock_pair.Detach(SocketPair::RECEIVER); - (*fds)[1] = delegate_sock_pair.Detach(SocketPair::RECEIVER); - int ret = DBusMock::GetInst().Send("TestApp", port_name, *fds); + int send_fds[2]; + send_fds[0] = main_sock_pair.Detach(SocketPair::RECEIVER); + send_fds[1] = delegate_sock_pair.Detach(SocketPair::RECEIVER); + int ret = DBusMock::GetInst().Send("TestApp", port_name, send_fds); if (ret < 0) return ret; - return main_sock_pair.Detach(SocketPair::SENDER); + (*fds)[0] = main_sock_pair.Detach(SocketPair::SENDER); + (*fds)[1] = delegate_sock_pair.Detach(SocketPair::SENDER); + return (*fds)[0]; } if (fd_list.Add(main_sock_pair.Detach(SocketPair::RECEIVER)) != 0) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index f5bd629..bdda25c 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -73,7 +73,8 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond, IEventListener* listener = proxy->listener_; proxy->listener_ = nullptr; proxy->main_port_.get()->SetSource(0); - listener->OnDisconnected(proxy->target_appid_); + if (listener) + listener->OnDisconnected(proxy->target_appid_); return FALSE; } @@ -200,7 +201,7 @@ void Proxy::ProxyPort::SetDisconnectedSource(int sourceId) { } void Proxy::ProxyPort::SetSource(int sourceId) { - disconn_src_ = sourceId; + src_ = sourceId; } } // namespace internal -- 2.7.4 From 49e009528a527972deef7ad8a197910fea4ee106 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Wed, 20 Jun 2018 10:03:34 +0900 Subject: [PATCH 07/16] Use delegate port to improve concurrency Change-Id: Id3b2bb7e452e6ebc32bfefe99a0a65a0c4f992e0 Signed-off-by: Junghoon Park --- src/port-internal.cc | 7 +++++-- src/port-internal.h | 3 ++- src/proxy-internal.cc | 17 ++++++++++------- src/proxy-internal.h | 4 ++-- src/stub-internal.cc | 28 ++++++++++++++++++++-------- src/stub-internal.h | 7 +++++-- unit_tests/src/rpc_port_test.cc | 18 ++++++++++++++---- 7 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index 23432aa..52e9128 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -41,8 +41,8 @@ namespace rpc_port { namespace internal { -Port::Port(int fd, const std::string& id) - : fd_(fd), id_(id) { +Port::Port(int fd, std::string id) + : fd_(fd), id_(std::move(id)) { char uuid[37]; uuid_t u; uuid_generate(u); @@ -50,6 +50,9 @@ Port::Port(int fd, const std::string& id) instance_ = std::string(uuid) + ":" + id; } +Port::Port(int fd, std::string id, std::string instance) + : fd_(fd), id_(std::move(id)), instance_(std::move(instance)) {} + Port::~Port() { close(fd_); } diff --git a/src/port-internal.h b/src/port-internal.h index 9d52ae2..2c0bb71 100644 --- a/src/port-internal.h +++ b/src/port-internal.h @@ -27,7 +27,8 @@ namespace internal { class Port { public: - Port(int fd, const std::string& id); + Port(int fd, std::string id, std::string instance); + Port(int fd, std::string id); virtual ~Port(); int Read(void* buf, unsigned int size); diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index bdda25c..2b6c6c6 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -67,12 +67,12 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond, int fd = g_io_channel_unix_get_fd(gio); char buffer[4]; - if (proxy->main_port_.get()->GetFd() == fd) { + if (proxy->delegate_port_.get()->GetFd() == fd) { if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { LOGW("Socket was disconnected by stub. fd(%d)", fd); IEventListener* listener = proxy->listener_; proxy->listener_ = nullptr; - proxy->main_port_.get()->SetSource(0); + proxy->delegate_port_.get()->SetSource(0); if (listener) listener->OnDisconnected(proxy->target_appid_); return FALSE; @@ -110,7 +110,7 @@ void Proxy::OnPortAppeared(const std::string& appid, } LOGW("[__OnPortAppeared__] fds[0]: %d, fds[1]: %d", fds[0], fds[1]); - main_port_.reset(new ProxyPort(this, fds[0], appid)); + main_port_.reset(new ProxyPort(this, fds[0], appid, false)); delegate_port_.reset(new ProxyPort(this, fds[1], appid)); listener_->OnConnected(appid, main_port_.get()); } @@ -145,9 +145,9 @@ int Proxy::Connect(const std::string appid, const std::string& port_name, return RPC_PORT_ERROR_NONE; } -Proxy::ProxyPort::ProxyPort(Proxy* parent, int fd, const std::string& id) - : Port(fd, id), parent_(parent) { - Watch(); +Proxy::ProxyPort::ProxyPort(Proxy* parent, int fd, const std::string& id, + bool receive) : Port(fd, id), parent_(parent) { + Watch(receive); } Proxy::ProxyPort::~ProxyPort() { @@ -161,7 +161,7 @@ Proxy::ProxyPort::~ProxyPort() { g_io_channel_unref(gioc_); } -int Proxy::ProxyPort::Watch() { +int Proxy::ProxyPort::Watch(bool receive) { char buf[1024]; int fd = GetFd(); @@ -181,6 +181,9 @@ int Proxy::ProxyPort::Watch() { return -1; } + if (!receive) + return 0; + src_ = g_io_add_watch(gioc_, (GIOCondition)(G_IO_IN), Proxy::OnDataReceived, parent_); diff --git a/src/proxy-internal.h b/src/proxy-internal.h index b053d84..f5768ed 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -59,13 +59,13 @@ class Proxy : public FdBroker::IEventWatcher { private: class ProxyPort : public Port { public: - ProxyPort(Proxy* parent, int fd, const std::string& id); + ProxyPort(Proxy* parent, int fd, const std::string& id, bool receive = true); virtual ~ProxyPort(); void SetDisconnectedSource(int sourceId); void SetSource(int sourceId); private: - int Watch(); + int Watch(bool receive); private: GIOChannel* gioc_ = nullptr; diff --git a/src/stub-internal.cc b/src/stub-internal.cc index b866b45..696eb6b 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -81,7 +81,6 @@ std::shared_ptr Stub::FindDelegatePort( return {}; } - gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, gpointer data) { Stub* stub = static_cast(data); @@ -145,8 +144,10 @@ gboolean Stub::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, void Stub::OnFdReceived(const std::string& sender, int fds[2]) { LOGW("[__OnFdReceived__] fds[0]: %d, fds[1]: %d", fds[0], fds[1]); - ports_.emplace_back(new AcceptedPort(this, false, fds[0], sender)); - ports_.emplace_back(new AcceptedPort(this, true, fds[1], sender)); + auto* main_port = new AcceptedPort(this, false, fds[0], sender, true); + ports_.emplace_back(main_port); + ports_.emplace_back(new AcceptedPort(this, true, fds[1], sender, + main_port->GetInstance(), false)); for (auto& p : ports_) { if (p->GetFd() == fds[0]) { listener_->OnConnected(p->GetId(), p->GetInstance()); @@ -155,10 +156,18 @@ void Stub::OnFdReceived(const std::string& sender, int fds[2]) { } } -Stub::AcceptedPort::AcceptedPort(Stub* parent, bool isDelegate, - int fd, const std::string& id) - : Port(fd, id), parent_(parent), is_delegate_(isDelegate) { - Watch(); +Stub::AcceptedPort::AcceptedPort(Stub* parent, bool isDelegate, int fd, + std::string id, std::string inst, bool watch) + : Port(fd, std::move(id), std::move(inst)), parent_(parent), + is_delegate_(isDelegate) { + Watch(watch); +} + +Stub::AcceptedPort::AcceptedPort(Stub* parent, bool isDelegate, int fd, + std::string id, bool watch) + : Port(fd, std::move(id)), parent_(parent), + is_delegate_(isDelegate) { + Watch(watch); } Stub::AcceptedPort::~AcceptedPort() { @@ -172,7 +181,7 @@ Stub::AcceptedPort::~AcceptedPort() { g_io_channel_unref(gioc_); } -int Stub::AcceptedPort::Watch() { +int Stub::AcceptedPort::Watch(bool receive) { char buf[1024]; int fd = GetFd(); @@ -192,6 +201,9 @@ int Stub::AcceptedPort::Watch() { return -1; } + if (!receive) + return 0; + src_ = g_io_add_watch(gioc_, (GIOCondition)(G_IO_IN), Stub::OnDataReceived, parent_); diff --git a/src/stub-internal.h b/src/stub-internal.h index 05ff1b2..e3408f2 100644 --- a/src/stub-internal.h +++ b/src/stub-internal.h @@ -55,14 +55,17 @@ class Stub : private FdBroker::IEventListener { private: class AcceptedPort : public Port { public: - AcceptedPort(Stub* parent, bool isDelegate, int fd, const std::string& id); + AcceptedPort(Stub* parent, bool isDelegate, int fd, std::string id, + std::string inst, bool receive); + AcceptedPort(Stub* parent, bool isDelegate, int fd, std::string id, + bool receive); virtual ~AcceptedPort(); bool IsDelegate() const { return is_delegate_; } private: - int Watch(); + int Watch(bool receive); private: GIOChannel* gioc_ = nullptr; diff --git a/unit_tests/src/rpc_port_test.cc b/unit_tests/src/rpc_port_test.cc index 11d6eaf..dd2dc87 100644 --- a/unit_tests/src/rpc_port_test.cc +++ b/unit_tests/src/rpc_port_test.cc @@ -105,6 +105,9 @@ class RpcPortConnection : public RpcPortBase { rpc_port_h port, void *data) -> int { RpcPortConnection* p = static_cast(data); p->stub_port_ = port; + rpc_port_stub_get_port(p->stub_handle_, RPC_PORT_PORT_CALLBACK, + instance, &p->stub_callback_port_); + p->Finish(); return 0; }, this); @@ -131,6 +134,8 @@ class RpcPortConnection : public RpcPortBase { [](const char *ep, const char *port_name, rpc_port_h port, void *data) { RpcPortConnection* p = static_cast(data); p->proxy_port_ = port; + rpc_port_proxy_get_port(p->proxy_handle_, RPC_PORT_PORT_CALLBACK, + &p->proxy_callback_port_); }, this); ASSERT_EQ(ret, 0); @@ -155,7 +160,9 @@ class RpcPortConnection : public RpcPortBase { } rpc_port_h proxy_port_ = nullptr; + rpc_port_h proxy_callback_port_ = nullptr; rpc_port_h stub_port_ = nullptr; + rpc_port_h stub_callback_port_ = nullptr; bool touch_proxy_disconnected_event_cb_ = false; bool touch_stub_disconnected_event_cb_ = false; bool touch_proxy_received_event_cb_ = false; @@ -216,23 +223,26 @@ TEST_F(RpcPortConnection, rpc_port_proxy_event_receive) { RunMainLoop(); ASSERT_NE(stub_port_, nullptr); + ASSERT_NE(stub_callback_port_, nullptr); - ret = rpc_port_write(stub_port_, res, sizeof(res)); + ret = rpc_port_write(stub_callback_port_, res, sizeof(res)); ASSERT_EQ(ret, 0); + RunMainLoop(); ASSERT_TRUE(touch_proxy_received_event_cb_); - ret = rpc_port_read(proxy_port_, r_buf, sizeof(res)); + ret = rpc_port_read(proxy_callback_port_, r_buf, sizeof(res)); ASSERT_EQ(ret, 0); ASSERT_STREQ(res, r_buf); touch_proxy_received_event_cb_ = false; - ret = rpc_port_write(stub_port_, res, sizeof(res)); + ret = rpc_port_write(stub_callback_port_, res, sizeof(res)); ASSERT_EQ(ret, 0); + RunMainLoop(); ASSERT_TRUE(touch_proxy_received_event_cb_); - ret = rpc_port_read(proxy_port_, r_buf, sizeof(res)); + ret = rpc_port_read(proxy_callback_port_, r_buf, sizeof(res)); ASSERT_EQ(ret, 0); ASSERT_STREQ(res, r_buf); } -- 2.7.4 From 26ae75d7087a1d361b92025a843058838a9116d0 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 21 Jun 2018 14:25:28 +0900 Subject: [PATCH 08/16] Release version 1.2.0 Changes - Use delegate port to improve concurrency - Fix bugs about port Change-Id: I93013985f7896676faf7860d7a639ee25ee32bf2 Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 577de83..bf63f1d 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.1.0 +Version: 1.2.0 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From cfb2d37eb6044d8b9019202be26f7d19f352e8bb Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Thu, 28 Jun 2018 14:20:43 +0900 Subject: [PATCH 09/16] Sleep and retry to write - If EAGAIN or EWOULDBLOCK happen, sleep some time and retry to write Change-Id: I40e57426d6d961b0b583cfd06388b8f6afcf1295 Signed-off-by: Junghoon Park --- src/port-internal.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index 52e9128..4287675 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -35,8 +35,10 @@ #define LOG_TAG "RPC_PORT" -#define MAX_RETRY_CNT 18 +#define MAX_RETRY_CNT 100 #define SEND_TIMEOUT 500 +#define MAX_SLEEP 100 * 1000 * 1000 +#define MIN_SLEEP 5 * 1000 * 1000 namespace rpc_port { namespace internal { @@ -61,7 +63,7 @@ int Port::Read(void* buf, unsigned int size) { unsigned int left = size; ssize_t nb; int retry_cnt = 0; - struct timespec TRY_SLEEP_TIME = { 0, 5 * 1000 * 1000 }; + struct timespec TRY_SLEEP_TIME = { 0, MIN_SLEEP }; int bytes_read = 0; char* buffer = static_cast(buf); std::lock_guard lock(mutex_); @@ -77,18 +79,20 @@ int Port::Read(void* buf, unsigned int size) { retry_cnt++; nanosleep(&TRY_SLEEP_TIME, 0); TRY_SLEEP_TIME.tv_nsec *= 2; - if (TRY_SLEEP_TIME.tv_nsec > 999999999) - TRY_SLEEP_TIME.tv_nsec = 999999999; + if (TRY_SLEEP_TIME.tv_nsec > MAX_SLEEP) + TRY_SLEEP_TIME.tv_nsec = MAX_SLEEP; continue; } + LOGE("read_socket: ...error fd %d: errno %d\n", fd_, errno); - return RPC_PORT_ERROR_IO_ERROR; + return RPC_PORT_ERROR_IO_ERROR; } left -= nb; buffer += nb; bytes_read += nb; retry_cnt = 0; + TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP; } if (left != 0) { @@ -103,6 +107,7 @@ int Port::Write(const void* buf, unsigned int size) { unsigned int left = size; ssize_t nb; int retry_cnt = 0; + struct timespec TRY_SLEEP_TIME = { 0, MIN_SLEEP }; struct pollfd fds[1]; int ret; int bytes_write = 0; @@ -122,9 +127,13 @@ int Port::Write(const void* buf, unsigned int size) { while (left && (retry_cnt < MAX_RETRY_CNT)) { nb = write(fd_, buffer, left); if (nb == -1) { - if (errno == EINTR) { - LOGE("write_socket: EINTR error continue ..."); + if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { + LOGE("write_socket: %d errno, sleep and retry ...", errno); retry_cnt++; + nanosleep(&TRY_SLEEP_TIME, 0); + TRY_SLEEP_TIME.tv_nsec *= 2; + if (TRY_SLEEP_TIME.tv_nsec > MAX_SLEEP) + TRY_SLEEP_TIME.tv_nsec = MAX_SLEEP; continue; } @@ -136,6 +145,7 @@ int Port::Write(const void* buf, unsigned int size) { buffer += nb; bytes_write += nb; retry_cnt = 0; + TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP; } if (left != 0) { -- 2.7.4 From c7090e85ce51443aa322ecd357a7d5b6d9478d30 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 29 Jun 2018 08:13:24 +0900 Subject: [PATCH 10/16] Modify exception handling If Send() method returns EILLEGALACCESS, OnRejected() function is invoked. Change-Id: I83c95f248784b9de1514dab5787fd70221c26dab Signed-off-by: Hwankyu Jhun --- src/fdbroker-internal.cc | 5 ++++- src/proxy-internal.cc | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index d0b53ee..2c183a3 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -33,6 +33,7 @@ #define LOG_TAG "RPC_PORT" +#define EILLEGALACCESS 127 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus" #define DBUS_PATH_DBUS "/org/freedesktop/DBus" @@ -100,6 +101,8 @@ FdBroker::DBusMock& FdBroker::DBusMock::GetInst() { int FdBroker::DBusMock::Send(const std::string& sender, const std::string& port, int fds[2]) { + if (port == "wrong_port") + return -EILLEGALACCESS; if (ports_.find(port) == ports_.end()) return -1; @@ -295,7 +298,7 @@ int FdBroker::Send(const std::string& target_appid, LOGE("Access Denied[sender_appid : %s]", sender_appid); g_object_unref(msg); g_object_unref(reply); - return -1; + return -EILLEGALACCESS; } LOGD("[Reply : %d]", ret); diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 2b6c6c6..4830f42 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -102,10 +102,13 @@ void Proxy::OnPortAppeared(const std::string& appid, int fds[2] = { 0, }; int r = fd_broker_.Send(appid, port_name, &fds); - if (r <= 0 || fds[0] <= 0 || fds[1] <= 0) { + if (r <= 0) { IEventListener* listener = listener_; listener_ = nullptr; - listener->OnRejected(appid); + if (r == -EILLEGALACCESS) + listener->OnRejected(appid); + else + listener->OnDisconnected(appid); return; } @@ -117,7 +120,8 @@ void Proxy::OnPortAppeared(const std::string& appid, void Proxy::OnPortVanished(const std::string& appid, const std::string& port_name) { - LOGD("endpoint(%s), port_name(%s)", appid.c_str(), port_name.c_str()); + LOGW("[__OnPortVanished__] endpoint(%s), port_name(%s)", + appid.c_str(), port_name.c_str()); } int Proxy::Connect(const std::string appid, const std::string& port_name, -- 2.7.4 From d132e6d984c54f32b2335a2a4f4c350972b02fc9 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Fri, 29 Jun 2018 09:51:58 +0900 Subject: [PATCH 11/16] Release version 1.2.1 Changes: - Sleep and retry to write - Modify exception handling Change-Id: I3b5d1799233f946724bea0e20f52358075c3b86c Signed-off-by: Junghoon Park --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index bf63f1d..5c1c181 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.2.0 +Version: 1.2.1 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 6a7164301621049ba29124ed604afb9badff5665 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 2 Aug 2018 08:59:12 +0900 Subject: [PATCH 12/16] Adjust timeout interval The maximum interval is changed to 10 seconds. If the waiting time is more than 10 seconds, the function returns a negative error value. Change-Id: I97c84b6c716c7e7a21910a3619bc879cc9fd1c05 Signed-off-by: Hwankyu Jhun --- src/port-internal.cc | 63 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index 4287675..42b745c 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -35,10 +35,10 @@ #define LOG_TAG "RPC_PORT" -#define MAX_RETRY_CNT 100 -#define SEND_TIMEOUT 500 -#define MAX_SLEEP 100 * 1000 * 1000 -#define MIN_SLEEP 5 * 1000 * 1000 +#define MAX_CNT 100 +#define MAX_SLEEP 100 +#define MIN_SLEEP 5 +#define BASE_SLEEP 1000 * 1000 namespace rpc_port { namespace internal { @@ -62,13 +62,13 @@ Port::~Port() { int Port::Read(void* buf, unsigned int size) { unsigned int left = size; ssize_t nb; - int retry_cnt = 0; - struct timespec TRY_SLEEP_TIME = { 0, MIN_SLEEP }; + struct timespec TRY_SLEEP_TIME = { 0, MIN_SLEEP * BASE_SLEEP}; int bytes_read = 0; char* buffer = static_cast(buf); + int max_timeout = MAX_CNT * MAX_SLEEP; /* 10 sec */ std::lock_guard lock(mutex_); - while (left && (retry_cnt < MAX_RETRY_CNT)) { + while (left) { nb = read(fd_, buffer, left); if (nb == 0) { LOGE("read_socket: ...read EOF, socket closed %d: nb %d\n", fd_, nb); @@ -76,11 +76,15 @@ int Port::Read(void* buf, unsigned int size) { } else if (nb == -1) { if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { LOGE("read_socket: %d errno, sleep and retry ...", errno); - retry_cnt++; nanosleep(&TRY_SLEEP_TIME, 0); + max_timeout -= (TRY_SLEEP_TIME.tv_nsec / (BASE_SLEEP)); + if (max_timeout <= 0) { + LOGE("read_socket: ...timed out fd %d: errno %d", fd_, errno); + return RPC_PORT_ERROR_IO_ERROR; + } TRY_SLEEP_TIME.tv_nsec *= 2; - if (TRY_SLEEP_TIME.tv_nsec > MAX_SLEEP) - TRY_SLEEP_TIME.tv_nsec = MAX_SLEEP; + if (TRY_SLEEP_TIME.tv_nsec > (MAX_SLEEP * BASE_SLEEP)) + TRY_SLEEP_TIME.tv_nsec = MAX_SLEEP * BASE_SLEEP; continue; } @@ -91,12 +95,11 @@ int Port::Read(void* buf, unsigned int size) { left -= nb; buffer += nb; bytes_read += nb; - retry_cnt = 0; - TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP; + TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP * BASE_SLEEP; } if (left != 0) { - LOGE("error fd %d: retry_cnt %d", fd_, retry_cnt); + LOGE("error fd %d: max_timeout %d", fd_, max_timeout); return RPC_PORT_ERROR_IO_ERROR; } @@ -106,34 +109,49 @@ int Port::Read(void* buf, unsigned int size) { int Port::Write(const void* buf, unsigned int size) { unsigned int left = size; ssize_t nb; - int retry_cnt = 0; - struct timespec TRY_SLEEP_TIME = { 0, MIN_SLEEP }; + struct timespec TRY_SLEEP_TIME = { 0, MIN_SLEEP * BASE_SLEEP }; struct pollfd fds[1]; int ret; int bytes_write = 0; const char* buffer = static_cast(buf); + int max_timeout = MAX_CNT * MAX_SLEEP; /* 10 sec */ + struct timespec start_time = { 0, }; + struct timespec end_time = { 0, }; std::lock_guard lock(mutex_); fds[0].fd = fd_; fds[0].events = POLLOUT; fds[0].revents = 0; - ret = poll(fds, 1, SEND_TIMEOUT); + clock_gettime(CLOCK_MONOTONIC, &start_time); + ret = poll(fds, 1, MAX_SLEEP * 1000); + clock_gettime(CLOCK_MONOTONIC, &end_time); if (ret == 0) { LOGE("write_socket: : fd %d poll timeout", fd_); return RPC_PORT_ERROR_IO_ERROR; } - while (left && (retry_cnt < MAX_RETRY_CNT)) { + max_timeout -= (((end_time.tv_sec - start_time.tv_sec) * 1000) + + ((end_time.tv_nsec - start_time.tv_nsec) / (BASE_SLEEP))); + if (max_timeout <= 0) { + LOGE("write_socket: ...timed out fd %d: errno %d", fd_, errno); + return RPC_PORT_ERROR_IO_ERROR; + } + + while (left) { nb = write(fd_, buffer, left); if (nb == -1) { if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { LOGE("write_socket: %d errno, sleep and retry ...", errno); - retry_cnt++; nanosleep(&TRY_SLEEP_TIME, 0); + max_timeout -= (TRY_SLEEP_TIME.tv_nsec / (BASE_SLEEP)); + if (max_timeout <= 0) { + LOGE("write_socket: ...timed out fd %d: errno %d", fd_, errno); + return RPC_PORT_ERROR_IO_ERROR; + } TRY_SLEEP_TIME.tv_nsec *= 2; - if (TRY_SLEEP_TIME.tv_nsec > MAX_SLEEP) - TRY_SLEEP_TIME.tv_nsec = MAX_SLEEP; + if (TRY_SLEEP_TIME.tv_nsec > (MAX_SLEEP * BASE_SLEEP)) + TRY_SLEEP_TIME.tv_nsec = MAX_SLEEP * BASE_SLEEP; continue; } @@ -144,12 +162,11 @@ int Port::Write(const void* buf, unsigned int size) { left -= nb; buffer += nb; bytes_write += nb; - retry_cnt = 0; - TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP; + TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP * BASE_SLEEP; } if (left != 0) { - LOGE("error fd %d: retry_cnt %d", fd_, retry_cnt); + LOGE("error fd %d: max_timeout %d", fd_, max_timeout); return RPC_PORT_ERROR_IO_ERROR; } -- 2.7.4 From 0543c071d50ec6d20426d1208804eebec9b1288a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 3 Aug 2018 12:15:37 +0900 Subject: [PATCH 13/16] Release version 1.2.2 Changes: - Adjust timeout interval Change-Id: Iedc38f1e0d6eee02d6aeded8b887389ccb713f5b Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 5c1c181..87a99e4 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.2.1 +Version: 1.2.2 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 796600d5198bb4f9d3ad106456dd28df09ba3698 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 13 Aug 2018 10:46:50 +0900 Subject: [PATCH 14/16] Remove unreachable code Change-Id: I094b5d37556b3157f40b9416c9de1c93c8ce01da Signed-off-by: Hwankyu Jhun --- src/port-internal.cc | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/port-internal.cc b/src/port-internal.cc index 42b745c..7733afd 100644 --- a/src/port-internal.cc +++ b/src/port-internal.cc @@ -98,11 +98,6 @@ int Port::Read(void* buf, unsigned int size) { TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP * BASE_SLEEP; } - if (left != 0) { - LOGE("error fd %d: max_timeout %d", fd_, max_timeout); - return RPC_PORT_ERROR_IO_ERROR; - } - return RPC_PORT_ERROR_NONE; } @@ -165,11 +160,6 @@ int Port::Write(const void* buf, unsigned int size) { TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP * BASE_SLEEP; } - if (left != 0) { - LOGE("error fd %d: max_timeout %d", fd_, max_timeout); - return RPC_PORT_ERROR_IO_ERROR; - } - return RPC_PORT_ERROR_NONE; } -- 2.7.4 From e2c948ae0e776f112004a3346f07b343cb80e154 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 18 Jul 2018 09:22:55 +0900 Subject: [PATCH 15/16] Modified the description - Changes since_tizen tags Change-Id: Ie52906f901b289273d4dcc0bcb8658f98efec2f1 Signed-off-by: Hwankyu Jhun --- include/rpc-port-parcel.h | 60 ++++++++++++++++++++++----------------------- include/rpc-port.h | 62 +++++++++++++++++++++++------------------------ 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/include/rpc-port-parcel.h b/include/rpc-port-parcel.h index 4ba9f9f..1a3d661 100644 --- a/include/rpc-port-parcel.h +++ b/include/rpc-port-parcel.h @@ -32,13 +32,13 @@ extern "C" { /** * @brief The rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif */ typedef void *rpc_port_parcel_h; /** * @brief The interface for converting data to/from a parcel. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif */ typedef struct __rpc_port_parcelable { void (*to)(rpc_port_parcel_h h, void *data); @@ -47,7 +47,7 @@ typedef struct __rpc_port_parcelable { /** * @brief Creates a rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @remarks You must release @a h using rpc_port_parcel_destroy(). * @param[out] h The rpc port parcel handle that is newly created * @return @c 0 on success, @@ -61,7 +61,7 @@ int rpc_port_parcel_create(rpc_port_parcel_h *h); * @brief Creates a rpc port parcel handle from port. * @details Creates a rpc port parcel handle using read data from the port. * It calls rpc_port_read() internally. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @remarks You must release @a h using rpc_port_parcel_destroy(). * @param[out] h The rpc port parcel handle that is newly created * @param[in] port The rpc port handle for creating handle @@ -79,7 +79,7 @@ int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h, rpc_port_h port); * @brief Sends parcel data through the port. * @details Sends parcel data through the port. It calls rpc_port_write() * internally. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle that is newly created * @param[in] port The rpc port handle for writing data * @return @c 0 on success, @@ -93,7 +93,7 @@ int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port); /** * @brief Destroys a rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @return @c 0 on success, * otherwise a negative error value @@ -105,7 +105,7 @@ int rpc_port_parcel_destroy(rpc_port_parcel_h h); /** * @brief Writes a byte value into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] b Byte data * @return @c 0 on success, @@ -118,7 +118,7 @@ int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b); /** * @brief Writes a short value into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] i short data * @return @c 0 on success, @@ -131,7 +131,7 @@ int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i); /** * @brief Writes a integer value into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] i int data * @return @c 0 on success, @@ -144,7 +144,7 @@ int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i); /** * @brief Writes a long long integer value into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] i long long data * @return @c 0 on success, @@ -157,7 +157,7 @@ int rpc_port_parcel_write_int64(rpc_port_parcel_h h, long long i); /** * @brief Writes a floating point value into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] f float data * @return @c 0 on success, @@ -170,7 +170,7 @@ int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f); /** * @brief Writes a double precision floating point value into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] d double data * @return @c 0 on success, @@ -183,7 +183,7 @@ int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d); /** * @brief Writes a string value into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] str string data * @return @c 0 on success, @@ -196,7 +196,7 @@ int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char *str); /** * @brief Writes a boolean value into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] b boolean data * @return @c 0 on success, @@ -209,7 +209,7 @@ int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b); /** * @brief Writes a bundle data into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] b Bundle data * @return @c 0 on success, @@ -222,7 +222,7 @@ int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle *b); /** * @brief Writes a count for array into rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] count Array count * @return @c 0 on success, @@ -235,7 +235,7 @@ int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count); /** * @brief Writes the data into parcel handle using @a parcelable. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] parcelable The interface to write the data into parcel handle * @param[in] data Data which write into parcel @@ -249,7 +249,7 @@ int rpc_port_parcel_write(rpc_port_parcel_h h, rpc_port_parcelable_t *parcelable /** * @brief Reads a byte value from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] b Byte data * @return @c 0 on success, @@ -262,7 +262,7 @@ int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char *b); /** * @brief Reads a short value from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] i short data * @return @c 0 on success, @@ -275,7 +275,7 @@ int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i); /** * @brief Reads a integer value from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] i int data * @return @c 0 on success, @@ -288,7 +288,7 @@ int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int *i); /** * @brief Reads a long long integer value from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] i long long data * @return @c 0 on success, @@ -301,7 +301,7 @@ int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long *i); /** * @brief Reads a floating point value from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] f float data * @return @c 0 on success, @@ -314,7 +314,7 @@ int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f); /** * @brief Reads a double precision floating point value from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] d double data * @return @c 0 on success, @@ -327,7 +327,7 @@ int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d); /** * @brief Reads a string value from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @remarks The @a str should be released using free(). * @param[in] h The rpc port parcel handle * @param[out] str string data @@ -341,7 +341,7 @@ int rpc_port_parcel_read_string(rpc_port_parcel_h h, char **str); /** * @brief Reads a boolean value from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] b boolean data * @return @c 0 on success, @@ -354,7 +354,7 @@ int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b); /** * @brief Reads a bundle data from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @remarks The @a b should be released using bundle_free(). * @param[in] h The rpc port parcel handle * @param[out] b Bundle data @@ -368,7 +368,7 @@ int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle **b); /** * @brief Reads a count for array from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] count Array count * @return @c 0 on success, @@ -381,7 +381,7 @@ int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count); /** * @brief Reads a parcel from the data using @a parcelable. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] parcelable The interface to get data from parcel handle * @param[in] data Data which get from parcel @@ -396,7 +396,7 @@ int rpc_port_parcel_read(rpc_port_parcel_h h, rpc_port_parcelable_t *parcelable, /** * @brief Reads bytes from rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[out] buf The array buffer to read * @param[in] size Bytes to read @@ -410,7 +410,7 @@ int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf, unsigned /** * @brief Write bytes to rpc port parcel handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port parcel handle * @param[in] buf The array buffer to write * @param[in] size Bytes to write diff --git a/include/rpc-port.h b/include/rpc-port.h index f14aac0..559141b 100755 --- a/include/rpc-port.h +++ b/include/rpc-port.h @@ -32,7 +32,7 @@ extern "C" { /** * @brief Enumeration for error codes of a rpc port. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif */ typedef enum { RPC_PORT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ @@ -44,7 +44,7 @@ typedef enum { /** * @brief Enumeration for types of communication channels. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif */ typedef enum { RPC_PORT_PORT_MAIN, /**< Main channel */ @@ -55,13 +55,13 @@ typedef enum { /** * @brief The rpc port handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif */ typedef void *rpc_port_h; /** * @brief Reads data from an RPC port. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * * @param[in] h The rpc port handle * @param[out] buf Buffer for reading data @@ -78,7 +78,7 @@ int rpc_port_read(rpc_port_h h, void *buf, unsigned int size); /** * @brief Writes data to an RPC port. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * * @param[in] h The rpc port handle * @param[in] buf Buffer for writing data @@ -99,7 +99,7 @@ int rpc_port_write(rpc_port_h h, const void *buf, unsigned int size); /** * @brief Called when the proxy is connected. * @details The function is called when the proxy is connected with stub by port. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] receiver The target stub app id * @param[in] port_name The name of the port * @param[in] port The rpc port handle for reading and writing @@ -111,7 +111,7 @@ typedef void (*rpc_port_proxy_connected_event_cb)(const char *receiver, /** * @brief Called when the proxy is disconnected. * @details The function is called when the proxy is disconnected from stub. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] receiver The target stub app id * @param[in] port_name The name of the port * @param[in] user_data The user data passed from the register function @@ -122,7 +122,7 @@ typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *receiver, /** * @brief Called when the proxy is rejected. * @details The function is called when the proxy is rejected to connect stub. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] receiver The target stub app id * @param[in] port_name The name of the port * @param[in] user_data The user data passed from the register function @@ -133,7 +133,7 @@ typedef void (*rpc_port_proxy_rejected_event_cb)(const char *receiver, /** * @brief Called when the proxy received data. * @details The function is called when the proxy received data from stub. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] receiver The target stub app id * @param[in] port_name The name of the port * @param[in] user_data The user data passed from the register function @@ -143,13 +143,13 @@ typedef void (*rpc_port_proxy_received_event_cb)(const char *receiver, /** * @brief The rpc port proxy handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif */ typedef void *rpc_port_proxy_h; /** * @brief Creates a rpc port proxy handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @remarks You must release @a h using rpc_port_proxy_destroy(). * @param[out] h The rpc port proxy handle that is newly created * @return @c 0 on success, @@ -162,7 +162,7 @@ int rpc_port_proxy_create(rpc_port_proxy_h *h); /** * @brief Destroys a rpc port proxy handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port proxy handle * @return @c 0 on success, * otherwise a negative error value @@ -175,7 +175,7 @@ int rpc_port_proxy_destroy(rpc_port_proxy_h h); /** * @brief Connects to @a port of @a appid. * @details To send and receive data, the proxy should connect to port of stub - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/appmanager.launch \n * %http://tizen.org/privilege/datasharing @@ -195,7 +195,7 @@ int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid, /** * @brief Adds a proxy connected callback. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port proxy handle * @param[in] cb The callback function to be called when proxy is connected * @param[in] user_data The user data to be passed to @@ -210,7 +210,7 @@ int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, /** * @brief Adds a proxy disconnected callback. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port proxy handle * @param[in] cb The callback function to be called when proxy is disconnected * @param[in] user_data The user data to be passed to @@ -225,7 +225,7 @@ int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, /** * @brief Adds a proxy rejected callback. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port proxy handle * @param[in] cb The callback function to be called when proxy is rejected * @param[in] user_data The user data to be passed to @@ -240,7 +240,7 @@ int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, /** * @brief Adds a proxy received callback. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port proxy handle * @param[in] cb The callback function to be called when proxy received data * @param[in] user_data The user data to be passed to @@ -255,7 +255,7 @@ int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, /** * @brief Gets a port from proxy handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @remarks This handle @a port will not be valid if the proxy was disconnected or destroyed. * @param[in] h The rpc port proxy handle * @param[in] type The type of port @@ -277,7 +277,7 @@ int rpc_port_proxy_get_port(rpc_port_proxy_h h, rpc_port_port_type_e type, /** * @brief The rpc port stub handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif */ typedef void *rpc_port_stub_h; @@ -286,7 +286,7 @@ typedef void *rpc_port_stub_h; * @details The function is called when the proxy is connected with stub. * When a proxy connects to stub several times with new port, * you can handle each request by using @a instance. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] sender The target proxy app id * @param[in] instance The information of the request * @param[in] user_data The user data passed from the register function @@ -299,7 +299,7 @@ typedef void (*rpc_port_stub_connected_event_cb)(const char *sender, * @details The function is called when the proxy is disconnected from stub. * When a proxy is disconnected, you can check the request * by using @a instance. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] sender The target proxy app id * @param[in] instance The information of the request * @param[in] user_data The user data passed from the register function @@ -313,7 +313,7 @@ typedef void (*rpc_port_stub_disconnected_event_cb)(const char *sender, * When a stub received data from several ports, you can handle * each request by using @a instance. If the function returns non zero * value, the stub is disconnected. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] sender The target proxy app id * @param[in] instance The information of the request * @param[in] port The rpc port handle for reading and writing @@ -326,7 +326,7 @@ typedef int (*rpc_port_stub_received_event_cb)(const char *sender, /** * @brief Creates a rpc port stub handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @remarks You must release @a h using rpc_port_stub_destroy(). * @param[out] h The rpc port stub handle that is newly created * @param[in] port_name The name of the port which want to listen @@ -340,7 +340,7 @@ int rpc_port_stub_create(rpc_port_stub_h *h, const char *port_name); /** * @brief Destroys a rpc port stub handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port stub handle * @return @c 0 on success, * otherwise a negative error value @@ -353,7 +353,7 @@ int rpc_port_stub_destroy(rpc_port_stub_h h); /** * @brief Listens to the requests for connections. * @details The stub listens requests to connect by port - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port stub handle * @return @c 0 on success, * otherwise a negative error value @@ -367,7 +367,7 @@ int rpc_port_stub_listen(rpc_port_stub_h h); * @brief Adds a privilege to the stub. * @details The stub can control access to the port using tizen privilege. * It allows connections only if the proxy which have the privileges. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port stub handle * @param[in] privilege The privilege to access this stub * @return @c 0 on success, @@ -382,7 +382,7 @@ int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege); * @details The stub can control access to the port using tizen certificate. * It allows connections only if the proxy is signed with the same * certificate. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port stub handle * @param[in] trusted Whether stub allows only trusted proxy or not * @return @c 0 on success, @@ -394,7 +394,7 @@ int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted); /** * @brief Adds a stub connected callback. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc stub stub handle * @param[in] cb The callback function to be called when proxy is connected * with the stub @@ -410,7 +410,7 @@ int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, /** * @brief Adds a stub disconnected callback. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port stub handle * @param[in] cb The callback function to be called when proxy is disconnected * with the stub @@ -426,7 +426,7 @@ int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, /** * @brief Adds a stub received callback. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] h The rpc port stub handle * @param[in] cb The callback function to be called when stub received data * @param[in] user_data The user data to be passed to @@ -441,7 +441,7 @@ int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, /** * @brief Gets a port from stub handle. - * @since_tizen 4.0 + * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @remarks This handle @a port will not be valid if the instance of the stub was disconnected or destroyed. * @param[in] h The rpc port stub handle * @param[in] type The type of port -- 2.7.4 From c7c0783f3d0f1cf3e537493955c3aff84c97f6f3 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 13 Aug 2018 12:09:40 +0900 Subject: [PATCH 16/16] Release version 1.2.4 Changes: - Remove unreachable code - Modified the description Change-Id: I4852ba4f515e08989be5c1af07c827da63339734 Signed-off-by: Hwankyu Jhun --- packaging/rpc-port.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 87a99e4..384c6cb 100755 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -1,6 +1,6 @@ Name: rpc-port Summary: RPC Port library -Version: 1.2.2 +Version: 1.2.4 Release: 0 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4