Doug Anson / mbedConnectorInterface

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Revision:
42:20c375e74e8e
Parent:
41:fb12c88260ad
Child:
43:769d491a48c1
--- a/api/TaskletResourceObserver.cpp	Sat Apr 11 18:42:51 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-/**
- * @file    TaskletResourceObserver.cpp
- * @brief   mbed CoAP DynamicResource Tasklet-based observer (implementation)
- * @author  Doug Anson/Chris Paola
- * @version 1.0
- * @see
- *
- * Copyright (c) 2014
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- 
- #include "TaskletResourceObserver.h"
-
- void *m_instance = NULL;
- 
- // constructor
- TaskletResourceObserver::TaskletResourceObserver(DynamicResource *resource,uint8_t timer_id,int sleep_time) : 
-                                    ResourceObserver(resource,sleep_time), 
-                                    m_tasklet_id(-1),
-                                    m_timer_id(timer_id) {
- #ifdef CONNECTOR_USING_TASKLETS
-     this->m_event = NULL; 
- #endif
- }
-  
- // destructor
- TaskletResourceObserver::~TaskletResourceObserver() {
-     this->stopObservation();
- }
- 
- #ifdef CONNECTOR_USING_TASKLETS      
- // set the current event
- void TaskletResourceObserver::setEvent(arm_event_s *event) {
-    this->m_event = event;
- }
- #endif
- 
- #ifdef CONNECTOR_USING_TASKLETS
- // notifier
- void TaskletResourceObserver::_observation_notifier(arm_event_s *event) {
-     if (event != NULL) {
-         TaskletResourceObserver *me = (TaskletResourceObserver *)m_instance;
-         if (event->event_id == me->getTimerID()) {
-             timer_sys_event_cancel(event->event_id);
-             me->setEvent(event);
-             if (me->isObserving() == true && me->getResource() != NULL && nsdl_endpoint_is_registered() == true) {
-                 std::printf("Calling observe()...\r\n");
-                 me->getResource()->observe();
-             }
-             me->startTimer(); 
-         }
-         else {
-             std::printf("TaskletResourceObserver::observation_notifier(): ignoring event_id=%d timer_id=%d\r\n",event->event_id,me->getTimerID());
-         }
-     } 
- }
- #endif
- 
- // begin observing...
- void TaskletResourceObserver::beginObservation() {
- #ifdef CONNECTOR_USING_TASKLETS
-     // create the tasklet and begin the observationing
-     if (this->m_tasklet_id < 0) {
-        this->m_tasklet_id = arm_ns_tasklet_create(&TaskletResourceObserver::_observation_notifier);
-     }
-     
-     // back pointer
-     if (m_instance == NULL) {
-        m_instance = (void *)this;
-     }
-     
-     // start a timer if we have created a tasklet...
-     if (this->m_tasklet_id >= 0) {
-         // start the timer...
-         std::printf("TaskletResourceObserver::beginObservation(): starting tasklet timer timer_id=%d sleep=%d...\r\n",this->m_timer_id,this->getSleepTime());
-         this->startTimer();
-     }
- #endif
- }
- 
- // begin observing...
- void TaskletResourceObserver::stopObservation() {
- #ifdef CONNECTOR_USING_TASKLETS
-     if (this->m_event != NULL) {
-        timer_sys_event_cancel(this->m_event->event_id);
-        this->m_timer_active = false;
-     }
- #endif
- }
-  
- // reset the timer
- void TaskletResourceObserver::startTimer() {
- #ifdef CONNECTOR_USING_TASKLETS
-    if (this->m_timer_active == false) {
-        timer_sys_event(this->m_timer_id,(uint32_t)this->getSleepTime()); 
-        this->m_timer_active = true;
-    }
- #endif
- }
- 
- // get the timer ID
- uint8_t TaskletResourceObserver::getTimerID() { 
-    return this->m_timer_id; 
- }