Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_1568_Regression / server.cpp
blob9a4a5a12258da13703a20702054ba5948b4c1f92
1 /**
2 * @file server.cpp
4 * @author Carlos O'Ryan <coryan@atdesk.com>
5 */
6 #include "TestS.h"
8 #include "tao/corba.h"
9 #include "tao/ORB_Core.h"
10 #include "ace/Get_Opt.h"
11 #include "ace/Reactor.h"
13 /**
14 * @class Simple_C
16 * @brief A simple implementation of the 'C' object.
18 class Simple_C
19 : public virtual POA_Baz::AMH_C
21 public:
22 Simple_C (CORBA::ORB_ptr orb);
24 void op1 (Foo::Bar::AMH_AResponseHandler_ptr _tao_rh);
25 void op2 (Foo::Bar::AMH_AResponseHandler_ptr _tao_rh);
26 void op3 (Foo::Bar::AMH_BResponseHandler_ptr _tao_rh);
27 void op4 (Baz::AMH_CResponseHandler_ptr _tao_rh);
28 void shutdown (Baz::AMH_CResponseHandler_ptr _tao_rh);
29 protected:
30 CORBA::ORB_var orb_;
34 /***************************/
35 /*** Servant Definition ***/
37 Simple_C::Simple_C (CORBA::ORB_ptr orb)
38 : orb_ (CORBA::ORB::_duplicate (orb))
42 void
43 Simple_C::op1(Foo::Bar::AMH_AResponseHandler_ptr _tao_rh)
45 _tao_rh->op1();
48 void
49 Simple_C::op2(Foo::Bar::AMH_AResponseHandler_ptr _tao_rh)
51 _tao_rh->op2();
54 void
55 Simple_C::op3(Foo::Bar::AMH_BResponseHandler_ptr _tao_rh)
57 _tao_rh->op3();
60 void
61 Simple_C::op4(Baz::AMH_CResponseHandler_ptr _tao_rh)
63 _tao_rh->op4();
66 void
67 Simple_C::shutdown (Baz::AMH_CResponseHandler_ptr)
69 this->orb_->shutdown (0);
72 // ****************************************************************
74 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
76 int
77 parse_args (int argc, ACE_TCHAR *argv[])
79 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
80 int c;
82 while ((c = get_opts ()) != -1)
83 switch (c)
85 case 'o':
86 ior_output_file = get_opts.opt_arg ();
87 break;
89 case '?':
90 default:
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "usage: %s "
93 "-o <iorfile>"
94 "\n",
95 argv [0]),
96 -1);
98 // Indicates successful parsing of the command line
99 return 0;
103 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
107 CORBA::ORB_var orb =
108 CORBA::ORB_init (argc, argv);
110 CORBA::Object_var poa_object =
111 orb->resolve_initial_references("RootPOA");
113 PortableServer::POA_var root_poa =
114 PortableServer::POA::_narrow (poa_object.in ());
116 if (CORBA::is_nil (root_poa.in ()))
117 ACE_ERROR_RETURN ((LM_ERROR,
118 " (%P|%t) Panic: nil RootPOA\n"),
121 PortableServer::POAManager_var poa_manager =
122 root_poa->the_POAManager ();
124 if (parse_args (argc, argv) != 0)
125 return 1;
127 PortableServer::Servant_var<Simple_C> simple_c_impl(
128 new Simple_C(orb.in()));
130 PortableServer::ObjectId_var id =
131 root_poa->activate_object (simple_c_impl.in ());
133 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
135 Baz::C_var simple_c =
136 Baz::C::_narrow (object.in ());
138 CORBA::String_var ior =
139 orb->object_to_string (simple_c.in ());
141 // Output the IOR to the <ior_output_file>
142 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
143 if (output_file == 0)
144 ACE_ERROR_RETURN ((LM_ERROR,
145 "Cannot open output file for writing IOR: %s",
146 ior_output_file),
148 ACE_OS::fprintf (output_file, "%s", ior.in ());
149 ACE_OS::fclose (output_file);
151 poa_manager->activate ();
153 orb->run ();
155 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
157 root_poa->destroy (1, 1);
159 orb->destroy ();
161 catch (const CORBA::Exception& ex)
163 ex._tao_print_exception ("Exception caught:");
164 return 1;
167 return 0;