Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / LongUpcalls / blocking_server.cpp
blob13f24970e2981c4a4a0fea69410b755f0c30ef8f
1 #include "ace/Get_Opt.h"
2 #include "Manager.h"
4 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
6 int
7 parse_args (int argc, ACE_TCHAR *argv[])
9 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
10 int c;
12 while ((c = get_opts ()) != -1)
13 switch (c)
15 case 'o':
16 ior_output_file = get_opts.opt_arg ();
17 break;
18 case '?':
19 default:
20 ACE_ERROR_RETURN ((LM_ERROR,
21 "usage: %s "
22 "-o <iorfile>"
23 "\n",
24 argv [0]),
25 -1);
27 // Indicates successful parsing of the command line
28 return 0;
31 int
32 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
34 try
36 CORBA::ORB_var orb =
37 CORBA::ORB_init (argc, argv);
39 CORBA::Object_var poa_object =
40 orb->resolve_initial_references("RootPOA");
42 if (CORBA::is_nil (poa_object.in ()))
43 ACE_ERROR_RETURN ((LM_ERROR,
44 " (%P|%t) Unable to initialize the POA.\n"),
45 1);
47 PortableServer::POA_var root_poa =
48 PortableServer::POA::_narrow (poa_object.in ());
50 PortableServer::POAManager_var poa_manager =
51 root_poa->the_POAManager ();
53 if (parse_args (argc, argv) != 0)
54 return 1;
56 Manager manager_impl (orb.in ());
58 PortableServer::ObjectId_var id =
59 root_poa->activate_object (&manager_impl);
61 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
63 Test::Manager_var manager =
64 Test::Manager::_narrow (object.in ());
66 CORBA::String_var ior =
67 orb->object_to_string (manager.in ());
69 // If the ior_output_file exists, output the ior to it
70 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
71 if (output_file == 0)
72 ACE_ERROR_RETURN ((LM_ERROR,
73 "Cannot open output file for writing IOR: %s",
74 ior_output_file),
75 1);
76 ACE_OS::fprintf (output_file, "%s", ior.in ());
77 ACE_OS::fclose (output_file);
79 poa_manager->activate ();
81 orb->run ();
83 // ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
85 root_poa->destroy (true, true);
87 orb->destroy ();
89 catch (const CORBA::Exception& ex)
91 ex._tao_print_exception ("Exception caught:");
92 return 1;
95 return 0;