Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Bug_3647_Regression / backend_server.cpp
blob85ed4b49a45901520967708dbfb5286f9ad32a3f
1 // -*- C++ -*-
2 #include "Backend_Impl.h"
3 #include "tao/Strategies/advanced_resource.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT ("backend.ior");
8 bool verbose = false;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("vo:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'o':
20 ior_output_file = get_opts.opt_arg ();
21 break;
23 case 'v':
24 verbose = true;
25 break;
27 case '?':
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 ACE_TEXT("usage: %s ")
31 ACE_TEXT("-o <iorfile>")
32 ACE_TEXT("\n"),
33 argv [0]),
34 -1);
36 // Indicates successful parsing of the command line
37 return 0;
40 int
41 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
43 try
45 CORBA::ORB_var orb =
46 CORBA::ORB_init (argc, argv);
48 CORBA::Object_var poa_object =
49 orb->resolve_initial_references("RootPOA");
51 PortableServer::POA_var root_poa =
52 PortableServer::POA::_narrow (poa_object.in ());
54 if (CORBA::is_nil (root_poa.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR,
57 "backend_server(%P|%t) - panic: nil RootPOA\n"),
58 1);
61 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
63 if (parse_args (argc, argv) != 0)
64 return 1;
66 using namespace Bug_3647_Regression;
67 PortableServer::ServantBase_var impl(
68 new Backend_Impl(orb.in(), verbose));
70 PortableServer::ObjectId_var id =
71 root_poa->activate_object (impl.in());
73 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
75 Bug_3647_Regression::Backend_var backend =
76 Bug_3647_Regression::Backend::_narrow (object.in ());
78 CORBA::String_var ior = orb->object_to_string (backend.in ());
80 // Output the IOR to the <ior_output_file>
81 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
82 if (output_file == 0)
84 ACE_ERROR_RETURN ((LM_ERROR,
85 "backend_server(%P|%) - cannot open output file "
86 "for writing IOR: %s\n",
87 ior_output_file),
88 1);
90 ACE_OS::fprintf (output_file, "%s", ior.in ());
91 ACE_OS::fclose (output_file);
93 poa_manager->activate ();
95 orb->run ();
97 ACE_DEBUG ((LM_DEBUG, "backend_server(%P|%t) - event loop finished\n"));
99 root_poa->destroy (true, true);
101 orb->destroy ();
103 catch (const CORBA::Exception& ex)
105 ACE_DEBUG ((LM_DEBUG,
106 "backend_server"));
107 ex._tao_print_exception ("Exception caught:");
108 return 1;
111 return 0;