Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / InterfaceRepo / Application_Test / server.cpp
blobdd9704490df04f2f5ccce01916ee45c8e6901b13
1 // -*- C++ -*-
2 #include "test_i.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "orbsvcs/Shutdown_Utilities.h"
5 #include "ace/Get_Opt.h"
8 static const ACE_TCHAR *ior_output_file = ACE_TEXT("iorfile");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
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 '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-o <ior> "
28 "\n",
29 argv [0]),
30 -1);
32 // Indicates successful parsing of the command line
33 return 0;
36 class Service_Shutdown_Functor : public Shutdown_Functor
38 public:
39 Service_Shutdown_Functor (CORBA::ORB_ptr orb)
40 : orb_(CORBA::ORB::_duplicate (orb))
44 void operator() (int which_signal)
46 ACE_DEBUG ((LM_DEBUG,
47 "shutting down on signal %d\n", which_signal));
48 (void) this->orb_->shutdown ();
51 private:
52 CORBA::ORB_var orb_;
55 static int
56 write_ior_to_file (const char *ior)
58 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
60 if (output_file == 0)
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "Cannot open output files for writing IOR: %s\n",
64 ior_output_file),
65 -1);
68 int result = ACE_OS::fprintf (output_file,
69 "%s",
70 ior);
71 if (result < 0)
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "ACE_OS::fprintf failed while writing %s to %s\n",
75 ior,
76 ior_output_file),
77 -1);
80 ACE_OS::fclose (output_file);
82 return 0;
85 int
86 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
88 try
90 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
92 if (parse_args (argc, argv) != 0)
93 return 1;
95 Service_Shutdown_Functor killer (orb.in ());
96 Service_Shutdown kill_contractor (killer);
98 CORBA::Object_var poa_object =
99 orb->resolve_initial_references ("RootPOA");
101 PortableServer::POA_var root_poa =
102 PortableServer::POA::_narrow (poa_object.in ());
104 PortableServer::POAManager_var poa_manager =
105 root_poa->the_POAManager ();
107 poa_manager->activate ();
109 inventory_i servant_impl;
111 warehouse::inventory_var servant =
112 servant_impl._this ();
114 CORBA::String_var ior =
115 orb->object_to_string (servant.in ());
117 int write_result = write_ior_to_file (ior.in ());
119 if (write_result != 0)
121 ACE_ERROR_RETURN ((LM_ERROR,
122 "%p\n",
123 "write_ior_to_file"),
124 -1);
127 orb->run ();
129 root_poa->destroy (true, true);
131 orb->destroy ();
133 catch (const CORBA::Exception& ex)
135 ex._tao_print_exception ("server exception:");
136 return 1;
139 return 0;