comp-manager: Add requester uuid when sending data to remote device
authorSaurav Babu <saurav.babu@samsung.com>
Fri, 6 Apr 2018 07:22:04 +0000 (12:52 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:49 +0000 (19:38 +0900)
This patch also notifies requester uuid to upper layer in request
result notification

Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/companion-manager/include/comp_gdbus_group.h
src/companion-manager/src/comp_gdbus_group.c
src/companion-manager/src/comp_iot.cpp
src/companion-manager/src/companion_gdbus.xml

index f62c17d..5d8c9f4 100644 (file)
@@ -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
 }
index 0f992fa..22ffac2 100644 (file)
@@ -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);
 }
 
index 5126930..2f1143e 100755 (executable)
@@ -375,7 +375,7 @@ OCEntityHandlerResult _request_handler(std::shared_ptr<OCResourceRequest> 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<OCResourceRequest> 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<OCResourceRequest> 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<OCResource> 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));
index f4ebd9a..8eca1c4 100644 (file)
                </signal>
                <signal name="RequestResult">
                        <arg type="s" name="command" direction="out" />
+                       <arg type="s" name="device_id" direction="out" />
                        <arg type="s" name="arg" direction="out" />
                        <arg type="i" name="result" direction="out" />
                </signal>