2 //=============================================================================
6 * A server program for the File IDL module
8 * @author Irfan Pyarali
10 //=============================================================================
14 #include "tao/debug.h"
15 #include "ace/streams.h"
16 #include "ace/Get_Opt.h"
17 #include "ace/SString.h"
18 #include "ace/OS_NS_stdio.h"
20 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("ior");
23 parse_args (int argc
, ACE_TCHAR
*argv
[])
25 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:d"));
28 while ((c
= get_opts ()) != -1)
32 ior_output_file
= get_opts
.opt_arg ();
39 ACE_ERROR_RETURN ((LM_ERROR
,
48 // Indicates successful parsing of command line.
53 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
58 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
60 int result
= parse_args (argc
, argv
);
64 // Obtain the RootPOA.
65 CORBA::Object_var obj
=
66 orb
->resolve_initial_references ("RootPOA");
68 // Narrow the object reference to a POA reference
69 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow (obj
.in ());
71 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
73 CORBA::PolicyList
policies (5);
76 // ID Assignment Policy
78 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
82 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
84 // Request Processing Policy
86 root_poa
->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT
);
88 // Servant Retention Policy
90 root_poa
->create_servant_retention_policy (PortableServer::RETAIN
);
92 // Id Uniqueness Policy
94 root_poa
->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID
);
96 ACE_CString name
= "firstPOA";
97 PortableServer::POA_var first_poa
= root_poa
->create_POA (name
.c_str (),
101 for (CORBA::ULong i
= 0;
102 i
< policies
.length ();
105 CORBA::Policy_ptr policy
= policies
[i
];
109 // Create a File System Implementation object in first_poa
110 FileImpl::System
file_system_impl (orb
.in (), first_poa
.in ());
112 PortableServer::ObjectId_var file_system_oid
=
113 PortableServer::string_to_ObjectId ("FileSystem");
115 first_poa
->activate_object_with_id (file_system_oid
.in (),
118 CORBA::Object_var file_system
=
119 first_poa
->id_to_reference (file_system_oid
.in ());
121 // Get the IOR for the "FileSystem" object
122 CORBA::String_var file_system_ior
=
123 orb
->object_to_string (file_system
.in ());
125 ACE_DEBUG ((LM_DEBUG
, "%C\n",
126 file_system_ior
.in ()));
128 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
129 if (output_file
== 0)
130 ACE_ERROR_RETURN ((LM_ERROR
,
131 "Cannot open output file %s for writing IOR",
134 ACE_OS::fprintf (output_file
, "%s", file_system_ior
.in ());
135 ACE_OS::fclose (output_file
);
137 // set the state of the poa_manager to active i.e ready to process requests
138 poa_manager
->activate ();
145 catch (const CORBA::Exception
& ex
)
147 ex
._tao_print_exception ("EXCEPTION CAUGHT");