Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / RTCORBA / Private_Connection / server.cpp
blob63d5ec79ab1da21e1e4768e521cb083e5e7a504f
1 #include "testS.h"
2 #include "tao/RTCORBA/RTCORBA.h"
3 #include "tao/RTPortableServer/RTPortableServer.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 class Test_i : public POA_Test
9 // = TITLE
10 // An implementation for the Test interface in test.idl
12 public:
13 Test_i (CORBA::ORB_ptr orb);
14 // ctor
16 // = The Test methods.
17 void test_method ();
19 //FUZZ: disable check_for_lack_ACE_OS
20 void shutdown ();
21 //FUZZ: enable check_for_lack_ACE_OS
23 private:
24 CORBA::ORB_var orb_;
25 // The ORB
28 Test_i::Test_i (CORBA::ORB_ptr orb)
29 : orb_ (CORBA::ORB::_duplicate (orb))
33 void
34 Test_i::test_method (/* */)
36 ACE_DEBUG ((LM_DEBUG,
37 "Server: test_method invoked.\n"));
40 void
41 Test_i::shutdown ()
43 this->orb_->shutdown (false);
46 //*************************************************************************
48 const ACE_TCHAR *ior_output_file1 = ACE_TEXT("test1.ior");
49 const ACE_TCHAR *ior_output_file2 = ACE_TEXT("test2.ior");
51 // Parse command-line arguments.
52 int
53 parse_args (int argc, ACE_TCHAR *argv[])
55 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:p:"));
56 int c;
58 while ((c = get_opts ()) != -1)
59 switch (c)
61 case 'o':
62 ior_output_file1 = get_opts.opt_arg ();
63 break;
65 case 'p':
66 ior_output_file2 = get_opts.opt_arg ();
67 break;
69 case '?':
70 default:
71 ACE_ERROR_RETURN ((LM_ERROR,
72 "usage: %s "
73 "-o <iorfile1>"
74 "-p <iorfile2>"
75 "\n",
76 argv [0]),
77 -1);
80 return 0;
83 int
84 check_for_nil (CORBA::Object_ptr obj, const char *msg)
86 if (CORBA::is_nil (obj))
87 ACE_ERROR_RETURN ((LM_ERROR,
88 "ERROR: Object reference <%C> is nil\n",
89 msg),
90 -1);
91 else
92 return 0;
95 int
96 create_object (PortableServer::POA_ptr poa,
97 CORBA::ORB_ptr orb,
98 Test_i *server_impl,
99 const ACE_TCHAR *filename)
101 // Register with poa.
102 PortableServer::ObjectId_var id =
103 poa->activate_object (server_impl);
106 CORBA::Object_var server =
107 poa->id_to_reference (id.in ());
109 // Print out the IOR.
110 CORBA::String_var ior =
111 orb->object_to_string (server.in ());
113 ACE_DEBUG ((LM_DEBUG, "<%C>\n\n", ior.in ()));
115 // Print ior to the file.
116 if (filename != 0)
118 FILE *output_file= ACE_OS::fopen (filename, "w");
119 if (output_file == 0)
120 ACE_ERROR_RETURN ((LM_ERROR,
121 "Cannot open output file for writing IOR: %s",
122 filename),
123 -1);
124 ACE_OS::fprintf (output_file, "%s", ior.in ());
125 ACE_OS::fclose (output_file);
128 return 0;
132 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
136 // ORB.
137 CORBA::ORB_var orb =
138 CORBA::ORB_init (argc, argv);
140 // Parse arguments.
141 if (parse_args (argc, argv) != 0)
142 return -1;
144 // RootPOA.
145 CORBA::Object_var object =
146 orb->resolve_initial_references("RootPOA");
147 PortableServer::POA_var root_poa =
148 PortableServer::POA::_narrow (object.in ());
149 if (check_for_nil (root_poa.in (), "RootPOA") == -1)
150 return -1;
152 // POAManager.
153 PortableServer::POAManager_var poa_manager =
154 root_poa->the_POAManager ();
156 // Servants.
157 Test_i server_impl1 (orb.in ());
158 Test_i server_impl2 (orb.in ());
160 // Create Objects.
161 int result;
162 result = create_object (root_poa.in (),
163 orb.in (),
164 &server_impl1,
165 ior_output_file1);
166 if (result == -1)
167 return -1;
169 result = create_object (root_poa.in (),
170 orb.in (),
171 &server_impl2,
172 ior_output_file2);
173 if (result == -1)
174 return -1;
176 // Run ORB Event loop.
177 poa_manager->activate ();
179 orb->run ();
181 ACE_DEBUG ((LM_DEBUG, "Server ORB event loop finished\n"));
183 catch (const CORBA::Exception& ex)
185 ex._tao_print_exception (
186 "Unexpected exception caught in Private_Connection test server:");
187 return -1;
190 return 0;