rubywmq 1.1.1 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +0 -4
- data/LICENSE.txt +201 -0
- data/README.md +192 -0
- data/Rakefile +87 -0
- data/examples/q_to_files.cfg +17 -0
- data/ext/extconf.rb +6 -22
- data/ext/extconf_client.rb +3 -19
- data/ext/generate/generate_const.rb +16 -43
- data/ext/generate/generate_reason.rb +23 -36
- data/ext/generate/generate_structs.rb +7 -22
- data/ext/generate/wmq_structs.erb +28 -58
- data/ext/wmq.c +1 -4
- data/ext/wmq.h +5 -1
- data/ext/wmq_message.c +1 -1
- data/ext/wmq_mq_load.c +1 -1
- data/ext/wmq_queue.c +1 -1
- data/ext/wmq_queue_manager.c +1 -1
- data/lib/wmq.rb +10 -19
- data/lib/wmq/message.rb +70 -0
- data/{ext/lib/wmq_temp.rb → lib/wmq/queue_manager.rb} +11 -98
- data/lib/wmq/version.rb +3 -0
- data/tests/test.rb +30 -40
- metadata +95 -65
- data/LICENSE +0 -13
- data/README +0 -73
- data/ext/build.bat +0 -3
- data/ext/build.sh +0 -6
@@ -0,0 +1,17 @@
|
|
1
|
+
dev:
|
2
|
+
qmgr_options:
|
3
|
+
:q_mgr_name: REID
|
4
|
+
input_queue:
|
5
|
+
:mode: :browse
|
6
|
+
:q_name: TEST.QUEUE
|
7
|
+
target_directory: messages
|
8
|
+
|
9
|
+
test:
|
10
|
+
qmgr_options:
|
11
|
+
:q_mgr_name: TEST.QMGR
|
12
|
+
:channel_name: SYSTEM.DEF.SVRCONN
|
13
|
+
:connection_name: remotehost(1414)
|
14
|
+
input_queue:
|
15
|
+
:mode: :browse
|
16
|
+
:q_name: TEST.QUEUE
|
17
|
+
target_directory: messages
|
data/ext/extconf.rb
CHANGED
@@ -1,27 +1,11 @@
|
|
1
|
-
################################################################################
|
2
|
-
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
################################################################################
|
16
|
-
|
17
1
|
require 'mkmf'
|
18
|
-
require '
|
19
|
-
require '
|
20
|
-
require '
|
2
|
+
require File.join(File.dirname(__FILE__), 'generate', 'generate_reason')
|
3
|
+
require File.join(File.dirname(__FILE__), 'generate', 'generate_const')
|
4
|
+
require File.join(File.dirname(__FILE__), 'generate', 'generate_structs')
|
21
5
|
|
22
6
|
include_path = ''
|
23
|
-
if RUBY_PLATFORM =~ /
|
24
|
-
include_path = 'C:\Program Files\IBM\WebSphere MQ\
|
7
|
+
if RUBY_PLATFORM =~ /win|mingw/i
|
8
|
+
include_path = 'C:\Program Files\IBM\WebSphere MQ\tools\c\include'
|
25
9
|
dir_config('mqm', include_path, '.')
|
26
10
|
else
|
27
11
|
include_path = '/opt/mqm/inc'
|
@@ -37,7 +21,7 @@ end
|
|
37
21
|
|
38
22
|
# Generate Source Files
|
39
23
|
GenerateReason.generate(include_path+'/')
|
40
|
-
GenerateConst.generate(include_path+'/', 'lib')
|
24
|
+
GenerateConst.generate(include_path+'/', File.dirname(__FILE__) + '/../lib/wmq')
|
41
25
|
GenerateStructs.new(include_path+'/', 'generate').generate
|
42
26
|
|
43
27
|
# Generate Makefile
|
data/ext/extconf_client.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
|
-
################################################################################
|
2
|
-
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
1
|
#
|
4
|
-
#
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
################################################################################
|
16
|
-
|
17
|
-
#
|
18
|
-
# NOTE: Do NOT use this file unless the platform being requested is not supported
|
2
|
+
# NOTE: Do NOT use this file unless the platform being used is not supported
|
19
3
|
# directly by Ruby WMQ. Ruby WMQ already supports automatic dynamic loading on
|
20
4
|
# Windows, Solaris and Linux
|
21
5
|
#
|
@@ -29,12 +13,12 @@ unless (RUBY_PLATFORM =~ /win/i) || (RUBY_PLATFORM =~ /solaris/i) || (RUBY_PLATF
|
|
29
13
|
include_path = '/opt/mqm/inc'
|
30
14
|
dir_config('mqm', include_path, '/opt/mqm/lib')
|
31
15
|
have_library('mqic')
|
32
|
-
|
16
|
+
|
33
17
|
# Generate Source Files # Could check if not already present
|
34
18
|
GenerateReason.generate(include_path+'/')
|
35
19
|
GenerateConst.generate(include_path+'/', '../../lib/wmq')
|
36
20
|
GenerateStructs.new(include_path+'/', '../../generate').generate
|
37
|
-
|
21
|
+
|
38
22
|
have_header('cmqc.h')
|
39
23
|
create_makefile('wmq_client')
|
40
24
|
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# Extract Constants from the WebSphere MQ header files
|
1
2
|
class GenerateConst
|
2
|
-
|
3
|
-
#Extract Constants from Header files
|
3
|
+
|
4
|
+
# Extract Constants from Header files
|
4
5
|
def GenerateConst.extract_const(filename, const_prefix, start_exp=nil, end_exp=nil)
|
5
6
|
@constants = []
|
6
7
|
active = if start_exp then false else true end # Sure there is a better way
|
@@ -23,8 +24,8 @@ class GenerateConst
|
|
23
24
|
end
|
24
25
|
@constants
|
25
26
|
end
|
26
|
-
|
27
|
-
#Extract MQ Constants from Header files
|
27
|
+
|
28
|
+
# Extract MQ Constants from Header files
|
28
29
|
def GenerateConst.rb_const(filename, const_prefix, exclude_exp=nil)
|
29
30
|
str = ''
|
30
31
|
GenerateConst.extract_const(filename, const_prefix).each do |item|
|
@@ -42,7 +43,7 @@ class GenerateConst
|
|
42
43
|
end
|
43
44
|
str
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
def GenerateConst.config(filename, prefix)
|
47
48
|
str = "# WMQ::QueueManager execute commands\n"
|
48
49
|
str << "execute_commands:\n"
|
@@ -55,24 +56,10 @@ class GenerateConst
|
|
55
56
|
end
|
56
57
|
str
|
57
58
|
end
|
58
|
-
|
59
|
+
|
59
60
|
def GenerateConst.wmq_const(path)
|
60
61
|
str = <<END_OF_STRING
|
61
62
|
################################################################################
|
62
|
-
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
63
|
-
#
|
64
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
65
|
-
# you may not use this file except in compliance with the License.
|
66
|
-
# You may obtain a copy of the License at
|
67
|
-
#
|
68
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
69
|
-
#
|
70
|
-
# Unless required by applicable law or agreed to in writing, software
|
71
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
72
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
73
|
-
# See the License for the specific language governing permissions and
|
74
|
-
# limitations under the License.
|
75
|
-
################################################################################
|
76
63
|
#
|
77
64
|
# WARNING: DO NOT MODIFY THIS FILE
|
78
65
|
#
|
@@ -81,18 +68,18 @@ class GenerateConst
|
|
81
68
|
################################################################################
|
82
69
|
module WMQ
|
83
70
|
END_OF_STRING
|
84
|
-
[ ['Connect Options','cmqc.h','MQCNO_',/(VERSION)|(CONN_TAG)|(HANDLE_SHARE)/],
|
71
|
+
[ ['Connect Options','cmqc.h','MQCNO_',/(VERSION)|(CONN_TAG)|(HANDLE_SHARE)|(_LENGTH)/],
|
85
72
|
['Open Options', 'cmqc.h','MQOO_' ],
|
86
73
|
['Close Options', 'cmqc.h','MQCO_'],
|
87
74
|
['Match Options', 'cmqc.h','MQMO_'],
|
88
75
|
['Message Format Options', 'cmqc.h','MQFMT_',/(_ARRAY)/],
|
89
|
-
['Get Message Options', 'cmqc.h','MQGMO_',/(VERSION)/],
|
76
|
+
['Get Message Options', 'cmqc.h','MQGMO_',/(VERSION)|(LENGTH)|(MQGMO_BROWSE_HANDLE)|(MQGMO_BROWSE_CO_OP)/],
|
90
77
|
['Transport Types', 'cmqxc.h','MQXPT_'] ,
|
91
78
|
['Report Options', 'cmqc.h', 'MQRO_'],
|
92
79
|
['Message Types', 'cmqc.h', 'MQMT_'],
|
93
80
|
['Expiry', 'cmqc.h', 'MQEI_'],
|
94
81
|
['Feedback Values', 'cmqc.h', 'MQFB_'],
|
95
|
-
['Encoding Values', 'cmqc.h', 'MQENC_'],
|
82
|
+
['Encoding Values', 'cmqc.h', 'MQENC_',/(MQENC_NORMAL)|(MQENC_REVERSED)|(MQENC_S390)|(MQENC_TNS)/],
|
96
83
|
['Coded Character Set Identifiers', 'cmqc.h', 'MQCCSI_'],
|
97
84
|
['Priority', 'cmqc.h', 'MQPRI_'],
|
98
85
|
['Persistence', 'cmqc.h', 'MQPER_'],
|
@@ -108,24 +95,10 @@ END_OF_STRING
|
|
108
95
|
end
|
109
96
|
str << "end\n"
|
110
97
|
end
|
111
|
-
|
98
|
+
|
112
99
|
def GenerateConst.admin_consts(path)
|
113
100
|
str = <<END_OF_STRING
|
114
101
|
################################################################################
|
115
|
-
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
116
|
-
#
|
117
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
118
|
-
# you may not use this file except in compliance with the License.
|
119
|
-
# You may obtain a copy of the License at
|
120
|
-
#
|
121
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
122
|
-
#
|
123
|
-
# Unless required by applicable law or agreed to in writing, software
|
124
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
125
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
126
|
-
# See the License for the specific language governing permissions and
|
127
|
-
# limitations under the License.
|
128
|
-
################################################################################
|
129
102
|
#
|
130
103
|
# WARNING: DO NOT MODIFY THIS FILE
|
131
104
|
#
|
@@ -142,7 +115,7 @@ END_OF_STRING
|
|
142
115
|
str << "\n# #{item[0]}\n"
|
143
116
|
str << GenerateConst.rb_const("#{path}/#{item[1]}", item[2], item[3])
|
144
117
|
end
|
145
|
-
GenerateConst.extract_const(path+'cmqc.h', 'MQ', /Queue\
|
118
|
+
GenerateConst.extract_const(path+'cmqc.h', 'MQ', /Queue\s+Attributes/, /General\s+Constants/).each do |item|
|
146
119
|
str << " %-30s = #{item[1]}\n" % item[0]
|
147
120
|
end
|
148
121
|
str << "# Admin constants from cmqcfc.h\n"
|
@@ -151,14 +124,14 @@ END_OF_STRING
|
|
151
124
|
end
|
152
125
|
str << "end\n"
|
153
126
|
end
|
154
|
-
|
127
|
+
|
155
128
|
def self.generate(path, target_path='')
|
156
|
-
File.open(File.join(target_path,'
|
129
|
+
File.open(File.join(target_path,'constants_admin.rb'), 'w') {|file| file.write(GenerateConst.admin_consts(path))}
|
157
130
|
puts 'Generated wmq_const_admin.rb'
|
158
|
-
File.open(File.join(target_path,'
|
131
|
+
File.open(File.join(target_path,'constants.rb'), 'w') {|file| file.write(GenerateConst.wmq_const(path))}
|
159
132
|
puts 'Generated wmq_const.rb'
|
160
133
|
end
|
161
|
-
end
|
134
|
+
end
|
162
135
|
|
163
136
|
if $0 == __FILE__
|
164
137
|
path = ARGV[0] || raise("Mandatory parameter: 'WebSphere MQ Include path' is missing")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class GenerateReason
|
2
2
|
|
3
|
-
#Extract Error Code Constants from Header files
|
3
|
+
# Extract Error Code Constants from Header files
|
4
4
|
def GenerateReason.extract_const(filename, const_prefix)
|
5
5
|
@constants = []
|
6
6
|
File.open(filename) do |file|
|
@@ -16,8 +16,8 @@ class GenerateReason
|
|
16
16
|
end
|
17
17
|
@constants
|
18
18
|
end
|
19
|
-
|
20
|
-
#Extract Error Code Constants from Header files
|
19
|
+
|
20
|
+
# Extract Error Code Constants from Header files
|
21
21
|
# Uses lazy print to collect duplicate values
|
22
22
|
def GenerateReason.reason_case(filename, prefix)
|
23
23
|
last_rc = nil
|
@@ -36,8 +36,8 @@ class GenerateReason
|
|
36
36
|
end
|
37
37
|
str
|
38
38
|
end
|
39
|
-
|
40
|
-
# The WebSphere MQ header files have several duplicate values,
|
39
|
+
|
40
|
+
# The WebSphere MQ header files have several duplicate values,
|
41
41
|
# so need to exclude duplicates.
|
42
42
|
def GenerateReason.selector_case(filename, prefix, excludes=nil, &block)
|
43
43
|
GenerateReason.extract_const(filename,prefix).each do |item|
|
@@ -46,24 +46,10 @@ class GenerateReason
|
|
46
46
|
block.call item
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def GenerateReason.wmq_reason(path)
|
51
51
|
str = <<END_OF_STRING
|
52
52
|
/* --------------------------------------------------------------------------
|
53
|
-
* Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
54
|
-
*
|
55
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
56
|
-
* you may not use this file except in compliance with the License.
|
57
|
-
* You may obtain a copy of the License at
|
58
|
-
*
|
59
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
60
|
-
*
|
61
|
-
* Unless required by applicable law or agreed to in writing, software
|
62
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
63
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
64
|
-
* See the License for the specific language governing permissions and
|
65
|
-
* limitations under the License.
|
66
|
-
* --------------------------------------------------------------------------
|
67
53
|
*
|
68
54
|
* WARNING: DO NOT MODIFY THIS FILE
|
69
55
|
*
|
@@ -97,9 +83,10 @@ END_OF_STRING
|
|
97
83
|
[['cmqc.h', 'MQIA_'],
|
98
84
|
['cmqcfc.h', 'MQIACF_', ['MQIACF_ERROR_ID',
|
99
85
|
'MQIACF_QUIESCE']],
|
100
|
-
['cmqcfc.h', 'MQIACH_', ['MQIACH_CURRENT_SEQ_NUMBER',
|
101
|
-
'MQIACH_BYTES_RCVD',
|
102
|
-
'MQIACH_BUFFERS_RCVD'
|
86
|
+
['cmqcfc.h', 'MQIACH_', ['MQIACH_CURRENT_SEQ_NUMBER',
|
87
|
+
'MQIACH_BYTES_RCVD',
|
88
|
+
'MQIACH_BUFFERS_RCVD',
|
89
|
+
'MQIACH_MSGS_RCVD']],
|
103
90
|
['cmqcfc.h', 'MQIAMO_'],
|
104
91
|
['cmqcfc.h', 'MQIAMO64_', ['MQIAMO64_AVG_Q_TIME',
|
105
92
|
'MQIAMO64_Q_TIME_AVG',
|
@@ -125,7 +112,7 @@ END_OF_STRING
|
|
125
112
|
str_switch << " case %-30s: return ID_#{id};\n" % const[0]
|
126
113
|
str_id_init << " ID_%-25s = rb_intern(\"#{id}\");\n" % id
|
127
114
|
str << "static ID ID_#{id};\n"
|
128
|
-
end
|
115
|
+
end
|
129
116
|
end
|
130
117
|
|
131
118
|
str << <<END_OF_STRING
|
@@ -156,8 +143,8 @@ END_OF_STRING
|
|
156
143
|
[['cmqc.h', 'MQIA_'],
|
157
144
|
['cmqcfc.h', 'MQIACF_', ['MQIACF_ERROR_ID',
|
158
145
|
'MQIACF_QUIESCE']],
|
159
|
-
['cmqcfc.h', 'MQIACH_', ['MQIACH_CURRENT_SEQ_NUMBER',
|
160
|
-
'MQIACH_BYTES_RCVD',
|
146
|
+
['cmqcfc.h', 'MQIACH_', ['MQIACH_CURRENT_SEQ_NUMBER',
|
147
|
+
'MQIACH_BYTES_RCVD',
|
161
148
|
'MQIACH_BUFFERS_RCVD']],
|
162
149
|
['cmqcfc.h', 'MQIAMO_'],
|
163
150
|
['cmqcfc.h', 'MQIAMO64_', ['MQIAMO64_AVG_Q_TIME',
|
@@ -169,8 +156,8 @@ END_OF_STRING
|
|
169
156
|
].each do |item|
|
170
157
|
str << " /* Consteants #{item[1]}* from #{item[0]} */\n"
|
171
158
|
GenerateReason.selector_case(path+item[0], item[1], item[2]) do |const|
|
172
|
-
str << " if(selector_id == %-32s{ *selector = #{const[0]}; return;}\n" % "ID_#{const[0].gsub(item[1],'').downcase})"
|
173
|
-
end
|
159
|
+
str << " if(selector_id == %-32s{ *selector = #{const[0]}; return;}\n" % "ID_#{const[0].gsub(item[1],'').downcase})"
|
160
|
+
end
|
174
161
|
end
|
175
162
|
str << "\n *selector_type = MQIT_STRING;\n\n"
|
176
163
|
# Character Selectors for Object Attributes
|
@@ -182,16 +169,16 @@ END_OF_STRING
|
|
182
169
|
# ['cmqc.h', 'MQBA_'],
|
183
170
|
# ['cmqcfc.h', 'MQBACF_'],
|
184
171
|
# Group Selectors for Object Attributes
|
185
|
-
# ['cmqcfc.h', 'MQGACF_']
|
172
|
+
# ['cmqcfc.h', 'MQGACF_']
|
186
173
|
].each do |item|
|
187
174
|
str << " /* Constants #{item[1]}* from #{item[0]} */\n"
|
188
175
|
GenerateReason.selector_case(path+item[0], item[1], item[2]) do |const|
|
189
|
-
str << " if(selector_id == %-32s{ *selector = #{const[0]}; return;}\n" % "ID_#{const[0].gsub(item[1],'').downcase})"
|
190
|
-
end
|
176
|
+
str << " if(selector_id == %-32s{ *selector = #{const[0]}; return;}\n" % "ID_#{const[0].gsub(item[1],'').downcase})"
|
177
|
+
end
|
191
178
|
end
|
192
179
|
|
193
180
|
str << <<END_OF_STRING
|
194
|
-
|
181
|
+
|
195
182
|
rb_raise(rb_eArgError, "WMQ::QueueManager#execute [wmq_selector] Unknown selector supplied");
|
196
183
|
}
|
197
184
|
|
@@ -208,9 +195,9 @@ END_OF_STRING
|
|
208
195
|
end
|
209
196
|
id = const[0].gsub('MQCMD_','').downcase
|
210
197
|
str_id_init << " ID_%-25s = rb_intern(\"#{id}\");\n" % id
|
211
|
-
str_if << "if(command_id == %-28s{ command = #{const[0]}; }\n" % "ID_#{const[0].gsub('MQCMD_','').downcase})"
|
198
|
+
str_if << "if(command_id == %-28s{ command = #{const[0]}; }\n" % "ID_#{const[0].gsub('MQCMD_','').downcase})"
|
212
199
|
str << "static ID ID_#{id};\n"
|
213
|
-
end
|
200
|
+
end
|
214
201
|
str << <<END_OF_STRING
|
215
202
|
|
216
203
|
void QueueManager_command_id_init()
|
@@ -221,7 +208,7 @@ void QueueManager_command_id_init()
|
|
221
208
|
MQLONG wmq_command_lookup(ID command_id)
|
222
209
|
{
|
223
210
|
MQLONG command = 0;
|
224
|
-
#{str_if}
|
211
|
+
#{str_if}
|
225
212
|
else
|
226
213
|
{
|
227
214
|
rb_raise(rb_eArgError, "WMQ::QueueManager#execute [wmq_command_lookup] Unknown command supplied");
|
@@ -232,7 +219,7 @@ MQLONG wmq_command_lookup(ID command_id)
|
|
232
219
|
END_OF_STRING
|
233
220
|
str
|
234
221
|
end
|
235
|
-
|
222
|
+
|
236
223
|
def self.generate(path)
|
237
224
|
File.open('wmq_reason.c', 'w') {|file| file.write(GenerateReason.wmq_reason(path))}
|
238
225
|
puts 'Generated wmq_reason.c'
|
@@ -1,30 +1,15 @@
|
|
1
|
-
################################################################################
|
2
|
-
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
################################################################################
|
16
1
|
require 'erb'
|
17
2
|
|
18
3
|
class GenerateStructs
|
19
|
-
|
4
|
+
|
20
5
|
@@field_ignore_list = [ 'StrucId', 'Version' , 'StrucLength']
|
21
|
-
|
6
|
+
|
22
7
|
# Store path to WebSphere MQ Structures
|
23
8
|
def initialize(wmq_includepath, templates_path='.')
|
24
9
|
@path = wmq_includepath
|
25
10
|
@templates_path = templates_path
|
26
11
|
end
|
27
|
-
|
12
|
+
|
28
13
|
def extract_struct (filename, struct_name)
|
29
14
|
properties_list = []
|
30
15
|
line_number = 0
|
@@ -51,7 +36,7 @@ class GenerateStructs
|
|
51
36
|
end
|
52
37
|
properties_list
|
53
38
|
end
|
54
|
-
|
39
|
+
|
55
40
|
def rubyize_name(name)
|
56
41
|
name.gsub(/::/, '/').
|
57
42
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
@@ -59,7 +44,7 @@ class GenerateStructs
|
|
59
44
|
tr("-", "_").
|
60
45
|
downcase
|
61
46
|
end
|
62
|
-
|
47
|
+
|
63
48
|
def self.test_rubyize_name
|
64
49
|
test = self.new
|
65
50
|
[['a', 'a'],
|
@@ -75,11 +60,11 @@ class GenerateStructs
|
|
75
60
|
raise("rubyize_name('#{item[0]}') == #{str} != '#{item[1]})") if str != item[1]
|
76
61
|
end
|
77
62
|
end
|
78
|
-
|
63
|
+
|
79
64
|
def generate_structs(erb)
|
80
65
|
erb.result(binding)
|
81
66
|
end
|
82
|
-
|
67
|
+
|
83
68
|
def generate(target_filename = 'wmq_structs.c')
|
84
69
|
erb = nil
|
85
70
|
File.open(@templates_path+'/wmq_structs.erb') { |file| erb = ERB.new(file.read) }
|
@@ -1,20 +1,4 @@
|
|
1
|
-
<%
|
2
|
-
################################################################################
|
3
|
-
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
################################################################################
|
17
|
-
|
1
|
+
<%
|
18
2
|
symbols = {
|
19
3
|
'descriptor='=>nil,
|
20
4
|
'headers='=>nil,
|
@@ -68,7 +52,7 @@
|
|
68
52
|
# Transmission-queue header - Todo: Need to deal with MQMDE
|
69
53
|
{:file=>'cmqc.h', :struct=>'MQXQH', :header=>'xmit_q_header', :format=>'MsgDesc.Format'},
|
70
54
|
]
|
71
|
-
|
55
|
+
|
72
56
|
wmq_structs.each do |struct|
|
73
57
|
# Parse WebSphere MQ 'C' Header file and extract elements
|
74
58
|
elements = extract_struct(@path+'/'+struct[:file], struct[:struct])
|
@@ -84,20 +68,6 @@
|
|
84
68
|
end
|
85
69
|
%>
|
86
70
|
/* --------------------------------------------------------------------------
|
87
|
-
* Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
88
|
-
*
|
89
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
90
|
-
* you may not use this file except in compliance with the License.
|
91
|
-
* You may obtain a copy of the License at
|
92
|
-
*
|
93
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
94
|
-
*
|
95
|
-
* Unless required by applicable law or agreed to in writing, software
|
96
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
97
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
98
|
-
* See the License for the specific language governing permissions and
|
99
|
-
* limitations under the License.
|
100
|
-
* --------------------------------------------------------------------------
|
101
71
|
*
|
102
72
|
* WARNING: DO NOT MODIFY THIS FILE
|
103
73
|
*
|
@@ -110,16 +80,16 @@
|
|
110
80
|
/* --------------------------------------------------------------------------
|
111
81
|
* Static's to hold Symbols
|
112
82
|
* --------------------------------------------------------------------------*/
|
113
|
-
<%
|
83
|
+
<%
|
114
84
|
header_file = 'cmqc.h'
|
115
85
|
struct = 'MQMD'
|
116
86
|
|
117
87
|
# Define static variables to hold Ruby symbols
|
118
88
|
key_list = symbols.keys.sort
|
119
|
-
key_list.each do |key, value|
|
89
|
+
key_list.each do |key, value|
|
120
90
|
%><%="static ID ID_#{key.sub('=', '_set')};\n" %><%
|
121
91
|
end
|
122
|
-
|
92
|
+
|
123
93
|
# initialize symbols
|
124
94
|
%>
|
125
95
|
/* --------------------------------------------------------------------------
|
@@ -127,7 +97,7 @@
|
|
127
97
|
* --------------------------------------------------------------------------*/
|
128
98
|
void wmq_structs_id_init()
|
129
99
|
{
|
130
|
-
<% key_list.each do |key, value|
|
100
|
+
<% key_list.each do |key, value|
|
131
101
|
%><%=" ID_%-20s = rb_intern(\"%s\");\n"% [key.sub('=', '_set'), key] %><%
|
132
102
|
end
|
133
103
|
%>}
|
@@ -145,18 +115,18 @@ void Message_from_<%=struct_name.downcase%>(VALUE hash, <%=struct_name%>* <%=var
|
|
145
115
|
{
|
146
116
|
VALUE str;
|
147
117
|
size_t size;
|
148
|
-
size_t length;
|
118
|
+
size_t length;
|
149
119
|
size_t i;
|
150
120
|
char* pChar;
|
151
|
-
|
121
|
+
|
152
122
|
<%
|
153
123
|
elements.each do |item|
|
154
124
|
type = item[0]
|
155
125
|
name = item[1]
|
156
|
-
|
126
|
+
|
157
127
|
next if @@field_ignore_list.include?(name) ||
|
158
128
|
(name=='Format' && struct[:header])
|
159
|
-
|
129
|
+
|
160
130
|
match = /(MQ\D+)/.match(type)
|
161
131
|
type = "#{match[1]}S" if match[1] != type
|
162
132
|
%><%= if type == 'MQMDS'
|
@@ -164,25 +134,25 @@ void Message_from_<%=struct_name.downcase%>(VALUE hash, <%=struct_name%>* <%=var
|
|
164
134
|
else
|
165
135
|
" %-16s(hash, %-30s #{variable}->%s)\n" % ["WMQ_#{type}2HASH", rubyize_name(name)+',',name]
|
166
136
|
end %><%
|
167
|
-
end
|
137
|
+
end
|
168
138
|
%>}
|
169
139
|
|
170
140
|
static int Message_to_<%=struct_name.downcase%>_each (VALUE key, VALUE value, <%=struct_name%>* p<%=struct_name.downcase%>)
|
171
141
|
{
|
172
142
|
VALUE str;
|
173
143
|
size_t size;
|
174
|
-
size_t length;
|
144
|
+
size_t length;
|
175
145
|
VALUE val;
|
176
146
|
ID id = rb_to_id(key);
|
177
|
-
|
147
|
+
|
178
148
|
<% contains = nil
|
179
149
|
elements.each do |item|
|
180
150
|
type = item[0]
|
181
151
|
name = item[1]
|
182
|
-
|
152
|
+
|
183
153
|
next if @@field_ignore_list.include?(name) ||
|
184
154
|
(name=='Format' && struct[:header])
|
185
|
-
|
155
|
+
|
186
156
|
match = /(MQ\D+)/.match(type)
|
187
157
|
type = "#{match[1]}S" if match[1] != type
|
188
158
|
%><%= if type == 'MQMDS'
|
@@ -198,9 +168,9 @@ static int Message_to_<%=struct_name.downcase%>_each (VALUE key, VALUE value, <%
|
|
198
168
|
else<% end
|
199
169
|
end
|
200
170
|
%><%=struct[:header]?" if(id != ID_header_type)":""%><%
|
201
|
-
if contains
|
171
|
+
if contains
|
202
172
|
%> {
|
203
|
-
Message_to_<%= contains%>_each(key, value, &pmqxqh->MsgDesc);
|
173
|
+
Message_to_<%= contains%>_each(key, value, &pmqxqh->MsgDesc);
|
204
174
|
}<%
|
205
175
|
else%>
|
206
176
|
{
|
@@ -215,7 +185,7 @@ void Message_to_<%=struct_name.downcase%>(VALUE hash, <%=struct_name%>* p<%=stru
|
|
215
185
|
{
|
216
186
|
rb_hash_foreach(hash, Message_to_<%=struct_name.downcase%>_each, (VALUE)p<%=struct_name.downcase%>);
|
217
187
|
}
|
218
|
-
<% end # wmq_structs.each
|
188
|
+
<% end # wmq_structs.each
|
219
189
|
%>
|
220
190
|
|
221
191
|
/* --------------------------------------------------------------------------
|
@@ -240,10 +210,10 @@ void Message_deblock(VALUE self, PMQMD pmqmd, PMQBYTE p_buffer, MQLONG total_len
|
|
240
210
|
{
|
241
211
|
VALUE hash = rb_hash_new();
|
242
212
|
P<%=struct[:struct]%> p_header = (P<%=struct[:struct]%>)p_data;
|
243
|
-
|
213
|
+
|
244
214
|
if(trace_level>2)
|
245
215
|
printf("WMQ::Message#deblock Found <%=struct[:header]%>\n");
|
246
|
-
|
216
|
+
|
247
217
|
if(memcmp(p_header->StrucId, <%=struct[:struct_id] || "#{struct[:struct].upcase}_STRUC_ID"%>, sizeof(p_header->StrucId)) != 0)
|
248
218
|
{
|
249
219
|
if(trace_level>1)
|
@@ -277,7 +247,7 @@ void Message_deblock(VALUE self, PMQMD pmqmd, PMQBYTE p_buffer, MQLONG total_len
|
|
277
247
|
else
|
278
248
|
<%
|
279
249
|
end
|
280
|
-
end # wmq_structs.each
|
250
|
+
end # wmq_structs.each
|
281
251
|
%> {
|
282
252
|
break;
|
283
253
|
}
|
@@ -287,7 +257,7 @@ void Message_deblock(VALUE self, PMQMD pmqmd, PMQBYTE p_buffer, MQLONG total_len
|
|
287
257
|
{
|
288
258
|
strncpy(pmqmd->Format, p_format, MQ_FORMAT_LENGTH);
|
289
259
|
}
|
290
|
-
|
260
|
+
|
291
261
|
Message_from_mqmd(descriptor, pmqmd);
|
292
262
|
rb_funcall(self, ID_descriptor_set, 1, descriptor);
|
293
263
|
rb_funcall(self, ID_headers_set, 1, headers);
|
@@ -302,8 +272,8 @@ void Message_build_set_format(ID header_type, PMQBYTE p_format)
|
|
302
272
|
%> if(header_type == ID_<%=struct[:header]%>) { memcpy(p_format, MQFMT_<%=struct[:header].upcase%>, MQ_FORMAT_LENGTH); return;}
|
303
273
|
<%
|
304
274
|
end
|
305
|
-
end # wmq_structs.each
|
306
|
-
|
275
|
+
end # wmq_structs.each
|
276
|
+
|
307
277
|
%>
|
308
278
|
rb_raise(rb_eArgError, "Invalid/Unknown header_type supplied in WMQ::Message#headers array");
|
309
279
|
}
|
@@ -332,7 +302,7 @@ int Message_build_header (VALUE hash, struct Message_build_header_arg* parg)
|
|
332
302
|
|
333
303
|
if(parg->trace_level>2)
|
334
304
|
printf ("WMQ::Message#build_header Found <%=struct[:header]%>\n");
|
335
|
-
|
305
|
+
|
336
306
|
p_data = Message_autogrow_data_buffer(parg, sizeof(<%=struct[:struct]%>));
|
337
307
|
|
338
308
|
memcpy(p_data, &<%=struct[:struct]%>_DEF, sizeof(<%=struct[:struct]%>));
|
@@ -351,13 +321,13 @@ int Message_build_header (VALUE hash, struct Message_build_header_arg* parg)
|
|
351
321
|
|
352
322
|
if(parg->trace_level>2)
|
353
323
|
printf ("WMQ::Message#build_header data offset:%ld\n", (long)(*(parg->p_data_offset)));
|
354
|
-
<% end
|
324
|
+
<% end
|
355
325
|
%> }
|
356
326
|
else
|
357
327
|
<%
|
358
328
|
end
|
359
|
-
end # wmq_structs.each
|
360
|
-
|
329
|
+
end # wmq_structs.each
|
330
|
+
|
361
331
|
%> {
|
362
332
|
rb_raise(rb_eArgError, "Unknown :header_type supplied in WMQ::Message#headers array");
|
363
333
|
}
|