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 ******************************************************************/
21 #include "tmsampleapp.h"
28 int isWaiting = 0; // 0: none to wait, 1: wait for the response of "getConfigurationValue"
29 const int SUCCESS_RESPONSE = 0;
31 OCResourceHandle configurationCollectionHandle = NULL;
32 OCResourceHandle configurationFoundHandle = NULL;
33 std::shared_ptr< OCResource > g_configurationCollection; // For a group of multiple resources
34 std::shared_ptr< OCResource > g_configurationResource; // For a single resource
36 OCResourceHandle diagnosticsCollectionHandle = NULL;
37 OCResourceHandle diagnosticsFoundHandle = NULL;
38 std::shared_ptr< OCResource > g_diagnosticsCollection; // For a group of multiple resources
39 std::shared_ptr< OCResource > g_diagnosticsResource; // For a single resource
41 OCResourceHandle setCollectionHandle = NULL;
42 OCResourceHandle setFoundHandle = NULL;
43 std::shared_ptr< OCResource > g_setCollection; // For a group of multiple resources
44 std::shared_ptr< OCResource > g_setResource; // For a single resource
46 std::map< std::string, std::shared_ptr< OCResource > > resourceTable;
47 std::vector< OCResourceHandle > configResourceHandleVector;
49 typedef std::string ConfigurationName;
50 typedef std::string ConfigurationValue;
52 static Evas_Object *log_entry = NULL;
54 string CONFIGURATION_COLLECTION_RESOURCE_URI = "/core/a/configuration/resourceset";
55 string CONFIGURATION_COLLECTION_RESOURCE_TYPE = "core.configuration.resourceset";
56 string DIAGNOSTIC_COLLECTION_RESOURCE_URI = "/core/a/diagnostics/resourceset";
57 string DIAGNOSTIC_COLLECTION_RESOURCE_TYPE = "core.diagnostics.resourceset";
58 string FACTORYSET_COLLECTION_RESOURCE_URI = "/core/a/factoryset/resourceset";
59 string FACTORYSET_COLLECTION_RESOURCE_TYPE = "core.factoryset.resourceset";
61 string CONFIGURATION_RESOURCE_URI = "/oic/con";
62 string DIAGNOSTIC_RESOURCE_URI = "/oic/diag";
63 string FACTORYSET_RESOURCE_URI = "/factorySet";
65 ThingsManager *configthingsMgr = new ThingsManager();
67 typedef struct region_popup
71 } region_popup_fields;
73 void *updateConfigLog(void *data)
75 string *log = (string *)data;
77 elm_entry_entry_append(log_entry, (*log).c_str());
78 elm_entry_cursor_end_set(log_entry);
82 // Callback to found collection resource
83 void onFoundCollectionResource(std::vector< std::shared_ptr< OCResource > > resources)
85 dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCollectionResource ENTRY!!!!");
88 // Do some operations with resource object.
89 for (unsigned int i = 0; i < resources.size(); ++i)
92 std::shared_ptr< OCResource > resource = resources.at(i);
95 string resourceURI = resource->host();
96 string hostAddress = resource->uri();
97 logMessage = "FoundHost: " + resource->host() + "<br>";
98 logMessage += "FoundUri : " + resource->uri() + "<br>";
99 logMessage += "----------------------<br>";
100 dlog_print(DLOG_INFO, LOG_TAG, "FoundHost: %s", resourceURI.c_str());
101 dlog_print(DLOG_INFO, LOG_TAG, "FoundUri : %s", hostAddress.c_str());
102 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
103 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
106 if (resource->uri() == CONFIGURATION_COLLECTION_RESOURCE_URI)
107 g_configurationCollection = resource;
108 else if (resource->uri() == DIAGNOSTIC_COLLECTION_RESOURCE_URI)
109 g_diagnosticsCollection = resource;
110 else if (resource->uri() == FACTORYSET_COLLECTION_RESOURCE_URI)
111 g_setCollection = resource;
120 // Resource is invalid
122 logMessage = "Found Resource invalid!";
123 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
124 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
129 catch (std::exception &e)
131 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
134 dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCollectionResource EXIT!!!!");
137 // Callback to found candidate resources
138 void onFoundCandidateResource(std::vector< std::shared_ptr< OCResource > > resources)
140 dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCandidateCollection ENTRY!!!!");
143 // Do some operations with resource object.
144 for (unsigned int i = 0; i < resources.size(); ++i)
147 std::shared_ptr< OCResource > resource = resources.at(i);
150 // Check if the resource is new one. If so, store it.
151 std::map< std::string, std::shared_ptr< OCResource > >::iterator iter =
152 resourceTable.find(resource->host() + resource->uri());
154 if (iter == resourceTable.end()) // new one
156 resourceTable[resource->host() + resource->uri()] = resource;
158 OCResourceHandle foundResourceHandle = NULL;
159 OCStackResult result = OCPlatform::registerResource(foundResourceHandle,
161 // TODO: null check for foundResourceHandle
162 dlog_print(DLOG_INFO, LOG_TAG, "#### (%s) REGISTERED",
163 resource->host().c_str());
164 if (OC_STACK_OK == result)
166 string resourceURI = resource->host();
167 string hostAddress = resource->uri();
168 logMessage = "FoundHost: " + resource->host() + "<br>";
169 logMessage += "FoundUri: " + resource->uri()
170 + " Registered <br>";
171 logMessage += "----------------------<br>";
172 dlog_print(DLOG_INFO, LOG_TAG, "Host: %s", resourceURI.c_str());
173 dlog_print(DLOG_INFO, LOG_TAG, "Uri : %s", hostAddress.c_str());
174 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
175 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
178 if (resource->uri() == CONFIGURATION_RESOURCE_URI &&
179 NULL != configurationCollectionHandle)
181 OCPlatform::bindResource(configurationCollectionHandle,
182 foundResourceHandle);
183 configurationFoundHandle = foundResourceHandle;
184 if (NULL == g_configurationResource)
186 dlog_print(DLOG_INFO, LOG_TAG, "g_configurationResource updated");
187 g_configurationResource = resource;
191 dlog_print(DLOG_INFO, LOG_TAG,
192 "g_configurationResource is not null");
195 else if (resource->uri() == DIAGNOSTIC_RESOURCE_URI &&
196 NULL != diagnosticsCollectionHandle)
198 OCPlatform::bindResource(diagnosticsCollectionHandle,
199 foundResourceHandle);
200 diagnosticsFoundHandle = foundResourceHandle;
201 if (NULL == g_diagnosticsResource)
203 dlog_print(DLOG_INFO, LOG_TAG,
204 "g_diagnosticsResource updated");
205 g_diagnosticsResource = resource;
209 dlog_print(DLOG_INFO, LOG_TAG,
210 "g_diagnosticsResource is not null");
213 else if (resource->uri() == FACTORYSET_RESOURCE_URI &&
214 NULL != setCollectionHandle)
216 OCPlatform::bindResource(setCollectionHandle, foundResourceHandle);
217 setFoundHandle = foundResourceHandle;
218 if (NULL == g_setResource)
220 dlog_print(DLOG_INFO, LOG_TAG, "g_setResource updated");
221 g_setResource = resource;
225 dlog_print(DLOG_INFO, LOG_TAG, "g_setResource is not null");
228 configResourceHandleVector.push_back(foundResourceHandle);
232 logMessage = "Resource Error!";
233 dlog_print(DLOG_INFO, LOG_TAG, "Resource Error!");
234 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
241 // Resource is invalid
242 logMessage = "Resource is invalid!";
243 dlog_print(DLOG_INFO, LOG_TAG, "Resource is invalid!");
244 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
249 catch (std::exception &e)
251 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
255 dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCandidateCollection EXIT!!!!");
258 // Callback to updateConfiguration
259 static void onUpdateConfigurationsCallback(const HeaderOptions &headerOptions,
260 const OCRepresentation &rep,
263 dlog_print(DLOG_INFO, LOG_TAG, "#### onUpdateConfigurationsCallback: ENTRY!!!!");
266 if (SUCCESS_RESPONSE != eCode)
268 dlog_print(DLOG_ERROR, LOG_TAG, "#### onUpdateConfigurationsCallback: "
269 "ERROR RESPONSE!!!!");
273 string logMessage = "Resource URI: " + rep.getUri() + "<br>";
274 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
276 if (rep.hasAttribute("loc"))
278 dlog_print(DLOG_INFO, LOG_TAG, "#### Location : %s",
279 rep.getValue< std::string >("loc").c_str());
280 logMessage = logMessage + "Location : " + rep.getValue< std::string >("loc") + "<br>";
282 if (rep.hasAttribute("st"))
284 dlog_print(DLOG_INFO, LOG_TAG, "#### SystemTime : %s",
285 rep.getValue< std::string >("st").c_str());
286 logMessage = logMessage + "SystemTime : " + rep.getValue< std::string >("st") + "<br>";
288 if (rep.hasAttribute("c"))
290 dlog_print(DLOG_INFO, LOG_TAG, "#### Currency : %s",
291 rep.getValue< std::string >("c").c_str());
292 logMessage = logMessage + "Currency : " + rep.getValue< std::string >("c") + "<br>";
294 if (rep.hasAttribute("r"))
296 dlog_print(DLOG_INFO, LOG_TAG, "#### Region : %s",
297 rep.getValue< std::string >("r").c_str());
298 logMessage = logMessage + "Region : " + rep.getValue< std::string >("r") + "<br>";
300 logMessage += "----------------------<br>";
301 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
302 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
304 dlog_print(DLOG_INFO, LOG_TAG, "#### onUpdateConfigurationsCallback: EXIT!!!!");
307 // Callback to getConfiguration
308 static void onGetConfigurationsCallback(const HeaderOptions &headerOptions,
309 const OCRepresentation &rep,
312 dlog_print(DLOG_INFO, LOG_TAG, "#### onGetConfigurationsCallback: enter!!!!");
315 if (SUCCESS_RESPONSE != eCode)
317 dlog_print(DLOG_ERROR, LOG_TAG, "#### onGetConfigurationsCallback: "
318 "ERROR RESPONSE!!!!");
322 string logMessage = "Resource URI: " + rep.getUri() + "<br>";
323 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
325 if (rep.hasAttribute("loc"))
327 dlog_print(DLOG_INFO, LOG_TAG, "#### Location : %s",
328 rep.getValue< std::string >("loc").c_str());
329 logMessage = logMessage + "Location : " + rep.getValue< std::string >("loc") + "<br>";
331 if (rep.hasAttribute("st"))
333 dlog_print(DLOG_INFO, LOG_TAG, "#### SystemTime : %s",
334 rep.getValue< std::string >("st").c_str());
335 logMessage = logMessage + "SystemTime : " + rep.getValue< std::string >("st") + "<br>";
337 if (rep.hasAttribute("c"))
339 dlog_print(DLOG_INFO, LOG_TAG, "#### Currency : %s",
340 rep.getValue< std::string >("c").c_str());
341 logMessage = logMessage + "Currency : " + rep.getValue< std::string >("c") + "<br>";
343 if (rep.hasAttribute("r"))
345 dlog_print(DLOG_INFO, LOG_TAG, "#### Region : %s",
346 rep.getValue< std::string >("r").c_str());
347 logMessage = logMessage + "Region : " + rep.getValue< std::string >("r") + "<br>";
350 logMessage += "----------------------<br>";
351 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
352 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
353 dlog_print(DLOG_INFO, LOG_TAG, "#### onGetConfigurationsCallback: exit!!!!");
356 static void onFactoryReset(const HeaderOptions &headerOptions, const OCRepresentation &rep,
359 dlog_print(DLOG_INFO, LOG_TAG, "#### onFactoryReset: enter!!!!");
362 if (SUCCESS_RESPONSE != eCode)
364 dlog_print(DLOG_ERROR, LOG_TAG, "#### onFactoryReset: ERROR RESPONSE!!!!");
368 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
369 dlog_print(DLOG_INFO, LOG_TAG, "#### FactoryReset : %s",
370 rep.getValue< std::string >("value").c_str());
371 string logMessage = "Resource URI : " + rep.getUri() + "<br>";
372 logMessage = logMessage + "FactoryReset : " +
373 rep.getValue< std::string >("value") + "<br>";
374 logMessage += "----------------------<br>";
375 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
376 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
377 dlog_print(DLOG_INFO, LOG_TAG, "#### onFactoryReset: exit!!!!");
380 static void onReboot(const HeaderOptions &headerOptions, const OCRepresentation &rep,
383 dlog_print(DLOG_INFO, LOG_TAG, "#### onReboot: enter!!!!");
386 if (SUCCESS_RESPONSE != eCode)
388 dlog_print(DLOG_ERROR, LOG_TAG, "#### onReboot: ERROR RESPONSE!!!!");
392 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
393 dlog_print(DLOG_INFO, LOG_TAG, "#### Reboot : %s",
394 rep.getValue< std::string >("value").c_str());
395 string logMessage = "Resource URI : " + rep.getUri() + "<br>";
396 logMessage = logMessage + "Reboot : " +
397 rep.getValue< std::string >("value") + "<br>";
398 logMessage += "----------------------<br>";
399 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
400 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
401 dlog_print(DLOG_INFO, LOG_TAG, "#### onReboot: exit!!!!");
404 static void createResourceCollection(string uri, string typeName, OCResourceHandle &tempHandle)
406 dlog_print(DLOG_INFO, LOG_TAG, "#### createResourceCollection: enter!!!!");
407 if (NULL != tempHandle)
409 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource already exists!!!!");
413 // Create resource collection
414 OCPlatform::registerResource(tempHandle, uri, typeName, BATCH_INTERFACE, NULL,
416 OCPlatform::bindInterfaceToResource(tempHandle, GROUP_INTERFACE);
417 OCPlatform::bindInterfaceToResource(tempHandle, DEFAULT_INTERFACE);
419 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource created : %s", typeName.c_str());
421 logMessage = "Resource created : <br>" + typeName + "<br>";
422 logMessage += "----------------------<br>";
423 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
424 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
425 dlog_print(DLOG_INFO, LOG_TAG, "#### createResourceCollection: exit!!!!");
428 // Unbinds and unregisters all resources
429 static void deleteResource(OCResourceHandle &tempCollectionHandle,
430 OCResourceHandle &tempResourceHandle)
432 dlog_print(DLOG_INFO, LOG_TAG, "#### calling deleteResources ENTRY!!!!");
434 if (NULL == tempCollectionHandle || NULL == tempResourceHandle)
436 dlog_print(DLOG_INFO, LOG_TAG, "#### Collection or resource does not exists");
442 OCPlatform::unbindResource(tempCollectionHandle, tempResourceHandle);
443 dlog_print(DLOG_INFO, LOG_TAG, "#### unbindResource DONE!!!!");
445 catch (std::exception &e)
447 dlog_print(DLOG_ERROR, LOG_TAG, "Exception Occured! (%s)", e.what());
452 OCPlatform::unregisterResource(tempResourceHandle);
453 dlog_print(DLOG_INFO, LOG_TAG, "#### unregisterResource DONE!!!!");
455 catch (std::exception &e)
457 dlog_print(DLOG_ERROR, LOG_TAG, "Exception Occured! (%s)", e.what());
460 dlog_print(DLOG_INFO, LOG_TAG, "#### calling deleteResources EXIT!!!!");
463 static void findAllGroups(void *data, Evas_Object *obj, void *event_info)
465 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources ENTRY!!!!");
466 std::vector<string> resourceTypes;
467 resourceTypes.push_back(CONFIGURATION_COLLECTION_RESOURCE_TYPE);
469 if (NULL != configthingsMgr)
471 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
474 resourceTypes.clear();
475 resourceTypes.push_back(DIAGNOSTIC_COLLECTION_RESOURCE_TYPE);
476 if (NULL != configthingsMgr)
478 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
481 resourceTypes.clear();
482 resourceTypes.push_back(FACTORYSET_COLLECTION_RESOURCE_TYPE);
483 if (NULL != configthingsMgr)
485 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
488 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources EXIT!!!!");
491 static void findAllResources(void *data, Evas_Object *obj, void *event_info)
493 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources ENTRY!!!!");
494 std::vector<string> resourceTypes;
495 resourceTypes.push_back("oic.con");
497 if (NULL != configthingsMgr)
499 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
502 resourceTypes.clear();
503 resourceTypes.push_back("oic.diag");
504 if (NULL != configthingsMgr)
506 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
509 resourceTypes.clear();
510 resourceTypes.push_back("factorySet");
511 if (NULL != configthingsMgr)
513 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
516 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources EXIT!!!!");
519 static void getConfiguration(void *data, Evas_Object *obj, void *event_info)
521 dlog_print(DLOG_INFO, LOG_TAG, "#### getConfiguration ENTRY!!!!");
522 if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
524 dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
525 string logMessage = "FIRST CREATE GROUP <br>";
526 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
527 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
531 ConfigurationName name = "all";
532 std::vector< ConfigurationName > configurations;
533 configurations.push_back(name);
537 configthingsMgr->getConfigurations(g_configurationCollection, configurations,
538 &onGetConfigurationsCallback);
540 catch (std::exception &e)
542 dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
546 dlog_print(DLOG_INFO, LOG_TAG, "#### getConfiguration EXIT!!!!");
549 // Updates the configuration i.e. region value to INDIA
550 static void updateConfiguration(std::string newRegionValue)
552 dlog_print(DLOG_INFO, LOG_TAG, "#### updateConfiguration ENTRY!!!!");
553 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", newRegionValue.c_str());
555 if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
557 dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
558 string logMessage = "FIRST CREATE GROUP <br>";
559 logMessage += "----------------------<br>";
560 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
561 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
565 OCStackResult result;
566 ConfigurationName name = "r";
567 ConfigurationValue value = newRegionValue;
569 std::map< ConfigurationName, ConfigurationValue > configurations;
570 configurations.insert(std::make_pair(name, value));
574 result = configthingsMgr->updateConfigurations(g_configurationCollection, configurations,
575 &onUpdateConfigurationsCallback);
577 catch (std::exception &e)
579 dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
582 if (OC_STACK_OK == result)
584 string logMessage = "UpdateConfigurations called successfully<br>";
585 logMessage += "----------------------<br>";
586 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
587 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
590 dlog_print(DLOG_INFO, LOG_TAG, "#### updateConfiguration EXIT!!!!");
593 // This method will reset all the configuration attributes to their default values
594 static void factoryReset(void *data, Evas_Object *obj, void *event_info)
596 dlog_print(DLOG_INFO, LOG_TAG, "#### factoryReset ENTRY!!!!");
597 if (NULL == g_diagnosticsCollection || NULL == g_diagnosticsCollection.get())
599 dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
600 string logMessage = "FIRST CREATE GROUP <br>";
601 logMessage += "----------------------<br>";
602 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
603 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
607 OCStackResult result;
611 result = configthingsMgr->factoryReset(g_diagnosticsCollection, &onFactoryReset);
613 catch (std::exception &e)
615 dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
618 if (OC_STACK_OK == result)
620 string logMessage = "FactoryReset called successfully<br>";
621 logMessage += "----------------------<br>";
622 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
623 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
626 dlog_print(DLOG_INFO, LOG_TAG, "#### factoryReset EXIT!!!!");
629 // Reboots the server
630 static void reboot(void *data, Evas_Object *obj, void *event_info)
632 dlog_print(DLOG_INFO, LOG_TAG, "#### reboot ENTRY!!!!");
633 if (NULL == g_diagnosticsCollection || NULL == g_diagnosticsCollection.get())
635 dlog_print(DLOG_INFO, LOG_TAG, "Note that you first create a group to use this command");
636 string logMessage = "FIRST CREATE GROUP <br>";
637 logMessage += "----------------------<br>";
638 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
639 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
643 OCStackResult result;
647 result = configthingsMgr->reboot(g_diagnosticsCollection, &onReboot);
649 catch (std::exception &e)
651 dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
654 if (OC_STACK_OK == result)
656 string logMessage = "Reboot called successfully<br>";
657 logMessage += "----------------------<br>";
658 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
659 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
661 dlog_print(DLOG_INFO, LOG_TAG, "#### reboot EXIT!!!!");
664 /* For getting list of all supported configuration Values it will give all
665 configuration in JSON format (key-value pair) */
666 static void getListOfSupportedConfigurationUnits(void *data, Evas_Object *obj, void *event_info)
668 dlog_print(DLOG_INFO, LOG_TAG, "#### getListOfSupportedConfigurationUnits ENTRY!!!!");
669 string listOfSupportedConfigurationUnits =
670 configthingsMgr->getListOfSupportedConfigurationUnits();
671 dlog_print(DLOG_INFO, LOG_TAG, "#### List : %s", listOfSupportedConfigurationUnits.c_str());
674 logMessage = "Supported Configuration List :<br>" + listOfSupportedConfigurationUnits + "<br>";
675 logMessage += "----------------------<br>";
676 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
677 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
678 dlog_print(DLOG_INFO, LOG_TAG, "#### getListOfSupportedConfigurationUnits EXIT!!!!");
681 // Creates all the resources
682 static void onStartConfigure()
684 createResourceCollection(CONFIGURATION_COLLECTION_RESOURCE_URI,
685 CONFIGURATION_COLLECTION_RESOURCE_TYPE,
686 configurationCollectionHandle);
687 createResourceCollection(DIAGNOSTIC_COLLECTION_RESOURCE_URI,
688 DIAGNOSTIC_COLLECTION_RESOURCE_TYPE,
689 diagnosticsCollectionHandle);
690 createResourceCollection(FACTORYSET_COLLECTION_RESOURCE_URI,
691 FACTORYSET_COLLECTION_RESOURCE_TYPE,
692 setCollectionHandle);
695 // Deletes all the resources
696 static void onDestroyConfigure()
698 dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called");
700 deleteResource(configurationCollectionHandle, configurationFoundHandle);
702 deleteResource(diagnosticsCollectionHandle, diagnosticsFoundHandle);
704 deleteResource(setCollectionHandle, setFoundHandle);
706 dlog_print(DLOG_INFO, LOG_TAG, "#### Resources destroyed successfully");
710 popup_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
712 region_popup_fields *popup_fields = (region_popup_fields *)data;
713 evas_object_del(popup_fields->popup);
718 popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info)
720 region_popup_fields *popup_fields = (region_popup_fields *)data;
721 Evas_Object *entry = popup_fields->entry;
722 const char *newRegionValue = elm_entry_entry_get(entry);
723 if (NULL == newRegionValue || strlen(newRegionValue) < 1)
725 dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL RegionValue");
726 string logMessage = "Region Value should not be NULL<br>";
727 logMessage += "----------------------<br>";
728 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
729 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
733 std::string regionValue = std::string(newRegionValue);
734 updateConfiguration(regionValue);
736 evas_object_del(popup_fields->popup);
741 list_update_region_cb(void *data, Evas_Object *obj, void *event_info)
743 if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
745 dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
746 string logMessage = "FIRST CREATE GROUP <br>";
747 dlog_print(DLOG_INFO, LOG_TAG, " %s", logMessage.c_str());
748 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
752 Evas_Object *popup, *btn;
753 Evas_Object *nf = (Evas_Object *)data;
758 popup = elm_popup_add(nf);
759 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
760 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
761 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
762 elm_object_part_text_set(popup, "title,text", "Enter New Region Value");
764 layout = elm_layout_add(popup);
765 elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_region_text");
766 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
767 elm_object_content_set(popup, layout);
769 entry = elm_entry_add(layout);
770 elm_entry_single_line_set(entry, EINA_TRUE);
771 elm_entry_scrollable_set(entry, EINA_TRUE);
772 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
773 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
774 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
775 elm_object_part_text_set(entry, "elm.guide", "region value");
776 elm_object_part_content_set(layout, "elm.swallow.content" , entry);
778 region_popup_fields *popup_fields;
779 popup_fields = (region_popup_fields *)malloc(sizeof(region_popup_fields));
780 if (NULL == popup_fields)
782 dlog_print(DLOG_INFO, LOG_TAG, "#### Memory allocation failed");
786 popup_fields->popup = popup;
787 popup_fields->entry = entry;
791 btn = elm_button_add(popup);
792 elm_object_style_set(btn, "popup");
793 elm_object_text_set(btn, "Cancel");
794 elm_object_part_content_set(popup, "button1", btn);
795 evas_object_smart_callback_add(btn, "clicked", popup_cancel_clicked_cb, popup_fields);
798 btn = elm_button_add(popup);
799 elm_object_style_set(btn, "popup");
800 elm_object_text_set(btn, "Set");
801 elm_object_part_content_set(popup, "button2", btn);
802 evas_object_smart_callback_add(btn, "clicked", popup_set_clicked_cb, popup_fields);
804 evas_object_show(popup);
808 list_selected_cb(void *data, Evas_Object *obj, void *event_info)
810 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
811 elm_list_item_selected_set(it, EINA_FALSE);
815 test_fn(void *data, Evas_Object *obj, void *event_info)
817 if (NULL != log_entry)
819 elm_entry_entry_append(log_entry, "First item selected");
820 elm_entry_cursor_end_set(log_entry);
824 dlog_print(DLOG_ERROR, "test_fn", "log_entry object is NULL");
829 naviframe_pop_cb(void *data, Elm_Object_Item *it)
831 onDestroyConfigure();
832 resourceTable.clear();
833 if (NULL != log_entry)
835 evas_object_del(log_entry);
841 // Method to be called when configuration API UI button is selected
843 configuration_cb(void *data, Evas_Object *obj, void *event_info)
846 Evas_Object *scroller;
848 Evas_Object *nf = (Evas_Object *)data;
849 Elm_Object_Item *nf_it;
852 scroller = elm_scroller_add(nf);
853 elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
854 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
857 layout = elm_layout_add(nf);
858 elm_layout_file_set(layout, ELM_DEMO_EDJ, "configuration_layout");
859 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
861 elm_object_content_set(scroller, layout);
864 list = elm_list_add(layout);
865 elm_list_mode_set(list, ELM_LIST_COMPRESS);
866 evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
867 elm_object_part_content_set(layout, "list", list);
870 // log_entry - text area for log
871 log_entry = elm_entry_add(layout);
872 elm_entry_scrollable_set(log_entry, EINA_TRUE);
873 elm_entry_editable_set(log_entry, EINA_FALSE);
874 elm_object_part_text_set(log_entry, "elm.guide", "logs will be updated here!!!");
875 evas_object_size_hint_weight_set(log_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
876 evas_object_size_hint_align_set(log_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
877 elm_object_part_content_set(layout, "log", log_entry);
879 nf_it = elm_naviframe_item_push(nf, "configuration APIs", NULL, NULL, scroller, NULL);
880 elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL);
884 // Shows the UI list of group APIs
885 elm_list_item_append(list, "Find All Groups", NULL, NULL, findAllGroups, NULL);
886 elm_list_item_append(list, "Find All Resources",
887 NULL, NULL, findAllResources, NULL);
888 elm_list_item_append(list, "Get a Configuration Resource", NULL, NULL, getConfiguration, NULL);
889 elm_list_item_append(list, "Update Attribute (Region)", NULL, NULL,
890 list_update_region_cb, nf);
891 elm_list_item_append(list, "Factory Reset", NULL, NULL, factoryReset, NULL);
892 elm_list_item_append(list, "Reboot", NULL, NULL, reboot, NULL);
893 elm_list_item_append(list, "Get Supported Configuration Units", NULL, NULL,
894 getListOfSupportedConfigurationUnits, NULL);