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"
9 const ACE_TCHAR
*testIOR
= ACE_TEXT ("corbaloc:iiop:localhost:15989/SIMPLE_TEST_KEY");
10 const ACE_TCHAR
*anotherIOR
= ACE_TEXT ("file://test.ior");
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:a:"));
18 while ((c
= get_opts ()) != -1)
22 testIOR
= get_opts
.opt_arg ();
26 anotherIOR
= get_opts
.opt_arg ();
31 ACE_ERROR_RETURN ((LM_ERROR
,
39 // Indicates successful parsing of the command line
43 //*************************************************************************
45 : public virtual IORTable::Locator
,
46 public virtual CORBA::LocalObject
49 Task (CORBA::ORB_ptr orb
);
51 char * locate (const 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 ());
64 "IN LOCATOR! Forwarding client to: %C\n",
67 return fwdString
._retn();
70 Task::Task (CORBA::ORB_ptr orb
)
71 : orb_ (CORBA::ORB::_duplicate (orb
))
76 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
81 CORBA::ORB_init (argc
, argv
, "MY_TEST_ORB");
83 if (parse_args (argc
, argv
) != 0)
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 ()))
95 "rootPOA is nil!\n"));
100 PortableServer::POAManager_var poa_manager
=
101 root_poa
->the_POAManager();
103 // Run ORB Event loop.
104 poa_manager
->activate ();
108 ACE_NEW_RETURN (task
,
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"));
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
,
157 catch (const CORBA::Exception
&ex
)
159 ex
._tao_print_exception ("CAUGHT EXCEPTION: ");