From 48b31783a86a6bde9900555d4aa1a5273166bdf1 Mon Sep 17 00:00:00 2001 From: "arya.k" Date: Wed, 30 Sep 2015 12:48:16 +0530 Subject: [PATCH] [TIZEN] RESampleApplication bug fixes taken from master branch. Change-Id: Ia25f7b2c53187f33e14cbc7804f026c318767e3e Signed-off-by: arya.k Reviewed-on: https://gerrit.iotivity.org/gerrit/3299 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../NestedAttributeClientApp/src/reclient.cpp | 6 +- .../examples/tizen/RESampleClientApp/.cproject | 3 + .../edc_resource/re_client_control.edc | 15 ++- .../tizen/RESampleClientApp/src/reclient.cpp | 120 +++++++++++++++------ .../tizen/RESampleServerApp/inc/reserver.h | 6 +- .../tizen/RESampleServerApp/src/recontainer.cpp | 6 +- .../tizen/RESampleServerApp/src/reserver.cpp | 5 + 7 files changed, 121 insertions(+), 40 deletions(-) diff --git a/service/resource-encapsulation/examples/tizen/NestedAttributeClientApp/src/reclient.cpp b/service/resource-encapsulation/examples/tizen/NestedAttributeClientApp/src/reclient.cpp index 0a896ea..1af212e 100644 --- a/service/resource-encapsulation/examples/tizen/NestedAttributeClientApp/src/reclient.cpp +++ b/service/resource-encapsulation/examples/tizen/NestedAttributeClientApp/src/reclient.cpp @@ -178,7 +178,7 @@ void onResourceDiscovered(std::shared_ptr foundResource cond.notify_all(); } -void onRemoteAttributesReceivedCallback(const RCSResourceAttributes &attributes) +void onRemoteAttributesReceived(const RCSResourceAttributes &attributes, int) { dlog_print(DLOG_INFO, LOG_TAG, "#### onRemoteAttributesReceivedCallback callback"); @@ -229,7 +229,7 @@ static void getAttributeFromRemoteServer(void *data, Evas_Object *obj, void *eve { if (checkResource) { - resource->getRemoteAttributes(&onRemoteAttributesReceivedCallback); + resource->getRemoteAttributes(&onRemoteAttributesReceived); } else { @@ -248,7 +248,7 @@ static void setAttributeToRemoteServer(int fanSpeed, int airSpeed) if (checkResource) { resource->setRemoteAttributes(setAttribute, - &onRemoteAttributesReceivedCallback); + &onRemoteAttributesReceived); } else { diff --git a/service/resource-encapsulation/examples/tizen/RESampleClientApp/.cproject b/service/resource-encapsulation/examples/tizen/RESampleClientApp/.cproject index 1190711..168d329 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleClientApp/.cproject +++ b/service/resource-encapsulation/examples/tizen/RESampleClientApp/.cproject @@ -236,6 +236,9 @@ + + + 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 0d61537..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,11 @@ 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 = "?rt=core.TemperatureSensor"; -const std::string targetUri = OC_RSRVD_WELL_KNOWN_URI + resourceType; - -std::mutex mtx; -std::condition_variable cond; +const std::string resourceType = "oic.r.temperaturesensor"; static Evas_Object *log_entry = NULL; static Evas_Object *list = NULL; @@ -75,6 +71,7 @@ void *updateGroupLog(void *data) static void onDestroy() { dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called"); + resourceList.clear(); resource = nullptr; } @@ -85,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) @@ -159,9 +154,9 @@ void onCacheUpdated(const RCSResourceAttributes &attributes) &logMessage); } -void onRemoteAttributesReceivedCallback(const RCSResourceAttributes &attributes) +void onRemoteAttributesReceived(const RCSResourceAttributes &attributes, int) { - dlog_print(DLOG_INFO, LOG_TAG, "#### onRemoteAttributesReceivedCallback callback"); + dlog_print(DLOG_INFO, LOG_TAG, "#### onRemoteAttributesReceived entry"); string logMessage = "Remote Attribute Updated :
"; @@ -257,7 +252,7 @@ static void getAttributeFromRemoteServer(void *data, Evas_Object *obj, void *eve { if (checkResource) { - resource->getRemoteAttributes(&onRemoteAttributesReceivedCallback); + resource->getRemoteAttributes(&onRemoteAttributesReceived); } else { @@ -276,7 +271,7 @@ static void setAttributeToRemoteServer(int setTemperature) if (checkResource) { resource->setRemoteAttributes(setAttribute, - &onRemoteAttributesReceivedCallback); + &onRemoteAttributesReceived); } else { @@ -479,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()->discoverResource(RCSAddress::multicast(), targetUri, - &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) { @@ -596,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) { @@ -610,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 @@ -673,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; @@ -690,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); diff --git a/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/reserver.h b/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/reserver.h index 7e86554..a8386d1 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/reserver.h +++ b/service/resource-encapsulation/examples/tizen/RESampleServerApp/inc/reserver.h @@ -33,10 +33,14 @@ typedef int ReturnValue; constexpr int DEFALUT_VALUE = 0; +constexpr int PRESENCE_ON = 1; +constexpr int PRESENCE_OFF = 2; + std::string resourceUri = "/a/TempSensor"; -std::string resourceType = "core.TemperatureSensor"; +std::string resourceType = "oic.r.temperaturesensor"; std::string resourceInterface = "oic.if."; std::string attributeKey = "Temperature"; +int isPresenceOn = PRESENCE_ON; enum class Control { diff --git a/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/recontainer.cpp b/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/recontainer.cpp index 86e4e7c..24ed43e 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/recontainer.cpp +++ b/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/recontainer.cpp @@ -322,7 +322,8 @@ static void addHueBundle(void *data, Evas_Object *obj, void *event_info) { std::map bundleParams; container->addBundle("oic.bundle.hueSample", "", - "/opt/usr/apps/org.tizen.resampleserver/lib/libHueBundle.so", bundleParams); + "/opt/usr/apps/org.tizen.resampleserver/lib/libHueBundle.so", + "hueSample", bundleParams); logMessage += "HUE Bundle added
"; } else @@ -348,7 +349,8 @@ static void addBMIBundle(void *data, Evas_Object *obj, void *event_info) { std::map bundleParams; container->addBundle("oic.bundle.BMISensor", "", - "/opt/usr/apps/org.tizen.resampleserver/lib/libBMISensorBundle.so", bundleParams); + "/opt/usr/apps/org.tizen.resampleserver/lib/libBMISensorBundle.so", + "BMISensor", bundleParams); logMessage += "BMI Bundle added
"; } else diff --git a/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/reserver.cpp b/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/reserver.cpp index 47aac09..6f837c5 100644 --- a/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/reserver.cpp +++ b/service/resource-encapsulation/examples/tizen/RESampleServerApp/src/reserver.cpp @@ -73,6 +73,11 @@ static void onDestroy() server = NULL; string logMessage = "SERVER DESTROYED"; + if(isPresenceOn == PRESENCE_ON) + { + OCPlatform::stopPresence(); + } + dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str()); ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage); -- 2.7.4