From 2be2218b188a2c2e9f748113f4a72278d57b2186 Mon Sep 17 00:00:00 2001 From: Saurav Babu Date: Fri, 6 Apr 2018 12:52:04 +0530 Subject: [PATCH] comp-manager: Add requester uuid when sending data to remote device This patch also notifies requester uuid to upper layer in request result notification Signed-off-by: Saurav Babu --- src/companion-manager/include/comp_gdbus_group.h | 3 ++- src/companion-manager/src/comp_gdbus_group.c | 6 +++-- src/companion-manager/src/comp_iot.cpp | 33 +++++++++++++++++------- src/companion-manager/src/companion_gdbus.xml | 1 + 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/companion-manager/include/comp_gdbus_group.h b/src/companion-manager/include/comp_gdbus_group.h index f62c17d..5d8c9f4 100644 --- a/src/companion-manager/include/comp_gdbus_group.h +++ b/src/companion-manager/include/comp_gdbus_group.h @@ -111,7 +111,8 @@ void notify_mowned_device_found(int device_count, GVariant *device_data); void notify_mowned_device_find_finish(int ret); void notify_group_join(int result); void notify_send_data_finish(const char *resp_data, int ret); -void notify_request_result(const char *cmd, char *arg, int ret); +void notify_request_result(const char *cmd, const char *requester_id, char *arg, + int ret); #ifdef __cplusplus } diff --git a/src/companion-manager/src/comp_gdbus_group.c b/src/companion-manager/src/comp_gdbus_group.c index 0f992fa..22ffac2 100644 --- a/src/companion-manager/src/comp_gdbus_group.c +++ b/src/companion-manager/src/comp_gdbus_group.c @@ -401,8 +401,10 @@ void notify_send_data_finish(const char *resp_data, int ret) group_emit_send_data_finish(group_dbus_get_object(), resp_data, ret); } -void notify_request_result(const char *cmd, char *arg, int ret) +void notify_request_result(const char *cmd, const char *requester_id, char *arg, + int ret) { - group_emit_request_result(group_dbus_get_object(), cmd, arg, ret); + group_emit_request_result(group_dbus_get_object(), cmd, requester_id, arg, + ret); } diff --git a/src/companion-manager/src/comp_iot.cpp b/src/companion-manager/src/comp_iot.cpp index 5126930..2f1143e 100755 --- a/src/companion-manager/src/comp_iot.cpp +++ b/src/companion-manager/src/comp_iot.cpp @@ -375,7 +375,7 @@ OCEntityHandlerResult _request_handler(std::shared_ptr reques char *arg = NULL; int result; int cmd; - std::string group_name, uuid, data; + std::string requester_id, group_name, uuid, data; comp_context_t *comp_ctx; try { @@ -383,11 +383,20 @@ OCEntityHandlerResult _request_handler(std::shared_ptr reques _print_oc_representation(rep); - if (!rep.getValue("CMD", cmd)) { + ObservationInfo observationInfo = request->getObservationInfo(); + LOG_DEBUG("Received request from %s:%d", + observationInfo.address.c_str(), observationInfo.port); + + if (!rep.getValue("CMD", cmd)) LOG_ERR("CMD not found in representation"); - } else { + else LOG_DEBUG("Command received %d", cmd); - } + + if (!rep.getValue("device_id", requester_id)) + LOG_ERR("device_id not found in representation"); + else + LOG_DEBUG("device_id received %s", requester_id.c_str()); + switch(cmd) { case COMP_REQ_SEND_DATA: #ifdef SUPPORT_BASE64_ENCODING @@ -485,7 +494,7 @@ OCEntityHandlerResult _request_handler(std::shared_ptr reques } notify_request_result(command2string((comp_request_type_e) cmd), - arg, result); + requester_id.c_str(), arg, result); g_free(arg); @@ -660,23 +669,23 @@ static bool _found_resource(std::shared_ptr resource, LOG_DEBUG("CMD = %s", command2string(cmd->command)); + rep.setValue("CMD", cmd->command); + + comp_context_t *comp_ctx = comp_context_get_context(); + rep.setValue("device_id", std::string(comp_ctx->device_uuid)); + if (cmd->command == COMP_REQ_CREATE_GROUP) { //request create group - rep.setValue("CMD", COMP_REQ_CREATE_GROUP); rep.setValue("name", std::string(cmd->arg1)); } else if (cmd->command == COMP_REQ_INVITE_DEVICE) { //request invite - rep.setValue("CMD", COMP_REQ_INVITE_DEVICE); rep.setValue("name", std::string(cmd->arg1)); rep.setValue("id", std::string(cmd->arg2)); rep.setValue("PIN", std::string(cmd->arg3)); } else if (cmd->command == COMP_REQ_EJECT_DEVICE) { //request eject - rep.setValue("CMD", COMP_REQ_EJECT_DEVICE); rep.setValue("name", std::string(cmd->arg1)); rep.setValue("id", std::string(cmd->arg2)); } else if (cmd->command == COMP_REQ_DELETE_GROUP) { //request delete group - rep.setValue("CMD", COMP_REQ_DELETE_GROUP); rep.setValue("name", std::string(cmd->arg1)); } else { /* Send Data */ - rep.setValue("CMD", COMP_REQ_SEND_DATA); #ifdef SUPPORT_BASE64_ENCODING uint32_t outSize = 0; size_t b64BufSize = B64ENCODE_OUT_SAFESIZE( @@ -808,6 +817,10 @@ int comp_iot_send_data(comp_resource_type_e resource_type, int timeout, OCRepresentation rep; rep.setValue("CMD", cmd->command); + + comp_context_t *comp_ctx = comp_context_get_context(); + rep.setValue("device_id", std::string(comp_ctx->device_uuid)); + switch (cmd->command) { case COMP_REQ_SEND_DATA: rep.setValue("data", std::string(cmd->arg1)); diff --git a/src/companion-manager/src/companion_gdbus.xml b/src/companion-manager/src/companion_gdbus.xml index f4ebd9a..8eca1c4 100644 --- a/src/companion-manager/src/companion_gdbus.xml +++ b/src/companion-manager/src/companion_gdbus.xml @@ -175,6 +175,7 @@ + -- 2.7.4