--- /dev/null
+{
+ global: main;
+ local: *;
+};
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#define POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 15
+#define POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC 96
+
+group
+{
+ name: "configuration_layout";
+ parts
+ {
+ part
+ {
+ name: "list";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ rel1.relative: 0.01 0.01;
+ rel2.relative: 0.99 0.6;
+ }
+ }
+ part
+ {
+ name: "log_bg";
+ type: RECT;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ rel1.relative: 0.01 0.61;
+ rel2.relative: 0.98 1.0;
+ color: 220 220 220 255;
+ }
+ }
+ part
+ {
+ name: "log";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ rel1.to: "log_bg";
+ rel2.to: "log_bg";
+ }
+ }
+ }
+}
+group
+{
+ name: "popup_region_text";
+ parts
+ {
+ part
+ {
+ name: "pad_l";
+ type: SPACER;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 0.0 1.0;
+ align: 0.0 0.0;
+ }
+ }
+ part
+ {
+ name: "pad_r";
+ type: SPACER;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 1.0 0.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 0.0;
+ }
+ }
+ part
+ {
+ name: "elm.swallow.content";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ min: 0 POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC;
+ max: -1 POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC;
+ align: 0.5 0.5;
+ rel1
+ {
+ relative: 1.0 0.0;
+ to_x: "pad_l";
+ }
+ rel2
+ {
+ relative: 0.0 1.0;
+ to_x: "pad_r";
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#define POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 15
+#define POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC 96
+
+group
+{
+ name: "group_layout";
+ parts
+ {
+ part
+ {
+ name: "find_button";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ rel1.relative: 0.01 0.01;
+ rel2.relative: 0.5 0.09;
+ }
+ }
+ part
+ {
+ name: "list";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ rel1.relative: 0.01 0.1;
+ rel2.relative: 0.99 0.7;
+ }
+ }
+ part
+ {
+ name: "log_bg";
+ type: RECT;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ rel1.relative: 0.01 0.71;
+ rel2.relative: 0.98 1.0;
+ color: 220 220 220 255;
+ }
+ }
+ part
+ {
+ name: "log";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ rel1.to: "log_bg";
+ rel2.to: "log_bg";
+ }
+ }
+ }
+}
+
+group
+{
+ name: "popup_datetime_text";
+ parts
+ {
+ part
+ {
+ name: "pad_l";
+ type: SPACER;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 0.0 1.0;
+ align: 0.0 0.0;
+ }
+ }
+ part
+ {
+ name: "pad_r";
+ type: SPACER;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 1.0 0.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 0.0;
+ }
+ }
+ part
+ {
+ name: "elm.swallow.content";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ min: 0 POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC;
+ max: -1 POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC;
+ align: 0.5 0.5;
+ rel1
+ {
+ relative: 1.0 0.0;
+ to_x: "pad_l";
+ }
+ rel2
+ {
+ relative: 0.0 1.0;
+ to_x: "pad_r";
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#ifndef __TMSAMPLEAPP_H__
+#define __TMSAMPLEAPP_H__
+
+#include <app.h>
+#include <Elementary.h>
+#include <system_settings.h>
+#include <efl_extension.h>
+#include <dlog.h>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "tmsampleapp"
+
+#if !defined(PACKAGE)
+#define PACKAGE "org.tizen.tmsampleapp"
+#endif
+
+#define ELM_DEMO_EDJ "opt/usr/apps/org.tizen.tmsampleapp/res/ui_controls.edj"
+
+void group_cb(void *data, Evas_Object *obj, void *event_info);
+void configuration_cb(void *data, Evas_Object *obj, void *event_info);
+
+#endif // __TMSAMPLEAPP_H__
\ No newline at end of file
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include<iostream>
+
+using namespace std;
+
+#ifndef __TMUTIL_H__
+#define __TMUTIL_H__
+
+extern std::string getOCStackResultStringFromInt(int result);
+
+#endif // __TMUTIL_H__
\ No newline at end of file
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+collections
+{
+ base_scale: 1.8;
+ #include "../edc_resource/configuration_control.edc"
+ #include "../edc_resource/group_control.edc"
+}
\ No newline at end of file
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "tmsampleapp.h"
+#include "tmutil.h"
+
+using namespace std;
+using namespace OC;
+using namespace OIC;
+
+int isWaiting = 0; // 0: none to wait, 1: wait for the response of "getConfigurationValue"
+const int SUCCESS_RESPONSE = 0;
+
+OCResourceHandle configurationCollectionHandle = NULL;
+OCResourceHandle configurationFoundHandle = NULL;
+std::shared_ptr< OCResource > g_configurationCollection; // For a group of multiple resources
+std::shared_ptr< OCResource > g_configurationResource; // For a single resource
+
+OCResourceHandle diagnosticsCollectionHandle = NULL;
+OCResourceHandle diagnosticsFoundHandle = NULL;
+std::shared_ptr< OCResource > g_diagnosticsCollection; // For a group of multiple resources
+std::shared_ptr< OCResource > g_diagnosticsResource; // For a single resource
+
+OCResourceHandle setCollectionHandle = NULL;
+OCResourceHandle setFoundHandle = NULL;
+std::shared_ptr< OCResource > g_setCollection; // For a group of multiple resources
+std::shared_ptr< OCResource > g_setResource; // For a single resource
+
+std::map< std::string, std::shared_ptr< OCResource > > resourceTable;
+std::vector< OCResourceHandle > configResourceHandleVector;
+
+typedef std::string ConfigurationName;
+typedef std::string ConfigurationValue;
+
+static Evas_Object *log_entry = NULL;
+
+string CONFIGURATION_COLLECTION_RESOURCE_URI = "/core/a/configuration/resourceset";
+string CONFIGURATION_COLLECTION_RESOURCE_TYPE = "core.configuration.resourceset";
+string DIAGNOSTIC_COLLECTION_RESOURCE_URI = "/core/a/diagnostics/resourceset";
+string DIAGNOSTIC_COLLECTION_RESOURCE_TYPE = "core.diagnostics.resourceset";
+string FACTORYSET_COLLECTION_RESOURCE_URI = "/core/a/factoryset/resourceset";
+string FACTORYSET_COLLECTION_RESOURCE_TYPE = "core.factoryset.resourceset";
+
+string CONFIGURATION_RESOURCE_URI = "/oic/con";
+string DIAGNOSTIC_RESOURCE_URI = "/oic/diag";
+string FACTORYSET_RESOURCE_URI = "/factorySet";
+
+ThingsManager *configthingsMgr = new ThingsManager();
+
+typedef struct region_popup
+{
+ Evas_Object *popup;
+ Evas_Object *entry;
+} region_popup_fields;
+
+void *updateConfigLog(void *data)
+{
+ string *log = (string *)data;
+ // Show the log
+ elm_entry_entry_append(log_entry, (*log).c_str());
+ elm_entry_cursor_end_set(log_entry);
+ return NULL;
+}
+
+// Callback to found collection resource
+void onFoundCollectionResource(std::vector< std::shared_ptr< OCResource > > resources)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCollectionResource ENTRY!!!!");
+ try
+ {
+ // Do some operations with resource object.
+ for (unsigned int i = 0; i < resources.size(); ++i)
+ {
+ string logMessage;
+ std::shared_ptr< OCResource > resource = resources.at(i);
+ if (resource)
+ {
+ string resourceURI = resource->host();
+ string hostAddress = resource->uri();
+ logMessage = "FoundHost: " + resource->host() + "<br>";
+ logMessage += "FoundUri : " + resource->uri() + "<br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "FoundHost: %s", resourceURI.c_str());
+ dlog_print(DLOG_INFO, LOG_TAG, "FoundUri : %s", hostAddress.c_str());
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
+ &logMessage);
+
+ if (resource->uri() == CONFIGURATION_COLLECTION_RESOURCE_URI)
+ g_configurationCollection = resource;
+ else if (resource->uri() == DIAGNOSTIC_COLLECTION_RESOURCE_URI)
+ g_diagnosticsCollection = resource;
+ else if (resource->uri() == FACTORYSET_COLLECTION_RESOURCE_URI)
+ g_setCollection = resource;
+ else
+ {
+ isWaiting = 0;
+ return;
+ }
+ }
+ else
+ {
+ // Resource is invalid
+ logMessage = "Found Resource invalid!";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
+ &logMessage);
+ }
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+ isWaiting = 0;
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCollectionResource EXIT!!!!");
+}
+
+// Callback to found candidate resources
+void onFoundCandidateResource(std::vector< std::shared_ptr< OCResource > > resources)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCandidateCollection ENTRY!!!!");
+ try
+ {
+ // Do some operations with resource object.
+ for (unsigned int i = 0; i < resources.size(); ++i)
+ {
+ string logMessage;
+ std::shared_ptr< OCResource > resource = resources.at(i);
+ if (resource)
+ {
+ // Check if the resource is new one. If so, store it.
+ std::map< std::string, std::shared_ptr< OCResource > >::iterator iter =
+ resourceTable.find(resource->host() + resource->uri());
+
+ if (iter == resourceTable.end()) // new one
+ {
+ resourceTable[resource->host() + resource->uri()] = resource;
+
+ OCResourceHandle foundResourceHandle = NULL;
+ OCStackResult result = OCPlatform::registerResource(foundResourceHandle,
+ resource);
+ // TODO: null check for foundResourceHandle
+ dlog_print(DLOG_INFO, LOG_TAG, "#### (%s) REGISTERED",
+ resource->host().c_str());
+ if (OC_STACK_OK == result)
+ {
+ string resourceURI = resource->host();
+ string hostAddress = resource->uri();
+ logMessage = "FoundHost: " + resource->host() + "<br>";
+ logMessage += "FoundUri: " + resource->uri()
+ + " Registered <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "Host: %s", resourceURI.c_str());
+ dlog_print(DLOG_INFO, LOG_TAG, "Uri : %s", hostAddress.c_str());
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
+ &logMessage);
+
+ if (resource->uri() == CONFIGURATION_RESOURCE_URI &&
+ NULL != configurationCollectionHandle)
+ {
+ OCPlatform::bindResource(configurationCollectionHandle,
+ foundResourceHandle);
+ configurationFoundHandle = foundResourceHandle;
+ if (NULL == g_configurationResource)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "g_configurationResource updated");
+ g_configurationResource = resource;
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG,
+ "g_configurationResource is not null");
+ }
+ }
+ else if (resource->uri() == DIAGNOSTIC_RESOURCE_URI &&
+ NULL != diagnosticsCollectionHandle)
+ {
+ OCPlatform::bindResource(diagnosticsCollectionHandle,
+ foundResourceHandle);
+ diagnosticsFoundHandle = foundResourceHandle;
+ if (NULL == g_diagnosticsResource)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG,
+ "g_diagnosticsResource updated");
+ g_diagnosticsResource = resource;
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG,
+ "g_diagnosticsResource is not null");
+ }
+ }
+ else if (resource->uri() == FACTORYSET_RESOURCE_URI &&
+ NULL != setCollectionHandle)
+ {
+ OCPlatform::bindResource(setCollectionHandle, foundResourceHandle);
+ setFoundHandle = foundResourceHandle;
+ if (NULL == g_setResource)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "g_setResource updated");
+ g_setResource = resource;
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "g_setResource is not null");
+ }
+ }
+ configResourceHandleVector.push_back(foundResourceHandle);
+ }
+ else
+ {
+ logMessage = "Resource Error!";
+ dlog_print(DLOG_INFO, LOG_TAG, "Resource Error!");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
+ &logMessage);
+ }
+ }
+ }
+ else
+ {
+ // Resource is invalid
+ logMessage = "Resource is invalid!";
+ dlog_print(DLOG_INFO, LOG_TAG, "Resource is invalid!");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
+ &logMessage);
+ }
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+
+ isWaiting = 0;
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onFoundCandidateCollection EXIT!!!!");
+}
+
+// Callback to updateConfiguration
+static void onUpdateConfigurationsCallback(const HeaderOptions &headerOptions,
+ const OCRepresentation &rep,
+ const int eCode)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onUpdateConfigurationsCallback: ENTRY!!!!");
+ isWaiting = 0;
+
+ if (SUCCESS_RESPONSE != eCode)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "#### onUpdateConfigurationsCallback: "
+ "ERROR RESPONSE!!!!");
+ return;
+ }
+
+ string logMessage = "Resource URI: " + rep.getUri() + "<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
+
+ if (rep.hasAttribute("loc"))
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Location : %s",
+ rep.getValue< std::string >("loc").c_str());
+ logMessage = logMessage + "Location : " + rep.getValue< std::string >("loc") + "<br>";
+ }
+ if (rep.hasAttribute("st"))
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### SystemTime : %s",
+ rep.getValue< std::string >("st").c_str());
+ logMessage = logMessage + "SystemTime : " + rep.getValue< std::string >("st") + "<br>";
+ }
+ if (rep.hasAttribute("c"))
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Currency : %s",
+ rep.getValue< std::string >("c").c_str());
+ logMessage = logMessage + "Currency : " + rep.getValue< std::string >("c") + "<br>";
+ }
+ if (rep.hasAttribute("r"))
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Region : %s",
+ rep.getValue< std::string >("r").c_str());
+ logMessage = logMessage + "Region : " + rep.getValue< std::string >("r") + "<br>";
+ }
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog,
+ &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onUpdateConfigurationsCallback: EXIT!!!!");
+}
+
+// Callback to getConfiguration
+static void onGetConfigurationsCallback(const HeaderOptions &headerOptions,
+ const OCRepresentation &rep,
+ const int eCode)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onGetConfigurationsCallback: enter!!!!");
+ isWaiting = 0;
+
+ if (SUCCESS_RESPONSE != eCode)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "#### onGetConfigurationsCallback: "
+ "ERROR RESPONSE!!!!");
+ return ;
+ }
+
+ string logMessage = "Resource URI: " + rep.getUri() + "<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
+
+ if (rep.hasAttribute("loc"))
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Location : %s",
+ rep.getValue< std::string >("loc").c_str());
+ logMessage = logMessage + "Location : " + rep.getValue< std::string >("loc") + "<br>";
+ }
+ if (rep.hasAttribute("st"))
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### SystemTime : %s",
+ rep.getValue< std::string >("st").c_str());
+ logMessage = logMessage + "SystemTime : " + rep.getValue< std::string >("st") + "<br>";
+ }
+ if (rep.hasAttribute("c"))
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Currency : %s",
+ rep.getValue< std::string >("c").c_str());
+ logMessage = logMessage + "Currency : " + rep.getValue< std::string >("c") + "<br>";
+ }
+ if (rep.hasAttribute("r"))
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Region : %s",
+ rep.getValue< std::string >("r").c_str());
+ logMessage = logMessage + "Region : " + rep.getValue< std::string >("r") + "<br>";
+ }
+
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onGetConfigurationsCallback: exit!!!!");
+}
+
+static void onFactoryReset(const HeaderOptions &headerOptions, const OCRepresentation &rep,
+ const int eCode)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onFactoryReset: enter!!!!");
+ isWaiting = 0;
+
+ if (SUCCESS_RESPONSE != eCode)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "#### onFactoryReset: ERROR RESPONSE!!!!");
+ return ;
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
+ dlog_print(DLOG_INFO, LOG_TAG, "#### FactoryReset : %s",
+ rep.getValue< std::string >("value").c_str());
+ string logMessage = "Resource URI : " + rep.getUri() + "<br>";
+ logMessage = logMessage + "FactoryReset : " +
+ rep.getValue< std::string >("value") + "<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onFactoryReset: exit!!!!");
+}
+
+static void onReboot(const HeaderOptions &headerOptions, const OCRepresentation &rep,
+ const int eCode)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onReboot: enter!!!!");
+ isWaiting = 0;
+
+ if (SUCCESS_RESPONSE != eCode)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "#### onReboot: ERROR RESPONSE!!!!");
+ return ;
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Resource URI: %s", rep.getUri().c_str());
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Reboot : %s",
+ rep.getValue< std::string >("value").c_str());
+ string logMessage = "Resource URI : " + rep.getUri() + "<br>";
+ logMessage = logMessage + "Reboot : " +
+ rep.getValue< std::string >("value") + "<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onReboot: exit!!!!");
+}
+
+static void createResourceCollection(string uri, string typeName, OCResourceHandle &tempHandle)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createResourceCollection: enter!!!!");
+ if (NULL != tempHandle)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Resource already exists!!!!");
+ return;
+ }
+
+ // Create resource collection
+ OCPlatform::registerResource(tempHandle, uri, typeName, BATCH_INTERFACE, NULL,
+ OC_DISCOVERABLE);
+ OCPlatform::bindInterfaceToResource(tempHandle, GROUP_INTERFACE);
+ OCPlatform::bindInterfaceToResource(tempHandle, DEFAULT_INTERFACE);
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Resource created : %s", typeName.c_str());
+ string logMessage;
+ logMessage = "Resource created : <br>" + typeName + "<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createResourceCollection: exit!!!!");
+}
+
+// Unbinds and unregisters all resources
+static void deleteResource(OCResourceHandle &tempCollectionHandle,
+ OCResourceHandle &tempResourceHandle)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling deleteResources ENTRY!!!!");
+
+ if (NULL == tempCollectionHandle || NULL == tempResourceHandle)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Collection or resource does not exists");
+ return;
+ }
+
+ try
+ {
+ OCPlatform::unbindResource(tempCollectionHandle, tempResourceHandle);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### unbindResource DONE!!!!");
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception Occured! (%s)", e.what());
+ }
+
+ try
+ {
+ OCPlatform::unregisterResource(tempResourceHandle);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### unregisterResource DONE!!!!");
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception Occured! (%s)", e.what());
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling deleteResources EXIT!!!!");
+}
+
+static void findAllGroups(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources ENTRY!!!!");
+ std::vector<string> resourceTypes;
+ resourceTypes.push_back(CONFIGURATION_COLLECTION_RESOURCE_TYPE);
+
+ if (NULL != configthingsMgr)
+ {
+ configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
+ }
+
+ resourceTypes.clear();
+ resourceTypes.push_back(DIAGNOSTIC_COLLECTION_RESOURCE_TYPE);
+ if (NULL != configthingsMgr)
+ {
+ configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
+ }
+
+ resourceTypes.clear();
+ resourceTypes.push_back(FACTORYSET_COLLECTION_RESOURCE_TYPE);
+ if (NULL != configthingsMgr)
+ {
+ configthingsMgr->findCandidateResources(resourceTypes, &onFoundCollectionResource, 5);
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources EXIT!!!!");
+}
+
+static void findAllResources(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources ENTRY!!!!");
+ std::vector<string> resourceTypes;
+ resourceTypes.push_back("oic.con");
+
+ if (NULL != configthingsMgr)
+ {
+ configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
+ }
+
+ resourceTypes.clear();
+ resourceTypes.push_back("oic.diag");
+ if (NULL != configthingsMgr)
+ {
+ configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
+ }
+
+ resourceTypes.clear();
+ resourceTypes.push_back("factorySet");
+ if (NULL != configthingsMgr)
+ {
+ configthingsMgr->findCandidateResources(resourceTypes, &onFoundCandidateResource, 7);
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources EXIT!!!!");
+}
+
+static void getConfiguration(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### getConfiguration ENTRY!!!!");
+ if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
+ string logMessage = "FIRST CREATE GROUP <br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ return;
+ }
+
+ ConfigurationName name = "all";
+ std::vector< ConfigurationName > configurations;
+ configurations.push_back(name);
+
+ try
+ {
+ configthingsMgr->getConfigurations(g_configurationCollection, configurations,
+ &onGetConfigurationsCallback);
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
+ }
+
+ isWaiting = 1;
+ dlog_print(DLOG_INFO, LOG_TAG, "#### getConfiguration EXIT!!!!");
+}
+
+// Updates the configuration i.e. region value to INDIA
+static void updateConfiguration(std::string newRegionValue)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### updateConfiguration ENTRY!!!!");
+ dlog_print(DLOG_INFO, LOG_TAG, "#### %s", newRegionValue.c_str());
+
+ if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
+ string logMessage = "FIRST CREATE GROUP <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ return;
+ }
+
+ OCStackResult result;
+ ConfigurationName name = "r";
+ ConfigurationValue value = newRegionValue;
+
+ std::map< ConfigurationName, ConfigurationValue > configurations;
+ configurations.insert(std::make_pair(name, value));
+
+ try
+ {
+ result = configthingsMgr->updateConfigurations(g_configurationCollection, configurations,
+ &onUpdateConfigurationsCallback);
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
+ }
+
+ if (OC_STACK_OK == result)
+ {
+ string logMessage = "UpdateConfigurations called successfully<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### updateConfiguration EXIT!!!!");
+}
+
+// This method will reset all the configuration attributes to their default values
+static void factoryReset(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### factoryReset ENTRY!!!!");
+ if (NULL == g_diagnosticsCollection || NULL == g_diagnosticsCollection.get())
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
+ string logMessage = "FIRST CREATE GROUP <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ return;
+ }
+
+ OCStackResult result;
+
+ try
+ {
+ result = configthingsMgr->factoryReset(g_diagnosticsCollection, &onFactoryReset);
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
+ }
+
+ if (OC_STACK_OK == result)
+ {
+ string logMessage = "FactoryReset called successfully<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### factoryReset EXIT!!!!");
+}
+
+// Reboots the server
+static void reboot(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### reboot ENTRY!!!!");
+ if (NULL == g_diagnosticsCollection || NULL == g_diagnosticsCollection.get())
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "Note that you first create a group to use this command");
+ string logMessage = "FIRST CREATE GROUP <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ return;
+ }
+
+ OCStackResult result;
+
+ try
+ {
+ result = configthingsMgr->reboot(g_diagnosticsCollection, &onReboot);
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception is occured! (%s)", e.what());
+ }
+
+ if (OC_STACK_OK == result)
+ {
+ string logMessage = "Reboot called successfully<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ }
+ dlog_print(DLOG_INFO, LOG_TAG, "#### reboot EXIT!!!!");
+}
+
+/* For getting list of all supported configuration Values it will give all
+ configuration in JSON format (key-value pair) */
+static void getListOfSupportedConfigurationUnits(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### getListOfSupportedConfigurationUnits ENTRY!!!!");
+ string listOfSupportedConfigurationUnits =
+ configthingsMgr->getListOfSupportedConfigurationUnits();
+ dlog_print(DLOG_INFO, LOG_TAG, "#### List : %s", listOfSupportedConfigurationUnits.c_str());
+
+ string logMessage;
+ logMessage = "Supported Configuration List :<br>" + listOfSupportedConfigurationUnits + "<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### getListOfSupportedConfigurationUnits EXIT!!!!");
+}
+
+// Creates all the resources
+static void onStartConfigure()
+{
+ createResourceCollection(CONFIGURATION_COLLECTION_RESOURCE_URI,
+ CONFIGURATION_COLLECTION_RESOURCE_TYPE,
+ configurationCollectionHandle);
+ createResourceCollection(DIAGNOSTIC_COLLECTION_RESOURCE_URI,
+ DIAGNOSTIC_COLLECTION_RESOURCE_TYPE,
+ diagnosticsCollectionHandle);
+ createResourceCollection(FACTORYSET_COLLECTION_RESOURCE_URI,
+ FACTORYSET_COLLECTION_RESOURCE_TYPE,
+ setCollectionHandle);
+}
+
+// Deletes all the resources
+static void onDestroyConfigure()
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called");
+
+ deleteResource(configurationCollectionHandle, configurationFoundHandle);
+
+ deleteResource(diagnosticsCollectionHandle, diagnosticsFoundHandle);
+
+ deleteResource(setCollectionHandle, setFoundHandle);
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Resources destroyed successfully");
+}
+
+static void
+popup_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ region_popup_fields *popup_fields = (region_popup_fields *)data;
+ evas_object_del(popup_fields->popup);
+ free(popup_fields);
+}
+
+static void
+popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ region_popup_fields *popup_fields = (region_popup_fields *)data;
+ Evas_Object *entry = popup_fields->entry;
+ const char *newRegionValue = elm_entry_entry_get(entry);
+ if (NULL == newRegionValue || strlen(newRegionValue) < 1)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL RegionValue");
+ string logMessage = "Region Value should not be NULL<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ }
+ else
+ {
+ std::string regionValue = std::string(newRegionValue);
+ updateConfiguration(regionValue);
+ }
+ evas_object_del(popup_fields->popup);
+ free(popup_fields);
+}
+
+static void
+list_update_region_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ if (NULL == g_configurationCollection || NULL == g_configurationCollection.get())
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Note that you first create a group to use this command");
+ string logMessage = "FIRST CREATE GROUP <br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateConfigLog, &logMessage);
+ return;
+ }
+
+ Evas_Object *popup, *btn;
+ Evas_Object *nf = (Evas_Object *)data;
+ Evas_Object *entry;
+ Evas_Object *layout;
+
+ /* popup */
+ popup = elm_popup_add(nf);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_part_text_set(popup, "title,text", "Enter New Region Value");
+
+ layout = elm_layout_add(popup);
+ elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_region_text");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_content_set(popup, layout);
+
+ entry = elm_entry_add(layout);
+ elm_entry_single_line_set(entry, EINA_TRUE);
+ elm_entry_scrollable_set(entry, EINA_TRUE);
+ evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
+ elm_object_part_text_set(entry, "elm.guide", "region value");
+ elm_object_part_content_set(layout, "elm.swallow.content" , entry);
+
+ region_popup_fields *popup_fields;
+ popup_fields = (region_popup_fields *)malloc(sizeof(region_popup_fields));
+ if (NULL == popup_fields)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Memory allocation failed");
+ popup_fields->popup = NULL;
+ popup_fields->entry = NULL;
+ }
+ else
+ {
+ popup_fields->popup = popup;
+ popup_fields->entry = entry;
+ }
+
+ /* Cancel button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Cancel");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", popup_cancel_clicked_cb, popup_fields);
+
+ /* Set button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Set");
+ elm_object_part_content_set(popup, "button2", btn);
+ evas_object_smart_callback_add(btn, "clicked", popup_set_clicked_cb, popup_fields);
+
+ evas_object_show(popup);
+}
+
+static void
+list_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = (Elm_Object_Item *)event_info;
+ elm_list_item_selected_set(it, EINA_FALSE);
+}
+
+void
+test_fn(void *data, Evas_Object *obj, void *event_info)
+{
+ if (NULL != log_entry)
+ {
+ elm_entry_entry_append(log_entry, "First item selected");
+ elm_entry_cursor_end_set(log_entry);
+ }
+ else
+ {
+ dlog_print(DLOG_ERROR, "test_fn", "log_entry object is NULL");
+ }
+}
+
+static Eina_Bool
+naviframe_pop_cb(void *data, Elm_Object_Item *it)
+{
+ onDestroyConfigure();
+ if (NULL != log_entry)
+ {
+ evas_object_del(log_entry);
+ log_entry = NULL;
+ }
+ return EINA_TRUE;
+}
+
+// Method to be called when configuration API UI button is selected
+void
+configuration_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *layout;
+ Evas_Object *scroller;
+ Evas_Object *list;
+ Evas_Object *nf = (Evas_Object *)data;
+ Elm_Object_Item *nf_it;
+
+ // Scroller
+ scroller = elm_scroller_add(nf);
+ elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ // Layout
+ layout = elm_layout_add(nf);
+ elm_layout_file_set(layout, ELM_DEMO_EDJ, "configuration_layout");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ elm_object_content_set(scroller, layout);
+
+ // List
+ list = elm_list_add(layout);
+ elm_list_mode_set(list, ELM_LIST_COMPRESS);
+ evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
+ elm_object_part_content_set(layout, "list", list);
+ elm_list_go(list);
+
+ // log_entry - text area for log
+ log_entry = elm_entry_add(layout);
+ elm_entry_scrollable_set(log_entry, EINA_TRUE);
+ elm_entry_editable_set(log_entry, EINA_FALSE);
+ elm_object_part_text_set(log_entry, "elm.guide", "logs will be updated here!!!");
+ evas_object_size_hint_weight_set(log_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(log_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_part_content_set(layout, "log", log_entry);
+
+ nf_it = elm_naviframe_item_push(nf, "configuration APIs", NULL, NULL, scroller, NULL);
+ elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL);
+
+ onStartConfigure();
+
+ // Shows the UI list of group APIs
+ elm_list_item_append(list, "Find All Groups", NULL, NULL, findAllGroups, NULL);
+ elm_list_item_append(list, "Find All Resources",
+ NULL, NULL, findAllResources, NULL);
+ elm_list_item_append(list, "Get a Configuration Resource", NULL, NULL, getConfiguration, NULL);
+ elm_list_item_append(list, "Update Attribute (Region)", NULL, NULL,
+ list_update_region_cb, nf);
+ elm_list_item_append(list, "Factory Reset", NULL, NULL, factoryReset, NULL);
+ elm_list_item_append(list, "Reboot", NULL, NULL, reboot, NULL);
+ elm_list_item_append(list, "Get Supported Configuration Units", NULL, NULL,
+ getListOfSupportedConfigurationUnits, NULL);
+
+ elm_list_go(list);
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include <algorithm>
+
+#include "tmsampleapp.h"
+#include "tmutil.h"
+
+using namespace std;
+using namespace OC;
+using namespace OIC;
+
+namespace PH = std::placeholders;
+
+static Evas_Object *log_entry = NULL;
+static Evas_Object *list = NULL;
+static Evas_Object *naviframe = NULL;
+
+string BULBOFF = "AllBulbOff";
+string BULBON = "AllBulbOn";
+string resourceURI = "/core/b/collection";
+string resourceTypeName = "b.collection";
+
+std::vector< OCResourceHandle > groupResourceHandleVector;
+OCResourceHandle resourceHandle = NULL;
+OCResourceHandle foundResourceHandle = NULL;
+shared_ptr< OCResource > g_resource ;
+std::vector< string > lights;
+
+ThingsManager *groupThingsMgr = new ThingsManager();
+
+typedef struct datetime_popup
+{
+ Evas_Object *popup;
+ Evas_Object *entry;
+} datetime_popup_fields;
+
+// Function to update the log in UI
+void *updateGroupLog(void *data)
+{
+ string *log = (string *)data;
+ // Show the log
+ elm_entry_entry_append(log_entry, (*log).c_str());
+ elm_entry_cursor_end_set(log_entry);
+ return NULL;
+}
+
+void onPut(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
+{
+ string logMessage;
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onPut Callback Received!!!!");
+ logMessage += "API Result: Success<br>onPut Callback Received<br>";
+ if (OC_STACK_OK == eCode)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Result is OK");
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Invalid Parameter");
+ }
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
+ &logMessage);
+}
+
+void onPost(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onPost callback received ENTRY!!!!");
+ string logMessage;
+ logMessage += "API Result: Success<br>onPost Callback Received<br>";
+
+ if (rep.hasAttribute("ActionSet"))
+ {
+ string plainText;
+ if (rep.getValue("ActionSet", plainText))
+ {
+ ActionSet *actionset = groupThingsMgr->getActionSetfromString(plainText);
+ if (NULL != actionset)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### ACTIONSET NAME :: (%s)",
+ actionset->actionsetName.c_str());
+ logMessage += "ACTIONSET NAME :: " + actionset->actionsetName + "<br>";
+ for (auto actIter = actionset->listOfAction.begin();
+ actIter != actionset->listOfAction.end(); ++actIter)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### TARGET :: (%s)",
+ (*actIter)->target.c_str());
+ logMessage += logMessage + "TARGET :: " + (*actIter)->target + "<br>";
+ for (auto capaIter = (*actIter)->listOfCapability.begin();
+ capaIter != (*actIter)->listOfCapability.end(); ++capaIter)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### POWER :: (%s)",
+ (*capaIter)->status.c_str());
+ logMessage += logMessage + "CAPABILITY :: " +
+ (*capaIter)->status + "<br>";
+ }
+ }
+ }
+ delete actionset;
+ }
+ }
+ else if (rep.hasAttribute("DoAction"))
+ {
+ string plainText;
+ if (rep.getValue("DoAction", plainText))
+ {
+ logMessage += plainText + "<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### DO ACTION :: (%s)", plainText.c_str());
+
+ }
+ }
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
+ &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onPost callback received EXIT!!!!");
+}
+
+// Method for Creating the action Set AllBulbOff
+static void createActionSet_AllBulbOff()
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff ENTRY");
+
+ OIC::ActionSet *actionSet = new OIC::ActionSet();
+ actionSet->actionsetName = BULBOFF;
+ int size = lights.size();
+
+ if (0 == size)
+ {
+ string logMessage = "NO LIGHTSERVER FOUND <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
+ &logMessage);
+ return;
+ }
+
+ for (int i = 0; i < size; i++)
+ {
+ OIC::Action *action = new OIC::Action();
+ action->target = lights.at(i);
+
+ OIC::Capability *capability = new OIC::Capability();
+ capability->capability = "power";
+ capability->status = "off";
+
+ action->listOfCapability.push_back(capability);
+ actionSet->listOfAction.push_back(action);
+ }
+ dlog_print(DLOG_INFO, LOG_TAG, "#### G_URI: %s", g_resource->uri().c_str());
+ dlog_print(DLOG_INFO, LOG_TAG, "#### G_HOST: %S", g_resource->host().c_str());
+
+ try
+ {
+ if (g_resource)
+ {
+ groupThingsMgr->addActionSet(g_resource, actionSet, onPut);
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+ delete actionSet;
+
+ string logMessage = "Create actionset AllBulbOFF success <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff EXIT");
+}
+
+/* Method for Creating the action Set AllBulbOn
+ once we create the ActionSet we can execute Action Set using executeActionSetOn()
+ or delete using deleteActionSetOn() */
+static void createActionSet_AllBulbOn()
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOn ENTRY");
+
+ OIC::ActionSet *actionSet = new OIC::ActionSet();
+ actionSet->actionsetName = BULBON;
+ int size = lights.size();
+
+ if (0 == size)
+ {
+ string logMessage = "NO LIGHTSERVER FOUND <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ return;
+ }
+
+ for (int i = 0; i < size; i++)
+ {
+ OIC::Action *action = new OIC::Action();
+ action->target = lights.at(i);
+
+ OIC::Capability *capability = new OIC::Capability();
+ capability->capability = "power";
+ capability->status = "on";
+
+ action->listOfCapability.push_back(capability);
+ actionSet->listOfAction.push_back(action);
+ }
+ string URI = g_resource->uri();
+ string host = g_resource->host();
+ dlog_print(DLOG_INFO, LOG_TAG, "#### G_URI: %s", g_resource->uri().c_str());
+ dlog_print(DLOG_INFO, LOG_TAG, "#### G_HOST: %S", g_resource->host().c_str());
+
+ try
+ {
+ if (g_resource)
+ {
+ groupThingsMgr->addActionSet(g_resource, actionSet, onPut);
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+ delete actionSet;
+
+ string logMessage = "Create actionset AllBulbON success <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createActionSet_AllBulbOff OFF EXIT");
+}
+
+static void createRecursiveActionSet_AllBulbOn(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createRecursiveActionSet_AllBulbOn ENTRY");
+ string actionsetDesc;
+ ActionSet *allBulbOn = new ActionSet();
+ allBulbOn->type = OIC::ACTIONSET_TYPE::RECURSIVE;
+
+ allBulbOn->actionsetName = "AllBulbOnRecursiveCall";
+ allBulbOn->mTime.tm_year = 0;
+ allBulbOn->mTime.tm_mon = 0;
+ allBulbOn->mTime.tm_mday = 0;
+ allBulbOn->mTime.tm_hour = 0;
+ allBulbOn->mTime.tm_min = 0;
+ allBulbOn->mTime.tm_sec = 5;
+
+ allBulbOn->setDelay(allBulbOn->getSecAbsTime());
+
+ for (auto iter = lights.begin(); iter != lights.end(); ++iter)
+ {
+ Action *action = new Action();
+ action->target = (*iter);
+
+ Capability *capa = new Capability();
+ capa->capability = "power";
+ capa->status = "on";
+
+ action->listOfCapability.push_back(capa);
+ allBulbOn->listOfAction.push_back(action);
+ }
+ if (g_resource)
+ {
+ groupThingsMgr->addActionSet(g_resource, allBulbOn, onPut);
+ }
+
+ delete allBulbOn;
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createRecursiveActionSet_AllBulbOn EXIT");
+}
+
+static void createScheduledActionSet_AllBulbOff(int date, int month, int year,
+ int hour, int minute, int second)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createScheduledActionSet_AllBulbOff ENTRY");
+ string actionsetDesc;
+ ActionSet *allBulbOff = new ActionSet();
+ allBulbOff->type = OIC::ACTIONSET_TYPE::SCHEDULED;
+ allBulbOff->actionsetName = "AllBulbOffScheduledCall";
+ allBulbOff->mTime.tm_year = year;
+ allBulbOff->mTime.tm_mon = month;
+ allBulbOff->mTime.tm_mday = date;
+ allBulbOff->mTime.tm_hour = hour;
+ allBulbOff->mTime.tm_min = minute;
+ allBulbOff->mTime.tm_sec = second;
+ dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_year :: %ld",
+ allBulbOff->mTime.tm_year);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_mon :: %ld",
+ allBulbOff->mTime.tm_mon);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_mday :: %ld",
+ allBulbOff->mTime.tm_mday);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_hour :: %ld",
+ allBulbOff->mTime.tm_hour);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_min :: %ld",
+ allBulbOff->mTime.tm_min);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### allBulbOff->mTime.tm_sec :: %ld",
+ allBulbOff->mTime.tm_sec);
+
+ allBulbOff->setDelay(allBulbOff->getSecondsFromAbsoluteTime());
+
+ for (auto iter = lights.begin(); iter != lights.end(); ++iter)
+ {
+ Action *action = new Action();
+ action->target = (*iter);
+
+ Capability *capa = new Capability();
+ capa->capability = "power";
+ capa->status = "off";
+
+ action->listOfCapability.push_back(capa);
+ allBulbOff->listOfAction.push_back(action);
+ }
+ if (g_resource)
+ {
+ groupThingsMgr->addActionSet(g_resource, allBulbOff, onPut);
+ }
+
+ delete allBulbOff;
+ dlog_print(DLOG_INFO, LOG_TAG, "#### createScheduledActionSet_AllBulbOff EXIT");
+}
+
+static void scheduled_AllbulbOff(void *data, Evas_Object *obj, void *event_info)
+{
+ groupThingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
+}
+
+static void scheduled_AllbulbOffEx(void *data, Evas_Object *obj, void *event_info)
+{
+ groupThingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", 10, &onPost);
+}
+
+static void cancelScheduled_AllBulbOff(void *data, Evas_Object *obj, void *event_info)
+{
+ groupThingsMgr->cancelActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
+}
+
+static void recursive_allBulbOn(void *data, Evas_Object *obj, void *event_info)
+{
+ groupThingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
+}
+
+static void recursive_allBulbOnEx(void *data, Evas_Object *obj, void *event_info)
+{
+ groupThingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", 10, &onPost);
+}
+
+static void cancelRecursive_allBulbOn(void *data, Evas_Object *obj, void *event_info)
+{
+
+ groupThingsMgr->cancelActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
+}
+
+/* Method for executing the action Set AllBulbOff that we have created using
+ createActionSet_AllBulbOff() */
+static void executeActionSetOff(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOff ENTRY");
+ int size = lights.size();
+
+ if (0 == size)
+ {
+ string logMessage = "NO LIGHTSERVER FOUND <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ return;
+ }
+
+ try
+ {
+ if (g_resource)
+ {
+ groupThingsMgr->executeActionSet(g_resource, BULBOFF, &onPost);
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+
+ string logMessage = "Actionset OFF called successfully <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOff EXIT");
+}
+
+/* Method for executing the action Set AllBulbOn that we have created using
+ createActionSet_AllBulbOn() */
+static void executeActionSetOn(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOn ENTRY");
+ int size = lights.size();
+
+ if (0 == size)
+ {
+ string logMessage = "NO LIGHTSERVER FOUND <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ return;
+ }
+
+ try
+ {
+ if (g_resource)
+ {
+ groupThingsMgr->executeActionSet(g_resource, BULBON, &onPost);
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+
+ string logMessage = "Actionset ON called successfully <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### executeActionSetOn EXIT");
+}
+
+/* Method for getting the action Set AllBulbOff that we have created using
+ createActionSet_AllBulbOff() */
+static void getActionSetOff(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOff ENTRY");
+ int size = lights.size();
+
+ if (0 == size)
+ {
+ string logMessage = "NO LIGHTSERVER FOUND <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ return;
+ }
+
+ try
+ {
+ if (g_resource)
+ {
+ groupThingsMgr->getActionSet(g_resource, BULBOFF, &onPost);
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOff EXIT");
+}
+
+/* Method for getting the action Set AllBulbOn that we have created using
+ createActionSet_AllBulbOn() */
+static void getActionSetOn(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOn ENTRY");
+ int size = lights.size();
+
+ if (0 == size)
+ {
+ string logMessage = "NO LIGHTSERVER FOUND <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ return;
+ }
+
+ try
+ {
+ if (g_resource)
+ {
+ groupThingsMgr->getActionSet(g_resource, BULBON, &onPost);
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### getActionSetOn EXIT");
+}
+
+/* Method for deleting the action Set AllBulbOff that we have created using
+ createActionSet_AllBulbOff() */
+static void deleteActionSetOff(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOff ENTRY");
+ int size = lights.size();
+
+ if (0 == size)
+ {
+ string logMessage = "NO LIGHTSERVER FOUND <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ return;
+ }
+
+ try
+ {
+ if (g_resource)
+ {
+ groupThingsMgr->deleteActionSet(g_resource, BULBOFF, &onPost);
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+
+ string logMessage = "Actionset OFF DELETED <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOff EXIT");
+}
+
+/* Method for deleting the action Set AllBulbOn that we have created using
+ createActionSet_AllBulbOn() */
+static void deleteActionSetOn(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOn ENTRY");
+ int size = lights.size();
+
+ if (0 == size)
+ {
+ string logMessage = "NO LIGHTSERVER FOUND <br>";
+ logMessage += "----------------------<br>";
+ dlog_print(DLOG_INFO, LOG_TAG, "#### NO LIGHT SERVER FOUND");
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ return;
+ }
+
+ try
+ {
+ if (g_resource)
+ {
+ groupThingsMgr->deleteActionSet(g_resource, BULBON, &onPost);
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+
+ string logMessage = "Actionset ON DELETED <br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### deleteActionSetOn EXIT");
+}
+
+void onObserve(const HeaderOptions headerOptions, const OCRepresentation &rep, const int &eCode,
+ const int &sequenceNumber)
+{
+ string logMessage;
+ char *buf;
+ if (OC_STACK_OK == eCode)
+ {
+ int level;
+ buf = (char *)malloc(4 * sizeof(char));
+ sprintf(buf, "%d", sequenceNumber);
+ logMessage = "OBSERVE RESULT <br>";
+ logMessage += "Sequencenumber:" + string(buf) + "<br>";
+
+ if (rep.getValue("level", level))
+ {
+ if (level == 0)
+ {
+ createActionSet_AllBulbOn();
+ executeActionSetOn(NULL, NULL, NULL);
+ }
+ else
+ {
+ createActionSet_AllBulbOff();
+ executeActionSetOff(NULL, NULL, NULL);
+ }
+ }
+ sprintf(buf, "%d", level);
+ logMessage += "level:" + string(buf) + "<br>";
+ }
+ else
+ {
+ logMessage = "onObserve error!!!";
+ }
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
+ &logMessage);
+}
+
+// Callback to be called when resources are found in the network
+void foundResources(std::vector< std::shared_ptr< OC::OCResource > > listOfResource)
+{
+ try
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### foundResources entry!!!!");
+
+ for (auto rsrc = listOfResource.begin(); rsrc != listOfResource.end(); ++rsrc)
+ {
+ string resourceURI = (*rsrc)->uri();
+ string hostAddress = (*rsrc)->host();
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### found uri: %s", resourceURI.c_str());
+ dlog_print(DLOG_INFO, LOG_TAG, "#### found host address: %s", hostAddress.c_str());
+ string logMessage = "URI: " + resourceURI + "<br>";
+ logMessage = logMessage + "Host:" + hostAddress + "<br>";
+ logMessage += "----------------------<br>";
+
+ if (resourceURI == "/a/light")
+ {
+ bool found;
+ found = std::find(lights.begin(), lights.end(),
+ hostAddress + resourceURI) != lights.end();
+ if (found == false)
+ {
+ lights.push_back((hostAddress + resourceURI));
+
+ try
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Registering Resource");
+ OCStackResult result = OCPlatform::registerResource(foundResourceHandle,
+ (*rsrc));
+ dlog_print(DLOG_INFO, LOG_TAG, "#### %s REGISTERED", resourceURI.c_str());
+ if (result == OC_STACK_OK)
+ {
+ OCPlatform::bindResource(resourceHandle, foundResourceHandle);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Bind Resource Done");
+ groupResourceHandleVector.push_back(foundResourceHandle);
+ }
+ else
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "#### Register Resource ERROR");
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+ }
+ }
+ else if (resourceURI == "/core/bookmark")
+ {
+ logMessage += "OBSERVING : " + resourceURI + "<br>";
+ logMessage += "----------------------<br>";
+ (*rsrc)->observe(ObserveType::Observe, QueryParamsMap(), &onObserve);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### after calling observe() for bookmark!!!!");
+ }
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
+ &logMessage);
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### foundResources exit!!!!");
+ }
+ catch (...)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Exception caught in foundResources");
+ }
+}
+
+static void create_group()
+{
+ if (NULL != groupThingsMgr)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling findCandidateResources from "
+ "create_group!!!!");
+ vector< string > types;
+ types.push_back("core.light");
+ groupThingsMgr->findCandidateResources(types, &foundResources, 5);
+ }
+
+ try
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling registerResource from create_group!!!!");
+ OCPlatform::registerResource(resourceHandle, resourceURI, resourceTypeName,
+ BATCH_INTERFACE, NULL,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (NULL != resourceHandle)
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Obtained resourceHandle from "
+ "registerResource!!!!");
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### calling bindInterfaceToResource from "
+ "create_group!!!!");
+ OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
+ OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+}
+
+// Method for Finding the Light Resource
+void findLightResource(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### findLightResource ENTRY");
+ if (NULL != groupThingsMgr)
+ {
+ vector< string > types;
+ types.push_back("core.light");
+ OCStackResult result = groupThingsMgr->findCandidateResources(types, &foundResources, 5);
+ if (result == OC_STACK_OK)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### create_group -- findCandidateResources :: "
+ "OC_STACK_OK!!!!");
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources failed!!");
+ }
+ }
+ dlog_print(DLOG_INFO, LOG_TAG, "#### findLightResource EXIT");
+}
+
+// Method for observing the Bookmark Resource
+void observeBookMark(void *data, Evas_Object *obj, void *event_info)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### observeBookMark ENTRY");
+ if (NULL != groupThingsMgr)
+ {
+ vector< string > types;
+ types.push_back("core.bookmark");
+ OCStackResult result = groupThingsMgr->findCandidateResources(types, &foundResources, 5);
+ if (OC_STACK_OK == result)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources :: "
+ "OC_STACK_OK!!!!");
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### create_group - findCandidateResources failed!!");
+ }
+ }
+ dlog_print(DLOG_INFO, LOG_TAG, "#### observeBookMark EXIT");
+}
+
+static void onDestroy()
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Destroy sequence called");
+
+ try
+ {
+ if (NULL != foundResourceHandle)
+ {
+ OCPlatform::unregisterResource(foundResourceHandle);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Light Resource unregistered");
+ lights.clear();
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### No resouceHandle found to unregister");
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+
+ try
+ {
+ if (NULL != resourceHandle)
+ {
+ // Unbind Light resource
+ if (NULL != foundResourceHandle)
+ {
+ OCPlatform::unbindResource(resourceHandle, foundResourceHandle);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Resource Unbind Done");
+ }
+ OCPlatform::unregisterResource(resourceHandle);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Group Unregistered");
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### foundResourceHandle is NULL");
+ }
+ }
+ catch (std::exception &e)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Exception occured! (%s)", e.what());
+ }
+}
+
+static void createActionSet(void *data, Evas_Object *obj, void *event_info)
+{
+ createActionSet_AllBulbOff();
+ createActionSet_AllBulbOn();
+}
+
+static void
+popup_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ datetime_popup_fields *popup_fields = (datetime_popup_fields *)data;
+ evas_object_del(popup_fields->popup);
+ free(popup_fields);
+}
+
+static int parseString(const char *str, int slen, int *beg, int what)
+{
+ int i, val = 0, ch = '/';
+ if (2 == what)
+ {
+ ch = ' ';
+ }
+ else if (3 <= what)
+ {
+ if (5 == what)
+ {
+ ch = '\0';
+ }
+ else
+ {
+ ch = ':';
+ }
+ }
+ // Remove whitespaces(if any) at the beginning
+ while (str[*beg] == ' ')
+ {
+ (*beg)++;
+ }
+ for (i = *beg; i < slen; i++)
+ {
+ if (str[i] != ch)
+ {
+ val = (val * 10) + (str[i] - 48);
+ continue;
+ }
+ break;
+ }
+ (*beg) = i + 1;
+ return val;
+}
+
+static bool validate(int date, int month, int year, int hour, int minute, int second)
+{
+ if (date <= 0 || month <= 0 || year <= 0 || hour < 0 || minute < 0 || second < 0
+ || month >= 13 || hour >= 24 || minute >= 60 || second >= 60)
+ {
+ return false;
+ }
+ return true;
+}
+
+static void
+popup_set_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ datetime_popup_fields *popup_fields = (datetime_popup_fields *)data;
+ Evas_Object *entry = popup_fields->entry;
+ const char *dateTimeValue = elm_entry_entry_get(entry);
+ int len;
+ len = strlen(dateTimeValue);
+ if (NULL == dateTimeValue || 1 > len)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Read NULL DateTime Value");
+ string logMessage = "DateTime should not be NULL<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog, &logMessage);
+ }
+ else
+ {
+ int date, month, year, hour, minute, second;
+ int beg = 0;
+ date = parseString(dateTimeValue, len, &beg, 0);
+ month = parseString(dateTimeValue, len, &beg, 1);
+ year = parseString(dateTimeValue, len, &beg, 2);
+ hour = parseString(dateTimeValue, len, &beg, 3);
+ minute = parseString(dateTimeValue, len, &beg, 4);
+ second = parseString(dateTimeValue, len, &beg, 5);
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### %d", date);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### %d", month);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### %d", year);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### %d", hour);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### %d", minute);
+ dlog_print(DLOG_INFO, LOG_TAG, "#### %d", second);
+ bool valid = validate(date, month, year, hour, minute, second);
+ if (valid)
+ {
+ createScheduledActionSet_AllBulbOff(date, month, year, hour, minute, second);
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Incorrect date/time values");
+ string logMessage = "Incorrect date/time value<br>";
+ logMessage += "----------------------<br>";
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
+ &logMessage);
+ }
+ }
+ evas_object_del(popup_fields->popup);
+ free(popup_fields);
+}
+
+static void
+list_scheduled_actionset_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *popup, *btn;
+ Evas_Object *nf = naviframe;
+ Evas_Object *entry;
+ Evas_Object *layout;
+
+ /* popup */
+ popup = elm_popup_add(nf);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_part_text_set(popup, "title,text", "Enter the date and time");
+
+ layout = elm_layout_add(popup);
+ elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_datetime_text");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_content_set(popup, layout);
+
+ entry = elm_entry_add(layout);
+ elm_entry_single_line_set(entry, EINA_TRUE);
+ elm_entry_scrollable_set(entry, EINA_TRUE);
+ evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
+ elm_object_part_text_set(entry, "elm.guide", "dd/mm/yyyy hh:mm:ss");
+ elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER);
+ elm_object_part_content_set(layout, "elm.swallow.content", entry);
+
+ datetime_popup_fields *popup_fields;
+ popup_fields = (datetime_popup_fields *)malloc(sizeof(datetime_popup_fields));
+ if (NULL == popup_fields)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Memory allocation failed");
+ popup_fields->popup = NULL;
+ popup_fields->entry = NULL;
+ }
+ else
+ {
+ popup_fields->popup = popup;
+ popup_fields->entry = entry;
+ }
+
+ /* Cancel button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Cancel");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", popup_cancel_clicked_cb, popup_fields);
+
+ /* Set button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Set");
+ elm_object_part_content_set(popup, "button2", btn);
+ evas_object_smart_callback_add(btn, "clicked", popup_set_clicked_cb, popup_fields);
+
+ evas_object_show(popup);
+}
+
+void *showGroupAPIs(void *data)
+{
+ // Add items to the list only if the list is empty
+ const Eina_List *eina_list = elm_list_items_get(list);
+ int count = eina_list_count(eina_list);
+ if (!count)
+ {
+ elm_list_item_append(list, "1. Create ActionSet<br>(ALLBULBON and ALLBULBOFF)", NULL, NULL,
+ createActionSet, NULL);
+
+ elm_list_item_append(list, "2. Execute ActionSet (ALLBULBON)", NULL, NULL,
+ executeActionSetOn, NULL);
+
+ elm_list_item_append(list, "3. Execute ActionSet (ALLBULBOFF)", NULL, NULL,
+ executeActionSetOff, NULL);
+
+ elm_list_item_append(list, "4. Create ActionSet<br>(Recursive_ALLBULBON)", NULL, NULL,
+ createRecursiveActionSet_AllBulbOn, NULL);
+
+ elm_list_item_append(list, " 4.1 Execute ActionSet", NULL, NULL,
+ recursive_allBulbOn, NULL);
+
+ elm_list_item_append(list, " 4.2 Cancel ActionSet", NULL, NULL,
+ cancelRecursive_allBulbOn, NULL);
+
+ elm_list_item_append(list, "5. Create ActionSet<br>(Scheduled_ALLBULBOFF)", NULL, NULL,
+ list_scheduled_actionset_cb, NULL);
+
+ elm_list_item_append(list, " 5.1 Execute ActionSet", NULL, NULL,
+ scheduled_AllbulbOff, NULL);
+
+ elm_list_item_append(list, " 5.2 Cancel ActionSet", NULL, NULL,
+ cancelScheduled_AllBulbOff, NULL);
+
+ elm_list_item_append(list, "6. Get ActionSet (All BULBOFF)", NULL, NULL,
+ getActionSetOff, NULL);
+
+ elm_list_item_append(list, "7. Delete ActionSet (All BULBOFF)", NULL, NULL,
+ deleteActionSetOff, NULL);
+
+ elm_list_item_append(list, "8. Find BookMark to Observe", NULL, NULL,
+ observeBookMark, NULL);
+
+ elm_list_go(list);
+ }
+ return NULL;
+}
+
+// Callback to be called when a resource is found in the network
+void foundResource(shared_ptr< OCResource > resource)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### foundResource entry!!!!");
+
+ if (resource)
+ {
+ string resourceURI = resource->uri();
+ string hostAddress = resource->host();
+ string logMessage;
+ if (resourceURI == "/core/b/collection")
+ {
+ g_resource = resource;
+ dlog_print(DLOG_INFO, LOG_TAG, "#### FOUND URI: %s", resourceURI.c_str());
+ dlog_print(DLOG_INFO, LOG_TAG, "#### FOUND HOST: %s", hostAddress.c_str());
+ logMessage = "FOUND RESOURCE URI <br>" + resourceURI + "<br>";
+ logMessage = "FOUND RESOURCE HOST <br>" + hostAddress + "<br>";
+ logMessage += "----------------------<br>";
+ // Show the UI list of group APIs
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))showGroupAPIs, NULL);
+
+ }
+ ecore_main_loop_thread_safe_call_sync((void * ( *)(void *))updateGroupLog,
+ &logMessage);
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### foundResource exit!!!!");
+}
+
+static void list_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = (Elm_Object_Item *)event_info;
+ elm_list_item_selected_set(it, EINA_FALSE);
+}
+
+// Method for Finding the Group
+static void find_group()
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup ENTRY");
+ vector< string > resourceTypes;
+ resourceTypes.push_back(resourceTypeName);
+ OCStackResult result = groupThingsMgr->findGroup(resourceTypes, &foundResource);
+ if (OC_STACK_OK == result)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup returned OC_STACK_OK");
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup failed");
+ }
+ dlog_print(DLOG_INFO, LOG_TAG, "#### findGroup EXIT");
+}
+
+// Method to be called when the Find Group UI Button is selected
+static void
+find_group_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ if (NULL != list)
+ {
+ find_group();
+ }
+ else
+ {
+ dlog_print(DLOG_ERROR, "find_group_cb", "list is NULL - So unable to add items!!!");
+ }
+}
+
+static Eina_Bool
+naviframe_pop_cb(void *data, Elm_Object_Item *it)
+{
+ onDestroy();
+
+ if (NULL != log_entry)
+ {
+ evas_object_del(log_entry);
+ log_entry = NULL;
+ }
+ if (NULL != list)
+ {
+ evas_object_del(list);
+ list = NULL;
+ }
+ return EINA_TRUE;
+}
+
+// Method to be called when the Group APIs UI Button is selected
+void group_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *layout;
+ Evas_Object *scroller;
+ Evas_Object *nf = (Evas_Object *)data;
+ Evas_Object *find_button;
+ Elm_Object_Item *nf_it;
+
+ naviframe = nf;
+
+ // Scroller
+ scroller = elm_scroller_add(nf);
+ elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ // Layout
+ layout = elm_layout_add(nf);
+ elm_layout_file_set(layout, ELM_DEMO_EDJ, "group_layout");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ elm_object_content_set(scroller, layout);
+
+ // Button
+ find_button = elm_button_add(layout);
+ elm_object_part_content_set(layout, "find_button", find_button);
+ elm_object_text_set(find_button, "Find Group");
+ evas_object_smart_callback_add(find_button, "clicked", find_group_cb, NULL);
+
+ // List
+ list = elm_list_add(layout);
+ elm_list_mode_set(list, ELM_LIST_COMPRESS);
+ evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
+ elm_object_part_content_set(layout, "list", list);
+ elm_list_go(list);
+
+ // log_entry - textarea for log
+ log_entry = elm_entry_add(layout);
+ elm_entry_scrollable_set(log_entry, EINA_TRUE);
+ elm_entry_editable_set(log_entry, EINA_FALSE);
+ elm_object_part_text_set(log_entry, "elm.guide", "Logs will be updated here!!!");
+ evas_object_size_hint_weight_set(log_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(log_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_part_content_set(layout, "log", log_entry);
+
+ nf_it = elm_naviframe_item_push(nf, "Group APIs", NULL, NULL, scroller, NULL);
+ elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, NULL);
+
+ create_group();
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "tmsampleapp.h"
+#include <tizen.h>
+
+typedef struct appdata
+{
+ Evas_Object *win;
+ Evas_Object *conform;
+ Evas_Object *layout;
+ Evas_Object *nf;
+ Evas_Object *findButton;
+ Evas_Object *logtext;
+ Evas_Object *listview;
+} appdata_s;
+
+static void
+win_delete_request_cb(void *data , Evas_Object *obj , void *event_info)
+{
+ ui_app_exit();
+}
+
+static void
+list_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = (Elm_Object_Item *)event_info;
+ elm_list_item_selected_set(it, EINA_FALSE);
+}
+
+static Eina_Bool
+naviframe_pop_cb(void *data, Elm_Object_Item *it)
+{
+ ui_app_exit();
+ return EINA_FALSE;
+}
+
+static void
+create_list_view(appdata_s *ad)
+{
+ Evas_Object *list;
+ Evas_Object *btn;
+ Evas_Object *nf = ad->nf;
+ Elm_Object_Item *nf_it;
+
+ // List
+ list = elm_list_add(nf);
+ elm_list_mode_set(list, ELM_LIST_COMPRESS);
+ evas_object_smart_callback_add(list, "selected", list_selected_cb, NULL);
+
+ // Main Menu Items Here
+ elm_list_item_append(list, "Group APIs", NULL, NULL, group_cb, nf);
+ elm_list_item_append(list, "Configuration APIs", NULL, NULL, configuration_cb, nf);
+
+ elm_list_go(list);
+
+ // This button is set for devices which doesn't have H/W back key.
+ btn = elm_button_add(nf);
+ elm_object_style_set(btn, "naviframe/end_btn/default");
+ nf_it = elm_naviframe_item_push(nf, "Things Manager", btn, NULL, list, NULL);
+ elm_naviframe_item_pop_cb_set(nf_it, naviframe_pop_cb, ad->win);
+}
+
+
+static void
+create_base_gui(appdata_s *ad)
+{
+ // Window
+ ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
+ elm_win_conformant_set(ad->win, EINA_TRUE);
+ elm_win_autodel_set(ad->win, EINA_TRUE);
+
+ if (elm_win_wm_rotation_supported_get(ad->win))
+ {
+ int rots[4] = { 0, 90, 180, 270 };
+ elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
+ }
+
+ evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
+
+ // Conformant
+ ad->conform = elm_conformant_add(ad->win);
+ evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(ad->win, ad->conform);
+ evas_object_show(ad->conform);
+
+ // Base Layout
+ ad->layout = elm_layout_add(ad->conform);
+ evas_object_size_hint_weight_set(ad->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_layout_theme_set(ad->layout, "layout", "application", "default");
+ evas_object_show(ad->layout);
+
+ elm_object_content_set(ad->conform, ad->layout);
+
+ // Naviframe
+ ad->nf = elm_naviframe_add(ad->layout);
+ create_list_view(ad);
+ elm_object_part_content_set(ad->layout, "elm.swallow.content", ad->nf);
+ eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
+ eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_MORE, eext_naviframe_more_cb, NULL);
+
+ // Show window after base gui is set up
+ evas_object_show(ad->win);
+}
+
+// Configures the OCPlatform
+static void
+configure_platform()
+{
+ try
+ {
+ PlatformConfig config
+ { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+
+ OCPlatform::Configure(config);
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Platform configuration done!!!!");
+ }
+ catch (OCException &e)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Platform configuration failed!!!!");
+ }
+}
+
+static bool
+app_create(void *data)
+{
+ /* Hook to take necessary actions before main event loop starts
+ Initialize UI resources and application's data
+ If this function returns true, the main loop of application starts
+ If this function returns false, the application is terminated */
+ appdata_s *ad = (appdata_s *)data;
+
+ elm_app_base_scale_set(1.8);
+
+ create_base_gui(ad);
+
+ configure_platform();
+
+ return true;
+}
+
+static void
+app_control(app_control_h app_control, void *data)
+{
+ // Handle the launch request.
+}
+
+static void
+app_pause(void *data)
+{
+ // Take necessary actions when application becomes invisible.
+}
+
+static void
+app_resume(void *data)
+{
+ // Take necessary actions when application becomes visible.
+}
+
+static void
+app_terminate(void *data)
+{
+ // Release all resources.
+}
+
+static void
+ui_app_lang_changed(app_event_info_h event_info, void *user_data)
+{
+ // APP_EVENT_LANGUAGE_CHANGED
+ char *locale = NULL;
+ system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
+ elm_language_set(locale);
+ free(locale);
+ return;
+}
+
+static void
+ui_app_orient_changed(app_event_info_h event_info, void *user_data)
+{
+ // APP_EVENT_DEVICE_ORIENTATION_CHANGED
+ return;
+}
+
+static void
+ui_app_region_changed(app_event_info_h event_info, void *user_data)
+{
+ // APP_EVENT_REGION_FORMAT_CHANGED
+}
+
+static void
+ui_app_low_battery(app_event_info_h event_info, void *user_data)
+{
+ // APP_EVENT_LOW_BATTERY
+}
+
+static void
+ui_app_low_memory(app_event_info_h event_info, void *user_data)
+{
+ // APP_EVENT_LOW_MEMORY
+}
+
+int
+main(int argc, char *argv[])
+{
+ appdata_s ad = {0,};
+ int ret = 0;
+
+ ui_app_lifecycle_callback_s event_callback = {0,};
+ app_event_handler_h handlers[5] = {NULL, };
+
+ event_callback.create = app_create;
+ event_callback.terminate = app_terminate;
+ event_callback.pause = app_pause;
+ event_callback.resume = app_resume;
+ event_callback.app_control = app_control;
+
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY,
+ ui_app_low_battery, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY,
+ ui_app_low_memory, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED],
+ APP_EVENT_DEVICE_ORIENTATION_CHANGED,
+ ui_app_orient_changed, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED],
+ APP_EVENT_LANGUAGE_CHANGED,
+ ui_app_lang_changed, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED],
+ APP_EVENT_REGION_FORMAT_CHANGED,
+ ui_app_region_changed, &ad);
+ ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
+
+ ret = ui_app_main(argc, argv, &event_callback, &ad);
+ if (APP_ERROR_NONE != ret)
+ {
+ dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
+ }
+ return ret;
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "tmutil.h"
+
+// Utility function to return the string equivalent of OCStackResult for the given integer value
+std::string getOCStackResultStringFromInt(int result)
+{
+ string ocresultstr;
+
+ switch (result)
+ {
+ case 0 :
+ ocresultstr = "OC_STACK_OK";
+ break;
+ case 1 :
+ ocresultstr = "OC_STACK_RESOURCE_CREATED";
+ break;
+ case 2 :
+ ocresultstr = "OC_STACK_RESOURCE_DELETED";
+ break;
+ case 3 :
+ ocresultstr = "OC_STACK_CONTINUE";
+ break;
+ case 20 :
+ ocresultstr = "OC_STACK_INVALID_URI";
+ break;
+ case 21 :
+ ocresultstr = "OC_STACK_INVALID_QUERY";
+ break;
+ case 22 :
+ ocresultstr = "OC_STACK_INVALID_QUERY";
+ break;
+ case 23 :
+ ocresultstr = "OC_STACK_INVALID_PORT";
+ break;
+ case 24 :
+ ocresultstr = "OC_STACK_INVALID_CALLBACK";
+ break;
+ case 25 :
+ ocresultstr = "OC_STACK_INVALID_METHOD";
+ break;
+ case 26 :
+ ocresultstr = "OC_STACK_INVALID_PARAM";
+ break;
+ case 27 :
+ ocresultstr = "OC_STACK_INVALID_OBSERVE_PARAM";
+ break;
+ case 28 :
+ ocresultstr = "OC_STACK_NO_MEMORY";
+ break;
+ case 29 :
+ ocresultstr = "OC_STACK_COMM_ERROR";
+ break;
+ case 30 :
+ ocresultstr = "OC_STACK_NOTIMPL";
+ break;
+ case 31 :
+ ocresultstr = "OC_STACK_NO_RESOURCE";
+ break;
+ case 32 :
+ ocresultstr = "OC_STACK_RESOURCE_ERROR";
+ break;
+ case 33 :
+ ocresultstr = "OC_STACK_SLOW_RESOURCE";
+ break;
+ case 34 :
+ ocresultstr = "OC_STACK_DUPLICATE_REQUEST";
+ break;
+ case 35 :
+ ocresultstr = "OC_STACK_NO_OBSERVERS";
+ break;
+ case 36 :
+ ocresultstr = "OC_STACK_OBSERVER_NOT_FOUND";
+ break;
+ case 37 :
+ ocresultstr = "OC_STACK_VIRTUAL_DO_NOT_HANDLE";
+ break;
+ case 38 :
+ ocresultstr = "OC_STACK_INVALID_OPTION";
+ break;
+ case 39 :
+ ocresultstr = "OC_STACK_MALFORMED_RESPONSE";
+ break;
+ case 40 :
+ ocresultstr = "OC_STACK_PERSISTENT_BUFFER_REQUIRED";
+ break;
+ case 41 :
+ ocresultstr = "OC_STACK_INVALID_REQUEST_HANDLE";
+ break;
+ case 42 :
+ ocresultstr = "OC_STACK_INVALID_DEVICE_INFO";
+ break;
+ case 43 :
+ ocresultstr = "OC_STACK_INVALID_JSON";
+ break;
+ case 128 :
+ ocresultstr = "OC_STACK_PRESENCE_STOPPED";
+ break;
+ case 129 :
+ ocresultstr = "OC_STACK_PRESENCE_TIMEOUT";
+ break;
+ case 130 :
+ ocresultstr = "OC_STACK_PRESENCE_DO_NOT_HANDLE";
+ break;
+ case 255 :
+ ocresultstr = "OC_STACK_ERROR";
+ break;
+ default :
+ ocresultstr = "OC_STACK_ERROR";
+ }
+ return ocresultstr;
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="2.3" package="org.tizen.tmsampleapp" version="1.0.0">
+ <profile name="mobile"/>
+ <ui-application appid="org.tizen.tmsampleapp" exec="tmsampleapp" multiple="false" nodisplay="false" taskmanage="true" type="capp">
+ <label>tmsampleapp</label>
+ <icon>tmsampleapp.png</icon>
+ </ui-application>
+ <privileges>
+ <privilege>http://tizen.org/privilege/internet</privilege>
+ </privileges>
+ <feature name="http://tizen.org/feature/network.wifi">true</feature>
+</manifest>