def get_statistic(idl, ior, context, argv=[]): 'Returns connection True/False and (str)answer' # connect corba service try: omniORB.importIDL(idl, [""]) except ImportError, msg: sys.stderr.write('CORBA ImportError: %s\n' % msg) return False, ''
#!/usr/bin/env python import os, socket, sys, signal from EdcbaBroker.ControlBroker import ControlBroker try: from omniORB import CORBA import omniORB # for now assume we are being run from edcba root omniORB.omniidlArguments(["-I./idl"]) omniORB.importIDL("./idl/BrokerNameService.idl") omniORB.importIDL("./idl/Stepper.idl") import EDCBA__POA as EDCBA except: print "Failed to initialise CORBA" def quitHandler(signum, frame): print "\nStopping Stepper Client" raise KeyboardInterrupt if __name__ == '__main__': print "Starting Stepper Client" orb = CORBA.ORB_init(sys.argv) # client code ns_ior = file('/tmp/BrokerNameService.ior').read() ns_obj = orb.string_to_object(ns_ior) ns = ns_obj._narrow(EDCBA.BrokerNameService)
from unittest import TestCase, TestSuite, main, makeSuite # Sucks that we need to do this. from omniORB import importIDL importIDL('../idl/epo.idl', ['-I../idl']) from Rambler.EventChannel import EventChannel from Interface import Interface from Interface.Implements import implements class Publisher: pass class Subscriber: message = "" def handleMessage(self, msg): self.message = msg class ITestMessage(Interface): pass class TestMessage: pass implements(TestMessage,ITestMessage) class ExtendString(str): pass class Test(TestCase): def setUp(self):
def systemFailure(cookie, retries, exc): if retries > 5: return False else: return True ENCODING = 'utf-8' cookie = None omniORB.installTransientExceptionHandler(cookie, transientFailure) omniORB.installCommFailureExceptionHandler(cookie, commFailure) omniORB.installSystemExceptionHandler(cookie, systemFailure) importIDL(whois.conf.get('corba', 'idl')) ccReg = sys.modules['ccReg'] registry = sys.modules['Registry'] # CORBA end def convertProperties(props, output): cproperties = [] if not props: return cproperties for key, value in props.iteritems(): if type(value) is unicode: value = value.encode(ENCODING) elif type(value) is not str: value = str(value)
def systemFailure(cookie, retries, exc): if retries > 5: return False else: return True ENCODING = 'utf-8' cookie = None omniORB.installTransientExceptionHandler(cookie, transientFailure) omniORB.installCommFailureExceptionHandler(cookie, commFailure) omniORB.installSystemExceptionHandler(cookie, systemFailure) importIDL(whois.conf.get('corba', 'idl')) ccReg = sys.modules['ccReg'] registry = sys.modules['Registry'] # CORBA end def convertProperties(props, output): cproperties = [] if not props: return cproperties for key, value in props.iteritems(): if type(value) is unicode: value = value.encode(ENCODING) elif type(value) is not str:
import unittest, os from Money import Money, getCurrency import logging logging.basicConfig() #logging.getLogger("EventChannel").setLevel(logging.DEBUG) #logging.getLogger("Rambler").setLevel(logging.DEBUG) #logging.getLogger("ZODBPool").setLevel(logging.DEBUG) # Sucks that we need to do this. from omniORB import importIDL importIDL('MoneyWidget.idl', ['-I../idl']) from Rambler import Server Server.init("giop:tcp::6666") # Sigh, all these import's have to be done in the proper order from Rambler import ZODBPool, ZODBMapper from ZODB import FileStorage, Persistent, DB from tempfile import mktemp tempdir = '/tmp' # Just for now filename = mktemp() storage = FileStorage.FileStorage(filename) db = DB(storage, cache_size=1000) Server.registerService(ZODBPool.ZODBConnectionPool(db, 6), "ZODBPool") from MoneyWidget import MoneyWidget, MoneyWidgetHome Server.loadConfig(MoneyWidget, 'MoneyWidget.cfg')
#!/usr/bin/env python # The Broker Name service. A simple registration location for all control # brokers. # Copyright 2006 John T. Kamenik, LGPL, All rights reserved. import os, sys, signal try: from omniORB import CORBA import omniORB # for now assume we are being run from edcba root omniORB.importIDL("./idl/BrokerNameService.idl") import EDCBA__POA as EDCBA base = EDCBA.BrokerNameService except: # if we can't be a CORBA object, then we can't be anything base = object class Registration: '''Registration object used as a holding place for registration information''' def __init__(self, controlBroker, address): self.brokername = controlBroker self.ior = address self.auth = None
from omniORB import CORBA import omniORB import sys omniORB.importIDL("./Bank.idl") class base: pass try: import Bank__POA base = Bank__POA.Account except: pass class Account(base): def __init__(self, bal): self.balance = bal print self.__dict__, self def deposit(self, amount): print "Adding %s to %s" % (amount, self.balance) self.balance += amount def notice(self, text): print "NOTICE: %s" % (text)
import sys from omniORB import CORBA, PortableServer, importIDL import CosNaming importIDL('Ping.idl') Example = sys.modules['Example'] Example__POA = sys.modules['Example__POA'] class Pingable_i(Example__POA.Pingable): def ping(self): print('pinged') orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) poa = orb.resolve_initial_references('RootPOA') obj = orb.resolve_initial_references('NameService') root_context = obj._narrow(CosNaming.NamingContext) if not root_context: print('Failed to narrow the root naming context') sys.exit(1) # Bind the root context name = [CosNaming.NameComponent('test', '')] try: test_context = root_context.bind_new_context(name) print('New test context bound') except CosNaming.NamingContext.AlreadyBound, ex: print('Test context already exists') obj = root_context.resolve(name) test_context = obj._narrow(CosNaming.NamingContext)
#!/usr/bin/env python # -*- Python -*- # -*- coding: utf-8 -*- #import sys #sys.path = sys.path from omniORB import CORBA, PortableServer, any import omniORB import sys import uuid print omniORB.importIDL("idl/SDOPackage.idl", ["-Iidl"]) print omniORB.importIDL("idl/ComponentObserver.idl", ["-Iidl"]) import SDOPackage import RTC__POA def dict_to_nvlist(dict): '''Convert a dictionary into a CORBA namevalue list.''' result = [] for item in list(dict.keys()): result.append( SDOPackage.NameValue(item, omniORB.any.to_any(dict[item]))) return result class RTCObserver(RTC__POA.ComponentObserver): def __init__(self): pass
{'classname': 'file', 'item': ccReg.FT_FILE},\ {'classname': 'logger', 'item': ccReg.FT_LOGGER},\ {'classname': 'session', 'item': ccReg.FT_SESSION},\ {'classname': 'bankstatement', 'item': ccReg.FT_STATEMENTITEM},\ {'classname': 'zone', 'item': ccReg.FT_ZONE},\ {'classname': 'statementhead', 'item': ccReg.FT_STATEMENTHEAD},\ {'classname': 'message', 'item': ccReg.FT_MESSAGE}] True """ import sys import fred_webadmin.config as config from pprint import pprint from omniORB import importIDL importIDL(config.idl) ccReg = sys.modules['ccReg'] Registry = sys.modules['Registry'] def corbaname_to_classname(item): """ Return classname (class name in lowercase) for a given ccReg.FT_FILTER* type. """ rules = {ccReg.FT_STATEMENTITEM._v: 'bankstatement'} return rules.get(item._v, item._n[3:].lower()) def reverse_dict(dictionary): return dict([(value, key) for key, value in dictionary.items()])
def __init__(self): self.orb = CORBA.ORB_init() try: self.ior = open("LTTSample0.rtc").read() except: print "LTTSample0.rtc not found" import time, sys write = sys.stdout.write write("Launching LTTSampleComp...") sys.stdout.flush() if os.sep == '\\': os.system("start LTTSampleComp.exe") else: os.system("./LTTSampleComp&") while True: try: self.ior = open("LTTSample0.rtc").read() break; except: write(".") sys.stdout.flush() time.sleep(0.01) pass print "done" obj = self.orb.string_to_object(self.ior) if CORBA.is_nil(obj): print "Object in LTTSample0.rtc is nil. Restarting LTTSampleComp..." if os.sep == '\\': os.system("start LTTSampleComp.exe") else: os.system("./LTTSampleComp&") self.ior = open("LTTSample0.rtc").read() obj = self.orb.string_to_object(self.ior) if CORBA.is_nil(obj): print "Object reference is nil" sys.exit(1) import omniORB import sys if os.sep == '\\': os.system("omniidl -I. -bpython SDOPackage.idl RTC.idl LogicalTimeTriggeredEC.idl") import RTC import OpenRTM else: self.sdo_idl = omniORB.importIDL("idl/SDOPackage.idl") self.rtc_idl = omniORB.importIDL("idl/RTC.idl", ["-Iidl"]) self.ltt_idl = omniORB.importIDL("idl/LogicalTimeTriggeredEC.idl", ["-Iidl"]) RTC = sys.modules["RTC"] OpenRTM = sys.modules["OpenRTM"] try: self.rtobj = obj._narrow(RTC.RTObject) except: print "Narrowing failed. Restarting LTTSampleComp..." import time print "Launching LTTSampleComp..." if os.sep == '\\': os.system("start LTTSampleComp.exe") else: os.system("./LTTSampleComp&") time.sleep(1.0) obj = self.orb.string_to_object(open("LTTSample0.rtc").read()) self.rtobj = obj._narrow(RTC.RTObject) cxts = self.rtobj.get_owned_contexts() self.lttcxt = cxts[0]._narrow(OpenRTM.LogicalTimeTriggeredEC) profile = self.lttcxt.get_profile() p = {} p["kind"] = profile.kind p["rate"] = profile.rate p["owner"] = profile.owner from omniORB import any for prop in profile.properties: p[prop.name] = any.from_any(prop.value) print "ExecutionContext:" print " type:", p.pop("type") print " name:", p.pop("name") print " kind:", p.pop("kind") print " rate:", p.pop("rate") print " owner:", p.pop("owner") print "properties:", p
{'classname': 'file', 'item': ccReg.FT_FILE},\ {'classname': 'logger', 'item': ccReg.FT_LOGGER},\ {'classname': 'session', 'item': ccReg.FT_SESSION},\ {'classname': 'bankstatement', 'item': ccReg.FT_STATEMENTITEM},\ {'classname': 'zone', 'item': ccReg.FT_ZONE},\ {'classname': 'statementhead', 'item': ccReg.FT_STATEMENTHEAD},\ {'classname': 'message', 'item': ccReg.FT_MESSAGE}] True """ import sys import fred_webadmin.config as config from pprint import pprint from omniORB import importIDL importIDL(config.idl) ccReg = sys.modules['ccReg'] Registry = sys.modules['Registry'] def corbaname_to_classname(item): """ Return classname (class name in lowercase) for a given ccReg.FT_FILTER* type. """ rules = { ccReg.FT_STATEMENTITEM._v : 'bankstatement' } return rules.get(item._v, item._n[3:].lower()) def reverse_dict(dictionary): return dict([(value, key) for key, value in dictionary.items()])
import sys, signal def quitHandler(signum, frame): raise KeyboardInterrupt signal.signal(signal.SIGQUIT, quitHandler) signal.signal(signal.SIGTSTP, quitHandler) from omniORB import CORBA import omniORB omniORB.omniidlArguments(["-I./idl"]) omniORB.importIDL("./idl/BrokerNameService.idl") omniORB.importIDL("./idl/IPControlBroker.idl") import EDCBA__POA as EDCBA orb = CORBA.ORB_init(sys.argv) ior = file('/tmp/BrokerNameService.ior').read() obj = orb.string_to_object(ior) nameservice = obj._narrow(EDCBA.BrokerNameService) registered = nameservice.getRegistered() for item in registered: print "%s: %s" % (item, nameservice.getAddressOf(item)) if 'IP Broker' in registered:
def systemFailure(cookie, retries, exc): if retries > 5: return False else: return True cookie = None omniORB.installTransientExceptionHandler(cookie, transientFailure) omniORB.installCommFailureExceptionHandler(cookie, commFailure) #omniORB.installSystemExceptionHandler(cookie, systemFailure) import config #module_name = importIDL(config.idl)[0] # this hase to be here because cherrypy session needs to know ccReg module on start (while loadin session from file) omniORB.importIDL(config.idl) ccReg = sys.modules['ccReg'] Registry = sys.modules['Registry'] orb = omniORB.CORBA.ORB_init(["-ORBnativeCharCodeSet", "UTF-8"], omniORB.CORBA.ORB_ID) #orb = CORBA.ORB_init(["-ORBnativeCharCodeSet", "UTF-8", "-ORBtraceLevel", "10"], CORBA.ORB_ID) #omniORB.setClientCallTimeout(2000) class Corba(object): def __init__(self): object.__init__(self) #self.module = sys.modules[module_name] #sys.modules[ #importIDL(idl or os.path.join(os.path.dirname(os.path.abspath(__file__)), IDL_FILE))[0] #] self.context = None def connect(self, ior = 'localhost', context_name = 'fred'):
import unittest, os # Sucks that we need to do this. from omniORB import importIDL importIDL("Widget.idl", ["-I../idl"]) # importIDL('../idl/epo.idl', ['-I../idl']) import logging logging.basicConfig() # logging.getLogger("EventChannel").setLevel(logging.DEBUG) # logging.getLogger("Rambler").setLevel(logging.DEBUG) # logging.getLogger("ZODBPool").setLevel(logging.DEBUG) from Rambler import Server Server.init("giop:tcp::6666") # from Rambler.PersistenceService import PersistenceService, InMemoryDataMapper from Rambler.PSQLPool import PSQLPool Server.registerService(PSQLPool("host=dev2", 20), "PSQLPool") Server.loadDescriptor("widget.xml") import Rambler.PostgresMappers tid = Server.txn.get_transaction_name()
#!/usr/bin/env python # This is a IP (L3) Broker for the Linux "ip addr" command # Copyright 2006 John T. Kamenik, GLPL, All rights reserved. import sys, signal from ControlBroker import ControlBroker from pprint import pprint try: from omniORB import CORBA import omniORB omniORB.omniidlArguments(["-I./idl"]) omniORB.importIDL("./idl/BrokerNameService.idl") omniORB.importIDL("./idl/IPControlBroker.idl") import EDCBA__POA import EDCBA pprint(EDCBA__POA.__dict__) pprint(EDCBA.__dict__) base = EDCBA__POA.IPControlBroker except object, reason: print "Exception", reason base = object class MyInterface(EDCBA.IPInterface): def __init__(self):
# This test code is chaotic, because it combines CORBA client and # server, both with variants for four different Python ORBs, one of # which doesn't even support the POA. Never ever do such thing in # real-world applications! import os, socket, sys, signal from EdcbaBroker.ControlBroker import ControlBroker try: from omniORB import CORBA import omniORB # for now assume we are being run from edcba root omniORB.omniidlArguments(["-I./idl"]) omniORB.importIDL("./idl/BrokerNameService.idl") omniORB.importIDL("./idl/echo.idl") import EDCBA__POA as EDCBA base = EDCBA.Echo except: # if we can't be a CORBA object, then we can't be anything base = object print "Failed to Initialize CORBA" # The echo servant class inherits from the ControlBroker class to get the # Name Server registration functions class EchoServant(base,ControlBroker): def __init__(self, orb): ControlBroker.__init__(self, orb, "Echo Server")
import unittest, os import logging logging.basicConfig() #logging.getLogger("EventChannel").setLevel(logging.DEBUG) #logging.getLogger("Rambler").setLevel(logging.DEBUG) #logging.getLogger("ZODBPool").setLevel(logging.DEBUG) # Sucks that we need to do this. from omniORB import importIDL importIDL('Widget.idl', ['-I../idl']) from Rambler import Server Server.init("giop:tcp::6666") from Rambler.PersistenceService import InMemoryDataMapper # Sigh, all these import's have to be done in the proper order ##from Rambler import ZODBPool, ZODBMapper ##from ZODB import FileStorage, Persistent, DB ##from tempfile import mktemp ##tempdir = '/tmp' # Just for now ##filename = mktemp() ##storage = FileStorage.FileStorage(filename) ##db = DB(storage, cache_size=1000) ##Server.registerService(ZODBPool.ZODBConnectionPool(db, 6), "ZODBPool") from Rambler.ciRelationService import ciRelationService RS = Server.registerService(ciRelationService, "RelationService") Server.loadDescriptor('widget.xml')
import CORBA, omniORB import sys omniORB.importIDL('./Bank.idl') import Bank class base: pass orb = CORBA.ORB_init(sys.argv) ior = open("/tmp/bank_example.ior").read() obj = orb.string_to_object(ior) account = obj._narrow(Bank.Account) print account account.notice( "Getting current balance" ) print "Current balance: %i" %(account.getBalance()) try: account.notice( "Withdrawing 30" ) account.withdraw(30) print "New balance: %i" %(account.getBalance()) except Bank.Account.InsufficientFunds, data: print "Overdrawn: %i"%(data.overdraft)