r2corba 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +159 -0
  3. data/LICENSE +59 -0
  4. data/README +62 -0
  5. data/THANKS +52 -0
  6. data/bin/r2corba +8 -0
  7. data/bin/ridlc +11 -0
  8. data/bin/rins +7 -0
  9. data/ext/ext.mwc +6 -0
  10. data/ext/extload/extload.c +60 -0
  11. data/ext/libr2tao/any.cpp +1543 -0
  12. data/ext/libr2tao/exception.cpp +202 -0
  13. data/ext/libr2tao/exception.h +104 -0
  14. data/ext/libr2tao/longdouble.cpp +173 -0
  15. data/ext/libr2tao/longdouble.h +31 -0
  16. data/ext/libr2tao/object.cpp +1150 -0
  17. data/ext/libr2tao/object.h +38 -0
  18. data/ext/libr2tao/orb.cpp +1029 -0
  19. data/ext/libr2tao/orb.h +36 -0
  20. data/ext/libr2tao/r2tao_export.h +45 -0
  21. data/ext/libr2tao/r2tao_ext.h +38 -0
  22. data/ext/libr2tao/required.cpp +463 -0
  23. data/ext/libr2tao/required.h +187 -0
  24. data/ext/libr2tao/typecode.cpp +888 -0
  25. data/ext/libr2tao/typecode.h +45 -0
  26. data/ext/libr2tao/values.cpp +2938 -0
  27. data/ext/libr2tao/values.h +396 -0
  28. data/ext/librpoa/iortable.cpp +250 -0
  29. data/ext/librpoa/poa.cpp +1076 -0
  30. data/ext/librpoa/poa.h +24 -0
  31. data/ext/librpoa/rpoa_export.h +44 -0
  32. data/ext/librpoa/servant.cpp +1338 -0
  33. data/ext/librpoa/servant.h +116 -0
  34. data/ext/librpoa/srvreq_fix.cpp +283 -0
  35. data/ext/librpoa/srvreq_fix.h +149 -0
  36. data/ext/librpol/policies.cpp +763 -0
  37. data/ext/librpol/policies.h +15 -0
  38. data/ext/librpol/rpol_export.h +44 -0
  39. data/lib/corba/cbase/IORMap.rb +33 -0
  40. data/lib/corba/cbase/ORB.rb +231 -0
  41. data/lib/corba/cbase/Request.rb +134 -0
  42. data/lib/corba/cbase/Streams.rb +129 -0
  43. data/lib/corba/cbase/Stub.rb +19 -0
  44. data/lib/corba/cbase/Typecode.rb +441 -0
  45. data/lib/corba/cbase/Values.rb +129 -0
  46. data/lib/corba/cbase/exception.rb +66 -0
  47. data/lib/corba/cbase/poa.rb +23 -0
  48. data/lib/corba/cbase/policies.rb +78 -0
  49. data/lib/corba/cbase/post_require.rb +14 -0
  50. data/lib/corba/cbase/require.rb +28 -0
  51. data/lib/corba/cmds/base.rb +85 -0
  52. data/lib/corba/cmds/test.rb +30 -0
  53. data/lib/corba/common/Any.rb +91 -0
  54. data/lib/corba/common/IDL.rb +104 -0
  55. data/lib/corba/common/ORB.rb +368 -0
  56. data/lib/corba/common/Object.rb +208 -0
  57. data/lib/corba/common/Request.rb +20 -0
  58. data/lib/corba/common/Servant.rb +108 -0
  59. data/lib/corba/common/Struct.rb +22 -0
  60. data/lib/corba/common/Stub.rb +79 -0
  61. data/lib/corba/common/Typecode.rb +1121 -0
  62. data/lib/corba/common/Union.rb +56 -0
  63. data/lib/corba/common/Values.rb +92 -0
  64. data/lib/corba/common/const.rb +22 -0
  65. data/lib/corba/common/exception.rb +68 -0
  66. data/lib/corba/common/require.rb +27 -0
  67. data/lib/corba/common/version.rb +22 -0
  68. data/lib/corba/idl/IDL.rb +21 -0
  69. data/lib/corba/idl/IORTable.pidl +62 -0
  70. data/lib/corba/idl/TAO_Ext.pidl +46 -0
  71. data/lib/corba/idl/require.rb +20 -0
  72. data/lib/corba/jbase/Any.rb +273 -0
  73. data/lib/corba/jbase/IORMap.rb +36 -0
  74. data/lib/corba/jbase/ORB.rb +99 -0
  75. data/lib/corba/jbase/Object.rb +98 -0
  76. data/lib/corba/jbase/Request.rb +226 -0
  77. data/lib/corba/jbase/Servant.rb +247 -0
  78. data/lib/corba/jbase/ServerRequest.rb +128 -0
  79. data/lib/corba/jbase/Streams.rb +671 -0
  80. data/lib/corba/jbase/Stub.rb +38 -0
  81. data/lib/corba/jbase/Typecode.rb +520 -0
  82. data/lib/corba/jbase/Values.rb +173 -0
  83. data/lib/corba/jbase/exception.rb +106 -0
  84. data/lib/corba/jbase/poa.rb +229 -0
  85. data/lib/corba/jbase/policies.rb +300 -0
  86. data/lib/corba/jbase/post_require.rb +14 -0
  87. data/lib/corba/jbase/require.rb +86 -0
  88. data/lib/corba/naming.rb +14 -0
  89. data/lib/corba/naming_service.rb +15 -0
  90. data/lib/corba/poa.rb +15 -0
  91. data/lib/corba/policies.rb +18 -0
  92. data/lib/corba/require.rb +17 -0
  93. data/lib/corba/svcs/ins/cos_naming.rb +426 -0
  94. data/lib/corba/svcs/ins/ins.rb +526 -0
  95. data/lib/corba/svcs/ins/naming_service.rb +119 -0
  96. data/lib/corba.rb +16 -0
  97. data/lib/ridlbe/ruby/config.rb +336 -0
  98. data/lib/ridlbe/ruby/require.rb +16 -0
  99. data/lib/ridlbe/ruby/walker.rb +1582 -0
  100. data/mkrf_conf_srcgem.rb +186 -0
  101. data/rakelib/bin.rake +80 -0
  102. data/rakelib/bin.rb +146 -0
  103. data/rakelib/build.rake +87 -0
  104. data/rakelib/config.rake +52 -0
  105. data/rakelib/config.rb +450 -0
  106. data/rakelib/ext.rake +242 -0
  107. data/rakelib/ext.rb +308 -0
  108. data/rakelib/ext_r2tao.rb +232 -0
  109. data/rakelib/gem.rake +212 -0
  110. data/rakelib/gem.rb +146 -0
  111. data/rakelib/package.rake +26 -0
  112. data/rakelib/test.rake +23 -0
  113. data/test/BiDirectional/Test.idl +34 -0
  114. data/test/BiDirectional/client.rb +132 -0
  115. data/test/BiDirectional/run_test.rb +68 -0
  116. data/test/BiDirectional/server.rb +169 -0
  117. data/test/CORBA_Services/Naming/BindingIterator/Test.idl +27 -0
  118. data/test/CORBA_Services/Naming/BindingIterator/client.rb +121 -0
  119. data/test/CORBA_Services/Naming/BindingIterator/run_test.rb +82 -0
  120. data/test/CORBA_Services/Naming/BindingIterator/server.rb +109 -0
  121. data/test/CORBA_Services/Naming/Corbaname/Test.idl +27 -0
  122. data/test/CORBA_Services/Naming/Corbaname/client.rb +85 -0
  123. data/test/CORBA_Services/Naming/Corbaname/run_test.rb +88 -0
  124. data/test/CORBA_Services/Naming/Corbaname/server.rb +135 -0
  125. data/test/CORBA_Services/Naming/Simple/Test.idl +27 -0
  126. data/test/CORBA_Services/Naming/Simple/client.rb +84 -0
  127. data/test/CORBA_Services/Naming/Simple/run_test.rb +82 -0
  128. data/test/CORBA_Services/Naming/Simple/server.rb +109 -0
  129. data/test/Collocation/Diamond.idl +39 -0
  130. data/test/Collocation/run_test.rb +52 -0
  131. data/test/Collocation/test.rb +195 -0
  132. data/test/Connect_Timeout/Test.idl +27 -0
  133. data/test/Connect_Timeout/client.rb +111 -0
  134. data/test/Connect_Timeout/run_test.rb +52 -0
  135. data/test/DII/Test.idl +27 -0
  136. data/test/DII/client.rb +115 -0
  137. data/test/DII/run_test.rb +69 -0
  138. data/test/DII/server.rb +95 -0
  139. data/test/DSI/Test.idl +27 -0
  140. data/test/DSI/client.rb +66 -0
  141. data/test/DSI/run_test.rb +69 -0
  142. data/test/DSI/server.rb +106 -0
  143. data/test/Exceptions/Test.idl +48 -0
  144. data/test/Exceptions/client.rb +118 -0
  145. data/test/Exceptions/run_test.rb +69 -0
  146. data/test/Exceptions/server.rb +131 -0
  147. data/test/Hello/Test.idl +27 -0
  148. data/test/Hello/client.rb +78 -0
  149. data/test/Hello/run_test.rb +71 -0
  150. data/test/Hello/server.rb +95 -0
  151. data/test/IDL_Test/Test.idl +113 -0
  152. data/test/IDL_Test/Test_inc.idl +17 -0
  153. data/test/IDL_Test/client.rb +102 -0
  154. data/test/IDL_Test/run_test.rb +69 -0
  155. data/test/IDL_Test/server.rb +99 -0
  156. data/test/IORMap/Test.idl +27 -0
  157. data/test/IORMap/client.rb +73 -0
  158. data/test/IORMap/run_test.rb +69 -0
  159. data/test/IORMap/server.rb +114 -0
  160. data/test/IORTable/Test.idl +27 -0
  161. data/test/IORTable/client.rb +75 -0
  162. data/test/IORTable/run_test.rb +69 -0
  163. data/test/IORTable/server.rb +130 -0
  164. data/test/Implicit_Conversion/Test.idl +31 -0
  165. data/test/Implicit_Conversion/client.rb +110 -0
  166. data/test/Implicit_Conversion/run_test.rb +69 -0
  167. data/test/Implicit_Conversion/server.rb +99 -0
  168. data/test/Multi_Threading/Multiple_ORB/Test.idl +27 -0
  169. data/test/Multi_Threading/Multiple_ORB/client.rb +82 -0
  170. data/test/Multi_Threading/Multiple_ORB/run_test.rb +71 -0
  171. data/test/Multi_Threading/Multiple_ORB/server.rb +108 -0
  172. data/test/Multi_Threading/Simple/Test.idl +27 -0
  173. data/test/Multi_Threading/Simple/client.rb +88 -0
  174. data/test/Multi_Threading/Simple/run_test.rb +69 -0
  175. data/test/Multi_Threading/Simple/server.rb +118 -0
  176. data/test/Multi_Threading/Threads/Test.idl +31 -0
  177. data/test/Multi_Threading/Threads/client.rb +80 -0
  178. data/test/Multi_Threading/Threads/run_test.rb +76 -0
  179. data/test/Multi_Threading/Threads/server.rb +119 -0
  180. data/test/Multi_Threading/Threads/watchdog.rb +87 -0
  181. data/test/Multiple_Servant_Interfaces/Test.idl +34 -0
  182. data/test/Multiple_Servant_Interfaces/client.rb +70 -0
  183. data/test/Multiple_Servant_Interfaces/run_test.rb +69 -0
  184. data/test/Multiple_Servant_Interfaces/server.rb +102 -0
  185. data/test/Nil/Test.idl +27 -0
  186. data/test/Nil/run_test.rb +52 -0
  187. data/test/Nil/test.rb +78 -0
  188. data/test/OBV/AbstractInterface/client.rb +179 -0
  189. data/test/OBV/AbstractInterface/run_test.rb +69 -0
  190. data/test/OBV/AbstractInterface/server.rb +149 -0
  191. data/test/OBV/AbstractInterface/test.idl +53 -0
  192. data/test/OBV/Custom/OBV.idl +18 -0
  193. data/test/OBV/Custom/OBV_impl.rb +40 -0
  194. data/test/OBV/Custom/client.rb +86 -0
  195. data/test/OBV/Custom/run_test.rb +69 -0
  196. data/test/OBV/Custom/server.rb +100 -0
  197. data/test/OBV/Simple/OBV.idl +15 -0
  198. data/test/OBV/Simple/OBV_impl.rb +26 -0
  199. data/test/OBV/Simple/client.rb +86 -0
  200. data/test/OBV/Simple/run_test.rb +69 -0
  201. data/test/OBV/Simple/server.rb +100 -0
  202. data/test/OBV/Simple_Event/Event.idl +15 -0
  203. data/test/OBV/Simple_Event/Event_impl.rb +26 -0
  204. data/test/OBV/Simple_Event/client.rb +86 -0
  205. data/test/OBV/Simple_Event/run_test.rb +69 -0
  206. data/test/OBV/Simple_Event/server.rb +100 -0
  207. data/test/OBV/Supports/client.rb +116 -0
  208. data/test/OBV/Supports/run_test.rb +69 -0
  209. data/test/OBV/Supports/server.rb +103 -0
  210. data/test/OBV/Supports/supports.idl +33 -0
  211. data/test/OBV/Supports/supports_impl.rb +57 -0
  212. data/test/OBV/Tree/client.rb +116 -0
  213. data/test/OBV/Tree/run_test.rb +69 -0
  214. data/test/OBV/Tree/server.rb +117 -0
  215. data/test/OBV/Tree/test.idl +32 -0
  216. data/test/OBV/Truncatable/Extra.idl +27 -0
  217. data/test/OBV/Truncatable/Truncatable.idl +105 -0
  218. data/test/OBV/Truncatable/Truncatable_impl.rb +86 -0
  219. data/test/OBV/Truncatable/client.rb +279 -0
  220. data/test/OBV/Truncatable/run_test.rb +69 -0
  221. data/test/OBV/Truncatable/server.rb +89 -0
  222. data/test/OBV/ValueBox/client.rb +497 -0
  223. data/test/OBV/ValueBox/run_test.rb +69 -0
  224. data/test/OBV/ValueBox/server.rb +271 -0
  225. data/test/OBV/ValueBox/valuebox.idl +101 -0
  226. data/test/OBV/ValueBox/vb_basic.idl +75 -0
  227. data/test/OBV/ValueBox/vb_struct.idl +68 -0
  228. data/test/OBV/ValueBox/vb_union.idl +21 -0
  229. data/test/Object/Test.idl +27 -0
  230. data/test/Object/client.rb +103 -0
  231. data/test/Object/run_test.rb +69 -0
  232. data/test/Object/server.rb +126 -0
  233. data/test/POA/Test.idl +27 -0
  234. data/test/POA/run_test.rb +52 -0
  235. data/test/POA/test.rb +112 -0
  236. data/test/Param_Test/Test.idl +182 -0
  237. data/test/Param_Test/client.rb +277 -0
  238. data/test/Param_Test/run_test.rb +69 -0
  239. data/test/Param_Test/server.rb +296 -0
  240. data/test/Performance/Simple/Test.idl +27 -0
  241. data/test/Performance/Simple/client.rb +90 -0
  242. data/test/Performance/Simple/run_test.rb +69 -0
  243. data/test/Performance/Simple/server.rb +95 -0
  244. data/test/Policies/Test.idl +27 -0
  245. data/test/Policies/run_test.rb +52 -0
  246. data/test/Policies/test.rb +144 -0
  247. data/test/Timeout/client.rb +207 -0
  248. data/test/Timeout/run_test.rb +69 -0
  249. data/test/Timeout/server.rb +109 -0
  250. data/test/Timeout/test.idl +19 -0
  251. data/test/lib/assert.rb +43 -0
  252. data/test/lib/test.rb +542 -0
  253. data/test/test_runner.rb +193 -0
  254. metadata +334 -0
@@ -0,0 +1,1338 @@
1
+ /*--------------------------------------------------------------------
2
+ # servant.cpp - R2TAO CORBA Servant support
3
+ #
4
+ # Author: Martin Corino
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the R2CORBA LICENSE which is
8
+ # included with this program.
9
+ #
10
+ # Copyright (c) Remedy IT Expertise BV
11
+ # Chamber of commerce Rotterdam nr.276339, The Netherlands
12
+ #------------------------------------------------------------------*/
13
+
14
+ #include "poa.h"
15
+ #include "tao/DynamicInterface/Server_Request.h"
16
+ #include "tao/DynamicInterface/Dynamic_Implementation.h"
17
+ #include "tao/AnyTypeCode/Any.h"
18
+ #include "tao/AnyTypeCode/NVList.h"
19
+ #include "tao/ORB.h"
20
+ #include "tao/Exception.h"
21
+ #include "tao/TSS_Resources.h"
22
+ #include "tao/PortableServer/POA_Current_Impl.h"
23
+ #include "typecode.h"
24
+ #include "object.h"
25
+ #include "exception.h"
26
+ #include "orb.h"
27
+ #include "servant.h"
28
+
29
+ #if RPOA_NEED_DSI_FIX
30
+ # include "srvreq_fix.cpp"
31
+ #endif
32
+
33
+ #define RUBY_INVOKE_FUNC RUBY_ALLOC_FUNC
34
+
35
+ VALUE r2tao_cServant;
36
+ static VALUE r2tao_cDynamicImp;
37
+ static VALUE r2tao_cServerRequest;
38
+
39
+ static int r2tao_IN_ARG;
40
+ static int r2tao_INOUT_ARG;
41
+ static int r2tao_OUT_ARG;
42
+
43
+ static ID invoke_ID;
44
+ static ID primary_interface_ID;
45
+
46
+ static ID repo_Id;
47
+ static ID repo_Ids;
48
+ static ID get_operation_sig_ID;
49
+ static ID include_ID;
50
+
51
+ static ID interface_repository_id_ID;
52
+
53
+ static R2TAO_RBFuncall FN_narrow ("_narrow");
54
+
55
+ static VALUE ID_arg_list;
56
+ static VALUE ID_result_type;
57
+ static VALUE ID_exc_list;
58
+ static VALUE ID_op_sym;
59
+
60
+ static VALUE r2tao_Servant_default_POA(VALUE self);
61
+ static VALUE r2tao_Servant_this(VALUE self);
62
+
63
+ static VALUE r2tao_ServerRequest_operation(VALUE self);
64
+ static VALUE r2tao_ServerRequest_describe(VALUE self, VALUE desc);
65
+ static VALUE r2tao_ServerRequest_arguments(VALUE self);
66
+ static VALUE r2tao_ServerRequest_get(VALUE self, VALUE key);
67
+ static VALUE r2tao_ServerRequest_set(VALUE self, VALUE key, VALUE val);
68
+
69
+ static VALUE srv_alloc(VALUE klass);
70
+ static void srv_free(void* ptr);
71
+
72
+ void r2tao_init_Servant()
73
+ {
74
+ VALUE klass;
75
+
76
+ r2tao_cServant = klass = rb_eval_string("::R2CORBA::PortableServer::Servant");
77
+ rb_define_alloc_func (r2tao_cServant, RUBY_ALLOC_FUNC (srv_alloc));
78
+ rb_define_method(klass, "_default_POA", RUBY_METHOD_FUNC(r2tao_Servant_default_POA), 0);
79
+ rb_define_method(klass, "_this", RUBY_METHOD_FUNC(r2tao_Servant_this), 0);
80
+
81
+ r2tao_cServerRequest = klass = rb_define_class_under (r2tao_nsCORBA, "ServerRequest", rb_cObject);
82
+ rb_define_method(klass, "operation", RUBY_METHOD_FUNC(r2tao_ServerRequest_operation), 0);
83
+ rb_define_method(klass, "describe", RUBY_METHOD_FUNC(r2tao_ServerRequest_describe), 1);
84
+ rb_define_method(klass, "arguments", RUBY_METHOD_FUNC(r2tao_ServerRequest_arguments), 0);
85
+ rb_define_method(klass, "[]", RUBY_METHOD_FUNC(r2tao_ServerRequest_get), 1);
86
+ rb_define_method(klass, "[]=", RUBY_METHOD_FUNC(r2tao_ServerRequest_set), 2);
87
+
88
+ ID_arg_list = rb_eval_string (":arg_list");
89
+ ID_result_type = rb_eval_string (":result_type");
90
+ ID_exc_list = rb_eval_string (":exc_list");
91
+ ID_op_sym = rb_eval_string (":op_sym");
92
+
93
+ repo_Id = rb_intern ("Id");
94
+ repo_Ids = rb_intern ("Ids");
95
+ get_operation_sig_ID = rb_intern("get_operation_signature");
96
+ include_ID = rb_intern ("include?");
97
+
98
+ interface_repository_id_ID = rb_intern ("_interface_repository_id");
99
+
100
+ r2tao_cDynamicImp = klass = rb_eval_string("::R2CORBA::PortableServer::DynamicImplementation");
101
+
102
+ invoke_ID = rb_intern ("invoke");
103
+ primary_interface_ID = rb_intern ("_primary_interface");
104
+
105
+ r2tao_IN_ARG = NUM2INT (rb_eval_string ("R2CORBA::CORBA::ARG_IN"));
106
+ r2tao_INOUT_ARG = NUM2INT (rb_eval_string ("R2CORBA::CORBA::ARG_INOUT"));
107
+ r2tao_OUT_ARG = NUM2INT (rb_eval_string ("R2CORBA::CORBA::ARG_OUT"));
108
+ }
109
+
110
+ //-------------------------------------------------------------------
111
+ // R2TAO CORBA ServerRequest native data structure
112
+ //
113
+ //===================================================================
114
+
115
+ struct DSI_Data {
116
+ R2CORBA_ServerRequest_ptr _request;
117
+ CORBA::NVList_ptr _nvlist;
118
+ CORBA::TypeCode_var _result_type;
119
+ VALUE _rData;
120
+
121
+ DSI_Data(R2CORBA_ServerRequest_ptr _req)
122
+ : _request(_req), _nvlist(0), _rData(Qnil) {}
123
+ ~DSI_Data() {
124
+ if (this->_rData!=Qnil) { DATA_PTR(this->_rData) = 0; }
125
+ }
126
+ };
127
+
128
+ //-------------------------------------------------------------------
129
+ // R2TAO CORBA ServerRequest methods
130
+ //
131
+ //===================================================================
132
+
133
+ VALUE r2tao_ServerRequest_operation(VALUE self)
134
+ {
135
+ if (DATA_PTR (self) != 0)
136
+ {
137
+ R2CORBA_ServerRequest_ptr request = static_cast<DSI_Data*> (DATA_PTR (self))->_request;
138
+ return rb_str_new2 (request->operation ());
139
+ }
140
+ return Qnil;
141
+ }
142
+
143
+ VALUE r2tao_ServerRequest_describe(VALUE self, VALUE desc)
144
+ {
145
+ if (DATA_PTR (self) != 0)
146
+ {
147
+ DSI_Data* dsi_data = static_cast<DSI_Data*> (DATA_PTR (self));
148
+
149
+ // only allowed once
150
+ if (CORBA::NVList::_nil () != dsi_data->_nvlist)
151
+ {
152
+ X_CORBA (BAD_INV_ORDER);
153
+ }
154
+
155
+ R2CORBA_ServerRequest_ptr request = dsi_data->_request;
156
+
157
+ if (desc != Qnil && rb_type (desc) == T_HASH)
158
+ {
159
+ // check desc and create argument list for ORB
160
+ VALUE arg_list = rb_hash_aref (desc, ID_arg_list);
161
+ if (arg_list != Qnil && rb_type (arg_list) != T_ARRAY)
162
+ {
163
+ X_CORBA(BAD_PARAM);
164
+ }
165
+ VALUE result_type = rb_hash_aref (desc, ID_result_type);
166
+ if (result_type != Qnil && rb_obj_is_kind_of(result_type, r2corba_cTypeCode) != Qtrue)
167
+ {
168
+ X_CORBA(BAD_PARAM);
169
+ }
170
+
171
+ CORBA::ORB_ptr _orb = request->_tao_server_request ().orb ();
172
+
173
+ R2TAO_TRY
174
+ {
175
+ _orb->create_list (0, dsi_data->_nvlist);
176
+ }
177
+ R2TAO_CATCH;
178
+
179
+ long arg_len =
180
+ arg_list == Qnil ? 0 : RARRAY_LEN (arg_list);
181
+ for (long arg=0; arg<arg_len ;++arg)
182
+ {
183
+ VALUE argspec = rb_ary_entry (arg_list, arg);
184
+ if (argspec != Qnil && rb_type (argspec) != T_ARRAY)
185
+ {
186
+ X_CORBA(BAD_PARAM);
187
+ }
188
+ VALUE argname = rb_ary_entry (argspec, 0);
189
+ if (argname != Qnil && rb_obj_is_kind_of(argname, rb_cString)==Qfalse)
190
+ {
191
+ X_CORBA(BAD_PARAM);
192
+ }
193
+ char *_arg_name = argname != Qnil ? RSTRING_PTR (argname) : 0;
194
+ int _arg_type = NUM2INT (rb_ary_entry (argspec, 1));
195
+ VALUE arg_rtc = rb_ary_entry (argspec, 2);
196
+ if (rb_obj_is_kind_of(arg_rtc, r2corba_cTypeCode)==Qfalse)
197
+ {
198
+ X_CORBA(BAD_PARAM);
199
+ }
200
+ R2TAO_TRY
201
+ {
202
+ CORBA::TypeCode_ptr _arg_tc = r2corba_TypeCode_r2t (arg_rtc);
203
+
204
+ CORBA::NamedValue_ptr _nv = _arg_name ?
205
+ dsi_data->_nvlist->add_item (_arg_name, _arg_type == r2tao_IN_ARG ?
206
+ CORBA::ARG_IN :
207
+ (_arg_type == r2tao_INOUT_ARG ?
208
+ CORBA::ARG_INOUT : CORBA::ARG_OUT))
209
+ :
210
+ dsi_data->_nvlist->add (_arg_type == r2tao_IN_ARG ?
211
+ CORBA::ARG_IN :
212
+ (_arg_type == r2tao_INOUT_ARG ?
213
+ CORBA::ARG_INOUT : CORBA::ARG_OUT));
214
+ // assign type info to Any
215
+ _nv->value ()->_tao_set_typecode (_arg_tc);
216
+ }
217
+ R2TAO_CATCH;
218
+ }
219
+
220
+ R2TAO_TRY
221
+ {
222
+ // set ORB arguments (retrieves data for IN/INOUT args)
223
+ request->arguments (dsi_data->_nvlist);
224
+
225
+ // register result type (if any)
226
+ if (result_type != Qnil)
227
+ {
228
+ dsi_data->_result_type =
229
+ CORBA::TypeCode::_duplicate(r2corba_TypeCode_r2t (result_type));
230
+ }
231
+ }
232
+ R2TAO_CATCH;
233
+ }
234
+ else
235
+ {
236
+ X_CORBA(BAD_PARAM);
237
+ }
238
+ }
239
+ return Qnil;
240
+ }
241
+
242
+ VALUE r2tao_ServerRequest_arguments(VALUE self)
243
+ {
244
+ if (DATA_PTR (self) != 0)
245
+ {
246
+ DSI_Data* dsi_data = static_cast<DSI_Data*> (DATA_PTR (self));
247
+ if (CORBA::NVList::_nil () == dsi_data->_nvlist)
248
+ {
249
+ X_CORBA (BAD_INV_ORDER);
250
+ }
251
+
252
+ R2TAO_TRY
253
+ {
254
+ // build argument list for servant implementation
255
+ CORBA::ULong arg_len = dsi_data->_nvlist->count ();
256
+ VALUE rargs = rb_ary_new ();
257
+ for (CORBA::ULong arg=0; arg<arg_len ;++arg)
258
+ {
259
+ CORBA::NamedValue_ptr _nv = dsi_data->_nvlist->item (arg);
260
+ if (ACE_BIT_DISABLED (_nv->flags (), CORBA::ARG_OUT))
261
+ {
262
+ CORBA::TypeCode_var _arg_tc = _nv->value ()->type ();
263
+ VALUE rval = r2tao_Any2Ruby(*_nv->value (), _arg_tc.in (), Qnil, Qnil);
264
+ rb_ary_push (rargs, rval);
265
+ }
266
+ }
267
+ return rargs;
268
+ }
269
+ R2TAO_CATCH;
270
+ }
271
+ return Qnil;
272
+ }
273
+
274
+ VALUE r2tao_ServerRequest_get(VALUE self, VALUE key)
275
+ {
276
+ if (DATA_PTR (self) != 0)
277
+ {
278
+ DSI_Data* dsi_data = static_cast<DSI_Data*> (DATA_PTR (self));
279
+ if (CORBA::NVList::_nil () == dsi_data->_nvlist)
280
+ {
281
+ X_CORBA (BAD_INV_ORDER);
282
+ }
283
+
284
+ if (key == Qnil)
285
+ {
286
+ X_CORBA (BAD_PARAM);
287
+ }
288
+
289
+ if (rb_obj_is_kind_of (key, rb_cString) == Qtrue)
290
+ {
291
+ char* arg_name = RSTRING_PTR (key);
292
+ CORBA::ULong arg_num = dsi_data->_nvlist->count ();
293
+ for (CORBA::ULong ix=0; ix<arg_num ;++ix)
294
+ {
295
+ CORBA::NamedValue_ptr _nv = dsi_data->_nvlist->item (ix);
296
+ if (_nv->name () && ACE_OS::strcmp (arg_name, _nv->name ()) == 0)
297
+ {
298
+ R2TAO_TRY
299
+ {
300
+ CORBA::TypeCode_var _arg_tc = _nv->value ()->type ();
301
+ return r2tao_Any2Ruby(*_nv->value (), _arg_tc.in (), Qnil, Qnil);
302
+ }
303
+ R2TAO_CATCH;
304
+ }
305
+ }
306
+
307
+ X_CORBA (BAD_PARAM);
308
+ }
309
+ else
310
+ {
311
+ CORBA::ULong ix = NUM2ULONG (key);
312
+ if (dsi_data->_nvlist->count () <= ix)
313
+ {
314
+ X_CORBA (BAD_PARAM);
315
+ }
316
+ R2TAO_TRY
317
+ {
318
+ CORBA::NamedValue_ptr _nv = dsi_data->_nvlist->item (ix);
319
+ CORBA::TypeCode_var _arg_tc = _nv->value ()->type ();
320
+ return r2tao_Any2Ruby(*_nv->value (), _arg_tc.in (), Qnil, Qnil);
321
+ }
322
+ R2TAO_CATCH;
323
+ }
324
+ }
325
+ return Qnil;
326
+ }
327
+
328
+ VALUE r2tao_ServerRequest_set(VALUE self, VALUE key, VALUE val)
329
+ {
330
+ if (DATA_PTR (self) != 0)
331
+ {
332
+ DSI_Data* dsi_data = static_cast<DSI_Data*> (DATA_PTR (self));
333
+ if (CORBA::NVList::_nil () == dsi_data->_nvlist)
334
+ {
335
+ X_CORBA (BAD_INV_ORDER);
336
+ }
337
+
338
+ if (key == Qnil)
339
+ {
340
+ X_CORBA (BAD_PARAM);
341
+ }
342
+
343
+ if (rb_obj_is_kind_of (key, rb_cString) == Qtrue)
344
+ {
345
+ char* arg_name = RSTRING_PTR (key);
346
+ CORBA::ULong arg_num = dsi_data->_nvlist->count ();
347
+ for (CORBA::ULong ix=0; ix<arg_num ;++ix)
348
+ {
349
+ CORBA::NamedValue_ptr _nv = dsi_data->_nvlist->item (ix);
350
+ if (_nv->name () && ACE_OS::strcmp (arg_name, _nv->name ()) == 0)
351
+ {
352
+ R2TAO_TRY
353
+ {
354
+ CORBA::TypeCode_var _arg_tc = _nv->value ()->type ();
355
+ r2tao_Ruby2Any(*_nv->value (), _arg_tc.in (), val);
356
+ return Qtrue;
357
+ }
358
+ R2TAO_CATCH;
359
+ }
360
+ }
361
+
362
+ X_CORBA (BAD_PARAM);
363
+ }
364
+ else
365
+ {
366
+ CORBA::ULong ix = NUM2ULONG (key);
367
+ if (dsi_data->_nvlist->count () <= ix)
368
+ {
369
+ X_CORBA (BAD_PARAM);
370
+ }
371
+ R2TAO_TRY
372
+ {
373
+ CORBA::NamedValue_ptr _nv = dsi_data->_nvlist->item (ix);
374
+ CORBA::TypeCode_var _arg_tc = _nv->value ()->type ();
375
+ r2tao_Ruby2Any(*_nv->value (), _arg_tc.in (), val);
376
+ return Qtrue;
377
+ }
378
+ R2TAO_CATCH;
379
+ }
380
+ }
381
+ return Qnil;
382
+ }
383
+
384
+ //-------------------------------------------------------------------
385
+ // R2TAO Servant class
386
+ //
387
+ //===================================================================
388
+
389
+ DSI_Servant::DSI_Servant(VALUE rbServant)
390
+ : rbServant_ (rbServant)
391
+ {
392
+ if (TAO_debug_level > 9)
393
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::ctor(%@) - rbsrv=%@\n", this, this->rbServant_));
394
+
395
+ this->register_with_servant();
396
+ }
397
+
398
+ DSI_Servant::~DSI_Servant()
399
+ {
400
+ if (TAO_debug_level > 9)
401
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::dtor(%@) - rbsrv=%@\n", this, this->rbServant_));
402
+
403
+ this->cleanup_servant ();
404
+ }
405
+
406
+ void DSI_Servant::register_with_servant ()
407
+ {
408
+ // register with Ruby servant (refcount == 1)
409
+ DATA_PTR(this->rbServant_) = this;
410
+ }
411
+
412
+ void DSI_Servant::cleanup_servant ()
413
+ {
414
+ r2tao_call_thread_safe (DSI_Servant::thread_safe_cleanup, this);
415
+ }
416
+
417
+ void DSI_Servant::inner_cleanup_servant ()
418
+ {
419
+ // we're being destroyed so unlink us from the Ruby servant (if any)
420
+ if (!NIL_P (this->rbServant_))
421
+ {
422
+ // clear our registration with the Ruby servant
423
+ DATA_PTR(this->rbServant_) = 0;
424
+
425
+ // unregister the Ruby servant so it can be GC-ed
426
+ r2tao_unregister_object (this->rbServant_);
427
+ }
428
+ }
429
+
430
+ // invocation helper for threadsafe calling of Ruby code
431
+ void* DSI_Servant::thread_safe_cleanup (void * arg)
432
+ {
433
+ DSI_Servant* svt = reinterpret_cast<DSI_Servant*> (arg);
434
+
435
+ try {
436
+ svt->inner_cleanup_servant ();
437
+ }
438
+ catch (...) {
439
+ return ::CORBA::UNKNOWN (0, CORBA::COMPLETED_MAYBE)._tao_duplicate ();
440
+ }
441
+ return 0;
442
+ }
443
+
444
+ void DSI_Servant::free_servant ()
445
+ {
446
+ if (TAO_debug_level > 9)
447
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::free_servant(%@) - rbsrv=%@\n", this, this->rbServant_));
448
+
449
+ // the Ruby servant is freed (GC-ed) so unlink and decrease refcount
450
+ // NOTE: only called if we were still registered with the Ruby servant
451
+ // at the time of GC
452
+ this->rbServant_ = Qnil;
453
+ this->_remove_ref (); // might trigger destructor
454
+ }
455
+
456
+ void DSI_Servant::activate_servant ()
457
+ {
458
+ // we've been activated
459
+ if (TAO_debug_level > 9)
460
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::activate_servant(%@) - rbsrv=%@\n", this, this->rbServant_));
461
+
462
+ // register the Ruby servant so it can't be GC-ed while we're alive
463
+ r2tao_register_object (this->rbServant_);
464
+
465
+ // ownership is transferred to a poa (raises refcount) so we can release
466
+ // the refcount the Ruby servant is holding on us
467
+ this->_remove_ref ();
468
+
469
+ // since the Ruby servant is protected against GC the only way the
470
+ // Ruby servant will be released is after we get deactivated
471
+ // (& subsequently destructed) at which time we detach from the
472
+ // Ruby servant before it can get GC-ed
473
+ }
474
+
475
+ // invocation helper for rb_protect()
476
+ VALUE DSI_Servant::_invoke_implementation(VALUE args)
477
+ {
478
+ VALUE servant = rb_ary_entry (args, 0);
479
+ VALUE operation = rb_ary_entry (args, 1);
480
+ VALUE opargs = rb_ary_entry (args, 2);
481
+ return rb_apply (servant, SYM2ID (operation), opargs);
482
+ }
483
+
484
+ DSI_Servant::METHOD DSI_Servant::method_id (const char* method)
485
+ {
486
+ if (ACE_OS::strcmp (method, "_is_a") == 0)
487
+ return IS_A;
488
+ else if (ACE_OS::strcmp (method, "_repository_id") == 0)
489
+ return REPOSITORY_ID;
490
+ else if (ACE_OS::strcmp (method, "_non_existent") == 0)
491
+ return NON_EXISTENT;
492
+ else if (ACE_OS::strcmp (method, "_component") == 0)
493
+ return GET_COMPONENT;
494
+ else if (ACE_OS::strcmp (method, "_interface") == 0)
495
+ return GET_INTERFACE;
496
+
497
+ return NONE;
498
+ }
499
+
500
+ #if RPOA_NEED_DSI_FIX
501
+ void DSI_Servant::invoke (CORBA::ServerRequest_ptr /*request*/)
502
+ {}
503
+
504
+ void DSI_Servant::_dispatch (TAO_ServerRequest &request,
505
+ void * /*context*/)
506
+ {
507
+ // No need to do any of this if the client isn't waiting.
508
+ if (request.response_expected ())
509
+ {
510
+ if (request.is_forwarded ())
511
+ {
512
+ request.init_reply ();
513
+ request.tao_send_reply ();
514
+
515
+ // No need to invoke in this case.
516
+ return;
517
+ }
518
+ else if (request.sync_with_server ())
519
+ {
520
+ // The last line before the call to this function
521
+ // was an ACE_CHECK_RETURN, so if we're here, we
522
+ // know there is no exception so far, and that's all
523
+ // a SYNC_WITH_SERVER client request cares about.
524
+ request.send_no_exception_reply ();
525
+ }
526
+ }
527
+
528
+ // Create DSI request object.
529
+ R2CORBA::ServerRequest *dsi_request = 0;
530
+ ACE_NEW (dsi_request,
531
+ R2CORBA::ServerRequest (request));
532
+
533
+ try
534
+ {
535
+ // Delegate to user.
536
+ this->invoke_fix (dsi_request);
537
+
538
+ // Only if the client is waiting.
539
+ if (request.response_expected () && !request.sync_with_server ())
540
+ {
541
+ dsi_request->dsi_marshal ();
542
+ }
543
+ }
544
+ catch (::CORBA::Exception& ex)
545
+ {
546
+ // Only if the client is waiting.
547
+ if (request.response_expected () && !request.sync_with_server ())
548
+ {
549
+ if (request.collocated ()
550
+ && request.operation_details ()->cac () != 0)
551
+ {
552
+ // If we have a cac it will handle the exception and no
553
+ // need to do any further processing
554
+ request.operation_details ()->cac ()->handle_corba_exception (
555
+ request, &ex);
556
+ return;
557
+ }
558
+ else
559
+ request.tao_send_reply_exception (ex);
560
+ }
561
+ }
562
+
563
+ ::CORBA::release (dsi_request);
564
+ }
565
+ #endif
566
+
567
+ // invocation helper for threadsafe calling of Ruby code
568
+ void* DSI_Servant::thread_safe_invoke (void * arg)
569
+ {
570
+ ThreadSafeArg* tca = reinterpret_cast<ThreadSafeArg*> (arg);
571
+
572
+ try {
573
+ tca->servant_->inner_invoke (tca->request_);
574
+ }
575
+ catch (const CORBA::SystemException& ex) {
576
+ return ex._tao_duplicate ();
577
+ }
578
+ catch (...) {
579
+ return ::CORBA::UNKNOWN (0, CORBA::COMPLETED_MAYBE)._tao_duplicate ();
580
+ }
581
+ return 0;
582
+ }
583
+
584
+ # if RPOA_NEED_DSI_FIX
585
+ void DSI_Servant::invoke_fix (R2CORBA::ServerRequest_ptr request)
586
+ # else
587
+ void DSI_Servant::invoke (CORBA::ServerRequest_ptr request)
588
+ # endif
589
+ {
590
+ ThreadSafeArg tca_(this, request);
591
+
592
+ void* rc = r2tao_call_thread_safe (DSI_Servant::thread_safe_invoke, &tca_);
593
+ if (rc != 0)
594
+ {
595
+ CORBA::SystemException* exc = reinterpret_cast<CORBA::SystemException*> (rc);
596
+ ACE_Auto_Basic_Ptr<CORBA::SystemException> e_ptr(exc);
597
+ exc->_raise ();
598
+ }
599
+ }
600
+
601
+ void DSI_Servant::inner_invoke (R2CORBA_ServerRequest_ptr request)
602
+ {
603
+ if (TAO_debug_level > 7)
604
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke(%C)\n", request->operation ()));
605
+
606
+ // check if Ruby servant still attached
607
+ if (this->rbServant_ == Qnil)
608
+ {
609
+ // we're detached so nothing is implemented anymore
610
+ throw ::CORBA::NO_IMPLEMENT (0, CORBA::COMPLETED_NO);
611
+ }
612
+
613
+ METHOD mt = this->method_id(request->operation ());
614
+
615
+ CORBA::Boolean f;
616
+ if (mt == IS_A || mt == NON_EXISTENT)
617
+ {
618
+ CORBA::ORB_ptr _orb = request->_tao_server_request ().orb ();
619
+
620
+ CORBA::NVList_ptr nvlist;
621
+ _orb->create_list (0, nvlist);
622
+
623
+ if (mt == IS_A)
624
+ {
625
+ CORBA::NamedValue_ptr _nv = nvlist->add (CORBA::ARG_IN);
626
+ _nv->value ()->_tao_set_typecode (CORBA::_tc_string);
627
+
628
+ // set ORB arguments (retrieves data for IN/INOUT args)
629
+ request->arguments (nvlist);
630
+
631
+ const char *tmp = 0;
632
+ (*_nv->value ()) >>= tmp;
633
+
634
+ f = this->_is_a (tmp);
635
+
636
+ if (TAO_debug_level > 5)
637
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) _is_a (%s) -> %d\n", tmp, f));
638
+ }
639
+ else
640
+ {
641
+ // set ORB arguments (retrieves data for IN/INOUT args)
642
+ request->arguments (nvlist);
643
+
644
+ f = this->_non_existent ();
645
+
646
+ if (TAO_debug_level > 5)
647
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) _non_existent () -> %d\n", f));
648
+ }
649
+
650
+ CORBA::Any _any;
651
+ _any <<= CORBA::Any::from_boolean (f);
652
+ request->set_result(_any);
653
+ }
654
+ else if (mt == REPOSITORY_ID)
655
+ {
656
+ CORBA::ORB_ptr _orb = request->_tao_server_request ().orb ();
657
+
658
+ CORBA::NVList_ptr nvlist;
659
+ _orb->create_list (0, nvlist);
660
+ // set ORB arguments (retrieves data for IN/INOUT args)
661
+ request->arguments (nvlist);
662
+
663
+ CORBA::String_var repo_id = this->_repository_id ();
664
+
665
+ if (TAO_debug_level > 5)
666
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) _repository_id () -> %s\n", repo_id.in ()));
667
+
668
+ CORBA::Any _any;
669
+ _any <<= repo_id.in ();
670
+ request->set_result(_any);
671
+ }
672
+ else if (mt == GET_COMPONENT)
673
+ {
674
+ CORBA::ORB_ptr _orb = request->_tao_server_request ().orb ();
675
+
676
+ CORBA::NVList_ptr nvlist;
677
+ _orb->create_list (0, nvlist);
678
+ // set ORB arguments (retrieves data for IN/INOUT args)
679
+ request->arguments (nvlist);
680
+
681
+ CORBA::Object_var obj = this->_get_component ();
682
+
683
+ if (TAO_debug_level > 5)
684
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) _get_component () -> %@\n", obj.in ()));
685
+
686
+ CORBA::Any _any;
687
+ _any <<= obj.in ();
688
+ request->set_result(_any);
689
+ }
690
+ else if (mt == GET_INTERFACE)
691
+ {
692
+ throw ::CORBA::NO_IMPLEMENT (0, CORBA::COMPLETED_NO);
693
+ }
694
+ else
695
+ {
696
+ if (rb_obj_is_kind_of (this->rbServant_, r2tao_cDynamicImp))
697
+ this->invoke_DSI(request);
698
+ else
699
+ this->invoke_SI(request);
700
+ }
701
+ }
702
+
703
+ void DSI_Servant::invoke_DSI (R2CORBA_ServerRequest_ptr request)
704
+ {
705
+ if (TAO_debug_level > 5)
706
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_DSI(%C) entry\n", request->operation ()));
707
+
708
+ // wrap request for Ruby; cleanup automatically
709
+ ACE_Auto_Basic_Ptr<DSI_Data> dsi_data(new DSI_Data(request));
710
+
711
+ VALUE srvreq = Data_Wrap_Struct(r2tao_cServerRequest, 0, 0, dsi_data.get ());
712
+
713
+ dsi_data.get()->_rData = srvreq; // have DSI_Data clean up Ruby object at destruction time
714
+
715
+ // invoke servant implementation
716
+ VALUE rargs = rb_ary_new2 (1);
717
+ rb_ary_push (rargs, srvreq);
718
+ VALUE invoke_holder = rb_ary_new2 (3);
719
+ rb_ary_push (invoke_holder, this->rbServant_);
720
+ rb_ary_push (invoke_holder, ID2SYM (invoke_ID));
721
+ rb_ary_push (invoke_holder, rargs);
722
+ int invoke_state = 0;
723
+ VALUE ret = rb_protect (RUBY_INVOKE_FUNC (DSI_Servant::_invoke_implementation),
724
+ invoke_holder,
725
+ &invoke_state);
726
+
727
+ if (invoke_state)
728
+ {
729
+ // handle exception
730
+ VALUE rexc = rb_gv_get ("$!");
731
+ if (rb_obj_is_kind_of(rexc, r2tao_cUserException) == Qtrue)
732
+ {
733
+ VALUE rextc = rb_eval_string ("R2CORBA::CORBA::Any.typecode_for_any ($!)");
734
+ if (rextc != Qnil)
735
+ {
736
+ CORBA::Any _xval;
737
+ CORBA::TypeCode_ptr _xtc = r2corba_TypeCode_r2t (rextc);
738
+ r2tao_Ruby2Any(_xval, _xtc, rexc);
739
+ request->set_exception (_xval);
740
+
741
+ return;
742
+ }
743
+ }
744
+
745
+ if (rb_obj_is_kind_of(rexc, r2tao_cSystemException) == Qtrue)
746
+ {
747
+ VALUE rid = rb_funcall (rexc, interface_repository_id_ID, 0);
748
+ CORBA::SystemException* _exc = TAO::create_system_exception (RSTRING_PTR (rid));
749
+
750
+ _exc->minor (
751
+ static_cast<CORBA::ULong> (NUM2ULONG (rb_iv_get (rexc, "@minor"))));
752
+ _exc->completed (
753
+ static_cast<CORBA::CompletionStatus> (NUM2ULONG (rb_iv_get (rexc, "@completed"))));
754
+
755
+ ACE_Auto_Basic_Ptr<CORBA::SystemException> e_ptr(_exc);
756
+ _exc->_raise ();
757
+ }
758
+ else
759
+ {
760
+ rb_eval_string ("STDERR.puts $!.to_s+\"\\n\"+$!.backtrace.join(\"\\n\")");
761
+ throw ::CORBA::UNKNOWN (0, CORBA::COMPLETED_MAYBE);
762
+ }
763
+ }
764
+ else
765
+ {
766
+ // check for oneway (no results at all) or twoway
767
+ if (!CORBA::is_nil (dsi_data.get()->_result_type.in ()))
768
+ {
769
+ // twoway
770
+ if (TAO_debug_level > 5)
771
+ ACE_DEBUG ((LM_INFO, "(%P|%t) checking return values of twoway invocation\n"));
772
+
773
+ // handle OUT values
774
+ long arg_out = 0;
775
+ long ret_off =
776
+ (dsi_data.get()->_result_type->kind () != CORBA::tk_void) ? 1 : 0;
777
+ CORBA::ULong arg_len = dsi_data.get()->_nvlist->count ();
778
+ for (CORBA::ULong arg=0; arg<arg_len ;++arg)
779
+ {
780
+ if (TAO_debug_level > 7)
781
+ ACE_DEBUG ((LM_INFO, "(%P|%t) handling (IN)OUT arg %d\n", arg));
782
+
783
+ CORBA::NamedValue_ptr _nv = dsi_data.get()->_nvlist->item (arg);
784
+ if (ACE_BIT_DISABLED (_nv->flags (), CORBA::ARG_IN))
785
+ {
786
+ ++arg_out; // count number of (IN)OUT arguments
787
+
788
+ VALUE retval = Qnil;
789
+ if (rb_type (ret) == T_ARRAY && ret_off<RARRAY_LEN (ret))
790
+ {
791
+ retval = rb_ary_entry (ret, ret_off++);
792
+ }
793
+ CORBA::TypeCode_var _arg_tc = _nv->value ()->type ();
794
+ r2tao_Ruby2Any(*_nv->value (), _arg_tc.in (), retval);
795
+
796
+ if (TAO_debug_level > 7)
797
+ ACE_DEBUG ((LM_INFO, "(%P|%t) converted (IN)OUT arg %d\n", arg));
798
+ }
799
+ }
800
+
801
+ // handle return value
802
+ if (dsi_data.get()->_result_type->kind () != CORBA::tk_void)
803
+ {
804
+ if (TAO_debug_level > 7)
805
+ ACE_DEBUG ((LM_INFO, "(%P|%t) handling result value\n"));
806
+
807
+ CORBA::Any _retval;
808
+ VALUE retval = Qnil;
809
+ if (arg_out == 0)
810
+ {
811
+ retval = ret;
812
+ }
813
+ else if (rb_type (ret) == T_ARRAY && 0<RARRAY_LEN (ret))
814
+ {
815
+ retval = rb_ary_entry (ret, 0);
816
+ }
817
+ r2tao_Ruby2Any(_retval, dsi_data.get()->_result_type.in (), retval);
818
+
819
+ if (TAO_debug_level > 7)
820
+ ACE_DEBUG ((LM_INFO, "(%P|%t) converted result value\n"));
821
+
822
+ request->set_result (_retval);
823
+ }
824
+ }
825
+ }
826
+ }
827
+
828
+ void DSI_Servant::invoke_SI (R2CORBA_ServerRequest_ptr request)
829
+ {
830
+ if (TAO_debug_level > 5)
831
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) entry\n", request->operation ()));
832
+
833
+ // retrieve targeted operation
834
+ VALUE ropsym = ID2SYM (rb_intern (request->operation ()));
835
+ // retrieve operation signature
836
+ VALUE ropsig = rb_funcall (this->rbServant_, get_operation_sig_ID, 1, ropsym);
837
+
838
+ if (ropsig != Qnil && rb_type (ropsig) == T_HASH)
839
+ {
840
+ // check signature and create argument list for ORB
841
+ VALUE arg_list = rb_hash_aref (ropsig, ID_arg_list);
842
+ if (arg_list != Qnil && rb_type (arg_list) != T_ARRAY)
843
+ {
844
+ throw ::CORBA::BAD_PARAM (0, CORBA::COMPLETED_NO);
845
+ }
846
+ VALUE result_type = rb_hash_aref (ropsig, ID_result_type);
847
+ if (result_type != Qnil && rb_obj_is_kind_of(result_type, r2corba_cTypeCode) != Qtrue)
848
+ {
849
+ throw ::CORBA::BAD_PARAM (0, CORBA::COMPLETED_NO);
850
+ }
851
+ VALUE exc_list = rb_hash_aref (ropsig, ID_exc_list);
852
+ if (exc_list != Qnil && rb_type (exc_list) != T_ARRAY)
853
+ {
854
+ throw ::CORBA::BAD_PARAM (0, CORBA::COMPLETED_NO);
855
+ }
856
+ VALUE alt_op_sym = rb_hash_aref (ropsig, ID_op_sym);
857
+ if (alt_op_sym != Qnil && rb_type (alt_op_sym) == T_SYMBOL)
858
+ {
859
+ ropsym = alt_op_sym;
860
+ }
861
+
862
+ CORBA::ORB_ptr _orb = request->_tao_server_request ().orb ();
863
+
864
+ CORBA::NVList_ptr nvlist;
865
+ _orb->create_list (0, nvlist);
866
+
867
+ long arg_len =
868
+ arg_list == Qnil ? 0 : RARRAY_LEN (arg_list);
869
+ for (long arg=0; arg<arg_len ;++arg)
870
+ {
871
+ VALUE argspec = rb_ary_entry (arg_list, arg);
872
+ if (argspec != Qnil && rb_type (argspec) != T_ARRAY)
873
+ {
874
+ throw ::CORBA::BAD_PARAM (0, CORBA::COMPLETED_NO);
875
+ }
876
+ char *_arg_name = RSTRING_PTR (rb_ary_entry (argspec, 0));
877
+ int _arg_type = NUM2INT (rb_ary_entry (argspec, 1));
878
+ VALUE argtc = rb_ary_entry (argspec, 2);
879
+ if (argtc != Qnil && rb_obj_is_kind_of(argtc, r2corba_cTypeCode) != Qtrue)
880
+ {
881
+ throw ::CORBA::BAD_PARAM (0, CORBA::COMPLETED_NO);
882
+ }
883
+ CORBA::TypeCode_ptr _arg_tc = r2corba_TypeCode_r2t (argtc);
884
+
885
+ if (TAO_debug_level > 6)
886
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) arg #%d : kind=%d, type=%d\n",
887
+ request->operation (),
888
+ arg,
889
+ _arg_tc->kind(),
890
+ _arg_type));
891
+
892
+ CORBA::NamedValue_ptr _nv = nvlist->add_item (_arg_name, _arg_type == r2tao_IN_ARG ?
893
+ CORBA::ARG_IN :
894
+ (_arg_type == r2tao_INOUT_ARG ?
895
+ CORBA::ARG_INOUT : CORBA::ARG_OUT));
896
+ // assign type info to Any
897
+ r2tao_Ruby2Any (*_nv->value (), _arg_tc, Qnil);
898
+ }
899
+
900
+ if (TAO_debug_level > 6)
901
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) retrieve request args\n", request->operation ()));
902
+
903
+ // set ORB arguments (retrieves data for IN/INOUT args)
904
+ request->arguments (nvlist);
905
+
906
+ if (TAO_debug_level > 6)
907
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) convert request args\n", request->operation ()));
908
+
909
+ // build argument list for servant implementation
910
+ VALUE rargs = rb_ary_new ();
911
+ for (long arg=0; arg<arg_len ;++arg)
912
+ {
913
+ CORBA::NamedValue_ptr _nv = nvlist->item (static_cast<CORBA::ULong> (arg));
914
+ if (ACE_BIT_DISABLED (_nv->flags (), CORBA::ARG_OUT))
915
+ {
916
+ VALUE argspec = rb_ary_entry (arg_list, arg);
917
+ VALUE argtc = rb_ary_entry (argspec, 2);
918
+ CORBA::TypeCode_ptr _arg_tc = r2corba_TypeCode_r2t (argtc);
919
+ VALUE rval = r2tao_Any2Ruby(*_nv->value (), _arg_tc, Qnil, Qnil);
920
+ rb_ary_push (rargs, rval);
921
+ }
922
+ }
923
+
924
+ if (TAO_debug_level > 6)
925
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) invoke implementation\n", request->operation ()));
926
+
927
+ // invoke servant implementation
928
+ VALUE invoke_holder = rb_ary_new2 (4);
929
+ rb_ary_push (invoke_holder, this->rbServant_);
930
+ rb_ary_push (invoke_holder, ropsym);
931
+ rb_ary_push (invoke_holder, rargs);
932
+ int invoke_state = 0;
933
+ VALUE ret = rb_protect (RUBY_INVOKE_FUNC (DSI_Servant::_invoke_implementation),
934
+ invoke_holder,
935
+ &invoke_state);
936
+ if (invoke_state)
937
+ {
938
+ if (TAO_debug_level > 5)
939
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) exception from invocation\n", request->operation ()));
940
+
941
+ // handle exception
942
+ VALUE rexc = rb_gv_get ("$!");
943
+ if (rb_obj_is_kind_of(rexc, r2tao_cUserException) == Qtrue)
944
+ {
945
+ if (TAO_debug_level > 6)
946
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) detected user exception\n",
947
+ request->operation ()));
948
+
949
+ if (exc_list != Qnil)
950
+ {
951
+ long exc_len = RARRAY_LEN (exc_list);
952
+ for (long x=0; x<exc_len ;++x)
953
+ {
954
+ VALUE exctc = rb_ary_entry (exc_list, x);
955
+ VALUE exklass = rb_funcall (exctc, rb_intern ("get_type"), 0);
956
+ if (rb_obj_is_kind_of(rexc, exklass) == Qtrue)
957
+ {
958
+ CORBA::Any _xval;
959
+ CORBA::TypeCode_ptr _xtc = r2corba_TypeCode_r2t (exctc);
960
+
961
+ if (TAO_debug_level > 9)
962
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) returning user exception %C\n",
963
+ request->operation (), _xtc->id ()));
964
+
965
+ r2tao_Ruby2Any(_xval, _xtc, rexc);
966
+ request->set_exception (_xval);
967
+
968
+ return;
969
+ }
970
+ }
971
+ }
972
+ }
973
+
974
+ if (rb_obj_is_kind_of(rexc, r2tao_cSystemException) == Qtrue)
975
+ {
976
+ VALUE rid = rb_funcall (rexc, interface_repository_id_ID, 0);
977
+ CORBA::SystemException* _exc = TAO::create_system_exception (RSTRING_PTR (rid));
978
+
979
+ if (TAO_debug_level > 9)
980
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) returning system exception %C\n",
981
+ request->operation (), RSTRING_PTR (rid)));
982
+
983
+ _exc->minor (
984
+ static_cast<CORBA::ULong> (NUM2ULONG (rb_iv_get (rexc, "@minor"))));
985
+ _exc->completed (
986
+ static_cast<CORBA::CompletionStatus> (NUM2ULONG (rb_iv_get (rexc, "@completed"))));
987
+
988
+ ACE_Auto_Basic_Ptr<CORBA::SystemException> e_ptr(_exc);
989
+ _exc->_raise ();
990
+ }
991
+ else
992
+ {
993
+ rb_eval_string ("STDERR.puts $!.to_s+\"\\n\"+$!.backtrace.join(\"\\n\")");
994
+ throw ::CORBA::UNKNOWN (0, CORBA::COMPLETED_MAYBE);
995
+ }
996
+ }
997
+ else
998
+ {
999
+ if (TAO_debug_level > 5)
1000
+ ACE_DEBUG ((LM_INFO, "R2TAO (%P|%t) - Servant::invoke_SI(%C) handle invocation result\n", request->operation ()));
1001
+
1002
+ // check for oneway (no results at all) or twoway
1003
+ if (result_type != Qnil)
1004
+ {
1005
+ if (TAO_debug_level > 6)
1006
+ ACE_DEBUG ((LM_INFO, "(%P|%t) Servant::invoke_SI(%C) checking return values of twoway invocation\n",
1007
+ request->operation ()));
1008
+
1009
+ // twoway
1010
+ CORBA::TypeCode_ptr _result_tc = r2corba_TypeCode_r2t (result_type);
1011
+
1012
+ // handle OUT values
1013
+ long ret_off =
1014
+ (_result_tc->kind () != CORBA::tk_void) ? 1 : 0;
1015
+ long arg_out = 0;
1016
+ for (long arg=0; arg<arg_len ;++arg)
1017
+ {
1018
+ if (TAO_debug_level > 9)
1019
+ ACE_DEBUG ((LM_INFO, "(%P|%t) Servant::invoke_SI(%C) handling (IN)OUT arg %d\n", request->operation (), arg));
1020
+
1021
+ CORBA::NamedValue_ptr _nv = nvlist->item (static_cast<CORBA::ULong> (arg));
1022
+ if (ACE_BIT_DISABLED (_nv->flags (), CORBA::ARG_IN))
1023
+ {
1024
+ ++arg_out; // count number of (IN)OUT arguments
1025
+
1026
+ VALUE retval = Qnil;
1027
+ if (rb_type (ret) == T_ARRAY && ret_off<RARRAY_LEN (ret))
1028
+ {
1029
+ retval = rb_ary_entry (ret, ret_off++);
1030
+ }
1031
+ VALUE argspec = rb_ary_entry (arg_list, arg);
1032
+ VALUE rtc = rb_ary_entry (argspec, 2);
1033
+ CORBA::TypeCode_ptr _arg_tc = r2corba_TypeCode_r2t (rtc);
1034
+
1035
+ //rb_funcall (rb_eval_string ("STDERR"), rb_intern ("puts"),
1036
+ // 1, rb_funcall (retval, rb_intern ("inspect"), 0));
1037
+
1038
+ r2tao_Ruby2Any(*_nv->value (), _arg_tc, retval);
1039
+
1040
+ if (TAO_debug_level > 9)
1041
+ ACE_DEBUG ((LM_INFO, "(%P|%t) Servant::invoke_SI(%C) converted (IN)OUT arg %d\n", request->operation (), arg));
1042
+ }
1043
+ }
1044
+
1045
+ // handle return value
1046
+ if (_result_tc->kind () != CORBA::tk_void)
1047
+ {
1048
+ if (TAO_debug_level > 9)
1049
+ ACE_DEBUG ((LM_INFO, "(%P|%t) Servant::invoke_SI(%C) handling result value\n", request->operation ()));
1050
+
1051
+ CORBA::Any _retval;
1052
+ VALUE retval = Qnil;
1053
+ if (arg_out == 0)
1054
+ {
1055
+ retval = ret;
1056
+ }
1057
+ else if (rb_type (ret) == T_ARRAY && 0<RARRAY_LEN (ret))
1058
+ {
1059
+ retval = rb_ary_entry (ret, 0);
1060
+ }
1061
+ r2tao_Ruby2Any(_retval, _result_tc, retval);
1062
+
1063
+ if (TAO_debug_level > 9)
1064
+ ACE_DEBUG ((LM_INFO, "(%P|%t) Servant::invoke_SI(%C) converted result value\n", request->operation ()));
1065
+
1066
+ request->set_result (_retval);
1067
+ }
1068
+ }
1069
+ }
1070
+ }
1071
+ else
1072
+ {
1073
+ throw ::CORBA::NO_IMPLEMENT (0, CORBA::COMPLETED_NO);
1074
+ }
1075
+ }
1076
+
1077
+ CORBA::Boolean DSI_Servant::_is_a (const char *logical_type_id)
1078
+ {
1079
+ static R2TAO_RBFuncall FN_is_a ("_is_a?");
1080
+
1081
+ // provide support for multiple interfaces
1082
+ if (rb_respond_to (this->rbServant_, FN_is_a.id ()) != 0)
1083
+ {
1084
+ // call overloaded #_is_a? method in servant implementation
1085
+ VALUE repo_id = rb_str_new2 (logical_type_id ? logical_type_id : "");
1086
+ return (Qtrue == FN_is_a.invoke (this->rbServant_, 1 , &repo_id));
1087
+ }
1088
+ else if (rb_const_defined (rb_class_of (this->rbServant_), repo_Ids) == Qtrue)
1089
+ {
1090
+ // check if requested interface included in servants Ids array
1091
+ return (Qtrue == rb_funcall (rb_const_get (rb_class_of (this->rbServant_), repo_Ids),
1092
+ include_ID, 1, rb_str_new2 (logical_type_id ? logical_type_id : "")));
1093
+ }
1094
+ else
1095
+ {
1096
+ return PortableServer::DynamicImplementation::_is_a (logical_type_id);
1097
+ }
1098
+ }
1099
+
1100
+ CORBA::Boolean DSI_Servant::_non_existent (void)
1101
+ {
1102
+ static R2TAO_RBFuncall FN_non_existent ("_non_existent?");
1103
+
1104
+ // provide support for multiple interfaces
1105
+ if (rb_respond_to (this->rbServant_, FN_non_existent.id ()) != 0)
1106
+ {
1107
+ // call overloaded #_non_existent? method in servant implementation
1108
+ return (Qtrue == FN_non_existent.invoke (this->rbServant_));
1109
+ }
1110
+ else
1111
+ {
1112
+ return PortableServer::DynamicImplementation::_non_existent ();
1113
+ }
1114
+ }
1115
+
1116
+ CORBA::Object_ptr DSI_Servant::_get_component (void)
1117
+ {
1118
+ static R2TAO_RBFuncall FN_get_component ("_get_component");
1119
+
1120
+ // provide support for multiple interfaces
1121
+ if (rb_respond_to (this->rbServant_, FN_get_component.id ()) != 0)
1122
+ {
1123
+ // call overloaded #_get_component method in servant implementation
1124
+ VALUE robj = FN_get_component.invoke (this->rbServant_);
1125
+ CORBA::Object_ptr obj = NIL_P(robj) ? CORBA::Object::_nil () : r2corba_Object_r2t (robj);
1126
+ return CORBA::Object::_duplicate (obj);
1127
+ }
1128
+ else
1129
+ {
1130
+ return PortableServer::DynamicImplementation::_get_component ();
1131
+ }
1132
+ }
1133
+
1134
+ const char *DSI_Servant::_interface_repository_id (void) const
1135
+ {
1136
+ static R2TAO_RBFuncall FN_repository_id ("_repository_id");
1137
+
1138
+ // check if Ruby servant still attached
1139
+ if (this->rbServant_ == Qnil)
1140
+ {
1141
+ return "";
1142
+ }
1143
+
1144
+ DSI_Servant* servant_ = const_cast<DSI_Servant*> (this);
1145
+
1146
+ // provide support for multiple interfaces
1147
+ if (rb_respond_to (servant_->rbServant_, FN_repository_id.id ()) != 0)
1148
+ {
1149
+ // call overloaded #_repository_id method in servant implementation
1150
+ VALUE repo_id = FN_repository_id.invoke (servant_->rbServant_);
1151
+ if (repo_id==Qnil || rb_obj_is_kind_of(repo_id, rb_cString)==Qfalse)
1152
+ {
1153
+ if (TAO_debug_level > 3)
1154
+ ACE_DEBUG ((LM_WARNING, "(%P|%t) Servant::_interface_repository_id - cannot retrieve repo-id\n"));
1155
+ return "";
1156
+ }
1157
+ else
1158
+ {
1159
+ return RSTRING_PTR (repo_id);
1160
+ }
1161
+ }
1162
+ else
1163
+ {
1164
+ if (servant_->repo_id_.in () == 0)
1165
+ {
1166
+ if (rb_const_defined (rb_class_of (servant_->rbServant_), repo_Id) == Qtrue)
1167
+ {
1168
+ VALUE rb_repo_id = rb_const_get (rb_class_of (servant_->rbServant_), repo_Id);
1169
+ servant_->repo_id_ = CORBA::string_dup (RSTRING_PTR (rb_repo_id));
1170
+ }
1171
+ else
1172
+ {
1173
+ if (TAO_debug_level > 3)
1174
+ ACE_DEBUG ((LM_WARNING, "(%P|%t) Servant::_interface_repository_id - cannot retrieve repo-id\n"));
1175
+ servant_->repo_id_ = CORBA::string_dup ("");
1176
+ }
1177
+ }
1178
+ return servant_->repo_id_.in ();
1179
+ }
1180
+ }
1181
+
1182
+ char * DSI_Servant::_repository_id (void)
1183
+ {
1184
+ return CORBA::string_dup (this->_interface_repository_id ());
1185
+ }
1186
+
1187
+ CORBA::RepositoryId DSI_Servant::_primary_interface (
1188
+ const PortableServer::ObjectId & oid,
1189
+ PortableServer::POA_ptr poa)
1190
+ {
1191
+ // check if Ruby servant still attached
1192
+ if (this->rbServant_ == Qnil)
1193
+ {
1194
+ return CORBA::string_dup ("");
1195
+ }
1196
+
1197
+ if (rb_obj_is_kind_of (this->rbServant_, r2tao_cDynamicImp))
1198
+ {
1199
+ // invoke servant implementation
1200
+ VALUE rargs = rb_ary_new2 (1);
1201
+ rb_ary_push (rargs, r2tao_ObjectId_t2r (oid));
1202
+ VALUE rpoa = r2corba_Object_t2r(dynamic_cast<CORBA::Object_ptr> (poa));
1203
+ rpoa = FN_narrow.invoke (r2tao_nsPOA, 1, &rpoa);
1204
+ rb_ary_push (rargs, rpoa);
1205
+ VALUE invoke_holder = rb_ary_new2 (3);
1206
+ rb_ary_push (invoke_holder, this->rbServant_);
1207
+ rb_ary_push (invoke_holder, ID2SYM (primary_interface_ID));
1208
+ rb_ary_push (invoke_holder, rargs);
1209
+ int invoke_state = 0;
1210
+ VALUE ret = rb_protect (RUBY_INVOKE_FUNC (DSI_Servant::_invoke_implementation),
1211
+ invoke_holder,
1212
+ &invoke_state);
1213
+ if (invoke_state || ret==Qnil || rb_obj_is_kind_of(ret, rb_cString)==Qfalse)
1214
+ {
1215
+ ACE_ERROR ((LM_ERROR, "(%P|%t) FAILED TO RETRIEVE REPO-ID FOR SERVANT!\n"));
1216
+ return CORBA::string_dup ("");
1217
+ }
1218
+ else
1219
+ {
1220
+ return CORBA::string_dup (RSTRING_PTR (ret));
1221
+ }
1222
+ }
1223
+ else
1224
+ {
1225
+ if (this->repo_id_.in () == 0)
1226
+ {
1227
+ if (rb_const_defined (rb_class_of (rbServant_), repo_Id) == Qtrue)
1228
+ {
1229
+ VALUE rb_repo_id = rb_const_get (rb_class_of (rbServant_), repo_Id);
1230
+ this->repo_id_ = CORBA::string_dup (RSTRING_PTR (rb_repo_id));
1231
+ }
1232
+ else
1233
+ {
1234
+ ACE_ERROR ((LM_ERROR, "(%P|%t) FAILED TO RETRIEVE REPO-ID FOR SERVANT!\n"));
1235
+ this->repo_id_ = CORBA::string_dup ("");
1236
+ }
1237
+ }
1238
+ return CORBA::string_dup (this->repo_id_.in ());
1239
+ }
1240
+ }
1241
+
1242
+ VALUE r2tao_Servant_default_POA(VALUE self)
1243
+ {
1244
+ R2TAO_TRY
1245
+ {
1246
+ DSI_Servant* _servant;
1247
+ if (DATA_PTR (self) == 0)
1248
+ {
1249
+ // create new C++ servant object
1250
+ _servant = new DSI_Servant (self);
1251
+ }
1252
+ else
1253
+ {
1254
+ // get existing C++ servant object
1255
+ _servant = static_cast<DSI_Servant*> (DATA_PTR (self));
1256
+ }
1257
+
1258
+ // get default POA
1259
+ PortableServer::POA_var _poa = _servant->_default_POA ();
1260
+ VALUE rpoa = r2corba_Object_t2r(dynamic_cast<CORBA::Object_ptr> (_poa.in ()));
1261
+ return FN_narrow.invoke (r2tao_nsPOA, 1, &rpoa);
1262
+ }
1263
+ R2TAO_CATCH;
1264
+ return Qnil;
1265
+ }
1266
+
1267
+ VALUE r2tao_Servant_this(VALUE self)
1268
+ {
1269
+ R2TAO_TRY
1270
+ {
1271
+ bool _new_srv = false;
1272
+ DSI_Servant* _servant;
1273
+ if (DATA_PTR (self) == 0)
1274
+ {
1275
+ // create new C++ servant object
1276
+ _servant = new DSI_Servant (self);
1277
+ _new_srv = true;
1278
+ }
1279
+ else
1280
+ {
1281
+ // get existing C++ servant object
1282
+ _servant = static_cast<DSI_Servant*> (DATA_PTR (self));
1283
+ }
1284
+
1285
+ // Check if we're called from the context of an invocation of this
1286
+ // servant or not. We check the POA_Current_Impl in TSS for this.
1287
+ if (!_new_srv)
1288
+ {
1289
+ TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
1290
+ static_cast <TAO::Portable_Server::POA_Current_Impl *>
1291
+ (TAO_TSS_Resources::instance ()->poa_current_impl_);
1292
+
1293
+ if (poa_current_impl != 0
1294
+ && poa_current_impl->servant () == _servant)
1295
+ {
1296
+ // in an invocation we can safely use _this()
1297
+ CORBA::Object_var _obj = _servant->_this ();
1298
+ return r2corba_Object_t2r(_obj.in ());
1299
+ }
1300
+ }
1301
+
1302
+ // register with default POA and return object ref
1303
+ VALUE rpoa = rb_funcall (self, rb_intern ("_default_POA"), 0);
1304
+ PortableServer::POA_var _poa = r2tao_POA_r2t (rpoa);
1305
+ PortableServer::ObjectId_var _oid = _poa->activate_object (_servant);
1306
+
1307
+ _servant->activate_servant (); // activate Ruby servant
1308
+
1309
+ CORBA::Object_var _obj = _poa->id_to_reference (_oid.in ());
1310
+ return r2corba_Object_t2r(_obj.in ());
1311
+ }
1312
+ R2TAO_CATCH;
1313
+ return Qnil;
1314
+ }
1315
+
1316
+ //-------------------------------------------------------------------
1317
+ // Ruby <-> TAO servant conversions
1318
+ //
1319
+ //===================================================================
1320
+
1321
+ static VALUE
1322
+ srv_alloc(VALUE klass)
1323
+ {
1324
+ VALUE obj;
1325
+ // we start off without the C++ representation
1326
+ obj = Data_Wrap_Struct(klass, 0, srv_free, 0);
1327
+ return obj;
1328
+ }
1329
+
1330
+ static void
1331
+ srv_free(void* ptr)
1332
+ {
1333
+ if (ptr)
1334
+ {
1335
+ // detach from Ruby servant object
1336
+ static_cast<DSI_Servant*> (ptr)->free_servant ();
1337
+ }
1338
+ }