Go to the documentation of this file.00001
00002
00003
00004
00005 import sys
00006 import string
00007 import time
00008
00009 import RTC
00010 import SimpleService, SimpleService__POA
00011 import OpenRTM_aist
00012
00013
00014 myserviceprovider_spec = ["implementation_id", "MyServiceProvider",
00015 "type_name", "MyServiceProvider",
00016 "description", "MyService Provider Sample component",
00017 "version", "1.0",
00018 "vendor", "Shinji Kurihara",
00019 "category", "example",
00020 "activity_type", "DataFlowComponent",
00021 "max_instance", "10",
00022 "language", "Python",
00023 "lang_type", "script",
00024 ""]
00025
00026
00027 class seq_print:
00028 def __init__(self):
00029 self._cnt = 0
00030 return
00031
00032 def __call__(self, val):
00033 print self._cnt, ": ", val
00034 self._cnt += 1
00035 return
00036
00037
00038
00039 class MyServiceSVC_impl(SimpleService__POA.MyService):
00040 def __init__(self):
00041 self._echoList = []
00042 self._valueList = []
00043 self._value = 0
00044 return
00045
00046 def __del__(self):
00047 pass
00048
00049 def echo(self, msg):
00050 OpenRTM_aist.CORBA_SeqUtil.push_back(self._echoList, msg)
00051 print "MyService::echo() was called."
00052 for i in range(10):
00053 print "Message: ", msg
00054 time.sleep(1)
00055 print "MyService::echo() was finished."
00056 return msg
00057
00058 def get_echo_history(self):
00059 print "MyService::get_echo_history() was called."
00060 OpenRTM_aist.CORBA_SeqUtil.for_each(self._echoList, seq_print())
00061 return self._echoList
00062
00063 def set_value(self, value):
00064 OpenRTM_aist.CORBA_SeqUtil.push_back(self._valueList, value)
00065 self._value = value
00066 print "MyService::set_value() was called."
00067 print "Current value: ", self._value
00068 return
00069
00070 def get_value(self):
00071 print "MyService::get_value() was called."
00072 print "Current value: ", self._value
00073 return float(self._value)
00074
00075 def get_value_history(self):
00076 print "MyService::get_value_history() was called."
00077 OpenRTM_aist.CORBA_SeqUtil.for_each(self._valueList, seq_print())
00078
00079 return self._valueList
00080
00081
00082
00083 class MyServiceProvider(OpenRTM_aist.DataFlowComponentBase):
00084 def __init__(self, manager):
00085 OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00086
00087 return
00088
00089
00090 def onInitialize(self):
00091
00092 self._myServicePort = OpenRTM_aist.CorbaPort("MyService")
00093
00094
00095 self._myservice0 = MyServiceSVC_impl()
00096
00097
00098 self._myServicePort.registerProvider("myservice0", "MyService", self._myservice0)
00099
00100
00101 self.addPort(self._myServicePort)
00102
00103 return RTC.RTC_OK
00104
00105
00106 def MyServiceProviderInit(manager):
00107 profile = OpenRTM_aist.Properties(defaults_str=myserviceprovider_spec)
00108 manager.registerFactory(profile,
00109 MyServiceProvider,
00110 OpenRTM_aist.Delete)
00111 return
00112
00113
00114 def MyModuleInit(manager):
00115 MyServiceProviderInit(manager)
00116
00117
00118 comp = manager.createComponent("MyServiceProvider")
00119
00120 """
00121 rtobj = manager.getPOA().servant_to_reference(comp)._narrow(RTC.RTObject)
00122
00123 ecs = rtobj.get_execution_context_services()
00124 ecs[0].activate_component(rtobj)
00125 """
00126 return
00127
00128
00129 def main():
00130
00131 mgr = OpenRTM_aist.Manager.init(sys.argv)
00132
00133
00134
00135 mgr.setModuleInitProc(MyModuleInit)
00136
00137
00138 mgr.activateManager()
00139
00140
00141
00142 mgr.runManager()
00143
00144
00145
00146
00147
00148 if __name__ == "__main__":
00149 main()