Doug Anson / mbedConnectorInterfaceWithDM

Fork of mbedConnectorInterfaceV3 by Doug Anson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MinarResourceObserver.cpp Source File

MinarResourceObserver.cpp

Go to the documentation of this file.
00001 /**
00002  * @file    MinarResourceObserver.cpp
00003  * @brief   mbed CoAP DynamicResource Minar-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 // class support
00024 #include "mbed-connector-interface/MinarResourceObserver.h"
00025 
00026 #if defined (MCI_MINAR_SCHEDULER)
00027 
00028  // constructor
00029  MinarResourceObserver::MinarResourceObserver(DynamicResource *resource,int sleep_time) : ResourceObserver(resource,sleep_time) {
00030      this->setObserving(false);
00031         
00032      // DEBUG
00033      this->logger()->log("MinarResourceObserver being used for %s (sleep_time: %d ms)",resource->getFullName().c_str(),sleep_time);
00034  }
00035 
00036  // destructor
00037  MinarResourceObserver::~MinarResourceObserver() {
00038      this->stopObservation();
00039  }
00040 
00041  // observation task method
00042  void MinarResourceObserver::observation_task() {
00043      if (this->isObserving() == true && this->getResource() != NULL) {
00044          DynamicResource *res = this->getResource();
00045          if (res != NULL && res->isRegistered() == true) {
00046              res->observe();
00047          }
00048      }
00049  }
00050 
00051  // begin observing...
00052  void MinarResourceObserver::beginObservation() {
00053      this->setObserving(true);
00054      minar::Scheduler::postCallback(this,&MinarResourceObserver::observation_task).period(minar::milliseconds(this->getSleepTime()));
00055  }
00056 
00057  // stop observing...
00058  void MinarResourceObserver::stopObservation() {
00059      this->setObserving(false);
00060  }
00061  
00062  // halt the underlying observer mechanism
00063  void MinarResourceObserver::halt() {
00064      minar::Scheduler::stop();
00065  }
00066  
00067  #endif // MCI_MINAR_SCHEDULER