[omniORB] corbaloc/corbaname
Frédéric Prin
frederic.prin@silvaco.com
Fri, 22 Feb 2002 13:56:33 +0100
Hi,
I've already wrote what you need : mangling argc argv
the following parseCommandLine method parse the main argc argv and update
the class member
m_nOrbArgc and m_nOrbArgv that will be passed to ORB_init
Hope it helps
void CorbaClient::parseCommandLine(int argc, char *argv[])
// Parse the command line and look for -ORB args.
// If no -ORBpoa_iiop_port exist, append the argument -ORBpoa_iiop_port
<m_nINSPOAPortNumber>
// in <m_OrbArgv> and update <m_nOrbArgc>.
// If the Import/Export mode is not ExM_INSPOA, m_OrbArgv and m_OrbArgc are
initialized with
// argv and argc.
// Note: argc and argv are unchanged
{
// The new argv, argc are initialised with the actual argv, argc values
m_OrbArgv = argv;
m_nOrbArgc = argc;
if (m_ImportExportMode == ExM_INSPOA)
{
//
// Look for -ORB arguments
//
bool bParamAlreadyExist = false;
int idx = 1;
while (argc > idx)
{
// -ORBxxxxxxx ?
if (strlen(argv[idx]) < 4 ||
!(argv[idx][0] == '-' && argv[idx][1] == 'O' &&
argv[idx][2] == 'R' && argv[idx][3] == 'B'))
// This is not an -ORB argument
{
// Go to next argument
idx++;
continue;
}
//
// Standard options
//
//
// -ORBpoa_iiop_port
//
if( strcmp(argv[idx],"-ORBpoa_iiop_port") == 0 )
{
if( (idx+1) >= argc )
{
cerr << "CorbaClientServer::Create failed -- missing -ORBpoa_iiop_port
parameter." << endl;
break;
}
unsigned port;
if( sscanf(argv[idx+1], "%u", &port) != 1 ||
(port == 0 || port >= 65536) )
{
cerr << "CorbaClientServer::Create failed -- invalid -ORBpoa_iiop_port
parameter." << endl;
break;
}
// The -ORBpoa_iiop_port argument exist and is valid
bParamAlreadyExist = true;
break;
}
// Go to next argument
idx++;
}
//
// Append -ORBpoa_iiop_port <m_nINSPOAPortNumber>
//
if (!bParamAlreadyExist)
{
// Create 2 arguments
// * -ORBpoa_iiop_port
// * "m_nINSPOAPortNumber"
char *szArg[2] = {"-ORBpoa_iiop_port", NULL};
char szNumPort[10];
sprintf(szNumPort, "%d", m_nINSPOAPortNumber);
szArg[1] = strdup(szNumPort);
int addedArgc = sizeof(szArg) / sizeof(char *);
m_nOrbArgc += addedArgc;
// allocate a new entry in the string array
m_OrbArgv = (char**)malloc(m_nOrbArgc*sizeof(char*));
m_bArgvAllocated = true;
// allocate each string and recopy argv[i] to newargv[i]
int i;
for (i = 0; i < argc; i++)
m_OrbArgv[i] = strdup(argv[i]);
// append the -ORBpoa_iiop_port arg
for (int j = i; j < m_nOrbArgc; j++)
m_OrbArgv[j] = strdup(szArg[j - i]);
// destroy the duplicated string because it is no more needed
// and already duplicated in m_OrbArgv.
delete szArg[1];
} // End if (!bParamAlreadyExist)
} // End if (m_ImportExportMode == ExM_INSPOA)
}
| Frédéric Prin
| Senior Software Engineer
|
| S I L V A C O
| Grenoble REsearch CEnter
| Tel 04 56 38 10 33
----- Original Message -----
From: Nick Murtagh <murtaghn@tcd.ie>
To: <omniorb-list@uk.research.att.com>
Sent: Friday, February 22, 2002 12:56 PM
Subject: Re: [omniORB] corbaloc/corbaname
> On Friday 22 February 2002 11:42, Duncan Grisby wrote:
> > orb = CORBA.ORB_init(sys.argv)
> > ins_poa = orb.resolve_initial_references("omniINSPOA")
> >
> > servant = MyImplementation()
> > ins_poa.activate_object_with_id("example", servant)
> >
> > ins_poa._get_the_POAManager().activate()
> > orb.run()
>
> Ah. Excellent.
>
> > The object is now available as corbaloc::host.name:port/example. You
> > should pin down the port number with -ORBpoa_iiop_port in omniORB 3 o=
r
> > -ORBendPoint in omniORB 4.
>
> Is there any way to specify this from within a program? Without having =
to
> mangle argc and argv? If not I suppose I can just write some kind of a
> wrapper.
>