2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
5 /// Implement the Server Interface
11 ServerServant (PortableServer::POA_ptr poa
,
14 void CreateExtra (CORBA::ULong length
,
15 ServerSequence_out seq
);
17 void DeleteExtra (const ServerSequence
&seq
);
19 //FUZZ: disable check_for_lack_ACE_OS
21 //FUZZ: enable check_for_lack_ACE_OS
25 PortableServer::POA_var root_poa_
;
27 /// The ORB on which we are running
32 ServerServant::ServerServant (PortableServer::POA_ptr poa
,
34 :root_poa_ (PortableServer::POA::_duplicate (poa
)),
35 orb_ (CORBA::ORB::_duplicate (orb
))
39 /// Servant implementations
41 ServerServant::CreateExtra (CORBA::ULong len
,
42 ServerSequence_out seq
)
45 "(%P|%t) Create extra called with "
46 " length [%d]\n", len
));
48 ACE_NEW_THROW_EX (seq
,
54 for (CORBA::ULong cnt
= 0 ;
58 ServerServant
*servant
= 0;
60 ACE_NEW_THROW_EX (servant
,
61 ServerServant (this->root_poa_
.in (),
65 PortableServer::ObjectId_var id
=
66 this->root_poa_
->activate_object (servant
);
67 CORBA::Object_var object
= this->root_poa_
->id_to_reference (id
.in ());
68 (*seq
)[cnt
] = Server::_narrow (object
.in ());
72 "(%P|%t) Returned from CreateExtra ()\n"));
77 ServerServant::DeleteExtra (const ServerSequence
&seq
)
80 "(%P|%t) Deleting %d sequences\n", seq
.length ()));
82 PortableServer::ObjectId_var oid
;
83 PortableServer::ServantBase
*servant
= 0;
85 for (CORBA::ULong cnt
= 0;
90 this->root_poa_
->reference_to_id (seq
[cnt
]);
92 this->root_poa_
->reference_to_servant (seq
[cnt
]);
94 this->root_poa_
->deactivate_object (oid
.in ());
95 servant
->_remove_ref ();
96 servant
->_remove_ref ();
100 "(%P|%t) Returned after deleting sequences\n"));
104 ServerServant::shutdown ()
106 this->orb_
->shutdown (false);
109 /******************************************************/
110 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
113 parse_args (int argc
, ACE_TCHAR
*argv
[])
115 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
118 while ((c
= get_opts ()) != -1)
122 ior_output_file
= get_opts
.opt_arg ();
127 ACE_ERROR_RETURN ((LM_ERROR
,
134 // Indicates successful parsing of the command line
139 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
144 // Initialize the broker
145 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
147 if (parse_args (argc
, argv
) == -1)
150 CORBA::Object_var vRootPOABase
=
151 orb
->resolve_initial_references ("RootPOA");
153 PortableServer::POA_var root_poa
=
154 PortableServer::POA::_narrow (vRootPOABase
.in ());
156 if (CORBA::is_nil (root_poa
.in ()))
157 ACE_ERROR_RETURN ((LM_ERROR
,
158 " (%P|%t) Panic: nil RootPOA\n"),
161 PortableServer::POAManager_ptr pRootPOAManager
=
162 root_poa
->the_POAManager ();
164 // Instantiate the server
165 ServerServant
*servant
= 0;
167 ACE_NEW_RETURN (servant
,
168 ServerServant (root_poa
.in (),
172 PortableServer::ServantBase_var
owner_transfer(servant
);
174 PortableServer::ObjectId_var id
=
175 root_poa
->activate_object (servant
);
177 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
180 Server::_narrow (object
.in ());
182 // Announce the server
183 CORBA::String_var obj_ref
=
184 orb
->object_to_string (server
.in ());
186 // Output the IOR to the <ior_output_file>
187 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
188 if (output_file
== 0)
189 ACE_ERROR_RETURN ((LM_ERROR
,
190 "Cannot open output file for writing IOR: %s",
193 ACE_OS::fprintf (output_file
, "%s", obj_ref
.in ());
194 ACE_OS::fclose (output_file
);
196 pRootPOAManager
->activate ();
200 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
202 root_poa
->destroy (true, true);
206 catch (const CORBA::Exception
& ex
)
208 ex
._tao_print_exception ("Exception caught:");