def __call__(self, *args, **kwargs): timeout = kwargs.get("timeout", CALL_TIMEOUT) wait = kwargs.get("wait", True) from_cache = kwargs.get("from_cache", False) if from_cache: # CACHE_DEV source_type = Tango.DevSource[2] else: # DEV source_type = Tango.DevSource[0] if not args: argin = CORBA.Any(CORBA.NullTypeCode(), None) else: argin = python2any(args[0], self.cmd_type) # timeout is only took into account when we wait for result tango_call_greenlet = gevent.spawn(do_tango_cmd_call, self.name, self.cmd_type, self.cmd_call, argin, source_type, wait, timeout if wait else None, parent_proxy=self.proxy) if wait: return tango_call_greenlet.get() else: return tango_call_greenlet
def __init__(self, iorFile='Server.ref', orbArgs=[]): if self.server == None: # Initialise the ORB. orb = CORBA.ORB_init(orbArgs, CORBA.ORB_ID) # Read the server's stringified IOR from a file (this is just a quick and # dirty way of locating the server - a better method is to use # the naming or trader services). try: stringified_ior = open(iorFile).read() except: raise RequestManagerUnavailable # Convert the stringified IOR into an active object reference. server = orb.string_to_object(stringified_ior) # Make sure that the server is not a 'nil object reference' (represented # in Python by the value 'None'). if server is None: raise 'Nil object reference!' # Make sure that the object implements the expected interface! try: server_check = server._is_a('IDL:RequestManager:1.0') except: raise RequestManagerUnavailable if not server_check: raise InvalidRequestManager RequestManager.server = server
def main ( argv ): # init ORB and BOA try: argv.append( "--ORBthreading-model=Threaded" ) orb = CORBA.ORB_init( argv, CORBA.ORB_ID ) boa = BOA.BOA_init( sys.argv, BOA.BOA_ID ) except: print "..... can`t initialize ORB" sys.exit( 1 ) # resolve NameService try : nsior = open( "ns.ior", "r" ).read() except : print "..... ns.ior file for NameService missing" sys.exit( 1 ) try : ns = orb.string_to_object( nsior )._narrow( CosNaming.NamingContext ) except : print "..... no NameService IOR in ns.ior file or service not running" sys.exit( 1 ) # create naming contexts nspath = [CosNaming.NameComponent( 'DCI', '' )] try: for component in nspath : ns.bind_new_context( [component] ) except CosNaming.NamingContext.AlreadyBound: pass # create ScriptProcessorRegistry object root = Tkinter.Tk() obj = boa.create( 'ScriptProcessorRegistry', ScriptProcessorRegistry._FNORB_ID ) impl = ScriptProcessorRegistry( root, orb, boa ) boa.obj_is_ready( obj, impl ) open( "script.ref", "w" ).write( orb.object_to_string( obj ) ) # bind name in name service name = nspath + [CosNaming.NameComponent( 'ScriptProcessorRegistry', '' )] ns.rebind( name, obj ) # register ScriptProcessor for Python obj2 = boa.create( uuid.uuid(), ScriptProcessor._FNORB_ID ) impl2 = ScriptProcessor( orb, boa ) boa.obj_is_ready( obj2, impl2 ) impl.register_processor( "Python", obj2 ) # mainloop print "..... ScriptProcessorRegistry running with ior:\n" print orb.object_to_string( obj ) #boa._fnorb_mainloop() thread.start_new_thread(boa._fnorb_mainloop,()) root.mainloop()
def python2any(data, data_type=None, force_array=False, attr=False): if attr: typeEnum2str = globals()["attrTypeEnum2str"] else: typeEnum2str = globals()["typeEnum2str"] data_type_name, array_data_type_name = typeEnum2str[data_type] if data_type_name == "DevVarDoubleStringArray": # data is supposed to be a tuple with a list of doubles and a list of strings data = {"dvalue": data[0], "svalue": data[1]} elif data_type_name == "DevVarLongStringArray": # data is supposed to be a tuple with a list of longs and a list of strings data = {"lvalue": data[0], "svalue": data[1]} if force_array: data_type_name = array_data_type_name data = [data] return CORBA.Any(CORBA.typecode("IDL:Tango/%s:1.0" % data_type_name), data)
def main(argv): """ Do it! """ print 'Initialising the ORB...' # Initialise the ORB. orb = CORBA.ORB_init(argv, CORBA.ORB_ID) # Get a reference to the initial naming service context. ctx = CORBA.ORB_init().resolve_initial_references("NameService") # The 'pathname' of the context that holds the thermometer references. path = [ CosNaming.NameComponent('SVM', ''), CosNaming.NameComponent('SVMMODULE', ''), CosNaming.NameComponent('test', '') ] # Lookup the temperatures of the thermometers in rooms 101-105, and then # force a lookup on a non-existent name "106"! for room in ["inf_0"]: # Create a naming service 'name' for the thermometer. name = path + [CosNaming.NameComponent(room, '')] try: # Lookup the thermometer in the naming service. thermometer = ctx.resolve(name) # Make sure the object implements the expected interface! if not thermometer._is_a(CORBA.id(test.inf_0)): raise 'This is not a Thermometer!' # Call the server! thermometer.p('e', [CORBA.Any(CORBA.TC_string, 'hello')]) except CosNaming.NamingContext.NotFound: print 'No thermometer in room', room return 0
def connect_device(tango_db, name, nodb=False): #, device_impl_number): while True: try: orb = CORBA.ORB_init(["--ORBthreading-model=Threaded"]) tango_db_dev, device_ior, device_impl_number = get_device_ior( orb, tango_db, name, nodb) device_impl = Device.impl[device_impl_number] device = orb.string_to_object(device_ior)._narrow(device_impl) device.ping() except: time.sleep(CALL_TIMEOUT) continue else: return orb, tango_db_dev, device, device_impl_number
def init_dns(eventhandler): if not SVMCORBA_RECORD.fnorb_installed: return RESULT_FNORB_NOT_INSTALLED orb = CORBA.ORB_init(FNORB_PARAMETERS) # orb._fnorb_override_options({'Threading Model': 'Threaded'}) if not orb: return RESULT_FNORB_NOT_STARTED SVMCORBA_RECORD.orb = orb services = orb.list_initial_services() for rs in REQUIRED_SERVICES: if not rs in services: return RESULT_SERVICE_NOT_FOUND ifctx = orb.resolve_initial_references(INTERFACE_REPOSITORY) nctx = orb.resolve_initial_references(NAME_SERVICE) SVMCORBA_RECORD.nctx = nctx SVMCORBA_RECORD.ifctx = ifctx SVMCORBA_RECORD.work_path = eventhandler.work_path SVMCORBA_RECORD.module_name = eventhandler.options[MODEL_NAME] SVMCORBA_RECORD.module_num = eventhandler.internal_prefix SVMCORBA_RECORD.ports = eventhandler.ports SVMCORBA_RECORD.eh = eventhandler try: os.mkdir(eventhandler.work_path) except: 1 idl_file = generate_stub() interfaces = lookup_interfaces(eventhandler.required_components) if interfaces: links = link_ports(SVMCORBA_RECORD.eh.required_connections, interfaces) generate_link_stub(links) SVMCORBA_RECORD.eh.outgoing_table = create_link_table(links) links = link_ports(SVMCORBA_RECORD.eh.required_connections, interfaces, 1) generate_link_stub(links) locate_components(links) feed_idl(idl_file) start_service() if interfaces: notify_components(links) return RESULT_OK
def main(argv): # init ORB and BOA try: argv.append("--ORBthreading-model=Threaded") orb = CORBA.ORB_init(argv, CORBA.ORB_ID) boa = BOA.BOA_init(sys.argv, BOA.BOA_ID) except: print "..... can`t initialize ORB" sys.exit(1) # get NameService try: nsior = open("ns.ior", "r").read() except: print "..... ns.ior file for NameService missing" sys.exit(1) try: ns = orb.string_to_object(nsior)._narrow(CosNaming.NamingContext) except: print "..... no NameService IOR in ns.ior or service not running" sys.exit(1) # create naming contexts nspath = [CosNaming.NameComponent('DCI', '')] try: for component in nspath: ns.bind_new_context([component]) except CosNaming.NamingContext.AlreadyBound: pass # create object for RuleProcessor obj = boa.create('RuleProcessor', RuleProcessor._FNORB_ID) impl = RuleProcessor(orb, boa) boa.obj_is_ready(obj, impl) open("rule.ref", "w").write(orb.object_to_string(obj)) # bind name in name service name = nspath + [CosNaming.NameComponent('RuleProcessor', '')] ns.rebind(name, obj) # mainloop print "..... RuleProcessor running with ior:\n" print orb.object_to_string(obj) boa._fnorb_mainloop()
def main(argv): try: orb = CORBA.ORB_init(argv, CORBA.ORB_ID) except: print "Can`t initialize ORB" sys.exit(1) boa = BOA.BOA_init(sys.argv, BOA.BOA_ID) obj = boa.create('TestObject', TestObject_impl._FNORB_ID) root = Tkinter.Tk() impl = TestObject_impl(root, obj, orb) boa.obj_is_ready(obj, impl) import thread thread.start_new_thread(boa._fnorb_mainloop, ()) root.mainloop()
def python2any(data, data_type=None, force_array=False, attr=False): if attr: typeEnum2str = globals()["attrTypeEnum2str"] else: typeEnum2str = globals()["typeEnum2str"] data_type_name, array_data_type_name = typeEnum2str[data_type] if data_type_name == "DevVarDoubleStringArray": # data is supposed to be a tuple with a list of doubles and a list of strings data = { "dvalue": data[0], "svalue": data[1] } elif data_type_name == "DevVarLongStringArray": # data is supposed to be a tuple with a list of longs and a list of strings data = { "lvalue": data[0], "svalue": data[1] } if force_array: data_type_name = array_data_type_name data = [data] return CORBA.Any(CORBA.typecode("IDL:Tango/%s:1.0" % data_type_name), data)
def main ( argv ): # get orb try: argv.append("--ORBthreading-model=Threaded") orb = CORBA.ORB_init(argv, CORBA.ORB_ID) except: print "Can`t initialize ORB" sys.exit(1) # get boa boa = BOA.BOA_init(sys.argv,BOA.BOA_ID) root = Tkinter.Tk() client = TestClient( orb, boa, root ) # mainloop import thread thread.start_new_thread( boa._fnorb_mainloop, () ) root.mainloop()
def main(argv): """ Do it! """ print 'Initialising the ORB...' # Initialise the ORB. orb = CORBA.ORB_init(argv, CORBA.ORB_ID) # Get a reference to the initial naming service context. ctx = CORBA.ORB_init().resolve_initial_references("NameService") # The 'pathname' of the context that holds the thermometer references. path = [CosNaming.NameComponent('SVM', ''), CosNaming.NameComponent('SVMMODULE', ''), CosNaming.NameComponent('test', '')] # Lookup the temperatures of the thermometers in rooms 101-105, and then # force a lookup on a non-existent name "106"! for room in ["inf_0"]: # Create a naming service 'name' for the thermometer. name = path + [CosNaming.NameComponent(room, '')] try: # Lookup the thermometer in the naming service. thermometer = ctx.resolve(name) # Make sure the object implements the expected interface! if not thermometer._is_a(CORBA.id(test.inf_0)): raise 'This is not a Thermometer!' # Call the server! thermometer.p('e', [CORBA.Any(CORBA.TC_string, 'hello')]) except CosNaming.NamingContext.NotFound: print 'No thermometer in room', room return 0