Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_1670_Regression / server.cpp
blobab5f3c2036af0b6b535268affe43af740d14f94c
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);
30 protected:
31 CORBA::ORB_var orb_;
35 /***************************/
36 /*** Servant Definition ***/
38 Simple_C::Simple_C (CORBA::ORB_ptr orb)
39 : orb_ (CORBA::ORB::_duplicate (orb))
43 void
44 Simple_C::op1(Foo::Bar::AMH_AResponseHandler_ptr _tao_rh)
46 _tao_rh->op1(1);
49 void
50 Simple_C::op2(Foo::Bar::AMH_AResponseHandler_ptr _tao_rh)
52 _tao_rh->op2(2);
55 void
56 Simple_C::op3(Foo::Bar::AMH_BResponseHandler_ptr _tao_rh)
58 _tao_rh->op3(3);
61 void
62 Simple_C::op4(Baz::AMH_CResponseHandler_ptr _tao_rh)
64 _tao_rh->op4(4);
67 void
68 Simple_C::shutdown (Baz::AMH_CResponseHandler_ptr)
70 this->orb_->shutdown ();
73 // ****************************************************************
75 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
77 int
78 parse_args (int argc, ACE_TCHAR *argv[])
80 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
81 int c;
83 while ((c = get_opts ()) != -1)
84 switch (c)
86 case 'o':
87 ior_output_file = get_opts.opt_arg ();
88 break;
90 case '?':
91 default:
92 ACE_ERROR_RETURN ((LM_ERROR,
93 "usage: %s "
94 "-o <iorfile>"
95 "\n",
96 argv [0]),
97 -1);
99 // Indicates successful parsing of the command line
100 return 0;
104 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
108 CORBA::ORB_var orb =
109 CORBA::ORB_init (argc, argv);
111 CORBA::Object_var poa_object =
112 orb->resolve_initial_references("RootPOA");
114 PortableServer::POA_var root_poa =
115 PortableServer::POA::_narrow (poa_object.in ());
117 if (CORBA::is_nil (root_poa.in ()))
118 ACE_ERROR_RETURN ((LM_ERROR,
119 " (%P|%t) Panic: nil RootPOA\n"),
122 PortableServer::POAManager_var poa_manager =
123 root_poa->the_POAManager ();
125 if (parse_args (argc, argv) != 0)
126 return 1;
128 PortableServer::Servant_var<Simple_C> simple_c_impl(
129 new Simple_C(orb.in()));
131 PortableServer::ObjectId_var id =
132 root_poa->activate_object (simple_c_impl.in ());
134 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
136 Baz::C_var simple_c =
137 Baz::C::_narrow (object.in ());
139 CORBA::String_var ior =
140 orb->object_to_string (simple_c.in ());
142 // Output the IOR to the <ior_output_file>
143 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
144 if (output_file == 0)
145 ACE_ERROR_RETURN ((LM_ERROR,
146 "Cannot open output file for writing IOR: %s",
147 ior_output_file),
149 ACE_OS::fprintf (output_file, "%s", ior.in ());
150 ACE_OS::fclose (output_file);
152 poa_manager->activate ();
154 orb->run ();
156 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
158 root_poa->destroy (1, 1);
160 orb->destroy ();
162 catch (const CORBA::Exception& ex)
164 ex._tao_print_exception ("Exception caught:");
165 return 1;
168 return 0;