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
[])
28 // Initialize the ORB first.
29 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
31 // Obtain the RootPOA.
32 CORBA::Object_var obj
=
33 orb
->resolve_initial_references ("RootPOA");
36 PortableServer::POA_var root_poa
=
37 PortableServer::POA::_narrow (obj
.in ());
39 // Get the POAManager of the POA.
40 PortableServer::POAManager_var poa_manager
=
41 root_poa
->the_POAManager ();
43 poa_manager
->activate ();
45 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
48 PortableServer::ThreadPolicy_var policy1
=
49 root_poa
->create_thread_policy (PortableServer::ORB_CTRL_MODEL
);
51 CORBA::Any policy_value
;
52 policy_value
<<= PortableServer::ORB_CTRL_MODEL
;
54 CORBA::Policy_var policy
=
55 orb
->create_policy (PortableServer::THREAD_POLICY_ID
,
58 PortableServer::ThreadPolicy_var policy2
=
59 PortableServer::ThreadPolicy::_narrow (policy
.in ());
61 ACE_ASSERT (policy1
->value () == policy2
->value ());
64 #endif /* TAO_HAS_MINIMUM_POA == 0 */
67 PortableServer::LifespanPolicy_var policy1
=
68 root_poa
->create_lifespan_policy (PortableServer::TRANSIENT
);
70 CORBA::Any policy_value
;
71 policy_value
<<= PortableServer::TRANSIENT
;
73 CORBA::Policy_var policy
=
74 orb
->create_policy (PortableServer::LIFESPAN_POLICY_ID
,
77 PortableServer::LifespanPolicy_var policy2
=
78 PortableServer::LifespanPolicy::_narrow (policy
.in ());
80 ACE_ASSERT (policy1
->value () == policy2
->value ());
84 PortableServer::IdUniquenessPolicy_var policy1
=
85 root_poa
->create_id_uniqueness_policy (PortableServer::UNIQUE_ID
);
87 CORBA::Any policy_value
;
88 policy_value
<<= PortableServer::UNIQUE_ID
;
90 CORBA::Policy_var policy
=
91 orb
->create_policy (PortableServer::ID_UNIQUENESS_POLICY_ID
,
94 PortableServer::IdUniquenessPolicy_var policy2
=
95 PortableServer::IdUniquenessPolicy::_narrow (policy
.in ());
97 ACE_ASSERT (policy1
->value () == policy2
->value ());
101 PortableServer::IdAssignmentPolicy_var policy1
=
102 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
104 CORBA::Any policy_value
;
105 policy_value
<<= PortableServer::USER_ID
;
107 CORBA::Policy_var policy
=
108 orb
->create_policy (PortableServer::ID_ASSIGNMENT_POLICY_ID
,
111 PortableServer::IdAssignmentPolicy_var policy2
=
112 PortableServer::IdAssignmentPolicy::_narrow (policy
.in ());
114 ACE_ASSERT (policy1
->value () == policy2
->value ());
117 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
120 PortableServer::ImplicitActivationPolicy_var policy1
=
121 root_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
123 CORBA::Any policy_value
;
124 policy_value
<<= PortableServer::IMPLICIT_ACTIVATION
;
126 CORBA::Policy_var policy
=
127 orb
->create_policy (PortableServer::IMPLICIT_ACTIVATION_POLICY_ID
,
130 PortableServer::ImplicitActivationPolicy_var policy2
=
131 PortableServer::ImplicitActivationPolicy::_narrow (policy
.in ());
133 ACE_ASSERT (policy1
->value () == policy2
->value ());
137 PortableServer::ServantRetentionPolicy_var policy1
=
138 root_poa
->create_servant_retention_policy (PortableServer::RETAIN
);
140 CORBA::Any policy_value
;
141 policy_value
<<= PortableServer::RETAIN
;
143 CORBA::Policy_var policy
=
144 orb
->create_policy (PortableServer::SERVANT_RETENTION_POLICY_ID
,
147 PortableServer::ServantRetentionPolicy_var policy2
=
148 PortableServer::ServantRetentionPolicy::_narrow (policy
.in ());
150 ACE_ASSERT (policy1
->value () == policy2
->value ());
154 PortableServer::RequestProcessingPolicy_var policy1
=
155 root_poa
->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY
);
157 CORBA::Any policy_value
;
158 policy_value
<<= PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY
;
160 CORBA::Policy_var policy
=
161 orb
->create_policy (PortableServer::REQUEST_PROCESSING_POLICY_ID
,
164 PortableServer::RequestProcessingPolicy_var policy2
=
165 PortableServer::RequestProcessingPolicy::_narrow (policy
.in ());
167 ACE_ASSERT (policy1
->value () == policy2
->value ());
170 #endif /* TAO_HAS_MINIMUM_POA == 0 */
174 ACE_DEBUG ((LM_DEBUG
,
178 catch (const CORBA::Exception
& ex
)
180 ex
._tao_print_exception ("Exception caught");