Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Bug_3790_Regression / server2.cpp
blobdc3b6a55cc69b7e1fcdb804dc8e0ca83f05e08c0
1 #include "simple_testC.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/IORTable/IORTable.h"
4 #include "tao/LocalObject.h"
5 #include "tao/PortableServer/PortableServer.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Task.h"
9 const ACE_TCHAR *testIOR = ACE_TEXT ("corbaloc:iiop:localhost:15989/SIMPLE_TEST_KEY");
10 const ACE_TCHAR *anotherIOR = ACE_TEXT ("file://test.ior");
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:a:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'a':
22 testIOR = get_opts.opt_arg ();
23 break;
25 case 'k':
26 anotherIOR = get_opts.opt_arg ();
27 break;
29 case '?':
30 default:
31 ACE_ERROR_RETURN ((LM_ERROR,
32 "usage: %s "
33 "-k <ior>"
34 "-a <cobraloc>"
35 "\n",
36 argv [0]),
37 -1);
39 // Indicates successful parsing of the command line
40 return 0;
43 //*************************************************************************
44 class Task
45 : public virtual IORTable::Locator,
46 public virtual CORBA::LocalObject
48 public:
49 Task (CORBA::ORB_ptr orb);
51 char * locate (const char *);
53 private:
54 CORBA::ORB_var orb_;
57 char *
58 Task::locate (const char *)
60 CORBA::Object_var fwdObj = orb_->string_to_object(anotherIOR);
61 CORBA::String_var fwdString = orb_->object_to_string(fwdObj.in ());
63 ACE_DEBUG ((LM_DEBUG,
64 "IN LOCATOR! Forwarding client to: %C\n",
65 fwdString.in ()));
67 return fwdString._retn();
70 Task::Task (CORBA::ORB_ptr orb)
71 : orb_ (CORBA::ORB::_duplicate (orb))
75 int
76 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
78 try
80 CORBA::ORB_var orb =
81 CORBA::ORB_init (argc, argv, "MY_TEST_ORB");
83 if (parse_args (argc, argv) != 0)
84 return 1;
86 CORBA::Object_var object =
87 orb->resolve_initial_references("RootPOA");
89 PortableServer::POA_var root_poa =
90 PortableServer::POA::_narrow (object.in ());
92 if (CORBA::is_nil (root_poa.in ()))
94 ACE_ERROR ((LM_ERROR,
95 "rootPOA is nil!\n"));
97 return -1;
100 PortableServer::POAManager_var poa_manager =
101 root_poa->the_POAManager();
103 // Run ORB Event loop.
104 poa_manager->activate ();
106 // Create task.
107 Task *task = 0;
108 ACE_NEW_RETURN (task,
109 Task (orb.in ()),
111 IORTable::Locator_var owner_transfer (task);
113 // Resolve the IORTable and set the locator
114 CORBA::Object_var iorTableObj =
115 orb->resolve_initial_references("IORTable");
117 IORTable::Table_var local_ior_table =
118 IORTable::Table::_narrow (iorTableObj.in ());
120 local_ior_table->set_locator (task);
124 ACE_DEBUG ((LM_DEBUG,
125 "OK, now try to resolve a co-located "
126 "IORTable entry...\n"));
128 CORBA::Object_var clientObj = orb->string_to_object (testIOR);
130 simple::SimpleTest_T_var simpleTestClient =
131 simple::SimpleTest_T::_narrow (clientObj.in ());
133 if (CORBA::is_nil (simpleTestClient.in ()))
135 ACE_ERROR ((LM_ERROR,
136 "Simpe client is nil!\n"));
137 return 1;
140 ACE_DEBUG ((LM_DEBUG,
141 "We narrowed the object, now let's invoke it!\n"));
143 simpleTestClient->shutdown ();
145 catch(const CORBA::OBJ_ADAPTER &objAdapter)
147 objAdapter._tao_print_exception ("CAUGHT OBJ_ADAPTER!!!");
149 catch(const CORBA::OBJECT_NOT_EXIST &objNE)
151 objNE._tao_print_exception ("CAUGHT OBJECT NOT EXIST!!!");
154 ACE_DEBUG ((LM_DEBUG,
155 "Leaving!\n"));
157 catch (const CORBA::Exception &ex)
159 ex._tao_print_exception ("CAUGHT EXCEPTION: ");
160 return -1;
163 return 0;