Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Oneway_Buffering / server.cpp
blob3540e408d41001c50d8d45cfca0c436a2b8c1ca4
1 #include "Oneway_Buffering.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
5 const ACE_TCHAR *ior_output_file = ACE_TEXT("server.ior");
6 const ACE_TCHAR *ior = ACE_TEXT("file://admin.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:k:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'o':
18 ior_output_file = get_opts.opt_arg ();
19 break;
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-o <iorfile> "
30 "-k <ior> "
31 "\n",
32 argv [0]),
33 -1);
35 // Indicates successful parsing of the command line
36 return 0;
39 int
40 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
42 try
44 CORBA::ORB_var orb =
45 CORBA::ORB_init (argc, argv);
47 CORBA::Object_var poa_object =
48 orb->resolve_initial_references("RootPOA");
50 PortableServer::POA_var root_poa =
51 PortableServer::POA::_narrow (poa_object.in ());
53 if (CORBA::is_nil (root_poa.in ()))
54 ACE_ERROR_RETURN ((LM_ERROR,
55 " (%P|%t) Panic: nil RootPOA\n"),
56 1);
58 PortableServer::POAManager_var poa_manager =
59 root_poa->the_POAManager ();
61 if (parse_args (argc, argv) != 0)
62 return 1;
64 CORBA::Object_var tmp =
65 orb->string_to_object(ior);
67 Test::Oneway_Buffering_Admin_var admin =
68 Test::Oneway_Buffering_Admin::_narrow(tmp.in ());
70 if (CORBA::is_nil (admin.in ()))
72 ACE_ERROR_RETURN ((LM_DEBUG,
73 "Nil Oneway_Buffering_Admin reference <%s>\n",
74 ior),
75 1);
78 Oneway_Buffering *oneway_buffering_impl;
79 ACE_NEW_RETURN (oneway_buffering_impl,
80 Oneway_Buffering (orb.in (),
81 admin.in ()),
82 1);
83 PortableServer::ServantBase_var owner_transfer(oneway_buffering_impl);
85 PortableServer::ObjectId_var id =
86 root_poa->activate_object (oneway_buffering_impl);
88 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
90 Test::Oneway_Buffering_var oneway_buffering =
91 Test::Oneway_Buffering::_narrow (object.in ());
93 CORBA::String_var ior =
94 orb->object_to_string (oneway_buffering.in ());
96 // If the ior_output_file exists, output the ior to it
97 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
98 if (output_file == 0)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "Cannot open output file for writing IOR: %s",
101 ior_output_file),
103 ACE_OS::fprintf (output_file, "%s", ior.in ());
104 ACE_OS::fclose (output_file);
106 poa_manager->activate ();
108 orb->run ();
110 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
112 root_poa->destroy (true, true);
114 orb->destroy ();
116 catch (const CORBA::Exception& ex)
118 ex._tao_print_exception ("Exception caught in server:");
119 return 1;
122 return 0;