You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mc...@apache.org on 2015/05/19 21:19:18 UTC

[01/15] qpid-proton git commit: PROTON-799: Test for the Wrapper and rbkey system

Repository: qpid-proton
Updated Branches:
  refs/heads/ruby-engine-apis b3ec4a3ec -> a26150ece (forced update)


PROTON-799: Test for the Wrapper and rbkey system


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/a26150ec
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/a26150ec
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/a26150ec

Branch: refs/heads/ruby-engine-apis
Commit: a26150ecefdf77c3828ff44cd8cc084de40256f5
Parents: eff40cc
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu May 14 15:57:02 2015 -0400
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 examples/ruby/wrapper_test.rb             | 82 ++++++++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb |  1 +
 2 files changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a26150ec/examples/ruby/wrapper_test.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/wrapper_test.rb b/examples/ruby/wrapper_test.rb
new file mode 100644
index 0000000..ca7e250
--- /dev/null
+++ b/examples/ruby/wrapper_test.rb
@@ -0,0 +1,82 @@
+#--
+# 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.
+#++
+
+require 'qpid_proton'
+
+def how_many_transports?(expected)
+  count = ObjectSpace.each_object(Qpid::Proton::Transport).count
+  if expected.min == expected.max
+    expectation = "#{expected.min}"
+  else
+    expectation = "#{expected.min} <= count <= #{expected.max}"
+  end
+  puts "Transport count: found #{count}, expected #{expectation} (#{expected.include?(count) ? 'Good' : 'Bad'})"
+end
+
+transport = Qpid::Proton::Transport.new
+timpl = transport.impl
+
+puts "================================="
+puts "= Storing my original transport ="
+puts "================================="
+puts "   Stored transport=#{transport} (#{Cproton.pni_address_of(timpl).to_s(16)})"
+how_many_transports?(1..1)
+puts "================================="
+transport.instance_eval { @first_name = "Darryl"; @last_name = "Pierce", @instance_id = 717 }
+transport = nil
+
+
+puts ""
+max = 1000
+puts "Creating #{max} instances of Transport"
+(0...max).each do |which|
+  t = Qpid::Proton::Transport.new
+  t.instance_eval { @instance_id = which }
+  t = nil
+end
+
+puts ""
+puts "===================================="
+puts "= Retrieving my original transport ="
+puts "===================================="
+transport = Qpid::Proton::Transport.wrap(timpl)
+puts "Retrieved transport=#{transport} (#{Cproton.pni_address_of(timpl).to_s(16)})"
+how_many_transports?(1..1001)
+puts "===================================="
+puts "My transport attributes:"
+puts transport
+
+transport = nil
+GC.start
+how_many_transports?(1..1)
+
+puts ""
+puts "======================================"
+puts "= Throwing away the Transport object ="
+puts "======================================"
+transport = nil
+timpl.instance_eval { @proton_wrapper = nil }
+GC.start
+begin
+  transport = Qpid::Proton::Transport.wrap(timpl)
+  puts "!!! This should fail!"
+rescue Qpid::Proton::ProtonError => error
+  puts "Good, it failed..."
+end
+how_many_transports?(0..0)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a26150ec/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 58b95d0..467d959 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -19,6 +19,7 @@
 
 require "cproton"
 require "date"
+require "weakref"
 
 if RUBY_VERSION < "1.9"
 require "kconv"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[08/15] qpid-proton git commit: PROTON-799: Added the Connection class to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the Connection class to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/14a6803b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/14a6803b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/14a6803b

Branch: refs/heads/ruby-engine-apis
Commit: 14a6803b240ef8fcb74c78a734025e9e74461fa6
Parents: 7cb84fd
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Fri Jan 16 15:13:04 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/connection.rb | 328 +++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb     |   1 +
 2 files changed, 329 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/14a6803b/proton-c/bindings/ruby/lib/core/connection.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/connection.rb b/proton-c/bindings/ruby/lib/core/connection.rb
new file mode 100644
index 0000000..252193d
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -0,0 +1,328 @@
+#--
+# 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
+
+  # A Connection option has at most one Qpid::Proton::Transport instance.
+  #
+  class Connection < Endpoint
+
+    # @private
+    include Util::SwigHelper
+
+    # @private
+    PROTON_METHOD_PREFIX = "pn_connection"
+
+    # @!attribute hostname
+    #
+    # @return [String] The AMQP hostname for the connection.
+    #
+    proton_accessor :hostname
+
+    # @private
+    proton_reader :attachments
+
+    attr_accessor :overrides
+    attr_accessor :session_policy
+
+    # @private
+    include Util::Wrapper
+
+    # @private
+    def self.wrap(impl)
+      return nil if impl.nil?
+
+      self.fetch_instance(impl, :pn_connection_attachments) || Connection.new(impl)
+    end
+
+    # Constructs a new instance of Connection.
+    #
+    # You do *not* need to provide the underlying C struct, as this is
+    # automatically generated as needed. The argument is a convenience
+    # for returning existing Connection objects.
+    #
+    # @param impl [pn_connection_t] The pn_connection_t struct.
+    #
+    def initialize(impl = Cproton.pn_connection)
+      super()
+      @impl = impl
+      @offered_capabilities = nil
+      @desired_capabilities = nil
+      @properties = nil
+      @overrides = nil
+      @collector = nil
+      @session_policy = nil
+      self.class.store_instance(self, :pn_connection_attachments)
+    end
+
+    def overrides?
+      !@overrides.nil?
+    end
+
+    def session_policy?
+      !@session_policy.nil?
+    end
+
+    # This method is used when working within the context of an event.
+    #
+    # @return [Connection] The connection itself.
+    #
+    def connection
+      self
+    end
+
+    # The Transport to which this connection is bound.
+    #
+    # @return [Transport] The transport, or nil if the Connection is unbound.
+    #
+    def transport
+      Transport.wrap(Cproton.pn_connection_transport(@impl))
+    end
+
+    # Associates the connection with an event collector.
+    #
+    # By doing this, key changes in the endpoint's state are reported to
+    # the connector via Event objects that can be inspected and processed.
+    #
+    # Note that, by registering a collector, the user is requesting that an
+    # indefinite number of events be queued up on its behalf. This means
+    # that, unless the application eventual processes these events, the
+    # storage requirements for keeping them will grow without bound. So be
+    # careful and do not register a collector with a connection unless the
+    # application will process the events.
+    #
+    # @param collector [Event::Collector] The event collector.
+    #
+    def collect(collector)
+      if collector.nil?
+        Cproton.pn_connection_collect(@impl, nil)
+      else
+        Cproton.pn_connection_collect(@impl, collector.impl)
+      end
+      @collector = collector
+    end
+
+    # Get the AMQP container name advertised by the remote connection
+    # endpoint.
+    #
+    # This will return nil until the REMOTE_ACTIVE state is reached.
+    #
+    # Any non-nil container returned by this operation will be valid
+    # until the connection is unbound from a transport, or freed,
+    # whichever happens sooner.
+    #
+    # @return [String] The remote connection's AMQP container name.
+    #
+    # @see #container
+    #
+    def remote_container
+      Cproton.pn_connection_remote_container(@impl)
+    end
+
+    def container=(name)
+      Cproton.pn_connection_set_container(@impl, name)
+    end
+
+    def container
+      Cproton.pn_connection_get_container(@impl)
+    end
+
+    # Get the AMQP hostname set by the remote connection endpoint.
+    #
+    # This will return nil until the #REMOTE_ACTIVE state is
+    # reached.
+    #
+    # @return [String] The remote connection's AMQP hostname.
+    #
+    # @see #hostname
+    #
+    def remote_hostname
+      Cproton.pn_connection_remote_hostname(@impl)
+    end
+
+    # Get the AMQP offered capabilities suppolied by the remote connection
+    # endpoint.
+    #
+    # This object returned is valid until the connection is freed. The Data
+    # object will be empty until the remote connection is opened, as
+    # indicated by the #REMOTE_ACTIVE flag.
+    #
+    # @return [Data] The offered capabilities.
+    #
+    def remote_offered_capabilities
+      data_to_object(Cproton.pn_connection_remote_offered_capabilities(@impl))
+    end
+
+    # Get the AMQP desired capabilities supplied by the remote connection
+    # endpoint.
+    #
+    # The object returned is valid until the connection is freed. The Data
+    # object will be empty until the remote connection is opened, as
+    # indicated by the #REMOTE_ACTIVE flag.
+    #
+    # @return [Data] The desired capabilities.
+    #
+    def remote_desired_capabilities
+      data_to_object(Cproton.pn_connection_remote_desired_capabilities(@impl))
+    end
+
+    # Get the AMQP connection properties supplie by the remote connection
+    # endpoint.
+    #
+    # The object returned is valid until the connection is freed. The Data
+    # object will be empty until the remote connection is opened, as
+    # indicated by the #REMOTE_ACTIVE flag.
+    #
+    # @return [Data] The remote properties.
+    #
+    def remote_properties
+      data_to_object(Cproton.pn_connection_remote_properites(@impl))
+    end
+
+    # Opens the connection.
+    #
+    def open
+      object_to_data(@offered_capabilities,
+                     Cproton.pn_connection_offered_capabilities(@impl))
+      object_to_data(@desired_capabilities,
+                     Cproton.pn_connection_desired_capabilities(@impl))
+      object_to_data(@properties,
+                     Cproton.pn_connection_properties(@impl))
+      Cproton.pn_connection_open(@impl)
+    end
+
+    # Closes the connection.
+    #
+    # Once this operation has completed, the #LOCAL_CLOSED state flag will be
+    # set.
+    #
+    def close
+      self._update_condition
+      Cproton.pn_connection_close(@impl)
+    end
+
+    # Gets the endpoint current state flags
+    #
+    # @see Endpoint#LOCAL_UNINIT
+    # @see Endpoint#LOCAL_ACTIVE
+    # @see Endpoint#LOCAL_CLOSED
+    # @see Endpoint#LOCAL_MASK
+    #
+    # @return [Fixnum] The state flags.
+    #
+    def state
+      Cproton.pn_connection_state(@impl)
+    end
+
+    # Returns the session for this connection.
+    #
+    # @return [Session] The session.
+    #
+    def session
+      @session ||= Session.wrap(Cproton.pn_session(@impl))
+    end
+
+    # Returns the first session from the connection that matches the specified
+    # state mask.
+    #
+    # Examines the state of each session owned by the connection, and returns
+    # the first session that matches the given state mask. If the state mask
+    # contains *both* local and remote flags, then an exact match against
+    # those flags is performed. If the state mask contains only local *or*
+    # remote flags, then a match occurs if a*any* of the local or remote flags
+    # are set, respectively.
+    #
+    # @param mask [Fixnum] The state mask to be matched.
+    #
+    # @return [Session] The first matching session, or nil if none matched.
+    #
+    # @see Endpoint#LOCAL_UNINIT
+    # @see Endpoint#LOCAL_ACTIVE
+    # @see Endpoint#LOCAL_CLOSED
+    # @see Endpoint#REMOTE_UNINIT
+    # @see Endpoint#REMOTE_ACTIVE
+    # @see Endpoint#REMOTE_CLOSED
+    #
+    def session_head(mask)
+      Session.wrap(Cproton.pn_session_header(@impl, mask))
+    end
+
+    # Returns the first link that matches the given state mask.
+    #
+    # Examines the state of each link owned by the connection and returns the
+    # first that matches the given state mask. If the state mask contains
+    # *both* local and remote flags, then an exact match against those flags
+    # is performed. If the state mask contains *only* local or remote flags,
+    # then a match occurs if *any* of the local ore remote flags are set,
+    # respectively.
+    #
+    # @param mask [Fixnum] The state mask to be matched.
+    #
+    # @return [Link] The first matching link, or nil if none matched.
+    #
+    # @see Endpoint#LOCAL_UNINIT
+    # @see Endpoint#LOCAL_ACTIVE
+    # @see Endpoint#LOCAL_CLOSED
+    # @see Endpoint#REMOTE_UNINIT
+    # @see Endpoint#REMOTE_ACTIVE
+    # @see Endpoint#REMOTE_CLOSED
+    #
+    def link_head(mask)
+      Link.wrap(Cproton.pn_link_head(@impl, mask))
+    end
+
+    # Extracts the first delivery on the connection that has pending
+    # operations.
+    #
+    # A readable delivery indicates message data is waiting to be read. A
+    # A writable delivery indcates that message data may be sent. An updated
+    # delivery indicates that the delivery's disposition has changed.
+    #
+    # A delivery will never be *both* readable and writable, but it may be
+    # both readable or writable and updated.
+    #
+    # @return [Delivery] The delivery, or nil if none are available.
+    #
+    # @see Delivery#next
+    #
+    def work_head
+      Delivery.wrap(Cproton.pn_work_head(@impl))
+    end
+
+    # Returns the code for a connection error.
+    #
+    # @return [Fixnum] The error code.
+    #
+    def error
+      Cproton.pn_error_code(Cproton.pn_connection_error(@impl))
+    end
+
+    # @private
+    def _local_condition
+      Cproton.pn_connection_condition(@impl)
+    end
+
+    # @private
+    def _remote_condition
+      Cproton.pn_connection_remote_condition(@impl)
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/14a6803b/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 ed8532f..2a57b32 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -62,6 +62,7 @@ require "core/delivery"
 require "core/link"
 require "core/sender"
 require "core/receiver"
+require "core/connection"
 
 # Messenger API classes
 require "messenger/filters"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[13/15] qpid-proton git commit: PROTON-799: Added the Event classes to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the Event classes to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b296a8b3
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b296a8b3
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b296a8b3

Branch: refs/heads/ruby-engine-apis
Commit: b296a8b33c53c7a33ff10c65a37153d98c303d56
Parents: 53ee768
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Feb 3 17:17:18 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/event/event.rb      | 296 ++++++++++++++++++++
 proton-c/bindings/ruby/lib/event/event_base.rb |  91 ++++++
 proton-c/bindings/ruby/lib/event/event_type.rb |  71 +++++
 proton-c/bindings/ruby/lib/qpid_proton.rb      |   3 +
 4 files changed, 461 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b296a8b3/proton-c/bindings/ruby/lib/event/event.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/event/event.rb b/proton-c/bindings/ruby/lib/event/event.rb
new file mode 100644
index 0000000..dd5d869
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/event/event.rb
@@ -0,0 +1,296 @@
+#--
+# 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
+
+  module Event
+
+    # @private
+    def self.event_type(const_name, method_name = nil) # :nodoc:
+      unless Cproton.const_defined?(const_name)
+        raise RuntimeError.new("no such constant: #{const_name}")
+      end
+
+      const_value = Cproton.const_get(const_name)
+      method_name = "on_#{const_name.to_s[3..-1]}".downcase if method_name.nil?
+
+      EventType.new(const_value, method_name)
+    end
+
+    # Defined as a programming convenience. No even of this type will ever
+    # be generated.
+    NONE = event_type(:PN_EVENT_NONE)
+
+    # A timer event has occurred.
+    TIMER_TASK = event_type(:PN_TIMER_TASK)
+
+    # A connection has been created. This is the first even that will ever
+    # be issued for a connection.
+    CONNECTION_INIT = event_type(:PN_CONNECTION_INIT)
+    # A conneciton has been bound toa  transport.
+    CONNECTION_BOUND = event_type(:PN_CONNECTION_BOUND)
+    # A connection has been unbound from its transport.
+    CONNECTION_UNBOUND = event_type(:PN_CONNECTION_UNBOUND)
+    # A local connection endpoint has been opened.
+    CONNECTION_LOCAL_OPEN = event_type(:PN_CONNECTION_LOCAL_OPEN)
+    # A local connection endpoint has been closed.
+    CONNECTION_LOCAL_CLOSE = event_type(:PN_CONNECTION_LOCAL_CLOSE)
+    # A remote endpoint has opened its connection.
+    CONNECTION_REMOTE_OPEN = event_type(:PN_CONNECTION_REMOTE_OPEN)
+    # A remote endpoint has closed its connection.
+    CONNECTION_REMOTE_CLOSE = event_type(:PN_CONNECTION_REMOTE_CLOSE)
+    # A connection has been freed and any outstanding processing has been
+    # completed. This is the final event htat will ever be issued for a
+    # connection
+    CONNECTION_FINAL = event_type(:PN_CONNECTION_FINAL)
+
+    # A session has been created. This is the first event that will ever be
+    # issues for a session.
+    SESSION_INIT = event_type(:PN_SESSION_INIT)
+    # A local session endpoint has been opened.
+    SESSION_LOCAL_OPEN = event_type(:PN_SESSION_LOCAL_OPEN)
+    # A local session endpoint has been closed.
+    SESSION_LOCAL_CLOSE = event_type(:PN_SESSION_LOCAL_CLOSE)
+    # A remote endpoint has opened its session.
+    SESSION_REMOTE_OPEN = event_type(:PN_SESSION_REMOTE_OPEN)
+    # A remote endpoint has closed its session.
+    SESSION_REMOTE_CLOSE = event_type(:PN_SESSION_REMOTE_CLOSE)
+    # A session has been freed and any outstanding processing has been
+    # completed. This is the final event that will ever be issued for a
+    # session
+    SESSION_FINAL = event_type(:PN_SESSION_FINAL)
+
+    # A link has been created. This is the first event that will ever be
+    # issued for a link.
+    LINK_INIT = event_type(:PN_LINK_INIT)
+    # A local link endpoint has been opened.
+    LINK_LOCAL_OPEN = event_type(:PN_LINK_LOCAL_OPEN)
+    # A local link endpoint has been closed.
+    LINK_LOCAL_CLOSE = event_type(:PN_LINK_LOCAL_CLOSE)
+    # A local link endpoint has been detached.
+    LINK_LOCAL_DETACH = event_type(:PN_LINK_LOCAL_DETACH)
+    # A remote endpoint has opened its link.
+    LINK_REMOTE_OPEN = event_type(:PN_LINK_REMOTE_OPEN)
+    # A remote endpoint has closed its link.
+    LINK_REMOTE_CLOSE = event_type(:PN_LINK_REMOTE_CLOSE)
+    # A remote endpoint has detached its link.
+    LINK_REMOTE_DETACH = event_type(:PN_LINK_REMOTE_DETACH)
+    # The flow control state for a link has changed.
+    LINK_FLOW = event_type(:PN_LINK_FLOW)
+    # A link has been freed and any outstanding processing has been completed.
+    # This is the final event htat will ever be issued for a link.
+    LINK_FINAL = event_type(:PN_LINK_FINAL)
+
+    # A delivery has been created or updated.
+    DELIVERY = event_type(:PN_DELIVERY)
+
+    # A transport has new data to read and/or write.
+    TRANSPORT = event_type(:PN_TRANSPORT)
+    # Indicates that a transport error has occurred.
+    # @see Transport#condition To access the details of the error.
+    TRANSPORT_ERROR = event_type(:PN_TRANSPORT_ERROR)
+    # Indicates that the head of a transport has been closed. This means the
+    # transport will never produce more bytes for output to the network.
+    TRANSPORT_HEAD_CLOSED = event_type(:PN_TRANSPORT_HEAD_CLOSED)
+    # Indicates that the trail of a transport has been closed. This means the
+    # transport will never be able to process more bytes from the network.
+    TRANSPORT_TAIL_CLOSED = event_type(:PN_TRANSPORT_TAIL_CLOSED)
+    # Indicates that both the head and tail of a transport are closed.
+    TRANSPORT_CLOSED = event_type(:PN_TRANSPORT_CLOSED)
+
+    SELECTABLE_INIT = event_type(:PN_SELECTABLE_INIT)
+    SELECTABLE_UPDATED = event_type(:PN_SELECTABLE_UPDATED)
+    SELECTABLE_READABLE = event_type(:PN_SELECTABLE_READABLE)
+    SELECTABLE_WRITABLE = event_type(:PN_SELECTABLE_WRITABLE)
+    SELECTABLE_EXPIRED = event_type(:PN_SELECTABLE_EXPIRED)
+    SELECTABLE_ERROR = event_type(:PN_SELECTABLE_ERROR)
+    SELECTABLE_FINAL = event_type(:PN_SELECTABLE_FINAL)
+
+    # An Event provides notification of a state change within the protocol
+    # engine.
+    #
+    # Every event has a type that identifies what sort of state change has
+    # occurred, along with a pointer to the object whose state has changed,
+    # and also any associated objects.
+    #
+    # For more details on working with Event, please refer to Collector.
+    #
+    # @see Qpid::Proton::Event The list of predefined events.
+    #
+    class Event < EventBase
+
+      # @private
+      include Qpid::Proton::Util::ClassWrapper
+      # @private
+      include Qpid::Proton::Util::Wrapper
+
+      # Creates a Ruby object for the given pn_event_t.
+      #
+      # @private
+      def self.wrap(impl, number = nil)
+        return nil if impl.nil?
+
+        result = self.fetch_instance(impl, :pn_event_attachments)
+        return result unless result.nil?
+        number = Cproton.pn_event_type(impl) if number.nil?
+        event = Event.new(impl, number)
+        return event.context if event.context.is_a? EventBase
+        return event
+      end
+
+      # @private
+      def initialize(impl, number)
+        @impl = impl
+        class_name = Cproton.pn_class_name(Cproton.pn_event_class(impl))
+        context = class_wrapper(class_name, Cproton.pn_event_context(impl))
+        event_type = EventType.by_type(Cproton.pn_event_type(impl))
+        super(class_name, context, event_type)
+        @type = EventType.by_type(number)
+        self.class.store_instance(self, :pn_event_attachments)
+      end
+
+      # Notifies the handler(s) of this event.
+      #
+      # If a handler responds to the event's method then that method is invoked
+      # and passed the event. Otherwise, if the handler defines the
+      # +on_unhandled+ method, then that will be invoked instead.
+      #
+      # If the handler defines a +handlers+ method then that will be invoked and
+      # passed the event afterward.
+      #
+      # @example
+      #
+      #   class FallbackEventHandler
+      #
+      #     # since it now defines a handlers method, any event will iterate
+      #     # through them and invoke the +dispatch+ method on each
+      #     attr_accessor handlers
+      #
+      #     def initialize
+      #       @handlers = []
+      #     end
+      #
+      #     # invoked for any event not otherwise handled
+      #     def on_unhandled(event)
+      #       puts "Unable to invoke #{event.type.method} on #{event.context}."
+      #     end
+      #
+      #   end
+      #
+      # @param handler [Object] An object which implements either the event's
+      #    handler method or else responds to :handlers with an array of other
+      #    handlers.
+      #
+      def dispatch(handler, type = nil)
+        type = @type if type.nil?
+        #notify any and all attached handlers
+        if handler.respond_to?(:handlers?) && handler.handlers?
+          handler.handlers.each {|hndlr| self.dispatch(hndlr, type)}
+        end
+        if handler.respond_to?(type.method)
+          handler.__send__(type.method, self)
+        elsif handler.respond_to?(:on_unhandled)
+          handler.on_unhandled(self)
+        end
+      end
+
+      # Returns the transport for this event.
+      #
+      # @return [Transport, nil] The transport.
+      #
+      def transport
+        Qpid::Proton::Transport.wrap(Cproton.pn_event_transport(@impl))
+      end
+
+      # Returns the Connection for this event.
+      #
+      # @return [Connection, nil] The connection.
+      #
+      def connection
+        Qpid::Proton::Connection.wrap(Cproton.pn_event_connection(@impl))
+      end
+
+      # Returns the Session for this event.
+      #
+      # @return [Session, nil] The session
+      #
+      def session
+        Qpid::Proton::Session.wrap(Cproton.pn_event_session(@impl))
+      end
+
+      # Returns the Link for this event.
+      #
+      # @return [Link, nil] The link.
+      #
+      def link
+        Qpid::Proton::Link.wrap(Cproton.pn_event_link(@impl))
+      end
+
+      # Returns the Sender, or nil if there is no Link, associated  with this
+      # event if that link is a sender.
+      #
+      # @return [Sender, nil] The sender.
+      #
+      def sender
+        return self.link if !self.link.nil? && self.link.sender?
+      end
+
+      # Returns the Receiver, or nil if there is no Link, associated with this
+      # event if that link is a receiver.
+      #
+      # @return [Receiver, nil] The receiver.
+      #
+      def receiver
+        return self.link if !self.link.nil? && self.link.receiver?
+      end
+
+      # Returns the Delivery associated with this event.
+      #
+      # @return [Delivery, nil] The delivery.
+      #
+      def delivery
+        Qpid::Proton::Delivery.wrap(Cproton.pn_event_delivery(@impl))
+      end
+
+      # Sets the message.
+      #
+      # @param message [Qpid::Proton::Message] The message
+      #
+      def message=(message)
+        @message = message
+      end
+
+      # Returns the message.
+      #
+      # @return [Qpid::Proton::Message] The message.
+      #
+      def message
+        @message
+      end
+
+      # @private
+      def to_s
+        "#{self.type}(#{self.context})"
+      end
+
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b296a8b3/proton-c/bindings/ruby/lib/event/event_base.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/event/event_base.rb b/proton-c/bindings/ruby/lib/event/event_base.rb
new file mode 100644
index 0000000..6ae6959
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/event/event_base.rb
@@ -0,0 +1,91 @@
+#--
+# 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::Event
+
+  # @private
+  def self.dispatch(handler, method, *args)
+    args = args.last unless args.nil?
+    if handler.respond_to? method.to_sym
+      return handler.__send__(method, args)
+    elsif handler.respond_to? :on_unhandled
+      return handler.__send__(:on_unhandled, method, args)
+    end
+  end
+
+  # EventBase is the foundation for creating application-specific events.
+  #
+  # @example
+  #
+  #   # SCENARIO: A continuation of the example in EventType.
+  #   #
+  #   #           An Event class is defined to handle receiving encrypted
+  #   #           data from a remote endpoint.
+  #
+  #   class EncryptedDataEvent < EventBase
+  #     def initialize(message)
+  #       super(EncryptedDataEvent, message,
+  #             Qpid::Proton::Event::ENCRYPTED_RECV)
+  #     end
+  #   end
+  #
+  #   # at another point, when encrypted data is received
+  #   msg = Qpid::Proton::Message.new
+  #   msg.decode(link.receive(link.pending))
+  #   if encrypted?(msg)
+  #     collector.put(EncryptedDataEvent.new(msg)
+  #   end
+  #
+  # @see EventType The EventType class for how ENCRYPTED_RECV was defined.
+  #
+  class EventBase
+
+    # Returns the name for the class associated with this event.
+    attr_reader :class_name
+
+    # Returns the associated context object for the event.
+    attr_reader :context
+
+    # Returns the type of the event.
+    attr_reader :type
+
+    # Creates a new event with the specific class_name and context of the
+    # specified type.
+    #
+    # @param class_name [String] The name of the class.
+    # @param context [Object] The event context.
+    # @param type [EventType] The event type.
+    #
+    def initialize(class_name, context, type)
+      @class_name = class_name
+      @context = context
+      @type = type
+    end
+
+    # Invokes the type-specific method on the provided handler.
+    #
+    # @param handler [Object] The handler to be notified of this event.
+    #
+    def dispatch(handler)
+      Qpid::Proton.dispatch(handler, @type.method, self)
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b296a8b3/proton-c/bindings/ruby/lib/event/event_type.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/event/event_type.rb b/proton-c/bindings/ruby/lib/event/event_type.rb
new file mode 100644
index 0000000..aa5944d
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/event/event_type.rb
@@ -0,0 +1,71 @@
+#--
+# 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::Event
+
+  # Manages the association between an Event and the method which should
+  # process on the context object associated with an occurance of the event.
+  #
+  # Each type is identified by a unique #type value.
+  #
+  # @example
+  #
+  #   # SCENARIO: A part of an application handles extracting and decrypting
+  #   #            data received from a remote endpoint.
+  #   #
+  #   #            An EventType is created to notify handlers that such a
+  #   #            situation has occurred.
+  #
+  #   ENCRYPTED_RECV = 10000 # the unique constant value for the event
+  #
+  #   # create a new event type which, when it occurs, invokes a method
+  #   # named :on_encrypted_data when a handler is notified of its occurrance
+  #   Qpid::Proton::Event::ENCRYPTED_RECV =
+  #     Qpid::Proton::Event::EventType.new(ENCRYPTED_RECV, :on_encrypted_data)
+  #
+  # @see EventBase EventBase for the rest of this example.
+  # @see Qpid::Proton::Event::Event The Event class for more details on events.
+  #
+  class EventType
+
+    # The method to invoke on any potential handler.
+    attr_reader :method
+    attr_reader :number
+
+    def initialize(number, method)
+      @number = number
+      @name = Cproton.pn_event_type_name(@number)
+      @method = method
+      @@types ||= {}
+      @@types[number] = self
+    end
+
+    # @private
+    def to_s
+      @name
+    end
+
+    # @private
+    def self.by_type(type) # :nodoc:
+      @@types[type]
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b296a8b3/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 9060b54..58b95d0 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -51,6 +51,9 @@ require "codec/mapping"
 require "codec/data"
 
 # Event API classes
+require "event/event_type"
+require "event/event_base"
+require "event/event"
 require "event/collector"
 
 # Main Proton classes


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[12/15] qpid-proton git commit: PROTON-799: Added the SSL classes to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the SSL classes to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/d296c27b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/d296c27b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/d296c27b

Branch: refs/heads/ruby-engine-apis
Commit: d296c27b0661c1ae7ce5d96d65306bf007a897d3
Parents: f03827d
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Apr 29 16:45:05 2015 -0400
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/exceptions.rb  |   6 +
 proton-c/bindings/ruby/lib/core/ssl.rb         | 160 ++++++++++++++++++++
 proton-c/bindings/ruby/lib/core/ssl_details.rb |  33 ++++
 proton-c/bindings/ruby/lib/core/ssl_domain.rb  | 156 +++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb      |   3 +
 proton-c/bindings/ruby/ruby.i                  |  14 ++
 6 files changed, 372 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d296c27b/proton-c/bindings/ruby/lib/core/exceptions.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/exceptions.rb b/proton-c/bindings/ruby/lib/core/exceptions.rb
index 714830b..2695709 100644
--- a/proton-c/bindings/ruby/lib/core/exceptions.rb
+++ b/proton-c/bindings/ruby/lib/core/exceptions.rb
@@ -100,6 +100,12 @@ module Qpid
     class LinkError < ProtonError
     end
 
+    class SSLError < TransportError
+    end
+
+    class SSLUnavailableError < SSLError
+    end
+
   end
 
 end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d296c27b/proton-c/bindings/ruby/lib/core/ssl.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/ssl.rb b/proton-c/bindings/ruby/lib/core/ssl.rb
new file mode 100644
index 0000000..9c4a3e9
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/ssl.rb
@@ -0,0 +1,160 @@
+#--
+# 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
+
+  # The SSL support for Transport.
+  #
+  # A Transport may be configured ot use SLL for encryption and/or
+  # authentication. A Transport can be configured as either the SSL
+  # client or the server. An SSL client is the party that proctively
+  # establishes a connection to an SSL server. An SSL server is the
+  # party that accepts a connection request from the remote SSL client.
+  #
+  # If either the client or the server needs to identify itself with the
+  # remote node, it must have its SSL certificate configured.
+  #
+  # @see SSLDomain#credentials For setting the SSL certificate.
+  #
+  # If either the client or the server needs to verify the identify of the
+  # remote node, it must have its database of trusted CAs configured.
+  #
+  # @see SSLDomain#trusted_ca_db Setting the CA database.
+  #
+  # An SSL server connection may allow the remote client to connect without
+  # SS (i.e., "in the clear").
+  #
+  # @see SSLDomain#allow_unsecured_client Allowing unsecured clients.
+  #
+  # The level of verification required of the remote may be configured.
+  #
+  # @see SSLDomain#peer_authentication Setting peer authentication.
+  #
+  # Support for SSL client session resume is provided as well.
+  #
+  # @see SSLDomain
+  # @see #resume_status
+  #
+  class SSL
+
+    # Session resume state is unkonnwn or not supported.
+    RESUME_UNKNOWN = Cproton::PN_SSL_RESUME_UNKNOWN
+    # Session renegotiated and not resumed.
+    RESUME_NEW = Cproton::PN_SSL_RESUME_NEW
+    # Session resumed from the previous session.
+    RESUME_REUSED = Cproton::PN_SSL_RESUME_REUSED
+
+    # @private
+    include Util::SwigHelper
+
+    # @private
+    PROTON_METHOD_PREFIX = "pn_ssl"
+
+    # @!attribute peer_hostname
+    #
+    # @return [String] The peer hostname.
+    proton_accessor :peer_hostname
+
+    # @private
+    include Util::ErrorHandler
+
+    can_raise_error :peer_hostname=, :error_class => SSLError
+
+    # Returns whether SSL is supported.
+    #
+    # @return [Boolean] True if SSL support is available.
+    #
+    def self.present?
+      Cproton.pn_ssl_present
+    end
+
+    # @private
+    def self.create(transport, domain, session_details = nil)
+      result = nil
+      # like python, make sure we're not creating a different SSL
+      # object for a transport with an existing SSL object
+      if transport.ssl?
+        transport.instance_eval { result = @ssl }
+        if ((!domain.nil? && (result.domain != domain)) ||
+            (!session_details.nil? && (result.session_details != session_details)))
+          raise SSLException.new("cannot re-configure existing SSL object")
+        end
+      else
+        impl = Cproton.pn_ssl(transport.impl)
+        session_id = nil
+        session_id = session_details.session_id unless session_details.nil?
+        result = SSL.new(impl, domain, session_details, session_id)
+      end
+      return result
+    end
+
+    private
+
+    def initialize(impl, domain, session_details, session_id)
+      @impl = impl
+      @domain = domain
+      @session_details = session_details
+      @session_id = session_id
+      Cproton.pn_ssl_init(@impl, @domain.impl, @session_id)
+    end
+
+    public
+
+    # Returns the cipher name that is currently in used.
+    #
+    # Gets the text description of the cipher that is currently active, or
+    # returns nil if SSL is not active. Note that the cipher in use my change
+    # over time due to renegotiation or other changes to the SSL layer.
+    #
+    # @return [String, nil] The cipher name.
+    #
+    def cipher_name
+      rc, name = Cproton.pn_ssl_get_cipher_name(@impl, 128)
+      return name if rc
+      nil
+    end
+
+    # Returns the name of the SSL protocol that is currently active, or
+    # returns nil if SSL is nota ctive. Not that the protocol may change over
+    # time due to renegotation.
+    #
+    # @return [String, nil] The protocol name.
+    #
+    def protocol_name
+      rc, name = Cproton.pn_ssl_get_protocol_name(@impl, 128)
+      retur name if rc
+      nil
+    end
+
+    # Checks whether or not the state has resumed.
+    #
+    # Used for client session resume. When called on an active session, it
+    # indicates wehther the state has been resumed from a previous session.
+    #
+    # *NOTE:* This is a best-effort service - there is no guarantee that the
+    # remote server will accept the resumed parameters. The remote server may
+    # choose to ignore these parameters, and request a renegotation instead.
+    #
+    def resume_status
+      Cproton.pn_ssl_resume_status(@impl)
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d296c27b/proton-c/bindings/ruby/lib/core/ssl_details.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/ssl_details.rb b/proton-c/bindings/ruby/lib/core/ssl_details.rb
new file mode 100644
index 0000000..5367c80
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/ssl_details.rb
@@ -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.
+#++
+
+module Qpid::Proton
+
+  # @private
+  class SSLSessionDetails
+
+    attr_reader :session_id
+
+    def initialize(session_id)
+      @session_id = session_id
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d296c27b/proton-c/bindings/ruby/lib/core/ssl_domain.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/ssl_domain.rb b/proton-c/bindings/ruby/lib/core/ssl_domain.rb
new file mode 100644
index 0000000..ef3c03c
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/ssl_domain.rb
@@ -0,0 +1,156 @@
+#--
+# 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
+
+  # The top-level object that stores the configuration used by one or more
+  # SSL sessions.
+  #
+  # @see SSL
+  #
+  class SSLDomain
+
+    # The local connection endpoint is an SSL client.
+    # @private
+    MODE_CLIENT = Cproton::PN_SSL_MODE_CLIENT
+    # The local connection endpoint is an SSL server.
+    # @private
+    MODE_SERVER = Cproton::PN_SSL_MODE_SERVER
+
+    # Require the peer to provide a valid identifying certificate.
+    VERIFY_PEER = Cproton::PN_SSL_VERIFY_PEER
+    # Do no require a certificate nor a cipher authorization.
+    ANONYMOUS_PEER = Cproton::PN_SSL_ANONYMOUS_PEER
+    # Require a valid certficate and matching name.
+    VERIFY_PEER_NAME = Cproton::PN_SSL_VERIFY_PEER_NAME
+
+    # @private
+    include Util::ErrorHandler
+
+    can_raise_error :credentials, :error_class => Qpid::Proton::SSLError
+    can_raise_error :trusted_ca_db, :error_class => Qpid::Proton::SSLError
+    can_raise_error :peer_authentication, :error_class => Qpid::Proton::SSLError
+    can_raise_error :allow_unsecured_client, :error_class => Qpid::Proton::SSLError
+
+    # @private
+    attr_reader :impl
+
+    # @private
+    def initialize(mode)
+      @impl = Cproton.pn_ssl_domain(mode)
+      raise SSLUnavailable.new if @impl.nil?
+    end
+
+    # Set the certificate that identifies the local node to the remote.
+    #
+    # This certificate establishes the identity for thelocal node for all SSL
+    # sessions created from this domain. It will be sent to the remote if the
+    # remote needs to verify the dientify of this node. This may be used for
+    # both SSL servers and SSL clients (if client authentication is required by
+    # the server).
+    #
+    # *NOTE:* This setting affects only those instances of SSL created *after*
+    # this call returns. SSL objects created before invoking this method will
+    # use the domain's previous settings.
+    #
+    # @param cert_file [String] The filename containing the identify
+    #  certificate. For OpenSSL users, this is a PEM file. For Windows SChannel
+    #  users, this is the PKCS\#12 file or system store.
+    # @param key_file [String] An option key to access the identifying
+    #  certificate. For OpenSSL users, this is an optional PEM file containing
+    #  the private key used to sign the certificate. For Windows SChannel users,
+    #  this is the friendly name of the self-identifying certficate if there are
+    #  multiple certfificates in the store.
+    # @param password [String] The password used to sign the key, or *nil* if
+    #  the key is not protected.
+    #
+    # @raise [SSLError] If an error occurs.
+    #
+    def credentials(cert_file, key_file, password)
+      Cproton.pn_ssl_domain_set_credentials(@impl,
+                                            cert_file, key_file, password)
+    end
+
+    # Configures the set of trusted CA certificates used by this domain to
+    # verify peers.
+    #
+    # If the local SSL client/server needs to verify the identify of the remote,
+    # it must validate the signature of the remote's certificate. This function
+    # sets the database of trusted CAs that will be used to verify the signature
+    # of the remote's certificate.
+    #
+    # *NOTE:# This setting affects only those SSL instances created *after* this
+    # call returns. SSL objects created before invoking this method will use the
+    # domain's previous setting.
+    #
+    # @param certificate_db [String] The filename for the databse of trusted
+    #   CAs, used to authenticate the peer.
+    #
+    # @raise [SSLError] If an error occurs.
+    #
+    def trusted_ca_db(certificate_db)
+      Cproton.pn_ssl_domain_set_trusted_ca_db(@impl, certificate_db)
+    end
+
+    # Configures the level of verification used on the peer certificate.
+    #
+    # This method congtrols how the peer's certificate is validated, if at all.
+    # By default, neither servers nor clients attempt to verify their peers
+    # (*ANONYMOUS_PEER*). Once certficates and trusted CAs are configured, peer
+    # verification can be enabled.
+    #
+    # *NOTE:* In order to verify a peer, a trusted CA must be configured.
+    #
+    # *NOTE:* Servers must provide their own certficate when verifying a peer.
+    #
+    # *NOTE:* This setting affects only those SSL instances created after this
+    # call returns. SSL instances created before invoking this method will use
+    # the domain's previous setting.
+    #
+    # @param verify_mode [Fixnum] The level of validation to apply to the peer.
+    # @param trusted_CAs [String] The path to a database of trusted CAs that
+    #   the server will advertise to the peer client if the server has been
+    #   configured to verify its peer.
+    #
+    # @see VERIFY_PEER
+    # @see ANONYMOUS_PEER
+    # @see VERIFY_PEER_NAME
+    #
+    # @raise [SSLError] If an error occurs.
+    #
+    def peer_authentication(verify_mode, trusted_CAs = nil)
+      Cproton.pn_ssl_domain_set_peer_authentication(@impl,
+                                                    verify_mode, trusted_CAs)
+    end
+
+    # Permit a server to accept connection requests from non-SSL clients.
+    #
+    # This configures the server to "sniff" the incomfing client data stream and
+    # dynamically determine whether SSL/TLS is being used. This option is
+    # disabled by default: only clients using SSL/TLS are accepted by default.
+    #
+    # @raise [SSLError] If an error occurs.
+    #
+    def allow_unsecured_client
+      Cproton.pn_ssl_domain_allow_unsecured_client(@impl);
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d296c27b/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 3ac0b9e..244e318 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -64,6 +64,9 @@ require "core/sender"
 require "core/receiver"
 require "core/connection"
 require "core/sasl"
+require "core/ssl_domain"
+require "core/ssl_details"
+require "core/ssl"
 
 # Messenger API classes
 require "messenger/filters"

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d296c27b/proton-c/bindings/ruby/ruby.i
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/ruby.i b/proton-c/bindings/ruby/ruby.i
index 5979fa1..211751b 100644
--- a/proton-c/bindings/ruby/ruby.i
+++ b/proton-c/bindings/ruby/ruby.i
@@ -551,4 +551,18 @@ VALUE pni_address_of(void *object) {
 //  %}
 //%ignore pn_collector_put;
 
+%rename(pn_ssl_get_peer_hostname) wrap_pn_ssl_get_peer_hostname;
+%inline %{
+  int wrap_pn_ssl_get_peer_hostname(pn_ssl_t *ssl, char *OUTPUT, size_t *OUTPUT_SIZE) {
+    ssize_t size = pn_ssl_get_peer_hostname(ssl, OUTPUT, *OUTPUT_SIZE);
+    if (size >= 0) {
+      *OUTPUT_SIZE = size;
+    } else {
+      *OUTPUT_SIZE = 0;
+    }
+    return size;
+  }
+  %}
+%ignore pn_ssl_get_peer_hostname;
+
 %include "proton/cproton.i"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[02/15] qpid-proton git commit: PROTON-799: Added yardopts

Posted by mc...@apache.org.
PROTON-799: Added yardopts


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/31f10a99
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/31f10a99
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/31f10a99

Branch: refs/heads/ruby-engine-apis
Commit: 31f10a995ea1b9860e8f75cc7e117cb5ed3d63cf
Parents: 266fe72
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Mon Feb 9 16:54:14 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/.yardopts | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/31f10a99/proton-c/bindings/ruby/.yardopts
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/.yardopts b/proton-c/bindings/ruby/.yardopts
new file mode 100644
index 0000000..bea5abe
--- /dev/null
+++ b/proton-c/bindings/ruby/.yardopts
@@ -0,0 +1 @@
+--no-private lib/**/*.rb


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[06/15] qpid-proton git commit: PROTON-799: Added the Sender class to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the Sender class to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4d65c200
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4d65c200
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4d65c200

Branch: refs/heads/ruby-engine-apis
Commit: 4d65c2004a8eeb8184d2a1f981111762cae11cfa
Parents: 42a8925
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Jan 20 09:17:14 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/sender.rb | 76 ++++++++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb |  1 +
 2 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4d65c200/proton-c/bindings/ruby/lib/core/sender.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/sender.rb b/proton-c/bindings/ruby/lib/core/sender.rb
new file mode 100644
index 0000000..9ddcaa0
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/sender.rb
@@ -0,0 +1,76 @@
+#--
+# 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
+
+  # The sending endpoint.
+  #
+  # @see Receiver
+  #
+  class Sender < Link
+
+    # @private
+    include Util::ErrorHandler
+
+    # @private
+    can_raise_error :stream, :error_class => Qpid::Proton::LinkError
+
+    # Signals the availability of deliveries.
+    #
+    # @param n [Fixnum] The number of deliveries potentially available.
+    #
+    def offered(n)
+      Cproton.pn_link_offered(@impl, n)
+    end
+
+    # Sends the specified data to the remote endpoint.
+    #
+    # @param object [Object] The content to send.
+    # @param tag [Object] The tag
+    #
+    # @return [Fixnum] The number of bytes sent.
+    #
+    def send(object, tag = nil)
+      if object.respond_to? :proton_send
+        object.proton_send(self, tag)
+      else
+        stream(object)
+      end
+    end
+
+    # Send the specified bytes as part of the current delivery.
+    #
+    # @param bytes [Array] The bytes to send.
+    #
+    # @return n [Fixnum] The number of bytes sent.
+    #
+    def stream(bytes)
+      Cproton.pn_link_send(@impl, bytes)
+    end
+
+    def delivery_tag
+      @tag_count ||= 0
+      result = @tag_count.succ
+      @tag_count = result
+      return "#{result}"
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4d65c200/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 9b3becb..39ef351 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -60,6 +60,7 @@ require "core/terminus"
 require "core/disposition"
 require "core/delivery"
 require "core/link"
+require "core/sender"
 
 # Messenger API classes
 require "messenger/filters"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[15/15] qpid-proton git commit: PROTON-799: Added the engine_send and engine_recv examples to Ruby.

Posted by mc...@apache.org.
PROTON-799: Added the engine_send and engine_recv examples to Ruby.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/266fe723
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/266fe723
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/266fe723

Branch: refs/heads/ruby-engine-apis
Commit: 266fe723c3687b2cc4890e1a3fe6594f799caa5e
Parents: b296a8b
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Jan 13 16:27:57 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 examples/ruby/engine_recv.rb       | 158 ++++++++++++++++++++++++++++++++
 examples/ruby/engine_send.rb       | 143 +++++++++++++++++++++++++++++
 examples/ruby/lib/driver.rb        |  69 ++++++++++++++
 examples/ruby/lib/qpid_examples.rb |  28 ++++++
 examples/ruby/lib/selectable.rb    | 120 ++++++++++++++++++++++++
 5 files changed, 518 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/266fe723/examples/ruby/engine_recv.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/engine_recv.rb b/examples/ruby/engine_recv.rb
new file mode 100644
index 0000000..1529964
--- /dev/null
+++ b/examples/ruby/engine_recv.rb
@@ -0,0 +1,158 @@
+#--
+# 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.
+#++
+
+require "qpid_examples"
+require "optparse"
+
+DEFAULT_PORT = 5672
+
+options = {
+  :port => DEFAULT_PORT,
+  :debug => false,
+  :verbose => false,
+}
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: engine_recv.rb [options]"
+
+  opts.on("-p [port]", "--port [port]",
+          "The port to use  (def. #{DEFAULT_PORT})") do |port|
+    options[:port] = port
+  end
+
+  opts.on("-v", "--verbose",
+          "Enable verbose output") do
+    options[:verbose] = true
+  end
+
+  opts.on("-d",
+          "--debug", "Enable debugging") do
+    options[:debug] = true
+  end
+
+  opts.parse!
+end
+
+server = TCPServer.new('localhost', options[:port])
+
+last_time = Time.now
+
+message_count = 0
+driver = Driver.new
+
+collector = Qpid::Proton::Event::Collector.new
+
+loop do
+  begin
+    client = server.accept_nonblock
+  rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EINTR, Errno::EWOULDBLOCK => error
+
+  end
+
+  unless client.nil?
+    puts "Connection from #{client.peeraddr.last}"
+    connection = Qpid::Proton::Connection.new
+    connection.collect(collector)
+    transport = Qpid::Proton::Transport.new(Qpid::Proton::Transport::SERVER)
+    transport.bind(connection)
+    selectable = Selectable.new(transport, client)
+    driver.add(selectable)
+  end
+
+  # let the driver process data
+  driver.process
+
+  event = collector.peek
+
+  while !event.nil?
+    puts "EVENT: #{event}" if options[:debug]
+
+    case event.type
+    when Qpid::Proton::Event::CONNECTION_INIT
+      conn = event.connection
+      if conn.state & Qpid::Proton::Endpoint::REMOTE_UNINIT
+        conn.transport.sasl.done(Qpid::Proton::SASL::OK)
+      end
+
+    when Qpid::Proton::Event::CONNECTION_BOUND
+      conn = event.connection
+      if conn.state & Qpid::Proton::Endpoint::LOCAL_UNINIT
+        conn.open
+      end
+
+    when Qpid::Proton::Event::CONNECTION_REMOTE_CLOSE
+      conn = event.context
+      if !(conn.state & Qpid::Proton::Endpoint::LOCAL_CLOSED)
+        conn.close
+      end
+
+    when Qpid::Proton::Event::SESSION_REMOTE_OPEN
+      session = event.session
+      if session.state & Qpid::Proton::Endpoint::LOCAL_UNINIT
+        session.incoming_capacity = 1000000
+        session.open
+      end
+
+    when Qpid::Proton::Event::SESSION_REMOTE_CLOSE
+      session = event.session
+      if !(session.state & Qpid::Proton::Endpoint::LOCAL_CLOSED)
+        session.close
+      end
+
+    when Qpid::Proton::Event::LINK_REMOTE_OPEN
+      link = event.link
+      if link.state & Qpid::Proton::Endpoint::LOCAL_UNINIT
+        link.open
+        link.flow 400
+      end
+
+    when Qpid::Proton::Event::LINK_REMOTE_CLOSE
+      link = event.context
+      if !(link.state & Qpid::Proton::Endpoint::LOCAL_CLOSED)
+        link.close
+      end
+
+    when Qpid::Proton::Event::DELIVERY
+      link = event.link
+      delivery = event.delivery
+      if delivery.readable? && !delivery.partial?
+        # decode the message and display it
+        msg = Qpid::Proton::Util::Engine.receive_message(delivery)
+        message_count += 1
+        puts "Received:"
+        puts " Count=#{message_count}" if options[:verbose]
+        puts " From=#{msg.id}" if msg.id
+        puts " Reply to=#{msg.reply_to}" if msg.reply_to
+        puts " Subject=#{msg.subject}" if msg.subject
+        puts " Body=#{msg.body}" if msg.body
+        puts ""
+        delivery.settle
+        credit = link.credit
+        link.flow(200) if credit <= 200
+      end
+
+    when Qpid::Proton::Event::TRANSPORT
+      driver.process
+
+    end
+
+    collector.pop
+    event = collector.peek
+  end
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/266fe723/examples/ruby/engine_send.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/engine_send.rb b/examples/ruby/engine_send.rb
new file mode 100644
index 0000000..189c7fd
--- /dev/null
+++ b/examples/ruby/engine_send.rb
@@ -0,0 +1,143 @@
+#--
+# 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.
+#++
+
+require 'qpid_examples'
+require "optparse"
+
+DEFAULT_ADDRESS = "0.0.0.0:5672"
+
+options = {
+  :address => DEFAULT_ADDRESS,
+  :debug => false,
+  :verbose => false,
+  :count => 1,
+  :content => "This message was sent #{Time.new}"
+}
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: engine_recv.rb [options]"
+
+  opts.on("-a [address]", "--address [address]",
+          "The target address (def. #{DEFAULT_ADDRESS})") do |address|
+    options[:address] = address
+  end
+
+  opts.on("-C [content]", "--content [content]",
+          "The message content") do |content|
+    options[:content] = content
+  end
+
+  opts.on("-c [count]", "--count [count]",
+          "The number of messages to send (def. 1)") do |count|
+    options[:count] = count.to_i
+  end
+
+  opts.on("-v", "--verbose",
+          "Enable verbose output") do
+    options[:verbose] = true
+  end
+
+  opts.on("-d",
+          "--debug", "Enable debugging") do
+    options[:debug] = true
+  end
+
+  opts.parse!
+end
+
+
+driver = Driver.new
+
+conn = Qpid::Proton::Connection.new
+collector = Qpid::Proton::Event::Collector.new
+conn.collect(collector)
+
+session = conn.session
+conn.open
+session.open
+
+sender = session.sender("tvc_15_1")
+sender.target.address = "queue"
+sender.open
+
+transport = Qpid::Proton::Transport.new
+transport.bind(conn)
+
+address, port = options[:address].split(":")
+
+socket = TCPSocket.new(address, port)
+selectable = Selectable.new(transport, socket)
+sent_count = 0
+
+sent_count = 0
+
+driver.add(selectable)
+
+loop do
+  # let the driver process
+  driver.process
+
+  event = collector.peek
+
+  unless event.nil?
+
+    print "EVENT: #{event}\n" if options[:debug]
+
+    case event.type
+
+    when Qpid::Proton::Event::LINK_FLOW
+      sender = event.sender
+      credit = sender.credit
+
+      message = Qpid::Proton::Message.new
+
+      if credit > 0 && sent_count < options[:count]
+        sent_count = sent_count.next
+        message.clear
+        message.address = options[:address]
+        message.subject = "Message #{sent_count}..."
+        message.body = options[:content]
+
+        delivery = sender.delivery("#{sent_count}")
+        sender.send(message.encode)
+        delivery.settle
+        sender.advance
+        credit = sender.credit
+      else
+        sender.close
+      end
+
+    when Qpid::Proton::Event::LINK_LOCAL_CLOSE
+      link = event.link
+      link.close
+      link.session.close
+
+    when Qpid::Proton::Event::SESSION_LOCAL_CLOSE
+      session = event.session
+      session.connection.close
+
+    when Qpid::Proton::Event::CONNECTION_LOCAL_CLOSE
+      break
+
+    end
+
+    collector.pop
+    event = collector.peek
+  end
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/266fe723/examples/ruby/lib/driver.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/lib/driver.rb b/examples/ruby/lib/driver.rb
new file mode 100644
index 0000000..4e223d0
--- /dev/null
+++ b/examples/ruby/lib/driver.rb
@@ -0,0 +1,69 @@
+#--
+# 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.
+#++
+
+class Driver
+
+  def initialize
+    @selectables = {}
+  end
+
+  def add(selectable)
+    @selectables[selectable.fileno] = selectable
+  end
+
+  def process
+    reading = []
+    writing = []
+
+    @selectables.each_value do |sel|
+      if sel.closed? || sel.fileno.nil?
+        @selectables.delete(sel.fileno)
+      else
+        begin
+          reading << sel.to_io if sel.reading?
+          writing << sel.to_io if sel.writing?
+        rescue Exception => error
+          puts "Error: #{error}"
+          puts error.backtrace.join("\n");
+          # @selectables.delete(sel.fileno)
+        end
+      end
+    end
+
+    read_from, write_to = IO.select(reading, writing, [], 0)
+
+    unless read_from.nil?
+      read_from.each do |r|
+        sel = @selectables[r.fileno]
+        sel.readable unless sel.nil? || sel.closed?
+      end
+    end
+
+    begin
+      unless write_to.nil?
+        write_to.each do |w|
+          sel = @selectables[w.fileno]
+          sel.writable unless sel.nil? || sel.closed?
+        end
+      end
+
+    end
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/266fe723/examples/ruby/lib/qpid_examples.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/lib/qpid_examples.rb b/examples/ruby/lib/qpid_examples.rb
new file mode 100644
index 0000000..8503fbe
--- /dev/null
+++ b/examples/ruby/lib/qpid_examples.rb
@@ -0,0 +1,28 @@
+#--
+# 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.
+#++
+
+require "qpid_proton"
+
+require "selectable"
+require "driver"
+require "socket"
+require "monitor"
+
+include Socket::Constants
+

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/266fe723/examples/ruby/lib/selectable.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/lib/selectable.rb b/examples/ruby/lib/selectable.rb
new file mode 100644
index 0000000..779ea24
--- /dev/null
+++ b/examples/ruby/lib/selectable.rb
@@ -0,0 +1,120 @@
+#--
+# 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.
+#++
+
+class Selectable
+
+  attr_reader :transport
+
+  def initialize(transport, socket)
+    @transport = transport
+    @socket = socket
+    @socket.autoclose = true
+    @write_done = false
+    @read_done = false
+  end
+
+  def closed?
+    return true if @socket.closed?
+    return false if !@read_done && !@write_done
+    @socket.close
+    true
+  end
+
+  def fileno
+    @socket.fileno unless @socket.closed?
+  end
+
+  def to_io
+    @socket
+  end
+
+  def reading?
+    return false if @read_done
+    c = @transport.capacity
+    if c > 0
+      return true
+    elsif c < 0
+      @read_done = true
+      return false
+    else
+      return false
+    end
+  end
+
+  def writing?
+    return false if @write_done
+    begin
+      p = @transport.pending
+      if p > 0
+        return true
+      elsif p < 0
+        @write_done = true
+        return false
+      else
+        return false
+      end
+    rescue Qpid::Proton::TransportError => error
+      @write_done = true
+      return false
+    end
+  end
+
+  def readable
+    c = @transport.capacity
+    if c > 0
+      begin
+        data = @socket.recv(c)
+        if data
+          @transport.push(data)
+        else
+          @transport.close_tail
+        end
+      rescue Exception => error
+        puts "read error; #{error}"
+        @transport.close_tail
+        @read_done = true
+      end
+    elsif c < 0
+      @read_done = true
+    end
+  end
+
+  def writable
+    begin
+      p = @transport.pending
+      if p > 0
+        data = @transport.peek(p)
+        n = @socket.send(data, 0)
+        @transport.pop(n)
+      elsif p < 0
+        @write_done = true
+      end
+    rescue Exception => error
+      puts "write error: #{error}"
+      puts error.backtrace.join("\n")
+      @transport.close_head
+      @write_done = true
+    end
+  end
+
+  def tick(now)
+    @transport.tick(now)
+  end
+
+end


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[07/15] qpid-proton git commit: PROTON-799: Added the Receiver class to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the Receiver class to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/7cb84fdb
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/7cb84fdb
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/7cb84fdb

Branch: refs/heads/ruby-engine-apis
Commit: 7cb84fdb5e94f326faf407005f7e396f9eb2df80
Parents: 4d65c20
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Jan 20 09:22:49 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/receiver.rb | 95 ++++++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb   |  1 +
 2 files changed, 96 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7cb84fdb/proton-c/bindings/ruby/lib/core/receiver.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/receiver.rb b/proton-c/bindings/ruby/lib/core/receiver.rb
new file mode 100644
index 0000000..ca7c5e1
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/receiver.rb
@@ -0,0 +1,95 @@
+#--
+# 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
+
+  # The receiving endpoint.
+  #
+  # @see Sender
+  #
+  class Receiver < Link
+
+    # @private
+    include Util::SwigHelper
+
+    # @private
+    PROTON_METHOD_PREFIX = "pn_link"
+
+    # @!attribute drain
+    #
+    # The drain mode.
+    #
+    # If a receiver is in drain mode, then the sending endpoint of a link must
+    # immediately use up all available credit on the link. If this is not
+    # possible, the excess credit must be returned by invoking #drained.
+    #
+    # Only the receiving endpoint can set the drain mode.
+    #
+    # @return [Boolean] True if drain mode is set.
+    #
+    proton_accessor :drain
+
+    # @!attribute [r] draining?
+    #
+    # Returns if a link is currently draining.
+    #
+    # A link is defined to be draining when drain mode is set to true and
+    # the sender still has excess credit.
+    #
+    # @return [Boolean] True if the receiver is currently draining.
+    #
+    proton_caller :draining?
+
+    # Grants credit for incoming deliveries.
+    #
+    # @param n [Fixnum] The amount to increment the link credit.
+    #
+    def flow(n)
+      Cproton.pn_link_flow(@impl, n)
+    end
+
+    # Allows receiving up to the specified limit of data from the remote
+    # endpoint.
+    #
+    # Note that large messages can be streamed across the network, so just
+    # because there is no data to read does not imply the message is complete.
+    #
+    # To ensure the entirety of the message data has been read, either call
+    # #receive until nil is returned, or verify that #partial? is false and
+    # Delivery#pending is 0.
+    #
+    # @param limit [Fixnum] The maximum bytes to receive.
+    #
+    # @return [Fixnum, nil] The number of bytes received, or nil if the end of
+    # the stream was reached.t
+    #
+    # @see Deliver#pending To see how much buffer space is needed.
+    #
+    # @raise [LinkError] If an error occurs.
+    #
+    def receive(limit)
+      (n, bytes) = Cproton.pn_link_recv(@impl, limit)
+      return nil if n == Qpid::Proton::Error::EOS
+      raise LinkError.new("[#{n}]: #{Cproton.pn_link_error(@impl)}") if n < 0
+      return bytes
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7cb84fdb/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 39ef351..ed8532f 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -61,6 +61,7 @@ require "core/disposition"
 require "core/delivery"
 require "core/link"
 require "core/sender"
+require "core/receiver"
 
 # Messenger API classes
 require "messenger/filters"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[04/15] qpid-proton git commit: PROTON-799: Added the Link class to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the Link class to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/42a89259
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/42a89259
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/42a89259

Branch: refs/heads/ruby-engine-apis
Commit: 42a89259f786e1019d7f935adda3a2443885ed9e
Parents: 13b466b
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Mon Jan 19 14:55:56 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/link.rb   | 387 +++++++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb |   1 +
 2 files changed, 388 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/42a89259/proton-c/bindings/ruby/lib/core/link.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/link.rb b/proton-c/bindings/ruby/lib/core/link.rb
new file mode 100644
index 0000000..86a307a
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/link.rb
@@ -0,0 +1,387 @@
+#--
+# 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
+
+  # The base for both Sender and Receiver, providing common functionality
+  # between both ends.
+  #
+  # A Link has a single parent Qpid::Proton::Session instance.
+  #
+  class Link < Endpoint
+
+    # The sender will send all deliveries initially unsettled.
+    SND_UNSETTLED = Cproton::PN_SND_UNSETTLED
+    # The sender will send all deliveries settled to the receiver.
+    SND_SETTLED = Cproton::PN_SND_SETTLED
+    # The sender may send a mixture of settled and unsettled deliveries.
+    SND_MIXED = Cproton::PN_SND_MIXED
+
+    # The receiver will settle deliveries regardless of what the sender does.
+    RCV_FIRST = Cproton::PN_RCV_FIRST
+    # The receiver will only settle deliveries after the sender settles.
+    RCV_SECOND = Cproton::PN_RCV_SECOND
+
+    # @private
+    include Util::SwigHelper
+
+    # @private
+    PROTON_METHOD_PREFIX = "pn_link"
+
+    # @!attribute [r] state
+    #
+    # Returns the endpoint state flags.
+    #
+    proton_caller :state
+
+    # @!method open
+    #
+    # Opens the link. Once this operation has completed, the state flag will be
+    # set.
+    #
+    # @see Endpoint::LOCAL_ACTIVE
+    proton_caller :open
+
+    # @!method close
+    #
+    # Closes the link.
+    #
+    # Once this operation has completed, the state flag will be set.
+    # This may be called without first calling #open, which is the equivalent to
+    # calling #open and then #close.
+    #
+    # @see Endpoint::LOCAL_CLOSED
+    proton_caller :close
+
+    # @!method detach
+    #
+    # Detaches the link.
+    proton_caller :detach
+
+    # Advance the current delivery to the next on the link.
+    #
+    # For sending links, this operation is used to finish sending message data
+    # for the current outgoing delivery and move on to the next outgoing
+    # delivery (if any).
+    #
+    # For receiving links, this operatoin is used to finish accessing message
+    # data from the current incoming delivery and move on to the next incoming
+    # delivery (if any).
+    #
+    # @return [Boolean] True if the current delivery was changed.
+    #
+    # @see #current
+    #
+    proton_caller :advance
+
+    proton_caller :unsettled
+
+    # @!attribute [r] credit
+    #
+    # Returns the credit balance for a link.
+    #
+    # Links use a credit based flow control scheme. Every receiver maintains a
+    # credit balance that corresponds to the number of deliveries that the
+    # receiver can accept at any given moment.
+    #
+    # As more capacity becomes available at the receiver, it adds credit to this
+    # balance and communicates the new balance to the sender. Whenever a
+    # delivery is sent/received, the credit balance maintained by the link is
+    # decremented by one.
+    #
+    # Once the credit balance at the sender reaches zero, the sender must pause
+    # sending until more credit is obtained from the receiver.
+    #
+    # NOte that a sending link may still be used to send deliveries eve if
+    # credit reaches zero. However those deliveries will end up being buffer by
+    # the link until enough credit is obtained from the receiver to send them
+    # over the wire. In this case the balance reported will go negative.
+    #
+    # @return [Fixnum] The credit balance.
+    #
+    # @see #flow
+    #
+    proton_caller :credit
+
+    # @!attribute [r] remote_credit
+    #
+    # Returns the remote view of the credit.
+    #
+    # The remote view of the credit for a link differs from the local view of
+    # credit for a link by the number of queued deliveries. In other words,
+    # remote credit is defined as credit - queued.
+    #
+    # @see #queued
+    # @see #credit
+    #
+    # @return [Fixnum] The remove view of the credit.
+    #
+    proton_caller :remote_credit
+
+    # @!attribute [r] available
+    #
+    # Returns the available deliveries hint for a link.
+    #
+    # The available count for a link provides a hint as to the number of
+    # deliveries that might be able to be sent if sufficient credit were issued
+    # by the receiving link endpoint.
+    #
+    # @return [Fixnum] The available deliveries hint.
+    #
+    # @see Sender#offered
+    #
+    proton_caller :available
+
+    # @!attribute [r] queued
+    #
+    # Returns the number of queued deliveries for a link.
+    #
+    # Links may queue deliveries for a number of reasons. For example, there may
+    # be insufficient credit to send them to the receiver, or they simply may
+    # not have yet had a chance to be written to the wire.
+    #
+    # @return [Fixnum] The number of queued deliveries.
+    #
+    # @see #credit
+    #
+    proton_caller :queued
+
+    # @!attribute [r] name
+    #
+    # Returns the name of the link.
+    #
+    # @return [String] The name.
+    #
+    proton_caller :name
+
+    # @!attribute [r] sender?
+    #
+    # Returns if the link is a sender.
+    #
+    # @return [Boolean] True if the link is a sender.
+    #
+    proton_reader  :sender, :is_or_get => :is
+
+    # @!attribute [r] receiver?
+    #
+    # Returns if the link is a receiver.
+    #
+    # @return [Boolean] True if the link is a receiver.
+    #
+    proton_reader  :receiver, :is_or_get => :is
+
+    # @private
+    proton_reader :attachments
+
+    # Drains excess credit.
+    #
+    # When a link is in drain mode, the sender must use all excess credit
+    # immediately and release any excess credit back to the receiver if there
+    # are no deliveries available to send.
+    #
+    # When invoked on a Sender that is in drain mode, this operation will
+    # release all excess credit back to the receiver and return the number of
+    # credits released back to the sender. If the link is not in drain mode,
+    # this operation is a noop.
+    #
+    # When invoked on a Receiver, this operation will return and reset the
+    # number of credits the sender has released back to it.
+    #
+    # @return [Fixnum] The number of credits drained.
+    #
+    proton_caller :drained
+
+    # @private
+    include Util::Wrapper
+
+    # @private
+    def self.wrap(impl)
+      return nil if impl.nil?
+
+      result = self.fetch_instance(impl, :pn_link_attachments)
+      return result unless result.nil?
+      if Cproton.pn_link_is_sender(impl)
+        return Sender.new(impl)
+      elsif Cproton.pn_link_is_receiver(impl)
+        return Receiver.new(impl)
+      end
+    end
+
+    # @private
+    def initialize(impl)
+      @impl = impl
+      self.class.store_instance(self, :pn_link_attachments)
+    end
+
+    # Returns additional error information.
+    #
+    # Whenever a link operation fails (i.e., returns an error code) additional
+    # error details can be obtained from this method. Ther error object that is
+    # returned may also be used to clear the error condition.
+    #
+    # @return [Error] The error.
+    #
+    def error
+      Cproton.pn_link_error(@impl)
+    end
+
+    # Returns the next link that matches the given state mask.
+    #
+    # @param state_mask [Fixnum] The state mask.
+    #
+    # @return [Sender, Receiver] The next link.
+    #
+    def next(state_mask)
+      return Link.wrap(Cproton.pn_link_next(@impl, state_mask))
+    end
+
+    # Returns the locally defined source terminus.
+    #
+    # @return [Terminus] The terminus
+    def source
+      Terminus.new(Cproton.pn_link_source(@impl))
+    end
+
+    # Returns the locally defined target terminus.
+    #
+    # @return [Terminus] The terminus.
+    #
+    def target
+      Terminus.new(Cproton.pn_link_target(@impl))
+    end
+
+    # Returns a representation of the remotely defined source terminus.
+    #
+    # @return [Terminus] The terminus.
+    #
+    def remote_source
+      Terminus.new(Cproton.pn_link_remote_source(@impl))
+    end
+
+    # Returns a representation of the remotely defined target terminus.
+    #
+    # @return [Terminus] The terminus.
+    #
+    def remote_target
+      Terminus.new(Cproton.pn_link_remote_target(@impl))
+    end
+
+    # Returns the parent session.
+    #
+    # @return [Session] The session.
+    #
+    def session
+      Session.wrap(Cproton.pn_link_session(@impl))
+    end
+
+    # Returns the parent connection.
+    #
+    # @return [Connection] The connection.
+    #
+    def connection
+      self.session.connection
+    end
+
+    # Returns the parent delivery.
+    #
+    # @return [Delivery] The delivery.
+    #
+    def delivery(tag)
+      Delivery.new(Cproton.pn_delivery(@impl, tag))
+    end
+
+    # Returns the current delivery.
+    #
+    # Each link maintains a sequence of deliveries in the order they were
+    # created, along with a reference to the *current* delivery. All send and
+    # receive operations on a link take place on the *current* delivery. If a
+    # link has no current delivery, the current delivery is automatically
+    # pointed to the *next* delivery created on the link.
+    #
+    # Once initialized, the current delivery remains the same until it is
+    # changed by advancing, or until it is settled.
+    #
+    # @see #next
+    # @see Delivery#settle
+    #
+    # @return [Delivery] The current delivery.
+    #
+    def current
+      Delivery.wrap(Cproton.pn_link_current(@impl))
+    end
+
+    # Sets the local sender settle mode.
+    #
+    # @param mode [Fixnum] The settle mode.
+    #
+    # @see #SND_UNSETTLED
+    # @see #SND_SETTLED
+    # @see #SND_MIXED
+    #
+    def snd_settle_mode=(mode)
+      Cproton.pn_link_set_snd_settle_mode(@impl, mode)
+    end
+
+    # Returns the local sender settle mode.
+    #
+    # @return [Fixnum] The local sender settle mode.
+    #
+    # @see #snd_settle_mode
+    #
+    def snd_settle_mode
+      Cproton.pn_link_snd_settle_mode(@impl)
+    end
+
+    # Sets the local receiver settle mode.
+    #
+    # @param mode [Fixnum] The settle mode.
+    #
+    # @see #RCV_FIRST
+    # @see #RCV_SECOND
+    #
+    def rcv_settle_mode=(mode)
+      Cproton.pn_link_set_rcv_settle_mode(@impl, mode)
+    end
+
+    # Returns the local receiver settle mode.
+    #
+    # @return [Fixnum] The local receiver settle mode.
+    #
+    def rcv_settle_mode
+      Cproton.pn_link_rcv_settle_mode(@impl)
+    end
+
+    # @private
+    def _local_condition
+      Cproton.pn_link_condition(@impl)
+    end
+
+    # @private
+    def _remote_condition
+      Cproton.pn_link_remote_condition(@impl)
+    end
+
+    def ==(other)
+      other.respond_to?(:impl) &&
+      (Cproton.pni_address_of(other.impl) == Cproton.pni_address_of(@impl))
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/42a89259/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 d7b5803..9b3becb 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -59,6 +59,7 @@ require "core/session"
 require "core/terminus"
 require "core/disposition"
 require "core/delivery"
+require "core/link"
 
 # Messenger API classes
 require "messenger/filters"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[11/15] qpid-proton git commit: PROTON-799: Added the ClassWrapper mixin for the Ruby engine APIs.

Posted by mc...@apache.org.
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/53ee7681
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/53ee7681
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/53ee7681

Branch: refs/heads/ruby-engine-apis
Commit: 53ee76813f5bd9c91ae1c588cca628fe7dba685f
Parents: 50dbe05
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Feb 4 09:35:31 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 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/53ee7681/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/53ee7681/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-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[03/15] qpid-proton git commit: PROTON-799: Added the Transport class to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the Transport class to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/50dbe059
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/50dbe059
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/50dbe059

Branch: refs/heads/ruby-engine-apis
Commit: 50dbe0596b202295502e122d4df10631541d7d1b
Parents: d296c27
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Wed Jan 14 09:31:46 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/exceptions.rb |   5 +
 proton-c/bindings/ruby/lib/core/transport.rb  | 412 +++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb     |   1 +
 3 files changed, 418 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/50dbe059/proton-c/bindings/ruby/lib/core/exceptions.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/exceptions.rb b/proton-c/bindings/ruby/lib/core/exceptions.rb
index 2695709..94d2957 100644
--- a/proton-c/bindings/ruby/lib/core/exceptions.rb
+++ b/proton-c/bindings/ruby/lib/core/exceptions.rb
@@ -80,6 +80,11 @@ module Qpid
     class InProgressError < ProtonError
     end
 
+    # Raised by instances of Transport.
+    #
+    class TransportError < ProtonError
+    end
+
     # Raised by instances of SASL
     #
     class SASLError < TransportError

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/50dbe059/proton-c/bindings/ruby/lib/core/transport.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/transport.rb b/proton-c/bindings/ruby/lib/core/transport.rb
new file mode 100644
index 0000000..206f97d
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/transport.rb
@@ -0,0 +1,412 @@
+#--
+# 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
+
+  # A transport is used by a connection to interface with the network.
+  #
+  # A transport is associated with, at most, one Connection.
+  #
+  # == Client And Server Mode
+  #
+  # Initially, a transport is configured to be a client tranpsort. It can be
+  # configured to act as a server when it is created.
+  #
+  # A client transport initiates outgoing connections.
+  #
+  # A client transport must be configured with the protocol layers to use and
+  # cannot configure itself automatically.
+  #
+  # A server transport accepts incoming connections. It can automatically
+  # configure itself to include the various protocol layers depending on the
+  # incoming protocol headers.
+  #
+  # == Tracing Data
+  #
+  # Data can be traced into and out of the transport programmatically by setting
+  # the #trace level to one of the defined trace values (TRACE_RAW, TRACE_FRM or
+  # TRACE_DRV). Tracing can also be turned off programmatically by setting the
+  # #trace level to TRACE_OFF.
+  #
+  # @example
+  #
+  #   # turns on frame tracing
+  #   @transport.trace = Qpid::Proton::Transport::TRACE_FRM
+  #
+  #   # ... do something where the frames are of interest, such as debugging
+  #
+  #   # turn tracing off again
+  #   @transport.trace = Qpid::Proton::Transport::TRACE_NONE
+  #
+  # Tracing can also be enabled from the command line by defining the similarly
+  # named environment variable before starting a Proton application:
+  #
+  # @example
+  #
+  #   # enable tracing from the command line
+  #   PN_TRACE_FRM=1 ruby my_proton_app.rb
+  #
+  class Transport
+
+    # @private
+    include Util::Engine
+
+    # Turn logging off entirely.
+    TRACE_OFF = Cproton::PN_TRACE_OFF
+    # Log raw binary data into/out of the transport.
+    TRACE_RAW = Cproton::PN_TRACE_RAW
+    # Log frames into/out of the transport.
+    TRACE_FRM = Cproton::PN_TRACE_FRM
+    # Log driver related events; i.e., initialization, end of stream, etc.
+    TRACE_DRV = Cproton::PN_TRACE_DRV
+
+    # @private
+    CLIENT = 1
+    # @private
+    SERVER = 2
+
+    # @private
+    include Util::SwigHelper
+
+    # @private
+    PROTON_METHOD_PREFIX = "pn_transport"
+
+    # @!attribute channel_max
+    #
+    # @return [Fixnum] The maximum allowed channel.
+    #
+    proton_accessor :channel_max
+
+    # @!attribute [r] remote_channel_max
+    #
+    # @return [Fixnum] The maximum allowed channel of a transport's remote peer.
+    #
+    proton_caller :remote_channel_max
+
+    # @!attribute max_frame_size
+    #
+    # @return [Fixnum] The maximum frame size.
+    #
+    proton_accessor :max_frame_size
+
+    # @!attribute [r] remote_max_frame_size
+    #
+    # @return [Fixnum] The maximum frame size of the transport's remote peer.
+    #
+    proton_reader :remote_max_frame_size
+
+    # @!attribute idle_timeout
+    #
+    # @return [Fixnum] The idle timeout.
+    #
+    proton_accessor :idle_timeout
+
+    # @!attribute [r] remote_idle_timeout
+    #
+    # @return [Fixnum] The idle timeout for the transport's remote peer.
+    #
+    proton_accessor :remote_idle_timeout
+
+    # @!attribute [r] capacity
+    #
+    # If the engine is in an exception state such as encountering an error
+    # condition or reaching the end of stream state, a negative value will
+    # be returned indicating the condition.
+    #
+    # If an error is indicated, further deteails can be obtained from
+    # #error.
+    #
+    # Calls to #process may alter the value of this value. See #process for
+    # more details
+    #
+    # @return [Fixnum] The amount of free space for input following the
+    # transport's tail pointer.
+    #
+    proton_caller :capacity
+
+    # @!attribute [r] head
+    #
+    # This referneces queued output data. It reports the bytes of output data.
+    #
+    # Calls to #pop may alter this attribute, and any data it references.
+    #
+    # @return [String] The transport's head pointer.
+    #
+    proton_caller :head
+
+    # @!attribute [r] tail
+    #
+    # The amount of free space following this data is reported by #capacity.
+    #
+    # Calls to #process may alter the value of this attribute.
+    #
+    # @return [String] The transport's tail pointer.
+    #
+    proton_caller :tail
+
+    # @!attribute [r] pending
+    #
+    # If the ending is in an exceptional state, such as encountering an error
+    # condition or reachign the end of the stream state, a negative value will
+    # be returned indicating the condition.
+    #
+    # If an error is indicated, further details can be obtained from #error.
+    #
+    # Calls to #pop may alter the value of this pointer as well.
+    #
+    # @return [Fixnum] The number of pending output bytes following the header
+    # pointer.
+    #
+    # @raise [TransportError] If any error other than an end of stream occurs.
+    #
+    proton_caller :pending
+
+    # @!attribute [r] closed?
+    #
+    # A transport is defined to be closed when both the tail and the head are
+    # closed. In other words, when both #capacity < 0 and #pending < 0.
+    #
+    # @return [Boolean] Returns true if the tranpsort is closed.
+    #
+    proton_caller :closed?
+
+    # @!attribute [r] frames_output
+    #
+    # @return [Fixnum] The number of frames output by a transport.
+    #
+    proton_reader :frames_output
+
+    # @!attribute [r] frames_input
+    #
+    # @return [Fixnum] The number of frames input by a transport.
+    #
+    proton_reader :frames_input
+
+    # @private
+    include Util::ErrorHandler
+
+    can_raise_error :process, :error_class => TransportError
+    can_raise_error :close_tail, :error_class => TransportError
+    can_raise_error :pending, :error_class => TransportError, :below => Error::EOS
+    can_raise_error :close_head, :error_class => TransportError
+
+    # @private
+    include Util::Wrapper
+
+    # @private
+    def self.wrap(impl)
+      return nil if impl.nil?
+
+      self.fetch_instance(impl, :pn_transport_attachments) || Transport.new(nil, impl)
+    end
+
+    # Creates a new transport instance.
+    #
+    # @param mode [Fixnum] The transport mode, either CLIENT or SERVER
+    # @param impl [pn_transport_t] Should not be used.
+    #
+    # @raise [TransportError] If the mode is invalid.
+    #
+    def initialize(mode = nil, impl = Cproton.pn_transport)
+      @impl = impl
+      if mode == SERVER
+        Cproton.pn_transport_set_server(@impl)
+      elsif (!mode.nil? && mode != CLIENT)
+        raise TransportError.new("cannot create transport for mode: #{mode}")
+      end
+      self.class.store_instance(self, :pn_transport_attachments)
+    end
+
+    # Returns whether the transport has any buffered data.
+    #
+    # @return [Boolean] True if the transport has no buffered data.
+    #
+    def quiesced?
+      Cproton.pn_transport_quiesced(@impl)
+    end
+
+    # Returns additional information about the condition of the transport.
+    #
+    # When a TRANSPORT_ERROR event occurs, this operaiton can be used to
+    # access the details of the error condition.
+    #
+    # The object returned is valid until the Transport is discarded.
+    #
+    def condition
+      condition_to_object Cproton.pn_transport_condition(@impl)
+    end
+
+    # Binds to the given connection.
+    #
+    # @param connection [Connection] The connection.
+    #
+    def bind(connection)
+      Cproton.pn_transport_bind(@impl, connection.impl)
+    end
+
+    # Unbinds from the previous connection.
+    #
+    def unbind
+      Cproton.pn_transport_unbind(@impl)
+    end
+
+    # Updates the transports trace flags.
+    #
+    # @param level [Fixnum] The trace level.
+    #
+    # @see TRACE_OFF
+    # @see TRACE_RAW
+    # @see TRACE_FRM
+    # @see TRACE_DRV
+    #
+    def trace(level)
+      Cproton.pn_transport_trace(@impl, level)
+    end
+
+    # Return the AMQP connection associated with the transport.
+    #
+    # @return [Connection, nil] The bound connection, or nil.
+    #
+    def connection
+      Connection.wrap(Cproton.pn_transport_connection(@impl))
+    end
+
+    # Log a message to the transport's logging mechanism.
+    #
+    # This can be using in a debugging scenario as the message will be
+    # prepended with the transport's identifier.
+    #
+    # @param message [String] The message to be logged.
+    #
+    def log(message)
+      Cproton.pn_transport_log(@impl, message)
+    end
+
+    # Pushes the supplied bytes into the tail of the transport.
+    #
+    # @param data [String] The bytes to be pushed.
+    #
+    # @return [Fixnum] The number of bytes pushed.
+    #
+    def push(data)
+      Cproton.pn_transport_push(@impl, data, data.length)
+    end
+
+    # Process input data following the tail pointer.
+    #
+    # Calling this function will cause the transport to consume the specified
+    # number of bytes of input occupying the free space following the tail
+    # pointer. It may also change the value for #tail, as well as the amount of
+    # free space reported by #capacity.
+    #
+    # @param size [Fixnum] The number of bytes to process.
+    #
+    # @raise [TransportError] If an error occurs.
+    #
+    def process(size)
+      Cproton.pn_transport_process(@impl, size)
+    end
+
+    # Indicate that the input has reached EOS (end of stream).
+    #
+    # This tells the transport that no more input will be forthcoming.
+    #
+    # @raise [TransportError] If an error occurs.
+    #
+    def close_tail
+      Cproton.pn_transport_close_tail(@impl)
+    end
+
+    # Returns the specified number of bytes from the transport's buffers.
+    #
+    # @param size [Fixnum] The number of bytes to return.
+    #
+    # @return [String] The data peeked.
+    #
+    # @raise [TransportError] If an error occurs.
+    #
+    def peek(size)
+      cd, out = Cproton.pn_transport_peek(@impl, size)
+      return nil if cd == Qpid::Proton::Error::EOS
+      raise TransportError.new if cd < -1
+      out
+    end
+
+    # Removes the specified number of bytes from the pending output queue
+    # following the transport's head pointer.
+    #
+    # @param size [Fixnum] The number of bytes to remove.
+    #
+    def pop(size)
+      Cproton.pn_transport_pop(@impl, size)
+    end
+
+    # Indicate that the output has closed.
+    #
+    # Tells the transport that no more output will be popped.
+    #
+    # @raise [TransportError] If an error occurs.
+    #
+    def close_head
+      Cproton.pn_transport_close_head(@impl)
+    end
+
+    # Process any pending transport timer events.
+    #
+    # This method should be called after all pending input has been
+    # processed by the transport (see #input), and before generating
+    # output (see #output).
+    #
+    # It returns the deadline for the next pending timer event, if any
+    # art present.
+    #
+    # @param now [Time] The timestamp.
+    #
+    # @return [Fixnum] If non-zero, the expiration time of the next pending
+    #   timer event for the transport. The caller must invoke #tick again at
+    #   least once at or before this deadline occurs.
+    #
+    def tick(now)
+      Cproton.pn_transport_tick(@impl, now)
+    end
+
+    def sasl
+      SASL.new(self)
+    end
+
+    # Creates, or returns an existing, SSL object for the transport.
+    #
+    # @param domain [SSLDomain] The SSL domain.
+    # @param session_details [SSLDetails] The SSL session details.
+    #
+    # @return [SSL] The SSL object.
+    #
+    def ssl(domain = nil, session_details = nil)
+      self.ssl = SSL.create(self, domain, session_details) if self.ssl.nil?
+      self.ssl
+    end
+
+    # @private
+    def ssl?
+      self.respond_to?(:ssl) && !self.ssl.nil?
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/50dbe059/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 244e318..16394f9 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -67,6 +67,7 @@ require "core/sasl"
 require "core/ssl_domain"
 require "core/ssl_details"
 require "core/ssl"
+require "core/transport"
 
 # Messenger API classes
 require "messenger/filters"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[10/15] qpid-proton git commit: PROTON-799: Added the SASL class to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the SASL class to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f03827d6
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f03827d6
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f03827d6

Branch: refs/heads/ruby-engine-apis
Commit: f03827d62c4e57c999983e70805d2453f992777b
Parents: 310ffcf
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Jan 20 16:09:30 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/sasl.rb   | 94 ++++++++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb |  1 +
 2 files changed, 95 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f03827d6/proton-c/bindings/ruby/lib/core/sasl.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/sasl.rb b/proton-c/bindings/ruby/lib/core/sasl.rb
new file mode 100644
index 0000000..7870652
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/sasl.rb
@@ -0,0 +1,94 @@
+#--
+# 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
+
+  # The SASL layer is responsible for establishing an authenticated and/or
+  # encrypted tunnel over which AMQP frames are passed between peers.
+  #
+  # The peer acting as the SASL client must provide authentication
+  # credentials.
+  #
+  # The peer acting as the SASL server must provide authentication against the
+  # received credentials.
+  #
+  # @example
+  #   # SCENARIO: the remote endpoint has not initialized their connection
+  #   #           then the local endpoint, acting as a SASL server, decides
+  #   #           to allow an anonymous connection.
+  #   #
+  #   #           The SASL layer locally assumes the role of server and then
+  #   #           enables anonymous authentication for the remote endpoint.
+  #   #
+  #   sasl = @transport.sasl
+  #   sasl.server
+  #   sasl.mechanisms("ANONYMOUS")
+  #   sasl.done(Qpid::Proton::SASL::OK)
+  #
+  class SASL
+
+    # Negotation has not completed.
+    NONE = Cproton::PN_SASL_NONE
+    # Authentication succeeded.
+    OK = Cproton::PN_SASL_OK
+    # Authentication failed due to bad credentials.
+    AUTH = Cproton::PN_SASL_AUTH
+
+    # Constructs a new instance for the given transport.
+    #
+    # @param transport [Transport] The transport.
+    #
+    # @private A SASL should be fetched only from its Transport
+    #
+    def initialize(transport)
+      @impl = Cproton.pn_sasl(transport.impl)
+    end
+
+    # Sets the acceptable SASL mechanisms.
+    #
+    # @param mechanisms [String] The space-delimited set of mechanisms.
+    #
+    # @example Use anonymous SASL authentication.
+    #  @sasl.mechanisms("GSSAPI CRAM-MD5 PLAIN")
+    #
+    def mechanisms(mechanisms)
+      Cproton.pn_sasl_mechanisms(@impl, mechanisms)
+    end
+
+    # Returns the outcome of the SASL negotiation.
+    #
+    # @return [Fixnum] The outcome.
+    #
+    def outcome
+      outcome = Cprotn.pn_sasl_outcome(@impl)
+      return nil if outcome == NONE
+      outcome
+    end
+
+    # Set the condition of the SASL negotiation.
+    #
+    # @param outcome [Fixnum] The outcome.
+    #
+    def done(outcome)
+      Cproton.pn_sasl_done(@impl, outcome)
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f03827d6/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 2a57b32..3ac0b9e 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -63,6 +63,7 @@ require "core/link"
 require "core/sender"
 require "core/receiver"
 require "core/connection"
+require "core/sasl"
 
 # Messenger API classes
 require "messenger/filters"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[14/15] qpid-proton git commit: PROTON-799: Adjusted the Ruby error macro

Posted by mc...@apache.org.
PROTON-799: Adjusted the Ruby error macro


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/eff40cc9
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/eff40cc9
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/eff40cc9

Branch: refs/heads/ruby-engine-apis
Commit: eff40cc9778718026c6f4c1c20d16c9a0efd3978
Parents: 31f10a9
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Feb 19 14:28:54 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/util/error_handler.rb | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/eff40cc9/proton-c/bindings/ruby/lib/util/error_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/error_handler.rb b/proton-c/bindings/ruby/lib/util/error_handler.rb
index 2f43609..da51214 100644
--- a/proton-c/bindings/ruby/lib/util/error_handler.rb
+++ b/proton-c/bindings/ruby/lib/util/error_handler.rb
@@ -41,7 +41,9 @@ module Qpid::Proton::Util
       end
     end
 
-    def can_raise_error(method_names, error_class = nil)
+    def can_raise_error(method_names, options = {})
+      error_class = options[:error_class]
+      below = options[:below] || 0
       # coerce the names to be an array
       Array(method_names).each do |method_name|
         # if the method doesn't already exist then queue this aliasing
@@ -49,12 +51,12 @@ module Qpid::Proton::Util
           @@to_be_wrapped ||= []
           @@to_be_wrapped << method_name
         else
-          create_exception_handler_wrapper(method_name, error_class)
+          create_exception_handler_wrapper(method_name, error_class, below)
         end
       end
     end
 
-    def create_exception_handler_wrapper(method_name, error_class = nil)
+    def create_exception_handler_wrapper(method_name, error_class = nil, below = 0)
       original_method_name = method_name.to_s
       wrapped_method_name = "_excwrap_#{original_method_name}"
       alias_method wrapped_method_name, original_method_name
@@ -63,7 +65,8 @@ module Qpid::Proton::Util
         # calls to Class.send interfere with Messenger.send
         method = self.method(wrapped_method_name.to_sym)
         rc = method.call(*args, &block)
-        check_for_error(rc, error_class)
+        check_for_error(rc, error_class) if rc < below
+        return rc
       end
     end
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[05/15] qpid-proton git commit: PROTON-799: Added the Delivery class to the Ruby engine APIs.

Posted by mc...@apache.org.
PROTON-799: Added the Delivery class to the Ruby engine APIs.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/13b466be
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/13b466be
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/13b466be

Branch: refs/heads/ruby-engine-apis
Commit: 13b466be8700c1fb179f51b2e96fb15a97b3bd8e
Parents: d147f1e
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Jan 20 11:10:34 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/delivery.rb | 271 +++++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb   |   1 +
 2 files changed, 272 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13b466be/proton-c/bindings/ruby/lib/core/delivery.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/delivery.rb b/proton-c/bindings/ruby/lib/core/delivery.rb
new file mode 100644
index 0000000..5c0b25c
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/core/delivery.rb
@@ -0,0 +1,271 @@
+#--
+# 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
+
+  # A Delivery maintains detail on the delivery of data to an endpoint.
+  #
+  # A Delivery has a single parent Qpid::Proton::Link
+  #
+  # @example
+  #
+  #   # SCENARIO: An event comes in notifying that data has been delivered to
+  #   #           the local endpoint. A Delivery object can be used to check
+  #   #           the details of the delivery.
+  #
+  #   delivery = @event.delivery
+  #   if delivery.readable? && !delivery.partial?
+  #     # decode the incoming message
+  #     msg = Qpid::Proton::Message.new
+  #     msg.decode(link.receive(delivery.pending))
+  #   end
+  #
+  class Delivery
+
+    # @private
+    include Util::Wrapper
+
+    # @private
+    def self.wrap(impl) # :nodoc:
+      return nil if impl.nil?
+      self.fetch_instance(impl, :pn_delivery_attachments) || Delivery.new(impl)
+    end
+
+    # @private
+    def initialize(impl)
+      @impl = impl
+      @local = Disposition.new(Cproton.pn_delivery_local(impl), true)
+      @remote = Disposition.new(Cproton.pn_delivery_remote(impl), false)
+      self.class.store_instance(self, :pn_delivery_attachments)
+    end
+
+    # @private
+    include Util::SwigHelper
+
+    # @private
+    PROTON_METHOD_PREFIX = "pn_delivery"
+
+    # @!attribute [r] tag
+    #
+    # @return [String] The tag for the delivery.
+    #
+    proton_caller :tag
+
+    # @!attribute [r] writable?
+    #
+    # A delivery is considered writable if it is the current delivery on an
+    # outgoing link, and the link has positive credit.
+    #
+    # @return [Boolean] Returns if a delivery is writable.
+    #
+    proton_caller :writable?
+
+    # @!attribute [r] readable?
+    #
+    # A delivery is considered readable if it is the current delivery on an
+    # incoming link.
+    #
+    # @return [Boolean] Returns if a delivery is readable.
+    #
+    proton_caller :readable?
+    # @!attribute [r] updated?
+    #
+    # A delivery is considered updated whenever the peer communicates a new
+    # disposition for the dlievery. Once a delivery becomes updated, it will
+    # remain so until cleared.
+    #
+    # @return [Boolean] Returns if a delivery is updated.
+    #
+    # @see #clear
+    #
+    proton_caller :updated?
+
+    # @!method clear
+    #
+    # Clear the updated flag for a delivery.
+    #
+    proton_caller :clear
+
+    # @!attribute [r] pending
+    #
+    # @return [Fixnum] Return the amount of pending message data for the
+    # delivery.
+    #
+    proton_caller :pending
+
+    # @!attribute [r] partial?
+    #
+    # @return [Boolean] Returns if the delivery has only partial message data.
+    #
+    proton_caller :partial?
+
+    # @!attribute [r] settled?
+    #
+    # @return [Boolean] Returns if the delivery is remotely settled.
+    #
+    proton_caller :settled?
+
+
+    # @!method settle
+    #
+    # Settles a delivery.
+    #
+    #  A settled delivery can never be used again.
+    #
+    proton_caller :settle
+
+    # @!method dump
+    #
+    #  Utility function for printing details of a delivery.
+    #
+    proton_caller :dump
+
+    # @!attribute [r] buffered?
+    #
+    # A delivery that is buffered has not yet been written to the wire.
+    #
+    # Note that returning false does not imply that a delivery was definitely
+    # written to the wire. If false is returned, it is not known whether the
+    # delivery was actually written to the wire or not.
+    #
+    # @return [Boolean] Returns if the delivery is buffered.
+    #
+    proton_caller :buffered?
+
+    include Util::Engine
+
+    def update(state)
+      impl = @local.impl
+      object_to_data(@local.data, Cproton.pn_disposition_data(impl))
+      object_to_data(@local.annotations, Cproton.pn_disposition_annotations(impl))
+      object_to_data(@local.condition, Cproton.pn_disposition_condition(impl))
+      Cproton.pn_delivery_update(@impl, state)
+    end
+
+    # Returns the local disposition state for the delivery.
+    #
+    # @return [Disposition] The local disposition state.
+    #
+    def local_state
+      Cproton.pn_delivery_local_state(@impl)
+    end
+
+    # Returns the remote disposition state for the delivery.
+    #
+    # @return [Disposition] The remote disposition state.
+    #
+    def remote_state
+      Cproton.pn_delivery_remote_state(@impl)
+    end
+
+    # Returns the next delivery on the connection that has pending operations.
+    #
+    # @return [Delivery, nil] The next delivery, or nil if there are none.
+    #
+    # @see Connection#work_head
+    #
+    def work_next
+      Delivery.wrap(Cproton.pn_work_next(@impl))
+    end
+
+    # Returns the parent link.
+    #
+    # @return [Link] The parent link.
+    #
+    def link
+      Link.wrap(Cproton.pn_delivery_link(@impl))
+    end
+
+    # Returns the parent session.
+    #
+    # @return [Session] The session.
+    #
+    def session
+      self.link.session
+    end
+
+    # Returns the parent connection.
+    #
+    # @return [Connection] The connection.
+    #
+    def connection
+      self.session.connection
+    end
+
+    # Returns the parent transport.
+    #
+    # @return [Transport] The transport.
+    #
+    def transport
+      self.connection.transport
+    end
+
+    # @private
+    def local_received?
+      self.local_state == Disposition::RECEIVED
+    end
+
+    # @private
+    def remote_received?
+      self.remote_state == Disposition::RECEIVED
+    end
+
+    # @private
+    def local_accepted?
+      self.local_state == Disposition::ACCEPTED
+    end
+
+    # @private
+    def remote_accepted?
+      self.remote_state == Disposition::ACCEPTED
+    end
+
+    # @private
+    def local_rejected?
+      self.local_state == Disposition::REJECTED
+    end
+
+    # @private
+    def remote_rejected?
+      self.remote_state == Disposition::REJECTED
+    end
+
+    # @private
+    def local_released?
+      self.local_state == Disposition::RELEASED
+    end
+
+    # @private
+    def remote_released?
+      self.remote_state == Disposition::RELEASED
+    end
+
+    # @private
+    def local_modified?
+      self.local_state == Disposition::MODIFIED
+    end
+
+    # @private
+    def remote_modified?
+      self.remote_state == Disposition::MODIFIED
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/13b466be/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 84c39fc..d7b5803 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -58,6 +58,7 @@ require "core/endpoint"
 require "core/session"
 require "core/terminus"
 require "core/disposition"
+require "core/delivery"
 
 # Messenger API classes
 require "messenger/filters"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[09/15] qpid-proton git commit: PROTON-799: Added the SASLError and TransportError errors to Ruby.

Posted by mc...@apache.org.
PROTON-799: Added the SASLError and TransportError errors to Ruby.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/310ffcf8
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/310ffcf8
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/310ffcf8

Branch: refs/heads/ruby-engine-apis
Commit: 310ffcf802b18cdfeb3036bc7e9083f38463749e
Parents: 14a6803
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Tue Jan 20 16:09:45 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Tue May 19 15:19:02 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/exceptions.rb | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/310ffcf8/proton-c/bindings/ruby/lib/core/exceptions.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/exceptions.rb b/proton-c/bindings/ruby/lib/core/exceptions.rb
index 8dead61..714830b 100644
--- a/proton-c/bindings/ruby/lib/core/exceptions.rb
+++ b/proton-c/bindings/ruby/lib/core/exceptions.rb
@@ -80,6 +80,11 @@ module Qpid
     class InProgressError < ProtonError
     end
 
+    # Raised by instances of SASL
+    #
+    class SASLError < TransportError
+    end
+
     # Raised by Session.
     #
     class SessionError < ProtonError


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org