# Collection of code snippets by Arne Vajhøj 
# (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import sys
import time

sys.path.append('C:\\DivNative\\64bit\\omniORBpy-4.2.2-2.7\\lib\\python')
sys.path.append('C:\\DivNative\\64bit\\omniORBpy-4.2.2-2.7\\lib\\x86_win32')

from omniORB import CORBA
from omniORB import PortableServer
import CosNaming

import corbatest.common
import corbatest__POA.common

class TestImpl(corbatest__POA.common.Test):
    def __init__(self):
        self.counter = 0
    def add(self,a,b):
        return a + b
    def dup(self,s):
        return s + s
    def process(self,d):
        return corbatest.common.Data(d.iv + 1, d.sv + 'X')
    def getCounter(self):
        self.counter = self.counter + 1
        return self.counter
    def noop(self):
        return
    
orb = CORBA.ORB_init(['-ORBInitRef', 'NameService=corbaname::localhost:2809'], CORBA.ORB_ID)
poa = orb.resolve_initial_references('RootPOA')
srv = TestImpl()
nc = orb.resolve_initial_references('NameService')._narrow(CosNaming.NamingContext)
n = [CosNaming.NameComponent('TestPy', "")]
try:
    nc.bind(n, srv._this())
except CosNaming.NamingContext.AlreadyBound:
    nc.rebind(n, srv._this())
poaman = poa._get_the_POAManager()
poaman.activate()
orb.run()
#nc.ubind(n)
#orb.destroy()

