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

 

         

ptricestormelement.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_PTR_ICESTORM_ELEMENT_H
00012 #define ORCAGUI_PTR_ICESTORM_ELEMENT_H
00013 
00014 #include <assert.h>
00015 #include <Ice/Ice.h>
00016 #include <IceStorm/IceStorm.h>
00017 #include <orcaqguielementutil/ptricestormlistener.h>
00018 #include <hydroqgui/hydroqgui.h>
00019 #include <hydroqguielementutil/guielement2d.h>
00020 
00021 // forward declarations
00022 class QPainter;
00023 
00024 namespace orcaqguielementutil {
00025 
00033 template<class PainterType, class DataType, class DataPtrType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00034 class PtrIceStormElement : public hydroqguielementutil::GuiElement2d
00035 {
00036   
00037 public:
00038 
00041     PtrIceStormElement( const orcaice::Context  &context,
00042                      const std::string       &proxyString,
00043                      PainterType             &painter,
00044                      const double            timeoutMs=5000.0 )
00045         : context_(context),
00046           listener_(context,proxyString),
00047           painter_(painter),
00048           timeoutMs_(timeoutMs),
00049           isConnected_(false)
00050     {
00051     };
00052 
00054     virtual void actionOnConnection()=0;
00055 
00057     virtual void update();
00058 
00060     virtual void paint( QPainter *p, int z )
00061         { painter_.paint( p, z ); }
00062 
00063     bool paintThisLayer( int z ) const
00064         { return painter_.paintThisLayer( z ); }
00065 
00066 protected:
00067 
00068     orcaice::Context              context_;
00069     
00070     DataPtrType                       data_;
00071     
00072     bool needToUpdate();
00073     
00075     orcaqguielementutil::PtrIceStormListener<DataType,
00076                                              DataPtrType,
00077                                              ProxyType,
00078                                              ConsumerType,
00079                                              ConsumerPrxType> listener_;
00080 
00082     PainterType                     &painter_;
00083     
00084     double                           timeoutMs_;
00085     bool                             isConnected_;
00086 };
00087 
00088 template<class PainterType, class DataType, class DataPtrType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00089 bool 
00090 PtrIceStormElement<PainterType,DataType,DataPtrType,ProxyType,ConsumerType,ConsumerPrxType>::needToUpdate()
00091 {
00092     if ( !isConnected_ )
00093     {
00094         if ( listener_.connect() == 0 )
00095         {
00096             isConnected_ = true;
00097             actionOnConnection();
00098         }
00099         return false;
00100     }
00101 
00102     if ( !listener_.buffer().isEmpty() )
00103     {
00104         // An object has arrived in our buffer.  We need to update.
00105         return true;
00106     }
00107 
00108     // The buffer is empty.  How long since we last received something?
00109     if ( timeoutMs_ != -1 && listener_.msSinceReceipt() >= timeoutMs_ )
00110     {
00111         std::cout<<"TRACE(icestormelement.h): Haven't received anything from " 
00112                  << listener_.interfaceName() << " for " << listener_.msSinceReceipt() << "ms" << std::endl;
00113         std::cout<<"TRACE(icestormelement.h): Timing out..." << std::endl;
00114 
00115         painter_.clear();
00116         listener_.resetTimer();
00117         if ( listener_.connect() == 0 )
00118             actionOnConnection();
00119     }
00120     return false;
00121 }
00122 
00123 template<class PainterType, class DataType, class DataPtrType, class ProxyType, class ConsumerType, class ConsumerPrxType>
00124 void 
00125 PtrIceStormElement<PainterType,DataType,DataPtrType,ProxyType,ConsumerType,ConsumerPrxType>::update()
00126 {
00127     if ( !needToUpdate() ) {
00128         return;
00129     }
00130     
00131     assert( !listener_.buffer().isEmpty() );
00132 
00133     // get data from the buffer
00134     listener_.buffer().getAndPop( data_ );
00135 
00136     // transfer data into painter
00137     painter_.setData( data_ );
00138 }
00139 
00140 }
00141 
00142 
00143 
00144 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5