Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_1361_Regression / server.cpp
blob8540bbe2b588fa0eda411c8eb5975c01152342a1
1 #include "Echo_Caller.h"
2 #include "tao/ORB_Core.h"
3 #include "ace/Get_Opt.h"
4 #include "Server_Thread_Pool.h"
5 #include "ORB_Task.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[]);
12 int
13 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
15 try
17 CORBA::ORB_var orb =
18 CORBA::ORB_init (argc, argv);
20 CORBA::Object_var poa_object =
21 orb->resolve_initial_references("RootPOA");
23 PortableServer::POA_var root_poa =
24 PortableServer::POA::_narrow (poa_object.in ());
26 if (CORBA::is_nil (root_poa.in ()))
27 ACE_ERROR_RETURN ((LM_ERROR,
28 " (%P|%t) Panic: nil RootPOA\n"),
29 1);
31 PortableServer::POAManager_var poa_manager =
32 root_poa->the_POAManager ();
34 if (parse_args (argc, argv) != 0)
35 return 1;
37 ACE_Thread_Manager mymanager;
38 Thread_Pool callback_pool (orb.in (), &mymanager, 10);
40 PortableServer::ServantBase_var impl;
42 Echo_Caller * tmp = 0;
43 // ACE_NEW_RETURN is the worst possible way to handle
44 // exceptions (think: what if the constructor allocates memory
45 // and fails?), but I'm not in the mood to fight for a more
46 // reasonable way to handle allocation errors in ACE.
47 ACE_NEW_RETURN (tmp,
48 Echo_Caller(&callback_pool),
49 1);
50 impl = tmp;
53 PortableServer::ObjectId_var id =
54 root_poa->activate_object (impl.in ());
56 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
58 Test::Echo_Caller_var server =
59 Test::Echo_Caller::_narrow (object_act.in ());
61 CORBA::String_var ior =
62 orb->object_to_string (server.in ());
64 // If the ior_output_file exists, output the ior to it
65 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
66 if (output_file == 0)
67 ACE_ERROR_RETURN ((LM_ERROR,
68 "Cannot open output file for writing IOR: %s",
69 ior_output_file),
70 1);
71 ACE_OS::fprintf (output_file, "%s", ior.in ());
72 ACE_OS::fclose (output_file);
74 poa_manager->activate ();
76 ORB_Task worker (orb.in ());
77 worker.activate (THR_NEW_LWP | THR_JOINABLE,
78 4);
80 orb->run();
82 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
84 mymanager.wait ();
85 worker.wait ();
87 root_poa->destroy (true, true);
89 orb->destroy ();
91 catch (const CORBA::Exception& ex)
93 ex._tao_print_exception ("Exception caught:");
94 return 1;
97 return 0;
101 parse_args (int argc, ACE_TCHAR *argv[])
103 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
104 int c;
106 while ((c = get_opts ()) != -1)
107 switch (c)
109 case 'o':
110 ior_output_file = get_opts.opt_arg ();
111 break;
113 case '?':
114 default:
115 ACE_ERROR_RETURN ((LM_ERROR,
116 "usage: %s "
117 "-o <iorfile> "
118 "\n",
119 argv [0]),
120 -1);
122 // Indicates successful parsing of the command line
123 return 0;