2 #include "Stock_Factory_i.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/streams.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("server.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
15 while ((c
= get_opts ()) != -1)
19 ior_output_file
= get_opts
.opt_arg ();
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
35 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
38 // First initialize the ORB, that will remove some arguments...
39 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
, "TestORB");
41 if (parse_args (argc
, argv
) != 0)
44 CORBA::Object_var poa_object
= orb
->resolve_initial_references ("RootPOA");
45 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow (poa_object
.in());
46 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
47 poa_manager
->activate ();
49 // Make policies for child POA
50 CORBA::PolicyList
policies(2) ;
52 policies
[0] = root_poa
->create_lifespan_policy ( PortableServer::PERSISTENT
) ;
53 policies
[1] = root_poa
->create_id_assignment_policy ( PortableServer::USER_ID
) ;
55 PortableServer::POA_var poa
= root_poa
->create_POA ( "MyPOA", poa_manager
.in(), policies
);
57 // Creation of the new POAs over, so destroy the Policy_ptr's.
58 for ( CORBA::ULong i
= 0 ; i
< policies
.length (); ++i
) {
59 CORBA::Policy_ptr policy
= policies
[i
];
63 // use this poa for making system objects
64 Quoter_Stock_i::set_default_POA ( poa
.in() ) ;
67 Quoter_Stock_Factory_i
*stock_factory_i
= 0;
68 ACE_NEW_RETURN (stock_factory_i
,
69 Quoter_Stock_Factory_i
,
71 PortableServer::ServantBase_var
safe (stock_factory_i
);
73 // Activate it to obtain the object reference
74 PortableServer::ObjectId_var id
=
75 root_poa
->activate_object (stock_factory_i
);
77 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
79 Quoter::Stock_Factory_var stock_factory
=
80 Quoter::Stock_Factory::_narrow (object_act
.in ());
82 // Put the object reference as an IOR string
83 CORBA::String_var ior
= orb
->object_to_string (stock_factory
.in ());
85 // Output the IOR to the <ior_output_file>
86 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
88 ACE_ERROR_RETURN ((LM_ERROR
,
89 "Cannot open output file for writing IOR: %s\n",
92 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
93 ACE_OS::fclose (output_file
);
95 ACE_Time_Value
timeout (15);
98 // Destroy the POA, waiting until the destruction terminates
99 root_poa
->destroy (1, 1);
102 catch (const CORBA::Exception
& e
) {
103 cerr
<< "CORBA exception raised: " << e
<< endl
;