orca-robotics


INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

REPOSITORY
Interfaces
Components
Libraries
Utilities
Software Map

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard
Wiki
login/pass: orca/orca

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-2008 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 <Ice/Ice.h>
00016 #include <IceStorm/IceStorm.h>
00017 #include <orcaqguielementutil/icestormlistener.h>
00018 #include <hydroqgui/hydroqgui.h>
00019 #include <hydroqguielementutil/guielement2d.h>
00020 
00021 namespace orcaqguielementutil {
00022 
00030 template<class PainterType, class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00031 class IceStormElement
00032 {
00033   
00034 public:
00035 
00038     IceStormElement( const orcaice::Context  &context,
00039                      const std::string       &proxyString,
00040                      PainterType             &painter,
00041                      const double            timeoutMs )
00042         : context_(context),
00043           listener_(context,proxyString),
00044           painter_(painter),
00045           timeoutMs_(timeoutMs),
00046           isConnected_(false)
00047     {};
00048 
00049     virtual ~IceStormElement() {}
00050 
00052     virtual void actionOnConnection()=0;
00053 
00055     void updateFromBuffer();
00056 
00057 protected:
00058 
00059     orcaice::Context              context_;
00060     
00061     DataType                       data_;
00062     
00063     bool needToUpdate();
00064     
00066     orcaqguielementutil::IceStormListener<DataType,
00067                                           ProxyType,
00068                                           ConsumerType,
00069                                           ConsumerPrxType> listener_;
00070 
00072     PainterType                     &painter_;
00073     
00074     double                           timeoutMs_;
00075     bool                             isConnected_;
00076 };
00077 
00078 template<class PainterType, class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00079 bool 
00080 IceStormElement<PainterType,DataType,ProxyType,ConsumerType,ConsumerPrxType>::needToUpdate()
00081 {
00082     if ( !isConnected_ )
00083     {
00084         if ( listener_.connect() == 0 )
00085         {
00086             isConnected_ = true;
00087             assert( listener_.proxy() != 0 );
00088             actionOnConnection();
00089         }
00090         return false;
00091     }
00092 
00093     if ( !listener_.buffer().isEmpty() )
00094     {
00095         // An object has arrived in our buffer.  We need to update.
00096         return true;
00097     }
00098 
00099     // The buffer is empty.  How long since we last received something?
00100     if ( timeoutMs_ != -1 && listener_.msSinceReceipt() >= timeoutMs_ )
00101     {
00102         std::cout<<"TRACE(icestormelement.h): Haven't received anything from " 
00103                  << listener_.interfaceName() << " for " << listener_.msSinceReceipt() << "ms" << std::endl;
00104         std::cout<<"TRACE(icestormelement.h): Timing out..." << std::endl;
00105 
00106         painter_.clear();
00107         listener_.resetTimer();
00108         if ( listener_.connect() == 0 )
00109             actionOnConnection();
00110         else
00111             isConnected_ = false;
00112     }
00113     return false;
00114 }
00115 
00116 template<class PainterType, class DataType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00117 void 
00118 IceStormElement<PainterType,DataType,ProxyType,ConsumerType,ConsumerPrxType>::updateFromBuffer()
00119 {
00120     if ( !needToUpdate() ) {
00121         return;
00122     }
00123     
00124     assert( !listener_.buffer().isEmpty() );
00125 
00126     // get data from the buffer
00127     listener_.buffer().getAndPop( data_ );
00128 
00129     // transfer data into painter
00130     painter_.setData( data_ );
00131 }
00132 
00133 } // namespace
00134 
00135 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5