Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / service / resource-encapsulation / examples / tizen / RESampleClientApp / src / reclient.cpp
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 #include "reclient.h"
22
23 #include<iostream>
24
25 #include "reclientmain.h"
26 #include "RCSDiscoveryManager.h"
27 #include "RCSRemoteResourceObject.h"
28 #include "RCSResourceAttributes.h"
29 #include "RCSAddress.h"
30 #include "OCPlatform.h"
31
32 # define checkResource nullptr == resource?false:true
33
34 using namespace std;
35 using namespace OC;
36 using namespace OIC::Service;
37
38 std::shared_ptr<RCSRemoteResourceObject>  resource;
39 std::vector<RCSRemoteResourceObject::Ptr> resourceList;
40 std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> discoveryTask;
41
42 std::string g_resourceUri;
43 std::string g_resourceType;
44 std::string g_attributeKey;
45
46 static Evas_Object *log_entry = NULL;
47 static Evas_Object *list = NULL;
48 static Evas_Object *naviframe = NULL;
49
50 typedef struct temperature_popup
51 {
52     Evas_Object *popup;
53     Evas_Object *entry;
54 } temperature_popup_fields;
55
56 // Function to update the log in UI
57 void *updateGroupLog(void *data)
58 {
59     string *log = (string *)data;
60     // Show the log
61     elm_entry_entry_append(log_entry, (*log).c_str());
62     elm_entry_cursor_end_set(log_entry);
63     return NULL;
64 }
65
66 static void onDestroy()
67 {
68     dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called");
69     resourceList.clear();
70     resource = nullptr;
71 }
72
73 void onResourceDiscovered(std::shared_ptr<RCSRemoteResourceObject> foundResource)
74 {
75     dlog_print(DLOG_INFO, LOG_TAG, "#### onResourceDiscovered callback");
76
77     std::string resourceURI = foundResource->getUri();
78     std::string hostAddress = foundResource->getAddress();
79
80     int resourceSize = resourceList.size() + 1;
81     string logMessage = "Resource Found : " + std::to_string(resourceSize) + "<br>";
82     logMessage = logMessage + "URI: " + resourceURI + "<br>";
83     logMessage = logMessage + "Host:" + hostAddress + "<br>";
84     logMessage += "----------------------<br>";
85     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
86     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
87                                           &logMessage);
88
89     resourceList.push_back(foundResource);
90
91     if (g_resourceUri == resourceURI)
92         resource = foundResource;
93 }
94
95 void onResourceStateChanged(const ResourceState &resourceState)
96 {
97     dlog_print(DLOG_INFO, LOG_TAG, "#### onResourceStateChanged");
98
99     std::string logMessage = "State changed to : ";
100
101     switch (resourceState)
102     {
103         case ResourceState::NONE:
104             logMessage = logMessage + "NOT_MONITORING <br>";
105             break;
106
107         case ResourceState::ALIVE:
108             logMessage = logMessage + "ALIVE <br>";
109             break;
110
111         case ResourceState::REQUESTED:
112             logMessage = logMessage + "REQUESTED <br>";
113             break;
114
115         case ResourceState::LOST_SIGNAL:
116             logMessage = logMessage + "LOST_SIGNAL <br>";
117             resource = nullptr;
118             break;
119
120         case ResourceState::DESTROYED:
121             logMessage = logMessage + "DESTROYED <br>";
122             break;
123     }
124
125     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
126     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
127                                           &logMessage);
128 }
129
130 void onCacheUpdated(const RCSResourceAttributes &attributes)
131 {
132     dlog_print(DLOG_INFO, LOG_TAG, "#### onCacheUpdated callback");
133
134     string logMessage = "Cache Updated : <br> ";
135
136     if (attributes.empty())
137     {
138         logMessage + logMessage + "Attribute is Empty <br>";
139         return;
140     }
141
142     for (const auto & attr : attributes)
143     {
144         logMessage = logMessage + "KEY:" + attr.key().c_str() + "<br>";
145         logMessage = logMessage + "VALUE:" + attr.value().toString().c_str() + "<br>";
146     }
147     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
148     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
149                                           &logMessage);
150 }
151
152 void onRemoteAttributesReceived(const RCSResourceAttributes &attributes, int)
153 {
154     dlog_print(DLOG_INFO, LOG_TAG, "#### onRemoteAttributesReceived entry");
155
156     string logMessage = "Remote Attribute Updated : <br> ";
157
158     if (attributes.empty())
159     {
160         logMessage + logMessage + "Attribute is Empty <br>";
161         return;
162     }
163
164     for (const auto & attr : attributes)
165     {
166         logMessage = logMessage + "KEY:" + attr.key().c_str() + "<br>";
167         logMessage = logMessage + "VALUE:" + attr.value().toString().c_str() + "<br>";
168     }
169
170     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
171     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
172                                           &logMessage);
173 }
174
175 static void startMonitoring(void *data, Evas_Object *obj, void *event_info)
176 {
177     string logMessage = "";
178
179     if (checkResource)
180     {
181         if (!resource->isMonitoring())
182         {
183             try
184             {
185                 logMessage = logMessage + "Started Monitoring <br>";
186                 resource->startMonitoring(&onResourceStateChanged);
187             }
188             catch (const RCSBadRequestException &e)
189             {
190                 logMessage = logMessage + "Exception BadRequest<br>";
191                 dlog_print(DLOG_INFO, LOG_TAG, "#### Exception in isMonitoring : %s", e.what());
192             }
193             catch (const RCSInvalidParameterException &e)
194             {
195                 logMessage = logMessage + "Exception Invalid Param<br>";
196                 dlog_print(DLOG_INFO, LOG_TAG, "#### Exception in isMonitoring : %s", e.what());
197             }
198         }
199         else
200         {
201             logMessage = logMessage + "Already Monitoring <br>";
202         }
203     }
204     else
205     {
206         logMessage = logMessage + "No Resource to monitor <br>";
207     }
208
209     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
210     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
211                                           &logMessage);
212 }
213
214 static void stopMonitoring(void *data, Evas_Object *obj, void *event_info)
215 {
216     string logMessage = "";
217
218     if (checkResource)
219     {
220         if (resource->isMonitoring())
221         {
222             resource->stopMonitoring();
223             logMessage = logMessage + "Stopped Monitoring <br>";
224         }
225         else
226         {
227             logMessage = logMessage + "Monitoring not started <br>";
228         }
229     }
230     else
231     {
232         logMessage = logMessage + "NO Resource to stop monitor <br>";
233     }
234
235     dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
236     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
237                                           &logMessage);
238 }
239
240 static void list_selected_cb(void *data, Evas_Object *obj, void *event_info)
241 {
242     Elm_Object_Item *it = (Elm_Object_Item *)event_info;
243     elm_list_item_selected_set(it, EINA_FALSE);
244 }
245
246 static void getAttributeFromRemoteServer(void *data, Evas_Object *obj, void *event_info)
247 {
248     if (checkResource)
249     {
250         resource->getRemoteAttributes(&onRemoteAttributesReceived);
251     }
252     else
253     {
254         dlog_print(DLOG_INFO, LOG_TAG, "#### No Resource to getAttributeFromRemoteServer...");
255     }
256 }
257
258 static void setAttributeToRemoteServer(int setValue)
259 {
260     string logMessage = "";
261
262     RCSResourceAttributes setAttribute;
263     setAttribute[g_attributeKey] = setValue;
264
265     if (checkResource)
266     {
267         resource->setRemoteAttributes(setAttribute,
268                                       &onRemoteAttributesReceived);
269     }
270     else
271     {
272         logMessage = "No Resource to setAttributeToRemoteServer";
273     }
274
275     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
276     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
277                                           &logMessage);
278 }
279
280 static void startCaching(std::function <void (const RCSResourceAttributes &)>cb)
281 {
282     string logMessage = "";
283
284     if (checkResource)
285     {
286         if (!resource->isCaching())
287         {
288             if (cb)
289             {
290                 try
291                 {
292                     logMessage = logMessage + "Caching with callback <br>";
293                     resource->startCaching(&onCacheUpdated);
294                 }
295                 catch (const RCSBadRequestException &e)
296                 {
297                     logMessage = logMessage + "Exception BadRequest<br>";
298                     dlog_print(DLOG_INFO, LOG_TAG, "#### Exception in startCaching : %s", e.what());
299                 }
300
301             }
302             else
303             {
304                 try
305                 {
306                     logMessage = logMessage + "Caching without callback <br>";
307                     resource->startCaching();
308                 }
309                 catch (const RCSBadRequestException &e)
310                 {
311                     logMessage = logMessage + "Exception BadRequest<br>";
312                     dlog_print(DLOG_INFO, LOG_TAG, "#### Exception in startCaching : %s", e.what());
313                 }
314             }
315         }
316         else
317         {
318             logMessage = logMessage + "Caching Already Started <br>";
319         }
320     }
321     else
322     {
323         logMessage = logMessage + "No resource to start Caching <br>";
324     }
325
326     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
327     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
328                                           &logMessage);
329 }
330
331 static void startCachingWithoutCallback(void *data, Evas_Object *obj, void *event_info)
332 {
333     startCaching(nullptr);
334 }
335
336 static void startCachingWithCallback(void *data, Evas_Object *obj, void *event_info)
337 {
338     startCaching(onCacheUpdated);
339 }
340
341 static void getResourceCacheState(void *data, Evas_Object *obj, void *event_info)
342 {
343     string logMessage = "CACHE STATE : ";
344     switch (resource->getCacheState())
345     {
346         case CacheState::READY:
347             logMessage = logMessage + "READY <br>";
348             break;
349
350         case CacheState::UNREADY:
351             logMessage = logMessage + "UNREADY <br>";
352             break;
353
354         case CacheState::LOST_SIGNAL:
355             logMessage = logMessage + "LOST_SIGNAL <br>";
356             break;
357
358         case CacheState::NONE:
359             logMessage = logMessage + "NONE <br>";
360             break;
361
362         default:
363             break;
364     }
365
366     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
367     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
368                                           &logMessage);
369 }
370
371 static void getCachedAttributes(void *data, Evas_Object *obj, void *event_info)
372 {
373     string logMessage = "";
374
375     if (checkResource)
376     {
377         try
378         {
379             if (resource->getCachedAttributes().empty())
380             {
381                 logMessage = "Cached attribute empty<br>";
382             }
383             else
384             {
385                 for (const auto & attr : resource->getCachedAttributes())
386                 {
387                     logMessage = logMessage + "KEY:" + attr.key().c_str() + "<br>";
388                     logMessage = logMessage + "VALUE:" + attr.value().toString().c_str() + "<br>";
389                     dlog_print(DLOG_INFO, LOG_TAG, "#### Cached attributes received ");
390                 }
391             }
392         }
393         catch (const RCSBadRequestException &e)
394         {
395             logMessage = "Exception Received<br>";
396             dlog_print(DLOG_INFO, LOG_TAG, "#### Exception in getCachedAttributes : %s", e.what());
397         }
398     }
399     else
400     {
401         logMessage = logMessage + "No Resource<br>";
402         dlog_print(DLOG_INFO, LOG_TAG, "#### No Resource to getCachedAttributes...");
403     }
404
405     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
406     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
407                                           &logMessage);
408 }
409
410 static void getCachedAttribute(void *data, Evas_Object *obj, void *event_info)
411 {
412     string logMessage = "";
413
414     if (checkResource)
415     {
416         try
417         {
418             logMessage = logMessage + "KEY:" + g_attributeKey.c_str() + "<br>";
419             int attrValue = resource->getCachedAttribute(g_attributeKey).get< int >();
420             logMessage = logMessage + "VALUE:" + to_string(attrValue) + "<br>";
421         }
422         catch (const RCSBadRequestException &e)
423         {
424             logMessage = logMessage + "Exception BadRequest<br>";
425             dlog_print(DLOG_INFO, LOG_TAG, "#### Exception in getCachedAttribute : %s", e.what());
426         }
427         catch (const RCSBadGetException &e)
428         {
429             logMessage = logMessage + "Exception BadGet<br>";
430             dlog_print(DLOG_INFO, LOG_TAG, "#### Exception in getCachedAttribute : %s", e.what());
431         }
432     }
433     else
434     {
435         logMessage = logMessage + "No resource<br>";
436     }
437
438     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
439     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
440                                           &logMessage);
441 }
442
443 static void stopCaching(void *data, Evas_Object *obj, void *event_info)
444 {
445     string logMessage = "";
446
447     if (checkResource)
448     {
449         if (resource->isCaching())
450         {
451             resource->stopCaching();
452             logMessage = logMessage + "Caching stopped <br>";
453         }
454         else
455         {
456             logMessage = logMessage + "Caching not started <br>";
457         }
458     }
459     else
460     {
461         logMessage = logMessage + "No resource found<br>";
462     }
463
464     dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
465     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
466                                           &logMessage);
467 }
468
469 void discoverResource()
470 {
471     dlog_print(DLOG_INFO, LOG_TAG, "#### discovery started");
472
473     while (!discoveryTask)
474     {
475         resourceList.clear();
476         resource = nullptr;
477         try
478         {
479             discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(
480                                 RCSAddress::multicast(), g_resourceType, &onResourceDiscovered);
481         }
482         catch (const RCSPlatformException &e)
483         {
484             std::cout << e.what() << std::endl;
485         }
486     }
487
488     dlog_print(DLOG_INFO, LOG_TAG, "#### Discovery over");
489 }
490
491 void cancelDiscoverResource()
492 {
493     dlog_print(DLOG_INFO, LOG_TAG, "#### cancelDiscoverResource entry");
494     string logMessage = "";
495
496     if (!discoveryTask)
497     {
498         logMessage += "There is no discovery request <br>";
499     }
500     else
501     {
502         discoveryTask->cancel();
503         discoveryTask = nullptr;
504
505         logMessage += "Discovery canceled <br>";
506
507         int resourceSize = resourceList.size();
508         if (!resourceSize)
509         {
510             logMessage += "No Resource Discovered <br>";
511         }
512         else
513         {
514             logMessage += std::to_string(resourceSize) + " : Resource Discovered <br>";
515             ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showClientAPIs, NULL);
516         }
517
518     }
519
520     dlog_print(DLOG_INFO, LOG_TAG, "#### %s", logMessage.c_str());
521     ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
522                                           &logMessage);
523 }
524
525 static void
526 popup_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
527 {
528     temperature_popup_fields *popup_fields = (temperature_popup_fields *)data;
529     evas_object_del(popup_fields->popup);
530     free(popup_fields);
531 }
532
533 static void
534 popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info)
535 {
536     temperature_popup_fields *popup_fields = (temperature_popup_fields *)data;
537     Evas_Object *entry = popup_fields->entry;
538     const char *attributeString = elm_entry_entry_get(entry);
539     // Remove white spaces(if any) at the beginning
540     int beginning = 0;
541     while (attributeString[beginning] == ' ')
542     {
543         (beginning)++;
544     }
545
546     int len = strlen(attributeString);
547     if (NULL == attributeString || 1 > len)
548     {
549         dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL attribute Value");
550         string logMessage = g_attributeKey + " Cannot be NULL<br>";
551         logMessage += "----------------------<br>";
552         dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
553         ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
554     }
555     else
556     {
557         int attributeValue = atoi(attributeString);
558         string attrString(attributeString);
559         setAttributeToRemoteServer(attributeValue);
560         dlog_print(DLOG_INFO, LOG_TAG, "#### Attribute to set : %d", attributeValue);
561
562         string logMessage = g_attributeKey + " to set : " + attrString + "<br>";
563         logMessage += "----------------------<br>";
564         dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
565         ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
566                                               &logMessage);
567     }
568     evas_object_del(popup_fields->popup);
569     free(popup_fields);
570 }
571
572 static void
573 list_get_attribute_value_cb(void *data, Evas_Object *obj, void *event_info)
574 {
575     Evas_Object *popup, *btn;
576     Evas_Object *nf = naviframe;
577     Evas_Object *entry;
578     Evas_Object *layout;
579
580     /* popup */
581     popup = elm_popup_add(nf);
582     elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
583     eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
584     evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
585     if (LIGHT_RT == g_resourceType)
586     {
587         elm_object_part_text_set(popup, "title,text", "Enter the brightness");
588     }
589     else
590     {
591         elm_object_part_text_set(popup, "title,text", "Enter the temperature");
592     }
593
594     layout = elm_layout_add(popup);
595     elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_datetime_text");
596     evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
597     elm_object_content_set(popup, layout);
598
599     entry = elm_entry_add(layout);
600     elm_entry_single_line_set(entry, EINA_TRUE);
601     elm_entry_scrollable_set(entry, EINA_TRUE);
602     evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
603     evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
604     eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
605     if (LIGHT_RT == g_resourceType)
606     {
607         elm_object_part_text_set(entry, "elm.guide", "RANGE (0 - 50)");
608     }
609     else
610     {
611         elm_object_part_text_set(entry, "elm.guide", "in degree celsius");
612     }
613     elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER);
614     elm_object_part_content_set(layout, "elm.swallow.content", entry);
615
616     temperature_popup_fields *popup_fields;
617     popup_fields = (temperature_popup_fields *)malloc(sizeof(temperature_popup_fields));
618     if (NULL == popup_fields)
619     {
620         dlog_print(DLOG_INFO, LOG_TAG, "#### Memory allocation failed");
621     }
622     else
623     {
624         popup_fields->popup = popup;
625         popup_fields->entry = entry;
626     }
627
628     /* Cancel button */
629     btn = elm_button_add(popup);
630     elm_object_style_set(btn, "popup");
631     elm_object_text_set(btn, "Cancel");
632     elm_object_part_content_set(popup, "button1", btn);
633     evas_object_smart_callback_add(btn, "clicked", popup_cancel_clicked_cb, popup_fields);
634
635     /* Set button */
636     btn = elm_button_add(popup);
637     elm_object_style_set(btn, "popup");
638     elm_object_text_set(btn, "Set");
639     elm_object_part_content_set(popup, "button2", btn);
640     evas_object_smart_callback_add(btn, "clicked", popup_set_clicked_cb, popup_fields);
641
642     evas_object_show(popup);
643 }
644
645 // Method to be called when the Start Discovery UI Button is selected
646 static void
647 find_resource_cb(void *data, Evas_Object *obj, void *event_info)
648 {
649     if (NULL != list)
650     {
651         discoverResource();
652     }
653     else
654     {
655         dlog_print(DLOG_ERROR, "find_resource_cb", "list is NULL - So unable to add items!!!");
656     }
657 }
658
659 // Method to be called when the Cancel Discovery UI Button is selected
660 static void
661 cancel_resource_cb(void *data, Evas_Object *obj, void *event_info)
662 {
663     if (NULL != list)
664     {
665         cancelDiscoverResource();
666     }
667     else
668     {
669         dlog_print(DLOG_ERROR, "cancel_resource_cb", "list is NULL - So unable to add items!!!");
670     }
671 }
672
673 void *showClientAPIs(void *data)
674 {
675     // Add items to the list only if the list is empty
676     const Eina_List *eina_list = elm_list_items_get(list);
677     int count = eina_list_count(eina_list);
678     if (!count)
679     {
680         elm_list_item_append(list, "1. Start Monitoring", NULL, NULL,
681                              startMonitoring, NULL);
682
683         elm_list_item_append(list, "2. Stop Monitoring", NULL, NULL,
684                              stopMonitoring, NULL);
685
686         elm_list_item_append(list, "3. Get Attribute", NULL, NULL,
687                              getAttributeFromRemoteServer, NULL);
688
689         elm_list_item_append(list, "4. Set Attribute", NULL, NULL,
690                              list_get_attribute_value_cb, NULL);
691
692         elm_list_item_append(list, "5. Start Caching - No update", NULL, NULL,
693                              startCachingWithoutCallback, NULL);
694
695         elm_list_item_append(list, "6. Start Caching - With update", NULL, NULL,
696                              startCachingWithCallback, NULL);
697
698         elm_list_item_append(list, "7. Get Cache State", NULL, NULL,
699                              getResourceCacheState, NULL);
700
701         elm_list_item_append(list, "8. Get cached attributes", NULL, NULL,
702                              getCachedAttributes, NULL);
703
704         elm_list_item_append(list, "9. Stop Caching", NULL, NULL,
705                              stopCaching, NULL);
706
707         elm_list_go(list);
708     }
709     return NULL;
710 }
711
712 static Eina_Bool
713 naviframe_pop_cb(void *data, Elm_Object_Item *it)
714 {
715     onDestroy();
716
717     if (NULL != log_entry)
718     {
719         evas_object_del(log_entry);
720         log_entry = NULL;
721     }
722     if (NULL != list)
723     {
724         evas_object_del(list);
725         list = NULL;
726     }
727     return EINA_TRUE;
728 }
729
730 void client_cb(void *data)
731 {
732     Evas_Object *layout;
733     Evas_Object *scroller;
734     Evas_Object *nf = (Evas_Object *)data;
735     Evas_Object *button1;
736     Evas_Object *button2;
737     Elm_Object_Item *nf_it;
738
739     naviframe = nf;
740
741     // Scroller
742     scroller = elm_scroller_add(nf);
743     elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
744     elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
745
746     // Layout
747     layout = elm_layout_add(nf);
748     elm_layout_file_set(layout, ELM_DEMO_EDJ, "group_layout");
749     evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
750
751     elm_object_content_set(scroller, layout);
752
753     // Start Discovery Button
754     button1 = elm_button_add(layout);
755     elm_object_part_content_set(layout, "button1", button1);
756     elm_object_text_set(button1, "Start Discovery");
757     evas_object_smart_callback_add(button1, "clicked", find_resource_cb, NULL);
758
759     // Cancel Discovery Button
760     button2 = elm_button_add(layout);
761     elm_object_part_content_set(layout, "button2", button2);
762     elm_object_text_set(button2, "Cancel Discovery");
763     evas_object_smart_callback_add(button2, "clicked", cancel_resource_cb, NULL);
764
765     // List
766     list = elm_list_add(layout);
767     elm_list_mode_set(list, ELM_LIST_COMPRESS);
768     evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
769     elm_object_part_content_set(layout, "list", list);
770     elm_list_go(list);
771
772     // log_entry - textarea for log
773     log_entry = elm_entry_add(layout);
774     elm_entry_scrollable_set(log_entry, EINA_TRUE);
775     elm_entry_editable_set(log_entry, EINA_FALSE);
776     elm_object_part_text_set(log_entry, "elm.guide", "Logs will be updated here!!!");
777     evas_object_size_hint_weight_set(log_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
778     evas_object_size_hint_align_set(log_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
779     elm_object_part_content_set(layout, "log", log_entry);
780
781     nf_it = elm_naviframe_item_push(nf, "Resource Encapsulation", NULL, NULL, scroller, NULL);
782     elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL);
783 }
784
785 void discoverTempSensor(void *data, Evas_Object *obj, void *event_info)
786 {
787     g_resourceUri = TEMPERATURE_URI;
788     g_resourceType = TEMPERATURE_RT;
789     g_attributeKey = TEMPERATURE_AK;
790
791     client_cb(data);
792 }
793
794 void discoverLight(void *data, Evas_Object *obj, void *event_info)
795 {
796     g_resourceUri = LIGHT_URI;
797     g_resourceType = LIGHT_RT;
798     g_attributeKey = LIGHT_AK;
799
800     client_cb(data);
801 }