4 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
7 #include "ace/OS_NS_unistd.h"
8 #include "ace/OS_NS_fcntl.h"
10 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT("ior");
11 static const int nthreads
= 2;
17 * Use the ACE_Task_Base class to run server threads
19 class Worker
: public ACE_Task_Base
22 Worker (CORBA::ORB_ptr orb
);
25 virtual int svc (void);
26 // The thread entry point.
35 parse_args (int argc
, ACE_TCHAR
**argv
)
37 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:d"));
40 while ((c
= get_opts ()) != -1)
44 ior_output_file
= get_opts
.opt_arg ();
51 ACE_ERROR_RETURN ((LM_ERROR
,
60 // Indicates successful parsing of command line.
66 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
68 ACE_HANDLE handle
= ACE_OS::open ("big.txt",
70 ACE_DEFAULT_FILE_PERMS
);
72 ACE_OS::lseek (handle
, 1024*1024*10, SEEK_SET
);
73 ACE_OS::write (handle
, "", 1);
74 ACE_OS::close (handle
);
79 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
81 int result
= parse_args (argc
, argv
);
85 // Obtain the RootPOA.
86 CORBA::Object_var obj
=
87 orb
->resolve_initial_references ("RootPOA");
89 // Narrow the object reference to a POA reference
90 PortableServer::POA_var root_poa
=
91 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
);
119 ACE_CString name
= "firstPOA";
120 PortableServer::POA_var first_poa
=
121 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 File System Implementation object in first_poa
134 FileImpl::System
file_system_impl (first_poa
.in ());
136 PortableServer::ObjectId_var file_system_oid
=
137 PortableServer::string_to_ObjectId ("FileSystem");
139 first_poa
->activate_object_with_id (file_system_oid
.in (),
142 CORBA::Object_var file_system
=
143 first_poa
->id_to_reference (file_system_oid
.in ());
145 // Get the IOR for the "FileSystem" object
146 CORBA::String_var file_system_ior
=
147 orb
->object_to_string (file_system
.in ());
149 ACE_DEBUG ((LM_DEBUG
,"%C\n",
150 file_system_ior
.in ()));
152 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
153 if (output_file
== 0)
154 ACE_ERROR_RETURN ((LM_ERROR
,
155 "Cannot open output file for writing IOR: %s",
158 ACE_OS::fprintf (output_file
, "%s", file_system_ior
.in ());
159 ACE_OS::fclose (output_file
);
161 // set the state of the poa_manager to active i.e ready to
163 poa_manager
->activate ();
165 Worker
worker (orb
.in ());
166 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
168 ACE_ERROR_RETURN ((LM_ERROR
,
169 "Cannot activate client threads\n"),
172 worker
.thr_mgr ()->wait ();
174 first_poa
->destroy(1, 1);
176 root_poa
->destroy(1, 1);
180 catch (const CORBA::Exception
& ex
)
182 ex
._tao_print_exception ("EXCEPTION CAUGHT");
190 // ****************************************************************
192 Worker::Worker (CORBA::ORB_ptr orb
)
193 : orb_ (CORBA::ORB::_duplicate (orb
))
202 // Run the ORB for atmost 75 seconds
203 ACE_Time_Value
tv (75, 0);
204 this->orb_
->run (tv
);
206 catch (const CORBA::Exception
& ex
)
208 ex
._tao_print_exception ("Worker::svc");