Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Smart_Proxies / Benchmark / server.cpp
blob04f63a733b802bf43079d9bfed915d237cd3b548
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * This is the server program that tests TAO's Smart Proxy extension.
8 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
9 */
10 //=============================================================================
13 #include "testS.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/OS_NS_string.h"
17 // The servant
19 class Test_i : public POA_Test
21 public:
22 Test_i (CORBA::ORB_ptr orb);
24 CORBA::Short box_prices ();
26 CORBA::Long tickets (CORBA::Short number);
28 //FUZZ: disable check_for_lack_ACE_OS
29 ///FUZZ: enable check_for_lack_ACE_OS
30 void shutdown ();
32 private:
33 CORBA::ORB_var orb_;
36 Test_i::Test_i (CORBA::ORB_ptr orb)
37 : orb_ (CORBA::ORB::_duplicate (orb))
41 CORBA::Short
42 Test_i::box_prices ()
44 return 125;
47 CORBA::Long
48 Test_i::tickets (CORBA::Short number)
50 return 125 * number;
53 void
54 Test_i::shutdown ()
56 this->orb_->shutdown (false);
59 static const ACE_TCHAR *ior_output_file = 0;
61 int
62 parse_args (int argc, ACE_TCHAR *argv[])
64 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
65 int c;
67 while ((c = get_opts ()) != -1)
68 switch (c)
70 case 'o':
71 ior_output_file = get_opts.opt_arg ();
72 break;
73 case '?':
74 default:
75 ACE_ERROR_RETURN ((LM_ERROR,
76 "usage: %s "
77 "-o <iorfile>"
78 "\n",
79 argv [0]),
80 -1);
82 // Indicates successful parsing of the command line
83 return 0;
86 int
87 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
89 try
91 CORBA::ORB_var orb = CORBA::ORB_init (argc,
92 argv);
93 if (parse_args (argc, argv) != 0)
94 return 1;
96 Test_i servant (orb.in ());
97 // Obtain RootPOA.
98 CORBA::Object_var object =
99 orb->resolve_initial_references ("RootPOA");
101 PortableServer::POA_var root_poa =
102 PortableServer::POA::_narrow (object.in ());
105 // Get the POAManager of the RootPOA.
106 PortableServer::POAManager_var poa_manager =
107 root_poa->the_POAManager ();
109 PortableServer::ObjectId_var id =
110 root_poa->activate_object (&servant);
112 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
114 Test_var Test_object =
115 Test::_narrow (object_act.in ());
117 CORBA::String_var ior =
118 orb->object_to_string (Test_object.in ());
120 // If the ior_output_file exists, output the ior to it
121 if (ior_output_file != 0)
123 FILE *output_file =
124 ACE_OS::fopen (ior_output_file, "w");
126 if (output_file == 0)
127 ACE_ERROR_RETURN ((LM_ERROR,
128 "Cannot open output file for writing IOR: %s",
129 ior_output_file),
132 ACE_OS::fprintf (output_file,
133 "%s",
134 ior.in ());
135 ACE_OS::fclose (output_file);
138 poa_manager->activate ();
140 orb->run ();
142 ACE_DEBUG ((LM_DEBUG,
143 "event loop finished\n"));
145 root_poa->destroy (true, true);
147 orb->destroy ();
149 catch (const CORBA::Exception& ex)
151 ex._tao_print_exception ("Exception in setting up server");
152 ACE_ASSERT (0);
154 return 0;