ext/generate/wmq_structs.erb in rubywmq-1.1.1 vs ext/generate/wmq_structs.erb in rubywmq-2.0.0.pre
- old
+ new
@@ -1,22 +1,6 @@
-<%
-################################################################################
-# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-################################################################################
-
+<%
symbols = {
'descriptor='=>nil,
'headers='=>nil,
'data='=>nil,
'header_type'=>nil,
@@ -66,11 +50,11 @@
{:file=>'cmqc.h', :struct=>'MQWIH', :header=>'work_info_header'},
# Transmission-queue header - Todo: Need to deal with MQMDE
{:file=>'cmqc.h', :struct=>'MQXQH', :header=>'xmit_q_header', :format=>'MsgDesc.Format'},
]
-
+
wmq_structs.each do |struct|
# Parse WebSphere MQ 'C' Header file and extract elements
elements = extract_struct(@path+'/'+struct[:file], struct[:struct])
struct[:elements] = elements
@@ -82,25 +66,11 @@
symbols[rubyize_name(item[1])] = nil unless @@field_ignore_list.include?(item[1])
end
end
%>
/* --------------------------------------------------------------------------
- * Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * --------------------------------------------------------------------------
- *
* WARNING: DO NOT MODIFY THIS FILE
*
* This file was generated by generate_structs.rb.
*
* --------------------------------------------------------------------------*/
@@ -108,28 +78,28 @@
#include "wmq.h"
/* --------------------------------------------------------------------------
* Static's to hold Symbols
* --------------------------------------------------------------------------*/
-<%
+<%
header_file = 'cmqc.h'
struct = 'MQMD'
# Define static variables to hold Ruby symbols
key_list = symbols.keys.sort
- key_list.each do |key, value|
+ key_list.each do |key, value|
%><%="static ID ID_#{key.sub('=', '_set')};\n" %><%
end
-
+
# initialize symbols
%>
/* --------------------------------------------------------------------------
* Initialize Symbols
* --------------------------------------------------------------------------*/
void wmq_structs_id_init()
{
-<% key_list.each do |key, value|
+<% key_list.each do |key, value|
%><%=" ID_%-20s = rb_intern(\"%s\");\n"% [key.sub('=', '_set'), key] %><%
end
%>}
<%
# Generate functions to move to/from a Ruby Hash of the symbols defined above
@@ -143,48 +113,48 @@
* --------------------------------------------------------------------------*/
void Message_from_<%=struct_name.downcase%>(VALUE hash, <%=struct_name%>* <%=variable%>)
{
VALUE str;
size_t size;
- size_t length;
+ size_t length;
size_t i;
char* pChar;
-
+
<%
elements.each do |item|
type = item[0]
name = item[1]
-
+
next if @@field_ignore_list.include?(name) ||
(name=='Format' && struct[:header])
-
+
match = /(MQ\D+)/.match(type)
type = "#{match[1]}S" if match[1] != type
%><%= if type == 'MQMDS'
" %-16s(hash, &#{variable}->%s);\n" % ['Message_from_mqmd1', name]
else
" %-16s(hash, %-30s #{variable}->%s)\n" % ["WMQ_#{type}2HASH", rubyize_name(name)+',',name]
end %><%
- end
+ end
%>}
static int Message_to_<%=struct_name.downcase%>_each (VALUE key, VALUE value, <%=struct_name%>* p<%=struct_name.downcase%>)
{
VALUE str;
size_t size;
- size_t length;
+ size_t length;
VALUE val;
ID id = rb_to_id(key);
-
+
<% contains = nil
elements.each do |item|
type = item[0]
name = item[1]
-
+
next if @@field_ignore_list.include?(name) ||
(name=='Format' && struct[:header])
-
+
match = /(MQ\D+)/.match(type)
type = "#{match[1]}S" if match[1] != type
%><%= if type == 'MQMDS'
contains = 'mqmd1'
""
@@ -196,13 +166,13 @@
struct[:other_keys].each do |key|
%> if(id == ID_<%=key.to_s%>) {}
else<% end
end
%><%=struct[:header]?" if(id != ID_header_type)":""%><%
- if contains
+ if contains
%> {
- Message_to_<%= contains%>_each(key, value, &pmqxqh->MsgDesc);
+ Message_to_<%= contains%>_each(key, value, &pmqxqh->MsgDesc);
}<%
else%>
{
val = rb_funcall(key, ID_to_s, 0);
rb_raise(rb_eArgError, "WMQ::Message#to_<%=struct_name.downcase%> Unknown symbol :%s supplied", RSTRING_PTR(val));
@@ -213,11 +183,11 @@
void Message_to_<%=struct_name.downcase%>(VALUE hash, <%=struct_name%>* p<%=struct_name.downcase%>)
{
rb_hash_foreach(hash, Message_to_<%=struct_name.downcase%>_each, (VALUE)p<%=struct_name.downcase%>);
}
-<% end # wmq_structs.each
+<% end # wmq_structs.each
%>
/* --------------------------------------------------------------------------
* Extract message data and headers
* --------------------------------------------------------------------------*/
@@ -238,14 +208,14 @@
%> /* <%=struct[:struct]%>: <%=struct[:header]%> */
if(strncmp(p_format, MQFMT_<%=struct[:header].upcase%>, MQ_FORMAT_LENGTH) == 0)
{
VALUE hash = rb_hash_new();
P<%=struct[:struct]%> p_header = (P<%=struct[:struct]%>)p_data;
-
+
if(trace_level>2)
printf("WMQ::Message#deblock Found <%=struct[:header]%>\n");
-
+
if(memcmp(p_header->StrucId, <%=struct[:struct_id] || "#{struct[:struct].upcase}_STRUC_ID"%>, sizeof(p_header->StrucId)) != 0)
{
if(trace_level>1)
printf("WMQ::Message#deblock MQFMT_<%=struct[:header].upcase%> received, but message does not contain <%=struct[:struct].upcase%>\n");
break; /* Bad Message received, do not deblock headers */
@@ -275,21 +245,21 @@
}
}
else
<%
end
- end # wmq_structs.each
+ end # wmq_structs.each
%> {
break;
}
}
/* Copy the last recognised header found to the Descriptor */
if(p_format && p_format != pmqmd->Format)
{
strncpy(pmqmd->Format, p_format, MQ_FORMAT_LENGTH);
}
-
+
Message_from_mqmd(descriptor, pmqmd);
rb_funcall(self, ID_descriptor_set, 1, descriptor);
rb_funcall(self, ID_headers_set, 1, headers);
rb_funcall(self, ID_data_set, 1, rb_str_new(p_data, data_length));
}
@@ -300,12 +270,12 @@
wmq_structs.each do |struct|
if struct[:header]
%> if(header_type == ID_<%=struct[:header]%>) { memcpy(p_format, MQFMT_<%=struct[:header].upcase%>, MQ_FORMAT_LENGTH); return;}
<%
end
- end # wmq_structs.each
-
+ end # wmq_structs.each
+
%>
rb_raise(rb_eArgError, "Invalid/Unknown header_type supplied in WMQ::Message#headers array");
}
/* --------------------------------------------------------------------------
@@ -330,11 +300,11 @@
static <%=struct[:struct]%> <%=struct[:struct]%>_DEF = {<%=struct[:struct]%>_DEFAULT};
<%=struct[:defaults]%>
if(parg->trace_level>2)
printf ("WMQ::Message#build_header Found <%=struct[:header]%>\n");
-
+
p_data = Message_autogrow_data_buffer(parg, sizeof(<%=struct[:struct]%>));
memcpy(p_data, &<%=struct[:struct]%>_DEF, sizeof(<%=struct[:struct]%>));
Message_to_<%=struct[:struct].downcase%>(hash, (P<%=struct[:struct]%>)p_data);
<% if struct[:format] != false%>
@@ -349,16 +319,16 @@
<% end %>
*(parg->p_data_offset) += sizeof(<%=struct[:struct]%>);
if(parg->trace_level>2)
printf ("WMQ::Message#build_header data offset:%ld\n", (long)(*(parg->p_data_offset)));
-<% end
+<% end
%> }
else
<%
end
- end # wmq_structs.each
-
+ end # wmq_structs.each
+
%> {
rb_raise(rb_eArgError, "Unknown :header_type supplied in WMQ::Message#headers array");
}
}
else