8 from com.sun.corba.se.impl.encoding
import EncapsOutputStream
15 from _SDOPackage
import *
17 import string, math, socket, time, sys
43 ports = self.ref.get_ports()
45 prof = p.get_port_profile()
46 name = prof.name.split(
'.')[1]
56 p = self.
ports[unicode(name)]
59 self.
ports[unicode(name)] = p
69 def service(self, instance_name, type_name="", port_name=""):
70 return findService(self, port_name, type_name, instance_name)
93 cfg = self.ref.get_configuration()
94 cfgsets = cfg.get_configuration_sets()
96 print "configuration set is not found" 99 for d
in cfgset.configuration_data:
101 return d.value.extract_string()
108 cfg = self.ref.get_configuration()
109 cfgsets = cfg.get_configuration_sets()
110 if len(cfgsets) == 0:
111 print "configuration set is not found" 114 for d
in cfgset.configuration_data:
115 print d.name,
":",d.value.extract_string()
126 ec.activate_component(self.
ref)
138 ec.deactivate_component(self.
ref)
151 return ec.get_component_state(self.
ref)
175 cprof = self.ref.get_component_profile()
176 return cprof.instance_name
189 osname = System.getProperty(
"os.name")
191 if osname ==
"Mac OS X":
202 path = basename+self.
soext 203 initfunc = basename+
"Init" 205 self.ref.load_module(path, initfunc)
207 print "failed to load",path
219 print 'RTC named "',name,
'" already exists.' 223 args +=
'?instance_name=' + name
224 ref = self.ref.create_component(args)
235 fps = self.ref.get_factory_profiles()
237 for p
in afp.properties:
238 if p.name ==
"implementation_id":
239 fs.append(p.value.extract_string())
247 crefs = self.ref.get_components()
264 nc = NameComponent(name, kind)
273 global rootnc, nshost, orb
274 props = System.getProperties()
276 args = string.split(System.getProperty(
"NS_OPT"))
277 nshost = System.getProperty(
"NS_OPT").split(
':')[2]
278 if nshost ==
"localhost" or nshost ==
"127.0.0.1":
279 nshost = socket.gethostname()
280 print 'nshost =',nshost
281 orb = ORB.init(args, props)
283 nameserver = orb.resolve_initial_references(
"NameService");
284 rootnc = NamingContextHelper.narrow(nameserver);
293 props = System.getProperties()
295 args = [
"-ORBInitRef", corbaloc]
296 orb = ORB.init(args, props)
298 nameserver = orb.resolve_initial_references(
"NameService");
299 return NamingContextHelper.narrow(nameserver);
309 nc = NameComponent(name,kind)
313 return rnc.resolve(path)
328 hostname = socket.gethostbyaddr(hostname)[0]
333 print "exception in findRTCmanager("+hostname+
")" 345 cxts = rtc.ref.get_participating_contexts()
359 ports = rtc.get_ports()
360 cprof = rtc.get_component_profile()
361 portname = cprof.instance_name+
"."+name
363 prof = p.get_port_profile()
364 if prof.name == portname:
381 if ec.add_component(rtc.ref) == ReturnCode_t.RTC_OK:
384 print 'error in add_component()' 386 print 'already serialized' 393 op = outP.get_port_profile()
394 for con_prof
in op.connector_profiles:
395 ports = con_prof.ports
396 if len(ports) == 2
and outP == ports[0]
and inP == ports[1]:
405 op = outP.get_port_profile()
406 for con_prof
in op.connector_profiles:
407 ports = con_prof.ports
408 if len(ports) == 2
and outP == ports[0]
and inP == ports[1]:
409 outP.disconnect(con_prof.connector_id)
417 prof = port.get_port_profile()
418 prop = prof.properties
420 if p.name ==
"dataport.data_type":
421 return p.value.extract_string()
433 def connectPorts(outP, inPs, subscription="flush", dataflow="Push", bufferlength=1, rate=1000):
434 if not isinstance(inPs, list):
438 print outP.get_port_profile().name,
'and',inP.get_port_profile().name,
'are already connected' 441 print outP.get_port_profile().name,
'and',inP.get_port_profile().name,
'have different data types' 444 con_prof = ConnectorProfile()
445 con_prof.connector_id =
"" 446 con_prof.name =
"connector0" 447 con_prof.ports = [outP, inP]
450 nv1.name =
"dataport.interface_type";
451 a1 = orb.create_any()
452 a1.insert_string(
"corba_cdr")
456 nv2.name =
"dataport.dataflow_type" 457 a2 = orb.create_any()
458 a2.insert_string(dataflow)
462 nv3.name =
"dataport.subscription_type" 463 a3 = orb.create_any()
464 a3.insert_string(subscription)
468 nv4.name =
"dataport.buffer.length" 469 a4 = orb.create_any()
470 a4.insert_string(str(bufferlength))
474 nv5.name =
"dataport.publisher.push_rate" 475 a5 = orb.create_any()
476 a5.insert_string(str(rate))
479 con_prof.properties = [nv1, nv2, nv3, nv4, nv5]
480 con_prof_holder = ConnectorProfileHolder()
481 con_prof_holder.value = con_prof
482 if inP.connect(con_prof_holder) != ReturnCode_t.RTC_OK:
483 print "failed to connect(",outP.get_port_profile().name,
'<->',inP.get_port_profile().name,
")" 487 print "connet() returned RTC_OK, but not connected" 495 holder = Class.forName(data.getClass().getCanonicalName()+
"Holder",
496 True, data.getClass().getClassLoader())
497 streamable = holder.newInstance()
500 streamable.value = data;
501 strm = EncapsOutputStream(orb,
True)
502 streamable._write(strm)
503 return strm.toByteArray()
512 ostrm = EncapsOutputStream(orb,
True)
513 ostrm.write_octet_array(cdr, 0, len(cdr))
514 istrm = ostrm.create_input_stream()
515 holder = Class.forName(
"RTC."+classname+
"Holder",
True, Manager.getClassLoader())
516 streamable = holder.newInstance()
517 streamable._read(istrm)
518 return streamable.value
527 con_prof = ConnectorProfile()
528 con_prof.connector_id =
"" 529 con_prof.name =
"connector0" 530 con_prof.ports = [port]
533 nv1.name =
"dataport.interface_type";
534 a1 = orb.create_any()
535 a1.insert_string(
"corba_cdr")
539 nv2.name =
"dataport.dataflow_type" 540 a2 = orb.create_any()
541 a2.insert_string(
"Push")
545 nv3.name =
"dataport.subscription_type" 546 a3 = orb.create_any()
547 a3.insert_string(
"flush")
550 con_prof.properties = [nv1, nv2, nv3]
551 con_prof_holder = ConnectorProfileHolder()
552 con_prof_holder.value = con_prof
553 if port.connect(con_prof_holder) != ReturnCode_t.RTC_OK:
554 print "failed to connect" 556 for p
in con_prof_holder.value.properties:
557 if p.name ==
'dataport.corba_cdr.inport_ior':
558 ior = p.value.extract_string()
559 obj = orb.string_to_object(ior)
560 inport = InPortCdrHelper.narrow(obj)
562 if inport.put(cdr) != PortStatus.PORT_OK:
563 print "failed to put" 565 port.disconnect(con_prof_holder.value.connector_id)
575 pprof = port.get_port_profile()
576 for prop
in pprof.properties:
577 if prop.name ==
"dataport.data_type":
578 classname = prop.value.extract_string()
580 con_prof = ConnectorProfile()
581 con_prof.connector_id =
"" 582 con_prof.name =
"connector0" 583 con_prof.ports = [port]
586 nv1.name =
"dataport.interface_type";
587 a1 = orb.create_any()
588 a1.insert_string(
"corba_cdr")
592 nv2.name =
"dataport.dataflow_type" 593 a2 = orb.create_any()
594 a2.insert_string(
"Pull")
598 nv3.name =
"dataport.subscription_type" 599 a3 = orb.create_any()
600 a3.insert_string(
"flush")
603 con_prof.properties = [nv1, nv2, nv3]
604 con_prof_holder = ConnectorProfileHolder()
605 con_prof_holder.value = con_prof
606 if port.connect(con_prof_holder) != ReturnCode_t.RTC_OK:
607 print "failed to connect" 609 for p
in con_prof_holder.value.properties:
611 if p.name ==
'dataport.corba_cdr.outport_ior':
612 ior = p.value.extract_string()
613 obj = orb.string_to_object(ior)
614 outport = OutPortCdrHelper.narrow(obj)
615 cdr = CdrDataHolder()
620 if len(cdr.value) > 0:
621 port.disconnect(con_prof_holder.value.connector_id)
622 return cdr2data(cdr.value, classname)
628 port.disconnect(con_prof_holder.value.connector_id)
643 prof = rtc.ref.get_component_profile()
645 port_prof = prof.port_profiles
647 p = rtc.port(port_name)
649 print "can't find a port named",port_name
652 port_prof = [p.get_port_profile()]
660 if aif.instance_name == instance_name
and (type_name ==
"" or aif.type_name == type_name):
663 print "can't find a service named",instance_name
666 con_prof = ConnectorProfile()
667 con_prof.name =
"noname" 668 con_prof.connector_id =
"" 669 con_prof.ports = [port]
670 con_prof.properties = []
671 con_prof_holder = ConnectorProfileHolder()
672 con_prof_holder.value = con_prof
673 port.connect(con_prof_holder)
674 ior = con_prof_holder.value.properties[0].value.extract_string()
675 port.disconnect(con_prof_holder.value.connector_id)
676 return orb.string_to_object(ior)
684 cfg = rtc.get_configuration()
685 cfgsets = cfg.get_configuration_sets()
686 if len(cfgsets) == 0:
687 print "configuration set is not found" 694 for d
in cfgset.configuration_data:
696 d.value.insert_string(value)
697 cfg.set_configuration_set_values(cfgset)
701 print "no such property(",name,
")" 702 cfg.activate_configuration_set(
'default')
709 def narrow(ior, klass, package="OpenHRP"):
710 return getattr(sys.modules[package], klass+
"Helper").
narrow(ior)
716 return sys.version.count(
"GCC") == 0
def isJython()
check if jython or python
def start(self, ec=None)
activate this component
def get_components(self)
get list of components
def getLifeCycleState(self, ec=None)
get life cycle state of the main execution context
def isActive(self, ec=None)
check the main execution context is active or not
def findRTC(name, rnc=None)
get RT component
def __init__(self, ref)
constructor
def getRootNamingContext(corbaloc)
get root naming context
def narrow(ior, klass, package="OpenHRP")
narrow ior
wrapper class of RTCmanager
def writeDataPort(port, data, tm=1.0)
write data to a data port
def findService(rtc, port_name, type_name, instance_name)
get a service of RT component
def cdr2data(cdr, classname)
convert data from CDR format
def name(self)
get instance name
def isInactive(self, ec=None)
check the main execution context is inactive or not
def unbindObject(name, kind)
unbind an object reference
def properties(self)
show list of property names and values
def setConfiguration(rtc, nvlist)
update default configuration set
def stop(self, ec=None)
deactivate this component
def readDataPort(port, timeout=1.0)
read data from a data port
def serializeComponents(rtcs, stopEC=True)
set up execution context of the first RTC so that RTCs are executed sequentially
def get_factory_names(self)
get list of factory names
def isConnected(outP, inP)
check two ports are connected or not
def data2cdr(data)
convert data into CDR format
def findRTCmanager(hostname=None, rnc=None)
get RTCmanager
def connectPorts(outP, inPs, subscription="flush", dataflow="Push", bufferlength=1, rate=1000)
connect ports
wrapper class of RT component
def findObject(name, kind="", rnc=None)
get IOR of the object
def restart(self)
restart Manager
def findPort(rtc, name)
get a port of RT component
def setProperty(self, name, value)
update value of the default configuration set
def create(self, module, name=None)
create an instance of RT component
def port(self, name)
get IOR of port
def load(self, basename)
load RT component factory
def __init__(self, ref)
constructor
def service(self, instance_name, type_name="", port_name="")
get IOR of the service
def disconnectPorts(outP, inP)
disconnect ports
def dataTypeOfPort(port)
get data type of a port
def getProperty(self, name)
get value of the property in the default configuration set
def setConfiguration(self, nvlist)
update default configuration set
def initCORBA()
initialize ORB