SeqIn.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "SeqIn.h"
00011 #include <iostream>
00012 
00013 // Connector Listener Dump Flag
00014 bool g_Listener_dump_enabled = false;
00015 
00016 // Module specification
00017 // <rtc-template block="module_spec">
00018 static const char* seqin_spec[] =
00019   {
00020     "implementation_id", "SeqIn",
00021     "type_name",         "SequenceInComponent",
00022     "description",       "Sequence InPort component",
00023     "version",           "1.0",
00024     "vendor",            "Noriaki Ando, AIST",
00025     "category",          "example",
00026     "activity_type",     "DataFlowComponent",
00027     "max_instance",      "10",
00028     "language",          "C++",
00029     "lang_type",         "compile",
00030     ""
00031   };
00032 // </rtc-template>
00033 
00034 SeqIn::SeqIn(RTC::Manager* manager)
00035   : RTC::DataFlowComponentBase(manager),
00036     // <rtc-template block="initializer">
00037     m_OctetIn("Octet", m_Octet),
00038     m_ShortIn("Short", m_Short),
00039     m_LongIn("Long", m_Long),
00040     m_FloatIn("Float", m_Float),
00041     m_DoubleIn("Double", m_Double),
00042     m_OctetSeqIn("OctetSeq", m_OctetSeq),
00043     m_ShortSeqIn("ShortSeq", m_ShortSeq),
00044     m_LongSeqIn("LongSeq", m_LongSeq),
00045     m_FloatSeqIn("FloatSeq", m_FloatSeq),
00046     m_DoubleSeqIn("DoubleSeq", m_DoubleSeq)
00047     
00048     // </rtc-template>
00049 {
00050 }
00051 
00052 SeqIn::~SeqIn()
00053 {
00054 }
00055 
00056 
00057 
00058 RTC::ReturnCode_t SeqIn::onInitialize()
00059 {
00060   // Registration: InPort/OutPort/Service
00061   // <rtc-template block="registration">
00062   // Set InPort buffers
00063   addInPort("Octet", m_OctetIn);
00064   addInPort("Short", m_ShortIn);
00065   addInPort("Long", m_LongIn);
00066   addInPort("Float", m_FloatIn);
00067   addInPort("Double", m_DoubleIn);
00068   addInPort("OctetSeq", m_OctetSeqIn);
00069   addInPort("ShortSeq", m_ShortSeqIn);
00070   addInPort("LongSeq", m_LongSeqIn);
00071   addInPort("FloatSeq", m_FloatSeqIn);
00072   addInPort("DoubleSeq", m_DoubleSeqIn);
00073   
00074   // check m_LongIn port only
00075   m_LongIn.addConnectorDataListener(ON_BUFFER_WRITE,
00076                                     new DataListener("ON_BUFFER_WRITE"));
00077   m_LongIn.addConnectorDataListener(ON_BUFFER_FULL, 
00078                                     new DataListener("ON_BUFFER_FULL"));
00079   m_LongIn.addConnectorDataListener(ON_BUFFER_WRITE_TIMEOUT, 
00080                                     new DataListener("ON_BUFFER_WRITE_TIMEOUT"));
00081   m_LongIn.addConnectorDataListener(ON_BUFFER_OVERWRITE, 
00082                                     new DataListener("ON_BUFFER_OVERWRITE"));
00083   m_LongIn.addConnectorDataListener(ON_BUFFER_READ, 
00084                                     new DataListener("ON_BUFFER_READ"));
00085   m_LongIn.addConnectorDataListener(ON_SEND, 
00086                                     new DataListener("ON_SEND"));
00087   m_LongIn.addConnectorDataListener(ON_RECEIVED,
00088                                     new DataListener("ON_RECEIVED"));
00089   m_LongIn.addConnectorDataListener(ON_RECEIVER_FULL, 
00090                                     new DataListener("ON_RECEIVER_FULL"));
00091   m_LongIn.addConnectorDataListener(ON_RECEIVER_TIMEOUT, 
00092                                     new DataListener("ON_RECEIVER_TIMEOUT"));
00093 
00094   m_LongIn.addConnectorListener(ON_BUFFER_EMPTY,
00095                                     new ConnListener("ON_BUFFER_EMPTY"));
00096   m_LongIn.addConnectorListener(ON_BUFFER_READ_TIMEOUT,
00097                                     new ConnListener("ON_BUFFER_READ_TIMEOUT"));
00098   m_LongIn.addConnectorListener(ON_SENDER_EMPTY,
00099                                     new ConnListener("ON_SENDER_EMPTY"));
00100   m_LongIn.addConnectorListener(ON_SENDER_TIMEOUT,
00101                                     new ConnListener("ON_SENDER_TIMEOUT"));
00102   m_LongIn.addConnectorListener(ON_SENDER_ERROR,
00103                                     new ConnListener("ON_SENDER_ERROR"));
00104   m_LongIn.addConnectorListener(ON_CONNECT,
00105                                     new ConnListener("ON_CONNECT"));
00106   m_LongIn.addConnectorListener(ON_DISCONNECT,
00107                                     new ConnListener("ON_DISCONNECT"));
00108 
00109   // Set OutPort buffer
00110   
00111   // Set service provider to Ports
00112   
00113   // Set service consumers to Ports
00114   
00115   // Set CORBA Service Ports
00116   
00117   // </rtc-template>
00118 
00119   return RTC::RTC_OK;
00120 }
00121 
00122 
00123 /*
00124 RTC::ReturnCode_t SeqIn::onFinalize()
00125 {
00126   return RTC::RTC_OK;
00127 }
00128 */
00129 
00130 /*
00131 RTC::ReturnCode_t SeqIn::onStartup(RTC::UniqueId ec_id)
00132 {
00133   return RTC::RTC_OK;
00134 }
00135 */
00136 
00137 /*
00138 RTC::ReturnCode_t SeqIn::onShutdown(RTC::UniqueId ec_id)
00139 {
00140   return RTC::RTC_OK;
00141 }
00142 */
00143 
00144 /*
00145 RTC::ReturnCode_t SeqIn::onActivated(RTC::UniqueId ec_id)
00146 {
00147   return RTC::RTC_OK;
00148 }
00149 */
00150 
00151 /*
00152 RTC::ReturnCode_t SeqIn::onDeactivated(RTC::UniqueId ec_id)
00153 {
00154   return RTC::RTC_OK;
00155 }
00156 */
00157 
00158 
00159 RTC::ReturnCode_t SeqIn::onExecute(RTC::UniqueId ec_id)
00160 {
00161   m_DoubleIn.read();
00162   m_FloatIn.read();
00163   m_LongIn.read();
00164   m_ShortIn.read();
00165   m_OctetIn.read();
00166   m_DoubleSeqIn.read();
00167   m_FloatSeqIn.read();
00168   m_LongSeqIn.read();
00169   m_ShortSeqIn.read();
00170   m_OctetSeqIn.read();
00171   
00172   int h_col(4);
00173   int col(13);
00174   int all_col = h_col + (col * 5);
00175   int all_row(0);
00176   
00177   int d_size(1);
00178   int f_size(1);
00179   int l_size(1);
00180   int s_size(1);
00181   int o_size(1);
00182   
00183   int ds_size(m_DoubleSeq.data.length());
00184   int fs_size(m_FloatSeq.data.length());
00185   int ls_size(m_LongSeq.data.length());
00186   int ss_size(m_ShortSeq.data.length());
00187   int os_size(m_OctetSeq.data.length());
00188   
00189   int max_size;
00190   
00191   std::vector<int> in_size;
00192   std::vector<int>::iterator it;
00193   in_size.reserve(10);
00194   in_size.push_back(d_size);
00195   in_size.push_back(f_size);
00196   in_size.push_back(l_size);
00197   in_size.push_back(s_size);
00198   in_size.push_back(o_size);
00199   in_size.push_back(ds_size);
00200   in_size.push_back(fs_size);
00201   in_size.push_back(ls_size);
00202   in_size.push_back(ss_size);
00203   in_size.push_back(os_size);
00204   
00205   it = std::max_element(in_size.begin(), in_size.end());
00206   
00207   max_size = *it;
00208   
00209   std::cout.width(h_col + (col * 5));
00210   std::cout.fill('-');
00211   std::cout << "-" << std::endl; all_row++;
00212   
00213   std::cout.width(h_col);
00214   std::cout.setf(std::ios::right, std::ios::adjustfield);
00215   std::cout.fill(' ');
00216   std::cout << " ";   
00217   std::cout.width(col);
00218   std::cout.setf(std::ios::right, std::ios::adjustfield);
00219   std::cout.fill(' ');
00220   std::cout << "Double";
00221   std::cout.width(col);
00222   std::cout.setf(std::ios::right, std::ios::adjustfield);
00223   std::cout.fill(' ');
00224   std::cout << "Float";
00225   std::cout.width(col);
00226   std::cout.setf(std::ios::right, std::ios::adjustfield);
00227   std::cout.fill(' ');
00228   std::cout << "Long";
00229   std::cout.width(col);
00230   std::cout.setf(std::ios::right, std::ios::adjustfield);
00231   std::cout.fill(' ');
00232   std::cout << "Short";
00233   std::cout.width(col);
00234   std::cout.setf(std::ios::right, std::ios::adjustfield);
00235   std::cout.fill(' ');
00236   std::cout << "Octet";
00237   std::cout << std::endl; all_row++;
00238   
00239   std::cout.width(all_col);
00240   std::cout.fill('-');
00241   std::cout << "-" << std::endl;  all_row++;
00242   
00243   for (int i = 0; i < (all_col - 10)/ 2; i++)
00244     std::cout << " ";
00245   std::cout << "Basic type";
00246   for (int i = 0; i < (all_col - 10)/ 2; i++)
00247     std::cout << " ";
00248   std::cout << std::endl; all_row++;
00249   
00250   std::cout.width(h_col + (col * 5));
00251   std::cout.fill('-');
00252   std::cout << "-" << std::endl; all_row++;
00253   
00254   std::cout.width(h_col);
00255   std::cout.setf(std::ios::right, std::ios::adjustfield);
00256   std::cout.fill(' ');
00257   std::cout << " ";   
00258   std::cout.width(col);
00259   std::cout.setf(std::ios::right, std::ios::adjustfield);
00260   std::cout.fill(' ');
00261   std::cout << m_Double.data;
00262   std::cout.width(col);
00263   std::cout.setf(std::ios::right, std::ios::adjustfield);
00264   std::cout.fill(' ');
00265   std::cout << m_Float.data;
00266   std::cout.width(col);
00267   std::cout.setf(std::ios::right, std::ios::adjustfield);
00268   std::cout.fill(' ');
00269   std::cout << m_Long.data;
00270   std::cout.width(col);
00271   std::cout.setf(std::ios::right, std::ios::adjustfield);
00272   std::cout.fill(' ');
00273   std::cout << m_Short.data;
00274   std::cout.width(col);
00275   std::cout.setf(std::ios::right, std::ios::adjustfield);
00276   std::cout.fill(' ');
00277   std::cout << int(m_Octet.data) << "[";
00278   if (int(m_Octet.data) < 0x20 || int(m_Octet.data) > 0x7e)
00279     {
00280       std::cout << " " << "]";
00281     }
00282   else
00283     {
00284       std::cout << m_Octet.data << "]";
00285     }
00286   std::cout << std::endl; all_row++;
00287   
00288   std::cout.width(all_col);
00289   std::cout.fill('-');
00290   std::cout << "-" << std::endl; all_row++;
00291   
00292   for (int i = 0; i < (all_col - 13)/ 2; i++)
00293     std::cout << " ";
00294   std::cout << "Sequence type";
00295   for (int i = 0; i < (all_col - 13)/ 2; i++)
00296     std::cout << " ";
00297   std::cout << std::endl; all_row++;
00298   
00299   std::cout.width(all_col);
00300   std::cout.fill('-');
00301   std::cout << "-" << std::endl; all_row++;
00302   
00303   for (int i = 0; i < max_size; i++)
00304     {
00305       std::cout.width(h_col - 2);
00306       std::cout.setf(std::ios::right, std::ios::adjustfield);
00307       std::cout.fill(' ');
00308       std::cout << i;
00309       std::cout.width(2);
00310       std::cout << ": ";
00311       
00312       std::cout.width(col);
00313       std::cout.setf(std::ios::right, std::ios::adjustfield);
00314       std::cout.fill(' ');
00315       if (i < ds_size)
00316         {
00317           std::cout << m_DoubleSeq.data[i];
00318         }
00319       else
00320         {
00321           std::cout << "-";
00322         }
00323       
00324       std::cout.width(col);
00325       std::cout.setf(std::ios::right, std::ios::adjustfield);
00326       std::cout.fill(' ');
00327       if (i < fs_size)
00328         {
00329           std::cout << m_FloatSeq.data[i];
00330         }
00331       else
00332         {
00333           std::cout << "-";
00334         }
00335       
00336       std::cout.width(col);
00337       std::cout.setf(std::ios::right, std::ios::adjustfield);
00338       std::cout.fill(' ');
00339       if (i < ls_size)
00340         {
00341           std::cout << m_LongSeq.data[i];
00342         }
00343       else
00344         {
00345           std::cout << "-";
00346         }
00347       
00348       std::cout.width(col);
00349       std::cout.setf(std::ios::right, std::ios::adjustfield);
00350       std::cout.fill(' ');
00351       if (i < ss_size)
00352         {
00353           std::cout << m_ShortSeq.data[i];
00354         }
00355       else
00356         {
00357           std::cout << "-";
00358         }
00359 
00360       std::cout.width(col);
00361       std::cout.setf(std::ios::right, std::ios::adjustfield);
00362       std::cout.fill(' ');
00363       if (i < os_size)
00364        {
00365          std::cout << int(m_OctetSeq.data[i]) << "[";
00366          if (int(m_OctetSeq.data[i]) < 0x20 || int(m_OctetSeq.data[i]) > 0x7e)
00367            {
00368              std::cout << " " << "]";
00369            }
00370          else
00371            {
00372              std::cout << m_OctetSeq.data[i] << "]";
00373            }
00374        }
00375       else
00376        {
00377          std::cout << "-";
00378        }
00379          
00380       std::cout << std::endl; all_row++;
00381     }
00382   
00383   // Connector Listener Dump check
00384   if(!g_Listener_dump_enabled)
00385     {
00386       for (int i = 0 ; i < all_row; i++)
00387         {
00388           std::cout << "\r";
00389         }
00390     }
00391 
00392   return RTC::RTC_OK;
00393 }
00394 
00395 
00396 /*
00397 RTC::ReturnCode_t SeqIn::onAborting(RTC::UniqueId ec_id)
00398 {
00399   return RTC::RTC_OK;
00400 }
00401 */
00402 
00403 /*
00404 RTC::ReturnCode_t SeqIn::onError(RTC::UniqueId ec_id)
00405 {
00406   return RTC::RTC_OK;
00407 }
00408 */
00409 
00410 /*
00411 RTC::ReturnCode_t SeqIn::onReset(RTC::UniqueId ec_id)
00412 {
00413   return RTC::RTC_OK;
00414 }
00415 */
00416 
00417 /*
00418 RTC::ReturnCode_t SeqIn::onStateUpdate(RTC::UniqueId ec_id)
00419 {
00420   return RTC::RTC_OK;
00421 }
00422 */
00423 
00424 /*
00425 RTC::ReturnCode_t SeqIn::onRateChanged(RTC::UniqueId ec_id)
00426 {
00427   return RTC::RTC_OK;
00428 }
00429 */
00430 
00431 
00432 
00433 extern "C"
00434 {
00435  
00436   void SeqInInit(RTC::Manager* manager)
00437   {
00438     coil::Properties profile(seqin_spec);
00439     manager->registerFactory(profile,
00440                              RTC::Create<SeqIn>,
00441                              RTC::Delete<SeqIn>);
00442   }
00443   
00444 };


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17