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 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
80 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
84 void onPost(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
86 dlog_print(DLOG_INFO, LOG_TAG, "#### onPost callback received ENTRY!!!!");
88 logMessage += "API Result: Success<br>onPost Callback Received<br>";
90 if (rep.hasAttribute("ActionSet"))
93 if (rep.getValue("ActionSet", plainText))
95 ActionSet *actionset = groupThingsMgr->getActionSetfromString(plainText);
96 if (NULL != actionset)
98 dlog_print(DLOG_INFO, LOG_TAG, "#### ACTIONSET NAME :: (%s)",
99 actionset->actionsetName.c_str());
100 logMessage += "ACTIONSET NAME :: " + actionset->actionsetName + "<br>";
101 for (auto actIter = actionset->listOfAction.begin();
102 actIter != actionset->listOfAction.end(); ++actIter)
104 dlog_print(DLOG_INFO, LOG_TAG, "#### TARGET :: (%s)",
105 (*actIter)->target.c_str());
106 logMessage += logMessage + "TARGET :: " + (*actIter)->target + "<br>";
107 for (auto capaIter = (*actIter)->listOfCapability.begin();
108 capaIter != (*actIter)->listOfCapability.end(); ++capaIter)
110 dlog_print(DLOG_INFO, LOG_TAG, "#### POWER :: (%s)",
111 (*capaIter)->status.c_str());
112 logMessage += logMessage + "CAPABILITY :: " +
113 (*capaIter)->status + "<br>";
120 else if (rep.hasAttribute("DoAction"))
123 if (rep.getValue("DoAction", plainText))
125 logMessage += plainText + "<br>";
126 dlog_print(DLOG_INFO, LOG_TAG, "#### DO ACTION :: (%s)", plainText.c_str());
130 logMessage += "----------------------<br>";
131 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
132 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
134 dlog_print(DLOG_INFO, LOG_TAG, "#### onPost callback received EXIT!!!!");
137 // Method for Creating the action Set AllBulbOff
138 static void createActionSet_AllBulbOff()
140 dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff ENTRY");
142 OIC::ActionSet *actionSet = new OIC::ActionSet();
143 actionSet->actionsetName = BULBOFF;
144 int size = lights.size();
148 string logMessage = "NO LIGHTSERVER FOUND <br>";
149 logMessage += "----------------------<br>";
150 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
151 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
152 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
158 for (int i = 0; i < size; i++)
160 OIC::Action *action = new OIC::Action();
161 action->target = lights.at(i);
163 OIC::Capability *capability = new OIC::Capability();
164 capability->capability = "power";
165 capability->status = "off";
167 action->listOfCapability.push_back(capability);
168 actionSet->listOfAction.push_back(action);
170 dlog_print(DLOG_INFO, LOG_TAG, "#### G_URI: %s", g_resource->uri().c_str());
171 dlog_print(DLOG_INFO, LOG_TAG, "#### G_HOST: %S", g_resource->host().c_str());
177 groupThingsMgr->addActionSet(g_resource, actionSet, onPut);
180 catch (std::exception &e)
182 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
186 string logMessage = "Create actionset AllBulbOFF success <br>";
187 logMessage += "----------------------<br>";
188 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
189 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
190 dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff EXIT");
193 /* Method for Creating the action Set AllBulbOn
194 once we create the ActionSet we can execute Action Set using executeActionSetOn()
195 or delete using deleteActionSetOn() */
196 static void createActionSet_AllBulbOn()
198 dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOn ENTRY");
200 OIC::ActionSet *actionSet = new OIC::ActionSet();
201 actionSet->actionsetName = BULBON;
202 int size = lights.size();
206 string logMessage = "NO LIGHTSERVER FOUND <br>";
207 logMessage += "----------------------<br>";
208 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
209 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
214 for (int i = 0; i < size; i++)
216 OIC::Action *action = new OIC::Action();
217 action->target = lights.at(i);
219 OIC::Capability *capability = new OIC::Capability();
220 capability->capability = "power";
221 capability->status = "on";
223 action->listOfCapability.push_back(capability);
224 actionSet->listOfAction.push_back(action);
226 string URI = g_resource->uri();
227 string host = g_resource->host();
228 dlog_print(DLOG_INFO, LOG_TAG, "#### G_URI: %s", g_resource->uri().c_str());
229 dlog_print(DLOG_INFO, LOG_TAG, "#### G_HOST: %S", g_resource->host().c_str());
235 groupThingsMgr->addActionSet(g_resource, actionSet, onPut);
238 catch (std::exception &e)
240 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
244 string logMessage = "Create actionset AllBulbON success <br>";
245 logMessage += "----------------------<br>";
246 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
247 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
248 dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff OFF EXIT");
251 static void createRecursiveActionSet_AllBulbOn(void *data, Evas_Object *obj, void *event_info)
253 dlog_print(DLOG_INFO, LOG_TAG, "#### createRecursiveActionSet_AllBulbOn ENTRY");
254 string actionsetDesc;
255 ActionSet *allBulbOn = new ActionSet();
256 allBulbOn->type = OIC::ACTIONSET_TYPE::RECURSIVE;
258 allBulbOn->actionsetName = "AllBulbOnRecursiveCall";
259 allBulbOn->mTime.tm_year = 0;
260 allBulbOn->mTime.tm_mon = 0;
261 allBulbOn->mTime.tm_mday = 0;
262 allBulbOn->mTime.tm_hour = 0;
263 allBulbOn->mTime.tm_min = 0;
264 allBulbOn->mTime.tm_sec = 5;
266 allBulbOn->setDelay(allBulbOn->getSecAbsTime());
268 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
270 Action *action = new Action();
271 action->target = (*iter);
273 Capability *capa = new Capability();
274 capa->capability = "power";
277 action->listOfCapability.push_back(capa);
278 allBulbOn->listOfAction.push_back(action);
282 groupThingsMgr->addActionSet(g_resource, allBulbOn, onPut);
286 dlog_print(DLOG_INFO, LOG_TAG, "#### createRecursiveActionSet_AllBulbOn EXIT");
289 static void createScheduledActionSet_AllBulbOff(int date, int month, int year,
290 int hour, int minute, int second)
292 dlog_print(DLOG_INFO, LOG_TAG, "#### createScheduledActionSet_AllBulbOff ENTRY");
293 string actionsetDesc;
294 ActionSet *allBulbOff = new ActionSet();
295 allBulbOff->type = OIC::ACTIONSET_TYPE::SCHEDULED;
296 allBulbOff->actionsetName = "AllBulbOffScheduledCall";
297 allBulbOff->mTime.tm_year = year;
298 allBulbOff->mTime.tm_mon = month;
299 allBulbOff->mTime.tm_mday = date;
300 allBulbOff->mTime.tm_hour = hour;
301 allBulbOff->mTime.tm_min = minute;
302 allBulbOff->mTime.tm_sec = second;
303 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_year :: %ld",
304 allBulbOff->mTime.tm_year);
305 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_mon :: %ld",
306 allBulbOff->mTime.tm_mon);
307 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_mday :: %ld",
308 allBulbOff->mTime.tm_mday);
309 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_hour :: %ld",
310 allBulbOff->mTime.tm_hour);
311 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_min :: %ld",
312 allBulbOff->mTime.tm_min);
313 dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_sec :: %ld",
314 allBulbOff->mTime.tm_sec);
316 allBulbOff->setDelay(allBulbOff->getSecondsFromAbsoluteTime());
318 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
320 Action *action = new Action();
321 action->target = (*iter);
323 Capability *capa = new Capability();
324 capa->capability = "power";
325 capa->status = "off";
327 action->listOfCapability.push_back(capa);
328 allBulbOff->listOfAction.push_back(action);
332 groupThingsMgr->addActionSet(g_resource, allBulbOff, onPut);
336 dlog_print(DLOG_INFO, LOG_TAG, "#### createScheduledActionSet_AllBulbOff EXIT");
339 static void scheduled_AllbulbOff(void *data, Evas_Object *obj, void *event_info)
341 groupThingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
344 static void scheduled_AllbulbOffEx(void *data, Evas_Object *obj, void *event_info)
346 groupThingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", 10, &onPost);
349 static void cancelScheduled_AllBulbOff(void *data, Evas_Object *obj, void *event_info)
351 groupThingsMgr->cancelActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
354 static void recursive_allBulbOn(void *data, Evas_Object *obj, void *event_info)
356 groupThingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
359 static void recursive_allBulbOnEx(void *data, Evas_Object *obj, void *event_info)
361 groupThingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", 10, &onPost);
364 static void cancelRecursive_allBulbOn(void *data, Evas_Object *obj, void *event_info)
367 groupThingsMgr->cancelActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
370 /* Method for executing the action Set AllBulbOff that we have created using
371 createActionSet_AllBulbOff() */
372 static void executeActionSetOff(void *data, Evas_Object *obj, void *event_info)
374 dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOff ENTRY");
375 int size = lights.size();
379 string logMessage = "NO LIGHTSERVER FOUND <br>";
380 logMessage += "----------------------<br>";
381 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
382 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
390 groupThingsMgr->executeActionSet(g_resource, BULBOFF, &onPost);
393 catch (std::exception &e)
395 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
398 string logMessage = "Actionset OFF called successfully <br>";
399 logMessage += "----------------------<br>";
400 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
401 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
402 dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOff EXIT");
405 /* Method for executing the action Set AllBulbOn that we have created using
406 createActionSet_AllBulbOn() */
407 static void executeActionSetOn(void *data, Evas_Object *obj, void *event_info)
409 dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOn ENTRY");
410 int size = lights.size();
414 string logMessage = "NO LIGHTSERVER FOUND <br>";
415 logMessage += "----------------------<br>";
416 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
417 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
425 groupThingsMgr->executeActionSet(g_resource, BULBON, &onPost);
428 catch (std::exception &e)
430 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
433 string logMessage = "Actionset ON called successfully <br>";
434 logMessage += "----------------------<br>";
435 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
436 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
437 dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOn EXIT");
440 /* Method for getting the action Set AllBulbOff that we have created using
441 createActionSet_AllBulbOff() */
442 static void getActionSetOff(void *data, Evas_Object *obj, void *event_info)
444 dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOff ENTRY");
445 int size = lights.size();
449 string logMessage = "NO LIGHTSERVER FOUND <br>";
450 logMessage += "----------------------<br>";
451 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
452 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
460 groupThingsMgr->getActionSet(g_resource, BULBOFF, &onPost);
463 catch (std::exception &e)
465 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
468 dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOff EXIT");
471 /* Method for getting the action Set AllBulbOn that we have created using
472 createActionSet_AllBulbOn() */
473 static void getActionSetOn(void *data, Evas_Object *obj, void *event_info)
475 dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOn ENTRY");
476 int size = lights.size();
480 string logMessage = "NO LIGHTSERVER FOUND <br>";
481 logMessage += "----------------------<br>";
482 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
483 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
491 groupThingsMgr->getActionSet(g_resource, BULBON, &onPost);
494 catch (std::exception &e)
496 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
499 dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOn EXIT");
502 /* Method for deleting the action Set AllBulbOff that we have created using
503 createActionSet_AllBulbOff() */
504 static void deleteActionSetOff(void *data, Evas_Object *obj, void *event_info)
506 dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOff ENTRY");
507 int size = lights.size();
511 string logMessage = "NO LIGHTSERVER FOUND <br>";
512 logMessage += "----------------------<br>";
513 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
514 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
522 groupThingsMgr->deleteActionSet(g_resource, BULBOFF, &onPost);
525 catch (std::exception &e)
527 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
530 string logMessage = "Actionset OFF DELETED <br>";
531 logMessage += "----------------------<br>";
532 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
533 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
534 dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOff EXIT");
537 /* Method for deleting the action Set AllBulbOn that we have created using
538 createActionSet_AllBulbOn() */
539 static void deleteActionSetOn(void *data, Evas_Object *obj, void *event_info)
541 dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOn ENTRY");
542 int size = lights.size();
546 string logMessage = "NO LIGHTSERVER FOUND <br>";
547 logMessage += "----------------------<br>";
548 dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
549 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
557 groupThingsMgr->deleteActionSet(g_resource, BULBON, &onPost);
560 catch (std::exception &e)
562 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
565 string logMessage = "Actionset ON DELETED <br>";
566 logMessage += "----------------------<br>";
567 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
568 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
569 dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOn EXIT");
572 void onObserve(const HeaderOptions headerOptions, const OCRepresentation &rep, const int &eCode,
573 const int &sequenceNumber)
577 if (OC_STACK_OK == eCode)
580 buf = (char *)malloc(4 * sizeof(char));
583 dlog_print(DLOG_INFO, LOG_TAG, " buf malloc failed");
586 sprintf(buf, "%d", sequenceNumber);
587 logMessage = "OBSERVE RESULT <br>";
588 logMessage += "Sequencenumber:" + string(buf) + "<br>";
590 if (rep.getValue("level", level))
594 createActionSet_AllBulbOn();
595 executeActionSetOn(NULL, NULL, NULL);
599 createActionSet_AllBulbOff();
600 executeActionSetOff(NULL, NULL, NULL);
603 sprintf(buf, "%d", level);
604 logMessage += "level:" + string(buf) + "<br>";
609 logMessage = "onObserve error!!!";
611 logMessage += "----------------------<br>";
612 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
613 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
617 // Callback to be called when resources are found in the network
618 void foundResources(std::vector< std::shared_ptr< OC::OCResource > > listOfResource)
622 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResources entry!!!!");
624 for (auto rsrc = listOfResource.begin(); rsrc != listOfResource.end(); ++rsrc)
626 string resourceURI = (*rsrc)->uri();
627 string hostAddress = (*rsrc)->host();
629 dlog_print(DLOG_INFO, LOG_TAG, "#### found uri: %s", resourceURI.c_str());
630 dlog_print(DLOG_INFO, LOG_TAG, "#### found host address: %s", hostAddress.c_str());
631 string logMessage = "URI: " + resourceURI + "<br>";
632 logMessage = logMessage + "Host:" + hostAddress + "<br>";
633 logMessage += "----------------------<br>";
635 if (resourceURI == "/a/light")
638 found = std::find(lights.begin(), lights.end(),
639 hostAddress + resourceURI) != lights.end();
642 lights.push_back((hostAddress + resourceURI));
646 dlog_print(DLOG_INFO, LOG_TAG, "#### Registering Resource");
647 OCStackResult result = OCPlatform::registerResource(foundResourceHandle,
649 dlog_print(DLOG_INFO, LOG_TAG, "#### %s REGISTERED", resourceURI.c_str());
650 if (result == OC_STACK_OK)
652 OCPlatform::bindResource(resourceHandle, foundResourceHandle);
653 dlog_print(DLOG_INFO, LOG_TAG, "#### Bind Resource Done");
654 groupResourceHandleVector.push_back(foundResourceHandle);
658 dlog_print(DLOG_ERROR, LOG_TAG, "#### Register Resource ERROR");
661 catch (std::exception &e)
663 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
667 else if (resourceURI == "/core/bookmark")
669 logMessage += "OBSERVING : " + resourceURI + "<br>";
670 logMessage += "----------------------<br>";
671 (*rsrc)->observe(ObserveType::Observe, QueryParamsMap(), &onObserve);
672 dlog_print(DLOG_INFO, LOG_TAG, "#### after calling observe() for bookmark!!!!");
674 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
675 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
679 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResources exit!!!!");
683 dlog_print(DLOG_INFO, LOG_TAG, "#### Exception caught in foundResources");
687 static void create_group()
689 if (NULL != groupThingsMgr)
691 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources from "
693 vector< string > types;
694 types.push_back("core.light");
695 groupThingsMgr->findCandidateResources(types, &foundResources, 5);
700 dlog_print(DLOG_INFO, LOG_TAG, "#### calling registerResource from create_group!!!!");
701 OCPlatform::registerResource(resourceHandle, resourceURI, resourceTypeName,
702 BATCH_INTERFACE, NULL,
703 OC_DISCOVERABLE | OC_OBSERVABLE);
705 if (NULL != resourceHandle)
706 dlog_print(DLOG_INFO, LOG_TAG, "#### Obtained resourceHandle from "
707 "registerResource!!!!");
709 dlog_print(DLOG_INFO, LOG_TAG, "#### calling bindInterfaceToResource from "
711 OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
712 OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
714 catch (std::exception &e)
716 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
720 // Method for Finding the Light Resource
721 void findLightResource(void *data, Evas_Object *obj, void *event_info)
723 dlog_print(DLOG_INFO, LOG_TAG, "#### findLightResource ENTRY");
724 if (NULL != groupThingsMgr)
726 vector< string > types;
727 types.push_back("core.light");
728 OCStackResult result = groupThingsMgr->findCandidateResources(types, &foundResources, 5);
729 if (result == OC_STACK_OK)
731 dlog_print(DLOG_INFO, LOG_TAG, "#### create_group -- findCandidateResources :: "
736 dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources failed!!");
739 dlog_print(DLOG_INFO, LOG_TAG, "#### findLightResource EXIT");
742 // Method for observing the Bookmark Resource
743 void observeBookMark(void *data, Evas_Object *obj, void *event_info)
745 dlog_print(DLOG_INFO, LOG_TAG, "#### observeBookMark ENTRY");
746 if (NULL != groupThingsMgr)
748 vector< string > types;
749 types.push_back("core.bookmark");
750 OCStackResult result = groupThingsMgr->findCandidateResources(types, &foundResources, 5);
751 if (OC_STACK_OK == result)
753 dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources :: "
758 dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources failed!!");
761 dlog_print(DLOG_INFO, LOG_TAG, "#### observeBookMark EXIT");
764 static void onDestroy()
766 dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called");
770 if (NULL != foundResourceHandle)
772 OCPlatform::unregisterResource(foundResourceHandle);
773 dlog_print(DLOG_INFO, LOG_TAG, "#### Light Resource unregistered");
778 dlog_print(DLOG_INFO, LOG_TAG, "#### No resouceHandle found to unregister");
781 catch (std::exception &e)
783 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
788 if (NULL != resourceHandle)
790 // Unbind Light resource
791 if (NULL != foundResourceHandle)
793 OCPlatform::unbindResource(resourceHandle, foundResourceHandle);
794 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource Unbind Done");
796 OCPlatform::unregisterResource(resourceHandle);
797 dlog_print(DLOG_INFO, LOG_TAG, "#### Group Unregistered");
801 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResourceHandle is NULL");
804 catch (std::exception &e)
806 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
810 static void createActionSet(void *data, Evas_Object *obj, void *event_info)
812 createActionSet_AllBulbOff();
813 createActionSet_AllBulbOn();
817 popup_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
819 datetime_popup_fields *popup_fields = (datetime_popup_fields *)data;
820 evas_object_del(popup_fields->popup);
824 static int parseString(const char *str, int slen, int *beg, int what)
826 int i, val = 0, ch = '/';
842 // Remove whitespaces(if any) at the beginning
843 while (str[*beg] == ' ')
847 for (i = *beg; i < slen; i++)
851 val = (val * 10) + (str[i] - 48);
860 static bool validate(int date, int month, int year, int hour, int minute, int second)
862 if (date <= 0 || month <= 0 || year <= 0 || hour < 0 || minute < 0 || second < 0
863 || month >= 13 || hour >= 24 || minute >= 60 || second >= 60)
871 popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info)
873 datetime_popup_fields *popup_fields = (datetime_popup_fields *)data;
874 Evas_Object *entry = popup_fields->entry;
875 const char *dateTimeValue = elm_entry_entry_get(entry);
877 len = strlen(dateTimeValue);
878 if (NULL == dateTimeValue || 1 > len)
880 dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL DateTime Value");
881 string logMessage = "DateTime should not be NULL<br>";
882 logMessage += "----------------------<br>";
883 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
884 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
888 int date, month, year, hour, minute, second;
890 date = parseString(dateTimeValue, len, &beg, 0);
891 month = parseString(dateTimeValue, len, &beg, 1);
892 year = parseString(dateTimeValue, len, &beg, 2);
893 hour = parseString(dateTimeValue, len, &beg, 3);
894 minute = parseString(dateTimeValue, len, &beg, 4);
895 second = parseString(dateTimeValue, len, &beg, 5);
897 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", date);
898 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", month);
899 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", year);
900 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", hour);
901 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", minute);
902 dlog_print(DLOG_INFO, LOG_TAG, "#### %d", second);
903 bool valid = validate(date, month, year, hour, minute, second);
906 createScheduledActionSet_AllBulbOff(date, month, year, hour, minute, second);
910 dlog_print(DLOG_INFO, LOG_TAG, "#### Incorrect date/time values");
911 string logMessage = "Incorrect date/time value<br>";
912 logMessage += "----------------------<br>";
913 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
914 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
918 evas_object_del(popup_fields->popup);
923 list_scheduled_actionset_cb(void *data, Evas_Object *obj, void *event_info)
925 Evas_Object *popup, *btn;
926 Evas_Object *nf = naviframe;
931 popup = elm_popup_add(nf);
932 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
933 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
934 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
935 elm_object_part_text_set(popup, "title,text", "Enter the date and time");
937 layout = elm_layout_add(popup);
938 elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_datetime_text");
939 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
940 elm_object_content_set(popup, layout);
942 entry = elm_entry_add(layout);
943 elm_entry_single_line_set(entry, EINA_TRUE);
944 elm_entry_scrollable_set(entry, EINA_TRUE);
945 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
946 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
947 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
948 elm_object_part_text_set(entry, "elm.guide", "dd/mm/yyyy hh:mm:ss");
949 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER);
950 elm_object_part_content_set(layout, "elm.swallow.content", entry);
952 datetime_popup_fields *popup_fields;
953 popup_fields = (datetime_popup_fields *)malloc(sizeof(datetime_popup_fields));
954 if (NULL == popup_fields)
956 dlog_print(DLOG_INFO, LOG_TAG, "#### Memory allocation failed");
960 popup_fields->popup = popup;
961 popup_fields->entry = entry;
965 btn = elm_button_add(popup);
966 elm_object_style_set(btn, "popup");
967 elm_object_text_set(btn, "Cancel");
968 elm_object_part_content_set(popup, "button1", btn);
969 evas_object_smart_callback_add(btn, "clicked", popup_cancel_clicked_cb, popup_fields);
972 btn = elm_button_add(popup);
973 elm_object_style_set(btn, "popup");
974 elm_object_text_set(btn, "Set");
975 elm_object_part_content_set(popup, "button2", btn);
976 evas_object_smart_callback_add(btn, "clicked", popup_set_clicked_cb, popup_fields);
978 evas_object_show(popup);
981 void *showGroupAPIs(void *data)
983 // Add items to the list only if the list is empty
984 const Eina_List *eina_list = elm_list_items_get(list);
985 int count = eina_list_count(eina_list);
988 elm_list_item_append(list, "1. Create ActionSet<br>(ALLBULBON and ALLBULBOFF)", NULL, NULL,
989 createActionSet, NULL);
991 elm_list_item_append(list, "2. Execute ActionSet (ALLBULBON)", NULL, NULL,
992 executeActionSetOn, NULL);
994 elm_list_item_append(list, "3. Execute ActionSet (ALLBULBOFF)", NULL, NULL,
995 executeActionSetOff, NULL);
997 elm_list_item_append(list, "4. Create ActionSet<br>(Recursive_ALLBULBON)", NULL, NULL,
998 createRecursiveActionSet_AllBulbOn, NULL);
1000 elm_list_item_append(list, " 4.1 Execute ActionSet", NULL, NULL,
1001 recursive_allBulbOn, NULL);
1003 elm_list_item_append(list, " 4.2 Cancel ActionSet", NULL, NULL,
1004 cancelRecursive_allBulbOn, NULL);
1006 elm_list_item_append(list, "5. Create ActionSet<br>(Scheduled_ALLBULBOFF)", NULL, NULL,
1007 list_scheduled_actionset_cb, NULL);
1009 elm_list_item_append(list, " 5.1 Execute ActionSet", NULL, NULL,
1010 scheduled_AllbulbOff, NULL);
1012 elm_list_item_append(list, " 5.2 Cancel ActionSet", NULL, NULL,
1013 cancelScheduled_AllBulbOff, NULL);
1015 elm_list_item_append(list, "6. Get ActionSet (All BULBOFF)", NULL, NULL,
1016 getActionSetOff, NULL);
1018 elm_list_item_append(list, "7. Delete ActionSet (All BULBOFF)", NULL, NULL,
1019 deleteActionSetOff, NULL);
1021 elm_list_item_append(list, "8. Find BookMark to Observe", NULL, NULL,
1022 observeBookMark, NULL);
1029 // Callback to be called when a resource is found in the network
1030 void foundResource(shared_ptr< OCResource > resource)
1032 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResource entry!!!!");
1036 string resourceURI = resource->uri();
1037 string hostAddress = resource->host();
1039 if (resourceURI == "/core/b/collection")
1041 g_resource = resource;
1042 dlog_print(DLOG_INFO, LOG_TAG, "#### FOUND URI: %s", resourceURI.c_str());
1043 dlog_print(DLOG_INFO, LOG_TAG, "#### FOUND HOST: %s", hostAddress.c_str());
1044 logMessage = "FOUND RESOURCE URI <br>" + resourceURI + "<br>";
1045 logMessage += "FOUND RESOURCE HOST <br>" + hostAddress + "<br>";
1046 logMessage += "----------------------<br>";
1047 // Show the UI list of group APIs
1048 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showGroupAPIs, NULL);
1051 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
1052 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
1056 dlog_print(DLOG_INFO, LOG_TAG, "#### foundResource exit!!!!");
1059 static void list_selected_cb(void *data, Evas_Object *obj, void *event_info)
1061 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
1062 elm_list_item_selected_set(it, EINA_FALSE);
1065 // Method for Finding the Group
1066 static void find_group()
1068 dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup ENTRY");
1069 vector< string > resourceTypes;
1070 resourceTypes.push_back(resourceTypeName);
1071 OCStackResult result = groupThingsMgr->findGroup(resourceTypes, &foundResource);
1072 if (OC_STACK_OK == result)
1074 dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup returned OC_STACK_OK");
1078 dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup failed");
1080 dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup EXIT");
1083 // Method to be called when the Find Group UI Button is selected
1085 find_group_cb(void *data, Evas_Object *obj, void *event_info)
1093 dlog_print(DLOG_ERROR, "find_group_cb", "list is NULL - So unable to add items!!!");
1098 naviframe_pop_cb(void *data, Elm_Object_Item *it)
1102 if (NULL != log_entry)
1104 evas_object_del(log_entry);
1109 evas_object_del(list);
1115 // Method to be called when the Group APIs UI Button is selected
1116 void group_cb(void *data, Evas_Object *obj, void *event_info)
1118 Evas_Object *layout;
1119 Evas_Object *scroller;
1120 Evas_Object *nf = (Evas_Object *)data;
1121 Evas_Object *find_button;
1122 Elm_Object_Item *nf_it;
1127 scroller = elm_scroller_add(nf);
1128 elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
1129 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
1132 layout = elm_layout_add(nf);
1133 elm_layout_file_set(layout, ELM_DEMO_EDJ, "group_layout");
1134 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1136 elm_object_content_set(scroller, layout);
1139 find_button = elm_button_add(layout);
1140 elm_object_part_content_set(layout, "find_button", find_button);
1141 elm_object_text_set(find_button, "Find Group");
1142 evas_object_smart_callback_add(find_button, "clicked", find_group_cb, NULL);
1145 list = elm_list_add(layout);
1146 elm_list_mode_set(list, ELM_LIST_COMPRESS);
1147 evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
1148 elm_object_part_content_set(layout, "list", list);
1151 // log_entry - textarea for log
1152 log_entry = elm_entry_add(layout);
1153 elm_entry_scrollable_set(log_entry, EINA_TRUE);
1154 elm_entry_editable_set(log_entry, EINA_FALSE);
1155 elm_object_part_text_set(log_entry, "elm.guide", "Logs will be updated here!!!");
1156 evas_object_size_hint_weight_set(log_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1157 evas_object_size_hint_align_set(log_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
1158 elm_object_part_content_set(layout, "log", log_entry);
1160 nf_it = elm_naviframe_item_push(nf, "Group APIs", NULL, NULL, scroller, NULL);
1161 elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL);