Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_1395_Regression / server.cpp
blob77444fc3533d153ec8a6d43476ccc67e8038dd7b
1 #include "ace/Get_Opt.h"
2 #include "Test_i.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "orbsvcs/Shutdown_Utilities.h"
6 const ACE_TCHAR *ior_output_file = 0;
8 class Service_Shutdown_Functor : public Shutdown_Functor
10 public:
11 Service_Shutdown_Functor (CORBA::ORB_ptr orb)
12 : orb_(CORBA::ORB::_duplicate (orb))
16 void operator() (int which_signal)
18 ACE_DEBUG ((LM_DEBUG,
19 "shutting down on signal %d\n", which_signal));
20 (void) this->orb_->shutdown ();
23 private:
24 CORBA::ORB_var orb_;
27 int
28 parse_args (int argc, ACE_TCHAR *argv[])
30 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
31 int c;
33 while ((c = get_opts ()) != -1)
34 switch (c)
36 case 'o':
37 ior_output_file = get_opts.opt_arg ();
38 break;
39 case '?':
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "SERVER (%P): usage: %s "
43 "-o <iorfile>"
44 "\n",
45 argv [0]),
46 -1);
48 // Indicates successful parsing of the command line
49 return 0;
52 int
53 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
55 try
57 CORBA::ORB_var orb =
58 CORBA::ORB_init (argc, argv);
60 Service_Shutdown_Functor killer (orb.in ());
61 Service_Shutdown kill_contractor (killer);
63 CORBA::Object_var poa_object =
64 orb->resolve_initial_references ("RootPOA");
66 if (CORBA::is_nil (poa_object.in ()))
67 ACE_ERROR_RETURN ((LM_ERROR,
68 "SERVER (%P): Unable to initialize the POA.\n"),
69 1);
71 PortableServer::POA_var root_poa =
72 PortableServer::POA::_narrow (poa_object.in ());
74 PortableServer::POAManager_var poa_manager =
75 root_poa->the_POAManager ();
77 if (parse_args (argc, argv) != 0)
78 return 1;
80 Test_i server_impl (orb.in ());
82 PortableServer::ObjectId_var tmp =
83 root_poa->activate_object (&server_impl);
86 CORBA::Object_var server = server_impl._this();
88 CORBA::String_var ior =
89 orb->object_to_string (server.in ());
91 // If the ior_output_file exists, output the ior to it
92 if (ior_output_file != 0)
94 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
95 if (output_file == 0)
96 ACE_ERROR_RETURN ((LM_ERROR,
97 "SERVER (%P): Cannot open output file "
98 "for writing IOR: %s",
99 ior_output_file),
101 ACE_OS::fprintf (output_file, "%s", ior.in ());
102 ACE_OS::fclose (output_file);
104 ACE_DEBUG ((LM_DEBUG,
105 "SERVER (%P): Activated as file://%s\n",
106 ior_output_file));
108 else
110 ACE_DEBUG ((LM_DEBUG,
111 "SERVER (%P): Activated as <%s>\n",
112 ior.in ()));
115 poa_manager->activate();
117 orb->run ();
119 root_poa->destroy (true, true);
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("SERVER (%P): Caught exception:");
124 return 1;
127 return 0;