IOT-893 is about the time delay after stopping the automation.
IOT-870 is about the server crash while notifying the observers.
Updated the code to allow errors when notifying the observers to be
propagated till application.
Managing thread objects using shared pointers
and detaching them for de-allocation of thread resources.
Change-Id: I06e33926a79fd241bf4089b8c4760742edab8290
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4721
Reviewed-by: Radha Bhavani <radha.p@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
void AttributeUpdateAutomation::start()
{
void AttributeUpdateAutomation::start()
{
- m_thread = new std::thread(&AttributeUpdateAutomation::updateAttribute, this);
+ m_thread = std::make_shared<std::thread>(&AttributeUpdateAutomation::updateAttribute, this);
+ m_thread->detach();
}
void AttributeUpdateAutomation::stop()
{
m_stopRequested = true;
}
void AttributeUpdateAutomation::stop()
{
m_stopRequested = true;
- if (m_thread)
- m_thread->join();
}
void AttributeUpdateAutomation::updateAttribute()
}
void AttributeUpdateAutomation::updateAttribute()
SimulatorResourceModel::Attribute attribute;
while (!m_stopRequested && true == m_attributeGen.next(attribute))
{
SimulatorResourceModel::Attribute attribute;
while (!m_stopRequested && true == m_attributeGen.next(attribute))
{
- if (false == m_resource->updateAttributeValue(attribute))
- OC_LOG_V(ERROR, ATAG, "Failed to update the attribute![%s]", attribute.getName().c_str());
- continue;
+ if (false == m_resource->updateAttributeValue(attribute))
+ {
+ OC_LOG_V(ERROR, ATAG, "Failed to update the attribute![%s]", attribute.getName().c_str());
+ continue;
+ }
+ catch(SimulatorException &e) {}
+
resourceImpl->notifyApp();
SLEEP_FOR(m_updateInterval);
resourceImpl->notifyApp();
SLEEP_FOR(m_updateInterval);
if (m_callback)
m_callback(m_resource->getURI(), m_id);
if (m_callback)
m_callback(m_resource->getURI(), m_id);
- if (m_finishedCallback && !m_stopRequested)
+ if (m_finishedCallback)
m_finishedCallback(m_id);
}
m_finishedCallback(m_id);
}
throw SimulatorException(SIMULATOR_ERROR, "Resource has zero attributes!");
}
throw SimulatorException(SIMULATOR_ERROR, "Resource has zero attributes!");
}
- m_thread = new std::thread(&ResourceUpdateAutomation::updateAttributes, this, attributes);
+ m_thread = std::make_shared<std::thread>(&ResourceUpdateAutomation::updateAttributes, this, attributes);
+ m_thread->detach();
}
void ResourceUpdateAutomation::stop()
{
m_stopRequested = true;
}
void ResourceUpdateAutomation::stop()
{
m_stopRequested = true;
- if (m_thread)
- m_thread->join();
}
void ResourceUpdateAutomation::updateAttributes(
}
void ResourceUpdateAutomation::updateAttributes(
{
for (auto &attributeEntry : resModel.getAttributes())
{
{
for (auto &attributeEntry : resModel.getAttributes())
{
- resourceImpl->updateAttributeValue(attributeEntry.second);
+ try
+ {
+ resourceImpl->updateAttributeValue(attributeEntry.second);
+ }
+ catch(SimulatorException &e) {}
}
resourceImpl->notifyApp();
}
resourceImpl->notifyApp();
if (m_callback)
m_callback(m_resource->getURI(), m_id);
if (m_callback)
m_callback(m_resource->getURI(), m_id);
- if (m_finishedCallback && !m_stopRequested)
+ if (m_finishedCallback)
m_finishedCallback(m_id);
}
m_finishedCallback(m_id);
}
AttributeGenerator m_attributeGen;
updateCompleteCallback m_callback;
std::function<void (const int)> m_finishedCallback;
AttributeGenerator m_attributeGen;
updateCompleteCallback m_callback;
std::function<void (const int)> m_finishedCallback;
+ std::shared_ptr<std::thread> m_thread;
};
typedef std::shared_ptr<AttributeUpdateAutomation> AttributeUpdateAutomationSP;
};
typedef std::shared_ptr<AttributeUpdateAutomation> AttributeUpdateAutomationSP;
int m_updateInterval;
updateCompleteCallback m_callback;
std::function<void (const int)> m_finishedCallback;
int m_updateInterval;
updateCompleteCallback m_callback;
std::function<void (const int)> m_finishedCallback;
+ std::shared_ptr<std::thread> m_thread;
};
typedef std::shared_ptr<ResourceUpdateAutomation> ResourceUpdateAutomationSP;
};
typedef std::shared_ptr<ResourceUpdateAutomation> ResourceUpdateAutomationSP;
if (m_resourceUpdationList.end() != m_resourceUpdationList.find(id))
{
m_resourceUpdationList[id]->stop();
if (m_resourceUpdationList.end() != m_resourceUpdationList.find(id))
{
m_resourceUpdationList[id]->stop();
- m_resourceUpdationList.erase(m_resourceUpdationList.find(id));
return;
}
else if (m_attrUpdationList.end() != m_attrUpdationList.find(id))
{
m_attrUpdationList[id]->stop();
return;
}
else if (m_attrUpdationList.end() != m_attrUpdationList.find(id))
{
m_attrUpdationList[id]->stop();
- m_attrUpdationList.erase(m_attrUpdationList.find(id));