use TCP to connect to mbed connector
Fork of mbedConnectorInterfaceWithDM by
source/TickerResourceObserver.cpp@16:dffa38c3340f, 2016-06-10 (annotated)
- Committer:
- ansond
- Date:
- Fri Jun 10 18:53:01 2016 +0000
- Revision:
- 16:dffa38c3340f
- Parent:
- 13:9edad7677211
- Child:
- 31:2507e64fcc42
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:1f1f55e73248 | 1 | /** |
ansond | 0:1f1f55e73248 | 2 | * @file TickerResourceObserver.cpp |
ansond | 0:1f1f55e73248 | 3 | * @brief mbed CoAP DynamicResource Ticker-based observer (implementation) |
ansond | 0:1f1f55e73248 | 4 | * @author Doug Anson/Chris Paola |
ansond | 0:1f1f55e73248 | 5 | * @version 1.0 |
ansond | 0:1f1f55e73248 | 6 | * @see |
ansond | 0:1f1f55e73248 | 7 | * |
ansond | 0:1f1f55e73248 | 8 | * Copyright (c) 2014 |
ansond | 0:1f1f55e73248 | 9 | * |
ansond | 0:1f1f55e73248 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 0:1f1f55e73248 | 11 | * you may not use this file except in compliance with the License. |
ansond | 0:1f1f55e73248 | 12 | * You may obtain a copy of the License at |
ansond | 0:1f1f55e73248 | 13 | * |
ansond | 0:1f1f55e73248 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 0:1f1f55e73248 | 15 | * |
ansond | 0:1f1f55e73248 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 0:1f1f55e73248 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 0:1f1f55e73248 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 0:1f1f55e73248 | 19 | * See the License for the specific language governing permissions and |
ansond | 0:1f1f55e73248 | 20 | * limitations under the License. |
ansond | 0:1f1f55e73248 | 21 | */ |
ansond | 0:1f1f55e73248 | 22 | |
ansond | 0:1f1f55e73248 | 23 | #include "TickerResourceObserver.h" |
ansond | 0:1f1f55e73248 | 24 | |
ansond | 0:1f1f55e73248 | 25 | // constructor |
ansond | 0:1f1f55e73248 | 26 | TickerResourceObserver::TickerResourceObserver(DynamicResource *resource,int sleep_time) : |
ansond | 0:1f1f55e73248 | 27 | ResourceObserver(resource,(int)(sleep_time/1000)) { |
ansond | 0:1f1f55e73248 | 28 | this->setObserving(false); |
ansond | 0:1f1f55e73248 | 29 | // DEBUG |
ansond | 0:1f1f55e73248 | 30 | std::printf("TickerResourceObserver being used for %s (sleep_time=%d)\r\n",resource->getFullName().c_str(),sleep_time); |
ansond | 0:1f1f55e73248 | 31 | } |
ansond | 0:1f1f55e73248 | 32 | |
ansond | 0:1f1f55e73248 | 33 | // destructor |
ansond | 0:1f1f55e73248 | 34 | TickerResourceObserver::~TickerResourceObserver() { |
ansond | 0:1f1f55e73248 | 35 | this->stopObservation(); |
ansond | 0:1f1f55e73248 | 36 | } |
ansond | 0:1f1f55e73248 | 37 | |
ansond | 0:1f1f55e73248 | 38 | // notifier |
ansond | 0:1f1f55e73248 | 39 | void TickerResourceObserver::observationNotifier() { |
ansond | 16:dffa38c3340f | 40 | if (this->isObserving() == true && this->getResource() != NULL && this->getResource()->isRegistered() == true) { |
ansond | 0:1f1f55e73248 | 41 | this->getResource()->observe(); |
ansond | 0:1f1f55e73248 | 42 | } |
ansond | 0:1f1f55e73248 | 43 | } |
ansond | 0:1f1f55e73248 | 44 | |
ansond | 0:1f1f55e73248 | 45 | // begin observing... |
ansond | 0:1f1f55e73248 | 46 | void TickerResourceObserver::beginObservation() { |
ansond | 0:1f1f55e73248 | 47 | if (this->isObserving() == false) { |
ansond | 0:1f1f55e73248 | 48 | this->m_ticker.attach(this,&TickerResourceObserver::observationNotifier,(float)this->getSleepTime()); |
ansond | 0:1f1f55e73248 | 49 | this->setObserving(true); |
ansond | 0:1f1f55e73248 | 50 | } |
ansond | 0:1f1f55e73248 | 51 | } |
ansond | 0:1f1f55e73248 | 52 | |
ansond | 0:1f1f55e73248 | 53 | // begin observing... |
ansond | 0:1f1f55e73248 | 54 | void TickerResourceObserver::stopObservation() { |
ansond | 0:1f1f55e73248 | 55 | this->setObserving(false); |
ansond | 0:1f1f55e73248 | 56 | } |