Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / OBV / Forward / server.cpp
blob85e0d013af2a3f3b45da0435f4acb080e0d87bbc
1 #include "TreeBaseC.h"
2 #include "TreeControllerC.h"
3 #include "TreeNodeC.h"
4 #include "Test_impl.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/OS_NS_stdio.h"
9 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior_output_file = get_opts.optarg;
22 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-o <iorfile>"
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
40 try
42 CORBA::ORB_var orb =
43 CORBA::ORB_init (argc, argv);
45 // All factories are kindly provided by
46 // compiler so we just to put everything in a right order.
48 // Create and register factory for BaseNode.
49 BaseNode_init *bn_factory = 0;
50 ACE_NEW_RETURN (bn_factory,
51 BaseNode_init,
52 1);
54 orb->register_value_factory (bn_factory->tao_repository_id (),
55 bn_factory);
56 bn_factory->_remove_ref (); // release ownership
58 // Create and register factory for TreeController.
59 TreeController_init *tc_factory = 0;
60 ACE_NEW_RETURN (tc_factory,
61 TreeController_init,
62 1);
64 orb->register_value_factory (tc_factory->tao_repository_id (),
65 tc_factory);
66 tc_factory->_remove_ref (); // release ownership
68 // Create and register factory for StringNode.
69 StringNode_init *sn_factory = 0;
70 ACE_NEW_RETURN (sn_factory,
71 StringNode_init,
72 1);
74 orb->register_value_factory (sn_factory->tao_repository_id (),
75 sn_factory);
76 sn_factory->_remove_ref (); // release ownership
78 //Well, done with factories.
80 CORBA::Object_var poa_object =
81 orb->resolve_initial_references("RootPOA");
83 PortableServer::POA_var root_poa =
84 PortableServer::POA::_narrow (poa_object.in ());
86 if (CORBA::is_nil (root_poa.in ()))
87 ACE_ERROR_RETURN ((LM_ERROR,
88 " (%P|%t) Panic: nil RootPOA\n"),
89 1);
91 PortableServer::POAManager_var poa_manager =
92 root_poa->the_POAManager ();
94 if (parse_args (argc, argv) != 0)
95 return 1;
97 Test_impl *test_impl;
98 ACE_NEW_RETURN (test_impl,
99 Test_impl (orb.in ()),
102 PortableServer::ServantBase_var owner_transfer(test_impl);
104 PortableServer::ObjectId_var id =
105 root_poa->activate_object (test_impl);
107 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
109 Test_var test = Test::_narrow (object.in ());
111 CORBA::String_var ior =
112 orb->object_to_string (test.in ());
114 // If the ior_output_file exists, output the ior to it
115 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
116 if (output_file == 0)
117 ACE_ERROR_RETURN ((LM_ERROR,
118 "Cannot open output file for writing IOR: %s",
119 ior_output_file),
121 ACE_OS::fprintf (output_file, "%s", ior.in ());
122 ACE_OS::fclose (output_file);
124 poa_manager->activate ();
126 orb->run ();
128 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
130 root_poa->destroy (true, true);
132 orb->destroy ();
134 catch (const CORBA::Exception& ex)
136 ex._tao_print_exception ("Exception caught:");
137 return 1;
140 return 0;