Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

RtcInPort.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00019 /*
00020  * $Log: RtcInPort.h,v $
00021  * Revision 1.1.1.1  2005/05/12 09:06:18  n-ando
00022  * Public release.
00023  *
00024  *
00025  */
00026 
00027 #ifndef RtcInPort_h
00028 #define RtcInPort_h
00029 
00030 #include "rtm/RtcInPortBase.h"
00031 #include "rtm/idl/RTCDataTypeSkel.h"
00032 #include <iostream>
00033 
00034 namespace RTM
00035 {
00068   template <class T> class InPortAny
00069         : public InPortBase
00070   {
00071   public:
00097         InPortAny(const char* name, T& value, int bufsize=64)
00098           : m_Buffer(bufsize), m_Value(value)
00099         {
00100           // Set PortProfile
00101           m_Profile.name = CORBA::string_dup(name);
00102           CORBA::Any var;
00103           var <<= m_Value;
00104           m_Profile.port_type = var.type();
00105           
00106           // Initializing ring buffer
00107           for (int i = 0 ; i <= m_Buffer.buff_length(); i++)
00108                 {
00109                   m_Buffer.put(value);
00110                 }
00111         };
00112 
00136         InPortAny(const char* name, int bufsize=64)
00137           : m_Buffer(bufsize), m_Value(m_Dummy)
00138         {
00139           // Set PortProfile
00140           m_Profile.name = CORBA::string_dup(name);
00141           CORBA::Any var;
00142           var <<= m_Value;
00143           m_Profile.port_type = var.type();
00144           
00145           // Initializing ring buffer
00146           for (int i = 0 ; i <= m_Buffer.buff_length(); i++)
00147                 {
00148                   m_Buffer.put(m_Value);
00149                 }
00150         };
00151         
00152         
00166         virtual ~InPortAny(){};
00167 
00181         virtual void put(const CORBA::Any& value)
00182           throw (RTM::InPort::Disconnected, CORBA::SystemException)
00183         {
00184           T* tmp;
00185 
00186           if (value >>= tmp)
00187                 m_Buffer.put(*tmp);
00188           return;
00189         }
00190         
00204         virtual void initBuffer(T& value)
00205         {
00206           for (int i = 0 ; i <= m_Buffer.buff_length(); i++)
00207                 {
00208                   m_Buffer.put(value);
00209                 }
00210         }
00211 
00212 
00229         virtual void read_pm()
00230         {
00231           m_Value = m_Buffer.get_new();
00232           return;
00233         };
00234         
00249         virtual T read()
00250         {
00251           m_Value = m_Buffer.get_new();
00252           return m_Value;
00253         };
00254         
00270         virtual bool operator>>(T& rhs)
00271         {
00272           rhs = m_Buffer.get_new();
00273           return true;
00274         };
00275 
00287         virtual bool isNew()
00288         {
00289           return m_Buffer.is_new();
00290         }
00291 
00292 
00304         virtual int getNewDataLen()
00305         {
00306           return m_Buffer.new_data_len();
00307         }
00308 
00309 
00321         virtual std::vector<T> getNewList()
00322         {
00323           return m_Buffer.get_new_list();
00324         }
00325         
00326 
00338         virtual std::vector<T> getNewListReverse()
00339         {
00340           return m_Buffer.get_new_rlist();
00341         }
00342         
00343 
00344   private:
00352         T& m_Value;
00353 
00361         T  m_Dummy;
00362 
00370         T* m_Tmp;
00371 
00379         RingBuffer<T> m_Buffer;
00380 
00381   };
00382   
00383 }; // End of namesepace RTM
00384 
00385 #endif // RtcInPort_h

Generated on Mon May 23 03:13:56 2005 for OpenRTM by doxygen 1.3.6