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;
- if (m_thread)
- m_thread->join();
}
void AttributeUpdateAutomation::updateAttribute()
SimulatorResourceModel::Attribute attribute;
while (!m_stopRequested && true == m_attributeGen.next(attribute))
{
- if (false == m_resource->updateAttributeValue(attribute))
+ try
{
- 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);
if (m_callback)
m_callback(m_resource->getURI(), m_id);
- if (m_finishedCallback && !m_stopRequested)
+ if (m_finishedCallback)
m_finishedCallback(m_id);
}
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;
- if (m_thread)
- m_thread->join();
}
void ResourceUpdateAutomation::updateAttributes(
{
for (auto &attributeEntry : resModel.getAttributes())
{
- resourceImpl->updateAttributeValue(attributeEntry.second);
+ try
+ {
+ resourceImpl->updateAttributeValue(attributeEntry.second);
+ }
+ catch(SimulatorException &e) {}
}
resourceImpl->notifyApp();
if (m_callback)
m_callback(m_resource->getURI(), m_id);
- if (m_finishedCallback && !m_stopRequested)
+ if (m_finishedCallback)
m_finishedCallback(m_id);
}
AttributeGenerator m_attributeGen;
updateCompleteCallback m_callback;
std::function<void (const int)> m_finishedCallback;
- std::thread *m_thread;
+ std::shared_ptr<std::thread> m_thread;
};
typedef std::shared_ptr<AttributeUpdateAutomation> AttributeUpdateAutomationSP;
int m_updateInterval;
updateCompleteCallback m_callback;
std::function<void (const int)> m_finishedCallback;
- std::thread *m_thread;
+ std::shared_ptr<std::thread> m_thread;
};
typedef std::shared_ptr<ResourceUpdateAutomation> ResourceUpdateAutomationSP;