2 #include "tao/IORTable/IORTable.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/SString.h"
12 class Hello_impl
: virtual public POA_Test::Hello
21 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
24 CORBA::ORB_var orb
= CORBA::ORB::_nil();
29 orb
= CORBA::ORB_init (argc
, argv
);
31 // create Hello object
32 Test::Hello_impl hello_i
;
35 CORBA::Object_var obj_root
= orb
->resolve_initial_references ("RootPOA");
37 PortableServer::POA_var rootPOA
= PortableServer::POA::_narrow (obj_root
.in ());
39 PortableServer::ObjectId_var id
=
40 rootPOA
->activate_object (&hello_i
);
42 CORBA::Object_var object
= rootPOA
->id_to_reference (id
.in ());
44 Test::Hello_var hello
= Test::Hello::_narrow (object
.in ());
46 // give our object a friendly name
47 CORBA::Object_var iorTableObj
=
48 orb
->resolve_initial_references ("IORTable");
50 IORTable::Table_var iorTable
51 = IORTable::Table::_narrow (iorTableObj
.in ());
53 CORBA::String_var ior_string
= orb
->object_to_string (hello
.in ());
55 iorTable
->bind("hello", ior_string
.in ());
57 ACE_DEBUG ((LM_DEBUG
, "Created binding of name 'hello' in IOR table for IOR:\n%C\n", ior_string
.in ()));
59 // Activate the POA manager
60 PortableServer::POAManager_var poaManager
= rootPOA
->the_POAManager ();
62 poaManager
->activate ();
64 // try and access the object with its friendly name
65 ACE_CString
full_corbaloc (ior_string
.in (), 0, 1);
67 CORBA::ULong first_slash
= full_corbaloc
.find ("/", 0);
69 ACE_CString friendly_corbaloc
=
70 full_corbaloc
.substring (0,
73 friendly_corbaloc
+= "/hello";
75 ACE_DEBUG ((LM_DEBUG
, "Trying to access object with object ref:\n%C\n", friendly_corbaloc
.c_str ()));
77 CORBA::Object_var obj
= orb
->string_to_object (friendly_corbaloc
.c_str ());
79 TimeBase::TimeT timeout
= 10000000;
81 CORBA::Any timeout_any
;
82 timeout_any
<<= timeout
;
84 CORBA::PolicyList
policy_list (1);
85 policy_list
.length (1);
87 policy_list
[0] = orb
->create_policy (
88 Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
91 CORBA::Object_var rtt_obj
= obj
->_set_policy_overrides (
95 policy_list
[0]->destroy();
97 Test::Hello_var hello2
= Test::Hello::_narrow (rtt_obj
.in ());
99 if (CORBA::is_nil (hello2
.in ()))
101 ACE_ERROR ((LM_ERROR
,
102 "Unable to narrow from "
103 "corbaloc with policy override\n"));
108 hello2
->say_hello ();
110 ACE_DEBUG ((LM_DEBUG
, "Test succeeded !!!\n"));
115 catch (const CORBA::Exception
& ex
)
117 ex
._tao_print_exception ("Error - test failed - exception caught:");