Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / docs / tutorials / Quoter / Simple / Impl-Repo / server.cpp
blob731c72a293cba6908f044680baea88db7d9249a5
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * In this example,
7 * - Example showing the working of implementation repository.
9 * @author Priyanka Gontla
11 //=============================================================================
14 #include "Stock_Factory_i.h"
15 #include "tao/IORTable/IORTable.h"
16 #include "ace/streams.h"
18 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
20 try {
21 // Initialze the ORB.
22 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
24 // Get a reference to the RootPOA.
25 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
27 // Get the POA_var object from Object_var.
28 PortableServer::POA_var root_poa =
29 PortableServer::POA::_narrow (obj.in ());
31 // Get the POAManager of the RootPOA.
32 PortableServer::POAManager_var poa_manager =
33 root_poa->the_POAManager ();
35 poa_manager->activate ();
37 // Policies for the childPOA to be created.
38 CORBA::PolicyList policies;
39 policies.length (2);
41 policies[0] =
42 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
43 policies[1] =
44 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
47 // Create the childPOA under the RootPOA.
48 PortableServer::POA_var child_poa =
49 root_poa->create_POA ("childPOA",
50 poa_manager.in (),
51 policies);
53 // Destroy the policy objects
54 for (CORBA::ULong i = 0; i != policies.length (); ++i) {
55 policies[i]->destroy ();
58 // Create an instance of class Quoter_Stock_Factory_i.
59 Quoter_Stock_Factory_i stock_factory_i;
61 // Get the Object ID.
62 PortableServer::ObjectId_var oid =
63 PortableServer::string_to_ObjectId ("Stock_Factory");
65 // Activate the Stock_Factory object.
66 child_poa->activate_object_with_id (oid.in (),
67 &stock_factory_i);
69 // Get the object reference.
70 CORBA::Object_var stock_factory =
71 child_poa->id_to_reference (oid.in ());
73 CORBA::Object_var table_object =
74 orb->resolve_initial_references ("IORTable");
76 // Stringify all the object referencs.
77 CORBA::String_var ior = orb->object_to_string (stock_factory.in ());
79 IORTable::Table_var adapter =
80 IORTable::Table::_narrow (table_object.in ());
81 if (CORBA::is_nil (adapter.in ()))
83 ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
85 else
87 CORBA::String_var ior =
88 orb->object_to_string (stock_factory.in ());
90 adapter->bind ("childPOA", ior.in ());
93 orb->run ();
95 // Destroy POA, waiting until the destruction terminates.
96 root_poa->destroy (true, true);
97 orb->destroy ();
99 catch (const CORBA::Exception &) {
100 cerr << "CORBA exception raised !" << endl;
102 return 0;