From: "Darryl L. Pierce" <[email protected]> The library file that's generated is named "cproton.so" to properly match what the Ruby VM expects when requiring the feature. --- examples/ruby/EXAMPLES | 1 + proton-c/bindings/CMakeLists.txt | 6 ++ proton-c/bindings/ruby/CMakeLists.txt | 33 +++++++ proton-c/bindings/ruby/cproton.i | 157 +++++++++++++++++++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 examples/ruby/EXAMPLES create mode 100644 proton-c/bindings/ruby/CMakeLists.txt create mode 100644 proton-c/bindings/ruby/cproton.i
diff --git a/examples/ruby/EXAMPLES b/examples/ruby/EXAMPLES new file mode 100644 index 0000000..468f072 --- /dev/null +++ b/examples/ruby/EXAMPLES @@ -0,0 +1 @@ +EXAMPLES: diff --git a/proton-c/bindings/CMakeLists.txt b/proton-c/bindings/CMakeLists.txt index 459c5d6..9bb644c 100644 --- a/proton-c/bindings/CMakeLists.txt +++ b/proton-c/bindings/CMakeLists.txt @@ -18,11 +18,17 @@ # include(UseSWIG) +include(FindRuby) # Build wrapper for Python: # @todo: conditionalize on whether python is available! add_subdirectory(python) +# Build wrapper for Ruby: +if (RUBY_FOUND) + add_subdirectory(ruby) +endif (RUBY_FOUND) + # Build wrapper for PHP # For now, assume PHP support if the 'php-config' tool is present. # @todo: allow user to specify which php-config if multiple PHP sources installed! diff --git a/proton-c/bindings/ruby/CMakeLists.txt b/proton-c/bindings/ruby/CMakeLists.txt new file mode 100644 index 0000000..b875e76 --- /dev/null +++ b/proton-c/bindings/ruby/CMakeLists.txt @@ -0,0 +1,33 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +include_directories (${RUBY_INCLUDE_PATH}) + +SWIG_ADD_MODULE(cproton ruby cproton.i) + +SWIG_LINK_LIBRARIES(cproton qpidproton ${LINK_DEPS} ${RUBY_LIBRARY}) + +ADD_CUSTOM_COMMAND(TARGET cproton + POST_BUILD + COMMAND cmake -E rename libcproton.so cproton.so) + +# TODO +# * Fix shared library name to be simply "cproton.so" since the +# "lib" prefix doesn't match the Ruby module name. + diff --git a/proton-c/bindings/ruby/cproton.i b/proton-c/bindings/ruby/cproton.i new file mode 100644 index 0000000..2bf4e36 --- /dev/null +++ b/proton-c/bindings/ruby/cproton.i @@ -0,0 +1,157 @@ +%module cproton + +%{ +#include <proton/engine.h> +#include <proton/message.h> +#include <proton/sasl.h> +#include <proton/driver.h> +#include <proton/messenger.h> +%} + +typedef unsigned int size_t; +typedef signed int ssize_t; +typedef unsigned char uint8_t; +typedef unsigned int uint32_t; +typedef unsigned long int uint64_t; +typedef int int32_t; + +%include <cstring.i> + +%cstring_output_withsize(char *OUTPUT, size_t *OUTPUT_SIZE) +%cstring_output_allocate_size(char **ALLOC_OUTPUT, size_t *ALLOC_SIZE, free(*$1)); + +%{ +#if !defined(RSTRING_LEN) +# define RSTRING_LEN(x) (RSTRING(X)->len) +# define RSTRING_PTR(x) (RSTRING(x)->ptr) +#endif +%} + +%typemap(in) pn_bytes_t { + if ($input == Qnil) { + $1.start = NULL; + $1.size = 0; + } else { + $1.start = RSTRING_PTR($input); + if (!$1.start) { + return NULL; + } + $1.size = RSTRING_LEN($input); + } +} + +%typemap(out) pn_bytes_t { + $result = rb_str_new($1.start, $1.size); +} + +%typemap (in) void * +{ + $1 = (void *) $input; +} + +%typemap (out) void * +{ + $result = (VALUE) $1; +} + +int pn_message_load(pn_message_t *msg, char *STRING, size_t LENGTH); +%ignore pn_message_load; + +int pn_message_load_data(pn_message_t *msg, char *STRING, size_t LENGTH); +%ignore pn_message_load_data; + +int pn_message_load_text(pn_message_t *msg, char *STRING, size_t LENGTH); +%ignore pn_message_load_text; + +int pn_message_load_amqp(pn_message_t *msg, char *STRING, size_t LENGTH); +%ignore pn_message_load_amqp; + +int pn_message_load_json(pn_message_t *msg, char *STRING, size_t LENGTH); +%ignore pn_message_load_json; + +int pn_message_encode(pn_message_t *msg, char *OUTPUT, size_t *OUTPUT_SIZE); +%ignore pn_message_encode; + +int pn_message_save(pn_message_t *msg, char *OUTPUT, size_t *OUTPUT_SIZE); +%ignore pn_message_save; + +int pn_message_save_data(pn_message_t *msg, char *OUTPUT, size_t *OUTPUT_SIZE); +%ignore pn_message_save_data; + +int pn_message_save_text(pn_message_t *msg, char *OUTPUT, size_t *OUTPUT_SIZE); +%ignore pn_message_save_text; + +int pn_message_save_amqp(pn_message_t *msg, char *OUTPUT, size_t *OUTPUT_SIZE); +%ignore pn_message_save_amqp; + +int pn_message_save_json(pn_message_t *msg, char *OUTPUT, size_t *OUTPUT_SIZE); +%ignore pn_message_save_json; + +ssize_t pn_send(pn_link_t *transport, char *STRING, size_t LENGTH); +%ignore pn_send; + +%rename(pn_recv) wrap_pn_recv; +%inline %{ + int wrap_pn_recv(pn_link_t *link, char *OUTPUT, size_t *OUTPUT_SIZE) { + ssize_t sz = pn_recv(link, OUTPUT, *OUTPUT_SIZE); + if (sz >= 0) { + *OUTPUT_SIZE = sz; + } else { + *OUTPUT_SIZE = 0; + } + return sz; + } +%} +%ignore pn_recv; + +ssize_t pn_input(pn_transport_t *transport, char *STRING, size_t LENGTH); +%ignore pn_input; + +%rename(pn_output) wrap_pn_output; +%inline %{ + int wrap_pn_output(pn_transport_t *transport, char *OUTPUT, size_t *OUTPUT_SIZE) { + ssize_t sz = pn_output(transport, OUTPUT, *OUTPUT_SIZE); + if (sz >= 0) { + *OUTPUT_SIZE = sz; + } else { + *OUTPUT_SIZE = 0; + } + return sz; + } +%} +%ignore pn_output; + +%rename(pn_delivery) wrap_pn_delivery; +%inline %{ + pn_delivery_t *wrap_pn_delivery(pn_link_t *link, char *STRING, size_t LENGTH) { + return pn_delivery(link, pn_dtag(STRING, LENGTH)); + } +%} +%ignore pn_delivery; + +%rename(pn_delivery_tag) wrap_pn_delivery_tag; +%inline %{ + void wrap_pn_delivery_tag(pn_delivery_t *delivery, char **ALLOC_OUTPUT, size_t *ALLOC_SIZE) { + pn_delivery_tag_t tag = pn_delivery_tag(delivery); + *ALLOC_OUTPUT = malloc(tag.size); + *ALLOC_SIZE = tag.size; + memcpy(*ALLOC_OUTPUT, tag.bytes, tag.size); + } +%} +%ignore pn_delivery_tag; + +%rename(pn_message_data) wrap_pn_message_data; +%inline %{ + int wrap_pn_message_data(char *STRING, size_t LENGTH, char *OUTPUT, size_t *OUTPUT_SIZE) { + ssize_t sz = pn_message_data(OUTPUT, *OUTPUT_SIZE, STRING, LENGTH); + if (sz >= 0) { + *OUTPUT_SIZE = sz; + } else { + *OUTPUT_SIZE = 0; + } + return sz; + } +%} +%ignore pn_message_data; + +%include "../cproton.i" -- 1.7.10.4 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
