#include "reclient.h"
#include<iostream>
-#include "mutex"
-#include "condition_variable"
#include "reclientmain.h"
constexpr int QUIT_INPUT = 3;
std::shared_ptr<RCSRemoteResourceObject> resource;
+std::vector<RCSRemoteResourceObject::Ptr> resourceList;
+std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> 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;
static void onDestroy()
{
dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called");
+ resourceList.clear();
resource = nullptr;
}
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 <br>";
+ int resourceSize = resourceList.size() + 1;
+ string logMessage = "Resource Found : " + std::to_string(resourceSize) + "<br>";
logMessage = logMessage + "URI: " + resourceURI + "<br>";
logMessage = logMessage + "Host:" + hostAddress + "<br>";
logMessage += "----------------------<br>";
- 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)
&logMessage);
}
-void onRemoteAttributesReceived(const RCSResourceAttributes& attributes, int)
+void onRemoteAttributesReceived(const RCSResourceAttributes &attributes, int)
{
dlog_print(DLOG_INFO, LOG_TAG, "#### onRemoteAttributesReceived entry");
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<std::mutex> 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 <br>";
+ }
+ else
+ {
+ discoveryTask->cancel();
+
+ logMessage += "Discovery canceled <br>";
+
+ int resourceSize = resourceList.size();
+ if (!resourceSize)
+ {
+ logMessage += "No Resource Discovered <br>";
+ }
+ else
+ {
+ logMessage += std::to_string(resourceSize) + " : Resource Discovered <br>";
+ 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)
{
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)
{
}
}
+// 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
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;
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);