Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / IORTable_Locator / server.cpp
blob6b4e9e418d0475d335f39c61f3490feb91a847e0
1 #include "simple_test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "tao/ORB_Core.h"
5 #include "tao/IORTable/IORTable.h"
6 #include "tao/LocalObject.h"
7 #include "tao/PortableServer/PortableServer.h"
9 CORBA::String_var testIOR;
11 //*************************************************************************
12 class Task
13 : public virtual IORTable::Locator,
14 public virtual CORBA::LocalObject
16 public:
17 Task (CORBA::ORB_ptr orb);
19 char * locate (const char *);
21 private:
22 CORBA::ORB_var orb_;
25 char *
26 Task::locate (const char * id)
28 CORBA::Object_var fwdObj = orb_->string_to_object(testIOR.in ());
29 CORBA::String_var fwdString = orb_->object_to_string(fwdObj.in ());
31 ACE_DEBUG ((LM_DEBUG,
32 "IN LOCATOR! Forwarding client %C to: %C\n",
33 id,
34 fwdString.in ()));
36 return fwdString._retn();
39 Task::Task (CORBA::ORB_ptr orb)
40 : orb_ (CORBA::ORB::_duplicate (orb))
44 int
45 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
47 try
49 CORBA::ORB_var orb =
50 CORBA::ORB_init (argc, argv);
52 CORBA::Object_var poa_object =
53 orb->resolve_initial_references ("RootPOA");
55 PortableServer::POA_var root_poa =
56 PortableServer::POA::_narrow (poa_object.in ());
58 if (CORBA::is_nil (root_poa.in ()))
59 ACE_ERROR_RETURN ((LM_ERROR,
60 " (%P|%t) Panic: nil RootPOA\n"),
61 1);
63 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
65 Simple_Test_i *test_impl = 0;
66 ACE_NEW_RETURN (test_impl,
67 Simple_Test_i (orb.in ()),
68 1);
69 PortableServer::ServantBase_var owner_transfer (test_impl);
71 PortableServer::ObjectId_var id =
72 root_poa->activate_object (test_impl);
74 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
76 simple::SimpleTest_T_var theServer =
77 simple::SimpleTest_T::_narrow (object.in ());
79 testIOR = orb->object_to_string (theServer.in ());
81 poa_manager->activate ();
83 // Create task.
84 Task *task = 0;
85 ACE_NEW_RETURN (task,
86 Task (orb.in ()),
87 1);
88 IORTable::Locator_var iorloc_transfer (task);
90 // Resolve the IORTable and set the locator
91 CORBA::Object_var iorTableObj =
92 orb->resolve_initial_references("IORTable");
94 IORTable::Table_var local_ior_table =
95 IORTable::Table::_narrow (iorTableObj.in ());
97 local_ior_table->set_locator (task);
99 orb->run ();
101 ACE_DEBUG ((LM_DEBUG, "Server - event loop finished\n"));
103 root_poa->destroy (true, true);
105 orb->destroy ();
107 catch (const CORBA::Exception& ex)
109 ex._tao_print_exception ("Server - Exception caught:");
110 return 1;
113 return 0;