}
void onResourceModelChanged(const std::string &uri,
- const std::vector<SimulatorResourceModel::Attribute> &attributes)
+ const SimulatorResourceModel &resModel)
{
- std::cout << "[callback] Resource model is changed URI: " << uri.c_str() << "Count : " <<
- attributes.size() << std::endl;
+ std::cout << "[callback] Resource model is changed URI: " << uri.c_str() << " Count : " <<
+ resModel.size() << std::endl;
std::cout << "#### Modified attributes are ####" << std::endl;
- for (auto & attribute : attributes)
+ for (auto & attribute : resModel.getAttributes())
{
- std::cout << attribute.getName() << " : " << attribute.valueToString().c_str() << std::endl;
+ std::cout << attribute.second.getName() << " : " << attribute.second.valueToString().c_str() << std::endl;
}
std::cout << "########################" << std::endl;
}
const int allowedValueIndex)
{
m_resModel.updateAttributeFromAllowedValues(attrName, allowedValueIndex);
+ notifyListOfObservers();
}
SimulatorResourceModel SimulatorResource::getModel() const
errCode = OC_EH_ERROR;
}
}
- else if (OC::RequestHandlerFlag::ObserverFlag & request->getRequestHandlerFlag())
+
+ if (OC::RequestHandlerFlag::ObserverFlag & request->getRequestHandlerFlag())
{
OC::ObservationInfo observationInfo = request->getObservationInfo();
if (OC::ObserveAction::ObserveRegister == observationInfo.action)
void SimulatorResource::notifyListOfObservers ()
{
- if (0 == m_interestedObservers.size())
- return;
-
- std::shared_ptr<OC::OCResourceResponse> resourceResponse =
- {std::make_shared<OC::OCResourceResponse>()};
+ if(getHandle())
+ {
+ if (m_interestedObservers.size())
+ {
+ std::shared_ptr<OC::OCResourceResponse> resourceResponse =
+ {std::make_shared<OC::OCResourceResponse>()};
- resourceResponse->setErrorCode(200);
- resourceResponse->setResponseResult(OC_EH_OK);
- resourceResponse->setResourceRepresentation(getOCRepresentation(), OC::DEFAULT_INTERFACE);
+ resourceResponse->setErrorCode(200);
+ resourceResponse->setResponseResult(OC_EH_OK);
+ resourceResponse->setResourceRepresentation(getOCRepresentation(), OC::DEFAULT_INTERFACE);
- OC::OCPlatform::notifyListOfObservers(getHandle(), m_interestedObservers, resourceResponse);
+ OC::OCPlatform::notifyListOfObservers(getHandle(), m_interestedObservers, resourceResponse);
+ }
+ if(m_callback)
+ {
+ m_callback(getURI(),getModel());
+ }
+ }
}