4 #include "MCast_Server_i.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/IORTable/IORTable.h"
10 #include "ace/Get_Opt.h"
11 #include "ace/Read_Buffer.h"
23 Server_i::~Server_i ()
25 delete this->ior_multicast_
;
29 Server_i::init (int &argc
,
37 // First initialize the ORB, that will remove some arguments...
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 ());
50 PortableServer::POAManager_var poa_manager
=
51 poa
->the_POAManager ();
53 // Activate the POA Manager.
54 poa_manager
->activate ();
56 CORBA::String_var ior
;
59 MCast_Server_i server_i
;
61 // Activate it to obtain the reference
62 MCast::Server_var mcast_server
=
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"));
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)
87 "ERROR: Unable to enable multicast "
88 "on specified address.\n"));
90 throw CORBA::INTERNAL ();
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");
110 Server_i::enable_multicast (const char *ior
)
112 if (this->parse_args (this->argc_
, this->argv_
) != 0)
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 (),
125 if (this->ior_multicast_
->init (ior
,
126 this->mcast_address_
.in (),
127 TAO_SERVICEID_MCASTSERVER
) == -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"));
144 Server_i::parse_args (int argc
, ACE_TCHAR
*argv
[])
146 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("a:"));
149 while ((c
= get_opts ()) != -1)
153 this->mcast_address_
= ACE_TEXT_ALWAYS_CHAR (get_opts
.opt_arg ());
158 ACE_ERROR_RETURN ((LM_ERROR
,
165 // Indicates successful parsing of the command line