1 #include "ace/Functor.h"
6 This isn't too complicated, but it is a little convoluted. So, here's the
9 1. Two threads. One thread is a CORBA server, the other a CORBA
10 client to that CORBA server.
12 2. the main thread sets up the server-side stuff, and then fires off
13 a task to run the server.
15 3. once the server thread/task is running, the main thread makes
16 invocations to "match_references()" and reports the outcome.
18 The CORBA Object compares the stringified representation of two IORs
19 both generated from the ORB but in different contexts, and returns the
20 result of the comparison as a boolean.
23 class Foo_Impl
: public virtual POA_foo
26 CORBA::Boolean
match_references ();
28 CORBA::String_var ior_from_main_
;
29 ACE_Equal_To
<const char*> equal_func
;
30 ACE_Hash
<const char*> hash_func
;
34 Foo_Impl::match_references ()
36 CORBA::Object_var o
= _this ();
37 CORBA::ORB_var orb
= o
->_get_orb ();
38 CORBA::String_var ior_from_upcall
= orb
->object_to_string (o
.in());
40 CORBA::Boolean r1
= equal_func (this->ior_from_main_
.in(), ior_from_upcall
.in());
45 class Server_Task
: public ACE_Task_Base
48 Server_Task (CORBA::ORB_ptr orb
)
49 : orb_ (CORBA::ORB::_duplicate (orb
))
52 virtual ~Server_Task ();
59 Server_Task::~Server_Task() { }
69 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
74 s_orb
= CORBA::ORB_init (argc
, argv
);
76 CORBA::Object_var o
= s_orb
->resolve_initial_references ("RootPOA");
77 PortableServer::POA_var rootpoa
= PortableServer::POA::_narrow (o
.in());
78 if (CORBA::is_nil (rootpoa
.in()))
79 ACE_ERROR_RETURN ((LM_ERROR
, "(%P|%t): failed to get root poa\n"), 1);
81 PortableServer::POAManager_var poamgr
= rootpoa
->the_POAManager();
84 ACE_NEW_RETURN (foo
, Foo_Impl
, 1);
85 PortableServer::ServantBase_var
owner_transfer (foo
);
86 PortableServer::ObjectId_var id
= rootpoa
->activate_object (foo
);
87 o
= rootpoa
->id_to_reference (id
.in());
90 ACE_NEW_RETURN (foo2
, Foo_Impl
, 1);
91 PortableServer::ServantBase_var
foo_owner (foo2
);
92 foo_var f2
= foo2
->_this (); // implicit activation
96 foo
->ior_from_main_
= s_orb
->object_to_string (o
.in());
97 foo2
->ior_from_main_
= foo
->ior_from_main_
;
99 Server_Task
server(s_orb
.in());
100 server
.activate(1); // activate one thread running the task
102 foo_var f
= foo::_narrow (o
.in()); // ignore the possibility that
103 // it's not a 'foo' since we
106 int const iterations
= 10;
107 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client: next %d iterations should match\n",
109 for (int i
= 0; i
< iterations
; ++i
)
111 CORBA::Boolean b
= f
->match_references ();
112 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client: iteration %d, match = %d\n",
116 ACE_DEBUG ((LM_DEBUG
,
117 "(%P|%t) client: next %d iterations should NOT match\n",
119 for (int i
= 0; i
< iterations
; ++i
)
121 CORBA::Boolean b
= f2
->match_references ();
122 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client: iteration %d, match = %d\n",