ServiceOptions is a component for handling of typical command options of CORBA Service-like program.
What it mean: usual CORBA Service export to "world" few objects: so called "Root Objects" of the service. For example, Collecion Service exports CollectionFactory and RACollectionFactory ; NamingService exports RootNamingContext. Service users obtaine access to such services via propierty mechanizme of ORB.
For standart CORBA services this is call of ORB::resolve_initial_references(name); but process of setting initial references in ORB with -ORBIntRef option require knowing IOR-s of using objects during start of the program.
Usually, "root objects" of the service are exported by
What do ServiceOptions: It's incapsulate all this work in one method call. I. e. you just point to serlet and name; after this you object is accessible via corbaloc-style IOR and optionally is published in other ways, depends from command line options of you server.
ServiceOptions is based on ProgOptions
(www.gradsdoft.kiev.ua/eng/Products/ToolBox/ProgOptions/ProgGuide/ProgrammingGuide_eng.html)
This document is an unformal description, for full specification, please, use API reference
(http://www.gradsoft.kiev.ua/common/ToolBox/ServiceOptions/API/index.html).
Programmer must perform the next steps:
ServiceOptions::putServiceName
ServiceOptions::parse for parsing options (options
--help and --config <filename>, if exist, will be handled,
see ProgOptions ProgrammingGuide for detail)
ServiceOptions::bindServiceObject
--with-naming - initial objects are registered in NameService
--ior-stdout - stringifized object references are printed on standart output of a program.
--ior-file-<name> - IOR of object wiht name <name> will be published to file with name <argument of thid option>
interface HelloWorlder
{
void hello_world();
};
#include <tao/CORBA.h> //
#include <tao/PortableServer/PortableServer.h> // for TAO-1.2
#include <orbsvcs/CosNamingC.h> //
#include <HelloWorlderS.h> //
#include <iostream>
using namespace std;
#include <GradSoft/ServiceOptions.h> // do'nt forget
using namespace GradSoft; //
class HelloWorlder_impl:public POA_HelloWorlder // interface
{ // implementation
public: //
void hello_world() { cout << "Hello, world" << endl; } //
}; //
int main(int argc, char** argv)
{
ServiceOptions options;
options.putServiceName("HelloService"); // set service name
if (!options.parse(argc,argv)) return 1; // parse options set
// use copy of ServiceOptions's internal (argument count,argument vector) pair
// to make it possible
// ORB_init() takes comand-line options in ProgOptions config file:
ProgOptions::ArgsHolder argsHolder;
argsHolder.takeArgv(options);
CORBA::ORB_var orb = CORBA::ORB_init(argsHolder.argc,argsHolder.argv);
CORBA::Object_var poaObj = // standard
orb->resolve_initial_references("RootPOA"); // steps
PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObj); //
PortableServer::POAManager_var poaManager = poa->the_POAManager(); //
poaManager->activate(); //
HelloWorlder_impl helloWorlder_impl; // create object
HelloWorlder_var helloWorlder = helloWorlder_impl._this();
options.bindServiceObject( // principal call
orb,
helloWorlder,
&helloWorlder_impl,
"HelloService",
true
);
orb->run();
orb->destroy();
return 0;
}
This program handle next options:
--with-naming, --ior-stdout, --ior-file-myName
as it was described above;
--help É --config
as it was described in Programming guide for ProgOptions package;