2 //=============================================================================
6 * A server program for the File IDL module
8 * @author Irfan Pyarali
10 //=============================================================================
13 #include "Database_i.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/SString.h"
17 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("ior");
20 parse_args (int argc
, ACE_TCHAR
**argv
)
22 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("f:"));
25 while ((c
= get_opts ()) != -1)
29 ior_output_file
= get_opts
.opt_arg ();
33 ACE_ERROR_RETURN ((LM_ERROR
,
35 "[-f ior_output_file] "
41 // Indicates successful parsing of command line.
46 write_iors_to_file (const char *first_ior
)
48 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
51 ACE_ERROR_RETURN ((LM_ERROR
, "Cannot open output files for writing IOR: %s\n",
57 result
= ACE_OS::fprintf (output_file
,
61 ACE_OS::fclose (output_file
);
64 static_cast<size_t> (result
) != ACE_OS::strlen (first_ior
))
65 ACE_ERROR_RETURN ((LM_ERROR
,
66 "ACE_OS::fprintf failed while writing %C to %s\n",
75 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
80 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
82 int result
= parse_args (argc
, argv
);
86 // Obtain the RootPOA.
87 CORBA::Object_var obj
=
88 orb
->resolve_initial_references ("RootPOA");
90 // Narrow the object reference to a POA reference
91 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow (obj
.in ());
93 PortableServer::POAManager_var poa_manager
=
94 root_poa
->the_POAManager ();
96 CORBA::PolicyList
policies (5);
99 // ID Assignment Policy
101 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
105 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
107 // Request Processing Policy
109 root_poa
->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT
);
111 // Servant Retention Policy
113 root_poa
->create_servant_retention_policy (PortableServer::RETAIN
);
115 // Id Uniqueness Policy
117 root_poa
->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID
);
120 ACE_CString name
= "firstPOA";
121 PortableServer::POA_var first_poa
= root_poa
->create_POA (name
.c_str (),
125 for (CORBA::ULong i
= 0;
126 i
< policies
.length ();
129 CORBA::Policy_ptr policy
= policies
[i
];
133 // Create a Database Agent Implementation object in first_poa
134 DatabaseImpl::Agent
database_agent_impl (orb
.in (),
137 PortableServer::ObjectId_var database_agent_oid
=
138 PortableServer::string_to_ObjectId ("DatabaseAgent");
140 first_poa
->activate_object_with_id (database_agent_oid
.in (),
141 &database_agent_impl
);
143 CORBA::Object_var database_agent
=
144 first_poa
->id_to_reference (database_agent_oid
.in ());
146 // Get the IOR for the "DatabaseAgent" object
147 CORBA::String_var database_agent_ior
=
148 orb
->object_to_string (database_agent
.in ());
150 ACE_DEBUG ((LM_DEBUG
,"%C\n",
151 database_agent_ior
.in ()));
153 int write_result
= write_iors_to_file (database_agent_ior
.in ());
154 if (write_result
!= 0)
157 // set the state of the poa_manager to active i.e ready to process requests
158 poa_manager
->activate ();
165 catch (const CORBA::Exception
& ex
)
167 ex
._tao_print_exception ("Exception caught");