2 //=============================================================================
6 * This program tests the construction of POA policies, both
7 * through the generic ORB::create_policy interface and the
8 * PortableServer specific interfaces.
10 * @author Irfan Pyarali
12 //=============================================================================
16 #include "tao/AnyTypeCode/Any.h"
17 #include "tao/PortableServer/PortableServer.h"
18 #include "tao/PI_Server/PI_Server.h"
20 #include "ace/Log_Msg.h"
23 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
27 // Initialize the ORB first.
28 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
30 // Obtain the RootPOA.
31 CORBA::Object_var obj
=
32 orb
->resolve_initial_references ("RootPOA");
35 PortableServer::POA_var root_poa
=
36 PortableServer::POA::_narrow (obj
.in ());
38 // Get the POAManager of the POA.
39 PortableServer::POAManager_var poa_manager
=
40 root_poa
->the_POAManager ();
42 poa_manager
->activate ();
44 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
47 PortableServer::ThreadPolicy_var policy1
=
48 root_poa
->create_thread_policy (PortableServer::ORB_CTRL_MODEL
);
50 CORBA::Any policy_value
;
51 policy_value
<<= PortableServer::ORB_CTRL_MODEL
;
53 CORBA::Policy_var policy
=
54 orb
->create_policy (PortableServer::THREAD_POLICY_ID
,
57 PortableServer::ThreadPolicy_var policy2
=
58 PortableServer::ThreadPolicy::_narrow (policy
.in ());
60 ACE_ASSERT (policy1
->value () == policy2
->value ());
63 #endif /* TAO_HAS_MINIMUM_POA == 0 */
66 PortableServer::LifespanPolicy_var policy1
=
67 root_poa
->create_lifespan_policy (PortableServer::TRANSIENT
);
69 CORBA::Any policy_value
;
70 policy_value
<<= PortableServer::TRANSIENT
;
72 CORBA::Policy_var policy
=
73 orb
->create_policy (PortableServer::LIFESPAN_POLICY_ID
,
76 PortableServer::LifespanPolicy_var policy2
=
77 PortableServer::LifespanPolicy::_narrow (policy
.in ());
79 ACE_ASSERT (policy1
->value () == policy2
->value ());
83 PortableServer::IdUniquenessPolicy_var policy1
=
84 root_poa
->create_id_uniqueness_policy (PortableServer::UNIQUE_ID
);
86 CORBA::Any policy_value
;
87 policy_value
<<= PortableServer::UNIQUE_ID
;
89 CORBA::Policy_var policy
=
90 orb
->create_policy (PortableServer::ID_UNIQUENESS_POLICY_ID
,
93 PortableServer::IdUniquenessPolicy_var policy2
=
94 PortableServer::IdUniquenessPolicy::_narrow (policy
.in ());
96 ACE_ASSERT (policy1
->value () == policy2
->value ());
100 PortableServer::IdAssignmentPolicy_var policy1
=
101 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
103 CORBA::Any policy_value
;
104 policy_value
<<= PortableServer::USER_ID
;
106 CORBA::Policy_var policy
=
107 orb
->create_policy (PortableServer::ID_ASSIGNMENT_POLICY_ID
,
110 PortableServer::IdAssignmentPolicy_var policy2
=
111 PortableServer::IdAssignmentPolicy::_narrow (policy
.in ());
113 ACE_ASSERT (policy1
->value () == policy2
->value ());
116 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
119 PortableServer::ImplicitActivationPolicy_var policy1
=
120 root_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
122 CORBA::Any policy_value
;
123 policy_value
<<= PortableServer::IMPLICIT_ACTIVATION
;
125 CORBA::Policy_var policy
=
126 orb
->create_policy (PortableServer::IMPLICIT_ACTIVATION_POLICY_ID
,
129 PortableServer::ImplicitActivationPolicy_var policy2
=
130 PortableServer::ImplicitActivationPolicy::_narrow (policy
.in ());
132 ACE_ASSERT (policy1
->value () == policy2
->value ());
136 PortableServer::ServantRetentionPolicy_var policy1
=
137 root_poa
->create_servant_retention_policy (PortableServer::RETAIN
);
139 CORBA::Any policy_value
;
140 policy_value
<<= PortableServer::RETAIN
;
142 CORBA::Policy_var policy
=
143 orb
->create_policy (PortableServer::SERVANT_RETENTION_POLICY_ID
,
146 PortableServer::ServantRetentionPolicy_var policy2
=
147 PortableServer::ServantRetentionPolicy::_narrow (policy
.in ());
149 ACE_ASSERT (policy1
->value () == policy2
->value ());
153 PortableServer::RequestProcessingPolicy_var policy1
=
154 root_poa
->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY
);
156 CORBA::Any policy_value
;
157 policy_value
<<= PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY
;
159 CORBA::Policy_var policy
=
160 orb
->create_policy (PortableServer::REQUEST_PROCESSING_POLICY_ID
,
163 PortableServer::RequestProcessingPolicy_var policy2
=
164 PortableServer::RequestProcessingPolicy::_narrow (policy
.in ());
166 ACE_ASSERT (policy1
->value () == policy2
->value ());
169 #endif /* TAO_HAS_MINIMUM_POA == 0 */
173 ACE_DEBUG ((LM_DEBUG
,
177 catch (const CORBA::Exception
& ex
)
179 ex
._tao_print_exception ("Exception caught");