Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Abstract_Interface / server.cpp
blob27aea7461808deb7668cc18ff3576b4481cfe82f
1 // -*- C++ -*-
2 #include "test_i.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'o':
18 ior_output_file = get_opts.optarg;
19 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 ACE_TEXT("usage: %s ")
24 ACE_TEXT("-o <iorfile>")
25 ACE_TEXT("\n"),
26 argv [0]),
27 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 try
39 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
41 // Create and register factory for BaseNode.
42 BaseNode_init *bn_factory = 0;
43 ACE_NEW_RETURN (bn_factory,
44 BaseNode_init,
45 1);
47 orb->register_value_factory (bn_factory->tao_repository_id (),
48 bn_factory);
49 bn_factory->_remove_ref (); // release ownership
51 // Create and register factory for TreeController.
52 TreeController_init *tc_factory = 0;
53 ACE_NEW_RETURN (tc_factory,
54 TreeController_init,
55 1);
57 orb->register_value_factory (tc_factory->tao_repository_id (),
58 tc_factory);
59 tc_factory->_remove_ref (); // release ownership
61 // Create and register factory for StringNode.
62 StringNode_init *sn_factory = 0;
63 ACE_NEW_RETURN (sn_factory,
64 StringNode_init,
65 1);
67 orb->register_value_factory (sn_factory->tao_repository_id (),
68 sn_factory);
69 sn_factory->_remove_ref (); // release ownership
71 CORBA::Object_var poa_object =
72 orb->resolve_initial_references ("RootPOA");
74 if (CORBA::is_nil (poa_object.in ()))
76 ACE_ERROR_RETURN ((LM_ERROR,
77 " (%P|%t) Unable to initialize the POA.\n"),
78 1);
81 PortableServer::POA_var root_poa =
82 PortableServer::POA::_narrow (poa_object.in ());
84 PortableServer::POAManager_var poa_manager =
85 root_poa->the_POAManager ();
87 if (parse_args (argc, argv) != 0)
89 return 1;
92 passer_i servant (orb.in (), root_poa.in ());
93 PortableServer::ObjectId_var id =
94 root_poa->activate_object (&servant);
96 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
98 passer_var server =
99 passer::_narrow (object.in ());
101 CORBA::String_var ior =
102 orb->object_to_string (server.in ());
104 ACE_DEBUG ((LM_DEBUG,
105 "Activated as <%C>\n",
106 ior.in ()));
108 // If the ior_output_file exists, output the ior to it
109 if (ior_output_file != 0)
111 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
113 if (output_file == 0)
115 ACE_ERROR_RETURN ((LM_ERROR,
116 "Can't open output file for writing IOR: %s",
117 ior_output_file),
121 ACE_OS::fprintf (output_file,
122 "%s",
123 ior.in ());
124 ACE_OS::fclose (output_file);
127 poa_manager->activate ();
129 orb->run ();
131 // Destroy the POA, waiting until the destruction terminates
132 root_poa->destroy (true, true);
134 orb->destroy ();
136 catch (const CORBA::Exception& ex)
138 ex._tao_print_exception ("Server: exception caught - ");
139 return 1;
142 return 0;