diff options
author | doccvs <doccvs@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-03-24 18:17:40 +0000 |
---|---|---|
committer | doccvs <doccvs@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-03-24 18:17:40 +0000 |
commit | 7315c85654dcb0a24a9db7d7ca40fefb25a03d9f (patch) | |
tree | a69a92e233c56416b58d60120728b8d641000ec5 | |
parent | 8a8f98762390a3fd3ab27d2e1501bab606988ee3 (diff) | |
download | ATCD-7315c85654dcb0a24a9db7d7ca40fefb25a03d9f.tar.gz |
2000-03-24 Priyanka Gontla <pgontla@doc.ece.uci.edu>
-rw-r--r-- | TAO/docs/tutorials/Quoter/Simple/Persistent/server.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/TAO/docs/tutorials/Quoter/Simple/Persistent/server.cpp b/TAO/docs/tutorials/Quoter/Simple/Persistent/server.cpp new file mode 100644 index 00000000000..6d062fd828d --- /dev/null +++ b/TAO/docs/tutorials/Quoter/Simple/Persistent/server.cpp @@ -0,0 +1,97 @@ +// $Id$ +// +//=========================================================================== +// = FILENAME +// server.cpp +// +// = DESCRIPTION +// In this example, +// - A new POA (childPOA) is created and its objects are +// made persistant. +// = AUTHOR +// Priyanka Gontla +//============================================================================ + +#include "Stock_Factory_i.h" +#include <iostream.h> + +int +main (int argc, char* argv[]) +{ + try { + + // Initialze the ORB. + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); + + // Get a reference to the RootPOA. + CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); + + // Get the POA_var object from Object_var. + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (obj.in ()); + + // Get the POAManager of the RootPOA. + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + poa_manager->activate (); + + // Create a USER_ID IdAssignmentpolicy object. + PortableServer::IdAssignmentPolicy_var idassignment = + root_poa->create_id_assignment_policy (PortableServer::USER_ID); + + // Create a PERSISTENT LifespanPolicy object. + PortableServer::LifespanPolicy_var lifespan = + root_poa->create_lifespan_policy (PortableServer::PERSISTENT); + + // Policies for the childPOA to be created. + CORBA::PolicyList policies; + policies.length (2); + + policies[0] = + PortableServer::IdAssignmentPolicy::_duplicate (idassignment); + + policies[1] = + PortableServer::LifespanPolicy::_duplicate (lifespan); + + // Create the childPOA under the RootPOA. + PortableServer::POA_var child_poa = + root_poa->create_POA ("childPOA", + poa_manager.in (), + policies); + + // Destroy policy objects. + idassignment->destroy (); + lifespan->destroy (); + + // Create an instance of class Quoter_Stock_Factory_i. + Quoter_Stock_Factory_i stock_factory_i; + + // Get the Object ID. + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId ("Stock_Factory"); + + // Activate the Stock_Factory object. + child_poa->activate_object_with_id (oid.in (), + &stock_factory_i); + + // Get the object reference. + CORBA::Object_var stock_factory = + child_poa->id_to_reference (oid.in ()); + + // Stringify all the object referencs. + CORBA::String_var ior = orb->object_to_string (stock_factory.in ()); + // Print them out ! + std::cout << ior.in () << std::endl; + + orb-> run (); + + // Destroy POA, waiting until the destruction terminates. + root_poa->destroy (1, 1); + orb->destroy (); + } + catch (CORBA::Exception &ex) { + std::cerr << "CORBA exception raised !" << std::endl; + } + return 0; +} |