int g_Steps = 0;
int isWaiting = 0; //0: none to wait, 1: wait for the response of "getConfigurationValue"
+const int SUCCESS_RESPONSE = 0;
+
static ThingsManager* g_thingsmanager;
OCResourceHandle configurationCollectionHandle;
typedef std::string ConfigurationName;
typedef std::string ConfigurationValue;
+void timeCheck(int timeSec)
+{
+ sleep(timeSec);
+ isWaiting = 0;
+}
+
void onReboot(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
- std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+ isWaiting = 0;
- std::cout << "\t\tReboot:" << rep.getValue< std::string >("value") << std::endl;
+ if (eCode != SUCCESS_RESPONSE)
+ {
+ return ;
+ }
- isWaiting = 0;
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+ std::cout << "\t\tReboot:" << rep.getValue< std::string >("value") << std::endl;
}
void onFactoryReset(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode)
{
- std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+ isWaiting = 0;
+
+ if (eCode != SUCCESS_RESPONSE)
+ {
+ return ;
+ }
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
std::cout << "\t\tFactoryReset:" << rep.getValue< std::string >("value") << std::endl;
- isWaiting = 0;
}
void onUpdate(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
- std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+ isWaiting = 0;
- std::cout << "\t\tvalue:" << rep.getValue< std::string >("value") << std::endl;
+ if (eCode != SUCCESS_RESPONSE)
+ {
+ return ;
+ }
- isWaiting = 0;
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+ std::cout << "\t\tvalue:" << rep.getValue< std::string >("value") << std::endl;
}
void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
+ isWaiting = 0;
+
+ if (eCode != SUCCESS_RESPONSE)
+ {
+ return ;
+ }
+
std::cout << "\tResource URI: " << rep.getUri() << std::endl;
if (rep.hasAttribute("value"))
else if (oit->hasAttribute("link"))
std::cout << "\t\tlink:" << oit->getValue< std::string >("link") << std::endl;
}
-
- isWaiting = 0;
}
// Callback to found collection resource
//log(e.what());
}
- if (g_configurationCollection != NULL && g_diagnosticsCollection != NULL
- && g_setCollection != NULL)
- isWaiting = 0;
+ isWaiting = 0;
}
// Callback to found resources
std::string resourceURI;
std::string hostAddress;
- static bool flagForCon = false, flagForDiag = false, flagForSet = false;
-
try
{
// Do some operations with resource object.
{
if (resource->uri() == "/oic/con")
{
- flagForCon = true;
OCPlatform::bindResource(configurationCollectionHandle,
foundResourceHandle);
if (g_configurationResource == NULL)
}
else if (resource->uri() == "/oic/diag")
{
- flagForDiag = true;
OCPlatform::bindResource(diagnosticsCollectionHandle,
foundResourceHandle);
if (g_diagnosticsResource == NULL)
}
else if (resource->uri() == "/factorySet")
{
- flagForSet = true;
OCPlatform::bindResource(setCollectionHandle, foundResourceHandle);
if (g_setResource == NULL)
g_setResource = resource;
//log(e.what());
}
- if (flagForCon && flagForDiag && flagForSet)
- isWaiting = 0;
+ isWaiting = 0;
}
int main(int argc, char* argv[])
g_thingsmanager->findCandidateResources(types, &onFoundCandidateCollection, 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
{
g_thingsmanager->findCandidateResources(types, &onFoundCollectionResource, 5);
std::cout << "Finding Collection resource... " << std::endl;
+
isWaiting = 1;
+ thread t(&timeCheck, 5);
+ t.join(); // After 5 seconds, isWaiting value will be 0.
+ t.~thread();
}
else if (g_Steps == 3)
{
ConfigurationName name = "region";
ConfigurationValue value = "U.S.A (new 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, change region resource's value" << std::endl;
std::cout << g_configurationCollection->uri() << std::endl;
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;
else if (g_Steps == 6)
{
// factory reset
+ if(g_diagnosticsCollection == NULL)
+ {
+ std::cout<<"Note that you first create a group to use this command." << std::endl;
+ continue;
+ }
+
if (g_thingsmanager->factoryReset(g_diagnosticsCollection, &onFactoryReset)
!= OC_STACK_ERROR)
isWaiting = 1;
else if (g_Steps == 7)
{
// reboot
+ if(g_diagnosticsCollection == NULL)
+ {
+ std::cout<<"Note that you first create a group to use this command." << std::endl;
+ continue;
+ }
+
if (g_thingsmanager->reboot(g_diagnosticsCollection, &onReboot) != OC_STACK_ERROR)
isWaiting = 1;
}
return 0;
}
-
// callback handler on GET request
void onBootstrap(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
- if (eCode == SUCCESS_RESPONSE)
- {
- 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;
+ isWaiting = 0;
- }
- else
+ if (eCode != SUCCESS_RESPONSE)
{
std::cout << "onGET Response error: " << eCode << std::endl;
- std::exit(-1);
+ return ;
}
- isWaiting = 0;
+
+ 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;
}
int main()
namespace OIC
{
- const int SUCCESS_RESPONSE = 0;
int cnt = 0;
std::map< std::string, ConfigurationRequestEntry > configurationRequestTable;
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;
void ThingsConfiguration::onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, std::string conf)
{
- if (eCode == SUCCESS_RESPONSE)
+ if (eCode != OC_STACK_OK)
{
- std::cout << "GET request was successful" << std::endl;
-
- std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+ std::cout << "onPut Response error: " << eCode << std::endl;
+ getCallback(conf)(headerOptions, rep, eCode);
+ return ;
+ }
- 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;
- }
+ std::cout << "GET request was successful" << std::endl;
- // Get information by using configuration name(conf)
- std::shared_ptr < OCResource > resource = getResource(conf);
- std::string actionstring = conf;
- std::string uri = getUriByConfigurationName(conf);
- std::string attr = getAttributeByConfigurationName(conf);
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
- if (uri == "")
- return;
+ 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 (resource)
- {
- // In this nest, we create a new action set of which name is the configuration name.
- // Required information consists of a host address, URI, attribute key, and
- // attribute value.
- ActionSet *newActionSet = new ActionSet();
- newActionSet->actionsetName = conf;
+ // Get information by using configuration name(conf)
+ std::shared_ptr < OCResource > resource = getResource(conf);
+ std::string actionstring = conf;
+ std::string uri = getUriByConfigurationName(conf);
+ std::string attr = getAttributeByConfigurationName(conf);
- for (auto oit = children.begin(); oit != children.end(); ++oit)
- {
- Action *newAction = new Action();
+ if (uri == "")
+ return;
- // oit->getUri() includes a host address as well as URI.
- // We should split these to each other and only use the host address to create
- // a child resource's URI. Note that the collection resource and its child
- // resource are located in same host.
- newAction->target = getHostFromURI(oit->getUri()) + uri;
+ if (resource)
+ {
+ // In this nest, we create a new action set of which name is the configuration name.
+ // Required information consists of a host address, URI, attribute key, and
+ // attribute value.
+ ActionSet *newActionSet = new ActionSet();
+ newActionSet->actionsetName = conf;
- Capability *newCapability = new Capability();
- newCapability->capability = attr;
- newCapability->status = getUpdateVal(conf);
+ for (auto oit = children.begin(); oit != children.end(); ++oit)
+ {
+ Action *newAction = new Action();
- newAction->listOfCapability.push_back(newCapability);
- newActionSet->listOfAction.push_back(newAction);
- }
+ // oit->getUri() includes a host address as well as URI.
+ // We should split these to each other and only use the host address to create
+ // a child resource's URI. Note that the collection resource and its child
+ // resource are located in same host.
+ newAction->target = getHostFromURI(oit->getUri()) + uri;
- // Request to create a new action set by using the above actionSet
- g_groupmanager->addActionSet(resource, newActionSet,
- std::function<
- void(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode) >(
- std::bind(&ThingsConfiguration::onCreateActionSet, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, conf)));
+ Capability *newCapability = new Capability();
+ newCapability->capability = attr;
+ newCapability->status = getUpdateVal(conf);
- free(newActionSet);
+ newAction->listOfCapability.push_back(newCapability);
+ newActionSet->listOfAction.push_back(newAction);
}
- }
- else
- {
- std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
+ // Request to create a new action set by using the above actionSet
+ g_groupmanager->addActionSet(resource, newActionSet,
+ std::function<
+ void(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode) >(
+ std::bind(&ThingsConfiguration::onCreateActionSet, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, conf)));
+
+ free(newActionSet);
}
}
void ThingsConfiguration::onGetChildInfoForGet(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, std::string conf)
{
- if (eCode == SUCCESS_RESPONSE)
+ if (eCode != OC_STACK_OK)
{
- std::cout << "GET request was successful" << std::endl;
- std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+ std::cout << "onGet Response error: " << eCode << std::endl;
+ getCallback(conf)(headerOptions, rep, eCode);
+ return ;
+ }
- std::shared_ptr< OCResource > resource, tempResource;
- std::vector < std::shared_ptr< OCResource > > p_resources;
- std::vector < std::string > m_if;
- std::string uri = getUriByConfigurationName(conf);
+ std::cout << "GET request was successful" << std::endl;
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
- if (uri == "")
- return;
+ std::shared_ptr< OCResource > resource, tempResource;
+ std::vector < std::shared_ptr< OCResource > > p_resources;
+ std::vector < std::string > m_if;
+ std::string uri = getUriByConfigurationName(conf);
- if (uri == "/oic/con" || uri == "/factoryset" || uri == "/factoryset/oic/con")
- m_if.push_back(BATCH_INTERFACE);
- else
- m_if.push_back(DEFAULT_INTERFACE);
+ if (uri == "")
+ return;
- 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 (uri == "/oic/con" || uri == "/factoryset" || uri == "/factoryset/oic/con")
+ m_if.push_back(BATCH_INTERFACE);
+ else
+ m_if.push_back(DEFAULT_INTERFACE);
- // Using a host address and child URIs, we can dynamically create resource objects.
- // Note that the child resources have not found before, we have no resource objects.
- // For this reason, we create the resource objects.
+ 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;
- std::string host = getHostFromURI(oit->getUri());
- tempResource = OCPlatform::constructResourceObject(host, uri, true,
- oit->getResourceTypes(), m_if);
+ // Using a host address and child URIs, we can dynamically create resource objects.
+ // Note that the child resources have not found before, we have no resource objects.
+ // For this reason, we create the resource objects.
- p_resources.push_back(tempResource);
- }
+ std::string host = getHostFromURI(oit->getUri());
+ tempResource = OCPlatform::constructResourceObject(host, uri, true,
+ oit->getResourceTypes(), m_if);
- // Send GET messages to the child resources in turn.
- for (unsigned int i = 0; i < p_resources.size(); ++i)
+ p_resources.push_back(tempResource);
+ }
+
+ // Send GET messages to the child resources in turn.
+ for (unsigned int i = 0; i < p_resources.size(); ++i)
+ {
+ resource = p_resources.at(i);
+ if (resource)
{
- resource = p_resources.at(i);
- if (resource)
+ try
{
- try
+ if (isSimpleResource(resource))
{
- 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)
+ else
{
- std::cout << e.reason() << std::endl;
+ QueryParamsMap test;
+ resource->get(resource->getResourceTypes().at(0), BATCH_INTERFACE, test,
+ getCallback(conf));
}
-
}
+ catch (OCException& e)
+ {
+ std::cout << e.reason() << std::endl;
+ }
+
}
}
- else
- {
- std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
- }
}
void ThingsConfiguration::onCreateActionSet(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, std::string conf)
{
- if (eCode == SUCCESS_RESPONSE)
+ if (eCode != OC_STACK_OK)
{
- std::cout << "PUT request was successful" << std::endl;
-
- std::shared_ptr < OCResource > resource = getResource(conf);
- if (resource)
- {
- // Now, it is time to execute the action set.
- g_groupmanager->executeActionSet(resource, conf,
- std::function<
- void(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode) >(
- std::bind(&ThingsConfiguration::onExecuteForGroupAction, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, conf)));
- }
+ std::cout << "onPut Response error: " << eCode << std::endl;
+ getCallback(conf)(headerOptions, rep, eCode);
+ return ;
}
- else
+
+ std::cout << "PUT request was successful" << std::endl;
+
+ std::shared_ptr < OCResource > resource = getResource(conf);
+ if (resource)
{
- std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
+ // Now, it is time to execute the action set.
+ g_groupmanager->executeActionSet(resource, conf,
+ std::function<
+ void(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode) >(
+ std::bind(&ThingsConfiguration::onExecuteForGroupAction, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, conf)));
}
}
void ThingsConfiguration::onExecuteForGroupAction(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, std::string conf)
{
- if (eCode == SUCCESS_RESPONSE)
- {
- std::cout << "PUT request was successful" << std::endl;
-
- getCallback(conf)(headerOptions, rep, eCode);
- }
- else
+ if (eCode != OC_STACK_OK)
{
std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
+ getCallback(conf)(headerOptions, rep, eCode);
+ return ;
}
+
+ std::cout << "PUT request was successful" << std::endl;
+
+ getCallback(conf)(headerOptions, rep, eCode);
}
bool ThingsConfiguration::isSimpleResource(std::shared_ptr< OCResource > resource)
void ThingsConfiguration::onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode, std::string conf)
{
- if (eCode == SUCCESS_RESPONSE)
+ if (eCode != OC_STACK_OK)
{
- std::cout << "Get request was successful" << std::endl;
-
+ std::cout << "onGet Response error: " << eCode << std::endl;
getCallback(conf)(headerOptions, rep, eCode);
+ return ;
}
- else
- {
- std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
- }
+
+ std::cout << "Get request was successful" << std::endl;
+
+ getCallback(conf)(headerOptions, rep, eCode);
}
void ThingsConfiguration::onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode, std::string conf)
{
- if (eCode == SUCCESS_RESPONSE)
- {
- std::cout << "PUT request was successful" << std::endl;
-
- // Callback
- getCallback(conf)(headerOptions, rep, eCode);
- }
- else
+ if (eCode != OC_STACK_OK)
{
std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
+ getCallback(conf)(headerOptions, rep, eCode);
+ return;
}
+
+ std::cout << "PUT request was successful" << std::endl;
+
+ getCallback(conf)(headerOptions, rep, eCode);
}
OCStackResult ThingsConfiguration::updateConfigurations(std::shared_ptr< OCResource > resource,
void ThingsConfiguration::onGetBootstrapInformation(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode)
{
- if (eCode == SUCCESS_RESPONSE)
+ if (eCode != OC_STACK_OK)
{
+ std::cout << "onGET Response error: " << eCode << std::endl;
g_bootstrapCallback(headerOptions, rep, eCode);
+ return;
}
- else
- {
- std::cout << "onGET Response error: " << eCode << std::endl;
- std::exit(-1);
- }
+ g_bootstrapCallback(headerOptions, rep, eCode);
}
void ThingsConfiguration::onFoundBootstrapServer(
namespace OIC
{
- const int SUCCESS_RESPONSE = 0;
-
std::map< std::string, DiagnosticsRequestEntry > diagnosticsRequestTable;
ThingsDiagnostics* ThingsDiagnostics::thingsDiagnosticsInstance = NULL;
void ThingsDiagnostics::onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, std::string diag)
{
- if (eCode == SUCCESS_RESPONSE)
+ if (eCode != OC_STACK_OK)
{
- std::cout << "GET request was successful" << std::endl;
+ std::cout << "onGet Response error: " << eCode << std::endl;
+ getCallback(diag)(headerOptions, rep, eCode);
+ return ;
+ }
- std::cout << "\tResource URI: " << rep.getUri() << std::endl;
+ std::cout << "GET request was successful" << 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;
- }
+ std::cout << "\tResource URI: " << rep.getUri() << std::endl;
- // Get information by using diagnostics name(diag)
- std::shared_ptr < OCResource > resource = getResource(diag);
- std::string actionstring = diag;
- std::string uri = getUriByDiagnosticsName(diag);
- std::string attr = getAttributeByDiagnosticsName(diag);
+ 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;
+ }
+
+ // Get information by using diagnostics name(diag)
+ std::shared_ptr < OCResource > resource = getResource(diag);
+ std::string actionstring = diag;
+ std::string uri = getUriByDiagnosticsName(diag);
+ std::string attr = getAttributeByDiagnosticsName(diag);
+
+ if (uri == "")
+ return;
- if (uri == "")
- return;
+ if (resource)
+ {
+ // In this nest, we create a new action set of which name is the dignostics name.
+ // Required information consists of a host address, URI, attribute key, and
+ // attribute value.
+ ActionSet *newActionSet = new ActionSet();
+ newActionSet->actionsetName = diag;
- if (resource)
+ for (auto oit = children.begin(); oit != children.end(); ++oit)
{
- // In this nest, we create a new action set of which name is the dignostics name.
- // Required information consists of a host address, URI, attribute key, and
- // attribute value.
- ActionSet *newActionSet = new ActionSet();
- newActionSet->actionsetName = diag;
-
- for (auto oit = children.begin(); oit != children.end(); ++oit)
- {
- Action *newAction = new Action();
-
- // oit->getUri() includes a host address as well as URI.
- // We should split these to each other and only use the host address to create
- // a child resource's URI. Note that the collection resource and its child
- // resource are located in same host.
- newAction->target = getHostFromURI(oit->getUri()) + uri;
-
- Capability *newCapability = new Capability();
- newCapability->capability = attr;
- newCapability->status = getUpdateVal(diag);
-
- newAction->listOfCapability.push_back(newCapability);
- newActionSet->listOfAction.push_back(newAction);
- }
-
- // Request to create a new action set by using the above actionSet
- g_groupmanager->addActionSet(resource, newActionSet,
- std::function<
- void(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode) >(
- std::bind(&ThingsDiagnostics::onCreateActionSet, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, diag)));
-
- free(newActionSet);
+ Action *newAction = new Action();
+
+ // oit->getUri() includes a host address as well as URI.
+ // We should split these to each other and only use the host address to create
+ // a child resource's URI. Note that the collection resource and its child
+ // resource are located in same host.
+ newAction->target = getHostFromURI(oit->getUri()) + uri;
+ Capability *newCapability = new Capability();
+ newCapability->capability = attr;
+ newCapability->status = getUpdateVal(diag);
+
+ newAction->listOfCapability.push_back(newCapability);
+ newActionSet->listOfAction.push_back(newAction);
}
- }
- else
- {
- std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
+ // Request to create a new action set by using the above actionSet
+ g_groupmanager->addActionSet(resource, newActionSet,
+ std::function<
+ void(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode) >(
+ std::bind(&ThingsDiagnostics::onCreateActionSet, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, diag)));
+
+ free(newActionSet);
+
}
}
void ThingsDiagnostics::onCreateActionSet(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, std::string diag)
{
- if (eCode == SUCCESS_RESPONSE)
+ if (eCode != OC_STACK_OK)
{
- std::cout << "PUT request was successful" << std::endl;
-
- std::shared_ptr < OCResource > resource = getResource(diag);
- if (resource)
- {
- // Now, it is time to execute the action set.
- g_groupmanager->executeActionSet(resource, diag,
- std::function<
- void(const HeaderOptions& headerOptions,
- const OCRepresentation& rep, const int eCode) >(
- std::bind(&ThingsDiagnostics::onExecuteForGroupAction, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, diag)));
- }
+ std::cout << "onPut Response error: " << eCode << std::endl;
+ getCallback(diag)(headerOptions, rep, eCode);
+ return ;
}
- else
+
+ std::cout << "PUT request was successful" << std::endl;
+
+ std::shared_ptr < OCResource > resource = getResource(diag);
+ if (resource)
{
- std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
+ // Now, it is time to execute the action set.
+ g_groupmanager->executeActionSet(resource, diag,
+ std::function<
+ void(const HeaderOptions& headerOptions,
+ const OCRepresentation& rep, const int eCode) >(
+ std::bind(&ThingsDiagnostics::onExecuteForGroupAction, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, diag)));
}
}
void ThingsDiagnostics::onExecuteForGroupAction(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, std::string diag)
{
- if (eCode == SUCCESS_RESPONSE)
- {
- std::cout << "PUT request was successful" << std::endl;
-
- getCallback(diag)(headerOptions, rep, eCode);
- }
- else
+ if (eCode != OC_STACK_OK)
{
std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
+ getCallback(diag)(headerOptions, rep, eCode);
+ return ;
}
+
+ std::cout << "PUT request was successful" << std::endl;
+
+ getCallback(diag)(headerOptions, rep, eCode);
}
void ThingsDiagnostics::onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode, std::string diag)
{
- if (eCode == SUCCESS_RESPONSE)
- {
- std::cout << "PUT request was successful" << std::endl;
-
- getCallback(diag)(headerOptions, rep, eCode);
- }
- else
+ if (eCode != OC_STACK_OK)
{
std::cout << "onPut Response error: " << eCode << std::endl;
- std::exit(-1);
+ getCallback(diag)(headerOptions, rep, eCode);
+ return ;
}
+
+ std::cout << "PUT request was successful" << std::endl;
+
+ getCallback(diag)(headerOptions, rep, eCode);
+
}
bool ThingsDiagnostics::isSimpleResource(std::shared_ptr< OCResource > resource)