use TCP to connect to mbed connector
Fork of mbedConnectorInterfaceWithDM by
source/MinarResourceObserver.cpp@27:b8aaf7dc7023, 2016-06-14 (annotated)
- Committer:
- ansond
- Date:
- Tue Jun 14 04:01:34 2016 +0000
- Revision:
- 27:b8aaf7dc7023
- Child:
- 31:2507e64fcc42
Initial merge and update of device and firmware objects
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 27:b8aaf7dc7023 | 1 | /** |
ansond | 27:b8aaf7dc7023 | 2 | * @file MinarResourceObserver.cpp |
ansond | 27:b8aaf7dc7023 | 3 | * @brief mbed CoAP DynamicResource Minar-based observer (implementation) |
ansond | 27:b8aaf7dc7023 | 4 | * @author Doug Anson/Chris Paola |
ansond | 27:b8aaf7dc7023 | 5 | * @version 1.0 |
ansond | 27:b8aaf7dc7023 | 6 | * @see |
ansond | 27:b8aaf7dc7023 | 7 | * |
ansond | 27:b8aaf7dc7023 | 8 | * Copyright (c) 2014 |
ansond | 27:b8aaf7dc7023 | 9 | * |
ansond | 27:b8aaf7dc7023 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 27:b8aaf7dc7023 | 11 | * you may not use this file except in compliance with the License. |
ansond | 27:b8aaf7dc7023 | 12 | * You may obtain a copy of the License at |
ansond | 27:b8aaf7dc7023 | 13 | * |
ansond | 27:b8aaf7dc7023 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 27:b8aaf7dc7023 | 15 | * |
ansond | 27:b8aaf7dc7023 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 27:b8aaf7dc7023 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 27:b8aaf7dc7023 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 27:b8aaf7dc7023 | 19 | * See the License for the specific language governing permissions and |
ansond | 27:b8aaf7dc7023 | 20 | * limitations under the License. |
ansond | 27:b8aaf7dc7023 | 21 | */ |
ansond | 27:b8aaf7dc7023 | 22 | |
ansond | 27:b8aaf7dc7023 | 23 | #if defined(MCI_MINAR_SCHEDULER) |
ansond | 27:b8aaf7dc7023 | 24 | |
ansond | 27:b8aaf7dc7023 | 25 | #include "mbed-connector-interface/MinarResourceObserver.h" |
ansond | 27:b8aaf7dc7023 | 26 | |
ansond | 27:b8aaf7dc7023 | 27 | // DEBUG |
ansond | 27:b8aaf7dc7023 | 28 | #ifndef NDEBUG |
ansond | 27:b8aaf7dc7023 | 29 | #define DEBUG_OUT(...) { printf(__VA_ARGS__); } |
ansond | 27:b8aaf7dc7023 | 30 | #else |
ansond | 27:b8aaf7dc7023 | 31 | #define DEBUG_OUT(...) /* nothing */ |
ansond | 27:b8aaf7dc7023 | 32 | #endif |
ansond | 27:b8aaf7dc7023 | 33 | |
ansond | 27:b8aaf7dc7023 | 34 | // constructor |
ansond | 27:b8aaf7dc7023 | 35 | MinarResourceObserver::MinarResourceObserver(DynamicResource *resource,int sleep_time) : ResourceObserver(resource,sleep_time) { |
ansond | 27:b8aaf7dc7023 | 36 | this->setObserving(false); |
ansond | 27:b8aaf7dc7023 | 37 | |
ansond | 27:b8aaf7dc7023 | 38 | // DEBUG |
ansond | 27:b8aaf7dc7023 | 39 | DEBUG_OUT("MinarResourceObserver being used for %s (sleep_time=%d ms)\r\n",resource->getName().c_str(),sleep_time); |
ansond | 27:b8aaf7dc7023 | 40 | } |
ansond | 27:b8aaf7dc7023 | 41 | |
ansond | 27:b8aaf7dc7023 | 42 | // destructor |
ansond | 27:b8aaf7dc7023 | 43 | MinarResourceObserver::~MinarResourceObserver() { |
ansond | 27:b8aaf7dc7023 | 44 | this->stopObservation(); |
ansond | 27:b8aaf7dc7023 | 45 | } |
ansond | 27:b8aaf7dc7023 | 46 | |
ansond | 27:b8aaf7dc7023 | 47 | // notifier |
ansond | 27:b8aaf7dc7023 | 48 | void MinarResourceObserver::perform_observation() { |
ansond | 27:b8aaf7dc7023 | 49 | if (this->isObserving() == true && this->getResource() != NULL && this->getResource()->isConnected() == true) { |
ansond | 27:b8aaf7dc7023 | 50 | this->getResource()->observe(); |
ansond | 27:b8aaf7dc7023 | 51 | } |
ansond | 27:b8aaf7dc7023 | 52 | } |
ansond | 27:b8aaf7dc7023 | 53 | |
ansond | 27:b8aaf7dc7023 | 54 | // begin observing... |
ansond | 27:b8aaf7dc7023 | 55 | void MinarResourceObserver::beginObservation() { |
ansond | 27:b8aaf7dc7023 | 56 | this->setObserving(true); |
ansond | 27:b8aaf7dc7023 | 57 | minar::Scheduler::postCallback(this,&MinarResourceObserver::perform_observation).period(minar::milliseconds(this->getSleepTime())); |
ansond | 27:b8aaf7dc7023 | 58 | } |
ansond | 27:b8aaf7dc7023 | 59 | |
ansond | 27:b8aaf7dc7023 | 60 | // stop observing... |
ansond | 27:b8aaf7dc7023 | 61 | void MinarResourceObserver::stopObservation() { |
ansond | 27:b8aaf7dc7023 | 62 | this->setObserving(false); |
ansond | 27:b8aaf7dc7023 | 63 | } |
ansond | 27:b8aaf7dc7023 | 64 | |
ansond | 27:b8aaf7dc7023 | 65 | #endif // MCI_MINAR_SCHEDULER |