Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / IOR_MCast / server_i.cpp
blob96e0f2cda8a52d47161cce4305d8f8f6e5274336
1 #include "MCastC.h"
2 #include "MCastS.h"
3 #include "server_i.h"
4 #include "MCast_Server_i.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/IORTable/IORTable.h"
8 #include "tao/debug.h"
10 #include "ace/Get_Opt.h"
11 #include "ace/Read_Buffer.h"
13 Server_i::Server_i ()
14 : argc_ (0),
15 argv_ (0),
16 orb_ (),
17 ior_multicast_ (0),
18 service_ior_ (),
19 mcast_address_ ()
23 Server_i::~Server_i ()
25 delete this->ior_multicast_;
28 int
29 Server_i::init (int &argc,
30 ACE_TCHAR **argv)
32 this->argc_ = argc;
33 this->argv_ = argv;
35 try
37 // First initialize the ORB, that will remove some arguments...
38 this->orb_ =
39 CORBA::ORB_init (this->argc_, this->argv_);
41 // Get a reference to the RootPOA.
42 CORBA::Object_var poa_object =
43 this->orb_->resolve_initial_references ("RootPOA");
45 // Narrow down to the correct reference.
46 PortableServer::POA_var poa =
47 PortableServer::POA::_narrow (poa_object.in ());
49 // Set a POA Manager.
50 PortableServer::POAManager_var poa_manager =
51 poa->the_POAManager ();
53 // Activate the POA Manager.
54 poa_manager->activate ();
56 CORBA::String_var ior;
58 // Create the servant
59 MCast_Server_i server_i;
61 // Activate it to obtain the reference
62 MCast::Server_var mcast_server =
63 server_i._this ();
65 CORBA::Object_var table_object =
66 this->orb_->resolve_initial_references ("IORTable");
68 IORTable::Table_var adapter =
69 IORTable::Table::_narrow (table_object.in ());
71 if (CORBA::is_nil (adapter.in ()))
73 ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
75 else
77 ior =
78 this->orb_->object_to_string (mcast_server.in ());
79 adapter->bind ("MCASTServer", ior.in ());
82 // Enable such that the server can listen for multicast requests
83 // at the specified address.
84 if (this->enable_multicast (ior.in ()) != 0)
86 ACE_ERROR ((LM_ERROR,
87 "ERROR: Unable to enable multicast "
88 "on specified address.\n"));
90 throw CORBA::INTERNAL ();
93 // Run the ORB
94 this->orb_->run ();
96 //Destroy the POA, waiting until the destruction terminates.
97 poa->destroy (true, true);
98 this->orb_->destroy ();
100 catch (const CORBA::Exception& ex)
102 ex._tao_print_exception ("client");
103 return 1;
106 return 0;
110 Server_i::enable_multicast (const char *ior)
112 if (this->parse_args (this->argc_, this->argv_) != 0)
113 return -1;
115 // Get reactor instance from TAO.
116 ACE_Reactor *reactor =
117 this->orb_->orb_core ()->reactor ();
119 // Instantiate a handler which will handle client requests for the
120 // bootstrappable service, received on the multicast port.
121 ACE_NEW_RETURN (this->ior_multicast_,
122 TAO_IOR_Multicast (),
123 -1);
125 if (this->ior_multicast_->init (ior,
126 this->mcast_address_.in (),
127 TAO_SERVICEID_MCASTSERVER) == -1)
128 return -1;
130 // Register event handler for the ior multicast.
131 if (reactor->register_handler (this->ior_multicast_,
132 ACE_Event_Handler::READ_MASK) == -1)
134 if (TAO_debug_level > 0)
135 ACE_DEBUG ((LM_DEBUG,
136 "MCast_Server: cannot register Event handler\n"));
137 return -1;
140 return 0;
144 Server_i::parse_args (int argc, ACE_TCHAR *argv[])
146 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("a:"));
147 int c;
149 while ((c = get_opts ()) != -1)
150 switch (c)
152 case 'a':
153 this->mcast_address_ = ACE_TEXT_ALWAYS_CHAR (get_opts.opt_arg ());
154 break;
156 case '?':
157 default:
158 ACE_ERROR_RETURN ((LM_ERROR,
159 "usage: %s "
160 "-a <mcast_address>"
161 "\n",
162 argv [0]),
163 -1);
165 // Indicates successful parsing of the command line
166 return 0;