Main Page | Namespace List | Class Hierarchy | Class List | Directories | 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.3  2005/05/27 07:29:32  n-ando
00022  * - InPort/OutPort interface was changed.
00023  *   Exception RTM::InPort::Disconnected -> RTM:PortBase::Disconnected
00024  *
00025  * Revision 1.2  2005/05/16 06:12:15  n-ando
00026  * - Time variables of "m_Value" were initialized in constructors.
00027  *
00028  * Revision 1.1.1.1  2005/05/12 09:06:18  n-ando
00029  * Public release.
00030  *
00031  *
00032  */
00033 
00034 #ifndef RtcInPort_h
00035 #define RtcInPort_h
00036 
00037 #include "rtm/RtcInPortBase.h"
00038 #include "rtm/idl/RTCDataTypeSkel.h"
00039 #include <iostream>
00040 
00041 namespace RTM
00042 {
00075   template <class T> class InPortAny
00076         : public InPortBase
00077   {
00078   public:
00104         InPortAny(const char* name, T& value, int bufsize=64)
00105           : m_Buffer(bufsize), m_Value(value)
00106         {
00107           // Set PortProfile
00108           m_Profile.name = CORBA::string_dup(name);
00109           CORBA::Any var;
00110           var <<= m_Value;
00111           m_Profile.port_type = var.type();
00112 
00113           // Init time of data variable
00114           m_Value.tm.sec = 0;
00115           m_Value.tm.nsec = 0;
00116           
00117           // Initializing ring buffer
00118           for (int i = 0 ; i <= m_Buffer.buff_length(); i++)
00119                 {
00120                   m_Buffer.put(value);
00121                 }
00122         };
00123 
00147         InPortAny(const char* name, int bufsize=64)
00148           : m_Buffer(bufsize), m_Value(m_Dummy)
00149         {
00150           // Set PortProfile
00151           m_Profile.name = CORBA::string_dup(name);
00152           CORBA::Any var;
00153           var <<= m_Value;
00154           m_Profile.port_type = var.type();
00155 
00156           // Init time of data variable
00157           m_Value.tm.sec = 0;
00158           m_Value.tm.nsec = 0;
00159 
00160           // Initializing ring buffer
00161           for (int i = 0 ; i <= m_Buffer.buff_length(); i++)
00162                 {
00163                   m_Buffer.put(m_Value);
00164                 }
00165         };
00166         
00167         
00181         virtual ~InPortAny(){};
00182 
00196         virtual void put(const CORBA::Any& value)
00197           throw (RTM::PortBase::Disconnected, CORBA::SystemException)
00198         {
00199           T* tmp;
00200 
00201           if (value >>= tmp)
00202                 m_Buffer.put(*tmp);
00203           return;
00204         }
00205         
00219         virtual void initBuffer(T& value)
00220         {
00221           for (int i = 0 ; i <= m_Buffer.buff_length(); i++)
00222                 {
00223                   m_Buffer.put(value);
00224                 }
00225         }
00226 
00227 
00244         virtual void read_pm()
00245         {
00246           m_Value = m_Buffer.get_new();
00247           return;
00248         };
00249         
00264         virtual T read()
00265         {
00266           m_Value = m_Buffer.get_new();
00267           return m_Value;
00268         };
00269         
00285         virtual bool operator>>(T& rhs)
00286         {
00287           rhs = m_Buffer.get_new();
00288           return true;
00289         };
00290 
00302         virtual bool isNew()
00303         {
00304           return m_Buffer.is_new();
00305         }
00306 
00307 
00319         virtual int getNewDataLen()
00320         {
00321           return m_Buffer.new_data_len();
00322         }
00323 
00324 
00336         virtual std::vector<T> getNewList()
00337         {
00338           return m_Buffer.get_new_list();
00339         }
00340         
00341 
00353         virtual std::vector<T> getNewListReverse()
00354         {
00355           return m_Buffer.get_new_rlist();
00356         }
00357         
00358 
00359   private:
00367         T& m_Value;
00368 
00376         T  m_Dummy;
00377 
00385         T* m_Tmp;
00386 
00394         RingBuffer<T> m_Buffer;
00395 
00396   };
00397   
00398 }; // End of namesepace RTM
00399 
00400 #endif // RtcInPort_h

Generated on Sat Oct 28 02:28:13 2006 for OpenRTM by  doxygen 1.4.1