Go to the documentation of this file.00001
00002
00003
00004
00005 import sys
00006
00007 from omniORB import CORBA
00008 from optparse import OptionParser, OptionError
00009
00010 import RTC
00011 import OpenRTM_aist
00012
00013 def usage():
00014 print "usage: ConnectorComp [options]"
00015 print " --flush "
00016 print ": Set subscription type Flush"
00017 print " --new "
00018 print ": Set subscription type New"
00019 print " --periodic [Hz] "
00020 print ": Set subscription type Periodic \n"
00021 print "exsample:"
00022 print " ConnectorComp --flush"
00023 print " ConnectorComp --new"
00024 print " ConnectorComp --new --policy ALL"
00025 print " ConnectorComp --new --policy SKIP --skip 100"
00026 print " ConnectorComp --periodic 10"
00027 print " ConnectorComp --periodic 10 --policy FIFO"
00028 print " ConnectorComp --periodic 10 --policy NEW \n"
00029
00030 def main():
00031
00032
00033 orb = CORBA.ORB_init(sys.argv)
00034
00035
00036 naming = OpenRTM_aist.CorbaNaming(orb, "localhost")
00037
00038 conin = OpenRTM_aist.CorbaConsumer()
00039 conout = OpenRTM_aist.CorbaConsumer()
00040
00041
00042 conin.setObject(naming.resolve("ConsoleIn0.rtc"))
00043
00044
00045 inobj = conin.getObject()._narrow(RTC.RTObject)
00046 pin = inobj.get_ports()
00047 pin[0].disconnect_all()
00048
00049
00050
00051 conout.setObject(naming.resolve("ConsoleOut0.rtc"))
00052
00053
00054 outobj = conout.getObject()._narrow(RTC.RTObject)
00055 pout = outobj.get_ports()
00056 pout[0].disconnect_all()
00057
00058
00059
00060 subs_type = "flush"
00061 period = "1.0"
00062 push_policy = "new"
00063 skip_count = "0"
00064
00065 for arg in sys.argv[1:]:
00066 if arg == "--flush":
00067 subs_type = "flush"
00068 break
00069
00070 elif arg == "--new":
00071 subs_type = "new"
00072 if len(sys.argv) > 2:
00073 push_policy = OpenRTM_aist.normalize([sys.argv[3]])
00074 if push_policy == "skip":
00075 skip_count = sys.argv[5]
00076 break
00077
00078 elif arg == "--periodic":
00079 subs_type = "periodic"
00080 period = sys.argv[2]
00081 if len(sys.argv) > 3:
00082 push_policy = OpenRTM_aist.normalize([sys.argv[4]])
00083 if push_policy == "skip":
00084 skip_count = sys.argv[6]
00085 break
00086
00087
00088
00089
00090
00091 else:
00092 usage()
00093
00094 print "Subscription Type: ", subs_type
00095 print "Period: ", period, " [Hz]"
00096 print "push policy: ", push_policy
00097 print "skip count: ", skip_count
00098
00099
00100 conprof = RTC.ConnectorProfile("connector0", "", [pin[0],pout[0]], [])
00101 OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00102 OpenRTM_aist.NVUtil.newNV("dataport.interface_type",
00103 "corba_cdr"))
00104
00105 OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00106 OpenRTM_aist.NVUtil.newNV("dataport.dataflow_type",
00107 "push"))
00108
00109 OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00110 OpenRTM_aist.NVUtil.newNV("dataport.subscription_type",
00111 subs_type))
00112
00113 if subs_type == "periodic":
00114 OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00115 OpenRTM_aist.NVUtil.newNV("dataport.publisher.push_rate",
00116 period))
00117 OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00118 OpenRTM_aist.NVUtil.newNV("dataport.publisher.push_policy",
00119 push_policy))
00120 if push_policy == "skip":
00121 OpenRTM_aist.CORBA_SeqUtil.push_back(conprof.properties,
00122 OpenRTM_aist.NVUtil.newNV("dataport.publisher.skip_count",
00123 skip_count))
00124
00125
00126 ret,conprof = pin[0].connect(conprof)
00127
00128
00129 eclistin = inobj.get_owned_contexts()
00130 eclistin[0].activate_component(inobj)
00131
00132
00133 eclistout = outobj.get_owned_contexts()
00134 eclistout[0].activate_component(outobj)
00135
00136
00137 if __name__ == "__main__":
00138 main()