メインページ | ネームスペース一覧 | クラス階層 | 構成 | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ

RtcOutPort.h

説明を見る。
00001 // -*- C++ -*-
00021 #ifndef __RtcOutPort_h__
00022 #define __RtcOutPort_h__
00023 
00024 #define ACE_HAS_CLOCK_GETTIME
00025 
00026 #include "rtm/RtcOutPortBase.h"
00027 #include "rtm/idl/RTCDataTypeSkel.h"
00028 #include <ace/OS.h>
00029 #include <ace/Time_Value.h>
00030 #include <iostream>
00031 
00032 #define DEFAULT_BUFFER_SIZE 64
00033 
00034 namespace RTM {
00062   template <class T> class OutPortAny
00063         : public OutPortBase
00064   {
00065   public:
00091         OutPortAny(const char* name, T& value, int bufsize=DEFAULT_BUFFER_SIZE)
00092           : m_Buffer(bufsize, value), m_Value(value)
00093         {
00094           // Set PortProfile
00095           m_Profile.name = CORBA::string_dup(name);
00096           CORBA::Any var;
00097           var <<= m_Value;
00098           m_Profile.port_type = var.type();
00099           
00100           // Initializing ring buffer
00101           for (int i = 0 ; i < m_Buffer.buff_length(); i++)
00102                 {
00103                   m_Buffer.put(m_Value);
00104                 }
00105         }
00106         
00130         OutPortAny(const char* name, int bufsize=DEFAULT_BUFFER_SIZE)
00131           : m_Buffer(bufsize, m_Dummy), m_Value(m_Dummy)
00132         {
00133           // Set PortProfile
00134           m_Profile.name = CORBA::string_dup(name);
00135           CORBA::Any var;
00136           var <<= m_Value;
00137           m_Profile.port_type = var.type();
00138           
00139           // Initializing ring buffer
00140           for (int i = 0 ; i < m_Buffer.buff_length(); i++)
00141                 {
00142                   m_Buffer.put(m_Value);
00143                 }
00144         }
00145         
00146         
00160         virtual ~OutPortAny(){};
00161         
00175         CORBA::Any* get()
00176           throw (CORBA::SystemException)
00177         {
00178           ACE_TRACE("OutPortBase::get()");
00179           CORBA::Any_var tmp = new CORBA::Any();
00180           tmp <<= m_Buffer.get_new();
00181           return tmp._retn();
00182         }
00183         
00197         //      RtmRes push(const InPort_ptr& inport, SubscriptionID subsid)
00198         RtmRes push(const InPort_ptr& inport, std::string& subsid)
00199         {
00200           ACE_TRACE("OutPortBase::push()");
00201           
00202           if (CORBA::is_nil(inport)) 
00203                 {
00204                   ACE_DEBUG((LM_DEBUG, "Invalid object reference: inport"));
00205                   return RTM_ERR;
00206                 }
00207 
00208           try
00209                 {
00210                   CORBA::Any val;
00211                   val <<= m_Buffer.get_new();
00212                   
00213                   if (inport != NULL)
00214                         {
00215                           inport->put(val);
00216                         }
00217                 }
00218           catch(CORBA::SystemException& e)
00219                 {
00220                   //              cout << "push(): CORBA System Exception." << endl;
00221 
00222                   // Subscribers already locked
00223                   unsubscribeNoLocked(subsid.c_str());
00224                   return RTM_ERR;
00225                 }
00226           catch(RTM::InPort::Disconnected& e)
00227                 {
00228                   //              ACE_DEBUG((LM_DEBUG, "Disconnected."));
00229 
00230                   // Subscribers already locked
00231                   unsubscribeNoLocked(subsid.c_str());
00232                   return RTM_ERR;
00233                 }
00234           return RTM_OK;
00235         }
00236         
00237         
00238         
00252         virtual void initBuffer(T& value)
00253         {
00254           for (int i = 0 ; i <= m_Buffer.buff_length(); i++)
00255                 {
00256                   m_Buffer.put(value);
00257                 }
00258         }
00259         
00260         
00275         virtual void write()
00276         {
00277           struct timespec ts;
00278           ACE_OS::clock_gettime(CLOCK_REALTIME, &ts);
00279           m_Value.tm.sec = ts.tv_sec;
00280           m_Value.tm.nsec = ts.tv_nsec;
00281           m_Buffer.put(m_Value);
00282           updateall();
00283         };
00284 
00285 
00302         virtual void write_pm()
00303         {
00304           write();
00305         };
00306         
00307         
00327         virtual void write(T value)
00328         {
00329           struct timespec ts;
00330           ACE_OS::clock_gettime(CLOCK_REALTIME, &ts);
00331           value.tm.sec = ts.tv_sec;
00332           value.tm.nsec = ts.tv_nsec;
00333           m_Buffer.put(value);
00334           updateall();
00335         };
00336         
00337         
00357         virtual void operator<<(T& value)
00358         {
00359           struct timespec ts;
00360           ACE_OS::clock_gettime(CLOCK_REALTIME, &ts);
00361           value.tm.sec = ts.tv_sec;
00362           value.tm.nsec = ts.tv_nsec;
00363           m_Buffer.put(value);
00364           updateall();
00365         }
00366         
00367         
00368   private:
00376         T& m_Value;
00377         
00385         T m_Dummy;
00386         
00394         RingBuffer<T> m_Buffer;
00395   };
00396   
00397 }; // End of namesepace RTM
00398 
00399 #endif // __RtcOutputChannel_h__

OpenRTMに対してWed Apr 6 14:22:11 2005に生成されました。 doxygen 1.3.6