--- /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.
+ *
+ ******************************************************************/
+#ifndef __CONFIGURATION_RESOURCE_H__
+#define __CONFIGURATION_RESOURCE_H__
+
+#include <functional>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+#pragma once
+
+using namespace OC;
+
+typedef std::function<OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request)>
+ResourceEntityHandler;
+
+static std::string defaultURIPrefix = "/oic/con";
+static std::string defaultResourceTypePrefix = "oic.con";
+
+extern std::string defaultLocation;
+extern std::string defaultSystemTime;
+extern std::string defaultCurrency;
+extern std::string defaultRegion;
+
+class ConfigurationResource
+{
+ public:
+ // Configuration members
+ std::string m_configurationUri;
+ std::string m_location;
+ std::string m_systemTime;
+ std::string m_currency;
+ std::string m_region;
+ std::vector< std::string > m_configurationTypes;
+ std::vector< std::string > m_configurationInterfaces;
+ OCResourceHandle m_configurationHandle;
+ OCRepresentation m_configurationRep;
+
+ public:
+
+ ConfigurationResource();
+
+ void createResource(ResourceEntityHandler callback);
+
+ void setConfigurationRepresentation(OCRepresentation &rep);
+
+ OCRepresentation getConfigurationRepresentation();
+
+ std::string getUri();
+
+ void factoryReset();
+
+ void deleteResource();
+};
+
+#endif // __CONFIGURATION_RESOURCE_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.
+ *
+ ******************************************************************/
+
+#ifndef __CONSERVERAPP_H__
+#define __CONSERVERAPP_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 "conserverapp"
+
+#if !defined(PACKAGE)
+#define PACKAGE "org.tizen.conserverapp"
+#endif
+
+#define ELM_DEMO_EDJ "opt/usr/apps/org.tizen.conserverapp/res/ui_controls.edj"
+
+#endif // __CONSERVERAPP_H__
--- /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 __DIAGNOSTICS_RESOURCE_H__
+#define __DIAGNOSTICS_RESOURCE_H__
+
+#include <functional>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+#pragma once
+
+using namespace OC;
+
+typedef std::function<OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request)>
+ResourceEntityHandler;
+
+static std::string defaultFactoryReset = "false";
+static std::string defaultReboot = "false";
+static std::string defaultStartStatCollection = "false";
+
+class DiagnosticsResource
+{
+ public:
+ // Diagnostics members
+ std::string m_diagnosticsUri;
+ std::string m_factoryReset;
+ std::string m_reboot;
+ std::string m_startStatCollection;
+ std::vector< std::string > m_diagnosticsTypes;
+ std::vector< std::string > m_diagnosticsInterfaces;
+ OCResourceHandle m_diagnosticsHandle;
+ OCRepresentation m_diagnosticsRep;
+
+ public:
+
+ DiagnosticsResource();
+
+ void createResource(ResourceEntityHandler callback);
+
+ void setDiagnosticsRepresentation(OCRepresentation &rep);
+
+ OCRepresentation getDiagnosticsRepresentation();
+
+ std::string getUri();
+
+ void diagnosticsMonitor(int second);
+
+ std::function< void() > factoryReset;
+
+ void deleteResource();
+};
+
+#endif // __DIAGNOSTICS_RESOURCE_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.
+ *
+ ******************************************************************/
+#ifndef __FACTORYSET_RESOURCE_H__
+#define __FACTORYSET_RESOURCE_H__
+
+#include <functional>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+#include "configurationresource.h"
+
+#pragma once
+
+using namespace OC;
+
+typedef std::function<OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request)>
+ResourceEntityHandler;
+
+class FactorySetResource : public ConfigurationResource
+{
+ public:
+
+ FactorySetResource();
+
+ ~FactorySetResource();
+
+ void createResource(ResourceEntityHandler callback);
+
+ void setFactorySetRepresentation(OCRepresentation &rep);
+
+ OCRepresentation getFactorySetRepresentation();
+
+ std::string getUri();
+
+ void deleteResource();
+};
+
+#endif // __FACTORYSET_RESOURCE_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;
+ group
+ {
+ name: "mainpage_layout";
+ parts
+ {
+ part
+ {
+ name: "bootstrap_button";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ rel1.relative: 0.01 0.02;
+ rel2.relative: 0.99 0.11;
+ }
+ }
+ part
+ {
+ name: "create_conf_button";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ rel1.relative: 0.01 0.13;
+ rel2.relative: 0.99 0.22;
+ }
+ }
+ part
+ {
+ name: "log_bg";
+ type: RECT;
+ scale: 1;
+ description
+ {
+ state: "default" 0.0;
+ rel1.relative: 0.01 0.23;
+ rel2.relative: 0.99 0.99;
+ color: 220 220 220 255;
+ }
+ }
+ part
+ {
+ name: "log";
+ type: SWALLOW;
+ scale: 1;
+ description
+ {
+ rel1.to: "log_bg";
+ rel2.to: "log_bg";
+ }
+ }
+ }
+ }
+}
\ 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 "configurationresource.h"
+
+#include <functional>
+#include <dlog.h>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+using namespace OC;
+
+// Constructor
+ConfigurationResource::ConfigurationResource() :
+ m_location(defaultLocation), m_systemTime(defaultSystemTime), m_currency(
+ defaultCurrency), m_region(defaultRegion)
+{
+ m_configurationUri = "/oic/con"; // URI of the resource
+ m_configurationTypes.push_back("oic.con"); // resource type name
+ m_configurationInterfaces.push_back(DEFAULT_INTERFACE); // resource interface
+ m_configurationRep.setValue("loc", m_location);
+ m_configurationRep.setValue("st", m_systemTime);
+ m_configurationRep.setValue("c", m_currency);
+ m_configurationRep.setValue("r", m_region);
+ m_configurationRep.setUri(m_configurationUri);
+ m_configurationRep.setResourceTypes(m_configurationTypes);
+ m_configurationRep.setResourceInterfaces(m_configurationInterfaces);
+ m_configurationHandle = NULL;
+}
+
+// Creates a ConfigurationResource
+void ConfigurationResource::createResource(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (NULL == callback)
+ {
+ dlog_print(DLOG_INFO, "ConfigurationResource", "#### Callback should be binded");
+ return;
+ }
+
+ // This will internally create and register the resource
+ OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
+ m_configurationTypes[0], m_configurationInterfaces[0],
+ callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ dlog_print(DLOG_INFO, "ConfigurationResource", "#### Resource creation"
+ "(configuration) was unsuccessful");
+ return;
+ }
+
+ dlog_print(DLOG_INFO, "ConfigurationResource", "#### Configuration Resource is Created");
+}
+
+void ConfigurationResource::setConfigurationRepresentation(OCRepresentation &rep)
+{
+ string value;
+
+ if (rep.getValue("loc", value))
+ {
+ m_location = value;
+ dlog_print(DLOG_INFO, "ConfigurationResource", "#### m_location: %s",
+ m_location.c_str());
+ }
+
+ if (rep.getValue("st", value))
+ {
+ dlog_print(DLOG_INFO, "ConfigurationResource", "#### SystemTime is not"
+ "allowed to be written");
+ }
+
+ if (rep.getValue("c", value))
+ {
+ m_currency = value;
+ dlog_print(DLOG_INFO, "ConfigurationResource", "#### m_currency: %s",
+ m_currency.c_str());
+ }
+
+ if (rep.getValue("r", value))
+ {
+ m_region = value;
+ dlog_print(DLOG_INFO, "ConfigurationResource", "#### m_region: %s",
+ m_region.c_str());
+ }
+}
+
+OCRepresentation ConfigurationResource::getConfigurationRepresentation()
+{
+ m_configurationRep.setValue("loc", m_location);
+ m_configurationRep.setValue("st", m_systemTime);
+ m_configurationRep.setValue("c", m_currency);
+ m_configurationRep.setValue("r", m_region);
+
+ return m_configurationRep;
+}
+
+std::string ConfigurationResource::getUri()
+{
+ return m_configurationUri;
+}
+
+// Assigns default values to all the attributes of the configuration resource
+void ConfigurationResource::factoryReset()
+{
+ m_location = defaultLocation;
+ m_systemTime = defaultSystemTime;
+ m_currency = defaultCurrency;
+ m_region = defaultRegion;
+}
+
+// Deletes the configuration resource which has been created using createResource()
+void ConfigurationResource::deleteResource()
+{
+ // Unregister the resource
+ if (NULL != m_configurationHandle)
+ {
+ OCPlatform::unregisterResource(m_configurationHandle);
+ }
+}
--- /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 "conserverapp.h"
+
+#include <tizen.h>
+#include <pthread.h>
+
+#include "configurationresource.h"
+#include "diagnosticsresource.h"
+#include "factorysetresource.h"
+
+using namespace std;
+using namespace OC;
+using namespace OIC;
+
+namespace PH = std::placeholders;
+
+/* Default system configuration value's variables
+ The variable's names should be same as the names of "extern" variables defined in
+ "configurationresource.h" */
+std::string defaultLocation;
+std::string defaultRegion;
+std::string defaultSystemTime;
+std::string defaultCurrency;
+
+static ThingsManager *g_thingsmanager;
+
+const int SUCCESS_RESPONSE = 0;
+
+bool resources_created = false;
+
+// Forward declaring the entityHandler (Configuration)
+bool prepareResponseForResource(std::shared_ptr< OCResourceRequest > request);
+OCStackResult sendResponseForResource(std::shared_ptr< OCResourceRequest > pRequest);
+OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceRequest > request);
+
+ConfigurationResource *myConfigurationResource;
+DiagnosticsResource *myDiagnosticsResource;
+FactorySetResource *myFactorySetResource;
+
+typedef std::function< void(OCRepresentation &) > putFunc;
+typedef std::function< OCRepresentation(void) > getFunc;
+
+typedef struct appdata
+{
+ Evas_Object *win;
+ Evas_Object *conform;
+ Evas_Object *naviframe;
+ Evas_Object *scroller;
+ Evas_Object *layout, *base_layout;
+ Evas_Object *bootButton;
+ Evas_Object *createConfButton;
+} appdata_s;
+
+Evas_Object *log_entry;
+
+std::string logMessage;
+
+getFunc getGetFunction(std::string uri)
+{
+ getFunc res = NULL;
+
+ if (uri == myConfigurationResource->getUri())
+ {
+ res = std::bind(&ConfigurationResource::getConfigurationRepresentation,
+ myConfigurationResource);
+ }
+ else if (uri == myDiagnosticsResource->getUri())
+ {
+ res = std::bind(&DiagnosticsResource::getDiagnosticsRepresentation,
+ myDiagnosticsResource);
+ }
+
+ return res;
+}
+
+putFunc getPutFunction(std::string uri)
+{
+ putFunc res = NULL;
+
+ if (uri == myConfigurationResource->getUri())
+ {
+ res = std::bind(&ConfigurationResource::setConfigurationRepresentation,
+ myConfigurationResource, std::placeholders::_1);
+ }
+ else if (uri == myDiagnosticsResource->getUri())
+ {
+ res = std::bind(&DiagnosticsResource::setDiagnosticsRepresentation,
+ myDiagnosticsResource, std::placeholders::_1);
+ }
+
+ return res;
+}
+
+// This function prepares a response for the incoming request
+bool prepareResponseForResource(std::shared_ptr< OCResourceRequest > request)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### In Server CPP prepareResponseForResource");
+ bool result = false;
+ if (request)
+ {
+ // Get the request type and request flag
+ std::string requestType = request->getRequestType();
+ int requestFlag = request->getRequestHandlerFlag();
+
+ if (requestFlag == RequestHandlerFlag::InitFlag)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### requestFlag : Init");
+ }
+ else if (requestFlag == RequestHandlerFlag::RequestFlag)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### requestFlag : Request");
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### requestType : GET");
+
+ // GET operations are directly handled while sending the response
+ result = true;
+ }
+ else if (requestType == "PUT")
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### requestType : PUT");
+ putFunc putFunction;
+ OCRepresentation rep = request->getResourceRepresentation();
+
+ // Get appropriate function to be called for the PUT request
+ putFunction = getPutFunction(request->getResourceUri());
+
+ // Do related operations related to PUT request
+ putFunction(rep);
+ result = true;
+ }
+ else if (requestType == "POST")
+ {
+ // POST request operations
+ }
+ else if (requestType == "DELETE")
+ {
+ // DELETE request operations
+ }
+ }
+ else if (requestFlag == RequestHandlerFlag::ObserverFlag)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### requestFlag : Observer");
+ }
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### Request invalid");
+ }
+
+ return result;
+}
+
+// This function sends a response for the incoming request
+OCStackResult sendResponseForResource(std::shared_ptr< OCResourceRequest > pRequest)
+{
+ auto pResponse = std::make_shared< OC::OCResourceResponse >();
+
+ // Check for query params (if any)
+ QueryParamsMap queryParamsMap = pRequest->getQueryParameters();
+
+ pResponse->setRequestHandle(pRequest->getRequestHandle());
+ pResponse->setResourceHandle(pRequest->getResourceHandle());
+
+ getFunc getFunction;
+ getFunction = getGetFunction(pRequest->getResourceUri());
+
+ OCRepresentation rep;
+ rep = getFunction();
+
+ auto findRes = queryParamsMap.find("if");
+
+ if (findRes != queryParamsMap.end())
+ {
+ pResponse->setResourceRepresentation(rep, findRes->second);
+ }
+ else
+ {
+ pResponse->setResourceRepresentation(rep, DEFAULT_INTERFACE);
+ }
+
+ pResponse->setErrorCode(200);
+ pResponse->setResponseResult(OC_EH_OK);
+
+ return OCPlatform::sendResponse(pResponse);
+}
+
+// This function handles the requests and sends the response
+OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceRequest > request)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### In Server CPP (entityHandlerForResource) entity"
+ "handler:");
+ OCEntityHandlerResult ehResult = OC_EH_ERROR;
+
+ if (prepareResponseForResource(request))
+ {
+ if (OC_STACK_OK == sendResponseForResource(request))
+ {
+ ehResult = OC_EH_OK;
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### sendResponse failed.");
+ }
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### PrepareResponse failed.");
+ }
+ return ehResult;
+}
+
+// Updates the log in the UI
+void *updateLog(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);
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### updateLog exit!!!!");
+
+ return NULL;
+}
+
+static void
+win_delete_request_cb(void *data , Evas_Object *obj , void *event_info)
+{
+ ui_app_exit();
+}
+
+// Function to delete all the configuration resources which are created
+void deleteResources()
+{
+ if (NULL != myConfigurationResource)
+ myConfigurationResource->deleteResource();
+ if (NULL != myDiagnosticsResource)
+ myDiagnosticsResource->deleteResource();
+ if (NULL != myFactorySetResource)
+ myFactorySetResource->deleteResource();
+}
+
+static void
+win_back_cb(void *data, Evas_Object *obj, void *event_info)
+{
+
+ deleteResources();
+
+ ui_app_exit();
+}
+
+/* Callback Function to be called by the platform
+ when response arrives from the BootStrap Server */
+void onBootStrapCallback(const HeaderOptions &headerOptions, const OCRepresentation &rep,
+ const int eCode)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onBootStrap entry");
+
+ if (SUCCESS_RESPONSE != eCode)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onBootStrap -- onGET Response error: %d", eCode);
+ return ;
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onBootStrap -- GET request was successful");
+ dlog_print(DLOG_INFO, LOG_TAG, "#### onBootStrap -- Resource URI: %s", rep.getUri().c_str());
+
+ logMessage = "----------------------------<br>";
+ logMessage += "GET request was successful<br>";
+ logMessage += "URI : " + rep.getUri() + "<br>";
+
+ defaultRegion = rep.getValue< std::string >("r");
+ defaultSystemTime = rep.getValue< std::string >("st");
+ defaultCurrency = rep.getValue< std::string >("c");
+ defaultLocation = rep.getValue< std::string >("loc");
+
+ logMessage += "Location : " + defaultLocation + "<br>";
+ logMessage += "SystemTime : " + defaultSystemTime + "<br>";
+ logMessage += "currency : " + defaultCurrency + "<br>";
+ logMessage += "Region : " + defaultRegion + "<br>";
+
+ //Call updateLog in the thread safe mode
+ ecore_main_loop_thread_safe_call_sync(updateLog, &logMessage);
+
+}
+
+// Function to be called when the doBootStrap UI button is clicked
+static void
+doBootStrap_cb(void *data , Evas_Object *obj , void *event_info)
+{
+ OCStackResult result = g_thingsmanager->doBootstrap(&onBootStrapCallback);
+ if (OC_STACK_OK == result)
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### doBootstrap returned OC_STACK_OK");
+ }
+ else
+ {
+ dlog_print(DLOG_INFO, LOG_TAG, "#### doBootstrap failed");
+ }
+}
+
+// Function to be called when Create Configuration Resources UI button is clicked
+static void
+createConfResource_cb(void *data , Evas_Object *obj , void *event_info)
+{
+ logMessage = "----------------------------<br>";
+ if (!resources_created)
+ {
+ resources_created = true;
+ myConfigurationResource = new ConfigurationResource();
+ myConfigurationResource->createResource(&entityHandlerForResource);
+
+ myDiagnosticsResource = new DiagnosticsResource();
+ myDiagnosticsResource->createResource(&entityHandlerForResource);
+
+ myFactorySetResource = new FactorySetResource();
+ myFactorySetResource->createResource(&entityHandlerForResource);
+
+ myDiagnosticsResource->factoryReset = std::function < void()
+ > (std::bind(&ConfigurationResource::factoryReset,
+ myConfigurationResource));
+
+ logMessage += "Resources Created Successfully!!! Server is Ready!!!<br>";
+ }
+ else
+ {
+ logMessage += "Resources were created already!!! <br>";
+ }
+ // Show the log in the UI
+ ecore_main_loop_thread_safe_call_sync(updateLog, &logMessage);
+}
+
+static void
+create_base_gui(appdata_s *ad)
+{
+ // Window
+ ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
+ 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);
+ eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);
+
+ // 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->base_layout = elm_layout_add(ad->conform);
+ evas_object_size_hint_weight_set(ad->base_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_layout_theme_set(ad->base_layout, "layout", "application", "default");
+ evas_object_show(ad->base_layout);
+
+ elm_object_content_set(ad->conform, ad->base_layout);
+
+ // naviframe
+ ad->naviframe = elm_naviframe_add(ad->base_layout);
+ elm_object_part_content_set(ad->base_layout, "elm.swallow.content", ad->naviframe);
+
+ // Scroller
+ ad->scroller = elm_scroller_add(ad->naviframe);
+ elm_scroller_bounce_set(ad->scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(ad->scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ // layout
+ ad->layout = elm_layout_add(ad->naviframe);
+ evas_object_size_hint_weight_set(ad->layout, EVAS_HINT_EXPAND, 0.0);
+ elm_layout_file_set(ad->layout, ELM_DEMO_EDJ, "mainpage_layout");
+
+ elm_object_content_set(ad->scroller, ad->layout);
+
+ ad->bootButton = elm_button_add(ad->layout);
+ elm_object_text_set(ad->bootButton, "doBootStrap");
+ evas_object_size_hint_weight_set(ad->bootButton, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(ad->bootButton, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_smart_callback_add(ad->bootButton, "clicked", doBootStrap_cb, ad);
+ elm_object_part_content_set(ad->layout, "bootstrap_button", ad->bootButton);
+
+ ad->createConfButton = elm_button_add(ad->layout);
+ elm_object_text_set(ad->createConfButton, "Create Configuration Resources");
+ evas_object_size_hint_weight_set(ad->createConfButton, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(ad->createConfButton, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_smart_callback_add(ad->createConfButton, "clicked", createConfResource_cb, ad);
+ elm_object_part_content_set(ad->layout, "create_conf_button", ad->createConfButton);
+
+ log_entry = elm_entry_add(ad->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(ad->layout, "log", log_entry);
+
+ elm_naviframe_item_push(ad->naviframe, "Configuration Server", NULL, NULL, ad->scroller, NULL);
+
+ // Show window after base gui is set up
+ evas_object_show(ad->win);
+}
+
+// Function which 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 and show the UI
+ create_base_gui(ad);
+
+ // Configure the OCPlatform
+ configure_platform();
+
+ g_thingsmanager = new ThingsManager();
+
+ 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 "diagnosticsresource.h"
+
+#include <functional>
+#include <dlog.h>
+
+#include "conserverapp.h"
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+extern string logMessage;
+
+extern void *updateLog(void *);
+
+using namespace OC;
+
+// Constructor
+DiagnosticsResource::DiagnosticsResource() :
+ m_factoryReset(defaultFactoryReset), m_reboot(defaultReboot),
+ m_startStatCollection(defaultStartStatCollection)
+{
+ m_diagnosticsUri = "/oic/diag"; // URI of the resource
+ m_diagnosticsTypes.push_back("oic.diag"); // resource type name
+ m_diagnosticsInterfaces.push_back(DEFAULT_INTERFACE); // resource interface
+ m_diagnosticsRep.setValue("fr", m_factoryReset);
+ m_diagnosticsRep.setValue("rb", m_reboot);
+ m_diagnosticsRep.setValue("ssc", m_startStatCollection);
+ m_diagnosticsRep.setUri(m_diagnosticsUri);
+ m_diagnosticsRep.setResourceTypes(m_diagnosticsTypes);
+ m_diagnosticsRep.setResourceInterfaces(m_diagnosticsInterfaces);
+ m_diagnosticsHandle = NULL;
+}
+
+// Creates a DiagnosticResource
+void DiagnosticsResource::createResource(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (NULL == callback)
+ {
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### Callback should be binded");
+ return;
+ }
+
+ // This will internally create and register the resource
+ OCStackResult result = registerResource(m_diagnosticsHandle, m_diagnosticsUri,
+ m_diagnosticsTypes[0], m_diagnosticsInterfaces[0],
+ callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### Resource creation"
+ "(configuration) was unsuccessful");
+ return;
+ }
+
+ thread exec(
+ std::function< void(int second) >(
+ std::bind(&DiagnosticsResource::diagnosticsMonitor, this,
+ std::placeholders::_1)), 1);
+ exec.detach();
+
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### Diagnostics Resource is Created");
+}
+
+void DiagnosticsResource::setDiagnosticsRepresentation(OCRepresentation &rep)
+{
+ string value;
+
+ if (rep.getValue("fr", value))
+ {
+ m_factoryReset = value;
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### m_factoryReset: %s",
+ m_factoryReset.c_str());
+ }
+
+ if (rep.getValue("rb", value))
+ {
+ m_reboot = value;
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### m_reboot: %s", m_reboot.c_str());
+ }
+
+ if (rep.getValue("ssc", value))
+ {
+ m_startStatCollection = value;
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### m_startStatCollection: %s",
+ m_startStatCollection.c_str());
+ }
+}
+
+OCRepresentation DiagnosticsResource::getDiagnosticsRepresentation()
+{
+ m_diagnosticsRep.setValue("fr", m_factoryReset);
+ m_diagnosticsRep.setValue("rb", m_reboot);
+ m_diagnosticsRep.setValue("ssc", m_startStatCollection);
+
+ return m_diagnosticsRep;
+}
+
+std::string DiagnosticsResource::getUri()
+{
+ return m_diagnosticsUri;
+}
+
+// Handles the Reboot and FactoryReset request
+void DiagnosticsResource::diagnosticsMonitor(int second)
+{
+ while (1)
+ {
+ sleep(second);
+
+ if (m_reboot == "true")
+ {
+ int res;
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### Reboot will be soon...");
+ m_reboot = defaultReboot;
+ res = system("sudo reboot"); // System reboot
+
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### return: %d", res);
+
+ logMessage = "----------------------------<br>";
+ logMessage += "*** System Reboot Success ***<br>";
+
+ //Show the log
+ ecore_main_loop_thread_safe_call_sync(updateLog, &logMessage);
+
+ }
+ else if (m_factoryReset == "true")
+ {
+ dlog_print(DLOG_INFO, "DiagnosticsResource", "#### Factory Reset will be soon...");
+ m_factoryReset = defaultFactoryReset;
+ factoryReset();
+ }
+ }
+}
+
+// Deletes the diagnostic resource which has been created using createResource()
+void DiagnosticsResource::deleteResource()
+{
+ // Unregister the resource
+ if (NULL != m_diagnosticsHandle)
+ {
+ OCPlatform::unregisterResource(m_diagnosticsHandle);
+ }
+}
--- /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 "factorysetresource.h"
+
+#include <functional>
+#include <dlog.h>
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "ThingsManager.h"
+
+using namespace OC;
+
+FactorySetResource::FactorySetResource()
+{
+ m_configurationUri = "/factorySet"; // URI of the resource
+ m_configurationTypes.clear();
+ m_configurationTypes.push_back("factorySet"); // resource type name.
+ m_configurationRep.setUri(m_configurationUri);
+ m_configurationRep.setResourceTypes(m_configurationTypes);
+}
+
+FactorySetResource::~FactorySetResource() {}
+
+// This function internally calls registerResource API.
+void FactorySetResource::createResource(ResourceEntityHandler callback)
+{
+ using namespace OC::OCPlatform;
+
+ if (NULL == callback)
+ {
+ dlog_print(DLOG_INFO, "FactorySetResource", "#### Callback should be binded");
+ return;
+ }
+
+ // This will internally create and register the resource
+ OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
+ m_configurationTypes[0], m_configurationInterfaces[0],
+ callback, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+ if (OC_STACK_OK != result)
+ {
+ dlog_print(DLOG_INFO, "FactorySetResource", "#### Resource creation"
+ "(configuration) was unsuccessful");
+ return;
+ }
+
+ dlog_print(DLOG_INFO, "FactorySetResource", "#### Configuration Resource is Created");
+}
+
+void FactorySetResource::setFactorySetRepresentation(OCRepresentation &rep)
+{
+ string value;
+
+ if (rep.getValue("loc", value))
+ {
+ m_location = value;
+ dlog_print(DLOG_INFO, "FactorySetResource", "#### m_location: %s",
+ m_location.c_str());
+ }
+
+ if (rep.getValue("st", value))
+ {
+ dlog_print(DLOG_INFO, "FactorySetResource", "#### SystemTime is not"
+ "allowed to be written");
+ }
+
+ if (rep.getValue("c", value))
+ {
+ m_currency = value;
+ dlog_print(DLOG_INFO, "FactorySetResource", "#### m_currency: %s",
+ m_currency.c_str());
+ }
+
+ if (rep.getValue("r", value))
+ {
+ m_region = value;
+ dlog_print(DLOG_INFO, "FactorySetResource", "#### m_region: %s",
+ m_region.c_str());
+ }
+}
+
+OCRepresentation FactorySetResource::getFactorySetRepresentation()
+{
+ m_configurationRep.setValue("loc", m_location);
+ m_configurationRep.setValue("st", m_systemTime);
+ m_configurationRep.setValue("c", m_currency);
+ m_configurationRep.setValue("r", m_region);
+
+ return m_configurationRep;
+}
+
+std::string FactorySetResource::getUri()
+{
+ return m_configurationUri;
+}
+
+// Deletes the factoryset resource which has been created using createResource()
+void FactorySetResource::deleteResource()
+{
+ // Unregister the Configuration resource
+ if (NULL != m_configurationHandle)
+ {
+ OCPlatform::unregisterResource(m_configurationHandle);
+ }
+}
--- /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.conserverapp" version="1.0.0">
+ <profile name="mobile"/>
+ <ui-application appid="org.tizen.conserverapp" exec="conserverapp" multiple="false" nodisplay="false" taskmanage="true" type="capp">
+ <label>conserverapp</label>
+ <icon>conserverapp.png</icon>
+ </ui-application>
+ <privileges>
+ <privilege>http://tizen.org/privilege/network.get</privilege>
+ <privilege>http://tizen.org/privilege/internet</privilege>
+ </privileges>
+ <feature name="http://tizen.org/feature/network.wifi">true</feature>
+</manifest>