ConfigSample.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include "ConfigSample.h"
00011 #include "VectorConvert.h"
00012 
00013 // Module specification
00014 // <rtc-template block="module_spec">
00015 static const char* configsample_spec[] =
00016   {
00017     "implementation_id", "ConfigSample",
00018     "type_name",         "ConfigSample",
00019     "description",       "Configuration example component",
00020     "version",           "1.0",
00021     "vendor",            "Noriaki Ando, AIST",
00022     "category",          "example",
00023     "activity_type",     "DataFlowComponent",
00024     "max_instance",      "10",
00025     "language",          "C++",
00026     "lang_type",         "compile",
00027     // Configuration variables
00028     "conf.default.int_param0", "0",
00029     "conf.default.int_param1", "1",
00030     "conf.default.double_param0", "0.11",
00031     "conf.default.double_param1", "9.9",
00032     "conf.default.str_param0", "hoge",
00033     "conf.default.str_param1", "dara",
00034     "conf.default.vector_param0", "0.0,1.0,2.0,3.0,4.0",
00035 
00036     ""
00037   };
00038 // </rtc-template>
00039 
00040 char ticktack()
00041 {
00042   static int i(0);
00043   const char* c = "/-\\|";
00044   i = (i + 1) % 4;
00045   return c[i];
00046 }
00047 
00048 
00049 ConfigSample::ConfigSample(RTC::Manager* manager)
00050   : RTC::DataFlowComponentBase(manager)
00051     // <rtc-template block="initializer">
00052     
00053     // </rtc-template>
00054 {
00055 }
00056 
00057 ConfigSample::~ConfigSample()
00058 {
00059 }
00060 
00061 
00062 RTC::ReturnCode_t ConfigSample::onInitialize()
00063 {
00064   // Registration: InPort/OutPort/Service
00065   // <rtc-template block="registration">
00066   // Set InPort buffers
00067   
00068   // Set OutPort buffer
00069   
00070   // Set service provider to Ports
00071   
00072   // Set service consumers to Ports
00073   
00074   // Set CORBA Service Ports
00075   
00076   // </rtc-template>
00077 
00078   // <rtc-template block="bind_config">
00079   // Bind variables and configuration variable
00080   bindParameter("int_param0", m_int_param0, "0");
00081   bindParameter("int_param1", m_int_param1, "1");
00082   bindParameter("double_param0", m_double_param0, "0.11");
00083   bindParameter("double_param1", m_double_param1, "9.9");
00084   bindParameter("str_param0", m_str_param0, "hoge");
00085   bindParameter("str_param1", m_str_param1, "dara");
00086   bindParameter("vector_param0", m_vector_param0, "0.0,1.0,2.0,3.0,4.0");
00087   
00088   // </rtc-template>
00089 
00090   std::cout << std::endl;
00091   std::cout << "Please change configuration values from RtcLink" << std::endl; 
00092   std::cout << std::endl;
00093 
00094   return RTC::RTC_OK;
00095 }
00096 
00097 
00098 
00099 /*
00100 RTC::ReturnCode_t ConfigSample::onFinalize()
00101 {
00102   return RTC::RTC_OK;
00103 }
00104 */
00105 
00106 /*
00107 RTC::ReturnCode_t ConfigSample::onStartup(RTC::UniqueId ec_id)
00108 {
00109   return RTC::RTC_OK;
00110 }
00111 */
00112 
00113 /*
00114 RTC::ReturnCode_t ConfigSample::onShutdown(RTC::UniqueId ec_id)
00115 {
00116   return RTC::RTC_OK;
00117 }
00118 */
00119 
00120 /*
00121 RTC::ReturnCode_t ConfigSample::onActivated(RTC::UniqueId ec_id)
00122 {
00123   return RTC::RTC_OK;
00124 }
00125 */
00126 
00127 /*
00128 RTC::ReturnCode_t ConfigSample::onDeactivated(RTC::UniqueId ec_id)
00129 {
00130   return RTC::RTC_OK;
00131 }
00132 */
00133 
00134 
00135 RTC::ReturnCode_t ConfigSample::onExecute(RTC::UniqueId ec_id)
00136 {
00137   static int  maxlen(0);
00138   int curlen(0);
00139   const char* c = "                    ";
00140   if (true)
00141     {
00142       std::cout << "---------------------------------------" << std::endl;
00143       std::cout << " Active Configuration Set: ";
00144       std::cout << m_configsets.getActiveId() << c << std::endl;
00145       std::cout << "---------------------------------------" << std::endl;
00146       
00147       std::cout << "int_param0:       " << m_int_param0 << c << std::endl;
00148       std::cout << "int_param1:       " << m_int_param1 << c << std::endl;
00149       std::cout << "double_param0:    " << m_double_param0 << c << std::endl;
00150       std::cout << "double_param1:    " << m_double_param1 << c << std::endl;
00151       std::cout << "str_param0:       " << m_str_param0 << c << std::endl;
00152       std::cout << "str_param1:       " << m_str_param1 << c << std::endl;
00153       for (int i(0), len(m_vector_param0.size()); i < len; ++i)
00154         {
00155           std::cout << "vector_param0[" << i << "]: ";
00156           std::cout << m_vector_param0[i] << c << std::endl;
00157         }
00158       std::cout << "---------------------------------------" << std::endl;
00159 
00160       curlen = m_vector_param0.size();
00161       maxlen = maxlen > curlen ? maxlen : curlen;
00162       for (int i(0), len(maxlen - curlen); i < len; ++i)
00163         {
00164           std::cout << c << c << std::endl;
00165         }
00166 
00167       std::cout << "Updating.... " << ticktack() << c << std::endl;
00168 
00169       for (int i(0), len(11 + maxlen); i < len; ++i)
00170         {
00171           std::cout << "\r";
00172         }
00173     }
00174   if (m_int_param0 > 1000 && m_int_param0 < 1000000)
00175     {
00176       coil::usleep(m_int_param0);
00177     }
00178   else
00179     {
00180       coil::usleep(100000);
00181     }
00182   return RTC::RTC_OK;
00183 }
00184 
00185 
00186 /*
00187 RTC::ReturnCode_t ConfigSample::onAborting(RTC::UniqueId ec_id)
00188 {
00189   return RTC::RTC_OK;
00190 }
00191 */
00192 
00193 /*
00194 RTC::ReturnCode_t ConfigSample::onError(RTC::UniqueId ec_id)
00195 {
00196   return RTC::RTC_OK;
00197 }
00198 */
00199 
00200 /*
00201 RTC::ReturnCode_t ConfigSample::onReset(RTC::UniqueId ec_id)
00202 {
00203   return RTC::RTC_OK;
00204 }
00205 */
00206 
00207 /*
00208 RTC::ReturnCode_t ConfigSample::onStateUpdate(RTC::UniqueId ec_id)
00209 {
00210   return RTC::RTC_OK;
00211 }
00212 */
00213 
00214 /*
00215 RTC::ReturnCode_t ConfigSample::onRateChanged(RTC::UniqueId ec_id)
00216 {
00217   return RTC::RTC_OK;
00218 }
00219 */
00220 
00221 
00222 
00223 extern "C"
00224 {
00225  
00226   void ConfigSampleInit(RTC::Manager* manager)
00227   {
00228     coil::Properties profile(configsample_spec);
00229     manager->registerFactory(profile,
00230                              RTC::Create<ConfigSample>,
00231                              RTC::Delete<ConfigSample>);
00232   }
00233   
00234 };
00235 
00236 


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:37