PROTON-799: Added the ClassWrapper mixin for the Ruby engine APIs. This mixin enables mapping an underlying C library engine class to the appropriate Ruby class type.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/113f6f6f Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/113f6f6f Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/113f6f6f Branch: refs/heads/ruby-engine-apis Commit: 113f6f6f18878b09b4f31278ca70dec268c36578 Parents: a655d2b Author: Darryl L. Pierce <mcpie...@gmail.com> Authored: Wed Feb 4 09:35:31 2015 -0500 Committer: Darryl L. Pierce <mcpie...@gmail.com> Committed: Thu May 14 15:57:10 2015 -0400 ---------------------------------------------------------------------- proton-c/bindings/ruby/lib/qpid_proton.rb | 1 + .../bindings/ruby/lib/util/class_wrapper.rb | 52 ++++++++++++++++++++ 2 files changed, 53 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/113f6f6f/proton-c/bindings/ruby/lib/qpid_proton.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/qpid_proton.rb b/proton-c/bindings/ruby/lib/qpid_proton.rb index 16394f9..9060b54 100644 --- a/proton-c/bindings/ruby/lib/qpid_proton.rb +++ b/proton-c/bindings/ruby/lib/qpid_proton.rb @@ -36,6 +36,7 @@ require "util/constants" require "util/swig_helper" require "util/condition" require "util/wrapper" +require "util/class_wrapper" require "util/engine" require "util/uuid" http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/113f6f6f/proton-c/bindings/ruby/lib/util/class_wrapper.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/util/class_wrapper.rb b/proton-c/bindings/ruby/lib/util/class_wrapper.rb new file mode 100644 index 0000000..134f655 --- /dev/null +++ b/proton-c/bindings/ruby/lib/util/class_wrapper.rb @@ -0,0 +1,52 @@ +#-- +# 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. +#++ + +module Qpid::Proton::Util + + # This mixin provides a method for mapping from an underlying Proton + # C library class to a Ruby class. + # + # @private + # + module ClassWrapper + + WRAPPERS = + { + "pn_void" => proc {|x| Cproton.pn_void2rb(x)}, + "pn_rbref" => proc {|x| Cproton.pn_void2rb(x)}, + "pn_connection" => proc {|x| Qpid::Proton::Connection.wrap(Cproton.pn_cast_pn_connection(x))}, + "pn_session" => proc {|x| Qpid::Proton::Session.wrap(Cproton.pn_cast_pn_session(x))}, + "pn_link" => proc {|x| Qpid::Proton::Link.wrap(Cproton.pn_cast_pn_link(x))}, + "pn_delivery" => proc {|x| Qpid::Proton::Delivery.wrap(Cproton.pn_cast_pn_delivery(x))}, + "pn_transport" => proc {|x| Qpid::Proton::Transport.wrap(Cproton.pn_cast_pn_transport(x))}, + "pn_selectable" => proc {|x| Qpid::Proton::Selectable.wrap(Cproton.pn_cast_pn_selectable(x))}, + } + + def class_wrapper(clazz, c_impl, &block) + proc_func = WRAPPERS[clazz] + if !proc_func.nil? + proc_func.yield(c_impl) + elsif block_given? + yield(c_impl) + end + end + + end + +end --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org