[omniORB] omniORBpy 3.0 sample code and some questions
Chris Knight
cknight@ptolemy.arc.nasa.gov
Mon, 8 May 2000 09:27:42 -0700
All, after much reverse engineering and mailing list perusing, I was able to
get a (rather simplistic) omniORBpy client using the latest versions of
omniORB(py) to hit my nameserver and to connect to a CORBA ORB as well as
establishing a callback. I'm curious if I'm doing everything "correctly and
efficiently" or if I have some steps that are superfluous or I'm using the
modules incorrectly. (In particular, with POA_CosNaming and CosNaming.)
Needless to say, a full day's work (scanning the mailing list and
reverse-engineering omniORBpy) to generate such a simple example makes me
think that more (better?) Python examples need to be generated (by us, the
user community?) What say you? (In particular, I'm looking for some DII
examples.)
---The IDL---
module ChatApp
{
interface ChatClientCallBack
{
attribute string id;
void printmessage (in string message);
};
interface ChatServ
{
void register(in ChatClientCallBack ClientObj);
void broadcastmessage(in ChatClientCallBack ClientObj, in
string message);
};
};
---Here's the code---
import sys
import omniORB
import POA_ChatApp
import CosNaming
print 'What is your name?',
name = sys.stdin.readline()[:-1]
orb = omniORB.CORBA.ORB_init(sys.argv, omniORB.CORBA.ORB_ID)
poa = orb.resolve_initial_references('RootPOA')
poaManager = poa._get_the_POAManager()
poaManager.activate()
class Callback(POA_ChatApp.ChatClientCallBack):
def __init__(self, name):
self.name = name
def _get_id(self, *args):
return self.name
def printmessage(self, message): print `message`
callback = Callback(name)
callbackobj = callback._this()
nsobj = orb.resolve_initial_references('NameService')
nc = CosNaming.NameComponent('ChatServ', ' ')
chatserv = nsobj.resolve([nc])
chatserv.register(callbackobj)
while 1:
print 'Type something:',
a = sys.stdin.readline()[:-1]
chatserv.broadcastmessage(callbackobj, a)