2 #include "TreeControllerC.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
15 while ((c
= get_opts ()) != -1)
19 ior
= get_opts
.optarg
;
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
36 dump_node (BaseNode
*bn
, int indent
)
40 // This is ugly I know
42 for (; i
!= 0; i
--) ACE_DEBUG ((LM_DEBUG
, " "));
44 StringNode
*sn
= StringNode::_downcast (bn
);
47 ACE_DEBUG ((LM_DEBUG
, "%x <StringNode> %C\n",
58 dump_node (bn
->left (), indent
+ 1);
59 dump_node (bn
->right (), indent
+ 1);
63 dump_tree (TreeController
*tc
)
66 "(%P|%t) start tree dump <%x>\n",
69 dump_node (tc
->root (), 1);
72 "(%P|%t) end tree dump <%x>\n",
78 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
83 CORBA::ORB_init (argc
, argv
);
85 if (parse_args (argc
, argv
) != 0)
88 // All factories are kindly provided by
89 // compiler so we just to put everything in a right order.
91 // Create and register factory for BaseNode.
92 BaseNode_init
*bn_factory
= 0;
93 ACE_NEW_RETURN (bn_factory
,
97 orb
->register_value_factory (bn_factory
->tao_repository_id (),
99 bn_factory
->_remove_ref (); // release ownership
101 // Create and register factory for TreeController.
102 TreeController_init
*tc_factory
= 0;
103 ACE_NEW_RETURN (tc_factory
,
107 orb
->register_value_factory (tc_factory
->tao_repository_id (),
109 tc_factory
->_remove_ref (); // release ownership
111 // Create and register factory for StringNode.
112 StringNode_init
*sn_factory
= 0;
113 ACE_NEW_RETURN (sn_factory
,
117 orb
->register_value_factory (sn_factory
->tao_repository_id (),
119 sn_factory
->_remove_ref (); // release ownership
121 //Well, done with factories.
123 // Obtain reference to the object.
124 CORBA::Object_var tmp
=
125 orb
->string_to_object(ior
);
127 Test_var test
= Test::_narrow(tmp
.in ());
129 if (CORBA::is_nil (test
.in ()))
131 ACE_ERROR_RETURN ((LM_DEBUG
,
132 "Nil Test reference <%s>\n",
137 // Now build simple graph (tree in our case).
139 TreeController_var tc
;
140 ACE_NEW_RETURN (tc
.inout (),
144 // Create the root node.
147 ACE_NEW_RETURN (sn
.inout (),
150 sn
->name ((const char*)("RootNode"));
153 // Create the left leaf.
155 StringNode_var dummy
;
156 ACE_NEW_RETURN (dummy
.inout (),
159 dummy
->name ((const char*)("LeftNode"));
163 // Create the right leaf.
165 StringNode_var dummy
;
166 ACE_NEW_RETURN (dummy
.inout (),
169 dummy
->name ((const char*)("RightNode"));
172 // dummy->right (sn); // ;-)
177 dump_tree (tc
.in ());
179 TreeController_var result_tc
=
180 test
->reflect (tc
.in ());
182 // Dump the resulting tree.
183 dump_tree (result_tc
.in ());
187 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - test finished\n"));
191 catch (const CORBA::Exception
& ex
)
193 ex
._tao_print_exception ("Exception caught:");