2 #include "Client_Task.h"
4 Client_Task::Client_Task (const ACE_TCHAR
*ior
,
6 ACE_Thread_Manager
*thr_mgr
)
7 : ACE_Task_Base (thr_mgr
)
9 , corb_ (CORBA::ORB::_duplicate (corb
))
20 // All factories are kindly provided by
21 // compiler so we just to put everything in a right order.
23 // Create and register factory for BaseNode.
24 BaseNode_init
*bn_factory
= 0;
25 ACE_NEW_RETURN (bn_factory
,
29 this->corb_
->register_value_factory (bn_factory
->tao_repository_id (),
31 bn_factory
->_remove_ref (); // release ownership
33 // Create and register factory for TreeController.
34 TreeController_init
*tc_factory
= 0;
35 ACE_NEW_RETURN (tc_factory
,
39 this->corb_
->register_value_factory (tc_factory
->tao_repository_id (),
41 tc_factory
->_remove_ref (); // release ownership
43 // Create and register factory for StringNode.
44 StringNode_init
*sn_factory
= 0;
45 ACE_NEW_RETURN (sn_factory
,
49 this->corb_
->register_value_factory (sn_factory
->tao_repository_id (),
51 sn_factory
->_remove_ref (); // release ownership
53 //Well, done with factories.
55 // Obtain reference to the object.
56 CORBA::Object_var tmp
=
57 this->corb_
->string_to_object(this->input_
);
59 Test_var test
= Test::_narrow(tmp
.in ());
61 if (CORBA::is_nil (test
.in ()))
63 ACE_ERROR_RETURN ((LM_DEBUG
,
64 "Nil Test reference <%s>\n",
69 // Now build simple graph (tree in our case).
71 TreeController_var tc
;
72 ACE_NEW_RETURN (tc
.inout (),
76 // Create the root node.
79 ACE_NEW_RETURN (sn
.inout (),
82 sn
->name ((const char*)("RootNode"));
85 // Create the left leaf.
88 ACE_NEW_RETURN (dummy
.inout (),
91 dummy
->name ((const char*)("LeftNode"));
95 // Create the right leaf.
98 ACE_NEW_RETURN (dummy
.inout (),
101 dummy
->name ((const char*)("RightNode"));
104 // dummy->right (sn); // ;-)
110 TreeController_var tc_copy
;
111 ACE_NEW_RETURN (tc_copy
.inout (),
115 // Create the root node.
118 ACE_NEW_RETURN (sn
.inout (),
121 sn
->name ((const char*)("RootNode"));
124 // Create the left leaf.
126 StringNode_var dummy
;
127 ACE_NEW_RETURN (dummy
.inout (),
130 dummy
->name ((const char*)("LeftNode"));
134 // Create the right leaf.
136 StringNode_var dummy
;
137 ACE_NEW_RETURN (dummy
.inout (),
140 dummy
->name ((const char*)("RightNode"));
143 // dummy->right (sn); // ;-)
147 if (!is_equal_tree (tc
.in (), tc_copy
.in ()))
149 ACE_ERROR ((LM_ERROR
,
150 "ERROR: tc != tc_copy\n"));
154 TreeController_var tc_result
=
155 test
->reflect (tc
.in ());
157 // The following two ifs will fail until bug 1390 is fixed.
158 if (is_equal_tree (tc
.in (), tc_result
.in ()))
160 ACE_ERROR ((LM_ERROR
,
161 "ERROR: tc == tc_result\n"));
164 if (result
== 0 && !is_equal_tree (tc
.in (), tc_copy
.in ()))
166 ACE_ERROR ((LM_ERROR
,
167 "ERROR: tc != tc_copy\n"));
173 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - test finished\n"));
175 catch (const CORBA::Exception
& ex
)
177 ex
._tao_print_exception ("Exception caught:");
185 Client_Task::is_equal_tree (TreeController
* tree1
, TreeController
* tree2
)
187 return is_equal_node (tree1
->root (), tree2
->root ());
192 Client_Task::is_equal_node (BaseNode
* node1
, BaseNode
* node2
)
195 if (!(node1
|| node2
))
199 StringNode
* sn1
= StringNode::_downcast (node1
);
200 StringNode
* sn2
= StringNode::_downcast (node2
);
202 if (!ACE_OS::strcmp (sn1
->name (), sn2
->name ()))
207 is_equal_node (node1
->left (), node2
->left ()) &&
208 is_equal_node (node1
->right (), node2
->right ()));
215 Client_Task::dump_node (BaseNode
*bn
, int indent
)
219 // This is ugly I know
221 for (; i
!= 0; i
--) ACE_DEBUG ((LM_DEBUG
, " "));
223 StringNode
*sn
= StringNode::_downcast (bn
);
226 ACE_DEBUG ((LM_DEBUG
, "%x <StringNode> %s\n",
232 ACE_DEBUG ((LM_DEBUG
,
237 dump_node (bn
->left (), indent
+ 1);
238 dump_node (bn
->right (), indent
+ 1);
242 Client_Task::dump_tree (TreeController
*tc
)
244 ACE_DEBUG ((LM_DEBUG
,
245 "(%P|%t) start tree dump <%x>\n",
248 dump_node (tc
->root (), 1);
250 ACE_DEBUG ((LM_DEBUG
,
251 "(%P|%t) end tree dump <%x>\n",