def main(): # # Start orb. orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) # Process Options verbose = 0 needNameService = 0 channelName = "EventChannel" factoryName = "EventChannelFactory" criteria = [] try: opts, args = getopt.getopt(sys.argv[1:], "n:N:m:c:i:p:q:R:r:vh") except getopt.error: # print help information and exit: usage() sys.exit(-1) for option, optarg in opts: if option == '-n': channelName = optarg needNameService = 1 elif option == '-N': factoryName = optarg elif option == '-m': ## OLD OPTION criteria.append(makeNVP("MaxEventsPerConsumer", int(optarg))) elif option == '-c': criteria.append(makeNVP("CyclePeriod_ns", int(optarg))) elif option == '-i': criteria.append(makeNVP("InsName", optarg)) # string param elif option == '-p': criteria.append(makeNVP("MaxNumProxies", int(optarg))) elif option == '-q': criteria.append(makeNVP("MaxQueueLength", int(optarg))) elif option == '-R': criteria.append(makeNVP("PullRetryPeriod_ms", int(optarg))) elif option == '-r': ## This option is deprecated in favour of -R: criteria.append(makeNVP("PullRetryPeriod", int(optarg))) elif option == '-v': verbose = 1 elif option == '-h': usage() sys.exit(0) else: usage() sys.exit(-1) # Use one big try...catch block. # 'action' variable keeps track of what we're doing. action = "start" try: # # Get Name Service root context. rootContext = None try: action = "resolve initial reference 'NameService'" obj = orb.resolve_initial_references("NameService") rootContext = obj._narrow(CosNaming.NamingContext) if rootContext is None: raise CORBA.OBJECT_NOT_EXIST(0, CORBA.COMPLETED_NO) except CORBA.Exception, ex: if needNameService: raise ex else: sys.stderr.write("Warning - failed to %s\n" % action) # # Obtain reference to the Event Channel Factory implementation. # (from command-line argument or from the Naming Service). if len(args): action = "convert URI from command line into object reference" obj = orb.string_to_object(args[0]) else: action = "find Event Channel Factory in naming service" obj = rootContext.resolve(str2name(factoryName)) action = "narrow object reference to event channel factory" factory = obj._narrow(EventChannelAdmin.EventChannelFactory) if factory is None: sys.stderr.write( "Failed to narrow Event Channel Factory reference.\n") sys.exit(1) # Check that the factory is of the right type action = "check factory supports EventChannel object interface" key = [CosNaming.NameComponent("EventChannel", "object interface")] if not factory.supports(key): sys.stderr.write('Factory does not support Event Channel Interface!'+ \ ' [%s]\n'%factoryName) sys.exit(1) # # Create Event Channel Object. action = "create EventChannel object" channelObj = factory.create_object(key, criteria) if channelObj is None: sys.stderr.write('Channel Factory returned nil reference!'+ \ ' [%s]\n'%channelName) sys.exit(1) # Print the new EventChannel's IOR to standard output. if verbose: print orb.object_to_string(channelObj) # Narrow object returned to an Event Channel channel = channelObj._narrow(CosEventChannelAdmin.EventChannel) if channel is None: sys.stderr.write('Failed to narrow Event Channel!'+ \ ' [%s]\n'%channelName) sys.exit(1) # # Register event channel with naming service if rootContext is not None: name = str2name(channelName) try: action = "register (bind) EventChannel with the naming service" rootContext.bind(name, channel) except CosNaming.NamingContext.AlreadyBound, ex: action = "register (rebind) EventChannel with the naming service" rootContext.rebind(name, channel)
def main(): orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) # Process Options discnum = 0 sleepInterval = 0 channelName = "EventChannel" # Process Options try: opts,args=getopt.getopt(sys.argv[1:],"d:s:n:h") except getopt.error: # print help information and exit: usage() sys.exit(-1) for option, optarg in opts: if option=='-d': discnum = int(optarg) elif option=='-s': sleepInterval = int(optarg) elif option=='-n': channelName = optarg elif option=='-h': usage() sys.exit(0) else: usage() sys.exit(-1) # Ignore broken pipes if signal.__dict__.has_key('SIGPIPE'): signal.signal(signal.SIGPIPE, signal.SIG_IGN) action="start" # Use this variable to help report errors. try: action="resolve initial reference 'RootPOA'" poa=orb.resolve_initial_references("RootPOA") action="activate the RootPOA's POAManager" poaManager=poa._get_the_POAManager() poaManager.activate() # # Obtain reference to the Event Channel. # (from command-line argument or from the Naming Service). if len(args): action="convert URI from command line into object reference" obj=orb.string_to_object(args[0]) else: # # Get Name Service root context. action="resolve initial reference 'NameService'" obj=orb.resolve_initial_references("NameService") rootContext=obj._narrow(CosNaming.NamingContext) if rootContext is None: raise CORBA.OBJECT_NOT_EXIST(0,CORBA.COMPLETED_NO) # # Obtain reference to the Event Channel. action="find Event Channel in naming service" obj=rootContext.resolve(str2name(channelName)) action="narrow object reference to event channel" channel=obj._narrow(CosEventChannelAdmin.EventChannel) if channel is None: raise CORBA.OBJECT_NOT_EXIST(0,CORBA.COMPLETED_NO) except CORBA.ORB.InvalidName, ex: # resolve_initial_references() sys.stderr.write("Failed to %s. ORB::InvalidName\n"%action) sys.exit(1)
def main(): result = 1 # # Start orb. orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) # Process Options ecName = str2name("EventChannel") try: opts, args = getopt.getopt(sys.argv[1:], "n:h") except getopt.error: # print help information and exit: usage() sys.exit(-1) for option, optarg in opts: if option == '-n': ecName = str2name(optarg) elif option == '-h': usage() sys.exit(0) else: usage() sys.exit(-1) # Use one big try...catch block. # 'action' variable keeps track of what we're doing. action = "start" try: # # Obtain reference to the Event Channel. # (from command-line argument or from the Naming Service). if len(args): action = "convert URI from command line into object reference" obj = orb.string_to_object(args[0]) else: # # Get Name Service root context. action = "resolve initial reference 'NameService'" obj = orb.resolve_initial_references("NameService") rootContext = obj._narrow(CosNaming.NamingContext) if rootContext is None: raise CORBA.OBJECT_NOT_EXIST(0, CORBA.COMPLETED_NO) # # Obtain reference to the Event Channel. action = "find Event Channel in naming service" obj = rootContext.resolve(ecName) # # Unbind the Channel's reference in the naming service. action = "unbind Event Channel from naming service" rootContext.unbind(ecName) action = "narrow object reference to event channel" channel = obj._narrow(CosEventChannelAdmin.EventChannel) if channel is None: raise CORBA.OBJECT_NOT_EXIST(0, CORBA.COMPLETED_NO) # # Destroy the EventChannel. action = "destroy Event Channel" channel.destroy() # # Clean up nicely. action = "destroy orb" orb.destroy() # # If we get here, then everything has worked OK. result = 0 except CORBA.ORB.InvalidName, ex: # resolve_initial_references() sys.stderr.write("Failed to %s. ORB::InvalidName\n" % action)