5 #include "ace/OS_NS_stdio.h"
7 LB_server::LB_server (int argc
, ACE_TCHAR
**argv
)
10 , ior_output_file_(ACE_TEXT("obj.ior"))
19 this->naming_manager_
->delete_object_group ("Basic Group");
21 this->root_poa_
->destroy (1, 1);
23 this->orb_
->destroy ();
25 catch (const CORBA::Exception
& ex
)
27 ex
._tao_print_exception (
28 ACE_TEXT ("Exception caught while destroying LB_server\n"));
37 return this->orb_
.in ();
41 LB_server::object_group ()
43 return this->object_group_
.in ();
46 FT_Naming::NamingManager_ptr
47 LB_server::naming_manager ()
49 return this->naming_manager_
.in ();
53 LB_server::write_ior_to_file (const char *ior
)
56 ACE_OS::fopen (this->ior_output_file_
, "w");
61 ACE_TEXT ("Cannot open output file for writing IOR:")));
65 ACE_OS::fprintf (output_file
, "%s", ior
);
66 ACE_OS::fclose (output_file
);
71 LB_server::parse_args (int argc
, ACE_TCHAR
*argv
[])
73 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
76 while ((c
= get_opts ()) != -1)
80 this->ior_output_file_
= get_opts
.opt_arg ();
84 ACE_ERROR_RETURN ((LM_ERROR
,
85 ACE_TEXT ("usage: %s ")
86 ACE_TEXT ("-o <iorfile>")
91 // Indicates successful parsing of the command line
96 LB_server::start_orb_and_poa ()
100 // Initialise the ORB.
101 this->orb_
= CORBA::ORB_init (this->argc_
, this->argv_
);
103 CORBA::Object_var poa_object
=
104 this->orb_
->resolve_initial_references("RootPOA");
106 if (CORBA::is_nil (poa_object
.in ()))
107 ACE_ERROR_RETURN ((LM_ERROR
,
108 ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
111 this->root_poa_
= PortableServer::POA::_narrow (poa_object
.in ());
113 PortableServer::POAManager_var poa_manager
=
114 this->root_poa_
->the_POAManager ();
116 poa_manager
->activate ();
118 ACE_Time_Value
timeout (10); // Wait up to 10 seconds for the naming service
119 if (name_svc_
.init (this->orb_
.in (), &timeout
) != 0)
120 ACE_ERROR_RETURN ((LM_DEBUG
,
121 ACE_TEXT ("LB_server: Could not connect to naming ")
122 ACE_TEXT ("service.\n")),
125 CORBA::Object_var obj
=
126 this->orb_
->resolve_initial_references ("NamingManager");
128 this->naming_manager_
=
129 FT_Naming::NamingManager::_narrow (obj
.in ());
131 if (CORBA::is_nil (this->naming_manager_
.in ()))
132 ACE_ERROR_RETURN ((LM_ERROR
,
133 ACE_TEXT (" (%P|%t) Unable to get Naming ")
134 ACE_TEXT ("Manager Reference\n")),
137 catch (const CORBA::Exception
& ex
)
139 ex
._tao_print_exception (
140 ACE_TEXT ("Exception raised initialising ORB or POA"));
148 LB_server::create_object_group ()
152 if (this->parse_args (argc_
, argv_
) != 0)
155 PortableGroup::Criteria
criteria (1);
158 PortableGroup::Property
&mem_style
= criteria
[0];
159 mem_style
.nam
.length (1);
161 // Set the membership style property
162 mem_style
.nam
[0].id
=
163 CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle");
164 PortableGroup::MembershipStyleValue msv
=
165 PortableGroup::MEMB_APP_CTRL
;
166 mem_style
.val
<<= msv
;
168 this->object_group_
= this->naming_manager_
->create_object_group (
170 FT_Naming::ROUND_ROBIN
,
173 CORBA::String_var ior
=
174 this->orb_
->object_to_string (this->object_group_
.in ());
176 this->write_ior_to_file (ior
.in ());
178 catch (const CORBA::Exception
& ex
)
180 ex
._tao_print_exception (
181 ACE_TEXT ("Exception raised while creating object group"));
189 LB_server::register_servant (Basic
*servant
, const char *loc
)
193 Test::Basic_var basic
=
196 PortableGroup::Location
location (1);
199 location
[0].id
= CORBA::string_dup (loc
);
201 this->object_group_
=
202 this->naming_manager_
->add_member (this->object_group_
.in (),
206 catch (const CORBA::Exception
& ex
)
208 ex
._tao_print_exception (
209 ACE_TEXT ("Exception raised while registering servant"));
217 LB_server::name_svc ()