PageRenderTime 64ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/rtt/transports/corba/POAUtility.cpp

https://github.com/jsreng/orocos-rtt
C++ | 332 lines | 179 code | 67 blank | 86 comment | 16 complexity | 9208385a164fa27282cccee51b5aa4b4 MD5 | raw file
Possible License(s): GPL-2.0
  1. /***************************************************************************
  2. tag: FMTC do nov 2 13:06:20 CET 2006 POAUtility.cpp
  3. POAUtility.cpp - description
  4. -------------------
  5. begin : do november 02 2006
  6. copyright : (C) 2006 FMTC
  7. email : peter.soetens@fmtc.be
  8. ***************************************************************************
  9. * This library is free software; you can redistribute it and/or *
  10. * modify it under the terms of the GNU General Public *
  11. * License as published by the Free Software Foundation; *
  12. * version 2 of the License. *
  13. * *
  14. * As a special exception, you may use this file as part of a free *
  15. * software library without restriction. Specifically, if other files *
  16. * instantiate templates or use macros or inline functions from this *
  17. * file, or you compile this file and link it with other files to *
  18. * produce an executable, this file does not by itself cause the *
  19. * resulting executable to be covered by the GNU General Public *
  20. * License. This exception does not however invalidate any other *
  21. * reasons why the executable file might be covered by the GNU General *
  22. * Public License. *
  23. * *
  24. * This library is distributed in the hope that it will be useful, *
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  27. * Lesser General Public License for more details. *
  28. * *
  29. * You should have received a copy of the GNU General Public *
  30. * License along with this library; if not, write to the Free Software *
  31. * Foundation, Inc., 59 Temple Place, *
  32. * Suite 330, Boston, MA 02111-1307 USA *
  33. * *
  34. ***************************************************************************/
  35. #include "POAUtility.h"
  36. PortableServer::POA_ptr
  37. POAUtility::create_basic_POA(
  38. PortableServer::POA_ptr parentPOAP,
  39. PortableServer::POAManager_ptr POAManagerP,
  40. const char * POAName,
  41. CORBA::Boolean isMultiThread,
  42. CORBA::Boolean isPersistent
  43. )
  44. {
  45. // Create a policy list.
  46. CORBA::PolicyList policies;
  47. policies.length(4);
  48. CORBA::ULong i = 0;
  49. // Thread Policy
  50. PortableServer::ThreadPolicyValue threadPolicy;
  51. if (isMultiThread) {
  52. threadPolicy = PortableServer::ORB_CTRL_MODEL;
  53. }
  54. else {
  55. threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
  56. }
  57. policies[i] = parentPOAP->create_thread_policy(threadPolicy);
  58. // Lifespan and IdAssignment Policies
  59. PortableServer::LifespanPolicyValue lifeSpanPolicy;
  60. PortableServer::IdAssignmentPolicyValue idAssignPolicy;
  61. PortableServer::ImplicitActivationPolicyValue implicitActivationPolicy;
  62. if (isPersistent) {
  63. // Policies for 'Entity' objects
  64. lifeSpanPolicy = PortableServer::PERSISTENT;
  65. idAssignPolicy = PortableServer::USER_ID;
  66. }
  67. else {
  68. // Policies for 'Session' objects
  69. lifeSpanPolicy = PortableServer::TRANSIENT;
  70. idAssignPolicy = PortableServer::SYSTEM_ID;
  71. }
  72. implicitActivationPolicy = PortableServer::IMPLICIT_ACTIVATION;
  73. // Lifespan Policy
  74. i++;
  75. policies[i] = parentPOAP->create_lifespan_policy(lifeSpanPolicy);
  76. // IdAssignment Policy
  77. i++;
  78. policies[i] = parentPOAP->create_id_assignment_policy(idAssignPolicy);
  79. // IdUniqueness Policy - Default = UNIQUE_ID
  80. // ImplicitActivation Policy - Default = NO_IMPLICIT_ACTIVATION
  81. // Override by PS:
  82. i++;
  83. policies[i] = parentPOAP->create_implicit_activation_policy(implicitActivationPolicy);
  84. // RequestProcessing Policy - Default = USE_ACTIVE_OBJECT_MAP_ONLY
  85. // ServantRetention Policy - Default = RETAIN
  86. return parentPOAP->create_POA(POAName, POAManagerP, policies);
  87. }
  88. PortableServer::POA_ptr
  89. POAUtility::create_service_POA(
  90. PortableServer::POA_ptr parentPOAP,
  91. PortableServer::POAManager_ptr POAManagerP,
  92. const char * POAName,
  93. CORBA::Boolean isMultiThread
  94. )
  95. {
  96. // Create a policy list.
  97. CORBA::PolicyList policies;
  98. policies.length(2);
  99. CORBA::ULong i = 0;
  100. // Thread Policy
  101. PortableServer::ThreadPolicyValue threadPolicy;
  102. if (isMultiThread) {
  103. threadPolicy = PortableServer::ORB_CTRL_MODEL;
  104. }
  105. else {
  106. threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
  107. }
  108. policies[i] = parentPOAP->create_thread_policy(threadPolicy);
  109. // LifeSpan Policy - Default = TRANSIENT
  110. // IdAssignment Policy - Default = SYSTEM_ID
  111. // IdUniqueness Policy
  112. i++;
  113. policies[i] = parentPOAP->create_id_uniqueness_policy(
  114. PortableServer::MULTIPLE_ID
  115. );
  116. // ImplicitActivation Policy - Default = NO_IMPLICIT_ACTIVATION
  117. // RequestProcessing Policy - Default = USE_ACTIVE_OBJECT_MAP_ONLY
  118. // ServantRetention Policy - Default = RETAIN
  119. return parentPOAP->create_POA(POAName, POAManagerP, policies);
  120. }
  121. PortableServer::POA_ptr
  122. POAUtility::create_servant_activator_POA(
  123. PortableServer::POA_ptr parentPOAP,
  124. PortableServer::POAManager_ptr POAManagerP,
  125. const char * POAName,
  126. CORBA::Boolean isMultiThread,
  127. CORBA::Boolean isPersistent
  128. )
  129. {
  130. // Create a policy list.
  131. CORBA::PolicyList policies;
  132. policies.length(4);
  133. CORBA::ULong i = 0;
  134. // Thread Policy
  135. PortableServer::ThreadPolicyValue threadPolicy;
  136. if (isMultiThread) {
  137. threadPolicy = PortableServer::ORB_CTRL_MODEL;
  138. }
  139. else {
  140. threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
  141. }
  142. policies[i] = parentPOAP->create_thread_policy(threadPolicy);
  143. PortableServer::LifespanPolicyValue lifeSpanPolicy;
  144. PortableServer::IdAssignmentPolicyValue idAssignPolicy;
  145. // Lifespan and IdAssignment Policies
  146. if (isPersistent) {
  147. // Policies for 'Entity' objects
  148. lifeSpanPolicy = PortableServer::PERSISTENT;
  149. idAssignPolicy = PortableServer::USER_ID;
  150. }
  151. else {
  152. // Policies for 'Session' objects
  153. lifeSpanPolicy = PortableServer::TRANSIENT;
  154. idAssignPolicy = PortableServer::SYSTEM_ID;
  155. }
  156. // Lifespan Policy
  157. i++;
  158. policies[i] = parentPOAP->create_lifespan_policy(lifeSpanPolicy);
  159. // IdAssignment Policy
  160. i++;
  161. policies[i] = parentPOAP->create_id_assignment_policy(idAssignPolicy);
  162. // IdUniqueness Policy - Default = UNIQUE_ID
  163. // ImplicitActivation Policy - Default = NO_IMPLICIT_ACTIVATION
  164. // RequestProcessing Policy
  165. i++;
  166. policies[i] = parentPOAP->create_request_processing_policy(
  167. PortableServer::USE_SERVANT_MANAGER
  168. );
  169. // ServantRetention Policy - Default = RETAIN
  170. return parentPOAP->create_POA(POAName, POAManagerP, policies);
  171. }
  172. PortableServer::POA_ptr
  173. POAUtility::create_servant_locator_POA(
  174. PortableServer::POA_ptr parentPOAP,
  175. PortableServer::POAManager_ptr POAManagerP,
  176. const char * POAName,
  177. CORBA::Boolean isMultiThread,
  178. CORBA::Boolean isPersistent
  179. )
  180. {
  181. // Create a policy list.
  182. CORBA::PolicyList policies;
  183. policies.length(5);
  184. CORBA::ULong i = 0;
  185. // Thread Policy
  186. PortableServer::ThreadPolicyValue threadPolicy;
  187. if (isMultiThread) {
  188. threadPolicy = PortableServer::ORB_CTRL_MODEL;
  189. }
  190. else {
  191. threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
  192. }
  193. policies[i] = parentPOAP->create_thread_policy(threadPolicy);
  194. PortableServer::LifespanPolicyValue lifeSpanPolicy;
  195. PortableServer::IdAssignmentPolicyValue idAssignPolicy;
  196. // Lifespan and IdAssignment Policies
  197. if (isPersistent) {
  198. // Policies for 'Entity' objects
  199. lifeSpanPolicy = PortableServer::PERSISTENT;
  200. idAssignPolicy = PortableServer::USER_ID;
  201. }
  202. else {
  203. // Policies for 'Session' objects
  204. lifeSpanPolicy = PortableServer::TRANSIENT;
  205. idAssignPolicy = PortableServer::SYSTEM_ID;
  206. }
  207. // Lifespan Policy
  208. i++;
  209. policies[i] = parentPOAP->create_lifespan_policy(lifeSpanPolicy);
  210. // IdAssignment Policy
  211. i++;
  212. policies[i] = parentPOAP->create_id_assignment_policy(idAssignPolicy);
  213. // IdUniqueness Policy - Default = UNIQUE_ID
  214. // ImplicitActivation Policy - Default = NO_IMPLICIT_ACTIVATION
  215. // RequestProcessing Policy
  216. i++;
  217. policies[i] = parentPOAP->create_request_processing_policy(
  218. PortableServer::USE_SERVANT_MANAGER
  219. );
  220. // ServantRetention Policy
  221. i++;
  222. policies[i] = parentPOAP->create_servant_retention_policy(
  223. PortableServer::NON_RETAIN
  224. );
  225. return parentPOAP->create_POA(POAName, POAManagerP, policies);
  226. }
  227. PortableServer::POA_ptr
  228. POAUtility::create_default_servant_POA(
  229. PortableServer::POA_ptr parentPOAP,
  230. PortableServer::POAManager_ptr POAManagerP,
  231. const char * POAName,
  232. CORBA::Boolean isMultiThread
  233. )
  234. {
  235. // Create a policy list.
  236. CORBA::PolicyList policies;
  237. policies.length(3);
  238. CORBA::ULong i = 0;
  239. // Thread Policy
  240. PortableServer::ThreadPolicyValue threadPolicy;
  241. if (isMultiThread) {
  242. threadPolicy = PortableServer::ORB_CTRL_MODEL;
  243. }
  244. else {
  245. threadPolicy = PortableServer::SINGLE_THREAD_MODEL;
  246. }
  247. policies[i] = parentPOAP->create_thread_policy(threadPolicy);
  248. // LifeSpan Policy - Default = TRANSIENT
  249. // IdAssignment Policy - Default = SYSTEM_ID
  250. // IdUniqueness Policy - Default = UNIQUE_ID
  251. // ImplicitActivation Policy - Default = NO_IMPLICIT_ACTIVATION
  252. // RequestProcessing Policy
  253. i++;
  254. policies[i] = parentPOAP->create_request_processing_policy(
  255. PortableServer::USE_DEFAULT_SERVANT
  256. );
  257. // ServantRetention Policy
  258. i++;
  259. policies[i] = parentPOAP->create_servant_retention_policy(
  260. PortableServer::NON_RETAIN
  261. );
  262. return parentPOAP->create_POA(POAName, POAManagerP, policies);
  263. }