[omniORB] Persistent Objects Question

jnye@micro-optics.com jnye@micro-optics.com
Mon, 29 Jan 2001 13:49:29 -0400


Hi David,

Nope, that was just a typo -- my program actually has a WinMain and I just
threw in main for the purposes of the email.

Thanks anyway,
Jason.

-----Original Message-----
From: David Byron [mailto:dbyron@coactive.com]
Sent: Monday, January 29, 2001 1:40 PM
To: 'jnye@micro-optics.com'
Subject: RE: [omniORB] Persistent Objects Question


I doubt this is it, and I haven't looked closely at your code, but argv is
usually declarded as (char **argv) or (char *argv[]).  Maybe it will have
some effect.

-DB

> int main(int argc, char * argv)
> {
>     try
>     {
>         namespace PS = PortableServer;  // Easier to read!!
> 
>         // Initialize the orb
>         CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
> 
>         // Get reference to Root POA
>         CORBA::Object_var obj = 
> orb->resolve_initial_references("RootPOA");
>         PS::POA_var poa = PS::POA::_narrow(obj);
> 
>         // Activate POA manager
>         PS::POAManager_var mgr = poa->the_POAManager();
> 
>         PS::LifespanPolicy_var lifespan =
> poa->create_lifespan_policy(PS::PERSISTENT);
>         PS::IdAssignmentPolicy_var assign =
> poa->create_id_assignment_policy(PS::USER_ID);
> 
>         CORBA::PolicyList poaPolicyList;
>         poaPolicyList.length(2);
>         poaPolicyList[0] = PS::LifespanPolicy::_duplicate(lifespan);
>         poaPolicyList[1] = PS::IdAssignmentPolicy::_duplicate(assign);
> 
>         PS::POA_var childPOA = poa->create_POA("MyObjectPOA", mgr,
> poaPolicyList);
>         lifespan->destroy();
>         assign->destroy();
> 
>         MyObjectImpl servant;
>         PS::ObjectId_var oid = PS::string_to_ObjectId("MyObject");
> 
>         // Just register and exit.
>         if (findCmdLineArg(argc, argv, "/RegServer"))
>         {
>             // Object registration/unregistration.
>             try
>             {
>                 CORBA::Object_var ref =
> childPOA->create_reference_with_id(oid, "IDL:MyObject:1.0");
>                 CORBA::String_var ior = orb->object_to_string(ref);
> 
>                 // Simply writes a reference to a globally accessable
> registration file in the form:
>                 //
>                 // MyObject=IOR:.....
>                 //
>                 ObjectRegistrar::registerIOR("MyObject", 
> (const char *)ior);
>             }
>             catch (...)
>             {
>                 ::MessageBox(0, "Failed to register IOR", 
> "MyObject", 0);
>                 return -1;
>             }
>         }
>         else
>         {
>             // Normal execution of server.
>             mgr->activate();
> 
>             // Activate object.
>             childPOA->activate_object_with_id(oid, &servant);
>             orb->run();
>         }
>     }
>     catch(const CORBA::Exception &e )
>     {
>         int size;
>         cout << e._NP_repoId(&size) << endl;
>         return -1;
>     }
> 
>     return 0;
> }