ComponentActionListenerTestComp.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # -*- Python -*-
00004 
00005 import sys
00006 
00007 import OpenRTM
00008 import RTC
00009 import OpenRTM_aist
00010 
00011 consolein_spec = ["implementation_id", "ConsoleIn",
00012                   "type_name",         "ConsoleIn",
00013                   "description",       "Console input component",
00014                   "version",           "1.0",
00015                   "vendor",            "Shinji Kurihara",
00016                   "category",          "example",
00017                   "activity_type",     "DataFlowComponent",
00018                   "max_instance",      "10",
00019                   "language",          "Python",
00020                   "lang_type",         "script",
00021                   ""]
00022 
00023 
00024 class DataListener(OpenRTM_aist.ConnectorDataListenerT):
00025   def __init__(self, name):
00026     self._name = name
00027     
00028   def __del__(self):
00029     print "dtor of ", self._name
00030 
00031   def __call__(self, info, cdrdata):
00032     data = OpenRTM_aist.ConnectorDataListenerT.__call__(self, info, cdrdata, RTC.TimedLong(RTC.Time(0,0),0))
00033     print "------------------------------"
00034     print "Listener:       ", self._name
00035     print "Profile::name:  ", info.name
00036     print "Profile::id:    ", info.id
00037     print "Data:           ", data.data
00038     print "------------------------------"
00039     
00040 class ConnListener(OpenRTM_aist.ConnectorListener):
00041   def __init__(self, name):
00042     self._name = name
00043 
00044   def __del__(self):
00045     print "dtor of ", self._name
00046 
00047   def __call__(self, info):
00048     print "------------------------------"
00049     print "Listener:       ", self._name
00050     print "Profile::name:  ", info.name
00051     print "Profile::id:    ", info.id
00052     print "------------------------------"
00053 
00054 
00055 class ConsoleIn(OpenRTM_aist.DataFlowComponentBase):
00056   def __init__(self, manager):
00057     OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00058     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_INITIALIZE,
00059                                        self.preOnInitializeFunc)
00060     self.addExecutionContextActionListener(OpenRTM_aist.ExecutionContextActionListenerType.EC_ATTACHED,
00061                                            self.onAttachExecutionContextFunc)
00062     self.addExecutionContextActionListener(OpenRTM_aist.ExecutionContextActionListenerType.EC_DETACHED,
00063                                            self.onDetachExecutionContextFunc)
00064 
00065     return
00066 
00067   def preOnInitializeFunc(self, ec_id):
00068     print "preOnInitializeFunc"
00069     return
00070 
00071   def preOnFinalizeFunc(self, ec_id):
00072     print "preOnFinalizeFunc"
00073     return
00074 
00075   def preOnStartupFunc(self, ec_id):
00076     print "preOnStartupFunc"
00077     return
00078 
00079   def preOnShutdownFunc(self, ec_id):
00080     print "preOnShutdownFunc"
00081     return
00082 
00083   def preOnActivatedFunc(self, ec_id):
00084     print "preOnActivatedFunc"
00085     return
00086 
00087   def preOnDeactivatedFunc(self, ec_id):
00088     print "preOnDeactivatedFunc"
00089     return
00090 
00091   def preOnAbortingFunc(self, ec_id):
00092     print "preOnAbortingFunc"
00093     return
00094 
00095   def preOnErrorFunc(self, ec_id):
00096     print "preOnErrorFunc"
00097     return
00098 
00099   def preOnResetFunc(self, ec_id):
00100     print "preOnResetFunc"
00101     return
00102 
00103   def preOnExecuteFunc(self, ec_id):
00104     print "preOnExecuteFunc"
00105     return
00106 
00107   def preOnStateUpdateFunc(self, ec_id):
00108     print "preOnStateUpdateFunc"
00109     return
00110     
00111   def preOnRateChangedFunc(self, ec_id):
00112     print "preOnRateChangedFunc"
00113     return
00114     
00115   def postOnInitializeFunc(self, ec_id, ret):
00116     print "postOnInitializeFunc, ret: ", ret
00117     return
00118     
00119   def postOnFinalizeFunc(self, ec_id, ret):
00120     print "postOnFinalizeFunc, ret: ", ret
00121     return
00122     
00123   def postOnStartupFunc(self, ec_id, ret):
00124     print "postOnStartupFunc, ret: ", ret
00125     return
00126     
00127   def postOnShutdownFunc(self, ec_id, ret):
00128     print "postOnShutdownFunc, ret: ", ret
00129     return
00130     
00131   def postOnActivatedFunc(self, ec_id, ret):
00132     print "postOnActivatedFunc, ret: ", ret
00133     return
00134     
00135   def postOnDeactivatedFunc(self, ec_id, ret):
00136     print "postOnDeactivatedFunc, ret: ", ret
00137     return
00138     
00139   def postOnAbortingFunc(self, ec_id, ret):
00140     print "postOnAbortingFunc, ret: ", ret
00141     return
00142     
00143   def postOnErrorFunc(self, ec_id, ret):
00144     print "postOnErrorFunc, ret: ", ret
00145     return
00146     
00147   def postOnResetFunc(self, ec_id, ret):
00148     print "postOnResetFunc, ret: ", ret
00149     return
00150     
00151   def postOnExecuteFunc(self, ec_id, ret):
00152     print "postOnExecuteFunc, ret: ", ret
00153     return
00154     
00155   def postOnStateUpdateFunc(self, ec_id, ret):
00156     print "postOnStateUpdateFunc, ret: ", ret
00157     return
00158     
00159   def postOnRateChangedFunc(self, ec_id, ret):
00160     print "postOnRateChangedFunc, ret: ", ret
00161     return
00162     
00163   def onAddPortFunc(self, pprof):
00164     print "onAddPortFunc"
00165     return
00166     
00167   def onRemovePortFunc(self, pprof):
00168     print "onRemovePortFunc"
00169     return
00170     
00171   def onAttachExecutionContextFunc(self, ec_id):
00172     print "onAttachExecutionContextFunc"
00173     return
00174     
00175   def onDetachExecutionContextFunc(self, ec_id):
00176     print "onDetachExecutionContextFunc"
00177     return
00178 
00179 
00180   def onNotifyConnectFunc(self, pname, prof):
00181     print "onNotifyConnectFunc pname: ",pname
00182     return
00183 
00184   def onNotifyDisconnectFunc(self, pname, prof):
00185     print "onNotifyDisconnectFunc pname: ",pname
00186     return
00187 
00188   def onUnsubscribeInterfacesFunc(self, pname, profile):
00189     print "onUnsubscribeInterfacesFunc pname: ", pname
00190     return
00191 
00192   def onPublishInterfacesFunc(self, portname, profile, ret):
00193     print "onPublishInterfacesFunc pname: ", portname, " ret: ", ret
00194     return
00195 
00196   def onConnectNextportFunc(self, portname, profile, ret):
00197     print "onConnectNextportFunc pname: ", portname, " ret: ", ret
00198     return
00199 
00200   def onSubscribeInterfacesFunc(self, portname, profile, ret):
00201     print "onSubscribeInterfacesFunc pname: ", portname, " ret: ", ret
00202     return
00203 
00204   def onConnectedFunc(self, portname, profile, ret):
00205     print "onConnectedFunc pname: ", portname, " ret: ", ret
00206     return
00207 
00208   def onDisconnectNextportFunc(self, portname, profile, ret):
00209     print "onDisconnectNextportFunc pname: ", portname, " ret: ", ret
00210     return
00211 
00212   def onDisconnectedFunc(self, portname, profile, ret):
00213     print "onDisconnectedFunc pname: ", portname, " ret: ", ret
00214     return
00215 
00216 
00217   def onInitialize(self):
00218     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_FINALIZE,
00219                                        self.preOnFinalizeFunc)
00220     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_STARTUP,
00221                                        self.preOnStartupFunc)
00222     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_SHUTDOWN,
00223                                        self.preOnShutdownFunc)
00224     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_ACTIVATED,
00225                                        self.preOnActivatedFunc)
00226     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_DEACTIVATED,
00227                                        self.preOnDeactivatedFunc)
00228     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_ABORTING,
00229                                        self.preOnAbortingFunc)
00230     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_ERROR,
00231                                        self.preOnErrorFunc)
00232     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_RESET,
00233                                        self.preOnResetFunc)
00234     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_EXECUTE,
00235                                        self.preOnExecuteFunc)
00236     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_STATE_UPDATE,
00237                                        self.preOnStateUpdateFunc)
00238     self.addPreComponentActionListener(OpenRTM_aist.PreComponentActionListenerType.PRE_ON_RATE_CHANGED,
00239                                        self.preOnRateChangedFunc)
00240 
00241     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_INITIALIZE,
00242                                         self.postOnInitializeFunc)
00243     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_FINALIZE,
00244                                         self.postOnFinalizeFunc)
00245     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_STARTUP,
00246                                         self.postOnStartupFunc)
00247     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_SHUTDOWN,
00248                                         self.postOnShutdownFunc)
00249     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_ACTIVATED,
00250                                         self.postOnActivatedFunc)
00251     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_DEACTIVATED,
00252                                         self.postOnDeactivatedFunc)
00253     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_ABORTING,
00254                                         self.postOnAbortingFunc)
00255     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_ERROR,
00256                                         self.postOnErrorFunc)
00257     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_RESET,
00258                                         self.postOnResetFunc)
00259     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_EXECUTE,
00260                                         self.postOnExecuteFunc)
00261     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_STATE_UPDATE,
00262                                         self.postOnStateUpdateFunc)
00263     self.addPostComponentActionListener(OpenRTM_aist.PostComponentActionListenerType.POST_ON_RATE_CHANGED,
00264                                         self.postOnRateChangedFunc)
00265 
00266     self.addPortActionListener(OpenRTM_aist.PortActionListenerType.ADD_PORT,
00267                                self.onAddPortFunc)
00268     self.addPortActionListener(OpenRTM_aist.PortActionListenerType.REMOVE_PORT,
00269                                self.onRemovePortFunc)
00270 
00271 
00272     self.addPortConnectListener(OpenRTM_aist.PortConnectListenerType.ON_NOTIFY_CONNECT,
00273                                 self.onNotifyConnectFunc)
00274     self.addPortConnectListener(OpenRTM_aist.PortConnectListenerType.ON_NOTIFY_DISCONNECT,
00275                                 self.onNotifyDisconnectFunc)
00276     self.addPortConnectListener(OpenRTM_aist.PortConnectListenerType.ON_UNSUBSCRIBE_INTERFACES,
00277                                 self.onUnsubscribeInterfacesFunc)
00278 
00279     self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_PUBLISH_INTERFACES,
00280                                    self.onPublishInterfacesFunc)
00281     self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_CONNECT_NEXTPORT,
00282                                    self.onConnectNextportFunc)
00283     self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_SUBSCRIBE_INTERFACES,
00284                                    self.onSubscribeInterfacesFunc)
00285     self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_CONNECTED,
00286                                    self.onConnectedFunc)
00287     self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_DISCONNECT_NEXT,
00288                                    self.onDisconnectNextportFunc)
00289     self.addPortConnectRetListener(OpenRTM_aist.PortConnectRetListenerType.ON_DISCONNECTED,
00290                                    self.onDisconnectedFunc)
00291 
00292 
00293     self._data = RTC.TimedLong(RTC.Time(0,0),0)
00294     self._outport = OpenRTM_aist.OutPort("out", self._data)
00295     # Set OutPort buffer
00296     self.addOutPort("out", self._outport)
00297     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE,
00298                                            DataListener("ON_BUFFER_WRITE"))
00299     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_FULL, 
00300                                            DataListener("ON_BUFFER_FULL"))
00301     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT, 
00302                                            DataListener("ON_BUFFER_WRITE_TIMEOUT"))
00303     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_OVERWRITE, 
00304                                            DataListener("ON_BUFFER_OVERWRITE"))
00305     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_BUFFER_READ, 
00306                                            DataListener("ON_BUFFER_READ"))
00307     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_SEND, 
00308                                            DataListener("ON_SEND"))
00309     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVED,
00310                                            DataListener("ON_RECEIVED"))
00311     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_FULL, 
00312                                            DataListener("ON_RECEIVER_FULL"))
00313     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_TIMEOUT, 
00314                                            DataListener("ON_RECEIVER_TIMEOUT"))
00315     self._outport.addConnectorDataListener(OpenRTM_aist.ConnectorDataListenerType.ON_RECEIVER_ERROR,
00316                                            DataListener("ON_RECEIVER_ERROR"))
00317 
00318     self._outport.addConnectorListener(OpenRTM_aist.ConnectorListenerType.ON_CONNECT,
00319                                        ConnListener("ON_CONNECT"))
00320     self._outport.addConnectorListener(OpenRTM_aist.ConnectorListenerType.ON_DISCONNECT,
00321                                        ConnListener("ON_DISCONNECT"))
00322 
00323     return RTC.RTC_OK
00324 
00325         
00326   def onExecute(self, ec_id):
00327     print "Please input number: ",
00328     self._data.data = long(sys.stdin.readline())
00329     if self._data.data == 9:
00330       return RTC.RTC_ERROR
00331     OpenRTM_aist.setTimestamp(self._data)
00332     print "Sending to subscriber: ", self._data.data
00333     self._outport.write()
00334     return RTC.RTC_OK
00335 
00336 
00337 def ConsoleInInit(manager):
00338   profile = OpenRTM_aist.Properties(defaults_str=consolein_spec)
00339   manager.registerFactory(profile,
00340                           ConsoleIn,
00341                           OpenRTM_aist.Delete)
00342 
00343 
00344 def MyModuleInit(manager):
00345   ConsoleInInit(manager)
00346 
00347   # Create a component
00348   comp = manager.createComponent("ConsoleIn")
00349 
00350 def main():
00351   # Initialize manager
00352   mgr = OpenRTM_aist.Manager.init(sys.argv)
00353 
00354   # Set module initialization proceduer
00355   # This procedure will be invoked in activateManager() function.
00356   mgr.setModuleInitProc(MyModuleInit)
00357 
00358   # Activate manager and register to naming service
00359   mgr.activateManager()
00360 
00361   # run the manager in blocking mode
00362   # runManager(False) is the default
00363   mgr.runManager()
00364 
00365   # If you want to run the manager in non-blocking mode, do like this
00366   # mgr.runManager(True)
00367 
00368 if __name__ == "__main__":
00369   main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28