JNIEXPORT jint JNICALL
Java_org_oic_simulator_server_SimulatorSingleResource_startResourceUpdation
-(JNIEnv *env, jobject object, jint type, jint interval, jobject listener)
+(JNIEnv *env, jobject object, jobject type, jint interval, jobject listener)
{
VALIDATE_CALLBACK_RET(env, listener, -1)
try
{
- int id = singleResource->startResourceUpdation((1 == type) ? AutomationType::RECURRENT :
- AutomationType::NORMAL, interval, callback);
+ AutomationType automationType = AutomationTypeToCpp(env, type);
+ int id = singleResource->startResourceUpdation(automationType, interval, callback);
return id;
}
catch (InvalidArgsException &e)
std::vector<std::vector<std::vector<OC::OCRepresentation>>> ocSubRepArray =
ocAttribute.getValue<std::vector<std::vector<std::vector<OC::OCRepresentation>>>>();
- std::vector<std::vector<std::vector<SimulatorResourceModel>>> subResModelArray(ocSubRepArray.size());
+ std::vector<std::vector<std::vector<SimulatorResourceModel>>> subResModelArray(
+ ocSubRepArray.size());
for (size_t i = 0; i < ocSubRepArray.size(); i++)
{
std::vector<std::vector<SimulatorResourceModel>> innerArray1(ocSubRepArray[i].size());
m_childProperty.reset(new SimulatorResourceModel::AttributeProperty(childProperty));
}
-std::shared_ptr<SimulatorResourceModel::AttributeProperty> SimulatorResourceModel::AttributeProperty::getChildProperty()
+std::shared_ptr<SimulatorResourceModel::AttributeProperty>
+SimulatorResourceModel::AttributeProperty::getChildProperty()
{
return m_childProperty;
}
&& SimulatorResourceModel::AttributeProperty::Type::UNKNOWN != prop.type())
{
RangeValidator rangeValidator(prop);
- return boost::apply_visitor(rangeValidator, element.second);
+ if (false == boost::apply_visitor(rangeValidator, element.second))
+ return false;
}
}
}
while (!m_stopRequested && AutomationType::RECURRENT == m_type);
+ if (!m_stopRequested)
+ {
+ SIM_LOG(ILogger::INFO, "Resource update automation complete [id: " << m_id << "]");
+ }
+
// Notify application
if (m_callback)
m_callback(m_resource->getURI(), m_id);
// Add OIC Link if it is not present
bool found = false;
- std::vector<SimulatorResourceModel> links = m_resModel.get<std::vector<SimulatorResourceModel>>("links");
+ std::vector<SimulatorResourceModel> links =
+ m_resModel.get<std::vector<SimulatorResourceModel>>("links");
for (auto &link : links)
{
std::string linkURI = link.get<std::string>("href");
return;
// Add OIC Link if it is not present
- std::vector<SimulatorResourceModel> links = m_resModel.get<std::vector<SimulatorResourceModel>>("links");
+ std::vector<SimulatorResourceModel> links =
+ m_resModel.get<std::vector<SimulatorResourceModel>>("links");
for (size_t i = 0; i < links.size(); i++)
{
std::string linkURI = links[i].get<std::string>("href");
if (linkURI == uri)
{
- links.erase(links.begin()+i);
+ links.erase(links.begin() + i);
m_resModel.updateValue("links", links);
break;
}
}\r
\r
SimulatorResourceModel SimulatorResourceFactory::buildModelFromResponseBody(\r
- RAML::RequestResponseBodyPtr responseBody, std::string &resourceType, std::vector<std::string> &interfaceType)\r
+ RAML::RequestResponseBodyPtr responseBody, std::string &resourceType,\r
+ std::vector<std::string> &interfaceType)\r
{\r
SimulatorResourceModel resModel;\r
\r
uri = ramlResource->getResourceUri();\r
\r
RAML::RequestResponseBodyPtr successResponseBody = getRAMLResponseBody(\r
- ramlResource, RAML::ActionType::GET, "200");\r
+ ramlResource, RAML::ActionType::GET, "200");\r
RAML::RequestResponseBodyPtr putErrorResponseBody = getRAMLResponseBody(\r
- ramlResource, RAML::ActionType::PUT, "403");\r
+ ramlResource, RAML::ActionType::PUT, "403");\r
RAML::RequestResponseBodyPtr postErrorResponseBody = getRAMLResponseBody(\r
- ramlResource, RAML::ActionType::POST, "403");\r
+ ramlResource, RAML::ActionType::POST, "403");\r
\r
SimulatorResourceModel successResponseModel = buildModelFromResponseBody(\r
- successResponseBody, resourceType, interfaceType);\r
+ successResponseBody, resourceType, interfaceType);\r
SimulatorResourceModel putErrorResponseModel = buildModelFromResponseBody(\r
- putErrorResponseBody, rt, ifType);\r
+ putErrorResponseBody, rt, ifType);\r
SimulatorResourceModel postErrorResponseModel = buildModelFromResponseBody(\r
- postErrorResponseBody, rt, ifType);\r
+ postErrorResponseBody, rt, ifType);\r
\r
// Create simple/collection resource\r
std::shared_ptr<SimulatorResource> simResource;\r
std::shared_ptr<RAML::Properties> propertyElement);
SimulatorResourceModel buildResourceModel(std::shared_ptr<RAML::Items> item);
SimulatorResourceModel buildModelFromResponseBody(
- RAML::RequestResponseBodyPtr responseBody, std::string &resourceType, std::vector<std::string> &interfaceType);
+ RAML::RequestResponseBodyPtr responseBody, std::string &resourceType,
+ std::vector<std::string> &interfaceType);
RAML::RequestResponseBodyPtr getRAMLResponseBody(
std::shared_ptr<RAML::RamlResource> ramlResource, RAML::ActionType type, std::string responseCode);
std::shared_ptr<SimulatorResource> buildResource(
if (!m_resourceHandle)
return;
+ // Stop all the update automation of this resource
+ m_updateAutomationMgr.stopAll();
+
+ // Clear all the observers
+ removeAllObservers();
+
+ // Unregister the resource from stack
typedef OCStackResult (*UnregisterResource)(const OCResourceHandle &);
invokeocplatform(static_cast<UnregisterResource>(OC::OCPlatform::unregisterResource),
if (OC::ObserveAction::ObserveRegister == observationInfo.action)
{
SIM_LOG(ILogger::INFO, "[" << m_uri << "] OBSERVE REGISTER request received");
-
- ObserverInfo info {observationInfo.obsId, observationInfo.address, observationInfo.port};
- m_observersList.push_back(info);
-
- if (m_observeCallback)
- m_observeCallback(m_uri, ObservationStatus::REGISTER, info);
+ addObserver(observationInfo);
}
else if (OC::ObserveAction::ObserveUnregister == observationInfo.action)
{
SIM_LOG(ILogger::INFO, "[" << m_uri << "] OBSERVE UNREGISTER request received");
-
- ObserverInfo info;
- for (auto iter = m_observersList.begin(); iter != m_observersList.end(); iter++)
- {
- if ((info = *iter), info.id == observationInfo.obsId)
- {
- m_observersList.erase(iter);
- break;
- }
- }
-
- if (m_observeCallback)
- m_observeCallback(m_uri, ObservationStatus::UNREGISTER, info);
+ removeObserver(observationInfo);
}
errCode = OC_EH_OK;
}
return response;
}
+
+void SimulatorSingleResourceImpl::addObserver(OC::ObservationInfo ocObserverInfo)
+{
+ ObserverInfo info {ocObserverInfo.obsId, ocObserverInfo.address, ocObserverInfo.port};
+ m_observersList.push_back(info);
+
+ if (m_observeCallback)
+ m_observeCallback(m_uri, ObservationStatus::REGISTER, info);
+}
+
+void SimulatorSingleResourceImpl::removeObserver(OC::ObservationInfo ocObserverInfo)
+{
+ ObserverInfo info;
+ for (auto iter = m_observersList.begin(); iter != m_observersList.end(); iter++)
+ {
+ if ((info = *iter), info.id == ocObserverInfo.obsId)
+ {
+ m_observersList.erase(iter);
+ break;
+ }
+ }
+
+ if (m_observeCallback)
+ m_observeCallback(m_uri, ObservationStatus::UNREGISTER, info);
+}
+
+void SimulatorSingleResourceImpl::removeAllObservers()
+{
+ std::vector<ObserverInfo> observerList = m_observersList;
+ m_observersList.clear();
+ for (int index = 0; index < observerList.size(); index++)
+ {
+ if (m_observeCallback)
+ m_observeCallback(m_uri, ObservationStatus::UNREGISTER, observerList[index]);
+ }
+}
\ No newline at end of file
std::shared_ptr<OC::OCResourceRequest> request);
void resourceModified();
bool updateResourceModel(OC::OCRepresentation &ocRep, SimulatorResourceModel &resModel);
+ void addObserver(OC::ObservationInfo ocObserverInfo);
+ void removeObserver(OC::ObservationInfo ocObserverInfo);
+ void removeAllObservers();
SimulatorResource::Type m_type;
std::string m_name;