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
))
46 Server_Task::svc (void)
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 (),
96 // Destroy the policy objects as they have been passed to
97 // create_POA and no longer needed.
98 for (CORBA::ULong i
= 0;
99 i
< policies
.length ();
102 CORBA::Policy_ptr policy
= policies
[i
];
105 // Allocate the servant activator.
106 ServantActivator
activator (this->sorb_
.in (), ACE_Thread::self ());
107 // Set ServantActivator object as the servant_manager of
110 first_poa
->set_servant_manager (&activator
);
111 // Create a reference with user created ID in firstPOA which uses
112 // the ServantActivator.
114 PortableServer::ObjectId_var first_test_oid
=
115 PortableServer::string_to_ObjectId ("first test");
117 CORBA::Object_var first_test
=
118 first_poa
->create_reference_with_id (first_test_oid
.in (), "IDL:test:1.0");
119 // Invoke object_to_string on the references created in firstPOA
121 CORBA::String_var first_test_ior
=
122 this->sorb_
->object_to_string (first_test
.in ());
124 // Print the ior's of first_test.
125 ACE_DEBUG((LM_DEBUG
,"<%C>\n",
126 first_test_ior
.in ()));
128 int write_result
= write_iors_to_file (first_test_ior
.in ());
129 if (write_result
!= 0)
132 // Set the poa_manager state to active, ready to process requests.
133 poa_manager
->activate ();
138 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
140 catch (const CORBA::Exception
& ex
)
142 ex
._tao_print_exception ("Exception caught:");