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,526 @@
1
+ #--------------------------------------------------------------------
2
+ # ins.rb - main file for R2CORBA INS service
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
+ require 'corba/svcs/ins/naming_service'
15
+ require 'optparse'
16
+
17
+ module R2CORBA
18
+ module INS
19
+ INS_VERSION_MAJOR = 0.freeze
20
+ INS_VERSION_MINOR = 1.freeze
21
+ INS_VERSION_RELEASE = 1.freeze
22
+ INS_COPYRIGHT = 'Copyright (c) 2011-2013 Remedy IT Expertise BV, The Netherlands'.freeze
23
+
24
+ IS_WIN32 = (RUBY_PLATFORM =~ /win32/ || RUBY_PLATFORM =~ /mingw32/ || ENV['OS'] =~ /windows/i) ? true : false
25
+ IS_JRUBY = defined?(JRUBY_VERSION)
26
+
27
+ @@daemons_installed = false
28
+
29
+ unless IS_WIN32 || IS_JRUBY
30
+ begin
31
+ require 'rubygems'
32
+ require 'daemons'
33
+ @@daemons_installed = true
34
+ rescue LoadError
35
+ STDERR.puts 'Daemon functionality requires installed "daemons" GEM.'
36
+ end
37
+ end
38
+
39
+ def INS.daemons_installed
40
+ @@daemons_installed
41
+ end
42
+
43
+ class Controller
44
+ def initialize(options)
45
+ @options = options
46
+ end
47
+
48
+ def report(msg)
49
+ STDERR.puts msg if @options[:verbose]
50
+ end
51
+ end
52
+
53
+ if IS_WIN32 || IS_JRUBY || !INS.daemons_installed
54
+ class Controller
55
+ def start
56
+ report 'INS - initializing service'
57
+
58
+ if self.pidfile_exists?
59
+ rc, pid = self.check_pidfile
60
+ if rc
61
+ STDERR.puts "ERROR: INS - existing PID file #{self.pidfile} found; service may still be alive"
62
+ exit 1
63
+ else
64
+ File.delete(self.pidfile)
65
+ end
66
+ end
67
+
68
+ begin
69
+ File.open(self.pidfile, File::CREAT|File::EXCL|File::WRONLY) do |f|
70
+ f.write Process.pid
71
+ end
72
+ report "INS - PID \##{Process.pid} written to '#{self.pidfile}'"
73
+ rescue ::Exception
74
+ STDERR.puts "ERROR: INS - failed to write PID file #{self.pidfile}"
75
+ exit 1
76
+ end
77
+
78
+ $ins_service_pid_file = self.pidfile
79
+ at_exit {
80
+ File.delete($ins_service_pid_file)
81
+ }
82
+
83
+ # initialize service
84
+ ins_svc = INS::Service.new(@options)
85
+
86
+ report 'INS - running service'
87
+
88
+ stop_proc = Proc.new do
89
+ report 'INS - shutting down'
90
+ begin; ins_svc.shutdown; rescue ::Exception; STDERR.puts "#{$!}\n#{$!.backtrace.join("\n")}"; end
91
+ end
92
+ Signal.trap('INT', stop_proc)
93
+ Signal.trap('TERM', stop_proc)
94
+
95
+ ins_svc.setup
96
+
97
+ ins_svc.run
98
+
99
+ report 'INS - stopped'
100
+ end
101
+
102
+ def stop
103
+ report 'INS - stopping service'
104
+
105
+ rc, pid = self.check_pidfile()
106
+
107
+ if pid
108
+ report 'INS - signalling service'
109
+ if IS_WIN32
110
+ Kernel.system("taskkill /PID #{pid} /F")
111
+ File.delete(self.pidfile)
112
+ else
113
+ Process.kill(:TERM, pid) rescue nil
114
+ end
115
+ end
116
+ end
117
+
118
+ def status
119
+ report 'INS - retrieving service status'
120
+
121
+ rc, pid = self.check_pidfile()
122
+
123
+ if pid
124
+ if rc
125
+ STDERR.puts "found PID #{pid} in file #{pidfile} : process is alive"
126
+ else
127
+ STDERR.puts "found PID #{pid} in file #{pidfile} : process is not running"
128
+ exit 1
129
+ end
130
+ end
131
+ end
132
+
133
+ protected
134
+ def pidfile
135
+ @pidfile ||= File.join(@options[:piddir], 'ins.rb.pid')
136
+ end
137
+
138
+ def pidfile_exists?
139
+ File.exists?(self.pidfile)
140
+ end
141
+
142
+ def check_pidfile
143
+ pid = nil
144
+ begin
145
+ File.open(self.pidfile, 'r') do |f|
146
+ pid = f.read.to_i
147
+ end
148
+ rescue ::Exception
149
+ STDERR.puts "ERROR: INS - failed to read PID file #{self.pidfile}"
150
+ return [false, nil]
151
+ end
152
+
153
+ begin
154
+ Process.kill(0, pid)
155
+ return [true, pid]
156
+ rescue ::Exception
157
+ return [false, pid]
158
+ end
159
+ end
160
+ end # Controller
161
+ else
162
+ # Service controller for *nix platforms
163
+ #
164
+ require 'rubygems'
165
+ require 'daemons'
166
+
167
+ class ::Daemons::Application
168
+ def exit
169
+ # make exit() call a NOOP here
170
+ # Daemons calls this when shutting down and that messes up our clean shutdown
171
+ # STDERR.puts 'exit NOOP'
172
+ end
173
+ end
174
+
175
+ class Controller
176
+ def start
177
+ report 'INS - initializing service'
178
+ # initialize service
179
+ ins_svc = INS::Service.new(@options)
180
+
181
+ if @options[:daemon]
182
+ report 'INS - starting daemon mode'
183
+
184
+ daemon_opt = {
185
+ :app_name => 'rins',
186
+ :ARGV => ['start'],
187
+ :dir_mode => :normal,
188
+ :dir => @options[:piddir],
189
+ :multiple => true,
190
+ :log_dir => @options[:logdir] || @options[:piddir],
191
+ :log_output => true,
192
+ :stop_proc => Proc.new do
193
+ report 'INS - shutting down'
194
+ ins_svc.shutdown
195
+ end
196
+ }
197
+
198
+ Daemons.run_proc('ins.rb', daemon_opt) do
199
+ report 'INS - daemon started'
200
+
201
+ ins_svc.setup
202
+
203
+ ins_svc.run
204
+
205
+ report 'INS - stopped'
206
+ end
207
+ else
208
+ report 'INS - running service in foreground'
209
+
210
+ if self.pidfile_exists?
211
+ rc, pid = self.check_pidfile
212
+ if rc
213
+ STDERR.puts "ERROR: INS - existing PID file #{self.pidfile} found; service may still be alive"
214
+ exit 1
215
+ else
216
+ File.delete(self.pidfile)
217
+ end
218
+ end
219
+
220
+ begin
221
+ File.open(self.pidfile, File::CREAT|File::EXCL|File::WRONLY) do |f|
222
+ f.write Process.pid
223
+ end
224
+ report "INS - PID \##{Process.pid} written to '#{self.pidfile}'"
225
+ rescue ::Exception
226
+ STDERR.puts "ERROR: INS - failed to write PID file #{self.pidfile}"
227
+ exit 1
228
+ end
229
+
230
+ $ins_service_pid_file = self.pidfile
231
+ at_exit {
232
+ File.delete($ins_service_pid_file)
233
+ }
234
+
235
+ stop_proc = Proc.new do
236
+ report 'INS - shutting down'
237
+ begin; ins_svc.shutdown; rescue ::Exception; STDERR.puts "#{$!}\n#{$!.backtrace.join("\n")}"; end
238
+ end
239
+ Signal.trap('INT', stop_proc)
240
+ Signal.trap('TERM', stop_proc)
241
+
242
+ ins_svc.setup
243
+
244
+ ins_svc.run
245
+
246
+ report 'INS - stopped'
247
+
248
+ exit(0)
249
+ end
250
+ end
251
+
252
+ def stop
253
+ report 'INS - stopping service'
254
+ if @options[:daemon]
255
+ daemon_opt = {
256
+ :app_name => 'rins',
257
+ :ARGV => ['stop'],
258
+ :dir_mode => :normal,
259
+ :dir => @options[:piddir],
260
+ :multiple => true,
261
+ }
262
+
263
+ Daemons.run_proc('ins.rb', daemon_opt) {}
264
+ else
265
+ rc, pid = self.check_pidfile()
266
+
267
+ if pid
268
+ report 'INS - signalling service'
269
+ Process.kill(:TERM, pid) rescue nil
270
+ end
271
+ end
272
+ end
273
+
274
+ def restart
275
+ if @options[:daemon]
276
+ report 'INS - initializing service'
277
+ # initialize service
278
+ ins_svc = INS::Service.new(@options)
279
+
280
+ report 'INS - restarting daemon mode'
281
+
282
+ daemon_opt = {
283
+ :app_name => 'rins',
284
+ :ARGV => ['restart'],
285
+ :dir_mode => :normal,
286
+ :dir => @options[:piddir],
287
+ :multiple => true,
288
+ :log_dir => @options[:logdir] || @options[:piddir],
289
+ :log_output => true,
290
+ :stop_proc => Proc.new do
291
+ report 'INS - shutting down'
292
+ ins_svc.shutdown
293
+ end
294
+ }
295
+
296
+ Daemons.run_proc('ins.rb', daemon_opt) do
297
+ report 'INS - daemon started'
298
+
299
+ ins_svc.setup
300
+
301
+ ins_svc.run
302
+
303
+ report 'INS - stopped'
304
+ end
305
+ else
306
+ STDERR.puts "INS - restart command is only functional in daemon mode"
307
+ exit 1
308
+ end
309
+ end
310
+
311
+ def status
312
+ report 'INS - retrieving service status'
313
+ daemon_opt = {
314
+ :app_name => 'rins',
315
+ :ARGV => ['status'],
316
+ :dir_mode => :normal,
317
+ :dir => @options[:piddir],
318
+ :multiple => true,
319
+ }
320
+
321
+ Daemons.run_proc('ins.rb', daemon_opt) {}
322
+ end
323
+
324
+ protected
325
+ def pidfile
326
+ @pidfile ||= File.join(@options[:piddir], 'ins.rb.pid')
327
+ end
328
+
329
+ def pidfile_exists?
330
+ File.exists?(self.pidfile)
331
+ end
332
+
333
+ def check_pidfile
334
+ pid = nil
335
+ begin
336
+ File.open(self.pidfile, 'r') do |f|
337
+ pid = f.read.to_i
338
+ end
339
+ rescue ::Exception
340
+ STDERR.puts "ERROR: INS - failed to read PID file #{self.pidfile}"
341
+ return [false, nil]
342
+ end
343
+
344
+ begin
345
+ Process.kill(0, pid)
346
+ return [true, pid]
347
+ rescue ::Exception
348
+ return [false, pid]
349
+ end
350
+ end
351
+ end # Controller
352
+ end
353
+
354
+ OPTIONS = {
355
+ :piddir => Dir.getwd,
356
+ :iorfile => 'ins.ior',
357
+ :debug => 0,
358
+ :logdir => nil,
359
+ :threads => 5,
360
+ :orbprop => {},
361
+ :port => 0,
362
+ }
363
+
364
+ COMMANDS = [
365
+ :start,
366
+ :stop,
367
+ :restart,
368
+ :status,
369
+ :help,
370
+ :version
371
+ ]
372
+ if IS_JRUBY
373
+ COMMANDS.delete(:restart)
374
+ end
375
+ if IS_WIN32
376
+ COMMANDS << :install
377
+ COMMANDS << :remove
378
+ end
379
+
380
+ @@command = nil
381
+
382
+ def INS.command
383
+ @@command
384
+ end
385
+
386
+ def INS.parse_arg
387
+ script_name = File.basename($0, '.bat')
388
+ if not script_name =~ /rins/
389
+ script_name = "ruby "+$0
390
+ end
391
+
392
+ @@command = ARGV.shift.to_sym unless ARGV.empty?
393
+ unless COMMANDS.include?(@@command)
394
+ STDERR.puts "ERROR: Invalid command [#{command}]!\n"+
395
+ "Usage: #{script_name} #{COMMANDS.join('|')} [options]\n"
396
+ exit 1
397
+ end
398
+
399
+ # extract -ORBxxx aguments
400
+ f_ = false
401
+ ARGV.collect! { |a|
402
+ if f_
403
+ f_ = false
404
+ OPTIONS[:orbprop] << a
405
+ nil
406
+ else
407
+ f_ = /^-ORB/ =~ a
408
+ OPTIONS[:orbprop] << a if f_
409
+ f_ ? nil : a
410
+ end
411
+ }.compact!
412
+
413
+ case @@command
414
+ when :help
415
+ puts "Usage: #{script_name} #{COMMANDS.join('|')} [options]\n"
416
+ puts "\n"
417
+ puts " #{script_name} #{(COMMANDS - [:help, :version]).join('|')} --help\n"
418
+ puts " provides help for the specified command\n\n"
419
+ exit
420
+ when :version
421
+ puts "R2CORBA Interoprable Naming Service (INS) #{INS_VERSION_MAJOR}.#{INS_VERSION_MINOR}.#{INS_VERSION_RELEASE}"
422
+ puts INS_COPYRIGHT
423
+ puts ''
424
+ exit
425
+ when :start, :restart
426
+ ARGV.options do |opts|
427
+ opts.banner = "Usage: #{script_name} start [options]"
428
+
429
+ opts.separator ""
430
+
431
+ opts.on("-i FILE", "--ior=FILE", String,
432
+ "Specifies filename (incl. path) to write IOR to.",
433
+ "Default: ./ins.ior") { |v| OPTIONS[:iorfile]=v }
434
+ unless IS_WIN32
435
+ opts.on("-p DIR", "--pid=DIR", String,
436
+ "Specifies path to write pidfile to.",
437
+ "Default: ./") { |v| OPTIONS[:piddir]=v }
438
+ unless IS_JRUBY
439
+ opts.on("-o DIR", "--output=DIR", String,
440
+ "Specifies filename to write logfile to.",
441
+ "Default: <piddir>") { |v| OPTIONS[:logdir]=v }
442
+ end
443
+ else
444
+ opts.on("-o DIR", "--output=DIR", String,
445
+ "Specifies path to write logfile to.",
446
+ "Default: ./") { |v| OPTIONS[:logdir]=v }
447
+ end
448
+ opts.on("-l PORTNUM", "--listen=PORTNUM", Integer,
449
+ "Specifies port number for service endpoint.",
450
+ "Default: none") { |v| OPTIONS[:port]=v }
451
+ if (IS_JRUBY or R2CORBA::TAO::RUBY_THREAD_SUPPORT)
452
+ opts.on("-t THREADNUM", "--threads=THREADNUM", Integer,
453
+ "Specifies (minimum) number of threads for service.",
454
+ "Default: 5") { |v| OPTIONS[:threads]=v }
455
+ end
456
+
457
+ unless IS_JRUBY || !INS.daemons_installed
458
+ opts.on("-d", "--daemon",
459
+ "Run as daemon.",
460
+ "Default: off") { |v| OPTIONS[:daemon]=v }
461
+ end
462
+ opts.on("-v", "--verbose",
463
+ "Run verbose.",
464
+ "Default: off") { |v| OPTIONS[:verbose]=v }
465
+
466
+ opts.on("--debug=LVL", Integer,
467
+ "Specifies debug level.",
468
+ "Default: 0") { |v| OPTIONS[:debug]=v }
469
+
470
+ opts.separator ""
471
+
472
+ opts.on("-h", "--help",
473
+ "Show this help message.") { puts opts; puts; exit }
474
+
475
+ opts.parse!
476
+ end
477
+ OPTIONS[:iorfile] = File.expand_path(OPTIONS[:iorfile])
478
+ when :stop, :status
479
+ ARGV.options do |opts|
480
+ opts.banner = "Usage: #{script_name} stop [options]"
481
+
482
+ opts.separator ""
483
+
484
+ unless IS_WIN32
485
+ opts.on("-p DIR", "--pid=DIR", String,
486
+ "Specifies path where pidfile is stored.",
487
+ "Default: ./") { |v| OPTIONS[:piddir]=v }
488
+ end
489
+
490
+ unless @@command == 'status'
491
+ OPTIONS[:daemon] = true unless IS_JRUBY || !INS.daemons_installed
492
+ opts.on("--[no-]daemon",
493
+ "Do not run in daemon mode.",
494
+ "Default: #{OPTIONS[:daemon] ? 'on' : 'off'}") { |v| OPTIONS[:daemon]=v }
495
+ end
496
+ opts.on("-v", "--verbose",
497
+ "Run verbose.",
498
+ "Default: off") { |v| OPTIONS[:verbose]=v }
499
+
500
+ opts.separator ""
501
+
502
+ opts.on("-h", "--help",
503
+ "Show this help message.") { puts opts; puts; exit }
504
+
505
+ opts.parse!
506
+ end
507
+ when :install
508
+ when :remove
509
+ end
510
+ OPTIONS[:piddir] = File.expand_path(OPTIONS[:piddir]) if OPTIONS[:piddir]
511
+ OPTIONS[:logdir] = File.expand_path(OPTIONS[:logdir]) if OPTIONS[:logdir]
512
+ end
513
+
514
+ def INS.run
515
+ self.parse_arg()
516
+
517
+ Controller.new(OPTIONS).send(self.command)
518
+ end
519
+ end
520
+ end
521
+
522
+ if __FILE__ == $0
523
+
524
+ R2CORBA::INS.run
525
+
526
+ end
@@ -0,0 +1,119 @@
1
+ #--------------------------------------------------------------------
2
+ # naming_service.rb - Implementation of Naming Service
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
+ require 'corba'
15
+ require 'corba/svcs/ins/cos_naming'
16
+
17
+ module R2CORBA
18
+ module INS
19
+ class Service
20
+ # default options
21
+ OPTIONS = {
22
+ :iorfile => 'ins.ior',
23
+ :debug => 0,
24
+ :threads => 5,
25
+ :orbprop => {},
26
+ :port => 0
27
+ }
28
+
29
+ def initialize(options = {})
30
+ @options = OPTIONS.merge(options)
31
+ raise RuntimeError, 'nr. of threads must >= 1' if @options[:threads] < 1
32
+ end
33
+
34
+ def setup
35
+ # process options
36
+ #
37
+ if defined?(JRUBY_VERSION)
38
+ @options[:orbprop]['jacorb.poa.thread_pool_min'] = @options[:threads]
39
+ @options[:orbprop]['jacorb.poa.thread_pool_max'] = @options[:threads]*4
40
+ if @options[:debug] > 0
41
+ @options[:orbprop]['jacorb.log.default.verbosity'] = case
42
+ when @options[:debug] < 2
43
+ 1
44
+ when (2...4) === @options[:debug]
45
+ 2
46
+ when (5...7) === @options[:debug]
47
+ 3
48
+ when @options[:debug] > 7
49
+ 4
50
+ end
51
+ end
52
+ if @options[:port] > 0
53
+ @options[:orbprop]['OAPort'] = @options[:port]
54
+ end
55
+ else
56
+ if @options[:debug] > 0
57
+ @options[:orbprop]['-ORBDebugLevel'] = @options[:debug]
58
+ end
59
+ if @options[:port] > 0
60
+ @options[:orbprop]['-ORBListenEndpoints'] = "iiop://:#{@options[:port]}"
61
+ end
62
+ end
63
+
64
+ # initialize ORB and POA.
65
+ #
66
+ @orb = CORBA.ORB_init('INS_ORB', @options[:orbprop])
67
+
68
+ obj = @orb.resolve_initial_references('RootPOA')
69
+
70
+ root_poa = PortableServer::POA._narrow(obj)
71
+
72
+ poa_man = root_poa.the_POAManager
73
+
74
+ poa_man.activate
75
+
76
+ # create and activate root Naming context
77
+ #
78
+ @naming_srv = INS::NamingContext.new(@orb)
79
+
80
+ naming_obj = @naming_srv._this()
81
+
82
+ naming_ior = @orb.object_to_string(naming_obj)
83
+
84
+ # simplify Corbaloc urls (corbaloc:iiop:[host][:port]/NamingService)
85
+ #
86
+ @orb.ior_map.map_ior('NamingService', naming_ior)
87
+
88
+ # save INS IOR to file
89
+ #
90
+ open(@options[:iorfile], 'w') { |io|
91
+ io.write naming_ior
92
+ }
93
+ end
94
+
95
+ def run
96
+ STDERR.puts "INS - starting service run" if @options[:verbose]
97
+ if (defined?(JRUBY_VERSION) or !R2CORBA::TAO::RUBY_THREAD_SUPPORT)
98
+ STDERR.puts "INS - running ORB" if @options[:verbose]
99
+ @orb.run
100
+ else
101
+ STDERR.puts "INS - starting #{@options[:threads]} ORB threads" if @options[:verbose]
102
+ @threads = []
103
+ @options[:threads].times do
104
+ @threads << Thread.new(@orb) { |orb| orb.run }
105
+ end
106
+ STDERR.puts "INS - joining ORB threads" if @options[:verbose]
107
+ @threads.each { |t| t.join }
108
+ end
109
+ STDERR.puts "INS - service run ended" if @options[:verbose]
110
+ end
111
+
112
+ def shutdown
113
+ STDERR.puts "INS - shutting down ORB" if @options[:verbose]
114
+ @orb.shutdown if @orb
115
+ STDERR.puts "INS - shutdown finished" if @options[:verbose]
116
+ end
117
+ end
118
+ end
119
+ end
data/lib/corba.rb ADDED
@@ -0,0 +1,16 @@
1
+ #--------------------------------------------------------------------
2
+ # corba.rb -
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
+ require "corba/require.rb"
15
+
16
+ include R2CORBA