1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
23 #include "tmsampleapp.h"
30 namespace PH = std::placeholders;
32 static Evas_Object *log_entry = NULL;
33 static Evas_Object *list = NULL;
34 static Evas_Object *naviframe = NULL;
36 string BULBOFF = "AllBulbOff";
37 string BULBON = "AllBulbOn";
38 string resourceURI = "/core/b/collection";
39 string resourceTypeName = "b.collection";
41 std::vector< OCResourceHandle > groupResourceHandleVector;
42 OCResourceHandle resourceHandle = NULL;
43 OCResourceHandle foundResourceHandle = NULL;
44 shared_ptr< OCResource > g_resource ;
45 std::vector< string > lights;
47 ThingsManager *groupThingsMgr = new ThingsManager();
49 typedef struct datetime_popup
53 } datetime_popup_fields;
55 // Function to update the log in UI
56 void *updateGroupLog(void *data)
58 string *log = (string *)data;
60 elm_entry_entry_append(log_entry, (*log).c_str());
61 elm_entry_cursor_end_set(log_entry);
65 void onPut(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
68 dlog_print(DLOG_INFO, LOG_TAG, "#### onPut Callback Received!!!!");
69 logMessage += "API Result: Success<br>onPut Callback Received<br>";
70 if (OC_STACK_OK == eCode)
72 dlog_print(DLOG_INFO, LOG_TAG, "#### Result is OK");
76 dlog_print(DLOG_INFO, LOG_TAG, "#### Invalid Parameter");
78 logMessage += "----------------------<br>";
79 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
83 void onPost(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
85 dlog_print(DLOG_INFO, LOG_TAG, "#### onPost callback received ENTRY!!!!");
87 logMessage += "API Result: Success<br>onPost Callback Received<br>";
89 if (rep.hasAttribute("ActionSet"))
92 if (rep.getValue("ActionSet", plainText))
94 ActionSet *actionset = groupThingsMgr->getActionSetfromString(plainText);
95 if (NULL != actionset)
97 dlog_print(DLOG_INFO, LOG_TAG, "#### ACTIONSET NAME :: (%s)",
98 actionset->actionsetName.c_str());
99 logMessage += "ACTIONSET NAME :: " + actionset->actionsetName + "<br>";
100 for (auto actIter = actionset->listOfAction.begin();
101 actIter != actionset->listOfAction.end(); ++actIter)
103 dlog_print(DLOG_INFO, LOG_TAG, "#### TARGET :: (%s)",
104 (*actIter)->target.c_str());
105 logMessage += logMessage + "TARGET :: " + (*actIter)->target + "<br>";
106 for (auto capaIter = (*actIter)->listOfCapability.begin();
107 capaIter != (*actIter)->listOfCapability.end(); ++capaIter)
109 dlog_print(DLOG_INFO, LOG_TAG, "#### POWER :: (%s)",
110 (*capaIter)->status.c_str());
111 logMessage += logMessage + "CAPABILITY :: " +
112 (*capaIter)->status + "<br>";
119 else if (rep.hasAttribute("DoAction"))
122 if (rep.getValue("DoAction", plainText))
124 logMessage += plainText + "<br>";
125 dlog_print(DLOG_INFO, LOG_TAG, "#### DO ACTION :: (%s)", plainText.c_str());
129 logMessage += "----------------------<br>";
130 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
132 dlog_print(DLOG_INFO, LOG_TAG, "#### onPost callback received EXIT!!!!");
135 // Method for Creating the action Set AllBulbOff
136 static void createActionSet_AllBulbOff()
138 dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff ENTRY");
140 OIC::ActionSet *actionSet = new OIC::ActionSet();
141 actionSet->actionsetName = BULBOFF;
142 int size = lights.size();
146 string logMessage = "NO LIGHTSERVER FOUND <br>";
147 logMessage += "----------------------<br>";
148 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
149 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
155 for (int i = 0; i < size; i++)
157 OIC::Action *action = new OIC::Action();
158 action->target = lights.at(i);
160 OIC::Capability *capability = new OIC::Capability();
161 capability->capability = "power";
162 capability->status = "off";
164 action->listOfCapability.push_back(capability);
165 actionSet->listOfAction.push_back(action);
167 dlog_print(DLOG_INFO, LOG_TAG, "#### G_URI: %s", g_resource->uri().c_str());
168 dlog_print(DLOG_INFO, LOG_TAG, "#### G_HOST: %S", g_resource->host().c_str());
174 groupThingsMgr->addActionSet(g_resource, actionSet, onPut);
177 catch (std::exception &e)
179 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
183 string logMessage = "Create actionset AllBulbOFF success <br>";
184 logMessage += "----------------------<br>";
185 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
186 dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff EXIT");
189 /* Method for Creating the action Set AllBulbOn
190 once we create the ActionSet we can execute Action Set using executeActionSetOn()
191 or delete using deleteActionSetOn() */
192 static void createActionSet_AllBulbOn()
194 dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOn ENTRY");
196 OIC::ActionSet *actionSet = new OIC::ActionSet();
197 actionSet->actionsetName = BULBON;
198 int size = lights.size();
202 string logMessage = "NO LIGHTSERVER FOUND <br>";
203 logMessage += "----------------------<br>";
204 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
205 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
210 for (int i = 0; i < size; i++)
212 OIC::Action *action = new OIC::Action();
213 action->target = lights.at(i);
215 OIC::Capability *capability = new OIC::Capability();
216 capability->capability = "power";
217 capability->status = "on";
219 action->listOfCapability.push_back(capability);
220 actionSet->listOfAction.push_back(action);
222 string URI = g_resource->uri();
223 string host = g_resource->host();
224 dlog_print(DLOG_INFO, LOG_TAG, "#### G_URI: %s", g_resource->uri().c_str());
225 dlog_print(DLOG_INFO, LOG_TAG, "#### G_HOST: %S", g_resource->host().c_str());
231 groupThingsMgr->addActionSet(g_resource, actionSet, onPut);
234 catch (std::exception &e)
236 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
240 string logMessage = "Create actionset AllBulbON success <br>";
241 logMessage += "----------------------<br>";
242 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
243 dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff OFF EXIT");
246 static void createRecursiveActionSet_AllBulbOn(void *data, Evas_Object *obj, void *event_info)
248 dlog_print(DLOG_INFO, LOG_TAG, "#### createRecursiveActionSet_AllBulbOn ENTRY");
249 string actionsetDesc;
250 ActionSet *allBulbOn = new ActionSet();
251 allBulbOn->type = OIC::ACTIONSET_TYPE::RECURSIVE;
253 allBulbOn->actionsetName = "AllBulbOnRecursiveCall";
254 allBulbOn->mTime.tm_year = 0;
255 allBulbOn->mTime.tm_mon = 0;
256 allBulbOn->mTime.tm_mday = 0;
257 allBulbOn->mTime.tm_hour = 0;
258 allBulbOn->mTime.tm_min = 0;
259 allBulbOn->mTime.tm_sec = 5;
261 allBulbOn->setDelay(allBulbOn->getSecAbsTime());
263 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
265 Action *action = new Action();
266 action->target = (*iter);
268 Capability *capa = new Capability();
269 capa->capability = "power";
272 action->listOfCapability.push_back(capa);
273 allBulbOn->listOfAction.push_back(action);
277 groupThingsMgr->addActionSet(g_resource, allBulbOn, onPut);
281 dlog_print(DLOG_INFO, LOG_TAG, "#### createRecursiveActionSet_AllBulbOn EXIT");
284 static void createScheduledActionSet_AllBulbOff(int date, int month, int year,
285 int hour, int minute, int second)
287 dlog_print(DLOG_INFO, LOG_TAG, "#### createScheduledActionSet_AllBulbOff ENTRY");
288 string actionsetDesc;
289 ActionSet *allBulbOff = new ActionSet();
290 allBulbOff->type = OIC::ACTIONSET_TYPE::SCHEDULED;
291 allBulbOff->actionsetName = "AllBulbOffScheduledCall";
292 allBulbOff->mTime.tm_year = year;
293 allBulbOff->mTime.tm_mon = month;
294 allBulbOff->mTime.tm_mday = date;
295 allBulbOff->mTime.tm_hour = hour;
296 allBulbOff->mTime.tm_min = minute;
297 allBulbOff->mTime.tm_sec = second;
298 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_year :: %ld",
299 allBulbOff->mTime.tm_year);
300 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_mon :: %ld",
301 allBulbOff->mTime.tm_mon);
302 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_mday :: %ld",
303 allBulbOff->mTime.tm_mday);
304 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_hour :: %ld",
305 allBulbOff->mTime.tm_hour);
306 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_min :: %ld",
307 allBulbOff->mTime.tm_min);
308 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_sec :: %ld",
309 allBulbOff->mTime.tm_sec);
311 allBulbOff->setDelay(allBulbOff->getSecondsFromAbsoluteTime());
313 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
315 Action *action = new Action();
316 action->target = (*iter);
318 Capability *capa = new Capability();
319 capa->capability = "power";
320 capa->status = "off";
322 action->listOfCapability.push_back(capa);
323 allBulbOff->listOfAction.push_back(action);
327 groupThingsMgr->addActionSet(g_resource, allBulbOff, onPut);
331 dlog_print(DLOG_INFO, LOG_TAG, "#### createScheduledActionSet_AllBulbOff EXIT");
334 static void scheduled_AllbulbOff(void *data, Evas_Object *obj, void *event_info)
336 groupThingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
339 static void scheduled_AllbulbOffEx(void *data, Evas_Object *obj, void *event_info)
341 groupThingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", 10, &onPost);
344 static void cancelScheduled_AllBulbOff(void *data, Evas_Object *obj, void *event_info)
346 groupThingsMgr->cancelActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
349 static void recursive_allBulbOn(void *data, Evas_Object *obj, void *event_info)
351 groupThingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
354 static void recursive_allBulbOnEx(void *data, Evas_Object *obj, void *event_info)
356 groupThingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", 10, &onPost);
359 static void cancelRecursive_allBulbOn(void *data, Evas_Object *obj, void *event_info)
362 groupThingsMgr->cancelActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
365 /* Method for executing the action Set AllBulbOff that we have created using
366 createActionSet_AllBulbOff() */
367 static void executeActionSetOff(void *data, Evas_Object *obj, void *event_info)
369 dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOff ENTRY");
370 int size = lights.size();
374 string logMessage = "NO LIGHTSERVER FOUND <br>";
375 logMessage += "----------------------<br>";
376 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
377 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
385 groupThingsMgr->executeActionSet(g_resource, BULBOFF, &onPost);
388 catch (std::exception &e)
390 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
393 string logMessage = "Actionset OFF called successfully <br>";
394 logMessage += "----------------------<br>";
395 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
396 dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOff EXIT");
399 /* Method for executing the action Set AllBulbOn that we have created using
400 createActionSet_AllBulbOn() */
401 static void executeActionSetOn(void *data, Evas_Object *obj, void *event_info)
403 dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOn ENTRY");
404 int size = lights.size();
408 string logMessage = "NO LIGHTSERVER FOUND <br>";
409 logMessage += "----------------------<br>";
410 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
411 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
419 groupThingsMgr->executeActionSet(g_resource, BULBON, &onPost);
422 catch (std::exception &e)
424 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
427 string logMessage = "Actionset ON called successfully <br>";
428 logMessage += "----------------------<br>";
429 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
430 dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOn EXIT");
433 /* Method for getting the action Set AllBulbOff that we have created using
434 createActionSet_AllBulbOff() */
435 static void getActionSetOff(void *data, Evas_Object *obj, void *event_info)
437 dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOff ENTRY");
438 int size = lights.size();
442 string logMessage = "NO LIGHTSERVER FOUND <br>";
443 logMessage += "----------------------<br>";
444 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
445 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
453 groupThingsMgr->getActionSet(g_resource, BULBOFF, &onPost);
456 catch (std::exception &e)
458 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
461 dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOff EXIT");
464 /* Method for getting the action Set AllBulbOn that we have created using
465 createActionSet_AllBulbOn() */
466 static void getActionSetOn(void *data, Evas_Object *obj, void *event_info)
468 dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOn ENTRY");
469 int size = lights.size();
473 string logMessage = "NO LIGHTSERVER FOUND <br>";
474 logMessage += "----------------------<br>";
475 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
476 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
484 groupThingsMgr->getActionSet(g_resource, BULBON, &onPost);
487 catch (std::exception &e)
489 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
492 dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOn EXIT");
495 /* Method for deleting the action Set AllBulbOff that we have created using
496 createActionSet_AllBulbOff() */
497 static void deleteActionSetOff(void *data, Evas_Object *obj, void *event_info)
499 dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOff ENTRY");
500 int size = lights.size();
504 string logMessage = "NO LIGHTSERVER FOUND <br>";
505 logMessage += "----------------------<br>";
506 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
507 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
515 groupThingsMgr->deleteActionSet(g_resource, BULBOFF, &onPost);
518 catch (std::exception &e)
520 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
523 string logMessage = "Actionset OFF DELETED <br>";
524 logMessage += "----------------------<br>";
525 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
526 dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOff EXIT");
529 /* Method for deleting the action Set AllBulbOn that we have created using
530 createActionSet_AllBulbOn() */
531 static void deleteActionSetOn(void *data, Evas_Object *obj, void *event_info)
533 dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOn ENTRY");
534 int size = lights.size();
538 string logMessage = "NO LIGHTSERVER FOUND <br>";
539 logMessage += "----------------------<br>";
540 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
541 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
549 groupThingsMgr->deleteActionSet(g_resource, BULBON, &onPost);
552 catch (std::exception &e)
554 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
557 string logMessage = "Actionset ON DELETED <br>";
558 logMessage += "----------------------<br>";
559 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
560 dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOn EXIT");
563 void onObserve(const HeaderOptions headerOptions, const OCRepresentation &rep, const int &eCode,
564 const int &sequenceNumber)
568 if (OC_STACK_OK == eCode)
571 buf = (char *)malloc(4 * sizeof(char));
574 dlog_print(DLOG_INFO, LOG_TAG, " buf malloc failed");
577 sprintf(buf, "%d", sequenceNumber);
578 logMessage = "OBSERVE RESULT <br>";
579 logMessage += "Sequencenumber:" + string(buf) + "<br>";
581 if (rep.getValue("level", level))
585 createActionSet_AllBulbOn();
586 executeActionSetOn(NULL, NULL, NULL);
590 createActionSet_AllBulbOff();
591 executeActionSetOff(NULL, NULL, NULL);
594 sprintf(buf, "%d", level);
595 logMessage += "level:" + string(buf) + "<br>";
599 logMessage = "onObserve error!!!";
601 logMessage += "----------------------<br>";
602 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
606 // Callback to be called when resources are found in the network
607 void foundResources(std::vector< std::shared_ptr< OC::OCResource > > listOfResource)
611 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResources entry!!!!");
613 for (auto rsrc = listOfResource.begin(); rsrc != listOfResource.end(); ++rsrc)
615 string resourceURI = (*rsrc)->uri();
616 string hostAddress = (*rsrc)->host();
618 dlog_print(DLOG_INFO, LOG_TAG, "#### found uri: %s", resourceURI.c_str());
619 dlog_print(DLOG_INFO, LOG_TAG, "#### found host address: %s", hostAddress.c_str());
620 string logMessage = "URI: " + resourceURI + "<br>";
621 logMessage = logMessage + "Host:" + hostAddress + "<br>";
622 logMessage += "----------------------<br>";
624 if (resourceURI == "/a/light")
627 found = std::find(lights.begin(), lights.end(),
628 hostAddress + resourceURI) != lights.end();
631 lights.push_back((hostAddress + resourceURI));
635 dlog_print(DLOG_INFO, LOG_TAG, "#### Registering Resource");
636 OCStackResult result = OCPlatform::registerResource(foundResourceHandle,
638 dlog_print(DLOG_INFO, LOG_TAG, "#### %s REGISTERED", resourceURI.c_str());
639 if (result == OC_STACK_OK)
641 OCPlatform::bindResource(resourceHandle, foundResourceHandle);
642 dlog_print(DLOG_INFO, LOG_TAG, "#### Bind Resource Done");
643 groupResourceHandleVector.push_back(foundResourceHandle);
647 dlog_print(DLOG_ERROR, LOG_TAG, "#### Register Resource ERROR");
650 catch (std::exception &e)
652 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
656 else if (resourceURI == "/core/bookmark")
658 logMessage += "OBSERVING : " + resourceURI + "<br>";
659 logMessage += "----------------------<br>";
660 (*rsrc)->observe(ObserveType::Observe, QueryParamsMap(), &onObserve);
661 dlog_print(DLOG_INFO, LOG_TAG, "#### after calling observe() for bookmark!!!!");
663 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
667 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResources exit!!!!");
671 dlog_print(DLOG_INFO, LOG_TAG, "#### Exception caught in foundResources");
675 static void create_group()
677 if (NULL != groupThingsMgr)
679 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources from "
681 vector< string > types;
682 types.push_back("core.light");
683 groupThingsMgr->findCandidateResources(types, &foundResources, 5);
688 dlog_print(DLOG_INFO, LOG_TAG, "#### calling registerResource from create_group!!!!");
689 OCPlatform::registerResource(resourceHandle, resourceURI, resourceTypeName,
690 BATCH_INTERFACE, NULL,
691 OC_DISCOVERABLE | OC_OBSERVABLE);
693 if (NULL != resourceHandle)
694 dlog_print(DLOG_INFO, LOG_TAG, "#### Obtained resourceHandle from "
695 "registerResource!!!!");
697 dlog_print(DLOG_INFO, LOG_TAG, "#### calling bindInterfaceToResource from "
699 OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
700 OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
702 catch (std::exception &e)
704 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
708 // Method for Finding the Light Resource
709 void findLightResource(void *data, Evas_Object *obj, void *event_info)
711 dlog_print(DLOG_INFO, LOG_TAG, "#### findLightResource ENTRY");
712 if (NULL != groupThingsMgr)
714 vector< string > types;
715 types.push_back("core.light");
716 OCStackResult result = groupThingsMgr->findCandidateResources(types, &foundResources, 5);
717 if (result == OC_STACK_OK)
719 dlog_print(DLOG_INFO, LOG_TAG, "#### create_group -- findCandidateResources :: "
724 dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources failed!!");
727 dlog_print(DLOG_INFO, LOG_TAG, "#### findLightResource EXIT");
730 // Method for observing the Bookmark Resource
731 void observeBookMark(void *data, Evas_Object *obj, void *event_info)
733 dlog_print(DLOG_INFO, LOG_TAG, "#### observeBookMark ENTRY");
734 if (NULL != groupThingsMgr)
736 vector< string > types;
737 types.push_back("core.bookmark");
738 OCStackResult result = groupThingsMgr->findCandidateResources(types, &foundResources, 5);
739 if (OC_STACK_OK == result)
741 dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources :: "
746 dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources failed!!");
749 dlog_print(DLOG_INFO, LOG_TAG, "#### observeBookMark EXIT");
752 static void onDestroy()
754 dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called");
758 if (NULL != foundResourceHandle)
760 OCPlatform::unregisterResource(foundResourceHandle);
761 dlog_print(DLOG_INFO, LOG_TAG, "#### Light Resource unregistered");
766 dlog_print(DLOG_INFO, LOG_TAG, "#### No resouceHandle found to unregister");
769 catch (std::exception &e)
771 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
776 if (NULL != resourceHandle)
778 // Unbind Light resource
779 if (NULL != foundResourceHandle)
781 OCPlatform::unbindResource(resourceHandle, foundResourceHandle);
782 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource Unbind Done");
784 OCPlatform::unregisterResource(resourceHandle);
785 dlog_print(DLOG_INFO, LOG_TAG, "#### Group Unregistered");
789 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResourceHandle is NULL");
792 catch (std::exception &e)
794 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
798 static void createActionSet(void *data, Evas_Object *obj, void *event_info)
800 createActionSet_AllBulbOff();
801 createActionSet_AllBulbOn();
805 popup_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
807 datetime_popup_fields *popup_fields = (datetime_popup_fields *)data;
808 evas_object_del(popup_fields->popup);
812 static int parseString(const char *str, int slen, int *beg, int what)
814 int i, val = 0, ch = '/';
830 // Remove whitespaces(if any) at the beginning
831 while (str[*beg] == ' ')
835 for (i = *beg; i < slen; i++)
839 val = (val * 10) + (str[i] - 48);
848 static bool validate(int date, int month, int year, int hour, int minute, int second)
850 if (date <= 0 || month <= 0 || year <= 0 || hour < 0 || minute < 0 || second < 0
851 || month >= 13 || hour >= 24 || minute >= 60 || second >= 60)
859 popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info)
861 datetime_popup_fields *popup_fields = (datetime_popup_fields *)data;
862 Evas_Object *entry = popup_fields->entry;
863 const char *dateTimeValue = elm_entry_entry_get(entry);
865 len = strlen(dateTimeValue);
866 if (NULL == dateTimeValue || 1 > len)
868 dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL DateTime Value");
869 string logMessage = "DateTime should not be NULL<br>";
870 logMessage += "----------------------<br>";
871 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
875 int date, month, year, hour, minute, second;
877 date = parseString(dateTimeValue, len, &beg, 0);
878 month = parseString(dateTimeValue, len, &beg, 1);
879 year = parseString(dateTimeValue, len, &beg, 2);
880 hour = parseString(dateTimeValue, len, &beg, 3);
881 minute = parseString(dateTimeValue, len, &beg, 4);
882 second = parseString(dateTimeValue, len, &beg, 5);
884 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", date);
885 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", month);
886 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", year);
887 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", hour);
888 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", minute);
889 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", second);
890 bool valid = validate(date, month, year, hour, minute, second);
893 createScheduledActionSet_AllBulbOff(date, month, year, hour, minute, second);
897 dlog_print(DLOG_INFO, LOG_TAG, "#### Incorrect date/time values");
898 string logMessage = "Incorrect date/time value<br>";
899 logMessage += "----------------------<br>";
900 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
904 evas_object_del(popup_fields->popup);
909 list_scheduled_actionset_cb(void *data, Evas_Object *obj, void *event_info)
911 Evas_Object *popup, *btn;
912 Evas_Object *nf = naviframe;
917 popup = elm_popup_add(nf);
918 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
919 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
920 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
921 elm_object_part_text_set(popup, "title,text", "Enter the date and time");
923 layout = elm_layout_add(popup);
924 elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_datetime_text");
925 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
926 elm_object_content_set(popup, layout);
928 entry = elm_entry_add(layout);
929 elm_entry_single_line_set(entry, EINA_TRUE);
930 elm_entry_scrollable_set(entry, EINA_TRUE);
931 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
932 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
933 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
934 elm_object_part_text_set(entry, "elm.guide", "dd/mm/yyyy hh:mm:ss");
935 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER);
936 elm_object_part_content_set(layout, "elm.swallow.content", entry);
938 datetime_popup_fields *popup_fields;
939 popup_fields = (datetime_popup_fields *)malloc(sizeof(datetime_popup_fields));
940 if (NULL == popup_fields)
942 dlog_print(DLOG_INFO, LOG_TAG, "#### Memory allocation failed");
943 popup_fields->popup = NULL;
944 popup_fields->entry = NULL;
948 popup_fields->popup = popup;
949 popup_fields->entry = entry;
953 btn = elm_button_add(popup);
954 elm_object_style_set(btn, "popup");
955 elm_object_text_set(btn, "Cancel");
956 elm_object_part_content_set(popup, "button1", btn);
957 evas_object_smart_callback_add(btn, "clicked", popup_cancel_clicked_cb, popup_fields);
960 btn = elm_button_add(popup);
961 elm_object_style_set(btn, "popup");
962 elm_object_text_set(btn, "Set");
963 elm_object_part_content_set(popup, "button2", btn);
964 evas_object_smart_callback_add(btn, "clicked", popup_set_clicked_cb, popup_fields);
966 evas_object_show(popup);
969 void *showGroupAPIs(void *data)
971 // Add items to the list only if the list is empty
972 const Eina_List *eina_list = elm_list_items_get(list);
973 int count = eina_list_count(eina_list);
976 elm_list_item_append(list, "1. Create ActionSet<br>(ALLBULBON and ALLBULBOFF)", NULL, NULL,
977 createActionSet, NULL);
979 elm_list_item_append(list, "2. Execute ActionSet (ALLBULBON)", NULL, NULL,
980 executeActionSetOn, NULL);
982 elm_list_item_append(list, "3. Execute ActionSet (ALLBULBOFF)", NULL, NULL,
983 executeActionSetOff, NULL);
985 elm_list_item_append(list, "4. Create ActionSet<br>(Recursive_ALLBULBON)", NULL, NULL,
986 createRecursiveActionSet_AllBulbOn, NULL);
988 elm_list_item_append(list, " 4.1 Execute ActionSet", NULL, NULL,
989 recursive_allBulbOn, NULL);
991 elm_list_item_append(list, " 4.2 Cancel ActionSet", NULL, NULL,
992 cancelRecursive_allBulbOn, NULL);
994 elm_list_item_append(list, "5. Create ActionSet<br>(Scheduled_ALLBULBOFF)", NULL, NULL,
995 list_scheduled_actionset_cb, NULL);
997 elm_list_item_append(list, " 5.1 Execute ActionSet", NULL, NULL,
998 scheduled_AllbulbOff, NULL);
1000 elm_list_item_append(list, " 5.2 Cancel ActionSet", NULL, NULL,
1001 cancelScheduled_AllBulbOff, NULL);
1003 elm_list_item_append(list, "6. Get ActionSet (All BULBOFF)", NULL, NULL,
1004 getActionSetOff, NULL);
1006 elm_list_item_append(list, "7. Delete ActionSet (All BULBOFF)", NULL, NULL,
1007 deleteActionSetOff, NULL);
1009 elm_list_item_append(list, "8. Find BookMark to Observe", NULL, NULL,
1010 observeBookMark, NULL);
1017 // Callback to be called when a resource is found in the network
1018 void foundResource(shared_ptr< OCResource > resource)
1020 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResource entry!!!!");
1024 string resourceURI = resource->uri();
1025 string hostAddress = resource->host();
1027 if (resourceURI == "/core/b/collection")
1029 g_resource = resource;
1030 dlog_print(DLOG_INFO, LOG_TAG, "#### FOUND URI: %s", resourceURI.c_str());
1031 dlog_print(DLOG_INFO, LOG_TAG, "#### FOUND HOST: %s", hostAddress.c_str());
1032 logMessage = "FOUND RESOURCE URI <br>" + resourceURI + "<br>";
1033 logMessage += "FOUND RESOURCE HOST <br>" + hostAddress + "<br>";
1034 logMessage += "----------------------<br>";
1035 // Show the UI list of group APIs
1036 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showGroupAPIs, NULL);
1039 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
1043 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResource exit!!!!");
1046 static void list_selected_cb(void *data, Evas_Object *obj, void *event_info)
1048 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
1049 elm_list_item_selected_set(it, EINA_FALSE);
1052 // Method for Finding the Group
1053 static void find_group()
1055 dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup ENTRY");
1056 vector< string > resourceTypes;
1057 resourceTypes.push_back(resourceTypeName);
1058 OCStackResult result = groupThingsMgr->findGroup(resourceTypes, &foundResource);
1059 if (OC_STACK_OK == result)
1061 dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup returned OC_STACK_OK");
1065 dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup failed");
1067 dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup EXIT");
1070 // Method to be called when the Find Group UI Button is selected
1072 find_group_cb(void *data, Evas_Object *obj, void *event_info)
1080 dlog_print(DLOG_ERROR, "find_group_cb", "list is NULL - So unable to add items!!!");
1085 naviframe_pop_cb(void *data, Elm_Object_Item *it)
1089 if (NULL != log_entry)
1091 evas_object_del(log_entry);
1096 evas_object_del(list);
1102 // Method to be called when the Group APIs UI Button is selected
1103 void group_cb(void *data, Evas_Object *obj, void *event_info)
1105 Evas_Object *layout;
1106 Evas_Object *scroller;
1107 Evas_Object *nf = (Evas_Object *)data;
1108 Evas_Object *find_button;
1109 Elm_Object_Item *nf_it;
1114 scroller = elm_scroller_add(nf);
1115 elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
1116 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
1119 layout = elm_layout_add(nf);
1120 elm_layout_file_set(layout, ELM_DEMO_EDJ, "group_layout");
1121 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1123 elm_object_content_set(scroller, layout);
1126 find_button = elm_button_add(layout);
1127 elm_object_part_content_set(layout, "find_button", find_button);
1128 elm_object_text_set(find_button, "Find Group");
1129 evas_object_smart_callback_add(find_button, "clicked", find_group_cb, NULL);
1132 list = elm_list_add(layout);
1133 elm_list_mode_set(list, ELM_LIST_COMPRESS);
1134 evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
1135 elm_object_part_content_set(layout, "list", list);
1138 // log_entry - textarea for log
1139 log_entry = elm_entry_add(layout);
1140 elm_entry_scrollable_set(log_entry, EINA_TRUE);
1141 elm_entry_editable_set(log_entry, EINA_FALSE);
1142 elm_object_part_text_set(log_entry, "elm.guide", "Logs will be updated here!!!");
1143 evas_object_size_hint_weight_set(log_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1144 evas_object_size_hint_align_set(log_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
1145 elm_object_part_content_set(layout, "log", log_entry);
1147 nf_it = elm_naviframe_item_push(nf, "Group APIs", NULL, NULL, scroller, NULL);
1148 elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL);