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 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
105 if (resource->uri() == CONFIGURATION_COLLECTION_RESOURCE_URI)
106 g_configurationCollection = resource;
107 else if (resource->uri() == DIAGNOSTIC_COLLECTION_RESOURCE_URI)
108 g_diagnosticsCollection = resource;
109 else if (resource->uri() == FACTORYSET_COLLECTION_RESOURCE_URI)
110 g_setCollection = resource;
119 // Resource is invalid
120 logMessage = "Found Resource invalid!";
121 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
126 catch (std::exception &e)
128 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
131 dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCollectionResource EXIT!!!!");
134 // Callback to found candidate resources
135 void onFoundCandidateResource(std::vector< std::shared_ptr< OCResource > > resources)
137 dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCandidateCollection ENTRY!!!!");
140 // Do some operations with resource object.
141 for (unsigned int i = 0; i < resources.size(); ++i)
144 std::shared_ptr< OCResource > resource = resources.at(i);
147 // Check if the resource is new one. If so, store it.
148 std::map< std::string, std::shared_ptr< OCResource > >::iterator iter =
149 resourceTable.find(resource->host() + resource->uri());
151 if (iter == resourceTable.end()) // new one
153 resourceTable[resource->host() + resource->uri()] = resource;
155 OCResourceHandle foundResourceHandle = NULL;
156 OCStackResult result = OCPlatform::registerResource(foundResourceHandle,
158 // TODO: null check for foundResourceHandle
159 dlog_print(DLOG_INFO, LOG_TAG, "#### (%s) REGISTERED",
160 resource->host().c_str());
161 if (OC_STACK_OK == result)
163 string resourceURI = resource->host();
164 string hostAddress = resource->uri();
165 logMessage = "FoundHost: " + resource->host() + "<br>";
166 logMessage += "FoundUri: " + resource->uri()
167 + " Registered <br>";
168 logMessage += "----------------------<br>";
169 dlog_print(DLOG_INFO, LOG_TAG, "Host: %s", resourceURI.c_str());
170 dlog_print(DLOG_INFO, LOG_TAG, "Uri : %s", hostAddress.c_str());
171 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
174 if (resource->uri() == CONFIGURATION_RESOURCE_URI &&
175 NULL != configurationCollectionHandle)
177 OCPlatform::bindResource(configurationCollectionHandle,
178 foundResourceHandle);
179 configurationFoundHandle = foundResourceHandle;
180 if (NULL == g_configurationResource)
182 dlog_print(DLOG_INFO, LOG_TAG, "g_configurationResource updated");
183 g_configurationResource = resource;
187 dlog_print(DLOG_INFO, LOG_TAG,
188 "g_configurationResource is not null");
191 else if (resource->uri() == DIAGNOSTIC_RESOURCE_URI &&
192 NULL != diagnosticsCollectionHandle)
194 OCPlatform::bindResource(diagnosticsCollectionHandle,
195 foundResourceHandle);
196 diagnosticsFoundHandle = foundResourceHandle;
197 if (NULL == g_diagnosticsResource)
199 dlog_print(DLOG_INFO, LOG_TAG,
200 "g_diagnosticsResource updated");
201 g_diagnosticsResource = resource;
205 dlog_print(DLOG_INFO, LOG_TAG,
206 "g_diagnosticsResource is not null");
209 else if (resource->uri() == FACTORYSET_RESOURCE_URI &&
210 NULL != setCollectionHandle)
212 OCPlatform::bindResource(setCollectionHandle, foundResourceHandle);
213 setFoundHandle = foundResourceHandle;
214 if (NULL == g_setResource)
216 dlog_print(DLOG_INFO, LOG_TAG, "g_setResource updated");
217 g_setResource = resource;
221 dlog_print(DLOG_INFO, LOG_TAG, "g_setResource is not null");
224 configResourceHandleVector.push_back(foundResourceHandle);
228 logMessage = "Resource Error!";
229 dlog_print(DLOG_INFO, LOG_TAG, "Resource Error!");
230 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
237 // Resource is invalid
238 logMessage = "Resource is invalid!";
239 dlog_print(DLOG_INFO, LOG_TAG, "Resource is invalid!");
240 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
245 catch (std::exception &e)
247 dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
251 dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCandidateCollection EXIT!!!!");
254 // Callback to updateConfiguration
255 static void onUpdateConfigurationsCallback(const HeaderOptions &headerOptions,
256 const OCRepresentation &rep,
259 dlog_print(DLOG_INFO, LOG_TAG, "#### onUpdateConfigurationsCallback: ENTRY!!!!");
262 if (SUCCESS_RESPONSE != eCode)
264 dlog_print(DLOG_ERROR, LOG_TAG, "#### onUpdateConfigurationsCallback: "
265 "ERROR RESPONSE!!!!");
269 string logMessage = "Resource URI: " + rep.getUri() + "<br>";
270 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
272 if (rep.hasAttribute("loc"))
274 dlog_print(DLOG_INFO, LOG_TAG, "#### Location : %s",
275 rep.getValue< std::string >("loc").c_str());
276 logMessage = logMessage + "Location : " + rep.getValue< std::string >("loc") + "<br>";
278 if (rep.hasAttribute("st"))
280 dlog_print(DLOG_INFO, LOG_TAG, "#### SystemTime : %s",
281 rep.getValue< std::string >("st").c_str());
282 logMessage = logMessage + "SystemTime : " + rep.getValue< std::string >("st") + "<br>";
284 if (rep.hasAttribute("c"))
286 dlog_print(DLOG_INFO, LOG_TAG, "#### Currency : %s",
287 rep.getValue< std::string >("c").c_str());
288 logMessage = logMessage + "Currency : " + rep.getValue< std::string >("c") + "<br>";
290 if (rep.hasAttribute("r"))
292 dlog_print(DLOG_INFO, LOG_TAG, "#### Region : %s",
293 rep.getValue< std::string >("r").c_str());
294 logMessage = logMessage + "Region : " + rep.getValue< std::string >("r") + "<br>";
296 logMessage += "----------------------<br>";
297 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
299 dlog_print(DLOG_INFO, LOG_TAG, "#### onUpdateConfigurationsCallback: EXIT!!!!");
302 // Callback to getConfiguration
303 static void onGetConfigurationsCallback(const HeaderOptions &headerOptions,
304 const OCRepresentation &rep,
307 dlog_print(DLOG_INFO, LOG_TAG, "#### onGetConfigurationsCallback: enter!!!!");
310 if (SUCCESS_RESPONSE != eCode)
312 dlog_print(DLOG_ERROR, LOG_TAG, "#### onGetConfigurationsCallback: "
313 "ERROR RESPONSE!!!!");
317 string logMessage = "Resource URI: " + rep.getUri() + "<br>";
318 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
320 if (rep.hasAttribute("loc"))
322 dlog_print(DLOG_INFO, LOG_TAG, "#### Location : %s",
323 rep.getValue< std::string >("loc").c_str());
324 logMessage = logMessage + "Location : " + rep.getValue< std::string >("loc") + "<br>";
326 if (rep.hasAttribute("st"))
328 dlog_print(DLOG_INFO, LOG_TAG, "#### SystemTime : %s",
329 rep.getValue< std::string >("st").c_str());
330 logMessage = logMessage + "SystemTime : " + rep.getValue< std::string >("st") + "<br>";
332 if (rep.hasAttribute("c"))
334 dlog_print(DLOG_INFO, LOG_TAG, "#### Currency : %s",
335 rep.getValue< std::string >("c").c_str());
336 logMessage = logMessage + "Currency : " + rep.getValue< std::string >("c") + "<br>";
338 if (rep.hasAttribute("r"))
340 dlog_print(DLOG_INFO, LOG_TAG, "#### Region : %s",
341 rep.getValue< std::string >("r").c_str());
342 logMessage = logMessage + "Region : " + rep.getValue< std::string >("r") + "<br>";
345 logMessage += "----------------------<br>";
346 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
347 dlog_print(DLOG_INFO, LOG_TAG, "#### onGetConfigurationsCallback: exit!!!!");
350 static void onFactoryReset(const HeaderOptions &headerOptions, const OCRepresentation &rep,
353 dlog_print(DLOG_INFO, LOG_TAG, "#### onFactoryReset: enter!!!!");
356 if (SUCCESS_RESPONSE != eCode)
358 dlog_print(DLOG_ERROR, LOG_TAG, "#### onFactoryReset: ERROR RESPONSE!!!!");
362 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
363 dlog_print(DLOG_INFO, LOG_TAG, "#### FactoryReset : %s",
364 rep.getValue< std::string >("value").c_str());
365 string logMessage = "Resource URI : " + rep.getUri() + "<br>";
366 logMessage = logMessage + "FactoryReset : " +
367 rep.getValue< std::string >("value") + "<br>";
368 logMessage += "----------------------<br>";
369 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
370 dlog_print(DLOG_INFO, LOG_TAG, "#### onFactoryReset: exit!!!!");
373 static void onReboot(const HeaderOptions &headerOptions, const OCRepresentation &rep,
376 dlog_print(DLOG_INFO, LOG_TAG, "#### onReboot: enter!!!!");
379 if (SUCCESS_RESPONSE != eCode)
381 dlog_print(DLOG_ERROR, LOG_TAG, "#### onReboot: ERROR RESPONSE!!!!");
385 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
386 dlog_print(DLOG_INFO, LOG_TAG, "#### Reboot : %s",
387 rep.getValue< std::string >("value").c_str());
388 string logMessage = "Resource URI : " + rep.getUri() + "<br>";
389 logMessage = logMessage + "Reboot : " +
390 rep.getValue< std::string >("value") + "<br>";
391 logMessage += "----------------------<br>";
392 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
393 dlog_print(DLOG_INFO, LOG_TAG, "#### onReboot: exit!!!!");
396 static void createResourceCollection(string uri, string typeName, OCResourceHandle &tempHandle)
398 dlog_print(DLOG_INFO, LOG_TAG, "#### createResourceCollection: enter!!!!");
399 if (NULL != tempHandle)
401 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource already exists!!!!");
405 // Create resource collection
406 OCPlatform::registerResource(tempHandle, uri, typeName, BATCH_INTERFACE, NULL,
408 OCPlatform::bindInterfaceToResource(tempHandle, GROUP_INTERFACE);
409 OCPlatform::bindInterfaceToResource(tempHandle, DEFAULT_INTERFACE);
411 dlog_print(DLOG_INFO, LOG_TAG, "#### Resource created : %s", typeName.c_str());
413 logMessage = "Resource created : <br>" + typeName + "<br>";
414 logMessage += "----------------------<br>";
415 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
416 dlog_print(DLOG_INFO, LOG_TAG, "#### createResourceCollection: exit!!!!");
419 // Unbinds and unregisters all resources
420 static void deleteResource(OCResourceHandle &tempCollectionHandle,
421 OCResourceHandle &tempResourceHandle)
423 dlog_print(DLOG_INFO, LOG_TAG, "#### calling deleteResources ENTRY!!!!");
425 if (NULL == tempCollectionHandle || NULL == tempResourceHandle)
427 dlog_print(DLOG_INFO, LOG_TAG, "#### Collection or resource does not exists");
433 OCPlatform::unbindResource(tempCollectionHandle, tempResourceHandle);
434 dlog_print(DLOG_INFO, LOG_TAG, "#### unbindResource DONE!!!!");
436 catch (std::exception &e)
438 dlog_print(DLOG_ERROR, LOG_TAG, "Exception Occured! (%s)", e.what());
443 OCPlatform::unregisterResource(tempResourceHandle);
444 dlog_print(DLOG_INFO, LOG_TAG, "#### unregisterResource DONE!!!!");
446 catch (std::exception &e)
448 dlog_print(DLOG_ERROR, LOG_TAG, "Exception Occured! (%s)", e.what());
451 dlog_print(DLOG_INFO, LOG_TAG, "#### calling deleteResources EXIT!!!!");
454 static void findAllGroups(void *data, Evas_Object *obj, void *event_info)
456 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources ENTRY!!!!");
457 std::vector<string> resourceTypes;
458 resourceTypes.push_back(CONFIGURATION_COLLECTION_RESOURCE_TYPE);
460 if (NULL != configthingsMgr)
462 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
465 resourceTypes.clear();
466 resourceTypes.push_back(DIAGNOSTIC_COLLECTION_RESOURCE_TYPE);
467 if (NULL != configthingsMgr)
469 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
472 resourceTypes.clear();
473 resourceTypes.push_back(FACTORYSET_COLLECTION_RESOURCE_TYPE);
474 if (NULL != configthingsMgr)
476 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
479 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources EXIT!!!!");
482 static void findAllResources(void *data, Evas_Object *obj, void *event_info)
484 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources ENTRY!!!!");
485 std::vector<string> resourceTypes;
486 resourceTypes.push_back("oic.con");
488 if (NULL != configthingsMgr)
490 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
493 resourceTypes.clear();
494 resourceTypes.push_back("oic.diag");
495 if (NULL != configthingsMgr)
497 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
500 resourceTypes.clear();
501 resourceTypes.push_back("factorySet");
502 if (NULL != configthingsMgr)
504 configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
507 dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources EXIT!!!!");
510 static void getConfiguration(void *data, Evas_Object *obj, void *event_info)
512 dlog_print(DLOG_INFO, LOG_TAG, "#### getConfiguration ENTRY!!!!");
513 if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
515 dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
516 string logMessage = "FIRST CREATE GROUP <br>";
517 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
521 ConfigurationName name = "all";
522 std::vector< ConfigurationName > configurations;
523 configurations.push_back(name);
527 configthingsMgr->getConfigurations(g_configurationCollection, configurations,
528 &onGetConfigurationsCallback);
530 catch (std::exception &e)
532 dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
536 dlog_print(DLOG_INFO, LOG_TAG, "#### getConfiguration EXIT!!!!");
539 // Updates the configuration i.e. region value to INDIA
540 static void updateConfiguration(std::string newRegionValue)
542 dlog_print(DLOG_INFO, LOG_TAG, "#### updateConfiguration ENTRY!!!!");
543 dlog_print(DLOG_INFO, LOG_TAG, "#### %s", newRegionValue.c_str());
545 if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
547 dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
548 string logMessage = "FIRST CREATE GROUP <br>";
549 logMessage += "----------------------<br>";
550 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
554 OCStackResult result;
555 ConfigurationName name = "r";
556 ConfigurationValue value = newRegionValue;
558 std::map< ConfigurationName, ConfigurationValue > configurations;
559 configurations.insert(std::make_pair(name, value));
563 result = configthingsMgr->updateConfigurations(g_configurationCollection, configurations,
564 &onUpdateConfigurationsCallback);
566 catch (std::exception &e)
568 dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
571 if (OC_STACK_OK == result)
573 string logMessage = "UpdateConfigurations called successfully<br>";
574 logMessage += "----------------------<br>";
575 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
578 dlog_print(DLOG_INFO, LOG_TAG, "#### updateConfiguration EXIT!!!!");
581 // This method will reset all the configuration attributes to their default values
582 static void factoryReset(void *data, Evas_Object *obj, void *event_info)
584 dlog_print(DLOG_INFO, LOG_TAG, "#### factoryReset ENTRY!!!!");
585 if (NULL == g_diagnosticsCollection || NULL == g_diagnosticsCollection.get())
587 dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
588 string logMessage = "FIRST CREATE GROUP <br>";
589 logMessage += "----------------------<br>";
590 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
594 OCStackResult result;
598 result = configthingsMgr->factoryReset(g_diagnosticsCollection, &onFactoryReset);
600 catch (std::exception &e)
602 dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
605 if (OC_STACK_OK == result)
607 string logMessage = "FactoryReset called successfully<br>";
608 logMessage += "----------------------<br>";
609 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
612 dlog_print(DLOG_INFO, LOG_TAG, "#### factoryReset EXIT!!!!");
615 // Reboots the server
616 static void reboot(void *data, Evas_Object *obj, void *event_info)
618 dlog_print(DLOG_INFO, LOG_TAG, "#### reboot ENTRY!!!!");
619 if (NULL == g_diagnosticsCollection || NULL == g_diagnosticsCollection.get())
621 dlog_print(DLOG_INFO, LOG_TAG, "Note that you first create a group to use this command");
622 string logMessage = "FIRST CREATE GROUP <br>";
623 logMessage += "----------------------<br>";
624 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
628 OCStackResult result;
632 result = configthingsMgr->reboot(g_diagnosticsCollection, &onReboot);
634 catch (std::exception &e)
636 dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
639 if (OC_STACK_OK == result)
641 string logMessage = "Reboot called successfully<br>";
642 logMessage += "----------------------<br>";
643 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
645 dlog_print(DLOG_INFO, LOG_TAG, "#### reboot EXIT!!!!");
648 /* For getting list of all supported configuration Values it will give all
649 configuration in JSON format (key-value pair) */
650 static void getListOfSupportedConfigurationUnits(void *data, Evas_Object *obj, void *event_info)
652 dlog_print(DLOG_INFO, LOG_TAG, "#### getListOfSupportedConfigurationUnits ENTRY!!!!");
653 string listOfSupportedConfigurationUnits =
654 configthingsMgr->getListOfSupportedConfigurationUnits();
655 dlog_print(DLOG_INFO, LOG_TAG, "#### List : %s", listOfSupportedConfigurationUnits.c_str());
658 logMessage = "Supported Configuration List :<br>" + listOfSupportedConfigurationUnits + "<br>";
659 logMessage += "----------------------<br>";
660 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
661 dlog_print(DLOG_INFO, LOG_TAG, "#### getListOfSupportedConfigurationUnits EXIT!!!!");
664 // Creates all the resources
665 static void onStartConfigure()
667 createResourceCollection(CONFIGURATION_COLLECTION_RESOURCE_URI,
668 CONFIGURATION_COLLECTION_RESOURCE_TYPE,
669 configurationCollectionHandle);
670 createResourceCollection(DIAGNOSTIC_COLLECTION_RESOURCE_URI,
671 DIAGNOSTIC_COLLECTION_RESOURCE_TYPE,
672 diagnosticsCollectionHandle);
673 createResourceCollection(FACTORYSET_COLLECTION_RESOURCE_URI,
674 FACTORYSET_COLLECTION_RESOURCE_TYPE,
675 setCollectionHandle);
678 // Deletes all the resources
679 static void onDestroyConfigure()
681 dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called");
683 deleteResource(configurationCollectionHandle, configurationFoundHandle);
685 deleteResource(diagnosticsCollectionHandle, diagnosticsFoundHandle);
687 deleteResource(setCollectionHandle, setFoundHandle);
689 dlog_print(DLOG_INFO, LOG_TAG, "#### Resources destroyed successfully");
693 popup_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
695 region_popup_fields *popup_fields = (region_popup_fields *)data;
696 evas_object_del(popup_fields->popup);
701 popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info)
703 region_popup_fields *popup_fields = (region_popup_fields *)data;
704 Evas_Object *entry = popup_fields->entry;
705 const char *newRegionValue = elm_entry_entry_get(entry);
706 if (NULL == newRegionValue || strlen(newRegionValue) < 1)
708 dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL RegionValue");
709 string logMessage = "Region Value should not be NULL<br>";
710 logMessage += "----------------------<br>";
711 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
715 std::string regionValue = std::string(newRegionValue);
716 updateConfiguration(regionValue);
718 evas_object_del(popup_fields->popup);
723 list_update_region_cb(void *data, Evas_Object *obj, void *event_info)
725 if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
727 dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
728 string logMessage = "FIRST CREATE GROUP <br>";
729 ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
733 Evas_Object *popup, *btn;
734 Evas_Object *nf = (Evas_Object *)data;
739 popup = elm_popup_add(nf);
740 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
741 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
742 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
743 elm_object_part_text_set(popup, "title,text", "Enter New Region Value");
745 layout = elm_layout_add(popup);
746 elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_region_text");
747 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
748 elm_object_content_set(popup, layout);
750 entry = elm_entry_add(layout);
751 elm_entry_single_line_set(entry, EINA_TRUE);
752 elm_entry_scrollable_set(entry, EINA_TRUE);
753 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
754 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
755 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
756 elm_object_part_text_set(entry, "elm.guide", "region value");
757 elm_object_part_content_set(layout, "elm.swallow.content" , entry);
759 region_popup_fields *popup_fields;
760 popup_fields = (region_popup_fields *)malloc(sizeof(region_popup_fields));
761 if (NULL == popup_fields)
763 dlog_print(DLOG_INFO, LOG_TAG, "#### Memory allocation failed");
764 popup_fields->popup = NULL;
765 popup_fields->entry = NULL;
769 popup_fields->popup = popup;
770 popup_fields->entry = entry;
774 btn = elm_button_add(popup);
775 elm_object_style_set(btn, "popup");
776 elm_object_text_set(btn, "Cancel");
777 elm_object_part_content_set(popup, "button1", btn);
778 evas_object_smart_callback_add(btn, "clicked", popup_cancel_clicked_cb, popup_fields);
781 btn = elm_button_add(popup);
782 elm_object_style_set(btn, "popup");
783 elm_object_text_set(btn, "Set");
784 elm_object_part_content_set(popup, "button2", btn);
785 evas_object_smart_callback_add(btn, "clicked", popup_set_clicked_cb, popup_fields);
787 evas_object_show(popup);
791 list_selected_cb(void *data, Evas_Object *obj, void *event_info)
793 Elm_Object_Item *it = (Elm_Object_Item *)event_info;
794 elm_list_item_selected_set(it, EINA_FALSE);
798 test_fn(void *data, Evas_Object *obj, void *event_info)
800 if (NULL != log_entry)
802 elm_entry_entry_append(log_entry, "First item selected");
803 elm_entry_cursor_end_set(log_entry);
807 dlog_print(DLOG_ERROR, "test_fn", "log_entry object is NULL");
812 naviframe_pop_cb(void *data, Elm_Object_Item *it)
814 onDestroyConfigure();
815 if (NULL != log_entry)
817 evas_object_del(log_entry);
823 // Method to be called when configuration API UI button is selected
825 configuration_cb(void *data, Evas_Object *obj, void *event_info)
828 Evas_Object *scroller;
830 Evas_Object *nf = (Evas_Object *)data;
831 Elm_Object_Item *nf_it;
834 scroller = elm_scroller_add(nf);
835 elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
836 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
839 layout = elm_layout_add(nf);
840 elm_layout_file_set(layout, ELM_DEMO_EDJ, "configuration_layout");
841 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
843 elm_object_content_set(scroller, layout);
846 list = elm_list_add(layout);
847 elm_list_mode_set(list, ELM_LIST_COMPRESS);
848 evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
849 elm_object_part_content_set(layout, "list", list);
852 // log_entry - text area for log
853 log_entry = elm_entry_add(layout);
854 elm_entry_scrollable_set(log_entry, EINA_TRUE);
855 elm_entry_editable_set(log_entry, EINA_FALSE);
856 elm_object_part_text_set(log_entry, "elm.guide", "logs will be updated here!!!");
857 evas_object_size_hint_weight_set(log_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
858 evas_object_size_hint_align_set(log_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
859 elm_object_part_content_set(layout, "log", log_entry);
861 nf_it = elm_naviframe_item_push(nf, "configuration APIs", NULL, NULL, scroller, NULL);
862 elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL);
866 // Shows the UI list of group APIs
867 elm_list_item_append(list, "Find All Groups", NULL, NULL, findAllGroups, NULL);
868 elm_list_item_append(list, "Find All Resources",
869 NULL, NULL, findAllResources, NULL);
870 elm_list_item_append(list, "Get a Configuration Resource", NULL, NULL, getConfiguration, NULL);
871 elm_list_item_append(list, "Update Attribute (Region)", NULL, NULL,
872 list_update_region_cb, nf);
873 elm_list_item_append(list, "Factory Reset", NULL, NULL, factoryReset, NULL);
874 elm_list_item_append(list, "Reboot", NULL, NULL, reboot, NULL);
875 elm_list_item_append(list, "Get Supported Configuration Units", NULL, NULL,
876 getListOfSupportedConfigurationUnits, NULL);