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"));
78 ServerServant::DeleteExtra (const ServerSequence
&seq
)
81 "(%P|%t) Deleting %d sequences\n", seq
.length ()));
83 PortableServer::ObjectId_var oid
;
84 PortableServer::ServantBase
*servant
= 0;
86 for (CORBA::ULong cnt
= 0;
91 this->root_poa_
->reference_to_id (seq
[cnt
]);
93 this->root_poa_
->reference_to_servant (seq
[cnt
]);
95 this->root_poa_
->deactivate_object (oid
.in ());
96 servant
->_remove_ref ();
97 servant
->_remove_ref ();
100 ACE_DEBUG ((LM_DEBUG
,
101 "(%P|%t) Returned after deleting sequences\n"));
105 ServerServant::shutdown (void)
107 this->orb_
->shutdown (0);
110 /******************************************************/
111 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
114 parse_args (int argc
, ACE_TCHAR
*argv
[])
116 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
119 while ((c
= get_opts ()) != -1)
123 ior_output_file
= get_opts
.opt_arg ();
128 ACE_ERROR_RETURN ((LM_ERROR
,
135 // Indicates successful parsing of the command line
140 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
145 // Initialize the broker
146 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
148 if (parse_args (argc
, argv
) == -1)
151 CORBA::Object_var vRootPOABase
=
152 orb
->resolve_initial_references ("RootPOA");
154 PortableServer::POA_var root_poa
=
155 PortableServer::POA::_narrow (vRootPOABase
.in ());
157 if (CORBA::is_nil (root_poa
.in ()))
158 ACE_ERROR_RETURN ((LM_ERROR
,
159 " (%P|%t) Panic: nil RootPOA\n"),
162 PortableServer::POAManager_ptr pRootPOAManager
=
163 root_poa
->the_POAManager ();
165 // Instantiate the server
166 ServerServant
*servant
= 0;
168 ACE_NEW_RETURN (servant
,
169 ServerServant (root_poa
.in (),
173 PortableServer::ServantBase_var
owner_transfer(servant
);
175 PortableServer::ObjectId_var id
=
176 root_poa
->activate_object (servant
);
178 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
181 Server::_narrow (object
.in ());
183 // Announce the server
184 CORBA::String_var obj_ref
=
185 orb
->object_to_string (server
.in ());
187 // Output the IOR to the <ior_output_file>
188 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
189 if (output_file
== 0)
190 ACE_ERROR_RETURN ((LM_ERROR
,
191 "Cannot open output file for writing IOR: %s",
194 ACE_OS::fprintf (output_file
, "%s", obj_ref
.in ());
195 ACE_OS::fclose (output_file
);
197 pRootPOAManager
->activate ();
201 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
203 root_poa
->destroy (1, 1);
207 catch (const CORBA::Exception
& ex
)
209 ex
._tao_print_exception ("Exception caught:");