INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

NONFRAMEWORK CODE
Driver Interfaces
Drivers
Libraries
Utilities

FRAMEWORK CODE
Interfaces
Components
Libraries
Utilities

Full Software Listings

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

icestormelement.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics 
00003  *               http://orca-robotics.sf.net/
00004  * Copyright (c) 2004-2009 Alex Brooks, Alexei Makarenko, Tobias Kaupp
00005  *
00006  * This copy of Orca is licensed to you under the terms described in
00007  * the LICENSE file included in this distribution.
00008  *
00009  */
00010 
00011 #ifndef ORCAGUI_ICESTORM_ELEMENT_H
00012 #define ORCAGUI_ICESTORM_ELEMENT_H
00013 
00014 #include <assert.h>
00015 #include <orcaqguielementutil/icestormlistener.h>
00016 
00017 namespace orcaqguielementutil {
00018 
00026 template<class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00027 class IceStormElement
00028 {
00029   
00030 public:
00031 
00034     IceStormElement( const orcaice::Context                     &context,
00035                      const std::string                          &proxyString,
00036                      const double                                timeoutMs,
00037                      const double                                tryConnectIntervalSec = 2.5 )
00038         : context_(context),
00039           listener_(context,proxyString),
00040           tryConnectTimer_(IceUtil::Time::seconds(999)),
00041           tryConnectIntervalSec_(tryConnectIntervalSec),
00042           timeoutMs_(timeoutMs),
00043           isConnected_(false),
00044           shouldClearPainter_(false)
00045     {};
00046 
00047     virtual ~IceStormElement() {}
00048 
00050     virtual void iceStormConnectedEvent() {};
00051 
00052 protected:
00053 
00055     bool updateFromStore();
00056 
00057     orcaice::Context context_;
00058     
00059     // alexm: this is a copy of the data in Store of the listener_
00060     // this duplicates data storage requirements
00061     DataType data_;
00062     
00063     bool needToUpdate();
00064     
00066     orcaqguielementutil::IceStormListener<DataType,
00067                                           ProxyType,
00068                                           ConsumerType,
00069                                           ConsumerPrxType> listener_;
00070 
00072     gbxiceutilacfr::Timer tryConnectTimer_;
00073     double tryConnectIntervalSec_;
00074     
00075     double timeoutMs_;
00076     bool isConnected_;
00077     bool shouldClearPainter_;
00078 };
00079 
00080 template<class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00081 bool 
00082 IceStormElement<DataType,ProxyType,ConsumerType,ConsumerPrxType>::needToUpdate()
00083 {
00084     if ( !isConnected_ )
00085     {
00086         if ( tryConnectTimer_.elapsedSec() < tryConnectIntervalSec_ )
00087             return false;
00088         tryConnectTimer_.restart();
00089 
00090         if ( listener_.connect() == 0 )
00091         {
00092             isConnected_ = true;
00093             assert( listener_.proxy() != 0 );
00094             iceStormConnectedEvent();
00095         }
00096         return false;
00097     }
00098 
00099     if ( listener_.store().isNewData() )
00100     {
00101         // An object has arrived in our buffer.  We need to update.
00102         return true;
00103     }
00104 
00105     // The store has nothing new.  How long since we last received something?
00106     if ( timeoutMs_ != -1 && listener_.msSinceReceipt() >= timeoutMs_ )
00107     {
00108         std::cout<<"TRACE(icestormelement.h): Haven't received anything from " 
00109                  << listener_.interfaceName() << " for " << listener_.msSinceReceipt() << "ms" << std::endl;
00110         std::cout<<"TRACE(icestormelement.h): Timing out..." << std::endl;
00111 
00112         shouldClearPainter_ = true;
00113         listener_.resetTimer();
00114         if ( listener_.connect() == 0 )
00115             iceStormConnectedEvent();
00116         else
00117             isConnected_ = false;
00118     }
00119     return false;
00120 }
00121 
00122 template<class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00123 bool 
00124 IceStormElement<DataType,ProxyType,ConsumerType,ConsumerPrxType>::updateFromStore()
00125 {
00126     if ( !needToUpdate() )
00127         return false;
00128     
00129     assert( listener_.store().isNewData() );
00130 
00131     // get data from the buffer
00132     listener_.store().get( data_ );
00133     
00134     return true;
00135 }
00136 
00137 } // namespace
00138 
00139 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5