From 1f0e7e997dabf18fe28a336c0c963e000b517086 Mon Sep 17 00:00:00 2001 From: Jihun Ha Date: Thu, 19 Mar 2015 21:39:28 +0900 Subject: [PATCH] Update a resource model of configuration/diagnostics resources We decide to change a resource model from IPSO model to OIC (resource-attribute)model. By this decision, configuration/diagnostics resource's server applications utilized by Things Manager are changed. And ThingsConfiguration and ThingsDiagnostics SDK implementations are also slightly changed. Additionally, fix an exception problem in con-server application, which is refered in [IoT-392] Change-Id: I267885d710390b3aee7fdd4852c2de33c9300f87 Signed-off-by: Jihun Ha Reviewed-on: https://gerrit.iotivity.org/gerrit/514 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- resource/csdk/stack/src/oicgroup.c | 1 + .../configuration/ConfigurationCollection.cpp | 532 +-------------------- .../linux/configuration/ConfigurationCollection.h | 487 +------------------ .../linux/configuration/DiagnosticsCollection.cpp | 166 +------ .../linux/configuration/DiagnosticsCollection.h | 91 +--- .../linux/configuration/FactorySetCollection.cpp | 105 ++-- .../linux/configuration/FactorySetCollection.h | 77 +-- .../linux/configuration/bootstrapserver.cpp | 27 +- .../sampleapp/linux/configuration/con-client.cpp | 156 +++--- .../sampleapp/linux/configuration/con-server.cpp | 124 ++--- .../things-manager/sdk/src/ThingsConfiguration.cpp | 84 ++-- .../things-manager/sdk/src/ThingsConfiguration.h | 324 +------------ .../things-manager/sdk/src/ThingsDiagnostics.cpp | 58 ++- service/things-manager/sdk/src/ThingsDiagnostics.h | 55 +-- 14 files changed, 366 insertions(+), 1921 deletions(-) mode change 100644 => 100755 service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.cpp mode change 100644 => 100755 service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.h mode change 100644 => 100755 service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.cpp mode change 100644 => 100755 service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.h mode change 100644 => 100755 service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp mode change 100644 => 100755 service/things-manager/sampleapp/linux/configuration/FactorySetCollection.h mode change 100644 => 100755 service/things-manager/sampleapp/linux/configuration/bootstrapserver.cpp mode change 100644 => 100755 service/things-manager/sdk/src/ThingsConfiguration.h mode change 100644 => 100755 service/things-manager/sdk/src/ThingsDiagnostics.h diff --git a/resource/csdk/stack/src/oicgroup.c b/resource/csdk/stack/src/oicgroup.c index 6024813..85eec2a 100755 --- a/resource/csdk/stack/src/oicgroup.c +++ b/resource/csdk/stack/src/oicgroup.c @@ -285,6 +285,7 @@ ClientRequstInfo* GetClientRequestInfo(ClientRequstInfo *head, tmp = tmp->next; } + return tmp; } return NULL; } diff --git a/service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.cpp b/service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.cpp old mode 100644 new mode 100755 index 7ee28d1..1096799 --- a/service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.cpp +++ b/service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.cpp @@ -33,7 +33,7 @@ using namespace OC; /// This function internally calls registerResource API. -void ConfigurationCollection::createResources(ResourceEntityHandler callback) +void ConfigurationResource::createResources(ResourceEntityHandler callback) { using namespace OC::OCPlatform; @@ -53,539 +53,57 @@ void ConfigurationCollection::createResources(ResourceEntityHandler callback) std::cout << "Resource creation (configuration) was unsuccessful\n"; } - result = bindInterfaceToResource(m_configurationHandle, m_configurationInterfaces[1]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_configurationHandle, m_configurationInterfaces[2]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = registerResource(m_regionHandle, m_regionUri, m_regionTypes[0], m_regionInterfaces[0], - callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (region) was unsuccessful\n"; - } - - result = registerResource(m_timeHandle, m_timeUri, m_timeTypes[0], m_timeInterfaces[0], - callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (time) was unsuccessful\n"; - } - - result = registerResource(m_networkHandle, m_networkUri, m_networkTypes[0], - m_networkInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (network) was unsuccessful\n"; - } - - result = registerResource(m_securityHandle, m_securityUri, m_securityTypes[0], - m_securityInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (security) was unsuccessful\n"; - } - - result = bindResource(m_configurationHandle, m_regionHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding region resource to room was unsuccessful\n"; - } - - result = bindResource(m_configurationHandle, m_timeHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding time resource to room was unsuccessful\n"; - } - - result = bindResource(m_configurationHandle, m_networkHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding network resource to room was unsuccessful\n"; - } - - result = bindResource(m_configurationHandle, m_securityHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding security resource to room was unsuccessful\n"; - } - - std::cout << "Configuration Collection is Created!(URI: " << m_configurationUri << ") \n"; - - myTimeCollection->createResources(callback); - myNetworkCollection->createResources(callback); - mySecurityCollection->createResources(callback); - + std::cout << "Configuration Resource is Created!(URI: " << m_configurationUri << ") \n"; } -void ConfigurationCollection::setConfigurationRepresentation(OCRepresentation& rep) +void ConfigurationResource::setConfigurationRepresentation(OCRepresentation& rep) { string value; - if (rep.getValue("value", value)) + if (rep.getValue("loc", value)) { - m_configurationValue = value; - - std::cout << "\t\t\t\t" << "m_configurationValue: " << m_configurationValue << std::endl; + m_location = value; + std::cout << "\t\t\t\t" << "m_location: " << m_location << std::endl; } -} - -void ConfigurationCollection::setTimeRepresentation(OCRepresentation& rep) -{ - string value; - if (rep.getValue("link", value)) + if (rep.getValue("st", value)) { - // NOT ALLOWED - - std::cout << "\t\t\t\t" << "link: " << m_timeLink << std::endl; + std::cout << "\t\t\t\t" << "SystemTime is not allowed to be written." << std::endl; } -} - -void ConfigurationCollection::setNetworkRepresentation(OCRepresentation& rep) -{ - string value; - if (rep.getValue("link", value)) + if (rep.getValue("c", value)) { - // NOT ALLOWED - - std::cout << "\t\t\t\t" << "link: " << m_networkLink << std::endl; + m_currency = value; + std::cout << "\t\t\t\t" << "m_currency: " << m_currency << std::endl; } -} -void ConfigurationCollection::setSecurityRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("link", value)) + if (rep.getValue("r", value)) { - // NOT ALLOWED - - std::cout << "\t\t\t\t" << "link: " << m_securityLink << std::endl; + m_region = value; + std::cout << "\t\t\t\t" << "m_region: " << m_region << std::endl; } } -void ConfigurationCollection::setRegionRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("value", value)) - { - m_regionValue = value; - - std::cout << "\t\t\t\t" << "value: " << m_regionValue << std::endl; - } -} - -OCRepresentation ConfigurationCollection::getTimeRepresentation() -{ - m_timeRep.setValue("link", m_timeLink); - - return m_timeRep; -} - -OCRepresentation ConfigurationCollection::getNetworkRepresentation() -{ - m_networkRep.setValue("link", m_networkLink); - - return m_networkRep; -} - -OCRepresentation ConfigurationCollection::getSecurityRepresentation() +OCRepresentation ConfigurationResource::getConfigurationRepresentation() { - m_securityRep.setValue("link", m_securityLink); - - return m_securityRep; -} - -OCRepresentation ConfigurationCollection::getRegionRepresentation() -{ - m_regionRep.setValue("value", m_regionValue); - - return m_regionRep; -} - -OCRepresentation ConfigurationCollection::getConfigurationRepresentation() -{ - m_configurationRep.clearChildren(); - - m_configurationRep.addChild(getRegionRepresentation()); - m_configurationRep.addChild(getTimeRepresentation()); - m_configurationRep.addChild(getNetworkRepresentation()); - m_configurationRep.addChild(getSecurityRepresentation()); - - m_configurationRep.setValue("value", m_configurationValue); + 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 ConfigurationCollection::getConfigurationUri() +std::string ConfigurationResource::getUri() { return m_configurationUri; } -std::string ConfigurationCollection::getTimeUri() -{ - return m_timeUri; -} - -std::string ConfigurationCollection::getNetworkUri() -{ - return m_networkUri; -} - -std::string ConfigurationCollection::getSecurityUri() -{ - return m_securityUri; -} - -std::string ConfigurationCollection::getRegionUri() -{ - return m_regionUri; -} - -void ConfigurationCollection::factoryReset() -{ - m_configurationValue = defaultConfigurationValue; - m_regionValue = defaultRegionValue; - m_timeLink = defaultTimeLink; - m_networkLink = defaultNetworkLink; - m_securityLink = defaultSecurityLink; - - myTimeCollection->factoryReset(); - myNetworkCollection->factoryReset(); - mySecurityCollection->factoryReset(); -} - -/// This function internally calls registerResource API. -void TimeCollection::createResources(ResourceEntityHandler callback) -{ - using namespace OC::OCPlatform; - - if (callback == NULL) - { - std::cout << "callback should be binded\t"; - return; - } - - // This will internally create and register the resource. - OCStackResult result = registerResource(m_timeHandle, m_timeUri, m_timeTypes[0], - m_timeInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (time) was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_timeHandle, m_timeInterfaces[1]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_timeHandle, m_timeInterfaces[2]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = registerResource(m_currentTimeHandle, m_currentTimeUri, m_currentTimeTypes[0], - m_currentTimeInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (currentTime) was unsuccessful\n"; - } - - result = bindResource(m_timeHandle, m_currentTimeHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding currentTime resource to room was unsuccessful\n"; - } - - std::cout << "Time Collection is Created!(URI: " << m_timeUri << ") \n"; -} - -void TimeCollection::setTimeRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("value", value)) - { - m_timeValue = value; - - std::cout << "\t\t\t\t" << "m_timeValue: " << m_timeValue << std::endl; - } -} - -void TimeCollection::setCurrentTimeRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("currentTime", value)) - { - m_currentTimeValue = value; - - std::cout << "\t\t\t\t" << "value: " << m_currentTimeValue << std::endl; - } -} - -OCRepresentation TimeCollection::getCurrentTimeRepresentation() -{ - m_currentTimeRep.setValue("value", m_currentTimeValue); - - return m_currentTimeRep; -} - -OCRepresentation TimeCollection::getTimeRepresentation() -{ - m_timeRep.clearChildren(); - - m_timeRep.addChild(getCurrentTimeRepresentation()); - - m_timeRep.setValue("value", m_timeValue); - - return m_timeRep; -} - -std::string TimeCollection::getTimeUri() -{ - return m_timeUri; -} - -std::string TimeCollection::getCurrentTimeUri() -{ - return m_currentTimeUri; -} - -void TimeCollection::factoryReset() -{ - m_timeValue = defaultTimeValue; - m_currentTimeValue = defaultCurrentTimeValue; -} - -/// This function internally calls registerResource API. -void NetworkCollection::createResources(ResourceEntityHandler callback) -{ - using namespace OC::OCPlatform; - - if (callback == NULL) - { - std::cout << "callback should be binded\t"; - return; - } - - // This will internally create and register the resource. - OCStackResult result = registerResource(m_networkHandle, m_networkUri, m_networkTypes[0], - m_networkInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (network) was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_networkHandle, m_networkInterfaces[1]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_networkHandle, m_networkInterfaces[2]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = registerResource(m_IPAddressHandle, m_IPAddressUri, m_IPAddressTypes[0], - m_IPAddressInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (IPAddress) was unsuccessful\n"; - } - - result = bindResource(m_networkHandle, m_IPAddressHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding IPAddress resource to room was unsuccessful\n"; - } - - std::cout << "Network Collection is Created!(URI: " << m_networkUri << ") \n"; -} - -void NetworkCollection::setNetworkRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("value", value)) - { - m_networkValue = value; - - std::cout << "\t\t\t\t" << "m_networkValue: " << m_networkValue << std::endl; - } -} - -void NetworkCollection::setIPAddressRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("IPAddress", value)) - { - m_IPAddressValue = value; - - std::cout << "\t\t\t\t" << "value: " << m_IPAddressValue << std::endl; - } -} -OCRepresentation NetworkCollection::getIPAddressRepresentation() -{ - m_IPAddressRep.setValue("value", m_IPAddressValue); - - return m_IPAddressRep; -} - -OCRepresentation NetworkCollection::getNetworkRepresentation() -{ - m_networkRep.clearChildren(); - - m_networkRep.addChild(getIPAddressRepresentation()); - - m_networkRep.setValue("value", m_networkValue); - - return m_networkRep; -} - -std::string NetworkCollection::getNetworkUri() -{ - return m_networkUri; -} - -std::string NetworkCollection::getIPAddressUri() -{ - return m_IPAddressUri; -} - -void NetworkCollection::factoryReset() -{ - m_networkValue = defaultNetworkValue; - m_IPAddressValue = defaultIPAddressValue; -} - -/// This function internally calls registerResource API. -void SecurityCollection::createResources(ResourceEntityHandler callback) -{ - using namespace OC::OCPlatform; - - if (callback == NULL) - { - std::cout << "callback should be binded\t"; - return; - } - - // This will internally create and register the resource. - OCStackResult result = registerResource(m_securityHandle, m_securityUri, m_securityTypes[0], - m_securityInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (security) was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_securityHandle, m_securityInterfaces[1]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_securityHandle, m_securityInterfaces[2]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = registerResource(m_modeHandle, m_modeUri, m_modeTypes[0], m_modeInterfaces[0], - callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (mode) was unsuccessful\n"; - } - - result = bindResource(m_securityHandle, m_modeHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding mode resource to room was unsuccessful\n"; - } - - std::cout << "Security Collection is Created!(URI: " << m_securityUri << ") \n"; -} - -void SecurityCollection::setSecurityRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("value", value)) - { - m_securityValue = value; - - std::cout << "\t\t\t\t" << "m_securityValue: " << m_securityValue << std::endl; - } -} - -void SecurityCollection::setModeRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("mode", value)) - { - m_modeValue = value; - - std::cout << "\t\t\t\t" << "value: " << m_modeValue << std::endl; - } -} - -OCRepresentation SecurityCollection::getModeRepresentation() -{ - m_modeRep.setValue("value", m_modeValue); - - return m_modeRep; -} - -OCRepresentation SecurityCollection::getSecurityRepresentation() -{ - m_securityRep.clearChildren(); - - m_securityRep.addChild(getModeRepresentation()); - - m_securityRep.setValue("value", m_securityValue); - - return m_securityRep; -} - -std::string SecurityCollection::getSecurityUri() -{ - return m_securityUri; -} - -std::string SecurityCollection::getModeUri() -{ - return m_modeUri; -} - -void SecurityCollection::factoryReset() +void ConfigurationResource::factoryReset() { - m_securityValue = defaultSecurityValue; - m_modeValue = defaultModeValue; + m_location = defaultLocation; + m_systemTime = defaultSystemTime; + m_currency = defaultCurrency; + m_region = defaultRegion; } diff --git a/service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.h b/service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.h old mode 100644 new mode 100755 index cbc1db5..2dc3bbf --- a/service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.h +++ b/service/things-manager/sampleapp/linux/configuration/ConfigurationCollection.h @@ -33,502 +33,63 @@ using namespace OC; -typedef std::function< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler; +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 defaultTimeValue; -extern std::string defaultCurrentTimeValue; +extern std::string defaultLocation; +extern std::string defaultSystemTime; +extern std::string defaultCurrency; +extern std::string defaultRegion; -class TimeCollection +class ConfigurationResource { public: - - // diagnostics members - std::string m_timeUri; - std::string m_timeValue; - std::vector< std::string > m_timeTypes; - std::vector< std::string > m_timeInterfaces; - OCResourceHandle m_timeHandle; - OCRepresentation m_timeRep; - - // factory reset members - std::string m_currentTimeUri; - std::string m_currentTimeValue; - std::vector< std::string > m_currentTimeTypes; - std::vector< std::string > m_currentTimeInterfaces; - OCResourceHandle m_currentTimeHandle; - OCRepresentation m_currentTimeRep; - -public: - /// Constructor - TimeCollection() : - m_timeValue(defaultTimeValue), m_currentTimeValue(defaultCurrentTimeValue) - { - m_currentTimeUri = defaultURIPrefix + "/time/0/currentTime"; // URI of the resource - m_currentTimeTypes.push_back("oic.con.time.currentTime"); // resource type name. - m_currentTimeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_currentTimeRep.setUri(m_currentTimeUri); - m_currentTimeRep.setResourceTypes(m_currentTimeTypes); - m_currentTimeRep.setResourceInterfaces(m_currentTimeInterfaces); - m_currentTimeRep.setValue("value", m_currentTimeValue); - m_currentTimeHandle = NULL; - - m_timeUri = defaultURIPrefix + "/time"; // URI of the resource - m_timeTypes.push_back("oic.con.time"); // resource type name. - m_timeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_timeInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_timeInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_timeRep.setValue("value", m_timeValue); - m_timeRep.setUri(m_timeUri); - m_timeRep.setResourceTypes(m_timeTypes); - m_timeRep.setResourceInterfaces(m_timeInterfaces); - m_timeHandle = NULL; - } - ; - - /// Constructor - TimeCollection(std::string URIPrefix, std::string ResourceTypePrefix) : - m_timeValue(defaultTimeValue), m_currentTimeValue(defaultCurrentTimeValue) - { - m_currentTimeUri = URIPrefix + "/time/0/currentTime"; // URI of the resource - m_currentTimeTypes.push_back(ResourceTypePrefix + ".time.currentTime"); // type name. - m_currentTimeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_currentTimeRep.setUri(m_currentTimeUri); - m_currentTimeRep.setResourceTypes(m_currentTimeTypes); - m_currentTimeRep.setResourceInterfaces(m_currentTimeInterfaces); - m_currentTimeRep.setValue("value", m_currentTimeValue); - m_currentTimeHandle = NULL; - - m_timeUri = URIPrefix + "/time"; // URI of the resource - m_timeTypes.push_back(ResourceTypePrefix + ".time"); // resource type name. - m_timeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_timeInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_timeInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_timeRep.setValue("value", m_timeValue); - m_timeRep.setUri(m_timeUri); - m_timeRep.setResourceTypes(m_timeTypes); - m_timeRep.setResourceInterfaces(m_timeInterfaces); - m_timeHandle = NULL; - } - ; - - /// This function internally calls registerResource API. - void createResources(ResourceEntityHandler callback); - - void setTimeRepresentation(OCRepresentation& rep); - void setCurrentTimeRepresentation(OCRepresentation& rep); - - OCRepresentation getTimeRepresentation(); - OCRepresentation getCurrentTimeRepresentation(); - - std::string getTimeUri(); - std::string getCurrentTimeUri(); - - void factoryReset(); - -}; - -extern std::string defaultNetworkValue; -extern std::string defaultIPAddressValue; - -class NetworkCollection -{ -public: - - // diagnostics members - std::string m_networkUri; - std::string m_networkValue; - std::vector< std::string > m_networkTypes; - std::vector< std::string > m_networkInterfaces; - OCResourceHandle m_networkHandle; - OCRepresentation m_networkRep; - - // factory reset members - std::string m_IPAddressUri; - std::string m_IPAddressValue; - std::vector< std::string > m_IPAddressTypes; - std::vector< std::string > m_IPAddressInterfaces; - OCResourceHandle m_IPAddressHandle; - OCRepresentation m_IPAddressRep; - -public: - - /// Constructor - NetworkCollection() : - m_networkValue(defaultNetworkValue), m_IPAddressValue(defaultIPAddressValue) - { - m_IPAddressUri = defaultURIPrefix + "/network/0/IPAddress"; // URI of the resource - m_IPAddressTypes.push_back("oic.con.network.IPAddress"); // resource type name. - m_IPAddressInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_IPAddressRep.setUri(m_IPAddressUri); - m_IPAddressRep.setResourceTypes(m_IPAddressTypes); - m_IPAddressRep.setResourceInterfaces(m_IPAddressInterfaces); - m_IPAddressRep.setValue("value", m_IPAddressValue); - m_IPAddressHandle = NULL; - - m_networkUri = defaultURIPrefix + "/network"; // URI of the resource - m_networkTypes.push_back("oic.con.network"); // resource type name. - m_networkInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_networkInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_networkInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_networkRep.setValue("value", m_networkValue); - m_networkRep.setUri(m_networkUri); - m_networkRep.setResourceTypes(m_networkTypes); - m_networkRep.setResourceInterfaces(m_networkInterfaces); - m_networkHandle = NULL; - } - ; - - /// Constructor - NetworkCollection(std::string URIPrefix, std::string ResourceTypePrefix) : - m_networkValue(defaultNetworkValue), m_IPAddressValue(defaultIPAddressValue) - { - m_IPAddressUri = URIPrefix + "/network/0/IPAddress"; // URI of the resource - m_IPAddressTypes.push_back(ResourceTypePrefix + "network.IPAddress"); // resource type name. - m_IPAddressInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_IPAddressRep.setUri(m_IPAddressUri); - m_IPAddressRep.setResourceTypes(m_IPAddressTypes); - m_IPAddressRep.setResourceInterfaces(m_IPAddressInterfaces); - m_IPAddressRep.setValue("value", m_IPAddressValue); - m_IPAddressHandle = NULL; - - m_networkUri = URIPrefix + "/network"; // URI of the resource - m_networkTypes.push_back(ResourceTypePrefix + ".network"); // resource type name. - m_networkInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_networkInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_networkInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_networkRep.setValue("value", m_networkValue); - m_networkRep.setUri(m_networkUri); - m_networkRep.setResourceTypes(m_networkTypes); - m_networkRep.setResourceInterfaces(m_networkInterfaces); - m_networkHandle = NULL; - } - ; - - /// This function internally calls registerResource API. - void createResources(ResourceEntityHandler callback); - - void setNetworkRepresentation(OCRepresentation& rep); - void setIPAddressRepresentation(OCRepresentation& rep); - - OCRepresentation getNetworkRepresentation(); - OCRepresentation getIPAddressRepresentation(); - - std::string getNetworkUri(); - std::string getIPAddressUri(); - - void factoryReset(); - -}; - -extern std::string defaultSecurityValue; -extern std::string defaultModeValue; - -class SecurityCollection -{ -public: - - // diagnostics members - std::string m_securityUri; - std::string m_securityValue; - std::vector< std::string > m_securityTypes; - std::vector< std::string > m_securityInterfaces; - OCResourceHandle m_securityHandle; - OCRepresentation m_securityRep; - - // factory reset members - std::string m_modeUri; - std::string m_modeValue; - std::vector< std::string > m_modeTypes; - std::vector< std::string > m_modeInterfaces; - OCResourceHandle m_modeHandle; - OCRepresentation m_modeRep; - -public: - /// Constructor - SecurityCollection() : - m_securityValue(defaultSecurityValue), m_modeValue(defaultModeValue) - { - m_modeUri = defaultURIPrefix + "/security/0/mode"; // URI of the resource - m_modeTypes.push_back("oic.con.security.mode"); // resource type name. - m_modeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_modeRep.setUri(m_modeUri); - m_modeRep.setResourceTypes(m_modeTypes); - m_modeRep.setResourceInterfaces(m_modeInterfaces); - m_modeRep.setValue("value", m_modeValue); - m_modeHandle = NULL; - - m_securityUri = defaultURIPrefix + "/security"; // URI of the resource - m_securityTypes.push_back("oic.con.security"); // resource type name. - m_securityInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_securityInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_securityInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_securityRep.setValue("value", m_securityValue); - m_securityRep.setUri(m_securityUri); - m_securityRep.setResourceTypes(m_securityTypes); - m_securityRep.setResourceInterfaces(m_securityInterfaces); - m_securityHandle = NULL; - } - ; - - /// Constructor - SecurityCollection(std::string URIPrefix, std::string ResourceTypePrefix) : - m_securityValue(defaultSecurityValue), m_modeValue(defaultModeValue) - { - m_modeUri = URIPrefix + "/security/0/mode"; // URI of the resource - m_modeTypes.push_back(ResourceTypePrefix + ".security.mode"); // resource type name. - m_modeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_modeRep.setUri(m_modeUri); - m_modeRep.setResourceTypes(m_modeTypes); - m_modeRep.setResourceInterfaces(m_modeInterfaces); - m_modeRep.setValue("value", m_modeValue); - m_modeHandle = NULL; - - m_securityUri = URIPrefix + "/security"; // URI of the resource - m_securityTypes.push_back(ResourceTypePrefix + ".security"); // resource type name. - m_securityInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_securityInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_securityInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_securityRep.setValue("value", m_securityValue); - m_securityRep.setUri(m_securityUri); - m_securityRep.setResourceTypes(m_securityTypes); - m_securityRep.setResourceInterfaces(m_securityInterfaces); - m_securityHandle = NULL; - } - ; - - /// This function internally calls registerResource API. - void createResources(ResourceEntityHandler callback); - - void setSecurityRepresentation(OCRepresentation& rep); - void setModeRepresentation(OCRepresentation& rep); - - OCRepresentation getSecurityRepresentation(); - OCRepresentation getModeRepresentation(); - - std::string getSecurityUri(); - std::string getModeUri(); - - void factoryReset(); - -}; - -extern std::string defaultConfigurationValue; -extern std::string defaultRegionValue; -static std::string defaultTimeLink = "/con/con/0/time"; -static std::string defaultNetworkLink = "/con/con/0/network"; -static std::string defaultSecurityLink = "/con/con/0/security"; - -class ConfigurationCollection -{ -public: - TimeCollection *myTimeCollection; - NetworkCollection *myNetworkCollection; - SecurityCollection *mySecurityCollection; - -public: // Configuration members std::string m_configurationUri; - std::string m_configurationValue; + 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; - // Security members - std::string m_regionUri; - std::string m_regionValue; - std::vector< std::string > m_regionTypes; - std::vector< std::string > m_regionInterfaces; - OCResourceHandle m_regionHandle; - OCRepresentation m_regionRep; - - // Time members - std::string m_timeUri; - std::string m_timeLink; - std::vector< std::string > m_timeTypes; - std::vector< std::string > m_timeInterfaces; - OCResourceHandle m_timeHandle; - OCRepresentation m_timeRep; - - // Network members - std::string m_networkUri; - std::string m_networkLink; - std::vector< std::string > m_networkTypes; - std::vector< std::string > m_networkInterfaces; - OCResourceHandle m_networkHandle; - OCRepresentation m_networkRep; - - // Security members - std::string m_securityUri; - std::string m_securityLink; - std::vector< std::string > m_securityTypes; - std::vector< std::string > m_securityInterfaces; - OCResourceHandle m_securityHandle; - OCRepresentation m_securityRep; - public: /// Constructor - ConfigurationCollection() : - m_configurationValue(defaultConfigurationValue), m_regionValue(defaultRegionValue), m_timeLink( - defaultTimeLink), m_networkLink(defaultNetworkLink), m_securityLink( - defaultSecurityLink) + ConfigurationResource() : + m_location(defaultLocation), m_systemTime(defaultSystemTime), m_currency( + defaultCurrency), m_region(defaultRegion) { - m_regionUri = defaultURIPrefix + "/0/region"; // URI of the resource - m_regionTypes.push_back(defaultResourceTypePrefix + ".region"); // resource type name. - m_regionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_regionRep.setUri(m_regionUri); - m_regionRep.setResourceTypes(m_regionTypes); - m_regionRep.setResourceInterfaces(m_regionInterfaces); - m_regionRep.setValue("value", m_regionValue); - m_regionHandle = NULL; - - m_timeUri = defaultURIPrefix + "/0/time"; // URI of the resource - m_timeTypes.push_back(defaultResourceTypePrefix + ".time"); // resource type name. - m_timeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_timeRep.setUri(m_timeUri); - m_timeRep.setResourceTypes(m_timeTypes); - m_timeRep.setResourceInterfaces(m_timeInterfaces); - m_timeRep.setValue("link", m_timeLink); - m_timeHandle = NULL; - - m_networkUri = defaultURIPrefix + "/0/net"; // URI of the resource - m_networkTypes.push_back(defaultResourceTypePrefix + ".net"); // resource type name. - m_networkInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_networkRep.setUri(m_networkUri); - m_networkRep.setResourceTypes(m_networkTypes); - m_networkRep.setResourceInterfaces(m_networkInterfaces); - m_networkRep.setValue("link", m_networkLink); - m_networkHandle = NULL; - - m_securityUri = defaultURIPrefix + "/0/sec"; // URI of the resource - m_securityTypes.push_back(defaultResourceTypePrefix + ".sec"); // resource type name. - m_securityInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_securityRep.setUri(m_securityUri); - m_securityRep.setResourceTypes(m_securityTypes); - m_securityRep.setResourceInterfaces(m_securityInterfaces); - m_securityRep.setValue("link", m_securityLink); - m_securityHandle = NULL; - - m_configurationUri = defaultURIPrefix + ""; // URI of the resource - m_configurationTypes.push_back(defaultResourceTypePrefix + ""); // resource type name. + 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_configurationInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_configurationInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_configurationRep.setValue("value", m_configurationValue); + //m_configurationInterfaces.push_back(BATCH_INTERFACE); // resource interface. + //m_configurationInterfaces.push_back(LINK_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; - - myTimeCollection = new TimeCollection(); - myNetworkCollection = new NetworkCollection(); - mySecurityCollection = new SecurityCollection(); } ; - /// Constructor - ConfigurationCollection(std::string URIPrefix, std::string ResourceTypePrefix) : - m_configurationValue(defaultConfigurationValue), m_regionValue(defaultRegionValue), m_timeLink( - defaultTimeLink), m_networkLink(defaultNetworkLink), m_securityLink( - defaultSecurityLink) + ~ConfigurationResource() { - m_regionUri = URIPrefix + "/0/region"; // URI of the resource - m_regionTypes.push_back(ResourceTypePrefix + ".region"); // type name. - m_regionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_regionRep.setUri(m_regionUri); - m_regionRep.setResourceTypes(m_regionTypes); - m_regionRep.setResourceInterfaces(m_regionInterfaces); - m_regionRep.setValue("value", m_regionValue); - m_regionHandle = NULL; - - m_timeUri = URIPrefix + "/0/time"; // URI of the resource - m_timeTypes.push_back(ResourceTypePrefix + ".time"); // resource type name. - m_timeInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_timeRep.setUri(m_timeUri); - m_timeRep.setResourceTypes(m_timeTypes); - m_timeRep.setResourceInterfaces(m_timeInterfaces); - m_timeRep.setValue("link", m_timeLink); - m_timeHandle = NULL; - - m_networkUri = URIPrefix + "/0/net"; // URI of the resource - m_networkTypes.push_back(ResourceTypePrefix + ".net"); // resource type name. - m_networkInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_networkRep.setUri(m_networkUri); - m_networkRep.setResourceTypes(m_networkTypes); - m_networkRep.setResourceInterfaces(m_networkInterfaces); - m_networkRep.setValue("link", m_networkLink); - m_networkHandle = NULL; - - m_securityUri = URIPrefix + "/0/sec"; // URI of the resource - m_securityTypes.push_back(ResourceTypePrefix + ".sec"); // resource type name. - m_securityInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_securityRep.setUri(m_securityUri); - m_securityRep.setResourceTypes(m_securityTypes); - m_securityRep.setResourceInterfaces(m_securityInterfaces); - m_securityRep.setValue("link", m_securityLink); - m_securityHandle = NULL; - - m_configurationUri = URIPrefix + ""; // URI of the resource - m_configurationTypes.push_back(ResourceTypePrefix + ""); // resource type name. - m_configurationInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_configurationInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_configurationInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_configurationRep.setValue("value", m_configurationValue); - m_configurationRep.setUri(m_configurationUri); - m_configurationRep.setResourceTypes(m_configurationTypes); - m_configurationRep.setResourceInterfaces(m_configurationInterfaces); - m_configurationHandle = NULL; - - myTimeCollection = new TimeCollection(URIPrefix, ResourceTypePrefix); - myNetworkCollection = new NetworkCollection(URIPrefix, ResourceTypePrefix); - mySecurityCollection = new SecurityCollection(URIPrefix, ResourceTypePrefix); - } - ; - - ~ConfigurationCollection() - { - free(myTimeCollection); - free(myNetworkCollection); - free(mySecurityCollection); } /// This function internally calls registerResource API. void createResources(ResourceEntityHandler callback); - void setConfigurationRepresentation(OCRepresentation& rep); - void setTimeRepresentation(OCRepresentation& rep); - void setNetworkRepresentation(OCRepresentation& rep); - void setSecurityRepresentation(OCRepresentation& rep); - void setRegionRepresentation(OCRepresentation& rep); - - OCRepresentation getTimeRepresentation(); - OCRepresentation getNetworkRepresentation(); - OCRepresentation getSecurityRepresentation(); - OCRepresentation getRegionRepresentation(); OCRepresentation getConfigurationRepresentation(); - - std::string getConfigurationUri(); - std::string getTimeUri(); - std::string getNetworkUri(); - std::string getSecurityUri(); - std::string getRegionUri(); + std::string getUri(); void factoryReset(); diff --git a/service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.cpp b/service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.cpp old mode 100644 new mode 100755 index 31eaf1e..7809396 --- a/service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.cpp +++ b/service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.cpp @@ -33,7 +33,7 @@ using namespace OC; /// This function internally calls registerResource API. -void DiagnosticsCollection::createResources(ResourceEntityHandler callback) +void DiagnosticsResource::createResources(ResourceEntityHandler callback) { using namespace OC::OCPlatform; @@ -53,192 +53,72 @@ void DiagnosticsCollection::createResources(ResourceEntityHandler callback) std::cout << "Resource creation (diagnostics) was unsuccessful\n"; } - result = bindInterfaceToResource(m_diagnosticsHandle, m_diagnosticsInterfaces[1]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_diagnosticsHandle, m_diagnosticsInterfaces[2]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = registerResource(m_factoryResetHandle, m_factoryResetUri, m_factoryResetTypes[0], - m_factoryResetInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (factoryReset) was unsuccessful\n"; - } - - result = registerResource(m_rebootHandle, m_rebootUri, m_rebootTypes[0], m_rebootInterfaces[0], - callback, OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (reboot) was unsuccessful\n"; - } - - result = registerResource(m_startCollectionHandle, m_startCollectionUri, - m_startCollectionTypes[0], m_startCollectionInterfaces[0], callback, - OC_DISCOVERABLE | OC_OBSERVABLE); - - if (OC_STACK_OK != result) - { - std::cout << "Resource creation (startCollection) was unsuccessful\n"; - } - - result = bindResource(m_diagnosticsHandle, m_factoryResetHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding installedLocation resource to room was unsuccessful\n"; - } - - result = bindResource(m_diagnosticsHandle, m_rebootHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding time resource to room was unsuccessful\n"; - } - - result = bindResource(m_diagnosticsHandle, m_startCollectionHandle); - if (OC_STACK_OK != result) - { - std::cout << "Binding network resource to room was unsuccessful\n"; - } - thread exec( std::function< void(int second) >( - std::bind(&DiagnosticsCollection::diagnosticsMonitor, this, + std::bind(&DiagnosticsResource::diagnosticsMonitor, this, std::placeholders::_1)), 10); // every 10 seconds exec.detach(); - std::cout << "Diagnostics Collection is Created!\n"; -} - -void DiagnosticsCollection::setDiagnosticsRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("value", value)) - { - m_diagnosticsValue = value; - - std::cout << "\t\t\t\t" << "m_diagnosticsValue: " << m_diagnosticsValue << std::endl; - } + std::cout << "Diagnostics Resource is Created!\n"; } -void DiagnosticsCollection::setFactoryResetRepresentation(OCRepresentation& rep) +void DiagnosticsResource::setDiagnosticsRepresentation(OCRepresentation& rep) { string value; - if (rep.getValue("value", value)) + if (rep.getValue("fr", value)) { - m_factoryResetValue = value; - - std::cout << "\t\t\t\t" << "value: " << m_factoryResetValue << std::endl; + m_factoryReset = value; + std::cout << "\t\t\t\t" << "m_factoryReset: " << m_factoryReset << std::endl; } -} - -void DiagnosticsCollection::setRebootRepresentation(OCRepresentation& rep) -{ - string value; - if (rep.getValue("value", value)) + if (rep.getValue("rb", value)) { - m_rebootValue = value; - - std::cout << "\t\t\t\t" << "value: " << m_rebootValue << std::endl; + m_reboot = value; + std::cout << "\t\t\t\t" << "m_reboot: " << m_reboot << std::endl; } -} - -void DiagnosticsCollection::setStartCollectionRepresentation(OCRepresentation& rep) -{ - string value; - if (rep.getValue("value", value)) + if (rep.getValue("ssc", value)) { - m_startCollectionValue = value; - - std::cout << "\t\t\t\t" << "value: " << m_startCollectionValue << std::endl; + m_startStatCollection = value; + std::cout << "\t\t\t\t" << "m_startStatCollection: " << m_startStatCollection << std::endl; } } -OCRepresentation DiagnosticsCollection::getFactoryResetRepresentation() -{ - m_factoryResetRep.setValue("value", m_factoryResetValue); - - return m_factoryResetRep; -} - -OCRepresentation DiagnosticsCollection::getRebootRepresentation() +OCRepresentation DiagnosticsResource::getDiagnosticsRepresentation() { - m_rebootRep.setValue("value", m_rebootValue); - - return m_rebootRep; -} - -OCRepresentation DiagnosticsCollection::getStartCollectionRepresentation() -{ - m_startCollectionRep.setValue("value", m_startCollectionValue); - - return m_startCollectionRep; -} - -OCRepresentation DiagnosticsCollection::getDiagnosticsRepresentation() -{ - m_diagnosticsRep.clearChildren(); - - m_diagnosticsRep.addChild(getFactoryResetRepresentation()); - m_diagnosticsRep.addChild(getRebootRepresentation()); - m_diagnosticsRep.addChild(getStartCollectionRepresentation()); - - m_diagnosticsRep.setValue("value", m_diagnosticsValue); + m_diagnosticsRep.setValue("fr", m_factoryReset); + m_diagnosticsRep.setValue("rb", m_reboot); + m_diagnosticsRep.setValue("ssc", m_startStatCollection); return m_diagnosticsRep; } -std::string DiagnosticsCollection::getDiagnosticsUri() +std::string DiagnosticsResource::getUri() { return m_diagnosticsUri; } -std::string DiagnosticsCollection::getFactoryResetUri() -{ - return m_factoryResetUri; -} - -std::string DiagnosticsCollection::getRebootUri() -{ - return m_rebootUri; -} - -std::string DiagnosticsCollection::getStartCollectionUri() -{ - return m_startCollectionUri; -} - -void DiagnosticsCollection::diagnosticsMonitor(int second) +void DiagnosticsResource::diagnosticsMonitor(int second) { while (1) { sleep(second); - if (m_rebootValue == "true") + if (m_reboot == "true") { int res; std::cout << "Reboot will be soon..." << std::endl; - m_rebootValue = defaultReboot; + m_reboot = defaultReboot; res = system("sudo reboot"); // System reboot std::cout << "return: " << res << std::endl; } - else if (m_factoryResetValue == "true") + else if (m_factoryReset == "true") { std::cout << "Factory Reset will be soon..." << std::endl; - m_factoryResetValue = defaultFactoryReset; + m_factoryReset = defaultFactoryReset; factoryReset(); } } diff --git a/service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.h b/service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.h old mode 100644 new mode 100755 index df4c83e..27f91a4 --- a/service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.h +++ b/service/things-manager/sampleapp/linux/configuration/DiagnosticsCollection.h @@ -33,91 +33,39 @@ using namespace OC; -typedef std::function< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler; +typedef std::function< + OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler; -static std::string defaultDiagnosticsValue = "false"; static std::string defaultFactoryReset = "false"; static std::string defaultReboot = "false"; -static std::string defaultStartCollection = "false"; +static std::string defaultStartStatCollection = "false"; -class DiagnosticsCollection +class DiagnosticsResource { public: // diagnostics members std::string m_diagnosticsUri; - std::string m_diagnosticsValue; + 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; - // factory reset members - std::string m_factoryResetUri; - std::string m_factoryResetValue; - std::vector< std::string > m_factoryResetTypes; - std::vector< std::string > m_factoryResetInterfaces; - OCResourceHandle m_factoryResetHandle; - OCRepresentation m_factoryResetRep; - - // reboot members - std::string m_rebootUri; - std::string m_rebootValue; - std::vector< std::string > m_rebootTypes; - std::vector< std::string > m_rebootInterfaces; - OCResourceHandle m_rebootHandle; - OCRepresentation m_rebootRep; - - // startcollection members - std::string m_startCollectionUri; - std::string m_startCollectionValue; - std::vector< std::string > m_startCollectionTypes; - std::vector< std::string > m_startCollectionInterfaces; - OCResourceHandle m_startCollectionHandle; - OCRepresentation m_startCollectionRep; - public: /// Constructor - DiagnosticsCollection() : - m_diagnosticsValue(defaultDiagnosticsValue), m_factoryResetValue(defaultFactoryReset), m_rebootValue( - defaultReboot), m_startCollectionValue(defaultStartCollection) + DiagnosticsResource() : + m_factoryReset(defaultFactoryReset), m_reboot(defaultReboot), + m_startStatCollection(defaultStartStatCollection) { - m_factoryResetUri = "/oic/diag/0/factoryReset"; // URI of the resource - m_factoryResetTypes.push_back("oic.diag.factoryReset"); // resource type name. - m_factoryResetInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_factoryResetRep.setUri(m_factoryResetUri); - m_factoryResetRep.setResourceTypes(m_factoryResetTypes); - m_factoryResetRep.setResourceInterfaces(m_factoryResetInterfaces); - m_factoryResetRep.setValue("value", m_factoryResetValue); - m_factoryResetHandle = NULL; - - m_rebootUri = "/oic/diag/0/reboot"; // URI of the resource - m_rebootTypes.push_back("oic.diag.reboot"); // resource type name. - m_rebootInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_rebootRep.setUri(m_rebootUri); - m_rebootRep.setResourceTypes(m_rebootTypes); - m_rebootRep.setResourceInterfaces(m_rebootInterfaces); - m_rebootRep.setValue("value", m_rebootValue); - m_rebootHandle = NULL; - - m_startCollectionUri = "/oic/diag/0/startCollection"; // URI of the resource - m_startCollectionTypes.push_back("oic.diag.startCollection"); // resource type name. - m_startCollectionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_startCollectionRep.setUri(m_startCollectionUri); - m_startCollectionRep.setResourceTypes(m_startCollectionTypes); - m_startCollectionRep.setResourceInterfaces(m_startCollectionInterfaces); - m_startCollectionRep.setValue("value", m_startCollectionValue); - m_startCollectionHandle = NULL; - 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_diagnosticsInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_diagnosticsInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_diagnosticsRep.setValue("value", m_diagnosticsValue); + 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); @@ -129,19 +77,10 @@ public: void createResources(ResourceEntityHandler callback); void setDiagnosticsRepresentation(OCRepresentation& rep); - void setFactoryResetRepresentation(OCRepresentation& rep); - void setRebootRepresentation(OCRepresentation& rep); - void setStartCollectionRepresentation(OCRepresentation& rep); OCRepresentation getDiagnosticsRepresentation(); - OCRepresentation getFactoryResetRepresentation(); - OCRepresentation getRebootRepresentation(); - OCRepresentation getStartCollectionRepresentation(); - - std::string getDiagnosticsUri(); - std::string getFactoryResetUri(); - std::string getRebootUri(); - std::string getStartCollectionUri(); + + std::string getUri(); void diagnosticsMonitor(int second); diff --git a/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp b/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp old mode 100644 new mode 100755 index d050096..36c4d93 --- a/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp +++ b/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp @@ -32,8 +32,19 @@ 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 FactorySetCollection::createResources(ResourceEntityHandler callback) +void FactorySetResource::createResources(ResourceEntityHandler callback) { using namespace OC::OCPlatform; @@ -44,8 +55,8 @@ void FactorySetCollection::createResources(ResourceEntityHandler callback) } // This will internally create and register the resource. - OCStackResult result = registerResource(m_factorySetHandle, m_factorySetUri, - m_factorySetTypes[0], m_factorySetInterfaces[0], callback, + OCStackResult result = registerResource(m_configurationHandle, m_configurationUri, + m_configurationTypes[0], m_configurationInterfaces[0], callback, OC_DISCOVERABLE | OC_OBSERVABLE); if (OC_STACK_OK != result) @@ -53,89 +64,49 @@ void FactorySetCollection::createResources(ResourceEntityHandler callback) std::cout << "Resource creation (configuration) was unsuccessful\n"; } - result = bindInterfaceToResource(m_factorySetHandle, m_factorySetInterfaces[1]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } - - result = bindInterfaceToResource(m_factorySetHandle, m_factorySetInterfaces[2]); - if (OC_STACK_OK != result) - { - std::cout << "Binding TypeName to Resource was unsuccessful\n"; - } + std::cout << "FactorySet Resource is Created!\n"; +} - result = registerResource(m_configurationCollectionHandle, m_configurationCollectionUri, - m_configurationCollectionTypes[0], m_configurationCollectionInterfaces[0], callback, - OC_DISCOVERABLE | OC_OBSERVABLE); +void FactorySetResource::setFactorySetRepresentation(OCRepresentation& rep) +{ + string value; - if (OC_STACK_OK != result) + if (rep.getValue("loc", value)) { - std::cout << "Resource creation (installedLocation) was unsuccessful\n"; + m_location = value; + std::cout << "\t\t\t\t" << "m_location: " << m_location << std::endl; } - result = bindResource(m_factorySetHandle, m_configurationCollectionHandle); - if (OC_STACK_OK != result) + if (rep.getValue("st", value)) { - std::cout << "Binding installedLocation resource to room was unsuccessful\n"; + std::cout << "\t\t\t\t" << "SystemTime is not allowed to be written." << std::endl; } - defaultConfigurationCollection = new ConfigurationCollection(defaultConfigurationURIPrefix, - defaultConfigurationResourceTypePrefix); - //defaultConfigurationCollection->bindEntityHander(callback); - defaultConfigurationCollection->createResources(callback); - - std::cout << "FactorySet Collection is Created!\n"; -} - -void FactorySetCollection::setFactorySetRepresentation(OCRepresentation& rep) -{ - string value; - - if (rep.getValue("value", value)) + if (rep.getValue("c", value)) { - m_factorySetValue = value; - - std::cout << "\t\t\t\t" << "m_factorySetValue: " << m_factorySetValue << std::endl; + m_currency = value; + std::cout << "\t\t\t\t" << "m_currency: " << m_currency << std::endl; } -} - -void FactorySetCollection::setConfigurationCollectionRepresentation(OCRepresentation& rep) -{ - string value; - if (rep.getValue("link", value)) + if (rep.getValue("r", value)) { - // NOT ALLOWED - - std::cout << "\t\t\t\t" << "link: " << m_configurationCollectionLink << std::endl; + m_region = value; + std::cout << "\t\t\t\t" << "m_region: " << m_region << std::endl; } } -OCRepresentation FactorySetCollection::getConfigurationCollectionRepresentation() +OCRepresentation FactorySetResource::getFactorySetRepresentation() { - m_configurationCollectionRep.setValue("link", m_configurationCollectionLink); + 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_configurationCollectionRep; + return m_configurationRep; } -OCRepresentation FactorySetCollection::getFactorySetRepresentation() +std::string FactorySetResource::getUri() { - m_factorySetRep.clearChildren(); - - m_factorySetRep.addChild(getConfigurationCollectionRepresentation()); - - m_factorySetRep.setValue("value", m_factorySetValue); - - return m_factorySetRep; + return m_configurationUri; } -std::string FactorySetCollection::getFactorySetUri() -{ - return m_factorySetUri; -} - -std::string FactorySetCollection::getConfigurationCollectionUri() -{ - return m_configurationCollectionUri; -} diff --git a/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.h b/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.h old mode 100644 new mode 100755 index bc20a71..15b5f3f --- a/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.h +++ b/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.h @@ -34,87 +34,22 @@ using namespace OC; -typedef std::function< OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler; +typedef std::function< + OCEntityHandlerResult(std::shared_ptr< OCResourceRequest > request) > ResourceEntityHandler; -extern std::string defaultFactorySetValue; -static std::string defaultConfigurationCollectionLink = "/factorySet/oic/con"; - -static std::string defaultConfigurationURIPrefix = "/factorySet/oic/con"; -static std::string defaultConfigurationResourceTypePrefix = "factorySet.oic.con"; - -class FactorySetCollection +class FactorySetResource : public ConfigurationResource { public: - - ConfigurationCollection *defaultConfigurationCollection; - -public: - - // diagnostics members - std::string m_factorySetUri; - std::string m_factorySetValue; - std::vector< std::string > m_factorySetTypes; - std::vector< std::string > m_factorySetInterfaces; - OCResourceHandle m_factorySetHandle; - OCRepresentation m_factorySetRep; - - // Configuration members - std::string m_configurationCollectionUri; - std::string m_configurationCollectionLink; - std::vector< std::string > m_configurationCollectionTypes; - std::vector< std::string > m_configurationCollectionInterfaces; - OCResourceHandle m_configurationCollectionHandle; - OCRepresentation m_configurationCollectionRep; - -public: /// Constructor - FactorySetCollection() : - m_factorySetValue(defaultFactorySetValue), m_configurationCollectionLink( - defaultConfigurationCollectionLink) - { - m_configurationCollectionUri = "/factorySet/0/con"; // URI of the resource - m_configurationCollectionTypes.push_back("factorySet.con"); // resource type name. - m_configurationCollectionInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - - m_configurationCollectionRep.setUri(m_configurationCollectionUri); - m_configurationCollectionRep.setResourceTypes(m_configurationCollectionTypes); - m_configurationCollectionRep.setResourceInterfaces(m_configurationCollectionInterfaces); - m_configurationCollectionRep.setValue("link", m_configurationCollectionLink); - m_configurationCollectionHandle = NULL; - - m_factorySetUri = "/factorySet"; // URI of the resource - m_factorySetTypes.push_back("factorySet"); // resource type name. - m_factorySetInterfaces.push_back(DEFAULT_INTERFACE); // resource interface. - m_factorySetInterfaces.push_back(BATCH_INTERFACE); // resource interface. - m_factorySetInterfaces.push_back(LINK_INTERFACE); // resource interface. - m_factorySetRep.setValue("value", m_factorySetValue); - m_factorySetRep.setUri(m_factorySetUri); - m_factorySetRep.setResourceTypes(m_factorySetTypes); - m_factorySetRep.setResourceInterfaces(m_factorySetInterfaces); - m_factorySetHandle = NULL; - - defaultConfigurationCollection = NULL; - } - ; + FactorySetResource(); - ~FactorySetCollection() - { - if (defaultConfigurationCollection != NULL) - free(defaultConfigurationCollection); - } - ; + ~FactorySetResource(); /// This function internally calls registerResource API. void createResources(ResourceEntityHandler callback); - void setFactorySetRepresentation(OCRepresentation& rep); - void setConfigurationCollectionRepresentation(OCRepresentation& rep); - OCRepresentation getFactorySetRepresentation(); - OCRepresentation getConfigurationCollectionRepresentation(); - - std::string getFactorySetUri(); - std::string getConfigurationCollectionUri(); + std::string getUri(); }; diff --git a/service/things-manager/sampleapp/linux/configuration/bootstrapserver.cpp b/service/things-manager/sampleapp/linux/configuration/bootstrapserver.cpp old mode 100644 new mode 100755 index e53f61c..5bc8141 --- a/service/things-manager/sampleapp/linux/configuration/bootstrapserver.cpp +++ b/service/things-manager/sampleapp/linux/configuration/bootstrapserver.cpp @@ -37,15 +37,11 @@ bool prepareResponse(std::shared_ptr< OCResourceRequest > request); OCStackResult sendResponse(std::shared_ptr< OCResourceRequest > pRequest); OCEntityHandlerResult entityHandlerBootstrap(std::shared_ptr< OCResourceRequest > request); -#define DefaultConfigurationValue "Configuration Collection" -#define DefaultRegionValue "Seoul, Korea" -#define DefaultTimeValue "Time Collection" -#define DefaultCurrentTimeValue "00:00:00" -#define DefaultNetworkValue "Network Collection" -#define DefaultIPAddressValue "192.168.0.2" -#define DefaultSecurityValue "SecurityValue" -#define DefaultModeValue "NoSec" -#define DefaultFactorySetValue "FactorySet Value" +#define DefaultRegion "Seoul, Korea" +#define DefaultSystemTime "00:00:00" +#define DefaultLocation "37.256616, 127.052806" +#define DefaultCurrency "Won" + class BootstrapResource { @@ -92,15 +88,10 @@ public: OCRepresentation getBootstrapRepresentation() { - m_bootstrapRep.setValue< std::string >("regionValue", DefaultRegionValue); - m_bootstrapRep.setValue< std::string >("timeValue", DefaultTimeValue); - m_bootstrapRep.setValue< std::string >("currentTimeValue", DefaultCurrentTimeValue); - m_bootstrapRep.setValue< std::string >("networkValue", DefaultNetworkValue); - m_bootstrapRep.setValue< std::string >("IPAddressValue", DefaultIPAddressValue); - m_bootstrapRep.setValue< std::string >("securityValue", DefaultSecurityValue); - m_bootstrapRep.setValue< std::string >("modeValue", DefaultModeValue); - m_bootstrapRep.setValue< std::string >("configurationValue", DefaultConfigurationValue); - m_bootstrapRep.setValue< std::string >("factorySetValue", DefaultFactorySetValue); + m_bootstrapRep.setValue< std::string >("r", DefaultRegion); + m_bootstrapRep.setValue< std::string >("st", DefaultSystemTime); + m_bootstrapRep.setValue< std::string >("loc", DefaultLocation); + m_bootstrapRep.setValue< std::string >("c", DefaultCurrency); return m_bootstrapRep; } diff --git a/service/things-manager/sampleapp/linux/configuration/con-client.cpp b/service/things-manager/sampleapp/linux/configuration/con-client.cpp index fbf4493..5e84817 100755 --- a/service/things-manager/sampleapp/linux/configuration/con-client.cpp +++ b/service/things-manager/sampleapp/linux/configuration/con-client.cpp @@ -107,7 +107,15 @@ void onUpdate(const HeaderOptions& headerOptions, const OCRepresentation& rep, c } std::cout << "\tResource URI: " << rep.getUri() << std::endl; - std::cout << "\t\tvalue:" << rep.getValue< std::string >("value") << std::endl; + + if (rep.hasAttribute("loc")) + std::cout << "\t\tLocation:" << rep.getValue< std::string >("loc") << std::endl; + if (rep.hasAttribute("st")) + std::cout << "\t\tSystemTime:" << rep.getValue< std::string >("st") << std::endl; + if (rep.hasAttribute("c")) + std::cout << "\t\tCurrency:" << rep.getValue< std::string >("c") << std::endl; + if (rep.hasAttribute("r")) + std::cout << "\t\tRegion:" << rep.getValue< std::string >("r") << std::endl; } void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode) @@ -121,28 +129,19 @@ void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, cons std::cout << "\tResource URI: " << rep.getUri() << std::endl; - if (rep.hasAttribute("value")) - std::cout << "\t\tvalue:" << rep.getValue< std::string >("value") << std::endl; - else if (rep.hasAttribute("link")) - std::cout << "\t\tlink:" << rep.getValue< std::string >("link") << std::endl; - - std::vector< OCRepresentation > children = rep.getChildren(); - - for (auto oit = children.begin(); oit != children.end(); ++oit) - { - std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl; - - if (oit->hasAttribute("value")) - std::cout << "\t\tvalue:" << oit->getValue< std::string >("value") << std::endl; - else if (oit->hasAttribute("link")) - std::cout << "\t\tlink:" << oit->getValue< std::string >("link") << std::endl; - } + if (rep.hasAttribute("loc")) + std::cout << "\t\tLocation:" << rep.getValue< std::string >("loc") << std::endl; + if (rep.hasAttribute("st")) + std::cout << "\t\tSystemTime:" << rep.getValue< std::string >("st") << std::endl; + if (rep.hasAttribute("c")) + std::cout << "\t\tCurrency:" << rep.getValue< std::string >("c") << std::endl; + if (rep.hasAttribute("r")) + std::cout << "\t\tRegion:" << rep.getValue< std::string >("r") << std::endl; } // Callback to found collection resource void onFoundCollectionResource(std::vector< std::shared_ptr< OCResource > > resources) { - std::string resourceURI; std::string hostAddress; try @@ -183,7 +182,7 @@ void onFoundCollectionResource(std::vector< std::shared_ptr< OCResource > > reso } // Callback to found resources -void onFoundCandidateCollection(std::vector< std::shared_ptr< OCResource > > resources) +void onFoundCandidateResource(std::vector< std::shared_ptr< OCResource > > resources) { std::string resourceURI; @@ -285,11 +284,10 @@ int main(int argc, char* argv[]) cout << endl << endl << "(0) Quit" << std::endl; cout << "(1) Find all resources(URI: /oic/con, /oic/diag, /factoryset)" << std::endl; cout << "(2) Find all groups" << std::endl; - cout << "(3) Get a new value (of \"Configuration\" Collection)" << std::endl; - cout << "(4) Update a value (of \"Region\" Resource)" << std::endl; - cout << "(5) Get a value (for \"Region\" Resource)" << std::endl; - cout << "(6) FactoryReset (for the group)" << std::endl; - cout << "(7) Reboot (for the group)" << std::endl; + cout << "(3) Get a Configuration resource" << std::endl; + cout << "(4) Update a region attribute value" << std::endl; + cout << "(5) FactoryReset (for the group)" << std::endl; + cout << "(6) Reboot (for the group)" << std::endl; cout << "(10) Show Configuration Units" << std::endl; cin >> g_Steps; @@ -299,90 +297,70 @@ int main(int argc, char* argv[]) else if (g_Steps == 1) { std::vector< std::string > types; - { // For Registering a collection resource for configuration resources + // For Registering a collection resource for configuration resources + if (configurationCollectionHandle == NULL) + { string resourceURI = "/core/a/configuration/resourceset"; string resourceTypeName = "core.configuration.resourceset"; string resourceInterface = BATCH_INTERFACE; - if (configurationCollectionHandle != NULL) - { - std::cout << "already exists" << std::endl; - continue; - } - OCPlatform::registerResource(configurationCollectionHandle, resourceURI, - resourceTypeName, resourceInterface, NULL, - //&entityHandler, // entityHandler - OC_DISCOVERABLE); + resourceTypeName, resourceInterface, NULL, + //&entityHandler, // entityHandler + OC_DISCOVERABLE); OCPlatform::bindInterfaceToResource(configurationCollectionHandle, GROUP_INTERFACE); OCPlatform::bindInterfaceToResource(configurationCollectionHandle, - DEFAULT_INTERFACE); - - // instead of registration - types.push_back("oic.con"); - std::cout << "Finding Configuration Resource... " << std::endl; + DEFAULT_INTERFACE); } - { // For Registering a collection resource for diagnostics resources - + // For Registering a collection resource for diagnostics resources + if (diagnosticsCollectionHandle == NULL) + { string resourceURI = "/core/a/diagnostics/resourceset"; string resourceTypeName = "core.diagnostics.resourceset"; string resourceInterface = BATCH_INTERFACE; - if (diagnosticsCollectionHandle != NULL) - { - std::cout << "already exists" << std::endl; - continue; - } - OCPlatform::registerResource(diagnosticsCollectionHandle, resourceURI, - resourceTypeName, resourceInterface, NULL, - //&entityHandler, // entityHandler - OC_DISCOVERABLE); + resourceTypeName, resourceInterface, NULL, + //&entityHandler, // entityHandler + OC_DISCOVERABLE); OCPlatform::bindInterfaceToResource(diagnosticsCollectionHandle, GROUP_INTERFACE); OCPlatform::bindInterfaceToResource(diagnosticsCollectionHandle, DEFAULT_INTERFACE); - - // instead of registration - types.push_back("oic.diag"); - std::cout << "Finding Diagnostics Resource... " << std::endl; - } - { // For Registering a collection resource for set resources - + // For Registering a collection resource for set resources + if (setCollectionHandle == NULL) + { string resourceURI = "/core/a/factoryset/resourceset"; string resourceTypeName = "core.factoryset.resourceset"; string resourceInterface = BATCH_INTERFACE; - if (setCollectionHandle != NULL) - { - std::cout << "already exists" << std::endl; - continue; - } - OCPlatform::registerResource(setCollectionHandle, resourceURI, resourceTypeName, - resourceInterface, NULL, - //&entityHandler, // entityHandler - OC_DISCOVERABLE); + resourceInterface, NULL, + //&entityHandler, // entityHandler + OC_DISCOVERABLE); OCPlatform::bindInterfaceToResource(setCollectionHandle, GROUP_INTERFACE); OCPlatform::bindInterfaceToResource(setCollectionHandle, DEFAULT_INTERFACE); - - // instead of registration - types.push_back("factorySet"); - std::cout << "Finding Set Resource... " << std::endl; } - g_thingsmanager->findCandidateResources(types, &onFoundCandidateCollection, 5); + types.push_back("oic.con"); + types.push_back("oic.diag"); + types.push_back("factorySet"); + + std::cout << "Finding Configuration Resource... " << std::endl; + std::cout << "Finding Diagnostics Resource... " << std::endl; + std::cout << "Finding Set Resource... " << std::endl; + + g_thingsmanager->findCandidateResources(types, &onFoundCandidateResource, 5); isWaiting = 1; thread t(&timeCheck, 5); t.join(); // After 5 seconds, isWaiting value will be 0. - t.~thread(); } else if (g_Steps == 2) // make a group with found things { @@ -399,27 +377,26 @@ int main(int argc, char* argv[]) thread t(&timeCheck, 5); t.join(); // After 5 seconds, isWaiting value will be 0. - t.~thread(); } else if (g_Steps == 3) { // get a value - ConfigurationName name = "configuration"; + ConfigurationName name = "all"; - std::cout << "For example, get configuration collection's value" << std::endl; + std::cout << "For example, get configuration resources's value" << std::endl; std::vector< ConfigurationName > configurations; configurations.push_back(name); - if (g_thingsmanager->getConfigurations(g_configurationResource, configurations, &onGet) + if (g_thingsmanager->getConfigurations(g_configurationCollection, configurations, &onGet) != OC_STACK_ERROR) isWaiting = 1; } else if (g_Steps == 4) { - ConfigurationName name = "region"; + ConfigurationName name = "r"; ConfigurationValue value = "U.S.A (new region)"; if(g_configurationCollection == NULL) @@ -441,28 +418,6 @@ int main(int argc, char* argv[]) } else if (g_Steps == 5) { - // get a value - - ConfigurationName name = "region"; - - if(g_configurationCollection == NULL) - { - std::cout<<"Note that you first create a group to use this command." << std::endl; - continue; - } - - std::cout << "For example, get region resource's value" << std::endl; - - std::vector< ConfigurationName > configurations; - - configurations.push_back(name); - - if (g_thingsmanager->getConfigurations(g_configurationCollection, configurations, - &onGet) != OC_STACK_ERROR) - isWaiting = 1; - } - else if (g_Steps == 6) - { // factory reset if(g_diagnosticsCollection == NULL) { @@ -474,7 +429,7 @@ int main(int argc, char* argv[]) != OC_STACK_ERROR) isWaiting = 1; } - else if (g_Steps == 7) + else if (g_Steps == 6) { // reboot if(g_diagnosticsCollection == NULL) @@ -496,3 +451,4 @@ int main(int argc, char* argv[]) return 0; } + diff --git a/service/things-manager/sampleapp/linux/configuration/con-server.cpp b/service/things-manager/sampleapp/linux/configuration/con-server.cpp index 9bf8cb8..bb68bfd 100755 --- a/service/things-manager/sampleapp/linux/configuration/con-server.cpp +++ b/service/things-manager/sampleapp/linux/configuration/con-server.cpp @@ -41,16 +41,11 @@ int isWaiting = 0; // Default system configuration value's variables // The variable's names should be same as the names of "extern" variables defined in -// "ConfigurationCollection.h" -std::string defaultRegionValue; -std::string defaultTimeValue; -std::string defaultCurrentTimeValue; -std::string defaultNetworkValue; -std::string defaultIPAddressValue; -std::string defaultSecurityValue; -std::string defaultModeValue; -std::string defaultConfigurationValue; -std::string defaultFactorySetValue; +// "ConfigurationResource.h" +std::string defaultLocation; +std::string defaultRegion; +std::string defaultSystemTime; +std::string defaultCurrency; static ThingsManager* g_thingsmanager; @@ -59,9 +54,9 @@ bool prepareResponseForResource(std::shared_ptr< OCResourceRequest > request); OCStackResult sendResponseForResource(std::shared_ptr< OCResourceRequest > pRequest); OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceRequest > request); -ConfigurationCollection *myConfigurationCollection; -DiagnosticsCollection *myDiagnosticsCollection; -FactorySetCollection *myFactorySetCollection; +ConfigurationResource *myConfigurationResource; +DiagnosticsResource *myDiagnosticsResource; +FactorySetResource *myFactorySetResource; typedef std::function< void(OCRepresentation&) > putFunc; typedef std::function< OCRepresentation(void) > getFunc; @@ -70,33 +65,15 @@ getFunc getGetFunction(std::string uri) { getFunc res = NULL; - if (uri == myConfigurationCollection->getTimeUri()) + if (uri == myConfigurationResource->getUri()) { - res = std::bind(&ConfigurationCollection::getTimeRepresentation, myConfigurationCollection); + res = std::bind(&ConfigurationResource::getConfigurationRepresentation, + myConfigurationResource); } - else if (uri == myConfigurationCollection->getConfigurationUri()) + else if (uri == myDiagnosticsResource->getUri()) { - res = std::bind(&ConfigurationCollection::getConfigurationRepresentation, - myConfigurationCollection); - } - else if (uri == myConfigurationCollection->myTimeCollection->getCurrentTimeUri()) - { - res = std::bind(&TimeCollection::getCurrentTimeRepresentation, - myConfigurationCollection->myTimeCollection); - } - else if (uri == myConfigurationCollection->getRegionUri()) - { - res = std::bind(&ConfigurationCollection::getRegionRepresentation, - myConfigurationCollection); - } - else if (uri == myDiagnosticsCollection->getFactoryResetUri()) - { - res = std::bind(&DiagnosticsCollection::getFactoryResetRepresentation, - myDiagnosticsCollection); - } - else if (uri == myDiagnosticsCollection->getRebootUri()) - { - res = std::bind(&DiagnosticsCollection::getRebootRepresentation, myDiagnosticsCollection); + res = std::bind(&DiagnosticsResource::getDiagnosticsRepresentation, + myDiagnosticsResource); } return res; @@ -106,25 +83,15 @@ putFunc getPutFunction(std::string uri) { putFunc res = NULL; - if (uri == myConfigurationCollection->getRegionUri()) + if (uri == myConfigurationResource->getUri()) { - res = std::bind(&ConfigurationCollection::setRegionRepresentation, - myConfigurationCollection, std::placeholders::_1); + res = std::bind(&ConfigurationResource::setConfigurationRepresentation, + myConfigurationResource, std::placeholders::_1); } - else if (uri == myConfigurationCollection->myTimeCollection->getCurrentTimeUri()) + else if (uri == myDiagnosticsResource->getUri()) { - res = std::bind(&TimeCollection::setCurrentTimeRepresentation, - myConfigurationCollection->myTimeCollection, std::placeholders::_1); - } - else if (uri == myDiagnosticsCollection->getFactoryResetUri()) - { - res = std::bind(&DiagnosticsCollection::setFactoryResetRepresentation, - myDiagnosticsCollection, std::placeholders::_1); - } - else if (uri == myDiagnosticsCollection->getRebootUri()) - { - res = std::bind(&DiagnosticsCollection::setRebootRepresentation, myDiagnosticsCollection, - std::placeholders::_1); + res = std::bind(&DiagnosticsResource::setDiagnosticsRepresentation, + myDiagnosticsResource, std::placeholders::_1); } return res; @@ -231,6 +198,8 @@ OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceReques std::cout << "\tIn Server CPP (entityHandlerForResource) entity handler:\n"; OCEntityHandlerResult ehResult = OC_EH_ERROR; + QueryParamsMap test = request->getQueryParameters(); + if (prepareResponseForResource(request)) { if (OC_STACK_OK == sendResponseForResource(request)) @@ -263,25 +232,16 @@ void onBootstrap(const HeaderOptions& headerOptions, const OCRepresentation& rep std::cout << "\n\nGET request was successful" << std::endl; std::cout << "\tResource URI: " << rep.getUri() << std::endl; - defaultRegionValue = rep.getValue< std::string >("regionValue"); - defaultTimeValue = rep.getValue< std::string >("timeValue"); - defaultCurrentTimeValue = rep.getValue< std::string >("currentTimeValue"); - defaultNetworkValue = rep.getValue< std::string >("networkValue"); - defaultIPAddressValue = rep.getValue< std::string >("IPAddressValue"); - defaultSecurityValue = rep.getValue< std::string >("securityValue"); - defaultModeValue = rep.getValue< std::string >("modeValue"); - defaultConfigurationValue = rep.getValue< std::string >("configurationValue"); - defaultFactorySetValue = rep.getValue< std::string >("factorySetValue"); - - std::cout << "\tregionValue : " << defaultRegionValue << std::endl; - std::cout << "\ttimeValue : " << defaultTimeValue << std::endl; - std::cout << "\tcurrentTimeValue : " << defaultCurrentTimeValue << std::endl; - std::cout << "\tnetworkValue : " << defaultNetworkValue << std::endl; - std::cout << "\tIPAddressValue : " << defaultIPAddressValue << std::endl; - std::cout << "\tsecurityValue : " << defaultSecurityValue << std::endl; - std::cout << "\tmodeValue : " << defaultModeValue << std::endl; - std::cout << "\tconfigurationValue : " << defaultConfigurationValue << std::endl; - std::cout << "\tfactorySetValue : " << defaultFactorySetValue << std::endl; + defaultRegion = rep.getValue< std::string >("r"); + defaultSystemTime = rep.getValue< std::string >("st"); + defaultCurrency = rep.getValue< std::string >("c"); + defaultLocation = rep.getValue< std::string >("loc"); + + std::cout << "\tLocation : " << defaultLocation << std::endl; + std::cout << "\tSystemTime : " << defaultSystemTime << std::endl; + std::cout << "\tCurrency : " << defaultCurrency << std::endl; + std::cout << "\tRegion : " << defaultRegion << std::endl; + } int main() @@ -330,17 +290,19 @@ int main() } else if (g_Steps == 2) { - myConfigurationCollection = new ConfigurationCollection(); - myConfigurationCollection->createResources(&entityHandlerForResource); + myConfigurationResource = new ConfigurationResource(); + myConfigurationResource->createResources(&entityHandlerForResource); + + myDiagnosticsResource = new DiagnosticsResource(); + myDiagnosticsResource->createResources(&entityHandlerForResource); + - myDiagnosticsCollection = new DiagnosticsCollection(); - myDiagnosticsCollection->createResources(&entityHandlerForResource); + myFactorySetResource = new FactorySetResource(); + myFactorySetResource->createResources(&entityHandlerForResource); + myDiagnosticsResource->factoryReset = std::function < void() + > (std::bind(&ConfigurationResource::factoryReset, + myConfigurationResource)); - myFactorySetCollection = new FactorySetCollection(); - myFactorySetCollection->createResources(&entityHandlerForResource); - myDiagnosticsCollection->factoryReset = std::function < void() - > (std::bind(&ConfigurationCollection::factoryReset, - myConfigurationCollection)); isWaiting = 1; } } diff --git a/service/things-manager/sdk/src/ThingsConfiguration.cpp b/service/things-manager/sdk/src/ThingsConfiguration.cpp index 53d64ce..33fa2e9 100755 --- a/service/things-manager/sdk/src/ThingsConfiguration.cpp +++ b/service/things-manager/sdk/src/ThingsConfiguration.cpp @@ -36,11 +36,59 @@ namespace OIC int cnt = 0; std::map< std::string, ConfigurationRequestEntry > configurationRequestTable; - ThingsConfiguration* ThingsConfiguration::thingsConfigurationInstance = NULL; - ConfigurationCallback g_bootstrapCallback; + ConfigurationRequestEntry::ConfigurationRequestEntry(std::string ID, + ConfigurationCallback callback, + std::shared_ptr< OCResource > resource, + std::string updateVal) + { + m_ID = ID; + m_callback = callback; + m_resource = resource; + m_updateVal = updateVal; + } + + ConfigurationUnitInfo::ConfigurationUnitInfo(std::string name, + std::string attribute, + std::string uri) + { + m_name = name; + m_attribute = attribute; + m_uri = uri; + } + + std::string ConfigurationUnitInfo::getJSON() + { + std::string res; + + res = "{\"name\":\"" + m_name + "\",\"property\":\"" + m_attribute + "\"}"; + + return res; + } + + ThingsConfiguration::ThingsConfiguration(void) + { + ConfigurationUnitInfo unit[] = + { + { "all", "All attributes", "/oic/con" }, + { "r", "Region", "/oic/con" }, + { "st", "System Time", "/oic/con"}, + { "loc", "Location", "/oic/con"}, + { "c","Currency", "/oic/con" } }; + + for (int i = 0; i < NUMCONFUNIT; i++) + ConfigurationUnitTable.push_back(unit[i]); + } + + ThingsConfiguration::~ThingsConfiguration(void){} + + void ThingsConfiguration::setGroupManager(GroupManager *groupmanager) + { + g_groupmanager = groupmanager; + } + ThingsConfiguration* ThingsConfiguration::getInstance() { if (thingsConfigurationInstance == NULL) @@ -153,17 +201,8 @@ namespace OIC void ThingsConfiguration::onDeleteActionSet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode, std::string conf) { - if (eCode != OC_STACK_OK) - { - std::cout << "onPut Response error: " << eCode << std::endl; - getCallback(conf)(headerOptions, rep, eCode); - return ; - } - std::shared_ptr < OCResource > resource = getResource(conf); - std::cout << __func__ << std::endl; - if (resource) { QueryParamsMap query; @@ -178,7 +217,6 @@ namespace OIC std::bind(&ThingsConfiguration::onGetChildInfoForUpdate, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, conf))); - } } @@ -207,7 +245,7 @@ namespace OIC std::shared_ptr < OCResource > resource = getResource(conf); std::string actionstring = conf; std::string uri = getUriByConfigurationName(conf); - std::string attr = getAttributeByConfigurationName(conf); + std::string attrKey = conf; if (uri == "") return; @@ -231,7 +269,7 @@ namespace OIC newAction->target = getHostFromURI(oit->getUri()) + uri; Capability *newCapability = new Capability(); - newCapability->capability = attr; + newCapability->capability = attrKey; newCapability->status = getUpdateVal(conf); newAction->listOfCapability.push_back(newCapability); @@ -272,7 +310,7 @@ namespace OIC if (uri == "") return; - if (uri == "/oic/con" || uri == "/factoryset" || uri == "/factoryset/oic/con") + if (uri == "/factoryset" || uri == "/factoryset/oic/con") m_if.push_back(BATCH_INTERFACE); else m_if.push_back(DEFAULT_INTERFACE); @@ -301,17 +339,8 @@ namespace OIC { try { - if (isSimpleResource(resource)) - { - QueryParamsMap test; - resource->get(test, getCallback(conf)); - } - else - { - QueryParamsMap test; - resource->get(resource->getResourceTypes().at(0), BATCH_INTERFACE, test, - getCallback(conf)); - } + QueryParamsMap test; + resource->get(test, getCallback(conf)); } catch (OCException& e) { @@ -453,7 +482,7 @@ namespace OIC if (isSimpleResource(resource)) { // This resource does not need to use a group manager. Just send a PUT message - rep.setValue(getAttributeByConfigurationName(conf), getUpdateVal(conf)); + rep.setValue(conf, getUpdateVal(conf)); return resource->put(resource->getResourceTypes().at(0), DEFAULT_INTERFACE, rep, query, std::function< void(const HeaderOptions& headerOptions, const OCRepresentation& rep, @@ -608,3 +637,4 @@ namespace OIC return g_groupmanager->findCandidateResources(type, &onFoundBootstrapServer); } } + diff --git a/service/things-manager/sdk/src/ThingsConfiguration.h b/service/things-manager/sdk/src/ThingsConfiguration.h old mode 100644 new mode 100755 index b21417e..a753440 --- a/service/things-manager/sdk/src/ThingsConfiguration.h +++ b/service/things-manager/sdk/src/ThingsConfiguration.h @@ -61,11 +61,7 @@ namespace OIC { public: ConfigurationRequestEntry(std::string ID, ConfigurationCallback callback, - std::shared_ptr< OCResource > resource, std::string updateVal): - m_ID(ID), m_callback(callback), m_resource(resource), m_updateVal(updateVal) - { - } - ; + std::shared_ptr< OCResource > resource, std::string updateVal); // Configuration Name (used in key value in std::map structure) // e.g., time, network, security, and so on @@ -92,29 +88,16 @@ namespace OIC public: std::string m_name; - std::string m_description; - std::string m_uri; std::string m_attribute; + std::string m_uri; - ConfigurationUnitInfo(std::string name, std::string description, std::string uri, - std::string attribute) : - m_name(name), m_description(description), m_uri(uri), m_attribute(attribute) - { - } - ; + ConfigurationUnitInfo(std::string name, std::string attribute, std::string uri); // If a developer wants to know a list of configuration names, gives it in JSON format. - std::string getJSON() - { - std::string res; - - res = "{\"name\":\"" + m_name + "\",\"description\":\"" + m_description + "\"}"; - - return res; - } + std::string getJSON(); }; -#define NUMCONFUNIT 6 +#define NUMCONFUNIT 5 typedef std::string ConfigurationName; typedef std::string ConfigurationValue; @@ -124,44 +107,18 @@ namespace OIC /** * Constructor for ThingsConfiguration. Constructs a new ThingsConfiguration */ - ThingsConfiguration(void) - { - ConfigurationUnitInfo unit[] = - { - { "configuration", "Configuration Collection's value and its child resource's value", - "/oic/con", "value" }, - { "region", "the current region in which the device is located geographically", - "/oic/con/0/region", "value" }, - { "timelink", "link of time collection.", "/oic/con/0/time", "link" }, - { "ipaddress", "IP Address", "/oic/con/network/0/IPAddress", "value" }, - { "securitymode", - "Resource for security information (credentials, access control list etc.)", - "/oic/con/security/0/mode", "value" }, - { "getfactoryset", "get all default configuration value", "/factoryset/oic/con", - "value" } }; - - for (int i = 0; i < NUMCONFUNIT; i++) - ConfigurationUnitTable.push_back(unit[i]); - } - ; + ThingsConfiguration(void); /** * Virtual destructor */ - ~ThingsConfiguration(void) - { - } - ; + ~ThingsConfiguration(void); static ThingsConfiguration *thingsConfigurationInstance; static ThingsConfiguration* getInstance(); void deleteInstance(); - void setGroupManager(GroupManager *groupmanager) - { - g_groupmanager = groupmanager; - } - ; + void setGroupManager(GroupManager *groupmanager); /** * API for updating configuration value of multiple things of a target group or a single @@ -265,271 +222,6 @@ namespace OIC static void onFoundBootstrapServer(std::vector< std::shared_ptr< OCResource > > resources); static void onGetBootstrapInformation(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode); - // Copyright 2014 Samsung Electronics All Rights Reserved. - - /// @file ThingsConfiguration.h - - /// @brief This file contains the declaration of classes and its members related to - /// ThingsConfiguration. - -#ifndef __OC_THINGSCONFIGURATION__ -#define __OC_THINGSCONFIGURATION__ - -#include -#include -#include -#include -#include "GroupManager.h" -#include "OCPlatform.h" -#include "OCApi.h" - - using namespace OC; - -/// Declearation of Configuation Callback funtion type - typedef std::function< - void(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode) > ConfigurationCallback; - - typedef std::string ConfigurationName; - typedef std::string ConfigurationValue; - - /** - * @brief - * The following class is used as a item stacking in request queue. The class stores a - * request and referential information (e.g., a configuration name, a target resource - * object, a callback function passed from the applications, and a update value). When the - * function for updating/getting configuration value is called from applications, this class - * instance is created and stored in the request queue. The queue is maintained in - * a std::map structure so if desiring to find a specific request, you can find it - * by querying a configuration name. - */ - class ConfigurationRequestEntry - { - public: - ConfigurationRequestEntry(std::string ID, ConfigurationCallback callback, - std::shared_ptr< OCResource > resource, std::string updateVal) : - m_ID(ID), m_callback(callback), m_resource(resource), m_updateVal(updateVal) - { - } - ; - - // Configuration Name (used in key value in std::map structure) - // e.g., time, network, security, and so on - std::string m_ID; - // Reference callback pointer - ConfigurationCallback m_callback; - // Reference resource object - std::shared_ptr< OCResource > m_resource; - // Update value only used for configuration update - std::string m_updateVal; - }; - - /** - * @brief - * The following class is used to store providing configuration name and its relevant - * information. The relevant information includes a brief description, uri, and attribute - * key. Note that a developer only specifies a configuration name, not URI nor attribute - * key, to update/get a value to a remote. Thus, using configuration name, we convert it to - * more specific information (i.e. uri and attribute key) to send a request. This class is - * reponsible to storing these information. - */ - class ConfigurationUnitInfo - { - public: - - std::string m_name; - std::string m_description; - std::string m_uri; - std::string m_attribute; - - ConfigurationUnitInfo(std::string name, std::string description, std::string uri, - std::string attribute) : - m_name(name), m_description(description), m_uri(uri), m_attribute(attribute) - { - } - ; - - // If a developer wants to know a list of configuration names, gives it in JSON format. - std::string getJSON() - { - std::string res; - - res = "{\"name\":\"" + m_name + "\",\"description\":\"" + m_description + "\"}"; - - return res; - } - }; - -#define NUMCONFUNIT 6 - typedef std::string ConfigurationName; - typedef std::string ConfigurationValue; - - class ThingsConfiguration - { - public: - /** - * Constructor for ThingsConfiguration. Constructs a new ThingsConfiguration - */ - ThingsConfiguration(void) - { - ConfigurationUnitInfo unit[] = - { - { "configuration", "Configuration value and its child resource's value", - "/oic/con", "value"}, - { "region", "the current region in which the Thing is located geographically", - "/oic/con/0/region", "value"}, - { "timelink", "link of time collection.", "/oic/con/0/time", "link"}, - { "ipaddress", "IP Address", "/oic/con/network/0/IPAddress", "value"}, - { "securitymode", - "Resource for security information (credentials, access control list etc.)", - "/oic/con/security/0/mode", "value"}, - { "getfactoryset", "get all default configuration value", - "/factoryset/oic/con", "value"}}; - - for (int i = 0; i < NUMCONFUNIT; i++) - ConfigurationUnitTable.push_back(unit[i]); - } - ; - - /** - * Virtual destructor - */ - ~ThingsConfiguration(void) - { - } - ; - - static ThingsConfiguration *thingsConfigurationInstance; - static ThingsConfiguration* getInstance(); - void deleteInstance(); - - void setGroupManager(GroupManager *groupmanager) - { - g_groupmanager = groupmanager; - } - ; - - /** - * API for updating configuration value of multiple things of a target group or a single - * thing. - * Callback is called when a response arrives. - * Before using the below function, a developer should acquire a resource pointer of - * (collection) resource that he want to send a request by calling findResource() - * function provided in OCPlatform. And he should also notice a "Configuration Name" - * term which represents a nickname of a target attribute of a resource that he wants to - * update. - * The base motivation to introduce the term is to avoid a usage of URI to access - * a resource from a developer. Thus, a developer should know which configuration names - * are supported by Things Configuration class and what the configuration name means. - * To get a list of supported configuration names, use getListOfSupportedConfigurationU- - * nits() function, which provides the list in JSON format. - * NOTICE: A series of callback functions is called from updateConfigurations() function - * (1) For a collection resource - * updateConfiguration()->onDeleteActionSet()->onGetChildInfoForUpdate()->onCreateActio- - * nSet()->...(CoAP msg. is transmitted)->OnExecuteForGroupAction()->callback function - * in APP. - * (2) For a simple resource - * updateConfiguration()->...(CoAP msg. is transmitted)->OnPut()->callback function in - * APP. - * - * @param resource - resource pointer representing the target group or the single thing. - * @param configurations - ConfigurationUnit: a nickname of attribute of target resource - * (e.g., installedlocation, currency, (IP)address) - * Value : a value to be updated - * @param callback - callback. - * - * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ - OCStackResult updateConfigurations(std::shared_ptr< OCResource > resource, - std::map< ConfigurationName, ConfigurationValue > configurations, - ConfigurationCallback callback); - - /** - * API for getting configuration value of multiple things of a target group or a single - * thing. - * Callback is called when a response arrives. - * NOTICE: A series of callback functions is called from getConfigurations() function: - * (1) For a collection resource - * getConfigurations()->onGetChildInfoForGet()->...(CoAP msg. is transmitted) - * ->callback function in APP. - * (2) For a simple resource - * getConfigurations()->...(CoAP msg. is transmitted)->onGet()->callback function in APP - * - * @param resource - resource pointer representing the target group or the single thing. - * @param configurations - ConfigurationUnit: a nickname of attribute of target resource - * @param callback - callback. - * - * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ - OCStackResult getConfigurations(std::shared_ptr< OCResource > resource, - std::vector< ConfigurationName > configurations, ConfigurationCallback callback); - - /** - * API to show a list of supported configuration units (configurable parameters) - * Callback call when a response arrives. - * - * @return the list in JSON format - */ - std::string getListOfSupportedConfigurationUnits(); - - /** - * API for bootstrapping functionality. Find a bootstrap server and get configuration - * information from the bootstrap server. With the information, make a configuration - * resource. - * - * @param callback - callback. - * - * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ - OCStackResult doBootstrap(ConfigurationCallback callback); - - private: - - GroupManager *g_groupmanager; - - std::vector< ConfigurationUnitInfo > ConfigurationUnitTable; - - void onExecuteForGroupAction(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode, std::string conf); - void onGetChildInfoForUpdate(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode, std::string conf); - void onGetChildInfoForGet(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode, std::string conf); - void onCreateActionSet(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode, std::string conf); - void onGetActionSet(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode, std::string conf); - void onDeleteActionSet(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode, std::string conf); - void onGet(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode, std::string conf); - void onPut(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode, std::string conf); - static void onFoundBootstrapServer(std::vector< std::shared_ptr< OCResource > - > resources); - static void onGetBootstrapInformation(const HeaderOptions& headerOptions, - const OCRepresentation& rep, const int eCode); - - std::shared_ptr< OCResource > getResource(std::string conf); - ConfigurationCallback getCallback(std::string conf); - std::string getUpdateVal(std::string conf); - std::string getAttributeByConfigurationName(ConfigurationName name); - std::string getUriByConfigurationName(ConfigurationName name); - - std::string getHostFromURI(std::string oldUri); - - bool isSimpleResource(std::shared_ptr< OCResource > resource); - bool hasBatchInterface(std::shared_ptr< OCResource > resource); - - }; - -#endif /* __OC_THINGSCONFIGURATION__*/ std::shared_ptr< OCResource > getResource(std::string conf); ConfigurationCallback getCallback(std::string conf); diff --git a/service/things-manager/sdk/src/ThingsDiagnostics.cpp b/service/things-manager/sdk/src/ThingsDiagnostics.cpp index 2c1cf6c..524c197 100755 --- a/service/things-manager/sdk/src/ThingsDiagnostics.cpp +++ b/service/things-manager/sdk/src/ThingsDiagnostics.cpp @@ -34,9 +34,56 @@ using namespace OC; namespace OIC { std::map< std::string, DiagnosticsRequestEntry > diagnosticsRequestTable; - ThingsDiagnostics* ThingsDiagnostics::thingsDiagnosticsInstance = NULL; + DiagnosticsRequestEntry::DiagnosticsRequestEntry(std::string ID, DiagnosticsCallback callback, + std::shared_ptr< OCResource > resource, std::string updateVal) + { + m_ID = ID; + m_callback = callback; + m_resource = resource; + m_updateVal = updateVal; + } + + DiagnosticsUnitInfo::DiagnosticsUnitInfo(std::string name, + std::string attribute, + std::string uri) + { + m_name = name; + m_attribute = attribute; + m_uri = uri; + } + + std::string DiagnosticsUnitInfo::getJSON() + { + std::string res; + + res = "{\"name\":\"" + m_name + "\",\"attribute\":\"" + m_attribute + "\"}"; + + return res; + } + + ThingsDiagnostics::ThingsDiagnostics() + { + DiagnosticsUnitInfo unit[] = + { + { "rb", "Reboot", "/oic/diag"}, + { "ssc", "StartStatCollection", "/oic/diag"}, + { "fr", "Factory Reset", "/oic/diag" } }; + + for (int i = 0; i < NUMDIAGUNIT; i++) + DiagnosticsUnitTable.push_back(unit[i]); + } + + ThingsDiagnostics::~ThingsDiagnostics() + { + } + + void ThingsDiagnostics::setGroupManager(GroupManager *groupmanager) + { + g_groupmanager = groupmanager; + } + ThingsDiagnostics* ThingsDiagnostics::getInstance() { if (thingsDiagnosticsInstance == NULL) @@ -170,7 +217,7 @@ namespace OIC std::shared_ptr < OCResource > resource = getResource(diag); std::string actionstring = diag; std::string uri = getUriByDiagnosticsName(diag); - std::string attr = getAttributeByDiagnosticsName(diag); + std::string attrKey = diag; if (uri == "") return; @@ -194,7 +241,7 @@ namespace OIC newAction->target = getHostFromURI(oit->getUri()) + uri; Capability *newCapability = new Capability(); - newCapability->capability = attr; + newCapability->capability = attrKey; newCapability->status = getUpdateVal(diag); newAction->listOfCapability.push_back(newCapability); @@ -292,7 +339,7 @@ namespace OIC return OC_STACK_ERROR; } - std::string diag = "reboot"; + std::string diag = "rb"; // Check the request queue if a previous request is still left. If so, remove it. std::map< std::string, DiagnosticsRequestEntry >::iterator iter = @@ -345,7 +392,7 @@ namespace OIC return OC_STACK_ERROR; } - std::string diag = "factoryreset"; + std::string diag = "fr"; // Check the request queue if a previous request is still left. If so, remove it. std::map< std::string, DiagnosticsRequestEntry >::iterator iter = @@ -389,3 +436,4 @@ namespace OIC } } } + diff --git a/service/things-manager/sdk/src/ThingsDiagnostics.h b/service/things-manager/sdk/src/ThingsDiagnostics.h old mode 100644 new mode 100755 index 072f367..024a2d9 --- a/service/things-manager/sdk/src/ThingsDiagnostics.h +++ b/service/things-manager/sdk/src/ThingsDiagnostics.h @@ -39,7 +39,6 @@ using namespace OC; namespace OIC { - /// Declearation of Diagnostics Callback funtion type typedef std::function< void(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode) @@ -58,11 +57,7 @@ namespace OIC { public: DiagnosticsRequestEntry(std::string ID, DiagnosticsCallback callback, - std::shared_ptr< OCResource > resource, std::string updateVal) : - m_ID(ID), m_callback(callback), m_resource(resource), m_updateVal(updateVal) - { - } - ; + std::shared_ptr< OCResource > resource, std::string updateVal); // Diagnostics Name (used in key value in std::map structure) // e.g., reboot and factoryset @@ -90,27 +85,14 @@ namespace OIC class DiagnosticsUnitInfo { public: - DiagnosticsUnitInfo(std::string name, std::string description, std::string uri, - std::string attribute) : - m_name(name), m_description(description), m_uri(uri), m_attribute(attribute) - { - } - ; - std::string m_name; - std::string m_description; - std::string m_uri; std::string m_attribute; + std::string m_uri; - // If a developer wants to know a list of diagnostics names, gives it in JSON format. - std::string getJSON() - { - std::string res; - - res = "{\"name\":\"" + m_name + "\",\"description\":\"" + m_description + "\"}"; + DiagnosticsUnitInfo(std::string name, std::string attribute, std::string uri); - return res; - } + // If a developer wants to know a list of configuration names, gives it in JSON format. + std::string getJSON(); }; #define NUMDIAGUNIT 3 @@ -123,39 +105,18 @@ namespace OIC /** * Constructor for ThingsDiagnostics. Constructs a new ThingsDiagnostics */ - ThingsDiagnostics(void) - { - DiagnosticsUnitInfo unit[] = - { - { "reboot", "reboot", "/oic/diag/0/reboot", "value" }, - { "value", - "Collecting any device statistics", - "/oic/diag/0/startCollection", "value" }, - { "factoryreset", "restore all configuration values to default values", - "/oic/diag/0/factoryReset", "value" } }; - - for (int i = 0; i < NUMDIAGUNIT; i++) - DiagnosticsUnitTable.push_back(unit[i]); - } - ; + ThingsDiagnostics(void); /** * Virtual destructor */ - ~ThingsDiagnostics(void) - { - } - ; + ~ThingsDiagnostics(void); static ThingsDiagnostics *thingsDiagnosticsInstance; static ThingsDiagnostics* getInstance(); void deleteInstance(); - void setGroupManager(GroupManager *groupmanager) - { - g_groupmanager = groupmanager; - } - ; + void setGroupManager(GroupManager *groupmanager); /** * API to make things reboot -- 2.7.4