mbed Connector Interface simplification API on top of mbed-client
Fork of mbedConnectorInterfaceV3 by
NOTE:
This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!
Diff: source/ThreadedResourceObserver.cpp
- Revision:
- 66:764ec3dd205a
- Parent:
- 65:57ad7b72108f
- Child:
- 67:0c130dc6b489
--- a/source/ThreadedResourceObserver.cpp Mon Aug 22 18:13:13 2016 +0000 +++ b/source/ThreadedResourceObserver.cpp Mon Aug 22 18:18:23 2016 +0000 @@ -26,20 +26,20 @@ #ifdef CONNECTOR_USING_THREADS // constructor - ThreadedResourceObserver::ThreadedResourceObserver(DynamicResource *resource,int sleep_time) : ResourceObserver(resource,sleep_time), m_observation_thread() { { - // default is not observing... - this->setObserving(false); - - // DEBUG - if (sleep_time > 0) { - this->logger()->log("ThreadedResourceObserver being used for %s (sleep_time: %d ms)",resource->getFullName().c_str(),sleep_time); - } - else { - this->logger()->log("ThreadedResourceObserver being used for %s",resource->getFullName().c_str()); - } - - // start the thread by invoking the thread task... - this->m_observation_thread.start(this,&ThreadedResourceObserver::observation_task); + ThreadedResourceObserver::ThreadedResourceObserver(DynamicResource *resource,int sleep_time) : ResourceObserver(resource,sleep_time), m_observation_thread() { + // default is not observing... + this->setObserving(false); + + // DEBUG + if (sleep_time > 0) { + this->logger()->log("ThreadedResourceObserver being used for %s (sleep_time: %d ms)",resource->getFullName().c_str(),sleep_time); + } + else { + this->logger()->log("ThreadedResourceObserver being used for %s",resource->getFullName().c_str()); + } + + // start the thread by invoking the thread task... + this->m_observation_thread.start(this,&ThreadedResourceObserver::observation_task); } // destructor @@ -48,13 +48,12 @@ this->m_observation_thread.terminate(); } - // notifier - void ThreadedResourceObserver::_observation_notifier(void const *instance) { - ThreadedResourceObserver *me = (ThreadedResourceObserver *)instance; + // thread task method + void ThreadedResourceObserver::observation_task() { while(true) { - Thread::wait(me->getSleepTime()); - if (me->isObserving() == true && me->getResource() != NULL && me->getResource()->isRegistered() == true) { - me->getResource()->observe(); + Thread::wait(this->getSleepTime()); + if (this->isObserving() == true && this->getResource() != NULL && this->getResource()->isRegistered() == true) { + this->getResource()->observe(); } } }