ComponentActionListenerTestComp.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # -*- Python -*-
4 
5 import sys
6 
7 import OpenRTM
8 import RTC
9 import OpenRTM_aist
10 
11 consolein_spec = ["implementation_id", "ConsoleIn",
12  "type_name", "ConsoleIn",
13  "description", "Console input component",
14  "version", "1.0",
15  "vendor", "Shinji Kurihara",
16  "category", "example",
17  "activity_type", "DataFlowComponent",
18  "max_instance", "10",
19  "language", "Python",
20  "lang_type", "script",
21  ""]
22 
23 
25  def __init__(self, name):
26  self._name = name
27 
28  def __del__(self):
29  print "dtor of ", self._name
30 
31  def __call__(self, info, cdrdata):
32  data = OpenRTM_aist.ConnectorDataListenerT.__call__(self, info, cdrdata, RTC.TimedLong(RTC.Time(0,0),0))
33  print "------------------------------"
34  print "Listener: ", self._name
35  print "Profile::name: ", info.name
36  print "Profile::id: ", info.id
37  print "Data: ", data.data
38  print "------------------------------"
39 
41  def __init__(self, name):
42  self._name = name
43 
44  def __del__(self):
45  print "dtor of ", self._name
46 
47  def __call__(self, info):
48  print "------------------------------"
49  print "Listener: ", self._name
50  print "Profile::name: ", info.name
51  print "Profile::id: ", info.id
52  print "------------------------------"
53 
54 
56  def __init__(self, manager):
57  OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
58  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_INITIALIZE,
60  self.addExecutionContextActionListener(OpenRTM_aist.ExecutionContextActionListenerType.EC_ATTACHED,
62  self.addExecutionContextActionListener(OpenRTM_aist.ExecutionContextActionListenerType.EC_DETACHED,
64 
65  return
66 
67  def preOnInitializeFunc(self, ec_id):
68  print "preOnInitializeFunc"
69  return
70 
71  def preOnFinalizeFunc(self, ec_id):
72  print "preOnFinalizeFunc"
73  return
74 
75  def preOnStartupFunc(self, ec_id):
76  print "preOnStartupFunc"
77  return
78 
79  def preOnShutdownFunc(self, ec_id):
80  print "preOnShutdownFunc"
81  return
82 
83  def preOnActivatedFunc(self, ec_id):
84  print "preOnActivatedFunc"
85  return
86 
87  def preOnDeactivatedFunc(self, ec_id):
88  print "preOnDeactivatedFunc"
89  return
90 
91  def preOnAbortingFunc(self, ec_id):
92  print "preOnAbortingFunc"
93  return
94 
95  def preOnErrorFunc(self, ec_id):
96  print "preOnErrorFunc"
97  return
98 
99  def preOnResetFunc(self, ec_id):
100  print "preOnResetFunc"
101  return
102 
103  def preOnExecuteFunc(self, ec_id):
104  print "preOnExecuteFunc"
105  return
106 
107  def preOnStateUpdateFunc(self, ec_id):
108  print "preOnStateUpdateFunc"
109  return
110 
111  def preOnRateChangedFunc(self, ec_id):
112  print "preOnRateChangedFunc"
113  return
114 
115  def postOnInitializeFunc(self, ec_id, ret):
116  print "postOnInitializeFunc, ret: ", ret
117  return
118 
119  def postOnFinalizeFunc(self, ec_id, ret):
120  print "postOnFinalizeFunc, ret: ", ret
121  return
122 
123  def postOnStartupFunc(self, ec_id, ret):
124  print "postOnStartupFunc, ret: ", ret
125  return
126 
127  def postOnShutdownFunc(self, ec_id, ret):
128  print "postOnShutdownFunc, ret: ", ret
129  return
130 
131  def postOnActivatedFunc(self, ec_id, ret):
132  print "postOnActivatedFunc, ret: ", ret
133  return
134 
135  def postOnDeactivatedFunc(self, ec_id, ret):
136  print "postOnDeactivatedFunc, ret: ", ret
137  return
138 
139  def postOnAbortingFunc(self, ec_id, ret):
140  print "postOnAbortingFunc, ret: ", ret
141  return
142 
143  def postOnErrorFunc(self, ec_id, ret):
144  print "postOnErrorFunc, ret: ", ret
145  return
146 
147  def postOnResetFunc(self, ec_id, ret):
148  print "postOnResetFunc, ret: ", ret
149  return
150 
151  def postOnExecuteFunc(self, ec_id, ret):
152  print "postOnExecuteFunc, ret: ", ret
153  return
154 
155  def postOnStateUpdateFunc(self, ec_id, ret):
156  print "postOnStateUpdateFunc, ret: ", ret
157  return
158 
159  def postOnRateChangedFunc(self, ec_id, ret):
160  print "postOnRateChangedFunc, ret: ", ret
161  return
162 
163  def onAddPortFunc(self, pprof):
164  print "onAddPortFunc"
165  return
166 
167  def onRemovePortFunc(self, pprof):
168  print "onRemovePortFunc"
169  return
170 
172  print "onAttachExecutionContextFunc"
173  return
174 
176  print "onDetachExecutionContextFunc"
177  return
178 
179 
180  def onNotifyConnectFunc(self, pname, prof):
181  print "onNotifyConnectFunc pname: ",pname
182  return
183 
184  def onNotifyDisconnectFunc(self, pname, prof):
185  print "onNotifyDisconnectFunc pname: ",pname
186  return
187 
188  def onUnsubscribeInterfacesFunc(self, pname, profile):
189  print "onUnsubscribeInterfacesFunc pname: ", pname
190  return
191 
192  def onPublishInterfacesFunc(self, portname, profile, ret):
193  print "onPublishInterfacesFunc pname: ", portname, " ret: ", ret
194  return
195 
196  def onConnectNextportFunc(self, portname, profile, ret):
197  print "onConnectNextportFunc pname: ", portname, " ret: ", ret
198  return
199 
200  def onSubscribeInterfacesFunc(self, portname, profile, ret):
201  print "onSubscribeInterfacesFunc pname: ", portname, " ret: ", ret
202  return
203 
204  def onConnectedFunc(self, portname, profile, ret):
205  print "onConnectedFunc pname: ", portname, " ret: ", ret
206  return
207 
208  def onDisconnectNextportFunc(self, portname, profile, ret):
209  print "onDisconnectNextportFunc pname: ", portname, " ret: ", ret
210  return
211 
212  def onDisconnectedFunc(self, portname, profile, ret):
213  print "onDisconnectedFunc pname: ", portname, " ret: ", ret
214  return
215 
216 
217  def onInitialize(self):
218  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_FINALIZE,
219  self.preOnFinalizeFunc)
220  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_STARTUP,
221  self.preOnStartupFunc)
222  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_SHUTDOWN,
223  self.preOnShutdownFunc)
224  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_ACTIVATED,
225  self.preOnActivatedFunc)
226  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_DEACTIVATED,
228  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_ABORTING,
229  self.preOnAbortingFunc)
230  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_ERROR,
231  self.preOnErrorFunc)
232  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_RESET,
233  self.preOnResetFunc)
234  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_EXECUTE,
235  self.preOnExecuteFunc)
236  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_STATE_UPDATE,
238  self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_RATE_CHANGED,
240 
241  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_INITIALIZE,
243  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_FINALIZE,
244  self.postOnFinalizeFunc)
245  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_STARTUP,
246  self.postOnStartupFunc)
247  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_SHUTDOWN,
248  self.postOnShutdownFunc)
249  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_ACTIVATED,
250  self.postOnActivatedFunc)
251  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_DEACTIVATED,
253  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_ABORTING,
254  self.postOnAbortingFunc)
255  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_ERROR,
256  self.postOnErrorFunc)
257  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_RESET,
258  self.postOnResetFunc)
259  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_EXECUTE,
260  self.postOnExecuteFunc)
261  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_STATE_UPDATE,
263  self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_RATE_CHANGED,
265 
266  self.addPortActionListener(OpenRTM_aist.PortActionListenerType.ADD_PORT,
267  self.onAddPortFunc)
268  self.addPortActionListener(OpenRTM_aist.PortActionListenerType.REMOVE_PORT,
269  self.onRemovePortFunc)
270 
271 
272  self.addPortConnectListener(OpenRTM_aist.PortConnectListenerType.ON_NOTIFY_CONNECT,
273  self.onNotifyConnectFunc)
274  self.addPortConnectListener(OpenRTM_aist.PortConnectListenerType.ON_NOTIFY_DISCONNECT,
276  self.addPortConnectListener(OpenRTM_aist.PortConnectListenerType.ON_UNSUBSCRIBE_INTERFACES,
278 
279  self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_PUBLISH_INTERFACES,
281  self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_CONNECT_NEXTPORT,
283  self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_SUBSCRIBE_INTERFACES,
285  self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_CONNECTED,
286  self.onConnectedFunc)
287  self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_DISCONNECT_NEXT,
289  self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_DISCONNECTED,
290  self.onDisconnectedFunc)
291 
292 
293  self._data = RTC.TimedLong(RTC.Time(0,0),0)
294  self._outport = OpenRTM_aist.OutPort("out", self._data)
295  # Set OutPort buffer
296  self.addOutPort("out", self._outport)
297  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE,
298  DataListener("ON_BUFFER_WRITE"))
299  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL,
300  DataListener("ON_BUFFER_FULL"))
301  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT,
302  DataListener("ON_BUFFER_WRITE_TIMEOUT"))
303  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE,
304  DataListener("ON_BUFFER_OVERWRITE"))
305  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ,
306  DataListener("ON_BUFFER_READ"))
307  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_SEND,
308  DataListener("ON_SEND"))
309  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
310  DataListener("ON_RECEIVED"))
311  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL,
312  DataListener("ON_RECEIVER_FULL"))
313  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_TIMEOUT,
314  DataListener("ON_RECEIVER_TIMEOUT"))
315  self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_ERROR,
316  DataListener("ON_RECEIVER_ERROR"))
317 
318  self._outport.addConnectorListener(OpenRTM_aist.ConnectorListenerType.ON_CONNECT,
319  ConnListener("ON_CONNECT"))
320  self._outport.addConnectorListener(OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT,
321  ConnListener("ON_DISCONNECT"))
322 
323  return RTC.RTC_OK
324 
325 
326  def onExecute(self, ec_id):
327  print "Please input number: ",
328  self._data.data = long(sys.stdin.readline())
329  if self._data.data == 9:
330  return RTC.RTC_ERROR
331  OpenRTM_aist.setTimestamp(self._data)
332  print "Sending to subscriber: ", self._data.data
333  self._outport.write()
334  return RTC.RTC_OK
335 
336 
337 def ConsoleInInit(manager):
338  profile = OpenRTM_aist.Properties(defaults_str=consolein_spec)
339  manager.registerFactory(profile,
340  ConsoleIn,
341  OpenRTM_aist.Delete)
342 
343 
344 def MyModuleInit(manager):
345  ConsoleInInit(manager)
346 
347  # Create a component
348  comp = manager.createComponent("ConsoleIn")
349 
350 def main():
351  # Initialize manager
352  mgr = OpenRTM_aist.Manager.init(sys.argv)
353 
354  # Set module initialization proceduer
355  # This procedure will be invoked in activateManager() function.
356  mgr.setModuleInitProc(MyModuleInit)
357 
358  # Activate manager and register to naming service
359  mgr.activateManager()
360 
361  # run the manager in blocking mode
362  # runManager(False) is the default
363  mgr.runManager()
364 
365  # If you want to run the manager in non-blocking mode, do like this
366  # mgr.runManager(True)
367 
368 if __name__ == "__main__":
369  main()
def addPortConnectRetListener(self, listener_type, memfunc, autoclean=True)
Adding PortConnectRet type listener.
Definition: RTObject.py:4126
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
This class is abstract base class for listener classes that provides callbacks for various events in ...
def addPortActionListener(self, listener_type, memfunc, autoclean=True)
Adding PortAction type listener.
Definition: RTObject.py:3816
def onSubscribeInterfacesFunc(self, portname, profile, ret)
def onPublishInterfacesFunc(self, portname, profile, ret)
def addExecutionContextActionListener(self, listener_type, memfunc, autoclean=True)
Adding ExecutionContextAction type listener.
Definition: RTObject.py:3916
def onDisconnectNextportFunc(self, portname, profile, ret)
def addOutPort(self, name, outport)
Definition: RTObject.py:2765
def addPreComponentActionListener(self, listener_type, memfunc, autoclean=True)
Adding PreComponentAction type listener.
Definition: RTObject.py:3596
def addPostComponentActionListener(self, listener_type, memfunc, autoclean=True)
Adding PostComponentAction type listener.
Definition: RTObject.py:3716
def addPortConnectListener(self, listener_type, memfunc, autoclean=True)
Adding PortConnect type listener.
Definition: RTObject.py:4019
This class is abstract base class for listener classes that provides callbacks for various events in ...


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34