MyServiceConsumer.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include "MyServiceConsumer.h"
11 #include <rtm/CORBA_SeqUtil.h>
12 #include <vector>
13 #include <stdlib.h>
14 #include <coil/Async.h>
15 #include <functional>
16 
17 // Module specification
18 // <rtc-template block="module_spec">
19 static const char* myserviceconsumer_spec[] =
20  {
21  "implementation_id", "MyServiceConsumer",
22  "type_name", "MyServiceConsumer",
23  "description", "MyService Consumer Sample component",
24  "version", "0.1",
25  "vendor", "AIST",
26  "category", "Generic",
27  "activity_type", "DataFlowComponent",
28  "max_instance", "10",
29  "language", "C++",
30  "lang_type", "compile",
31  ""
32  };
33 // </rtc-template>
34 
36  : RTC::DataFlowComponentBase(manager),
37  // <rtc-template block="initializer">
38  m_MyServicePort("MyService"),
39  // </rtc-template>
40  async_set_value(0), async_echo(0)
41 {
42 }
43 
45 {
46 }
47 
48 
50 {
51  // Registration: InPort/OutPort/Service
52  // <rtc-template block="registration">
53  // Set InPort buffers
54 
55  // Set OutPort buffer
56 
57  // Set service provider to Ports
58 
59  // Set service consumers to Ports
60  m_MyServicePort.registerConsumer("myservice0", "MyService", m_myservice0);
61 
62  // Set CORBA Service Ports
64 
65  // </rtc-template>
66 
67  return RTC::RTC_OK;
68 }
69 
70 /*
71 RTC::ReturnCode_t MyServiceConsumer::onFinalize()
72 {
73  return RTC::RTC_OK;
74 }
75 */
76 
77 /*
78 RTC::ReturnCode_t MyServiceConsumer::onStartup(RTC::UniqueId ec_id)
79 {
80  return RTC::RTC_OK;
81 }
82 */
83 
84 /*
85 RTC::ReturnCode_t MyServiceConsumer::onShutdown(RTC::UniqueId ec_id)
86 {
87  return RTC::RTC_OK;
88 }
89 */
90 
91 /*
92 RTC::ReturnCode_t MyServiceConsumer::onActivated(RTC::UniqueId ec_id)
93 {
94  return RTC::RTC_OK;
95 }
96 */
97 
98 /*
99 RTC::ReturnCode_t MyServiceConsumer::onDeactivated(RTC::UniqueId ec_id)
100 {
101  return RTC::RTC_OK;
102 }
103 */
104 
105 
107 {
108  try
109  {
110  std::cout << std::endl;
111  std::cout << "Command list: " << std::endl;
112  std::cout << " echo [msg] : echo message." << std::endl;
113  std::cout << " set_value [value]: set value." << std::endl;
114  std::cout << " get_value : get current value." << std::endl;
115  std::cout << " get_echo_history : get input messsage history." << std::endl;
116  std::cout << " get_value_history: get input value history." << std::endl;
117  std::cout << "> ";
118 
119  std::string args;
120  std::string::size_type pos;
121  std::vector<std::string> argv;
122  std::getline(std::cin, args);
123 
124  pos = args.find_first_of(" ");
125  if (pos != std::string::npos)
126  {
127  argv.push_back(args.substr(0, pos));
128  argv.push_back(args.substr(++pos));
129  }
130  else
131  {
132  argv.push_back(args);
133  }
134 
135  if (async_echo != 0 && async_echo->finished())
136  {
137  std::cout << "echo() finished: " << m_result << std::endl;
138  delete async_echo;
139  async_echo = 0;
140  }
141 
142  if (argv[0] == "echo" && argv.size() > 1)
143  {
144  if (async_echo == 0)
145  {
146  // char* retmsg;
147  // retmsg = m_myservice0->echo(argv[1].c_str());
148  async_echo =
150  echo_functor(argv[1], m_result));
151  async_echo->invoke();
152  // std::cout << "echo return: " << retmsg << std::endl;
153  }
154  else
155  {
156  std::cout << "set_value() still invoking" << std::endl;
157  }
158  return RTC::RTC_OK;
159  }
160 
161  if (argv[0] == "set_value" && argv.size() > 1)
162  {
163  CORBA::Float val(atof(argv[1].c_str()));
165  true)->invoke();
166  std::cout << "Set remote value: " << val << std::endl;
167 
168  return RTC::RTC_OK;
169  }
170 
171  if (argv[0] == "get_value")
172  {
173  std::cout << "Current remote value: "
174  << m_myservice0->get_value() << std::endl;
175  return RTC::RTC_OK;
176  }
177 
178  if (argv[0] == "get_echo_history")
179  {
180  CORBA_SeqUtil::for_each(*(m_myservice0->get_echo_history()),
182  return RTC::RTC_OK;
183  }
184 
185  if (argv[0] == "get_value_history")
186  {
187  CORBA_SeqUtil::for_each(*(m_myservice0->get_value_history()),
189  return RTC::RTC_OK;
190  }
191 
192  std::cout << "Invalid command or argument(s)." << std::endl;
193  }
194  catch (...)
195  {
196  std::cout << "No service connected." << std::endl;
197  }
198  return RTC::RTC_OK;
199 }
200 
201 
202 /*
203 RTC::ReturnCode_t MyServiceConsumer::onAborting(RTC::UniqueId ec_id)
204 {
205  return RTC::RTC_OK;
206 }
207 */
208 
209 /*
210 RTC::ReturnCode_t MyServiceConsumer::onError(RTC::UniqueId ec_id)
211 {
212  return RTC::RTC_OK;
213 }
214 */
215 
216 /*
217 RTC::ReturnCode_t MyServiceConsumer::onReset(RTC::UniqueId ec_id)
218 {
219  return RTC::RTC_OK;
220 }
221 */
222 
223 /*
224 RTC::ReturnCode_t MyServiceConsumer::onStateUpdate(RTC::UniqueId ec_id)
225 {
226  return RTC::RTC_OK;
227 }
228 */
229 
230 /*
231 RTC::ReturnCode_t MyServiceConsumer::onRateChanged(RTC::UniqueId ec_id)
232 {
233  return RTC::RTC_OK;
234 }
235 */
236 
237 
238 
239 extern "C"
240 {
241 
243  {
245  manager->registerFactory(profile,
246  RTC::Create<MyServiceConsumer>,
247  RTC::Delete<MyServiceConsumer>);
248  }
249 
250 };
251 
252 
virtual bool finished()=0
Check on completion state.
virtual RTC::ReturnCode_t onInitialize()
Callback function to initialize.
RT-Component.
DataFlowComponentBase class.
MyServiceConsumer(RTC::Manager *manager)
ReturnCode_t
Definition: doil.h:53
coil::Async * async_echo
Manager class.
Definition: Manager.h:80
RTC::CorbaPort m_MyServicePort
MyService Consumer Sample component.
ExecutionContextHandle_t UniqueId
void MyServiceConsumerInit(RTC::Manager *manager)
CORBA sequence utility template functions.
virtual void invoke()=0
Asynchronous invocation.
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Callback function to execute periodically.
Class represents a set of properties.
Definition: Properties.h:101
bool addPort(PortBase &port)
[local interface] Register Port
Definition: RTObject.cpp:1558
RTC::CorbaConsumer< SimpleService::MyService > m_myservice0
bool registerConsumer(const char *instance_name, const char *type_name, CorbaConsumerBase &consumer)
Register the consumer.
Definition: CorbaPort.cpp:125
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.
Definition: Manager.cpp:433
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
Definition: CORBA_SeqUtil.h:98
static const char * myserviceconsumer_spec[]
Async_t< Object, Func > * AsyncInvoker(Object *obj, Func func, bool auto_delete=false)
Helper function for async member function summons.
Definition: Async.h:550


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:53