2 //=============================================================================
6 * This class implements a simple server for the
7 * Nested Upcalls - MT_Client test.
9 * @author Michael Kircher
11 //=============================================================================
15 #include "tao/debug.h"
16 #include "ace/OS_NS_stdio.h"
18 #include "ace/Event_Handler.h"
19 #include "ace/Sig_Handler.h"
21 class TestShutdown
: public ACE_Event_Handler
24 TestShutdown (CORBA::ORB_ptr orb
)
25 : orb_(CORBA::ORB::_duplicate (orb
))
27 #if !defined(ACE_LACKS_UNIX_SIGNALS)
28 this->shutdown_
.register_handler (SIGTERM
, this);
29 this->shutdown_
.register_handler (SIGINT
, this);
30 #elif defined(ACE_WIN32)
31 this->shutdown_
.register_handler (SIGINT
, this);
37 #if !defined(ACE_LACKS_UNIX_SIGNALS)
38 this->shutdown_
.remove_handler (SIGTERM
);
39 this->shutdown_
.remove_handler (SIGINT
);
40 #elif defined(ACE_WIN32)
41 this->shutdown_
.remove_handler (SIGINT
);
45 virtual int handle_signal (int, siginfo_t
*, ucontext_t
*)
47 this->orb_
->shutdown ();
54 ACE_Sig_Handler shutdown_
;
57 MT_Object_Server::MT_Object_Server (void)
58 : ior_output_file_ (0)
63 MT_Object_Server::parse_args (void)
65 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("do:m"));
68 while ((c
= get_opts ()) != -1)
71 case 'd': // debug flag.
74 case 'o': // output the IOR to a file.
75 this->ior_output_file_
= ACE_OS::fopen (get_opts
.opt_arg (), "w");
76 if (this->ior_output_file_
== 0)
77 ACE_ERROR_RETURN ((LM_ERROR
,
78 "Unable to open %s for writing: %p\n",
79 get_opts
.opt_arg ()), -1);
83 ACE_ERROR_RETURN ((LM_ERROR
,
86 " [-o] <ior_output_file>"
92 // Indicates successful parsing of command line.
97 MT_Object_Server::init (int argc
, ACE_TCHAR
** argv
)
99 // Call the init of TAO_ORB_Manager to create a child POA
100 // under the root POA.
101 this->orb_manager_
.init_child_poa (argc
,
109 // ~~ check for the return value here
111 CORBA::String_var str
;
112 str
= this->orb_manager_
.activate_under_child_poa ("MT_Object",
113 &this->mT_Object_i_
);
116 ACE_DEBUG ((LM_DEBUG
,
117 "The IOR is: <%s>\n",
121 if (this->ior_output_file_
)
123 ACE_OS::fprintf (this->ior_output_file_
,
126 ACE_OS::fclose (this->ior_output_file_
);
135 MT_Object_Server::run (void)
137 CORBA::ORB_var orb
= this->orb_manager_
.orb ();
138 TestShutdown
killer (orb
.in ());
140 int result
= this->orb_manager_
.run ();
143 ACE_ERROR_RETURN ((LM_ERROR
,
144 "NestedUpCalls_Server::run"),
149 MT_Object_Server::~MT_Object_Server (void)
154 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
156 ACE_DEBUG ((LM_DEBUG
,
157 "\n \t NestedUpCalls.Triangle_Test: Object A Server \n\n"));
161 MT_Object_Server MT_Object_Server
;
163 int r
= MT_Object_Server
.init (argc
,argv
);
169 MT_Object_Server
.run ();
172 catch (const CORBA::SystemException
& sysex
)
174 sysex
._tao_print_exception ("System Exception");
177 catch (const CORBA::UserException
& userex
)
179 userex
._tao_print_exception ("User Exception");