[omniORB] Is there another way to get a reference other than
NameService
Guy Trudel
gtrudel@mediatrix.com
Wed, 22 Dec 1999 09:33:09 -0500
Glad you ask this question. I found a way to do it using the
omniORB::loader.
My goal is to replace a NT service named pipe server by a Nt service corba
server,
so clients already know the server ip address.
The code below is part of my test (with OmniOrb 2.8) of doing it, I'm quite
new
with OmniOrb, so I don't pretend it's the way to do it.
On the server side:
int main(int argc, char* argv[])
{
int nArcg = 7;
char *ppArg[] = { argv[0] ,
"-ORBInitialHost", "xxx.xxx.xxx.xxx",
"-ORBInitialPort", "1000",
"-BOAiiop_port", "1002" };
CORBA::ORB_ptr orb = CORBA::ORB_init(nArcg,ppArg,"omniORB2");
CORBA::BOA_ptr boa = orb->BOA_init(nArcg,ppArg,"omniORB2_BOA");
// Set the loader (found below)
omniORB::loader::set(loader);
CCorbaServerImpl server;
m_pUniqueServer = &server;
server._obj_is_ready(boa);
cout << orb->object_to_string(&server) << " is ready" << endl;
boa->impl_is_ready();
...
}
static CORBA::Object_ptr loader(const omniORB::objectKey& key)
{
if( (key.hi == 0) && (key.med == 0) && (key.lo == 1) )
{
if( m_pUniqueServer == NULL )
return CORBA::Object::_nil();
else
return CORBA::Object::_duplicate(m_pUniqueServer);
}
else
{
return CORBA::Object::_nil();
}
}
On client side:
void encodeIOPprofile(IOP::TaggedProfile& profile)
{
int objkeysize = sizeof(omniORB::objectKey);
profile.tag = IOP::TAG_INTERNET_IOP;
// ORBInitialHost
CORBA::ULong hlen = strlen((const char *)"xxx.xxx.xxx.xxx") + 1;
{
// calculate the total size of the encapsulated stream
CORBA::ULong total = 8 + hlen; // first 4 bytes + aligned
host
total = ((total + 1) & ~(1)) + 2; // aligned port value
total = ((total + 3) & ~(3)) + 4 + // aligned object key
objkeysize;
profile.profile_data.length(total);
}
profile.profile_data[0] = omni::myByteOrder;
profile.profile_data[1] = 1; // IIOP major version no. = 1
profile.profile_data[2] = 0; // IIOP minor version no. = 0
profile.profile_data[3] = 0;
{
CORBA::ULong &l = (CORBA::ULong &) profile.profile_data[4];
l = hlen;
}
// ORBInitialHost
memcpy((void *)&(profile.profile_data[8]),(void
*)"xxx.xxx.xxx.xxx",hlen);
CORBA::ULong idx = ((8 + hlen) + 1) & ~(1);
{
CORBA::UShort &l = (CORBA::UShort &) profile.profile_data[idx];
//### BOAiiop_port
l = 1002;
}
idx = ((idx + 2) + 3) & ~(3);
{
CORBA::ULong &l = (CORBA::ULong &) profile.profile_data[idx];
l = objkeysize;
}
if (objkeysize)
{
// Put objkey.hi and objkey.med to 0 so loader will know
// it's a "special" load
omniORB::objectKey objkey;
objkey.hi = 0;
objkey.med = 0;
// Use objkey.lo as the object key (see server loader)
objkey.lo = 1;
idx += 4;
memcpy((void *)&profile.profile_data[idx],
(void *)&objkey,objkeysize);
}
}
MyCorbaServer_ptr GetMyCorbaServer()
{
int nArcg = 7;
char *ppArg[] = { argv[0] ,
"-ORBInitialHost", "xxx.xxx.xxx.xxx",
"-ORBInitialPort", "1000",
"-BOAiiop_port", "1002" };
CORBA::ORB_ptr orb = CORBA::ORB_init(nArcg,ppArg,"omniORB2");
MyCorbaServer_ptr pServer = NULL;
IOP::TaggedProfileList taggedProfileList;
taggedProfileList.length(1);
encodeIOPprofile(taggedProfileList[0]);
omniObject* pOmniObject;
pOmniObject = omni::createObjRef(MyCorbaServer_IntfRepoID,NULL,
&taggedProfileList,false);
if( pOmniObject != NULL )
{
CORBA::Object_ptr pCorbaObject;
pCorbaObject =
(CORBA::Object_ptr)pOmniObject->_widenFromTheMostDerivedIntf(0);
if( pCorbaObject != NULL )
{
pServer = MyCorbaServer::_narrow(pCorbaObject);
}
}
return pServer;
}
Guy Trudel
-----Original Message-----
From: Ceyhun ÖZGÜN [mailto:ceyhun_ozgun@hotmail.com]
Sent: Wednesday, December 22, 1999 2:27 AM
To: djr@uk.research.att.com
Cc: omniorb-list@uk.research.att.com
Subject: [omniORB] Is there another way to get a reference other than
NameService
Hi,
I want to use specific server machines with static IP to implement objects.
And I don't want to use NameService.
I want to get a reference with given an IP address and a port number of
server machine.
Is it possible to do this?
Or is there any other way ?
Thanks in advance.
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com