Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / OBV / Forward / client.cpp
blobcf08b7f0dee133396c21f4bb695f29af5df603f9
1 #include "TreeBaseC.h"
2 #include "TreeControllerC.h"
3 #include "TreeNodeC.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'k':
19 ior = get_opts.optarg;
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-k <ior> "
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 void
36 dump_node (BaseNode *bn, int indent)
38 if (bn == 0) return;
40 // This is ugly I know
41 int i = indent;
42 for (; i != 0; i--) ACE_DEBUG ((LM_DEBUG, " "));
44 StringNode *sn = StringNode::_downcast (bn);
45 if (sn != 0)
47 ACE_DEBUG ((LM_DEBUG, "%x <StringNode> %C\n",
48 bn,
49 sn->name ()));
51 else
53 ACE_DEBUG ((LM_DEBUG,
54 "%x <BaseNode>\n",
55 bn));
58 dump_node (bn->left (), indent + 1);
59 dump_node (bn->right (), indent + 1);
62 void
63 dump_tree (TreeController *tc)
65 ACE_DEBUG ((LM_DEBUG,
66 "(%P|%t) start tree dump <%x>\n",
67 tc));
69 dump_node (tc->root (), 1);
71 ACE_DEBUG ((LM_DEBUG,
72 "(%P|%t) end tree dump <%x>\n",
73 tc));
77 int
78 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
80 try
82 CORBA::ORB_var orb =
83 CORBA::ORB_init (argc, argv);
85 if (parse_args (argc, argv) != 0)
86 return 1;
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,
94 BaseNode_init,
95 1);
97 orb->register_value_factory (bn_factory->tao_repository_id (),
98 bn_factory);
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,
104 TreeController_init,
107 orb->register_value_factory (tc_factory->tao_repository_id (),
108 tc_factory);
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,
114 StringNode_init,
117 orb->register_value_factory (sn_factory->tao_repository_id (),
118 sn_factory);
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",
133 ior),
137 // Now build simple graph (tree in our case).
139 TreeController_var tc;
140 ACE_NEW_RETURN (tc.inout (),
141 OBV_TreeController,
144 // Create the root node.
146 StringNode_var sn;
147 ACE_NEW_RETURN (sn.inout (),
148 OBV_StringNode,
150 sn->name ((const char*)("RootNode"));
151 tc->root (sn);
153 // Create the left leaf.
155 StringNode_var dummy;
156 ACE_NEW_RETURN (dummy.inout (),
157 OBV_StringNode,
159 dummy->name ((const char*)("LeftNode"));
160 sn->left (dummy);
163 // Create the right leaf.
165 StringNode_var dummy;
166 ACE_NEW_RETURN (dummy.inout (),
167 OBV_StringNode,
169 dummy->name ((const char*)("RightNode"));
170 sn->right (dummy);
172 // dummy->right (sn); // ;-)
176 // Dump the tree.
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 ());
185 test->shutdown ();
187 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - test finished\n"));
189 orb->destroy ();
191 catch (const CORBA::Exception& ex)
193 ex._tao_print_exception ("Exception caught:");
194 return 1;
197 return 0;