Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / docs / tutorials / Quoter / On_Demand_Activation / server.cpp
blob09f2f8bb23db2eadf6ae458a39e25b28226199a9
2 #include "Stock_Factory_Locator_i.h"
3 #include "ace/streams.h"
5 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
7 try {
8 // First initialize the ORB, that will remove some arguments...
9 CORBA::ORB_var orb =
10 CORBA::ORB_init (argc, argv);
11 CORBA::Object_var poa_object =
12 orb->resolve_initial_references ("RootPOA");
13 PortableServer::POA_var poa =
14 PortableServer::POA::_narrow (poa_object.in ());
15 PortableServer::POAManager_var poa_manager =
16 poa->the_POAManager ();
17 poa_manager->activate ();
19 CORBA::PolicyList policies (3);
20 policies.length (3);
22 // Assign the polices
24 policies[0] =
25 poa->create_id_assignment_policy (PortableServer::USER_ID);
27 policies [1] =
28 poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);
30 policies [2] =
31 poa->create_servant_retention_policy (PortableServer::NON_RETAIN);
33 // Create the POA with these policies
34 PortableServer::POA_var child_poa =
35 poa->create_POA ("childPOA",
36 poa_manager.in (),
37 policies);
39 // Destroy the policy objects
40 for (CORBA::ULong i = 0; i != policies.length (); ++i) {
41 policies[i]->destroy ();
44 // Create a Stock_Factory_Locator
45 PortableServer::ServantLocator_var servant_locator =
46 new Quoter_Stock_Factory_Locator_i (orb.in ());
48 // Set the SM with the childPOA
49 child_poa->set_servant_manager (servant_locator.in ());
51 PortableServer::ObjectId_var child_oid =
52 PortableServer::string_to_ObjectId ("childFoo");
54 CORBA::Object_var stock_factory =
55 child_poa->create_reference_with_id (child_oid.in (),
56 "IDL:Quoter/Stock_Factory:1.0");
59 // Put the object reference as an IOR string
60 CORBA::String_var ior = orb->object_to_string (stock_factory.in ());
62 // Print it out!
63 cout << ior.in () << endl;
65 orb->run ();
67 // Destroy the POA, waiting until the destruction terminates
68 poa->destroy (1, 1);
69 orb->destroy ();
71 catch (const CORBA::Exception &) {
72 cerr << "CORBA exception raised!" << endl;
74 return 0;