From 00da58168147c8de5ce0e6c8d339448bd9feef22 Mon Sep 17 00:00:00 2001 From: "arya.k" Date: Tue, 29 Sep 2015 15:10:09 +0530 Subject: [PATCH] [TIZEN] RESampleClient application resource discovery fix. Change-Id: I80c2e436bbfac92420cb67fc405e2786c081b432 Signed-off-by: arya.k Reviewed-on: https://gerrit.iotivity.org/gerrit/3265 Reviewed-by: Abhishek Pandey Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- .../edc_resource/re_client_control.edc | 15 ++- .../tizen/RESampleClientApp/src/reclient.cpp | 111 ++++++++++++++++----- 2 files changed, 97 insertions(+), 29 deletions(-) diff --git a/service/resource-encapsulation/examples/tizen/RESampleClientApp/edc_resource/re_client_control.edc b/service/resource-encapsulation/examples/tizen/RESampleClientApp/edc_resource/re_client_control.edc index e936bbb..8146661 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleClientApp/edc_resource/re_client_control.edc +++ b/service/resource-encapsulation/examples/tizen/RESampleClientApp/edc_resource/re_client_control.edc @@ -28,13 +28,24 @@ group { part { - name: "find_button"; + name: "button1"; type: SWALLOW; scale: 1; description { rel1.relative: 0.01 0.01; - rel2.relative: 0.7 0.09; + rel2.relative: 0.5 0.09; + } + } + part + { + name: "button2"; + type: SWALLOW; + scale: 1; + description + { + rel1.relative: 0.51 0.01; + rel2.relative: 1.0 0.09; } } part diff --git a/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclient.cpp b/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclient.cpp index bfd0755..7097230 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclient.cpp +++ b/service/resource-encapsulation/examples/tizen/RESampleClientApp/src/reclient.cpp @@ -21,8 +21,6 @@ #include "reclient.h" #include -#include "mutex" -#include "condition_variable" #include "reclientmain.h" @@ -44,13 +42,12 @@ constexpr int INCORRECT_INPUT = 2; constexpr int QUIT_INPUT = 3; std::shared_ptr resource; +std::vector resourceList; +std::unique_ptr discoveryTask; const std::string defaultKey = "Temperature"; const std::string resourceType = "oic.r.temperaturesensor"; -std::mutex mtx; -std::condition_variable cond; - static Evas_Object *log_entry = NULL; static Evas_Object *list = NULL; static Evas_Object *naviframe = NULL; @@ -74,6 +71,7 @@ void *updateGroupLog(void *data) static void onDestroy() { dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called"); + resourceList.clear(); resource = nullptr; } @@ -84,21 +82,19 @@ void onResourceDiscovered(std::shared_ptr foundResource std::string resourceURI = foundResource->getUri(); std::string hostAddress = foundResource->getAddress(); - dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI : %s", resourceURI.c_str()); - dlog_print(DLOG_INFO, LOG_TAG, "#### Resource Host : %S", hostAddress.c_str()); - - string logMessage = "Resource Found
"; + int resourceSize = resourceList.size() + 1; + string logMessage = "Resource Found : " + std::to_string(resourceSize) + "
"; logMessage = logMessage + "URI: " + resourceURI + "
"; logMessage = logMessage + "Host:" + hostAddress + "
"; logMessage += "----------------------
"; - dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str()); + dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str()); ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage); - resource = foundResource; + resourceList.push_back(foundResource); - ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showClientAPIs, NULL); - cond.notify_all(); + if ("/a/TempSensor" == resourceURI) + resource = foundResource; } void onResourceStateChanged(const ResourceState &resourceState) @@ -158,7 +154,7 @@ void onCacheUpdated(const RCSResourceAttributes &attributes) &logMessage); } -void onRemoteAttributesReceived(const RCSResourceAttributes& attributes, int) +void onRemoteAttributesReceived(const RCSResourceAttributes &attributes, int) { dlog_print(DLOG_INFO, LOG_TAG, "#### onRemoteAttributesReceived entry"); @@ -478,17 +474,57 @@ static void stopCaching(void *data, Evas_Object *obj, void *event_info) void discoverResource() { - dlog_print(DLOG_INFO, LOG_TAG, "#### Wait 2 seconds until discovered"); - - RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(), resourceType, - &onResourceDiscovered); + dlog_print(DLOG_INFO, LOG_TAG, "#### discovery started"); - std::unique_lock lck(mtx); - cond.wait_for(lck, std::chrono::seconds(2)); + while (!discoveryTask) + { + try + { + discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType( + RCSAddress::multicast(), resourceType, &onResourceDiscovered); + } + catch (const RCSPlatformException &e) + { + std::cout << e.what() << std::endl; + } + } dlog_print(DLOG_INFO, LOG_TAG, "#### Discovery over"); } +void cancelDiscoverResource() +{ + dlog_print(DLOG_INFO, LOG_TAG, "#### cancelDiscoverResource entry"); + string logMessage = ""; + + if (!discoveryTask) + { + logMessage += "There is no discovery request
"; + } + else + { + discoveryTask->cancel(); + + logMessage += "Discovery canceled
"; + + int resourceSize = resourceList.size(); + if (!resourceSize) + { + logMessage += "No Resource Discovered
"; + } + else + { + logMessage += std::to_string(resourceSize) + " : Resource Discovered
"; + ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showClientAPIs, NULL); + } + + } + + dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str()); + ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, + &logMessage); +} + static void popup_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info) { @@ -595,7 +631,7 @@ list_scheduled_actionset_cb(void *data, Evas_Object *obj, void *event_info) evas_object_show(popup); } -// Method to be called when the Discover Resource UI Button is selected +// Method to be called when the Start Discovery UI Button is selected static void find_resource_cb(void *data, Evas_Object *obj, void *event_info) { @@ -609,6 +645,20 @@ find_resource_cb(void *data, Evas_Object *obj, void *event_info) } } +// Method to be called when the Cancel Discovery UI Button is selected +static void +cancel_resource_cb(void *data, Evas_Object *obj, void *event_info) +{ + if (NULL != list) + { + cancelDiscoverResource(); + } + else + { + dlog_print(DLOG_ERROR, "cancel_resource_cb", "list is NULL - So unable to add items!!!"); + } +} + void *showClientAPIs(void *data) { // Add items to the list only if the list is empty @@ -672,7 +722,8 @@ void group_cb(void *data, Evas_Object *obj, void *event_info) Evas_Object *layout; Evas_Object *scroller; Evas_Object *nf = (Evas_Object *)data; - Evas_Object *find_button; + Evas_Object *button1; + Evas_Object *button2; Elm_Object_Item *nf_it; naviframe = nf; @@ -689,11 +740,17 @@ void group_cb(void *data, Evas_Object *obj, void *event_info) elm_object_content_set(scroller, layout); - // Button - find_button = elm_button_add(layout); - elm_object_part_content_set(layout, "find_button", find_button); - elm_object_text_set(find_button, "Discover Resource"); - evas_object_smart_callback_add(find_button, "clicked", find_resource_cb, NULL); + // Start Discovery Button + button1 = elm_button_add(layout); + elm_object_part_content_set(layout, "button1", button1); + elm_object_text_set(button1, "Start Discovery"); + evas_object_smart_callback_add(button1, "clicked", find_resource_cb, NULL); + + // Cancel Discovery Button + button2 = elm_button_add(layout); + elm_object_part_content_set(layout, "button2", button2); + elm_object_text_set(button2, "Cancel Discovery"); + evas_object_smart_callback_add(button2, "clicked", cancel_resource_cb, NULL); // List list = elm_list_add(layout); -- 2.7.4