00001
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef RtcOutPort_h
00028 #define RtcOutPort_h
00029
00030 #define ACE_HAS_CLOCK_GETTIME
00031
00032 #include "rtm/RtcOutPortBase.h"
00033 #include "rtm/idl/RTCDataTypeSkel.h"
00034 #include <ace/OS.h>
00035 #include <ace/Time_Value.h>
00036 #include <iostream>
00037
00038 #define DEFAULT_BUFFER_SIZE 64
00039
00040 namespace RTM {
00068 template <class T> class OutPortAny
00069 : public OutPortBase
00070 {
00071 public:
00097 OutPortAny(const char* name, T& value, int bufsize=DEFAULT_BUFFER_SIZE)
00098 : m_Buffer(bufsize, value), m_Value(value)
00099 {
00100
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
00107 for (int i = 0 ; i < m_Buffer.buff_length(); i++)
00108 {
00109 m_Buffer.put(m_Value);
00110 }
00111 }
00112
00136 OutPortAny(const char* name, int bufsize=DEFAULT_BUFFER_SIZE)
00137 : m_Buffer(bufsize, m_Dummy), m_Value(m_Dummy)
00138 {
00139
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
00146 for (int i = 0 ; i < m_Buffer.buff_length(); i++)
00147 {
00148 m_Buffer.put(m_Value);
00149 }
00150 }
00151
00152
00166 virtual ~OutPortAny(){};
00167
00181 CORBA::Any* get()
00182 throw (CORBA::SystemException)
00183 {
00184 ACE_TRACE("OutPortBase::get()");
00185 CORBA::Any_var tmp = new CORBA::Any();
00186 tmp <<= m_Buffer.get_new();
00187 return tmp._retn();
00188 }
00189
00203
00204 RtmRes push(const InPort_ptr& inport, std::string& subsid)
00205 {
00206 ACE_TRACE("OutPortBase::push()");
00207
00208 if (CORBA::is_nil(inport))
00209 {
00210 ACE_DEBUG((LM_DEBUG, "Invalid object reference: inport"));
00211 return RTM_ERR;
00212 }
00213
00214 try
00215 {
00216 CORBA::Any val;
00217 val <<= m_Buffer.get_new();
00218
00219 if (inport != NULL)
00220 {
00221 inport->put(val);
00222 }
00223 }
00224 catch(CORBA::SystemException& e)
00225 {
00226
00227
00228
00229 unsubscribeNoLocked(subsid.c_str());
00230 return RTM_ERR;
00231 }
00232 catch(RTM::InPort::Disconnected& e)
00233 {
00234
00235
00236
00237 unsubscribeNoLocked(subsid.c_str());
00238 return RTM_ERR;
00239 }
00240 return RTM_OK;
00241 }
00242
00243
00244
00258 virtual void initBuffer(T& value)
00259 {
00260 for (int i = 0 ; i <= m_Buffer.buff_length(); i++)
00261 {
00262 m_Buffer.put(value);
00263 }
00264 }
00265
00266
00281 virtual void write()
00282 {
00283 struct timespec ts;
00284 ACE_OS::clock_gettime(CLOCK_REALTIME, &ts);
00285 m_Value.tm.sec = ts.tv_sec;
00286 m_Value.tm.nsec = ts.tv_nsec;
00287 m_Buffer.put(m_Value);
00288 updateall();
00289 };
00290
00291
00308 virtual void write_pm()
00309 {
00310 write();
00311 };
00312
00313
00333 virtual void write(T value)
00334 {
00335 struct timespec ts;
00336 ACE_OS::clock_gettime(CLOCK_REALTIME, &ts);
00337 value.tm.sec = ts.tv_sec;
00338 value.tm.nsec = ts.tv_nsec;
00339 m_Buffer.put(value);
00340 updateall();
00341 };
00342
00343
00363 virtual void operator<<(T& value)
00364 {
00365 struct timespec ts;
00366 ACE_OS::clock_gettime(CLOCK_REALTIME, &ts);
00367 value.tm.sec = ts.tv_sec;
00368 value.tm.nsec = ts.tv_nsec;
00369 m_Buffer.put(value);
00370 updateall();
00371 }
00372
00373
00374 private:
00382 T& m_Value;
00383
00391 T m_Dummy;
00392
00400 RingBuffer<T> m_Buffer;
00401 };
00402
00403 };
00404
00405 #endif // RtcOutputChannel_h