Orocos Real-Time Toolkit  2.6.0
POAUtility.cpp
00001 /***************************************************************************
00002   tag: FMTC  do nov 2 13:06:20 CET 2006  POAUtility.cpp
00003 
00004                         POAUtility.cpp -  description
00005                            -------------------
00006     begin                : do november 02 2006
00007     copyright            : (C) 2006 FMTC
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 
00040 #include "POAUtility.h"
00041 
00042 PortableServer::POA_ptr
00043 POAUtility::create_basic_POA(
00044     PortableServer::POA_ptr           parentPOAP,
00045     PortableServer::POAManager_ptr    POAManagerP,
00046     const char *                            POAName,
00047     CORBA::Boolean                    isMultiThread,
00048     CORBA::Boolean                    isPersistent
00049 )
00050 {
00051     // Create a policy list.
00052     CORBA::PolicyList policies;
00053     policies.length(4);
00054     CORBA::ULong i = 0;
00055 
00056     // Thread Policy
00057     PortableServer::ThreadPolicyValue threadPolicy;
00058 
00059     if (isMultiThread) {
00060         threadPolicy = PortableServer::ORB_CTRL_MODEL;
00061     }
00062     else {
00063         threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
00064     }
00065     policies[i] = parentPOAP->create_thread_policy(threadPolicy);
00066 
00067     // Lifespan and IdAssignment Policies
00068     PortableServer::LifespanPolicyValue     lifeSpanPolicy;
00069     PortableServer::IdAssignmentPolicyValue idAssignPolicy;
00070     PortableServer::ImplicitActivationPolicyValue implicitActivationPolicy;
00071 
00072     if (isPersistent) {
00073         // Policies for 'Entity' objects
00074         lifeSpanPolicy = PortableServer::PERSISTENT;
00075         idAssignPolicy = PortableServer::USER_ID;
00076     }
00077     else {
00078         // Policies for 'Session' objects
00079         lifeSpanPolicy = PortableServer::TRANSIENT;
00080         idAssignPolicy = PortableServer::SYSTEM_ID;
00081     }
00082 
00083     implicitActivationPolicy = PortableServer::IMPLICIT_ACTIVATION;
00084 
00085     // Lifespan Policy
00086     i++;
00087     policies[i] = parentPOAP->create_lifespan_policy(lifeSpanPolicy);
00088 
00089     // IdAssignment Policy
00090     i++;
00091     policies[i] = parentPOAP->create_id_assignment_policy(idAssignPolicy);
00092 
00093     // IdUniqueness Policy        -  Default = UNIQUE_ID
00094 
00095     // ImplicitActivation Policy  -  Default = NO_IMPLICIT_ACTIVATION
00096     // Override by PS:
00097     i++;
00098     policies[i] = parentPOAP->create_implicit_activation_policy(implicitActivationPolicy);
00099     
00100 
00101     // RequestProcessing Policy   -  Default = USE_ACTIVE_OBJECT_MAP_ONLY
00102 
00103     // ServantRetention Policy    -  Default = RETAIN
00104  
00105     return parentPOAP->create_POA(POAName, POAManagerP, policies);
00106 }
00107 
00108 
00109 PortableServer::POA_ptr
00110 POAUtility::create_service_POA(
00111     PortableServer::POA_ptr           parentPOAP,
00112     PortableServer::POAManager_ptr    POAManagerP,
00113     const char *                            POAName,
00114     CORBA::Boolean                    isMultiThread
00115 )
00116 {
00117     // Create a policy list.
00118     CORBA::PolicyList policies;
00119     policies.length(2);
00120     CORBA::ULong i = 0;
00121 
00122     // Thread Policy
00123     PortableServer::ThreadPolicyValue threadPolicy;
00124 
00125     if (isMultiThread) {
00126         threadPolicy = PortableServer::ORB_CTRL_MODEL;
00127     }
00128     else {
00129         threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
00130     }
00131     policies[i] = parentPOAP->create_thread_policy(threadPolicy);
00132 
00133     // LifeSpan Policy            -  Default = TRANSIENT
00134 
00135     // IdAssignment Policy        -  Default = SYSTEM_ID
00136 
00137     // IdUniqueness Policy
00138     i++;
00139     policies[i] = parentPOAP->create_id_uniqueness_policy(
00140         PortableServer::MULTIPLE_ID
00141     );
00142 
00143     // ImplicitActivation Policy  -  Default = NO_IMPLICIT_ACTIVATION
00144 
00145     // RequestProcessing Policy   -  Default = USE_ACTIVE_OBJECT_MAP_ONLY
00146 
00147     // ServantRetention Policy    -  Default = RETAIN
00148 
00149     return parentPOAP->create_POA(POAName, POAManagerP, policies);
00150 }
00151 
00152 
00153 PortableServer::POA_ptr
00154 POAUtility::create_servant_activator_POA(
00155     PortableServer::POA_ptr           parentPOAP,
00156     PortableServer::POAManager_ptr    POAManagerP,
00157     const char *                            POAName,
00158     CORBA::Boolean                    isMultiThread,
00159     CORBA::Boolean                    isPersistent
00160 )
00161 {
00162     // Create a policy list.
00163     CORBA::PolicyList policies;
00164     policies.length(4);
00165     CORBA::ULong i = 0;
00166 
00167     // Thread Policy
00168     PortableServer::ThreadPolicyValue threadPolicy;
00169 
00170     if (isMultiThread) {
00171         threadPolicy = PortableServer::ORB_CTRL_MODEL;
00172     }
00173     else {
00174         threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
00175     }
00176     policies[i] = parentPOAP->create_thread_policy(threadPolicy);
00177 
00178     PortableServer::LifespanPolicyValue     lifeSpanPolicy;
00179     PortableServer::IdAssignmentPolicyValue idAssignPolicy;
00180 
00181     // Lifespan and IdAssignment Policies
00182     if (isPersistent) {
00183         // Policies for 'Entity' objects
00184         lifeSpanPolicy = PortableServer::PERSISTENT;
00185         idAssignPolicy = PortableServer::USER_ID;
00186     }
00187     else {
00188         // Policies for 'Session' objects
00189         lifeSpanPolicy = PortableServer::TRANSIENT;
00190         idAssignPolicy = PortableServer::SYSTEM_ID;
00191     }
00192 
00193     // Lifespan Policy
00194     i++;
00195     policies[i] = parentPOAP->create_lifespan_policy(lifeSpanPolicy);
00196 
00197     // IdAssignment Policy
00198     i++;
00199     policies[i] = parentPOAP->create_id_assignment_policy(idAssignPolicy);
00200 
00201     // IdUniqueness Policy        -  Default = UNIQUE_ID
00202 
00203     // ImplicitActivation Policy  -  Default = NO_IMPLICIT_ACTIVATION
00204 
00205     // RequestProcessing Policy
00206     i++;
00207     policies[i] = parentPOAP->create_request_processing_policy(
00208         PortableServer::USE_SERVANT_MANAGER
00209     );
00210 
00211     // ServantRetention Policy    -  Default = RETAIN
00212 
00213     return parentPOAP->create_POA(POAName, POAManagerP, policies);
00214 }
00215 
00216 
00217 PortableServer::POA_ptr
00218 POAUtility::create_servant_locator_POA(
00219     PortableServer::POA_ptr           parentPOAP,
00220     PortableServer::POAManager_ptr    POAManagerP,
00221     const char *                            POAName,
00222     CORBA::Boolean                    isMultiThread,
00223     CORBA::Boolean                    isPersistent
00224 )
00225 {
00226     // Create a policy list.
00227     CORBA::PolicyList policies;
00228     policies.length(5);
00229     CORBA::ULong i = 0;
00230 
00231     // Thread Policy
00232     PortableServer::ThreadPolicyValue threadPolicy;
00233 
00234     if (isMultiThread) {
00235         threadPolicy = PortableServer::ORB_CTRL_MODEL;
00236     }
00237     else {
00238         threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
00239     }
00240     policies[i] = parentPOAP->create_thread_policy(threadPolicy);
00241 
00242     PortableServer::LifespanPolicyValue     lifeSpanPolicy;
00243     PortableServer::IdAssignmentPolicyValue idAssignPolicy;
00244 
00245     // Lifespan and IdAssignment Policies
00246     if (isPersistent) {
00247         // Policies for 'Entity' objects
00248         lifeSpanPolicy = PortableServer::PERSISTENT;
00249         idAssignPolicy = PortableServer::USER_ID;
00250     }
00251     else {
00252         // Policies for 'Session' objects
00253         lifeSpanPolicy = PortableServer::TRANSIENT;
00254         idAssignPolicy = PortableServer::SYSTEM_ID;
00255     }
00256 
00257     // Lifespan Policy
00258     i++;
00259     policies[i] = parentPOAP->create_lifespan_policy(lifeSpanPolicy);
00260 
00261     // IdAssignment Policy
00262     i++;
00263     policies[i] = parentPOAP->create_id_assignment_policy(idAssignPolicy);
00264 
00265     // IdUniqueness Policy        -  Default = UNIQUE_ID
00266 
00267     // ImplicitActivation Policy  -  Default = NO_IMPLICIT_ACTIVATION
00268 
00269     // RequestProcessing Policy
00270     i++;
00271     policies[i] = parentPOAP->create_request_processing_policy(
00272         PortableServer::USE_SERVANT_MANAGER
00273     );
00274 
00275     // ServantRetention Policy
00276     i++;
00277     policies[i] = parentPOAP->create_servant_retention_policy(
00278         PortableServer::NON_RETAIN
00279     );
00280 
00281     return parentPOAP->create_POA(POAName, POAManagerP, policies);
00282 }
00283 
00284 
00285 PortableServer::POA_ptr
00286 POAUtility::create_default_servant_POA(
00287     PortableServer::POA_ptr           parentPOAP,
00288     PortableServer::POAManager_ptr    POAManagerP,
00289     const char *                            POAName,
00290     CORBA::Boolean                    isMultiThread
00291 )
00292 {
00293     // Create a policy list.
00294     CORBA::PolicyList policies;
00295     policies.length(3);
00296     CORBA::ULong i = 0;
00297 
00298     // Thread Policy
00299     PortableServer::ThreadPolicyValue threadPolicy;
00300 
00301     if (isMultiThread) {
00302         threadPolicy = PortableServer::ORB_CTRL_MODEL;
00303     }
00304     else {
00305         threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
00306     }
00307     policies[i] = parentPOAP->create_thread_policy(threadPolicy);
00308 
00309     // LifeSpan Policy            -  Default = TRANSIENT
00310 
00311     // IdAssignment Policy        -  Default = SYSTEM_ID
00312 
00313     // IdUniqueness Policy        -  Default = UNIQUE_ID
00314 
00315     // ImplicitActivation Policy  -  Default = NO_IMPLICIT_ACTIVATION
00316 
00317     // RequestProcessing Policy
00318     i++;
00319     policies[i] = parentPOAP->create_request_processing_policy(
00320         PortableServer::USE_DEFAULT_SERVANT
00321     );
00322 
00323     // ServantRetention Policy
00324     i++;
00325     policies[i] = parentPOAP->create_servant_retention_policy(
00326         PortableServer::NON_RETAIN
00327     );
00328 
00329     return parentPOAP->create_POA(POAName, POAManagerP, policies);
00330 }
00331 
00332