1 #include "Server_Task.h"
2 #include "Servant_Activator.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/Manual_Event.h"
6 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
9 write_iors_to_file (const char *first_ior
)
11 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
12 if (output_file
== 0 )
13 ACE_ERROR_RETURN ((LM_ERROR
, "Cannot open output files for writing IORs: %Cn",
17 int result
= ACE_OS::fprintf (output_file
,
21 ACE_OS::fclose (output_file
);
24 || static_cast<size_t> (result
) != ACE_OS::strlen (first_ior
))
25 ACE_ERROR_RETURN ((LM_ERROR
,
26 "ACE_OS::fprintf failed while writing %C to %s\n",
34 Server_Task::Server_Task (const ACE_TCHAR
*output
,
37 ACE_Thread_Manager
*thr_mgr
)
38 : ACE_Task_Base (thr_mgr
)
41 , sorb_ (CORBA::ORB::_duplicate (sorb
))
50 CORBA::Object_var poa_object
=
51 this->sorb_
->resolve_initial_references("RootPOA");
53 PortableServer::POA_var root_poa
=
54 PortableServer::POA::_narrow (poa_object
.in ());
56 if (CORBA::is_nil (root_poa
.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 " (%P|%t) Panic: nil RootPOA\n"),
61 PortableServer::POAManager_var poa_manager
=
62 root_poa
->the_POAManager ();
65 CORBA::PolicyList
policies (4);
68 // ID Assignment Policy
70 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
74 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
76 // Request Processing Policy
78 root_poa
->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER
);
80 PortableServer::POA_var first_poa
;
82 // Servant Retention Policy
84 root_poa
->create_servant_retention_policy (PortableServer::RETAIN
);
86 ACE_CString name
= "firstPOA";
88 // Create firstPOA as the child of RootPOA with the above policies
89 // firstPOA will use SERVANT_ACTIVATOR because of RETAIN policy.
90 first_poa
= root_poa
->create_POA (name
.c_str (),
95 // Destroy the policy objects as they have been passed to
96 // create_POA and no longer needed.
97 for (CORBA::ULong i
= 0;
98 i
< policies
.length ();
101 CORBA::Policy_ptr policy
= policies
[i
];
104 // Allocate the servant activator.
105 ServantActivator
activator (this->sorb_
.in (), ACE_Thread::self ());
106 // Set ServantActivator object as the servant_manager of
109 first_poa
->set_servant_manager (&activator
);
110 // Create a reference with user created ID in firstPOA which uses
111 // the ServantActivator.
113 PortableServer::ObjectId_var first_test_oid
=
114 PortableServer::string_to_ObjectId ("first test");
116 CORBA::Object_var first_test
=
117 first_poa
->create_reference_with_id (first_test_oid
.in (), "IDL:test:1.0");
118 // Invoke object_to_string on the references created in firstPOA
120 CORBA::String_var first_test_ior
=
121 this->sorb_
->object_to_string (first_test
.in ());
123 // Print the ior's of first_test.
124 ACE_DEBUG((LM_DEBUG
,"<%C>\n",
125 first_test_ior
.in ()));
127 int write_result
= write_iors_to_file (first_test_ior
.in ());
128 if (write_result
!= 0)
131 // Set the poa_manager state to active, ready to process requests.
132 poa_manager
->activate ();
137 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
139 catch (const CORBA::Exception
& ex
)
141 ex
._tao_print_exception ("Exception caught:");