1. Fix for SVACE reported issues.
2. Fix for Klocwork reported issues.
3. Fix the resource creation issue when "rt" property is having null value.
4. Added to code to check the uniqueness property of array for primitive types int,
double, boolean and string.
Change-Id: Ib869361f0ffa1dac5d3f7b36ebf76754661e2a7f
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5369
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
java_headers.append(os.path.join(java_headers[0], 'solaris'))
simulator_env.AppendUnique(CPPPATH = java_headers)
+simulator_env.Append( RPATH = env.Literal('\\$$ORIGIN'))
+
simulator_env.AppendUnique(CPPPATH = ['../../extlibs/cjson'])
simulator_env.PrependUnique(LIBS = ['octbstack', 'oc', 'RamlParser'])
simulator_env.AppendUnique(LIBS = ['pthread'])
int index = 1;
std::vector<std::string> ids;
- for (auto & resourceEntry : m_resList)
+ for (auto &resourceEntry : m_resList)
{
std::cout << index++ << ": " << (resourceEntry.second)->getURI() << "[" <<
(resourceEntry.second)->getHost() << "]" << std::endl;
std::cout << "Host: " << resource->getHost().c_str() << std::endl;
std::cout << "ID: " << resource->getID().c_str() << std::endl;
std::cout << "Resource Types: ";
- for (auto & type : resource->getResourceTypes())
+ for (auto &type : resource->getResourceTypes())
std::cout << type << " ";
std::cout << "\nInterface Types: ";
- for (auto & type : resource->getInterface())
+ for (auto &type : resource->getInterface())
std::cout << type << " ";
std::cout << std::boolalpha << "\nisObservable : " << resource->isObservable()
- << std::noboolalpha << std::endl;
+ << std::noboolalpha << std::endl;
std::cout << "#############################" << std::endl;
}
// callback implementaion
SimulatorRemoteResource::ObserveNotificationCallback callback =
- [](const std::string &uid, SimulatorResult result,
- const SimulatorResourceModel &rep, int seq)
+ [](const std::string & uid, SimulatorResult result,
+ const SimulatorResourceModel & rep, int seq)
{
std::cout << "\nObserve notification received ###[errorcode: " << result <<
- " seq: " << seq << "UID: " << uid << "]" << std::endl;
+ " seq: " << seq << "UID: " << uid << "]" << std::endl;
std::cout << "Representation is: " << std::endl;
std::cout << rep.asString() << std::endl;
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
// callback implementaion
SimulatorRemoteResource::ResponseCallback callback =
- [](const std::string &uid, SimulatorResult result, const SimulatorResourceModel &rep)
+ [](const std::string & uid, SimulatorResult result, const SimulatorResourceModel & rep)
{
std::cout << "\nGET Response received ### [errorcode: " << result << "]"
- << std::endl;
+ << std::endl;
std::cout << "UID is: " << uid << std::endl;
std::cout << "Representation is: " << std::endl;
std::cout << rep.asString() << std::endl;
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
// callback implementaion
SimulatorRemoteResource::ResponseCallback callback =
- [](const std::string &uid, SimulatorResult result, const SimulatorResourceModel &rep)
+ [](const std::string & uid, SimulatorResult result, const SimulatorResourceModel & rep)
{
std::cout << "\nPUT Response received ![errorcode: " << result << "]"
- << std::endl;
+ << std::endl;
std::cout << "UID is: " << uid << std::endl;
std::cout << "Representation is: " << std::endl;
std::cout << rep.asString() << std::endl;
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
// callback implementaion
SimulatorRemoteResource::ResponseCallback callback =
- [](const std::string &uid, SimulatorResult result, const SimulatorResourceModel &rep)
+ [](const std::string & uid, SimulatorResult result, const SimulatorResourceModel & rep)
{
std::cout << "\nPOST Response received ![errorcode: " << result << "]"
- << std::endl;
+ << std::endl;
std::cout << "UID is: " << uid << std::endl;
std::cout << "Representation is: " << std::endl;
std::cout << rep.asString() << std::endl;
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
if (!resource) return;
SimulatorRemoteResource::AutoRequestGenerationCallback callback =
- [] (const std::string &uid, int sessionId, OperationState state)
+ [] (const std::string & uid, int sessionId, OperationState state)
{
std::cout << "\nResource verification status received ![id: " << sessionId <<
- " State: " << getOperationStateString(state) << " UID: " << uid << "]" <<
- std::endl;
+ " State: " << getOperationStateString(state) << " UID: " << uid << "]" <<
+ std::endl;
};
try
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
if (!resource) return;
SimulatorRemoteResource::AutoRequestGenerationCallback callback =
- [] (const std::string &uid, int sessionId, OperationState state)
+ [] (const std::string & uid, int sessionId, OperationState state)
{
std::cout << "\nResource verification status received ![id: " << sessionId <<
- " State: " << getOperationStateString(state) << " UID: " << uid << "]" <<
- std::endl;
+ " State: " << getOperationStateString(state) << " UID: " << uid << "]" <<
+ std::endl;
};
try
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
if (!resource) return;
SimulatorRemoteResource::AutoRequestGenerationCallback callback =
- [] (const std::string &uid, int sessionId, OperationState state)
+ [] (const std::string & uid, int sessionId, OperationState state)
{
std::cout << "\nResource verification status received ![id: " << sessionId <<
- " State: " << getOperationStateString(state) << " UID: " << uid << "]"
- << std::endl;
+ " State: " << getOperationStateString(state) << " UID: " << uid << "]"
+ << std::endl;
};
try
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
try
{
SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(),
- std::bind([](const std::string & host, DeviceInfo & deviceInfo)
+ std::bind([](const std::string & host, DeviceInfo & deviceInfo)
{
std::cout << "###Device Information received...." << std::endl;
std::ostringstream out;
try
{
SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(),
- std::bind([](const std::string & host, PlatformInfo & platformInfo)
+ std::bind([](const std::string & host, PlatformInfo & platformInfo)
{
std::cout << "###Platform Information received...." << std::endl;
std::ostringstream out;
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code()
- << " Detail: " << e.what() << "]" << std::endl;
+ << " Detail: " << e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code()
- << " Detail: " << e.what() << "]" << std::endl;
+ << " Detail: " << e.what() << "]" << std::endl;
}
}
}
int index = 1;
- for (auto & resource : g_singleResources)
+ for (auto &resource : g_singleResources)
{
std::cout << index++ << ": " << resource->getURI().c_str() << std::endl;
}
{
// Resource model change callback
SimulatorResource::ResourceModelUpdateCallback modelChangeCB =
- [](const std::string &uri, const SimulatorResourceModel &resModel)
+ [](const std::string & uri, const SimulatorResourceModel & resModel)
{
std::cout << "[callback] Resource model is changed URI: " << uri.c_str() << std::endl;
std::cout << "#### Modified attributes are ####" << std::endl;
// Observer added/removed callback
SimulatorResource::ObserverCallback observerCB =
- [] (const std::string &uri, ObservationStatus state, const ObserverInfo &observerInfo)
+ [] (const std::string & uri, ObservationStatus state, const ObserverInfo & observerInfo)
{
std::cout << "[callback] Observer notification received..." << uri << std::endl;
out << "ID: " << (int) observerInfo.id << std::endl;
out << " [address: " << observerInfo.address << " port: " << observerInfo.port
<< "]" << std::endl;
- out << "State: " << ((state == ObservationStatus::REGISTER)? "REGISTER" : "UNREGISTER") << std::endl;
+ out << "State: " << ((state == ObservationStatus::REGISTER) ? "REGISTER" : "UNREGISTER") <<
+ std::endl;
std::cout << out.str();
};
// Get the RAML file path from user
std::string configPath;
std::cout << "Enter RAML path: ";
- std::cin>>configPath;
+ std::cin >> configPath;
SimulatorResourceSP resource =
SimulatorManager::getInstance()->createResource(configPath);
void automateResourceUpdate()
{
SimulatorSingleResource::AutoUpdateCompleteCallback callback =
- [](const std::string &uri, const int id) {
- std::cout << "Update automation is completed [URI: " << uri
- << " AutomationID: " << id << "] ###" << std::endl;
- };
+ [](const std::string & uri, const int id)
+ {
+ std::cout << "Update automation is completed [URI: " << uri
+ << " AutomationID: " << id << "] ###" << std::endl;
+ };
int index = selectResource();
if (-1 == index)
void automateAttributeUpdate()
{
SimulatorSingleResource::AutoUpdateCompleteCallback callback =
- [](const std::string &uri, const int id) {
- std::cout << "Update automation is completed [URI: " << uri
- << " AutomationID: " << id << "] ###" << std::endl;
- };
+ [](const std::string & uri, const int id)
+ {
+ std::cout << "Update automation is completed [URI: " << uri
+ << " AutomationID: " << id << "] ###" << std::endl;
+ };
int index = selectResource();
if (-1 == index)
std::map<std::string, SimulatorResourceAttribute> attributes =
resource->getAttributes();
int size = 0;
- for (auto & attributeEntry : attributes)
+ for (auto &attributeEntry : attributes)
{
std::cout << ++size << ": " << attributeEntry.first << std::endl;
}
int choice = -1;
std::cout << "Select the attribute which you want to automate for updation: " <<
- std::endl;
+ std::endl;
std::cin >> choice;
if (choice < 0 || choice > size)
{
int count = 0;
std::string attributeName;
- for (auto & attributeEntry : attributes)
+ for (auto &attributeEntry : attributes)
{
if (count == choice - 1)
{
type = AutoUpdateType::REPEAT;
std::cout << "Requesting attribute automation for " << attributeName <<
- std::endl;
+ std::endl;
try
{
return;
}
- for (auto & id : ids)
+ for (auto &id : ids)
{
std::cout << id << " ";
resource->stopUpdation(id);
std::vector<ObserverInfo> observersList = resource->getObservers();
std::cout << "##### Number of Observers [" << observersList.size() << "]" << std::endl;
- for (auto & observerInfo : observersList)
+ for (auto &observerInfo : observersList)
{
std::cout << " ID : " << (int) observerInfo.id << " [address: " <<
observerInfo.address << " port: " << observerInfo.port << "]" << std::endl;
void setDeviceInfo()
{
- SimulatorManager::getInstance()->setDeviceInfo("IoTivity Simulator Linux Sample");
- std::cout << "Setting Device Info is successful" << std::endl;
+ try
+ {
+ SimulatorManager::getInstance()->setDeviceInfo("IoTivity Simulator Linux Sample");
+ std::cout << "Setting Device Info is successful" << std::endl;
+ }
+ catch (InvalidArgsException &e)
+ {
+ std::cout << "InvalidArgsException occured [code : " << e.code() << " Details: "
+ << e.what() << "]" << std::endl;
+ }
+ catch (SimulatorException &e)
+ {
+ std::cout << "SimulatorException occured [code : " << e.code() << " Details: "
+ << e.what() << "]" << std::endl;
+ }
}
void setPlatformInfo()
pInfo.setSystemTime("2015-09-10T11:10:30Z");
pInfo.setDateOfManfacture("2015-09-10T11:10:30Z");
- SimulatorManager::getInstance()->setPlatformInfo(pInfo);
- std::cout << "Setting Platform Info is successful" << std::endl;
+ try
+ {
+ SimulatorManager::getInstance()->setPlatformInfo(pInfo);
+ std::cout << "Setting Platform Info is successful" << std::endl;
+ }
+ catch (SimulatorException &e)
+ {
+ std::cout << "SimulatorException occured [code : " << e.code() << " Details: "
+ << e.what() << "]" << std::endl;
+ }
}
void addInterface()
{
+
int index = selectResource();
if (-1 == index)
return;
class SimulatorRequestModel
{
public:
- SimulatorRequestModel() = default;
+ SimulatorRequestModel();
SimulatorRequestModel(RequestType type);
RequestType getType() const;
auto x = m_attributes.find(name);
if (x != m_attributes.end())
{
- val = boost::get<T>(x->second);
+ try
+ {
+ val = boost::get<T>(x->second);
+ }
+ catch (boost::bad_get &e)
+ {
+ return val;
+ }
}
return val;
}
requestInfo.type = RequestType::RQ_TYPE_GET;
requestInfo.queryParams = queryParams;
- SIM_LOG(ILogger::INFO, "Sending GET request..." << "\n**Payload Details**\n" << getRequestString(
- queryParams));
+ SIM_LOG(ILogger::INFO, "Sending GET request." << "\n" << getRequestString(queryParams))
OCStackResult ocResult = m_ocResource->get(queryParams,
std::bind(&GETRequestSender::onResponseReceived, this, std::placeholders::_1,
const OC::OCRepresentation &rep, const int errorCode, RequestInfo &requestInfo,
ResponseCallback callback)
{
- SIM_LOG(ILogger::INFO, "Response received for GET..." << "\n" << getPayloadString(rep));
+ SIM_LOG(ILogger::INFO, "Response received for GET." << "\n" << getPayloadString(rep));
SimulatorResourceModel resourceModel = SimulatorResourceModel::build(rep);
callback(static_cast<SimulatorResult>(errorCode), resourceModel, requestInfo);
}
requestInfo.queryParams = queryParams;
requestInfo.payLoad = representation;
- SIM_LOG(ILogger::INFO, "Sending PUT request..." << "\n**Payload Details**\n" << getRequestString(
- queryParams));
+ OC::OCRepresentation ocRep = representation.asOCRepresentation();
+ SIM_LOG(ILogger::INFO, "Sending PUT request." << "\n**Payload Details**\n" << getRequestString(
+ queryParams, ocRep));
- OCStackResult ocResult = m_ocResource->put(representation.asOCRepresentation(), queryParams,
+ OCStackResult ocResult = m_ocResource->put(ocRep, queryParams,
std::bind(&PUTRequestSender::onResponseReceived, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, requestInfo, callback));
return static_cast<SimulatorResult>(ocResult);
const OC::OCRepresentation &rep, const int errorCode, RequestInfo &requestInfo,
ResponseCallback callback)
{
- SIM_LOG(ILogger::INFO, "Response received for PUT..." << "\n" << getPayloadString(rep));
+ SIM_LOG(ILogger::INFO, "Response received for PUT." << "\n" << getPayloadString(rep));
SimulatorResourceModel resourceModel = SimulatorResourceModel::build(rep);
callback(static_cast<SimulatorResult>(errorCode), resourceModel, requestInfo);
}
requestInfo.queryParams = queryParams;
requestInfo.payLoad = representation;
- SIM_LOG(ILogger::INFO, "Sending POST request..." << "\n**Payload Details**\n" << getRequestString(
- queryParams));
+ OC::OCRepresentation ocRep = representation.asOCRepresentation();
+ SIM_LOG(ILogger::INFO, "Sending POST request." << "\n**Payload Details**\n" << getRequestString(
+ queryParams, ocRep));
- OCStackResult ocResult = m_ocResource->post(representation.asOCRepresentation(), queryParams,
+ OCStackResult ocResult = m_ocResource->post(ocRep, queryParams,
std::bind(&POSTRequestSender::onResponseReceived, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, requestInfo, callback));
return static_cast<SimulatorResult>(ocResult);
const OC::OCRepresentation &rep, const int errorCode, RequestInfo &requestInfo,
ResponseCallback callback)
{
- SIM_LOG(ILogger::INFO, "Response received for POST..." << "\n" << getPayloadString(rep));
+ SIM_LOG(ILogger::INFO, "Response received for POST." << "\n" << getPayloadString(rep));
SimulatorResourceModel resourceModel = SimulatorResourceModel::build(rep);
callback(static_cast<SimulatorResult>(errorCode), resourceModel, requestInfo);
}
if (m_observeState)
{
OC_LOG(ERROR, TAG, "Resource is already being observed!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Resource is already being observed!")
+
throw SimulatorException(SIMULATOR_ERROR, "Resource is already being observed!");
}
[](const OC::HeaderOptions & headerOptions, const OC::OCRepresentation & ocRep,
const int errorCode, const int sqNum, std::string id, ObserveNotificationCallback callback)
{
- SIM_LOG(ILogger::INFO, "Observe response received..." << "\n" << getPayloadString(ocRep));
+ SIM_LOG(ILogger::INFO, "Response received for OBSERVE request."
+ << "\n" << getPayloadString(ocRep))
SimulatorResourceModel resourceModel = SimulatorResourceModel::build(ocRep);
callback(id, static_cast<SimulatorResult>(errorCode), resourceModel, sqNum);
if (OC_STACK_OK != ocResult)
throw SimulatorException(static_cast<SimulatorResult>(ocResult), OC::OCException::reason(ocResult));
- SIM_LOG(ILogger::INFO, "OBSERVE request sent");
+ SIM_LOG(ILogger::INFO, "[URI: " << getURI() << "] Sent OBSERVE request.")
}
catch (OC::OCException &e)
{
if (OC_STACK_OK != ocResult)
{
OC_LOG(ERROR, TAG, "Cancelling observe failed!");
+ SIM_LOG(ILogger::INFO, "[URI: " << getURI() << "] Sending OBSERVE cancel request failed!")
+
throw SimulatorException(static_cast<SimulatorResult>(ocResult),
OC::OCException::reason(ocResult));
}
- SIM_LOG(ILogger::INFO, "OBSERVE CANCEL request sent");
+ SIM_LOG(ILogger::INFO, "[URI: " << getURI() << "] Sent OBSERVE cancel request.")
}
catch (OC::OCException &e)
{
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send GET request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send GET request!")
+
throw SimulatorException(result, "Failed to send GET request!");
}
}
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send GET request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send GET request!")
+
throw SimulatorException(result, "Failed to send GET request!");
}
}
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send GET request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send GET request!")
+
throw SimulatorException(result, "Failed to send GET request!");
}
}
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send PUT request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send PUT request!")
+
throw SimulatorException(result, "Failed to send PUT request!");
}
}
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send PUT request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send PUT request!")
+
throw SimulatorException(result, "Failed to send PUT request!");
}
}
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send PUT request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send PUT request!")
+
throw SimulatorException(result, "Failed to send PUT request!");
}
}
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send POST request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send POST request!")
+
throw SimulatorException(result, "Failed to send POST request!");
}
}
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send POST request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send POST request!")
+
throw SimulatorException(result, "Failed to send POST request!");
}
}
if (SIMULATOR_OK != result)
{
OC_LOG(ERROR, TAG, "Failed to send POST request!");
+ SIM_LOG(ILogger::ERROR, "[URI: " << getURI() << "] Failed to send POST request!")
+
throw SimulatorException(result, "Failed to send POST request!");
}
}
******************************************************************/
#include "simulator_request_model.h"
+SimulatorRequestModel::SimulatorRequestModel()
+ : m_type(RequestType::RQ_TYPE_UNKNOWN),
+ m_reqBodySchema(nullptr) {}
+
SimulatorRequestModel::SimulatorRequestModel(RequestType type)
: m_type(type) {}
{
updateAttributeInModel(m_index);
resModel = m_resModel;
- return true;
}
else
{
}
resModel = m_resModel;
- return true;
}
- return false;
+ return true;
}
void AttributeCombinationGen::updateAttributeInModel(int index)
std::shared_ptr<IntegerProperty> intProperty = property->asInteger();
if (intProperty->hasRange())
{
- int min, max;
+ int min = 0;
+ int max = 0;
intProperty->getRange(min, max);
return std::unique_ptr<AttributeValueGen>(
new RangeValueGen<int>(min, max));
std::shared_ptr<DoubleProperty> doubleProperty = property->asDouble();
if (doubleProperty->hasRange())
{
- double min, max;
+ double min = 0.0;
+ double max = 0.0;
doubleProperty->getRange(min, max);
return std::unique_ptr<AttributeValueGen>(
new RangeValueGen<double>(min, max));
TYPE m_cur;
public:
- RangeValueGen(TYPE min, TYPE max) : m_min(min), m_max(max), m_cur(m_min) {}
+ RangeValueGen(TYPE min, TYPE max) : m_min(min), m_max(max), m_cur(min) {}
bool hasNext()
{
std::shared_ptr<IntegerProperty> elementProperty =
buildIntegerAttribute(elementAttribute);
- if (arrayAttribute.isDefaultValue())
- {
- auto defaultValue = boost::get<int>(arrayAttribute.getValue());
- elementProperty->setDefaultValue(defaultValue);
- }
-
+ setArrayProperties(property, arrayProperty);
arrayProperty->setElementProperty(elementProperty);
}
break;
std::shared_ptr<DoubleProperty> elementProperty =
buildDoubleAttribute(elementAttribute);
- if (arrayAttribute.isDefaultValue())
- {
- auto defaultValue = boost::get<double>(arrayAttribute.getValue());
- elementProperty->setDefaultValue(defaultValue);
- }
-
+ setArrayProperties(property, arrayProperty);
arrayProperty->setElementProperty(elementProperty);
}
break;
std::shared_ptr<BooleanProperty> elementProperty =
buildBooleanAttribute(elementAttribute);
- if (arrayAttribute.isDefaultValue())
- {
- auto defaultValue = boost::get<bool>(arrayAttribute.getValue());
- elementProperty->setDefaultValue(defaultValue);
- }
-
+ setArrayProperties(property, arrayProperty);
arrayProperty->setElementProperty(elementProperty);
}
break;
std::shared_ptr<StringProperty> elementProperty =
buildStringAttribute(elementAttribute);
- if (arrayAttribute.isDefaultValue())
- {
- auto defaultValue = boost::get<std::string>(arrayAttribute.getValue());
- elementProperty->setDefaultValue(defaultValue);
- }
-
+ setArrayProperties(property, arrayProperty);
arrayProperty->setElementProperty(elementProperty);
}
break;
}
std::shared_ptr<ArrayProperty> arrayProperty = ArrayProperty::build();
+ setArrayProperties(property, arrayProperty);
arrayProperty->setElementProperty(modelProperty);
return arrayProperty;
}
return modelProperty;
+}
+
+void ResourceModelSchemaBuilder::setArrayProperties(
+ const std::shared_ptr<RAML::Properties> &property,
+ const std::shared_ptr<ArrayProperty> &arrayProperty)
+{
+ for (auto &valueProperty : property->getValueProperties())
+ {
+ if (RAML::ValueProperty::Type::ARRAY == valueProperty->type())
+ {
+ int minItems = 0;
+ int maxItems = 0;
+ bool unique = false;
+ bool additionalItems = false;
+
+ valueProperty->valueArray(minItems, maxItems, unique, additionalItems);
+ arrayProperty->setRange(minItems, maxItems);
+ arrayProperty->setUnique(unique);
+ arrayProperty->setVariable(additionalItems);
+ break;
+ }
+ }
}
\ No newline at end of file
std::shared_ptr<ModelProperty> buildModelAttribute(
const std::shared_ptr<RAML::Properties> &property);
+ void setArrayProperties(
+ const std::shared_ptr<RAML::Properties> &property,
+ const std::shared_ptr<ArrayProperty> &arrayProperty);
+
std::shared_ptr<RAML::RequestResponseBody> m_ramlSchema;
};
return arrayValue;
}
+template <typename T, typename=void>
+struct UniquenessChecker
+{
+ static bool get(const std::vector<T> &/*value*/)
+ {
+ return true;
+ }
+};
+
+template <typename T>
+struct UniquenessChecker<T, typename std::enable_if<
+ std::is_same<T, int>::value
+ || std::is_same<T, double>::value
+ || std::is_same<T, bool>::value
+ || std::is_same<T, std::string>::value
+ >::type >
+{
+ static bool get(const std::vector<T> &value)
+ {
+ std::vector<T> valueCopy = value;
+ std::sort(valueCopy.begin(), valueCopy.end());
+ if(valueCopy.end() != std::unique(valueCopy.begin(), valueCopy.end()))
+ return false;
+ return true;
+ }
+};
+
class IntegerValidator : public boost::static_visitor<bool>
{
public:
bool operator ()(const std::vector<T> &value)
{
// Validating length of array
- if (m_property->hasRange())
+ if (!checkLength(value))
{
- if (value.size() < m_property->getMinItems()
- || (value.size() > m_property->getMaxItems() && !m_property->isVariable()))
- {
- return false;
- }
+ return false;
+ }
+
+ // Validate the uniqueness of elements of array
+ if (!checkUniqueness(value))
+ {
+ return false;
}
// Validating elements of array
}
private:
+ template <typename T>
+ bool checkLength(const std::vector<T> &value)
+ {
+ if (m_property->hasRange())
+ {
+ if (value.size() < m_property->getMinItems()
+ || (value.size() > m_property->getMaxItems() && !m_property->isVariable()))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ template <typename T>
+ bool checkUniqueness(const std::vector<T> &value)
+ {
+ if (m_property->isUnique())
+ {
+ return UniquenessChecker<T>::get(value);
+ }
+
+ return true;
+ }
+
std::shared_ptr<ArrayProperty> m_property;
};
IntegerProperty::IntegerProperty(int defaultValue)
: AttributeProperty(AttributeProperty::Type::INTEGER),
m_defaultValue(defaultValue),
+ m_min(0),
+ m_max(0),
m_hasRange(false) {}
std::shared_ptr<IntegerProperty> IntegerProperty::build(int defaultValue)
DoubleProperty::DoubleProperty(double defaultValue)
: AttributeProperty(AttributeProperty::Type::DOUBLE),
m_defaultValue(defaultValue),
+ m_min(0),
+ m_max(0),
m_hasRange(false) {}
std::shared_ptr<DoubleProperty> DoubleProperty::build(double defaultValue)
StringProperty::StringProperty(const std::string &defaultValue)
: AttributeProperty(AttributeProperty::Type::STRING),
m_defaultValue(defaultValue),
+ m_min(0),
+ m_max(0),
m_hasRange(false) {}
std::shared_ptr<StringProperty> StringProperty::build(const std::string &defaultValue)
ArrayProperty::ArrayProperty()
: AttributeProperty(AttributeProperty::Type::ARRAY),
+ m_min(0),
+ m_max(0),
m_isVariableSize(false),
m_isUnique(false),
m_hasRange(false) {}
}
requestString << std::endl;
- requestString << "Payload: No payload";
return requestString.str();
}
if (!m_stopRequested)
{
OC_LOG_V(DEBUG, ATAG, "Attribute:%s automation is completed!", m_attrName.c_str());
- SIM_LOG(ILogger::INFO, "Automation of " << m_attrName << " attribute is completed.");
+ SIM_LOG(ILogger::INFO, "Attribute automation completed [Name: \"" << m_attrName
+ << "\", id: " << m_id <<"].");
+ }
+ else
+ {
+ SIM_LOG(ILogger::INFO, "Attribute automation stopped [Name: \"" << m_attrName
+ << "\", id: " << m_id <<"].");
}
// Notify application through callback
if (!m_stopRequested)
{
OC_LOG_V(DEBUG, ATAG, "Resource update automation complete [id: %d]!", m_id);
- SIM_LOG(ILogger::INFO, "Resource update automation complete [id: " << m_id << "]");
+ SIM_LOG(ILogger::INFO, "Resource automation completed [URI: \"" << m_resource->getURI()
+ << "\", id: " << m_id << "].");
+ }
+ else
+ {
+ SIM_LOG(ILogger::INFO, "Resource automation stopped [URI: \"" << m_resource->getURI()
+ << "\", id: " << m_id <<"].");
}
// Notify application
std::lock_guard<std::mutex> lock(m_lock);
resourceAutomation->start();
- SIM_LOG(ILogger::INFO, "Resource automation successfully started [ id: " << m_id << " ]");
+ SIM_LOG(ILogger::INFO, "Resource automation started [URI: \"" << resource->getURI()
+ << "\", id: " << m_id << "].");
m_resourceUpdationList[m_id] = resourceAutomation;
return m_id++;
std::lock_guard<std::mutex> lock(m_lock);
attributeAutomation->start();
- SIM_LOG(ILogger::INFO, "Automation for " << attrName << " attribute has successfully started [ id: "
- << m_id << " ]");
+ SIM_LOG(ILogger::INFO, "Attribute automation started [Name: \"" << attrName << "\", id: "
+ << m_id << "].");
m_attrUpdationList[m_id] = attributeAutomation;
return m_id++;
#define TAG "SIMULATOR_COLLECTION_RESOURCE"
SimulatorCollectionResourceImpl::SimulatorCollectionResourceImpl()
- : m_resourceHandle(nullptr)
{
m_type = SimulatorResource::Type::COLLECTION_RESOURCE;
m_interfaces.push_back(OC::LINK_INTERFACE);
// Add empty vector of OIC Links
std::vector<SimulatorResourceModel> links;
m_resModel.add("links", links);
+
+ m_resourceHandle = nullptr;
}
bool SimulatorCollectionResourceImpl::isCollection() const
bool SimulatorCollectionResourceImpl::isObservable() const
{
- return (m_property & OC_OBSERVABLE);
+ return ((m_property & OC_OBSERVABLE) == OC_OBSERVABLE);
}
bool SimulatorCollectionResourceImpl::isDiscoverable() const
{
- return (m_property & OC_DISCOVERABLE);
+ return ((m_property & OC_DISCOVERABLE) == OC_DISCOVERABLE);
}
bool SimulatorCollectionResourceImpl::isStarted() const
std::string linkURI = link.get<std::string>("href");
if (linkURI == resource->getURI())
{
- break;
found = true;
+ break;
}
}
std::string resourceURI = ramlResource->getResourceUri();\r
std::string resourceName = ramlResource->getDisplayName();\r
std::string resourceType;\r
+\r
+ // Extracting resource type.\r
if (resourceModel.contains("rt"))\r
{\r
resourceType = resourceModel.get<std::string>("rt");\r
resourceModel.remove("rt");\r
}\r
-\r
- if (resourceModel.contains("resourceType"))\r
+ else if (resourceModel.contains("resourceType"))\r
{\r
resourceType = resourceModel.get<std::string>("resourceType");\r
resourceModel.remove("resourceType");\r
}\r
\r
+ // Construct resource type from uri\r
+ if(resourceType.empty())\r
+ {\r
+ std::ostringstream rtString;\r
+ rtString << "oic.r.";\r
+\r
+ size_t pos = resourceURI.rfind("/");\r
+ if (pos == std::string::npos)\r
+ pos = -1;\r
+\r
+ std::string rtName = resourceURI.substr(pos+1);\r
+ std::transform(rtName.begin(), rtName.end(), rtName.begin(), ::tolower);\r
+ rtString << rtName;\r
+ resourceType = rtString.str();\r
+ }\r
+\r
+ // Extracting interface type.\r
std::vector<std::string> interfaceTypes;\r
if (resourceModel.contains("if"))\r
{\r
{\r
interfaceTypes.push_back(resourceModel.get<std::string>("if"));\r
}\r
- else if(AttributeValueType::STRING == typeInfo.baseType()\r
- && AttributeValueType::VECTOR == typeInfo.type()\r
+ else if(AttributeValueType::VECTOR == typeInfo.type()\r
+ && AttributeValueType::STRING == typeInfo.baseType()\r
&& typeInfo.depth() == 1)\r
{\r
interfaceTypes = resourceModel.get<std::vector<std::string>>("if");\r
+ if (interfaceTypes.size() > 1)\r
+ interfaceTypes.erase(interfaceTypes.begin()+1, interfaceTypes.end());\r
}\r
- else\r
+\r
+ resourceModel.remove("if");\r
+ }\r
+\r
+ for (auto &requestModel : requestModels)\r
+ {\r
+ if (requestModel.second)\r
{\r
- return nullptr;\r
+ addInterfaceFromQueryParameter((requestModel.second)->getQueryParams("if"),\r
+ interfaceTypes);\r
}\r
- resourceModel.remove("if");\r
}\r
\r
+ // Remove properties which are not part of resource representation\r
resourceModel.remove("p");\r
resourceModel.remove("n");\r
resourceModel.remove("id");\r
\r
collectionRes->setName(resourceName);\r
collectionRes->setResourceType(resourceType);\r
- collectionRes->setInterface(interfaceTypes);\r
+ if (interfaceTypes.size() > 0)\r
+ collectionRes->setInterface(interfaceTypes);\r
collectionRes->setURI(ResourceURIFactory::getInstance()->makeUniqueURI(resourceURI));\r
\r
// Set the resource model and its schema to simulated resource\r
\r
singleRes->setName(resourceName);\r
singleRes->setResourceType(resourceType);\r
- singleRes->setInterface(interfaceTypes);\r
+ if (interfaceTypes.size() > 0)\r
+ singleRes->setInterface(interfaceTypes);\r
singleRes->setURI(ResourceURIFactory::getInstance()->makeUniqueURI(resourceURI));\r
\r
// Set the resource model and its schema to simulated resource\r
return simResource;\r
}\r
\r
+void SimulatorResourceFactory::addInterfaceFromQueryParameter(\r
+ std::vector<std::string> queryParamValue, std::vector<std::string> &interfaceTypes)\r
+{\r
+ for (auto &interfaceType : queryParamValue)\r
+ {\r
+ if (interfaceTypes.end() ==\r
+ std::find(interfaceTypes.begin(), interfaceTypes.end(), interfaceType))\r
+ {\r
+ interfaceTypes.push_back(interfaceType);\r
+ }\r
+ }\r
+}\r
+\r
ResourceURIFactory *ResourceURIFactory::getInstance()\r
{\r
static ResourceURIFactory s_instance;\r
std::shared_ptr<SimulatorResource> buildResource(
const std::shared_ptr<RAML::RamlResource> &ramlResource);
+ void addInterfaceFromQueryParameter(
+ std::vector<std::string> queryParamValue, std::vector<std::string> &interfaceTypes);
+
SimulatorResourceFactory() = default;
SimulatorResourceFactory(const SimulatorResourceFactory &) = delete;
SimulatorResourceFactory &operator=(const SimulatorResourceFactory &) = delete;
#define TAG "SIMULATOR_SINGLE_RESOURCE"
SimulatorSingleResourceImpl::SimulatorSingleResourceImpl()
- : m_resourceHandle(nullptr)
{
m_type = SimulatorResource::Type::SINGLE_RESOURCE;
m_interfaces.push_back(OC::DEFAULT_INTERFACE);
m_property = static_cast<OCResourceProperty>(OC_DISCOVERABLE | OC_OBSERVABLE);
m_resModelSchema = SimulatorResourceModelSchema::build();
+
+ // Set resource supports GET, PUT and POST by default
+ m_requestModels["GET"] = nullptr;
+ m_requestModels["POST"] = nullptr;
+ m_requestModels["PUT"] = nullptr;
+
+ m_resourceHandle = nullptr;
}
void SimulatorSingleResourceImpl::setName(const std::string &name)
m_uri = uri;
}
-// TODO: Support adding multiple resource types for a resource
void SimulatorSingleResourceImpl::setResourceType(const std::string &resourceType)
{
VALIDATE_INPUT(resourceType.empty(), "Resource type is empty!")
m_resourceType = resourceType;
}
-// TODO: Assuming baseline is not mandatory to be present always.
void SimulatorSingleResourceImpl::setInterface(const std::string &interfaceType)
{
VALIDATE_INPUT(interfaceType.empty(), "Interface type list is empty!")
m_interfaces = {interfaceType};
}
-// TODO: Assuming baseline is not mandatory to be present always.
void SimulatorSingleResourceImpl::setInterface(const std::vector<std::string> &interfaceTypes)
{
VALIDATE_INPUT(interfaceTypes.empty(), "Interface type list is empty!")
"Resource interface can not be reset when resource is started!");
}
- m_interfaces = interfaceTypes;
- auto lastElement = std::unique(m_interfaces.begin(), m_interfaces.end());
- m_interfaces.erase(lastElement, m_interfaces.end());
+ m_interfaces.clear();
+ for (auto &interfaceType : interfaceTypes)
+ {
+ if (m_interfaces.end() ==
+ std::find(m_interfaces.begin(), m_interfaces.end(), interfaceType))
+ {
+ m_interfaces.push_back(interfaceType);
+ }
+ }
}
void SimulatorSingleResourceImpl::addInterface(const std::string &interfaceType)
if (m_interfaces.end() != std::find(m_interfaces.begin(), m_interfaces.end(), interfaceType))
{
- SIM_LOG(ILogger::ERROR, "Resource already supporting this Interface: " << interfaceType);
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "Resource already supporting this Interface: " << interfaceType)
return;
}
bool SimulatorSingleResourceImpl::isObservable() const
{
- return (m_property & OC_OBSERVABLE);
+ return ((m_property & OC_OBSERVABLE) == OC_OBSERVABLE);
}
bool SimulatorSingleResourceImpl::isDiscoverable() const
{
- return (m_property & OC_DISCOVERABLE);
+ return ((m_property & OC_DISCOVERABLE) == OC_DISCOVERABLE);
}
bool SimulatorSingleResourceImpl::isStarted() const
std::lock_guard<std::recursive_mutex> lock(m_objectLock);
if (m_resourceHandle)
{
- SIM_LOG(ILogger::INFO, "[" << m_name << "] " << "Resource already started!")
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " << "Resource already started!")
return;
}
std::lock_guard<std::recursive_mutex> lock(m_objectLock);
if (!m_resourceHandle)
{
- SIM_LOG(ILogger::INFO, "[" << m_name << "] " << "Resource is not started yet!")
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " << "Resource is not started yet!")
return;
}
return false;
}
+ // Add attribute to resource representation and its schema
std::lock_guard<std::recursive_mutex> modelLock(m_modelLock);
std::lock_guard<std::mutex> schemaLock(m_modelSchemaLock);
- if (!m_resModel.contains(attribute.getName()))
+ if (!m_resModel.add(attribute.getName(), attribute.getValue()))
{
- m_resModel.add(attribute.getName(), attribute.getValue());
- m_resModelSchema->add(attribute.getName(), attribute.getProperty());
- return true;
+ return false;
}
- return false;
+ m_resModelSchema->add(attribute.getName(), attribute.getProperty());
+
+ if (notify && isStarted())
+ {
+ try
+ {
+ notifyAll();
+ }
+ catch (SimulatorException &e)
+ {
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " << "Error when notifying the observers!")
+ }
+ notifyApp();
+ }
+
+ return true;
}
bool SimulatorSingleResourceImpl::updateAttributeValue(
return false;
}
+ // Validate the new value against attribute schema property
+ std::lock_guard<std::mutex> schemaLock(m_modelSchemaLock);
+ auto property = m_resModelSchema->get(attribute.getName());
+ if (!(property->validate(attribute.getValue())))
+ {
+ return false;
+ }
+
+ // Update the attribute value
std::lock_guard<std::recursive_mutex> modelLock(m_modelLock);
- if (m_resModel.update(attribute.getName(), attribute.getValue()))
+ if (!m_resModel.update(attribute.getName(), attribute.getValue()))
{
- if (notify && isStarted())
+ return false;
+ }
+
+ if (notify && isStarted())
+ {
+ try
{
- try
- {
- notifyAll();
- }
- catch (SimulatorException &e)
- {
- SIM_LOG(ILogger::ERROR, "Error when notifying the observers.")
- }
- notifyApp();
+ notifyAll();
}
- return true;
+ catch (SimulatorException &e)
+ {
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " << "Error when notifying the observers!")
+ }
+ notifyApp();
}
- return false;
+ return true;
}
bool SimulatorSingleResourceImpl::removeAttribute(
return false;
}
+ // Remove attribute from resource representation and its schema
std::lock_guard<std::recursive_mutex> modelLock(m_modelLock);
std::lock_guard<std::mutex> schemaLock(m_modelSchemaLock);
- m_resModel.remove(attrName);
+
m_resModelSchema->remove(attrName);
+ if (!m_resModel.remove(attrName))
+ {
+ return false;
+ }
+
+ if (notify && isStarted())
+ {
+ try
+ {
+ notifyAll();
+ }
+ catch (SimulatorException &e)
+ {
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " << "Error when notifying the observers!")
+ }
+ notifyApp();
+ }
return true;
}
}
catch (SimulatorException &e)
{
- SIM_LOG(ILogger::ERROR, "Error when notifying the observers.")
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " << "Error when notifying the observers!")
}
notifyApp();
}
std::lock_guard<std::recursive_mutex> lock(m_objectLock);
ocResRep.setValue("rt", m_resourceType);
ocResRep.setValue("if", m_interfaces);
- // TODO: How to set property "p" ????
ocResRep.setValue("n", m_name);
}
{
OC::OCRepresentation rep = request->getResourceRepresentation();
std::string payload = getPayloadString(rep);
- SIM_LOG(ILogger::INFO, "[" << m_name << "] " << request->getRequestType()
+ SIM_LOG(ILogger::INFO, "[" << m_uri << "] " << request->getRequestType()
<< " request received. \n**Payload details**\n" << payload)
}
if (OC::ObserveAction::ObserveRegister == observationInfo.action)
{
addObserver(observationInfo);
- SIM_LOG(ILogger::INFO, "[" << m_uri << "] Observer added [id: " << observationInfo.obsId <<
- ", address: " << observationInfo.address << "port: " << observationInfo.port << "]");
+ SIM_LOG(ILogger::INFO, "[" << m_uri << "] Observer added [id: "
+ << (int)observationInfo.obsId << ", address: " << observationInfo.address
+ << ", port: " << observationInfo.port << "].");
}
else if (OC::ObserveAction::ObserveUnregister == observationInfo.action)
{
removeObserver(observationInfo);
- SIM_LOG(ILogger::INFO, "[" << m_uri << "] Observer removed [id: " << observationInfo.obsId <<
- ", address: " << observationInfo.address << "port: " << observationInfo.port << "]");
+ SIM_LOG(ILogger::INFO, "[" << m_uri << "] Observer removed [id: "
+ << (int)observationInfo.obsId << ", address: " << observationInfo.address
+ << ", port: " << observationInfo.port << "].");
}
}
// Check if resource support GET request
if (m_requestModels.end() == m_requestModels.find("GET"))
{
- SIM_LOG(ILogger::INFO, "Resource does not support GET request!")
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "Resource does not support GET request!")
return sendResponse(request, 405, OC_EH_ERROR);
}
- RequestModelSP requestModel = m_requestModels["GET"];
-
// Handling interface query parameter "if"
auto interfaceType = m_interfaces[0];
auto requestQueryParams = request->getQueryParameters();
if (!isValidInterface(interfaceType, "GET"))
{
- SIM_LOG(ILogger::INFO, "Invalid interface type: " << interfaceType)
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "GET request received on invalid interface : " << interfaceType)
return OC_EH_ERROR;
}
setCommonProperties(resourceRep);
}
- if (OC_EH_OK == sendResponse(request, 200, OC_EH_OK, resourceRep, interfaceType))
- {
- SIM_LOG(ILogger::INFO, "[" << m_uri <<
- "] Sent response for GET request \n**Payload details**" <<
- getPayloadString(resourceRep))
- return OC_EH_OK;
- }
-
- SIM_LOG(ILogger::INFO, "[" << m_uri << "] Failed to send response for GET request!")
- return OC_EH_ERROR;
+ return sendResponse(request, 200, OC_EH_OK, resourceRep, interfaceType);
}
OCEntityHandlerResult SimulatorSingleResourceImpl::handlePUT(
// Check if resource support PUT request
if (m_requestModels.end() == m_requestModels.find("PUT"))
{
- SIM_LOG(ILogger::INFO, "Resource does not support PUT request!")
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "Resource does not support PUT request!")
return sendResponse(request, 405, OC_EH_ERROR);
}
- RequestModelSP requestModel = m_requestModels["PUT"];
-
// Handling interface query parameter "if"
auto interfaceType = m_interfaces[0];
auto requestQueryParams = request->getQueryParameters();
if (!isValidInterface(interfaceType, "PUT"))
{
- SIM_LOG(ILogger::INFO, "Invalid interface type: " << interfaceType)
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "PUT request received on invalid interface : " << interfaceType)
return OC_EH_ERROR;
}
OC::OCRepresentation reqOcRep = request->getResourceRepresentation();
SimulatorResourceModel reqResModel = SimulatorResourceModel::build(reqOcRep);
SimulatorResourceModel updatedResModel;
- if (true == updateResourceModel(reqResModel, updatedResModel, true))
+ if (true == updateResourceModel(reqResModel, updatedResModel, true, false))
{
auto ocRep = updatedResModel.asOCRepresentation();
auto result = sendResponse(request, 200, OC_EH_OK,
ocRep, m_interfaces[0]);
notifyApp(updatedResModel);
- notifyAll();
+ try
+ {
+ notifyAll();
+ }
+ catch (SimulatorException &e)
+ {
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "Error when notifying the observers!")
+ }
+
return result;
}
- SIM_LOG(ILogger::ERROR, "Updating resource representation failed!");
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " << "Updating resource representation failed!")
return sendResponse(request, 400, OC_EH_ERROR);
}
// Check if resource support PUT request
if (m_requestModels.end() == m_requestModels.find("POST"))
{
- SIM_LOG(ILogger::INFO, "Resource does not support POST request!")
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "Resource does not support POST request!")
return sendResponse(request, 405, OC_EH_ERROR);
}
- RequestModelSP requestModel = m_requestModels["POST"];
-
// Handling interface query parameter "if"
auto interfaceType = m_interfaces[0];
auto requestQueryParams = request->getQueryParameters();
if (!isValidInterface(interfaceType, "POST"))
{
- SIM_LOG(ILogger::INFO, "Invalid interface type: " << interfaceType)
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "POST request received on invalid interface : " << interfaceType)
return OC_EH_ERROR;
}
OC::OCRepresentation reqOcRep = request->getResourceRepresentation();
SimulatorResourceModel reqResModel = SimulatorResourceModel::build(reqOcRep);
SimulatorResourceModel updatedResModel;
- if (true == updateResourceModel(reqResModel, updatedResModel))
+ if (true == updateResourceModel(reqResModel, updatedResModel, false, false))
{
auto ocRep = updatedResModel.asOCRepresentation();
auto result = sendResponse(request, 200, OC_EH_OK,
ocRep, m_interfaces[0]);
notifyApp(updatedResModel);
- notifyAll();
+ try
+ {
+ notifyAll();
+ }
+ catch (SimulatorException &e)
+ {
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "Error when notifying the observers!")
+ }
+
return result;
}
- SIM_LOG(ILogger::ERROR, "Updating resource representation failed!");
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] " << "Updating resource representation failed!")
return sendResponse(request, 400, OC_EH_ERROR);
}
OCEntityHandlerResult SimulatorSingleResourceImpl::handleDELETE(
const std::shared_ptr<OC::OCResourceRequest> &request)
{
- return OC_EH_ERROR;
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] "
+ << "Resource does not support DELETE request!")
+ return sendResponse(request, 405, OC_EH_ERROR);;
}
bool SimulatorSingleResourceImpl::isValidInterface(const std::string &interfaceType,
response->setResponseResult(responseResult);
if (OC_STACK_OK != OC::OCPlatform::sendResponse(response))
{
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] Failed to send response for " <<
+ request->getRequestType() <<" request!")
return OC_EH_ERROR;
}
+ SIM_LOG(ILogger::INFO, "[" << m_uri << "] Sent response for " <<
+ request->getRequestType() << " request.")
+
return OC_EH_OK;
}
OCEntityHandlerResult SimulatorSingleResourceImpl::sendResponse(
const std::shared_ptr<OC::OCResourceRequest> &request, const int errorCode,
- OCEntityHandlerResult responseResult, OC::OCRepresentation &Payload,
+ OCEntityHandlerResult responseResult, OC::OCRepresentation &payload,
const std::string &interfaceType)
{
std::shared_ptr<OC::OCResourceResponse> response(new OC::OCResourceResponse());
response->setResourceHandle(request->getResourceHandle());
response->setErrorCode(errorCode);
response->setResponseResult(responseResult);
- response->setResourceRepresentation(Payload, interfaceType);
+ response->setResourceRepresentation(payload, interfaceType);
if (OC_STACK_OK != OC::OCPlatform::sendResponse(response))
{
+ SIM_LOG(ILogger::ERROR, "[" << m_uri << "] Failed to send response for " <<
+ request->getRequestType() <<" request!")
return OC_EH_ERROR;
}
+ SIM_LOG(ILogger::INFO, "[" << m_uri << "] Sent response for " <<
+ request->getRequestType() << " request \n\n" <<
+ "**Payload details**" << getPayloadString(payload))
+
return OC_EH_OK;
}
#passwd =
obs = obs.tizen
#Comma separated list of repositories
-repos = repo.tizen_latest
+repos = repo.public_latest, repo.devel-gcc49-base,
#repos = repo.tizen_main, repo.tizen_base
#Build config for gbs build
#buildconf = <patch/to/build-config-file>
#passwd =
#Repo section example
-[repo.tizen_latest]
+[repo.public_latest]
#Build against repo's URL
-url = http://download.tizen.org/releases/2.3/2.3-mobile/tizen-2.3-mobile_20150206.1/repos/target/packages/
+url = http://download.tizen.org/snapshots/2.4-mobile/common/latest/repos/target-TM1/packages/
#Optional user and password, set if differ from profile's user and password
#user =
#passwd =
-#Individual repo is also supported
-#[repo.tizen_base]
-#url = http://download.tizen.org/releases/daily/trunk/ivi/latest/repos/base/ia32/packages/
-#[repo.tizen_main]
-#url = http://download.tizen.org/releases/daily/trunk/ivi/latest/repos/ivi/ia32/packages/
+[repo.devel-gcc49-base]
+url = http://download.tizen.org/releases/2.4/2.4-base/tizen-2.4-base_20151027.1/repos/standard/packages/