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

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


Generated for Orca Robotics by  doxygen 1.4.5