From 87c6a5b4aab5138e9dd8477b9a9d901c16ea53c7 Mon Sep 17 00:00:00 2001 From: kmook Date: Thu, 8 Dec 2016 14:08:59 +0900 Subject: [PATCH] Applied direct binary array transfer via dbus Change-Id: I52c36f97cb39f3e98363c42b7cb64caeec713a64 Signed-off-by: kmook --- common/Types.h | 8 ++- daemon/CMakeLists.txt | 3 +- daemon/ConnectionManager.cpp | 2 +- daemon/DbusServer.cpp | 24 ++++--- daemon/DbusServer.h | 4 +- daemon/DiscoveryManager.cpp | 6 +- daemon/Json.cpp | 16 +++++ daemon/Json.h | 1 + daemon/Request.cpp | 33 ++++++++-- daemon/Request.h | 13 +++- daemon/access_control/ACLManager.cpp | 2 +- .../WifiDirectDiscoveryProvider.cpp | 6 +- .../service_provider/AppCommServiceApplication.cpp | 30 ++++----- daemon/service_provider/AppCommServiceProvider.cpp | 20 ++---- .../RemoteAppControlServiceProvider.cpp | 4 +- lib/CMakeLists.txt | 2 +- lib/conv_lib.cpp | 6 +- lib/conv_lib_acl.cpp | 12 ++-- lib/conv_lib_payload.cpp | 30 +++++++++ lib/conv_lib_service.cpp | 66 ++++++++++++------- lib/dbus_client.cpp | 24 ++++--- lib/dbus_client.h | 6 +- lib/include/d2d_conv_internal.h | 36 ++++++++++ lib/internal_types.h | 2 + msf_tizen_client/include/Channel.h | 17 ++--- msf_tizen_client/src/Channel.cpp | 76 ++++++++++++++++------ packaging/d2d-conv-manager.spec | 2 +- 27 files changed, 318 insertions(+), 133 deletions(-) diff --git a/common/Types.h b/common/Types.h index 2cab709..bd8cf9c 100644 --- a/common/Types.h +++ b/common/Types.h @@ -49,6 +49,10 @@ #define ARG_RESULT_ERR "r_err" #define ARG_RESULT_ADD "r_add" #define ARG_OUTPUT "output" +#define ARG_INPUT_BINARY "input_binary" +#define ARG_OUTPUT_BINARY "output_binary" +#define ARG_INPUT_BINARY_LENGTH "input_binary_length" +#define ARG_OUTPUT_BINARY_LENGTH "output_binary_length" #define CONV_METHOD_REQUEST "CONV_Request" #define CONV_METHOD_RESPOND "CONV_Respond" @@ -160,10 +164,10 @@ enum AccessControlState { #define CONV_JSON_RESULT_TYPE "result_type" #define CONV_JSON_READ_TYPE "read_type" #define CONV_JSON_MESSAGE "message_smartview" -#define CONV_JSON_DATA "data" +#define CONV_JSON_DATA "data_smartview" #define CONV_JSON_CLIENT "client" #define CONV_JSON_PAYLOAD_SIZE "payload_size_smartview" -#define CONV_JSON_EVENT "event" +#define CONV_JSON_EVENT "event_smartview" #define CONV_JSON_FROM "from" #define CONV_JSON_IS_HOST "isHost" #define CONV_JSON_CONNECT_TIME "connectTime" diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 3cba0fa..e12df80 100755 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -13,8 +13,9 @@ FILE(GLOB DAEMON_SRCS ${DAEMON_SRCS} discovery_provider/iotcon/*.cpp) FILE(GLOB DAEMON_SRCS ${DAEMON_SRCS} discovery_provider/smartview/*.cpp) FILE(GLOB DAEMON_SRCS ${DAEMON_SRCS} ../msf_tizen_client/src/*.cpp) -SET(provider_deps "glib-2.0 dlog json-glib-1.0 iotcon capi-appfw-app-manager iotcon vconf capi-network-bluetooth capi-network-wifi-direct capi-appfw-application bundle capi-network-connection cynara-creds-gdbus cynara-client cynara-session capi-appfw-package-manager sqlite3 syspopup-caller") +SET(provider_deps "glib-2.0 dlog json-glib-1.0 iotcon capi-appfw-app-manager vconf capi-network-bluetooth capi-appfw-application bundle capi-network-connection cynara-creds-gdbus cynara-client cynara-session capi-appfw-package-manager sqlite3 syspopup-caller") SET(provider_deps "${provider_deps} openssl libwebsockets libcurl nsd-dns-sd") +#SET(provider_deps "${provider_deps} capi-network-wifi-direct") # Wearable profile IF("${PROFILE}" STREQUAL "wearable") diff --git a/daemon/ConnectionManager.cpp b/daemon/ConnectionManager.cpp index 4d41151..804ba12 100755 --- a/daemon/ConnectionManager.cpp +++ b/daemon/ConnectionManager.cpp @@ -91,7 +91,7 @@ int conv::ConnectionManager::handleRequest(Request* requestObj) cb_json.set(NULL, CONV_JSON_DESCRIPTION, requestObj->getDescription()); cb_json.set(NULL, CONV_JSON_PAYLOAD, tmp_payload); if (cur_Req != NULL) { - cur_Req->publish(CONV_ERROR_NONE, cb_json); + cur_Req->publish(CONV_ERROR_NONE, cb_json, 0, NULL); } error = CONV_ERROR_NONE; } diff --git a/daemon/DbusServer.cpp b/daemon/DbusServer.cpp index ed17273..1963e67 100755 --- a/daemon/DbusServer.cpp +++ b/daemon/DbusServer.cpp @@ -40,6 +40,8 @@ static const gchar introspectionXml[] = " " " " " " + " " + " " " " " " " " @@ -72,12 +74,16 @@ static void __handle_request(GDBusConnection* conn, const char *sender, GVariant gint req_id = 0; const gchar *subject = NULL; const gchar *input = NULL; + gint length = 0; + GVariant *binaryArray = NULL; - g_variant_get(param, "(ii&s&s)", &req_type, &req_id, &subject, &input); + g_variant_get(param, "(ii&s&si@a(y))", &req_type, &req_id, &subject, &input, &length, &binaryArray); IF_FAIL_VOID_TAG(req_type > 0 && req_id > 0 && subject && input, _E, "Invalid request"); + const unsigned char *binary = (const unsigned char*)g_variant_get_data(binaryArray); _I("[%s] ReqId: %d, Subject: %s", __req_type_to_str(req_type), req_id, subject); _SI("Input: %s", input); + _I("binary length:%d", length); conv::Credentials *creds = NULL; @@ -86,10 +92,9 @@ static void __handle_request(GDBusConnection* conn, const char *sender, GVariant g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", CONV_ERROR_INVALID_OPERATION)); return; } - conv::Request *recvRequest = NULL; try{ - recvRequest = new conv::Request(req_type, DEFAULT_APP_ID, req_id, subject, input, sender, creds, invocation); + recvRequest = new conv::Request(req_type, DEFAULT_APP_ID, req_id, subject, input, sender, creds, invocation, length, binary); } catch (std::bad_alloc& ba) { _E("Memory Allocation Failed.."); g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", CONV_ERROR_INVALID_OPERATION)); @@ -108,7 +113,6 @@ static void __handle_request(GDBusConnection* conn, const char *sender, GVariant delete creds; return; } - conv::sendRequest(recvRequest); } @@ -221,13 +225,15 @@ void conv::DbusServer::release() } } -void conv::DbusServer::publish(const char* dest, int reqId, const char* subject, int error, const char* data) +void conv::DbusServer::publish(const char* dest, int reqId, const char* subject, int error, const char* data, int binaryLength, const unsigned char* binary) { IF_FAIL_VOID_TAG(dest && subject && data, _E, "Parameter null"); - _SI("Publish: %s, %d, %s, %#x, %s", dest, reqId, subject, error, data); + _SI("Publish: %s, %d, %s, %#x, %s, %d", dest, reqId, subject, error, data, binaryLength); + + GVariant *binaryVariant = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"), binary, binaryLength, true, NULL, NULL); - GVariant *param = g_variant_new("(isis)", reqId, subject, error, data); + GVariant *param = g_variant_new("(isisi@a(y))", reqId, subject, error, data, binaryLength, binaryVariant); IF_FAIL_VOID_TAG(param, _E, "Memory allocation failed"); _D("before g_dbusConnection_call.."); @@ -264,9 +270,9 @@ void conv::DbusServer::call(const char *dest, const char *obj, const char *iface G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, __handle_call_result, &callCount); } -void conv::dbus_server::publish(const char* dest, int reqId, const char* subject, int error, const char* data) +void conv::dbus_server::publish(const char* dest, int reqId, const char* subject, int error, const char* data, int binaryLength, const unsigned char* binary) { - __instance->publish(dest, reqId, subject, error, data); + __instance->publish(dest, reqId, subject, error, data, binaryLength, binary); } void conv::dbus_server::call(const char *dest, const char *obj, const char *iface, const char *method, GVariant *param) diff --git a/daemon/DbusServer.h b/daemon/DbusServer.h index f710084..beef303 100644 --- a/daemon/DbusServer.h +++ b/daemon/DbusServer.h @@ -30,12 +30,12 @@ namespace conv { bool init(); void release(); - void publish(const char *dest, int req_id, const char *subject, int error, const char *data); + void publish(const char *dest, int req_id, const char *subject, int error, const char *data, int binaryLength, const unsigned char* binary); void call(const char *dest, const char *obj, const char *iface, const char *method, GVariant *param); }; /* class conv::dbus_server */ namespace dbus_server { - void publish(const char *dest, int req_id, const char *subject, int error, const char *data); + void publish(const char *dest, int req_id, const char *subject, int error, const char *data, int binaryLength, const unsigned char* binary); void call(const char *dest, const char *obj, const char *iface, const char *method, GVariant *param); void setInstance(IDbusServer* svr); } diff --git a/daemon/DiscoveryManager.cpp b/daemon/DiscoveryManager.cpp index 54c202f..f6e5a86 100755 --- a/daemon/DiscoveryManager.cpp +++ b/daemon/DiscoveryManager.cpp @@ -94,7 +94,7 @@ int conv::DiscoveryManager::notifyTimeOut(std::string client) if (requestIter != __requestMap.end()) { Json noData; Request* currentRequest = requestIter->second; - currentRequest->publish(CONV_DISCOVERY_FINISHED, noData); + currentRequest->publish(CONV_DISCOVERY_FINISHED, noData, 0, NULL); __requestMap.erase(requestIter); } @@ -361,7 +361,7 @@ int conv::DiscoveryManager::notifyLostDevice(IDevice* discoveredDevice) convertDeviceIntoJson(discoveredDevice, &deviceJson); for (IterPos = __requestMap.begin(); IterPos != __requestMap.end(); ++IterPos) { Request* currentRequest = IterPos->second; - currentRequest->publish(CONV_DISCOVERY_DEVICE_LOST, deviceJson); + currentRequest->publish(CONV_DISCOVERY_DEVICE_LOST, deviceJson, 0, NULL); } } @@ -416,7 +416,7 @@ int conv::DiscoveryManager::appendDiscoveredResult(conv::IDevice* discoveredDevi RequestMap::iterator IterPos; for (IterPos = __requestMap.begin(); IterPos != __requestMap.end(); ++IterPos) { Request* currentRequest = IterPos->second; - currentRequest->publish(CONV_ERROR_NONE, deviceJson); + currentRequest->publish(CONV_ERROR_NONE, deviceJson, 0, NULL); index++; } diff --git a/daemon/Json.cpp b/daemon/Json.cpp index 1a299cf..abc0089 100755 --- a/daemon/Json.cpp +++ b/daemon/Json.cpp @@ -934,3 +934,19 @@ bool conv::Json::arrayEquals(json_node_t* lhs, json_node_t* rhs) return true; } + +std::string conv::Json::serializedStr() +{ + std::string jsonStr = str(); + std::string from = "\""; + std::string to = "\\\""; + unsigned int startIndex = 0; + startIndex = jsonStr.find(from, startIndex); + while (startIndex != std::string::npos) { + jsonStr.replace(startIndex, from.length(), to); + startIndex += to.length(); + startIndex = jsonStr.find(from, startIndex); + } + return jsonStr; +} + diff --git a/daemon/Json.h b/daemon/Json.h index fcbd0a6..2ef2d6d 100644 --- a/daemon/Json.h +++ b/daemon/Json.h @@ -76,6 +76,7 @@ namespace conv { char* dupCstr(); std::string str(); + std::string serializedStr(); bool getKeys(std::list* list); diff --git a/daemon/Request.cpp b/daemon/Request.cpp index 8776575..a089dc0 100755 --- a/daemon/Request.cpp +++ b/daemon/Request.cpp @@ -19,6 +19,22 @@ #include "Request.h" #include "DbusServer.h" +conv::Request::Request(int type, const char *client, int reqId, const char *subj, const char *desc, + const char *sender, Credentials *creds, GDBusMethodInvocation *inv, + int binaryLength, const unsigned char* binary) + : __type(type) + , __reqId(reqId) + , __client(client) + , __subject(subj) + , __description(desc) + , __creds(creds) + , __sender(sender) + , __invocation(inv) + , __binaryLength(binaryLength) + , __binary(binary) +{ +} + conv::Request::Request(int type, const char* client, int reqId, const char* subj, const char* desc) : __type(type) , __reqId(reqId) @@ -59,6 +75,16 @@ int conv::Request::getId() return __reqId; } +int conv::Request::getBinaryLength() +{ + return __binaryLength; +} + +const unsigned char* conv::Request::getBinary() +{ + return __binary; +} + const char* conv::Request::getClient() { return __client.c_str(); @@ -96,7 +122,7 @@ bool conv::Request::reply(int error) return true; } -bool conv::Request::publish(int error, conv::Json& data) +bool conv::Request::publish(int error, conv::Json& data, int binaryLength, const unsigned char* binary) { char *dataStr = data.dupCstr(); IF_FAIL_RETURN_TAG(dataStr, false, _E, "Memory allocation failed"); @@ -106,11 +132,10 @@ bool conv::Request::publish(int error, conv::Json& data) _D("info : subject %s", __subject.c_str()); _D("info : error %d", error); _D("info : data %s", dataStr); + _D("info : binary length %d", binaryLength); _D("info : description %s", __description.str().c_str()); - _D("publish info : sender[%s] reqId[%d] subject[%s] error[%d] data[%s]" - , __sender.c_str(), __reqId, __subject.c_str(), error, dataStr); - conv::dbus_server::publish(__sender.c_str(), __reqId, __subject.c_str(), error, dataStr); + conv::dbus_server::publish(__sender.c_str(), __reqId, __subject.c_str(), error, dataStr, binaryLength, binary); g_free(dataStr); return true; diff --git a/daemon/Request.h b/daemon/Request.h index b3c0e99..0072310 100644 --- a/daemon/Request.h +++ b/daemon/Request.h @@ -30,19 +30,24 @@ namespace conv { public: Request(int type, const char *client, int reqId, const char *subj, const char *desc); Request(int type, - const char *client, int reqId, const char *subj, const char *desc, - const char *sender, Credentials *creds, GDBusMethodInvocation *inv); + const char *client, int reqId, const char *subj, const char *desc, + const char *sender, Credentials *creds, GDBusMethodInvocation *inv); + Request(int type, const char *client, int reqId, const char *subj, const char *desc, + const char *sender, Credentials *creds, GDBusMethodInvocation *inv, + int binaryLength, const unsigned char* binary); ~Request(); int getType(); int getId(); + int getBinaryLength(); const char *getClient(); const char *getSender(); const char *getSubject(); + const unsigned char *getBinary(); Json& getDescription(); Credentials *getCreds(); bool reply(int error); - bool publish(int error, Json &data); + bool publish(int error, Json &data, int binaryLength, const unsigned char* binary); bool getChannelFromDescription(Json* target); bool getPayloadFromDescription(Json* target); @@ -64,6 +69,8 @@ namespace conv { IServiceInfo* __serviceInfo; ICommunicationInfo* __communicationInfo; + int __binaryLength; + const unsigned char* __binary; }; } diff --git a/daemon/access_control/ACLManager.cpp b/daemon/access_control/ACLManager.cpp index 4fb7395..326e2e9 100644 --- a/daemon/access_control/ACLManager.cpp +++ b/daemon/access_control/ACLManager.cpp @@ -535,7 +535,7 @@ static void GetACLDeviceList(conv::Request *requestObj) result_data.set(NULL, CONV_JSON_DEVICE_TYPE, deviceType); result_data.set(NULL, CONV_JSON_DEVICE_NAME, deviceName); result_data.set(NULL, CONV_JSON_ACCESS_CONTROL_STATE, aclState); - requestObj->publish(CONV_ERROR_NONE, result_data); + requestObj->publish(CONV_ERROR_NONE, result_data, 0, NULL); } ret = database_finalize(database, stmt); diff --git a/daemon/discovery_provider/WifiDirectDiscoveryProvider.cpp b/daemon/discovery_provider/WifiDirectDiscoveryProvider.cpp index 4d4e704..75b6b51 100755 --- a/daemon/discovery_provider/WifiDirectDiscoveryProvider.cpp +++ b/daemon/discovery_provider/WifiDirectDiscoveryProvider.cpp @@ -18,7 +18,7 @@ #include "../DiscoveryManager.h" #include -#include +//#include #define TEMP_TEST @@ -34,7 +34,7 @@ conv::WifiDirectDiscoveryProvider::WifiDirectDiscoveryProvider() conv::WifiDirectDiscoveryProvider::~WifiDirectDiscoveryProvider() { } - +#if 0 void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data) { switch (device_state) { @@ -303,6 +303,8 @@ int start_wfd_discovery(void) return result; } +#endif + int conv::WifiDirectDiscoveryProvider::init() { //init_wfd_client((void*)this); diff --git a/daemon/service_provider/AppCommServiceApplication.cpp b/daemon/service_provider/AppCommServiceApplication.cpp index ab601cd..83c30a0 100755 --- a/daemon/service_provider/AppCommServiceApplication.cpp +++ b/daemon/service_provider/AppCommServiceApplication.cpp @@ -58,9 +58,9 @@ void conv::AppCommServiceApplication::onStart(bool start_result) result.set(NULL, CONV_JSON_DESCRIPTION, description); result.set(NULL, CONV_JSON_PAYLOAD, payload); if (start_result) - (*requestObj)->publish(CONV_ERROR_NONE, result); + (*requestObj)->publish(CONV_ERROR_NONE, result, 0, NULL); else - (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result); + (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result, 0, NULL); } } @@ -96,9 +96,9 @@ void conv::AppCommServiceApplication::onStop(bool stop_result) result.set(NULL, CONV_JSON_DESCRIPTION, description); result.set(NULL, CONV_JSON_PAYLOAD, payload); if (stop_result) - (*requestObj)->publish(CONV_ERROR_NONE, result); + (*requestObj)->publish(CONV_ERROR_NONE, result, 0, NULL); else - (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result); + (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result, 0, NULL); } } @@ -142,24 +142,18 @@ void conv::AppCommServiceApplication::onMessage(Message message) if ((*requestObj) != NULL) { _D(RED("publishing_response")); Json result; - Json message_json; Json description; _D("size %d", message.m_payload_size); - _D("payload %s", message.m_payload); - - message_json.set(NULL, CONV_JSON_EVENT, message.m_event); - message_json.set(NULL, CONV_JSON_DATA, message.m_data); - message_json.set(NULL, CONV_JSON_FROM, message.m_from); - string payload_str(reinterpret_cast(message.m_payload), message.m_payload_size); + string payload_str(message.m_data); Json payload = payload_str; + payload.set(NULL, CONV_JSON_DATA, message.m_data); payload.set(NULL, CONV_JSON_PAYLOAD_SIZE, message.m_payload_size); payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_MESSAGE); -// payload.set(NULL, CONV_JSON_MESSAGE, message_json); - payload.set(NULL, CONV_JSON_MESSAGE, message_json.dupCstr()); payload.set(NULL, CONV_JSON_FROM, message.m_from); + payload.set(NULL, CONV_JSON_EVENT, message.m_event); description = (*requestObj)->getDescription(); @@ -170,7 +164,7 @@ void conv::AppCommServiceApplication::onMessage(Message message) result.set(NULL, CONV_JSON_PAYLOAD, payload); _D("size of msg:%d", result.str().length()); - (*requestObj)->publish(CONV_ERROR_NONE, result); + (*requestObj)->publish(CONV_ERROR_NONE, result, message.m_payload_size, message.m_payload); _D("publishing done"); } } @@ -196,7 +190,7 @@ void conv::AppCommServiceApplication::onError(Error error) result.set(NULL, CONV_JSON_DESCRIPTION, description); result.set(NULL, CONV_JSON_PAYLOAD, payload); - (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result); + (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result, 0, NULL); } } @@ -220,9 +214,9 @@ void conv::AppCommServiceApplication::onPublished(bool publish_result, void* use result.set(NULL, CONV_JSON_DESCRIPTION, description); result.set(NULL, CONV_JSON_PAYLOAD, payload); if (publish_result) - (*requestObj)->publish(CONV_ERROR_NONE, result); + (*requestObj)->publish(CONV_ERROR_NONE, result, 0, NULL); else - (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result); + (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result, 0, NULL); } } @@ -249,6 +243,6 @@ void conv::AppCommServiceApplication::publishResponse(int error, string result_t result.set(NULL, CONV_JSON_DESCRIPTION, description); result.set(NULL, CONV_JSON_PAYLOAD, payload); - (*requestObj)->publish(error, result); + (*requestObj)->publish(error, result, 0, NULL); } } diff --git a/daemon/service_provider/AppCommServiceProvider.cpp b/daemon/service_provider/AppCommServiceProvider.cpp index c3bd805..70eb333 100755 --- a/daemon/service_provider/AppCommServiceProvider.cpp +++ b/daemon/service_provider/AppCommServiceProvider.cpp @@ -367,7 +367,11 @@ int conv::AppCommServiceProvider::readRequest(Request* requestObj) client.set(NULL, CONV_JSON_CHANNEL_URI, cha->getChannelUri(NULL).c_str()); // result.appendArray(NULL, CONV_JSON_CLIENT_LIST, client); - result.set(NULL, CONV_JSON_CLIENT_LIST, client.dupCstr()); + char* client_char = client.dupCstr(); + result.set(NULL, CONV_JSON_CLIENT_LIST, client_char); + if (client_char != NULL) { + g_free(client_char); + } } sendReadResponse(result, CONV_JSON_GET_CLIENTS, CONV_ERROR_NONE, svcInfo->registeredRequest); @@ -395,7 +399,7 @@ int conv::AppCommServiceProvider::sendReadResponse(Json payload, const char* rea result.set(NULL, CONV_JSON_DESCRIPTION, description); result.set(NULL, CONV_JSON_PAYLOAD, payload); - requestObj->publish(error, result); + requestObj->publish(error, result, 0, NULL); return CONV_ERROR_NONE; } @@ -426,19 +430,9 @@ int conv::AppCommServiceProvider::publishRequest(Request* requestObj) requestObj->getPayloadFromDescription(&payload); - char* message = new(std::nothrow) char[strlen(payload.str().c_str())+1]; - ASSERT_ALLOC(message); - - strncpy(message, payload.str().c_str(), strlen(payload.str().c_str())+1); - - string payload_str = payload.str(); - _D("payload : %s, size : %d", message, strlen(message)); - - (*iter)->application->publish("d2d_service_message", NULL, reinterpret_cast(message), strlen(message), NULL); + (*iter)->application->publish("d2d_service_message", payload.serializedStr().c_str(), requestObj->getBinary(), requestObj->getBinaryLength(), NULL); _D("publishing done"); - - delete[] message; return CONV_ERROR_NONE; } } diff --git a/daemon/service_provider/RemoteAppControlServiceProvider.cpp b/daemon/service_provider/RemoteAppControlServiceProvider.cpp index 5176684..10c1f8e 100755 --- a/daemon/service_provider/RemoteAppControlServiceProvider.cpp +++ b/daemon/service_provider/RemoteAppControlServiceProvider.cpp @@ -161,7 +161,7 @@ static int sendResponse(conv::Json payload, const char* request_type, conv_error result.set(NULL, CONV_JSON_DESCRIPTION, description); result.set(NULL, CONV_JSON_PAYLOAD, payload); - requestObj->publish(error, result); + requestObj->publish(error, result, 0, NULL); return CONV_ERROR_NONE; } @@ -848,7 +848,7 @@ static void __on_response(iotcon_remote_resource_h resource, iotcon_error_e err, result.set(NULL, CONV_JSON_DESCRIPTION, cb_info.requestObj->getDescription()); result.set(NULL, CONV_JSON_PAYLOAD, payload); - cb_info.requestObj->publish(CONV_ERROR_NONE, result); + cb_info.requestObj->publish(CONV_ERROR_NONE, result, 0, NULL); _D("response published"); } } diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4edc698..fd6176b 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -19,7 +19,7 @@ pkg_check_modules(client_pkgs REQUIRED ${client_depends}) INCLUDE_DIRECTORIES(${client_pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${client_pkgs_LIBRARY_DIRS}) -ADD_DEFINITIONS("-DBROKER_DBUS_INTERFACE=\"${DBUS_INTERFACE}\"") +ADD_DEFINITIONS("-DCONV_DBUS_INTERFACE=\"${DBUS_INTERFACE}\"") ADD_LIBRARY(${CLIENT} SHARED ${CLIENT_SRCS}) TARGET_LINK_LIBRARIES(${CLIENT} ${client_pkgs_LIBRARIES}) diff --git a/lib/conv_lib.cpp b/lib/conv_lib.cpp index 2aac300..7f76bf5 100755 --- a/lib/conv_lib.cpp +++ b/lib/conv_lib.cpp @@ -41,7 +41,7 @@ typedef std::map callback_map_t; static callback_map_t callback_map; //LCOV_EXCL_START -static void conv_subject_cb(const char* subject, int req_id, int error, json data) +static void conv_subject_cb(const char* subject, int req_id, int error, json data, int binary_length, const unsigned char* binary) { _D("Callback response %d : subject[%s] json_data[%s]", req_id, subject, data.str().c_str()); @@ -118,7 +118,7 @@ EXTAPI int conv_discovery_start(conv_h handle, const int timeout_seconds, conv_d int req_id; const char* input = const_cast (input_data.str().c_str()); _D("input:%s", input); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_DISCOVERY_START, input_data.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_DISCOVERY_START, input_data.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service"); callback_map[req_id] = cb_info; @@ -134,7 +134,7 @@ EXTAPI int conv_discovery_stop(conv_h handle) ASSERT_NOT_NULL(handle); int req_id; - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_DISCOVERY_STOP, NULL); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_DISCOVERY_STOP, NULL, 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service"); return CONV_ERROR_NONE; diff --git a/lib/conv_lib_acl.cpp b/lib/conv_lib_acl.cpp index 6c26a8b..d0d9353 100644 --- a/lib/conv_lib_acl.cpp +++ b/lib/conv_lib_acl.cpp @@ -33,7 +33,7 @@ EXTAPI int conv_internal_regist_acl_device(char *mac_address, char *device_type, const char* input = const_cast (input_data.str().c_str()); _D("input:%s", input); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_REGIST, input_data.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_REGIST, input_data.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in conv_internal_regist_acl_device()"); return CONV_ERROR_NONE; @@ -51,7 +51,7 @@ EXTAPI int conv_internal_set_acl_state(char *mac_address, char *device_type, cha const char* input = const_cast (input_data.str().c_str()); _D("input:%s", input); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_SET, input_data.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_SET, input_data.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in conv_internal_set_acl_state()"); return CONV_ERROR_NONE; @@ -66,7 +66,7 @@ EXTAPI int conv_internal_remove_acl_device(char *mac_address) const char* input = const_cast (input_data.str().c_str()); _D("input:%s", input); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_REMOVE, input_data.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_REMOVE, input_data.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in conv_internal_remove_acl_device())"); return CONV_ERROR_NONE; @@ -80,7 +80,7 @@ struct access_control_callback_info_s { typedef std::map callback_map_t; static callback_map_t callback_map; -static void conv_subject_cb(const char *subject, int req_id, int error, json data) +static void conv_subject_cb(const char *subject, int req_id, int error, json data, int binary_length, const unsigned char* binary) { std::string mac_address; std::string device_type; @@ -117,10 +117,10 @@ EXTAPI int conv_internal_get_acl_list(conv_access_control_list_foreach_cb callba cb_info->user_data = user_data; int req_id; - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_GET, NULL); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_ACCESS_CONTROL_GET, NULL, 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in conv_internal_get_acl_list()"); callback_map[req_id] = cb_info; return CONV_ERROR_NONE; -} \ No newline at end of file +} diff --git a/lib/conv_lib_payload.cpp b/lib/conv_lib_payload.cpp index f9ece34..6f7d133 100755 --- a/lib/conv_lib_payload.cpp +++ b/lib/conv_lib_payload.cpp @@ -42,6 +42,9 @@ EXTAPI int conv_payload_create(conv_payload_h* handle) *handle = new(std::nothrow) _conv_payload_handle(); ASSERT_ALLOC(*handle); + (*handle)->binary = NULL; + (*handle)->binary_length = 0; + return CONV_ERROR_NONE; } @@ -49,6 +52,7 @@ EXTAPI int conv_payload_destroy(conv_payload_h handle) { IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported"); ASSERT_NOT_NULL(handle); + delete handle; return CONV_ERROR_NONE; @@ -195,5 +199,31 @@ EXTAPI int conv_payload_internal_export_to_string(conv_payload_h handle, char** return CONV_ERROR_NONE; } + +EXTAPI int conv_payload_set_binary(conv_payload_h handle, int length, const unsigned char* value) +{ + IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported"); + ASSERT_NOT_NULL(handle); + ASSERT_NOT_NULL(value); + + handle->binary_length = length; + handle->binary = value; + + return CONV_ERROR_NONE; +} + +EXTAPI int conv_payload_get_binary(conv_payload_h handle, int* length, const unsigned char** value) +{ + IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported"); + ASSERT_NOT_NULL(handle); + ASSERT_NOT_NULL(value); + + IF_FAIL_RETURN_TAG(handle->binary_length > 0, CONV_ERROR_NO_DATA, _E, "No data"); + + *value = handle->binary; + *length = handle->binary_length; + + return CONV_ERROR_NONE; +} //LCOV_EXCL_STOP diff --git a/lib/conv_lib_service.cpp b/lib/conv_lib_service.cpp index 9b59aff..6a3d55f 100755 --- a/lib/conv_lib_service.cpp +++ b/lib/conv_lib_service.cpp @@ -37,7 +37,7 @@ std::string convert_type_to_string(conv_service_e service_type); conv_service_e convert_string_to_type(std::string type_name); //LCOV_EXCL_START -static void conv_subject_cb(const char* subject, int req_id, int error, json data) +static void conv_subject_cb(const char* subject, int req_id, int error, json data, int binary_length, const unsigned char* binary) { _D("Callback response %d", req_id); @@ -92,15 +92,18 @@ static void conv_subject_cb(const char* subject, int req_id, int error, json dat IF_FAIL_VOID_TAG(payload_handle, _E, "Memory allocation failed"); payload_handle->jpayload = payload; + payload_handle->binary_length = binary_length; + payload_handle->binary = binary; + conv_error_e conv_error = (conv_error_e)error; - callback_info->cb(service_handle, channel_handle, CONV_ERROR_NONE, payload_handle, callback_info->user_data); + callback_info->cb(service_handle, channel_handle, conv_error, payload_handle, callback_info->user_data); delete payload_handle; delete channel_handle; delete service_handle; } -static void conv_connect_subject_cb(const char* subject, int req_id, int error, json data) +static void conv_connect_subject_cb(const char* subject, int req_id, int error, json data, int binary_length, const unsigned char* binary) { _D("Callback response %d", req_id); @@ -237,7 +240,7 @@ EXTAPI int conv_service_set_listener_cb(conv_service_h handle, conv_service_list int req_id; - int err = conv::dbus_client::request(REQ_SUBSCRIBE, &req_id, CONV_SUBJECT_COMMUNICATION_RECV, description.str().c_str()); + int err = conv::dbus_client::request(REQ_SUBSCRIBE, &req_id, CONV_SUBJECT_COMMUNICATION_RECV, description.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Getting list failed"); return CONV_ERROR_NONE; @@ -263,7 +266,7 @@ EXTAPI int conv_service_unset_listener_cb(conv_service_h handle) description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local); int req_id; - int err = conv::dbus_client::request(REQ_UNSUBSCRIBE, &req_id, CONV_SUBJECT_COMMUNICATION_RECV, description.str().c_str()); + int err = conv::dbus_client::request(REQ_UNSUBSCRIBE, &req_id, CONV_SUBJECT_COMMUNICATION_RECV, description.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Unset observe failed"); std::map::iterator it = callback_map.find(description.str()); @@ -291,12 +294,17 @@ EXTAPI int conv_service_start(conv_service_h handle, conv_channel_h channel_hand json description; json channel; json payload; + int binary_length = 0; + const unsigned char* binary = NULL; - if ( channel_handle != NULL ) + if (channel_handle != NULL) channel = channel_handle->jchannel; - if ( payload_handle != NULL) + if (payload_handle != NULL) { payload = payload_handle->jpayload; + binary_length = payload_handle->binary_length; + binary = payload_handle->binary; + } json service = handle->jservice; json device = handle->jdevice; @@ -311,7 +319,7 @@ EXTAPI int conv_service_start(conv_service_h handle, conv_channel_h channel_hand description.set(NULL, CONV_JSON_TYPE, type); description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_START, description.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_START, description.str().c_str(), binary_length, binary); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service"); return CONV_ERROR_NONE; @@ -328,14 +336,18 @@ EXTAPI int conv_service_read(conv_service_h handle, conv_channel_h channel_handl json description; json channel; + json payload; + int binary_length = 0; + const unsigned char* binary = NULL; - if ( channel_handle != NULL ) + if (channel_handle != NULL) channel = channel_handle->jchannel; - json payload; - - if ( payload_handle != NULL) + if (payload_handle != NULL) { payload = payload_handle->jpayload; + binary_length = payload_handle->binary_length; + binary = payload_handle->binary; + } json service = handle->jservice; json device = handle->jdevice; @@ -350,7 +362,7 @@ EXTAPI int conv_service_read(conv_service_h handle, conv_channel_h channel_handl description.set(NULL, CONV_JSON_TYPE, type); description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_GET, description.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_GET, description.str().c_str(), binary_length, binary); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service"); return CONV_ERROR_NONE; @@ -368,12 +380,17 @@ EXTAPI int conv_service_stop(conv_service_h handle, conv_channel_h channel_handl json description; json channel; json payload; + int binary_length = 0; + const unsigned char* binary = NULL; - if ( channel_handle != NULL ) + if (channel_handle != NULL) channel = channel_handle->jchannel; - if (payload_handle != NULL) + if (payload_handle != NULL) { payload = payload_handle->jpayload; + binary_length = payload_handle->binary_length; + binary = payload_handle->binary; + } json service = handle->jservice; json device = handle->jdevice; @@ -388,7 +405,7 @@ EXTAPI int conv_service_stop(conv_service_h handle, conv_channel_h channel_handl description.set(NULL, CONV_JSON_TYPE, type); description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_STOP, description.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_STOP, description.str().c_str(), binary_length, binary); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service"); return CONV_ERROR_NONE; @@ -406,12 +423,17 @@ EXTAPI int conv_service_publish(conv_service_h handle, conv_channel_h channel_ha json description; json channel; json payload; + int binary_length = 0; + const unsigned char* binary = NULL; if (channel_handle != NULL) channel = channel_handle->jchannel; - if (payload_handle != NULL) + if (payload_handle != NULL) { payload = payload_handle->jpayload; + binary_length = payload_handle->binary_length; + binary = payload_handle->binary; + } json service = handle->jservice; json device = handle->jdevice; @@ -427,7 +449,7 @@ EXTAPI int conv_service_publish(conv_service_h handle, conv_channel_h channel_ha description.set(NULL, CONV_JSON_TYPE, type); description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_SET, description.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_SET, description.str().c_str(), binary_length, binary); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service"); return CONV_ERROR_NONE; @@ -454,7 +476,7 @@ static int conv_service_set_connected_cb(conv_service_h handle, json description int req_id; - int err = conv::dbus_client::request(REQ_SUBSCRIBE, &req_id, CONV_SUBJECT_CONNECTION_START, description.str().c_str()); + int err = conv::dbus_client::request(REQ_SUBSCRIBE, &req_id, CONV_SUBJECT_CONNECTION_START, description.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Getting list failed"); return CONV_ERROR_NONE; @@ -476,7 +498,7 @@ static int conv_service_unset_connected_cb(conv_service_h handle) description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local); int req_id; - int err = conv::dbus_client::request(REQ_UNSUBSCRIBE, &req_id, CONV_SUBJECT_CONNECTION_START, NULL); + int err = conv::dbus_client::request(REQ_UNSUBSCRIBE, &req_id, CONV_SUBJECT_CONNECTION_START, NULL, 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Unset observe failed"); std::map::iterator it = connect_callback_map.find(description.str()); @@ -536,7 +558,7 @@ EXTAPI int conv_service_connect(conv_service_h handle, conv_service_connected_cb conv_service_set_connected_cb(handle, description, callback, user_data); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_CONNECTION_START, description.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_CONNECTION_START, description.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service"); return CONV_ERROR_NONE; @@ -565,7 +587,7 @@ EXTAPI int conv_service_disconnect(conv_service_h handle) description.set(NULL, CONV_JSON_DEVICE, device); description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local); - int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_CONNECTION_STOP, description.str().c_str()); + int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_CONNECTION_STOP, description.str().c_str(), 0, NULL); IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service"); return CONV_ERROR_NONE; diff --git a/lib/dbus_client.cpp b/lib/dbus_client.cpp index 65218ff..858a462 100755 --- a/lib/dbus_client.cpp +++ b/lib/dbus_client.cpp @@ -35,6 +35,8 @@ static const gchar introspection_xml[] = " " " " " " + " " + " " " " " " ""; @@ -57,13 +59,16 @@ static void handle_response(const gchar *sender, GVariant *param, GDBusMethodInv const gchar *subject = NULL; gint error = 0; const gchar *data = NULL; + gint length = 0; + GVariant *binary_array = NULL; - g_variant_get(param, "(i&si&s)", &req_id, &subject, &error, &data); + g_variant_get(param, "(i&si&si@a(y))", &req_id, &subject, &error, &data, &length, &binary_array); _D("[Response] ReqId: %d, Subject: %s, Error: %d", req_id, subject, error); + const unsigned char *binary = (const unsigned char*)g_variant_get_data(binary_array); response_cb_map_t::iterator it = response_cb_map->find(subject); IF_FAIL_VOID_TAG(it!= response_cb_map->end(), _E, "Unknown subject'%s'", subject); - it->second(subject, req_id, error, data); + it->second(subject, req_id, error, data, length, binary); g_dbus_method_invocation_return_value(invocation, NULL); } @@ -144,7 +149,7 @@ void conv::dbus_client::release() } int conv::dbus_client::request( - int type, int* req_id, const char* subject, const char* input) + int type, int* req_id, const char* subject, const char* input, const int binary_length, const unsigned char* binary) { _D("Requesting: %d, %s", type, subject); IF_FAIL_RETURN_TAG(init(), CONV_ERROR_INVALID_OPERATION, _E, "Connection failed"); @@ -159,11 +164,13 @@ int conv::dbus_client::request( } *req_id = get_req_id(); - // second param is security cookie which is deprecated in 3.0 - GVariant *param = g_variant_new("(iiss)", type, *req_id, subject, input); + GVariant *binary_variant = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"), binary, binary_length, true, NULL, NULL); + + GVariant *param = g_variant_new("(iissi@a(y))", type, *req_id, subject, input, binary_length, binary_variant); IF_FAIL_RETURN_TAG(param, CONV_ERROR_OUT_OF_MEMORY, _E, "Memory allocation failed"); GError *err = NULL; + _D("call start"); GVariant *response = g_dbus_connection_call_sync(dbus_connection, DBUS_DEST, DBUS_PATH, DBUS_IFACE, METHOD_REQUEST, param, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, &err); @@ -181,7 +188,7 @@ int conv::dbus_client::request( //LCOV_EXCL_START int conv::dbus_client::request_with_no_reply( - int type, int* req_id, const char* subject, const char* input) + int type, int* req_id, const char* subject, const char* input, const int binary_length, const unsigned char* binary) { _D("Requesting: %d, %d, %s", type, req_id, subject); IF_FAIL_RETURN_TAG(init(), CONV_ERROR_INVALID_OPERATION, _E, "Connection failed"); @@ -197,8 +204,9 @@ int conv::dbus_client::request_with_no_reply( *req_id = get_req_id(); - // second param is security cookie which is deprecated in 3.0 - GVariant *param = g_variant_new("(iiss)", type, req_id, subject, input); + GVariant *binary_variant = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"), binary, binary_length, true, NULL, NULL); + + GVariant *param = g_variant_new("(iissi@a(y))", type, *req_id, subject, input, binary_length, binary_variant); IF_FAIL_RETURN_TAG(param, CONV_ERROR_OUT_OF_MEMORY, _E, "Memory allocation failed"); GError *err = NULL; diff --git a/lib/dbus_client.h b/lib/dbus_client.h index 2aa2a83..8f512d6 100644 --- a/lib/dbus_client.h +++ b/lib/dbus_client.h @@ -19,7 +19,7 @@ #include -typedef void(* subject_response_cb)(const char* subject, int req_id, int error, json response); +typedef void(* subject_response_cb)(const char* subject, int req_id, int error, json response, int binary_length, const unsigned char* binary); namespace conv { @@ -27,8 +27,8 @@ namespace conv { bool init(); void release(); - int request(int type, int* req_id, const char* subject, const char* input); - int request_with_no_reply(int type, int* req_id, const char* subject, const char* input); + int request(int type, int* req_id, const char* subject, const char* input, const int binary_length, const unsigned char* binary); + int request_with_no_reply(int type, int* req_id, const char* subject, const char* input, const int binary_length, const unsigned char* binary); int register_callback(const char* subject, subject_response_cb callback); int call(const char* subject); } diff --git a/lib/include/d2d_conv_internal.h b/lib/include/d2d_conv_internal.h index 4c60093..7758179 100755 --- a/lib/include/d2d_conv_internal.h +++ b/lib/include/d2d_conv_internal.h @@ -234,6 +234,42 @@ typedef void(* conv_access_control_list_foreach_cb)(char *mac_address, char *dev */ int conv_internal_get_acl_list(conv_access_control_list_foreach_cb callback, void *user_data); +/** + * @brief Sets binary to payload. + * @since_tizen 3.0 + * + * @param[in] handle The payload handle + * @param[in] length The length of binary to set + * @param[in] value The binary to set + * + * @return 0 on success, otherwise a negative error value + * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONV_ERROR_NOT_SUPPORTED Not supported + * + * @see conv_payload_get_binary() + */ +int conv_payload_set_binary(conv_payload_h handle, int length, const unsigned char* value); + +/** + * @brief Gets binary from payload. + * @since_tizen 3.0 + * @remarks The @a value must be released using free(). + * + * @param[in] handle The payload handle + * @param[out] length The length of binary + * @param[out] value The result value + * + * @return 0 on success, otherwise a negative error value + * @retval #CONV_ERROR_NONE Successful + * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONV_ERROR_NOT_SUPPORTED Not supported + * @retval #CONV_ERROR_NO_DATA No Data + * + * @see conv_payload_set_binary() + */ +int conv_payload_get_binary(conv_payload_h handle, int* length, const unsigned char** value); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/lib/internal_types.h b/lib/internal_types.h index 16fce04..43d17dc 100755 --- a/lib/internal_types.h +++ b/lib/internal_types.h @@ -47,6 +47,8 @@ typedef struct _conv_channel_handle_s { typedef struct _conv_payload_handle_s { json jpayload; + const unsigned char* binary; + int binary_length; } _conv_payload_handle; typedef struct _conv_service_handle_s { diff --git a/msf_tizen_client/include/Channel.h b/msf_tizen_client/include/Channel.h index 9f4df29..6503f61 100755 --- a/msf_tizen_client/include/Channel.h +++ b/msf_tizen_client/include/Channel.h @@ -154,21 +154,21 @@ public: void setonPublishListener(OnPublishListener *); void unsetonPublishListener(); void publish(string event, const char *data, void *user_data); - void publish(string event, const char *data, unsigned char payload[], + void publish(string event, const char *data, const unsigned char payload[], int payload_size, void *user_data); void publish(string event, const char *data, const char *target, void *user_data); void publish(string event, const char *data, const char *target, - unsigned char payload[], int payload_size, void *user_data); + const unsigned char payload[], int payload_size, void *user_data); void publish(string event, const char *data, Client client, void *user_data); void publish(string event, const char *data, Client client, - unsigned char payload[], int payload_size, void *user_data); + const unsigned char payload[], int payload_size, void *user_data); void publish(string event, const char *data, list clients, void *user_data); void publish(string event, const char *data, list clients, - unsigned char payload[], int payload_size, void *user_data); + const unsigned char payload[], int payload_size, void *user_data); void publishMessage(string event, const char *data, const char *to, - unsigned char payload[], int payload_size, void *user_data); + const unsigned char payload[], int payload_size, void *user_data); void publishMessage(string method, string event, const char *data, - const char *to, unsigned char payload[], + const char *to, const unsigned char payload[], int payload_size, void *user_data); void handleWsiDestroy(); void setCommunicated(bool value); @@ -243,7 +243,7 @@ private: void create_websocket(void *att); unsigned char *prepareMessageMap(string, string, const char *data, const char *to, long *, - unsigned char payload[], int payload_size); + const unsigned char payload[], int payload_size); static string ROUTE; static string ERROR_EVENT; @@ -262,7 +262,8 @@ private: static pthread_t connect_thread; int mirror_lifetime; int force_exit; - char *messagedata; + unsigned char *cl_data; + int cl_data_size; //bool isWrite; //bool binary_message; bool disconnecting; diff --git a/msf_tizen_client/src/Channel.cpp b/msf_tizen_client/src/Channel.cpp index e93390e..1b62bc7 100755 --- a/msf_tizen_client/src/Channel.cpp +++ b/msf_tizen_client/src/Channel.cpp @@ -93,8 +93,11 @@ Channel::Channel() { write_buf_index = 0; write_buf_last_sent_index = 0; cl_payload = NULL; + cl_data = NULL; + cl_data_size = 0; is_header_parsed = false; eventType = ""; + resultobj = NULL; } Channel::Channel(Service *service1, string uri1) { @@ -121,8 +124,11 @@ Channel::Channel(Service *service1, string uri1) { write_buf_index = 0; write_buf_last_sent_index = 0; cl_payload = NULL; + cl_data = NULL; + cl_data_size = 0; is_header_parsed = false; eventType = ""; + resultobj = NULL; } Channel *Channel::create(Service *service, string uri) { @@ -157,6 +163,16 @@ Channel::~Channel() { free(cl_payload); cl_payload = NULL; } + + if (cl_data != NULL) { + free(cl_data); + cl_data = NULL; + } + + if (resultobj) { + g_free(resultobj); + resultobj = NULL; + } } void Channel::init_json_key_map() { @@ -274,7 +290,10 @@ void Channel::foreach_json_object(JsonObject *object, const gchar *name, p->msg_subject = Message::PROPERTY_RESULT; } else if (json_node_get_node_type(node) == JSON_NODE_OBJECT) { MSF_DBG("set resultobj"); - g_free(p->resultobj); + if (p->resultobj) { + g_free(p->resultobj); + p->resultobj = NULL; + } p->resultobj = json_node_dup_object(node); } } break; @@ -476,9 +495,6 @@ void Channel::handleApplicationMessage(string uid) { } void Channel::doApplicationCallback(Result_Base *result1) { - if (resultobj != NULL) { - } - bool errorMap = errobj; if (errorMap != false) { @@ -951,15 +967,33 @@ int Channel::callback_lws_mirror(struct lws *wsi, } } else { MSF_DBG("TEXT MESSAGE ARRIVED. len:%d", len); - this_ptr->eventType = ""; - this_ptr->json_parse((char *)in); + if (this_ptr->cl_data == NULL) { + this_ptr->cl_data = (unsigned char*)calloc(1, sizeof(unsigned char)); + this_ptr->cl_data_size = 0; + } + + this_ptr->cl_data = (unsigned char*)realloc(this_ptr->cl_data, this_ptr->cl_data_size + len + 1); + memcpy(&(this_ptr->cl_data[this_ptr->cl_data_size]), (char*)in, len); + this_ptr->cl_data_size += len; + this_ptr->cl_data[this_ptr->cl_data_size] = '\0'; this_ptr->connectionHandler->resetLastPingReceived(); - if (this_ptr->eventType == CONNECT_EVENT) { - this_ptr->handleConnectMessage(this_ptr->UID); - } else { - // this_ptr->handleMessage(this_ptr->UID); - this_ptr->handleMessage(this_ptr->UID, NULL); + if (lws_remaining_packet_payload(wsi) == 0) { + this_ptr->json_parse((char*)this_ptr->cl_data); + + if (this_ptr->eventType == CONNECT_EVENT) { + this_ptr->handleConnectMessage(this_ptr->UID); + } else { + // this_ptr->handleMessage(this_ptr->UID); + this_ptr->handleMessage(this_ptr->UID, NULL); + } + + if (this_ptr->cl_data) { + free(this_ptr->cl_data); + this_ptr->cl_data = NULL; + this_ptr->cl_data_size = 0; + this_ptr->eventType.clear(); + } } } break; @@ -1024,7 +1058,7 @@ void Channel::publish(string event, const char *data, void *user_data) publishMessage(event, data, to.c_str(), NULL, 0, user_data); } -void Channel::publish(string event, const char *data, unsigned char payload[], +void Channel::publish(string event, const char *data, const unsigned char payload[], int payload_size, void *user_data) { string to = "\""; @@ -1043,7 +1077,7 @@ void Channel::publish(string event, const char *data, const char *target, } void Channel::publish(string event, const char *data, const char *target, - unsigned char payload[], int payload_size, void *user_data) + const unsigned char payload[], int payload_size, void *user_data) { string to = "\""; to.append(target); @@ -1061,7 +1095,7 @@ void Channel::publish(string event, const char *data, Client client, } void Channel::publish(string event, const char *data, Client client, - unsigned char payload[], int payload_size, void *user_data) + const unsigned char payload[], int payload_size, void *user_data) { string to = "\""; to.append(client.getId()); @@ -1076,7 +1110,7 @@ void Channel::publish(string event, const char *data, list clients, } void Channel::publish(string event, const char *data, list clients, - unsigned char payload[], int payload_size, void *user_data) + const unsigned char payload[], int payload_size, void *user_data) { string to = "["; @@ -1098,14 +1132,17 @@ void Channel::publish(string event, const char *data, list clients, } void Channel::publishMessage(string event, const char *data, const char *to, - unsigned char payload[], int payload_size, void *user_data) { + const unsigned char payload[], int payload_size, void *user_data) { publishMessage(Message::METHOD_EMIT, event, data, to, payload, payload_size, user_data); } void Channel::publishMessage(string method, string event, const char *data, - const char *to, unsigned char payload[], + const char *to, const unsigned char payload[], int payload_size, void *user_data) { + if (data) + MSF_DBG("data len %d, payload len %d", strlen(data), payload_size); + if (!isWebSocketOpen()) { handleError(string(), Error::create("Not Connected")); return; @@ -1154,12 +1191,12 @@ void Channel::publishMessage(string method, string event, const char *data, unsigned char *Channel::prepareMessageMap(string method, string event, const char *data, const char *to, long *prepare_buf_len, - unsigned char payload[], + const unsigned char payload[], int payload_size) { int l = 0; int header_size = 0; - int prepare_buf_size = LWS_SEND_BUFFER_PRE_PADDING + payload_size + LWS_SEND_BUFFER_POST_PADDING + 128; + int prepare_buf_size = LWS_SEND_BUFFER_PRE_PADDING + strlen(data) + payload_size + 512 + LWS_SEND_BUFFER_POST_PADDING; unsigned char *prepare_buf = new unsigned char[prepare_buf_size]; if (payload) { @@ -1183,7 +1220,6 @@ unsigned char *Channel::prepareMessageMap(string method, string event, payload_size); l += payload_size; - //binary_message = true; } else { l += snprintf((char *)&prepare_buf[LWS_SEND_BUFFER_PRE_PADDING], diff --git a/packaging/d2d-conv-manager.spec b/packaging/d2d-conv-manager.spec index 069cdde..b770cf4 100755 --- a/packaging/d2d-conv-manager.spec +++ b/packaging/d2d-conv-manager.spec @@ -26,7 +26,7 @@ BuildRequires: pkgconfig(libwebsockets) BuildRequires: pkgconfig(iotcon) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-network-bluetooth) -BuildRequires: pkgconfig(capi-network-wifi-direct) +#BuildRequires: pkgconfig(capi-network-wifi-direct) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-network-connection) BuildRequires: pkgconfig(bundle) -- 2.7.4