Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Smart_Proxies / server.cpp
blob61dff5a477da9569818224597c64159085e1de8a
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 method (CORBA::Short boo);
26 //FUZZ: disable check_for_lack_ACE_OS
27 ///FUZZ: enable check_for_lack_ACE_OS
28 void shutdown ();
30 private:
31 CORBA::ORB_var orb_;
34 Test_i::Test_i (CORBA::ORB_ptr orb)
35 : orb_ (CORBA::ORB::_duplicate (orb))
39 CORBA::Short
40 Test_i :: method (CORBA::Short boo)
42 ACE_DEBUG ((LM_DEBUG,
43 ACE_TEXT ("Test_i::method () invoked\n")));
44 if (boo == 5)
45 throw Test::Oops ("Invalid boo\n");
47 return 0;
50 void
51 Test_i::shutdown ()
53 this->orb_->shutdown (false);
56 static const ACE_TCHAR *ior_output_file = 0;
58 int
59 parse_args (int argc, ACE_TCHAR *argv[])
61 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
62 int c;
64 while ((c = get_opts ()) != -1)
65 switch (c)
67 case 'o':
68 ior_output_file = get_opts.opt_arg ();
69 break;
70 case '?':
71 default:
72 ACE_ERROR_RETURN ((LM_ERROR,
73 "usage: %s "
74 "-o <iorfile>"
75 "\n",
76 argv [0]),
77 -1);
79 // Indicates successful parsing of the command line
80 return 0;
83 int
84 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
86 try
88 CORBA::ORB_var orb = CORBA::ORB_init (argc,
89 argv);
91 if (parse_args (argc, argv) != 0)
92 return 1;
94 Test_i servant (orb.in ());
95 // Obtain RootPOA.
96 CORBA::Object_var object =
97 orb->resolve_initial_references ("RootPOA");
99 PortableServer::POA_var root_poa =
100 PortableServer::POA::_narrow (object.in ());
103 // Get the POAManager of the RootPOA.
104 PortableServer::POAManager_var poa_manager =
105 root_poa->the_POAManager ();
107 PortableServer::ObjectId_var id =
108 root_poa->activate_object (&servant);
110 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
112 Test_var Test_object =
113 Test::_narrow (object_act.in ());
115 CORBA::String_var ior =
116 orb->object_to_string (Test_object.in ());
118 // If the ior_output_file exists, output the ior to it
119 if (ior_output_file != 0)
121 FILE *output_file =
122 ACE_OS::fopen (ior_output_file, "w");
124 if (output_file == 0)
125 ACE_ERROR_RETURN ((LM_ERROR,
126 "Cannot open output file for writing IOR: %s",
127 ior_output_file),
130 ACE_OS::fprintf (output_file,
131 "%s",
132 ior.in ());
133 ACE_OS::fclose (output_file);
136 poa_manager->activate ();
138 orb->run ();
140 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
142 root_poa->destroy (true, true);
144 orb->destroy ();
146 catch (const CORBA::Exception& ex)
148 ex._tao_print_exception ("Exception in setting up server");
149 return 1;
151 return 0;