Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / NestedUpcall / MT_Client_Test / server.cpp
blob8c4ce3fcc1773a57058223895a36f5f21223fd77
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * This class implements a simple server for the
7 * Nested Upcalls - MT_Client test.
9 * @author Michael Kircher
11 //=============================================================================
14 #include "server.h"
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
23 public:
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);
32 #endif
35 ~TestShutdown (void)
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);
42 #endif
45 virtual int handle_signal (int, siginfo_t*, ucontext_t*)
47 this->orb_->shutdown ();
48 return 0;
51 private:
52 CORBA::ORB_var orb_;
54 ACE_Sig_Handler shutdown_;
57 MT_Object_Server::MT_Object_Server (void)
58 : ior_output_file_ (0)
62 int
63 MT_Object_Server::parse_args (void)
65 ACE_Get_Opt get_opts (argc_, argv_, ACE_TEXT("do:m"));
66 int c;
68 while ((c = get_opts ()) != -1)
69 switch (c)
71 case 'd': // debug flag.
72 TAO_debug_level++;
73 break;
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);
80 break;
81 case '?':
82 default:
83 ACE_ERROR_RETURN ((LM_ERROR,
84 "usage: %s"
85 " [-d]"
86 " [-o] <ior_output_file>"
87 "\n",
88 argv_ [0]),
89 1);
92 // Indicates successful parsing of command line.
93 return 0;
96 int
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,
102 argv,
103 "child_poa");
105 this->argc_ = argc;
106 this->argv_ = argv;
108 this->parse_args ();
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_);
115 #if 0
116 ACE_DEBUG ((LM_DEBUG,
117 "The IOR is: <%s>\n",
118 str.in ()));
119 #endif /*if 0*/
121 if (this->ior_output_file_)
123 ACE_OS::fprintf (this->ior_output_file_,
124 "%s",
125 str.in ());
126 ACE_OS::fclose (this->ior_output_file_);
130 return 0;
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 ();
142 if (result == -1)
143 ACE_ERROR_RETURN ((LM_ERROR,
144 "NestedUpCalls_Server::run"),
145 -1);
146 return 0;
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);
165 if (r == -1)
166 return 1;
167 else
169 MT_Object_Server.run ();
172 catch (const CORBA::SystemException& sysex)
174 sysex._tao_print_exception ("System Exception");
175 return -1;
177 catch (const CORBA::UserException& userex)
179 userex._tao_print_exception ("User Exception");
180 return -1;
182 return 0;