observe updates

Fork of mbedConnectorInterface by Doug Anson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TickerResourceObserver.cpp Source File

TickerResourceObserver.cpp

Go to the documentation of this file.
00001 /**
00002  * @file    TickerResourceObserver.cpp
00003  * @brief   mbed CoAP DynamicResource Ticker-based observer (implementation)
00004  * @author  Doug Anson/Chris Paola
00005  * @version 1.0
00006  * @see
00007  *
00008  * Copyright (c) 2014
00009  *
00010  * Licensed under the Apache License, Version 2.0 (the "License");
00011  * you may not use this file except in compliance with the License.
00012  * You may obtain a copy of the License at
00013  *
00014  *     http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing, software
00017  * distributed under the License is distributed on an "AS IS" BASIS,
00018  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  * See the License for the specific language governing permissions and
00020  * limitations under the License.
00021  */
00022  
00023  #include "TickerResourceObserver.h"
00024  
00025  // DEBUG
00026  //DigitalOut __ticker_led(LED2);
00027  
00028  // determines whether the mDS endpoint has been registered or not...
00029  extern "C" bool nsdl_endpoint_is_registered(void);
00030  
00031  // constructor
00032  TickerResourceObserver::TickerResourceObserver(DynamicResource *resource,int sleep_time) : 
00033                                     ResourceObserver(resource,(int)(sleep_time/1000)) {
00034      this->setObserving(false);
00035      // DEBUG
00036      std::printf("TickerResourceObserver being used for %s (sleep_time=%d)\r\n",resource->getName().c_str(),sleep_time);
00037  }
00038   
00039  // destructor
00040  TickerResourceObserver::~TickerResourceObserver() {
00041      this->stopObservation();
00042  }
00043 
00044  // notifier
00045  void TickerResourceObserver::observationNotifier() {
00046      if (this->isObserving() == true && this->getResource() != NULL && nsdl_endpoint_is_registered() == true) {
00047          this->getResource()->observe();
00048          //__ticker_led = !__ticker_led;
00049      }
00050  }
00051  
00052  // begin observing...
00053  void TickerResourceObserver::beginObservation() {
00054      if (this->isObserving() == false) {
00055         this->m_ticker.attach(this,&TickerResourceObserver::observationNotifier,(float)this->getSleepTime());
00056         this->setObserving(true);
00057      }
00058  }
00059  
00060  // begin observing...
00061  void TickerResourceObserver::stopObservation() {
00062      this->setObserving(false);
00063  }