Merge remote-tracking branch 'upstream/master'
[ACE_TAO.git] / TAO / tests / Smart_Proxies / Benchmark / server.cpp
blobc6c407c2e998e754d4a73d240d856e2ffb11df02
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 (void);
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 (void);
32 private:
33 CORBA::ORB_var orb_;
37 Test_i::Test_i (CORBA::ORB_ptr orb)
38 : orb_ (CORBA::ORB::_duplicate (orb))
42 CORBA::Short
43 Test_i::box_prices (void)
45 return 125;
48 CORBA::Long
49 Test_i::tickets (CORBA::Short number)
51 return 125 * number;
54 void
55 Test_i::shutdown (void)
57 this->orb_->shutdown (false);
60 static const ACE_TCHAR *ior_output_file = 0;
62 int
63 parse_args (int argc, ACE_TCHAR *argv[])
65 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
66 int c;
68 while ((c = get_opts ()) != -1)
69 switch (c)
71 case 'o':
72 ior_output_file = get_opts.opt_arg ();
73 break;
74 case '?':
75 default:
76 ACE_ERROR_RETURN ((LM_ERROR,
77 "usage: %s "
78 "-o <iorfile>"
79 "\n",
80 argv [0]),
81 -1);
83 // Indicates successful parsing of the command line
84 return 0;
87 int
88 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
91 try
93 CORBA::ORB_var orb = CORBA::ORB_init (argc,
94 argv);
95 if (parse_args (argc, argv) != 0)
96 return 1;
98 Test_i servant (orb.in ());
99 // Obtain RootPOA.
100 CORBA::Object_var object =
101 orb->resolve_initial_references ("RootPOA");
103 PortableServer::POA_var root_poa =
104 PortableServer::POA::_narrow (object.in ());
107 // Get the POAManager of the RootPOA.
108 PortableServer::POAManager_var poa_manager =
109 root_poa->the_POAManager ();
111 PortableServer::ObjectId_var id =
112 root_poa->activate_object (&servant);
114 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
116 Test_var Test_object =
117 Test::_narrow (object_act.in ());
119 CORBA::String_var ior =
120 orb->object_to_string (Test_object.in ());
122 // If the ior_output_file exists, output the ior to it
123 if (ior_output_file != 0)
125 FILE *output_file =
126 ACE_OS::fopen (ior_output_file, "w");
128 if (output_file == 0)
129 ACE_ERROR_RETURN ((LM_ERROR,
130 "Cannot open output file for writing IOR: %s",
131 ior_output_file),
134 ACE_OS::fprintf (output_file,
135 "%s",
136 ior.in ());
137 ACE_OS::fclose (output_file);
140 poa_manager->activate ();
142 orb->run ();
144 ACE_DEBUG ((LM_DEBUG,
145 "event loop finished\n"));
147 root_poa->destroy (true, true);
149 orb->destroy ();
151 catch (const CORBA::Exception& ex)
153 ex._tao_print_exception ("Exception in setting up server");
154 ACE_ASSERT (0);
156 return 0;