Debian Codegraph @

ruby/lib/core/endpoint.rb

raw
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18
19 module Qpid::Proton
20
21 # Endpoint is the parent classes for Link and Session.
22 #
23 # It provides a namespace for constant values that relate to the current
24 # state of both links and sessions.
25 #
26 # @example
27 #
28 # conn = Qpid::Proton::Connection.new
29 # puts "Local connection flags : #{conn.state || Qpid::Proton::Endpoint::LOCAL_MASK}"
30 # puts "Remote connection flags: #{conn.state || Qpid::Proton::Endpoint::REMOTE_MASK}"
31 #
32 class Endpoint
33 include Util::Deprecation
34
35 # The local connection is uninitialized.
36 LOCAL_UNINIT = Cproton::PN_LOCAL_UNINIT
37 # The local connection is active.
38 LOCAL_ACTIVE = Cproton::PN_LOCAL_ACTIVE
39 # The local connection is closed.
40 LOCAL_CLOSED = Cproton::PN_LOCAL_CLOSED
41
42 # The remote connection is unitialized.
43 REMOTE_UNINIT = Cproton::PN_REMOTE_UNINIT
44 # The remote connection is active.
45 REMOTE_ACTIVE = Cproton::PN_REMOTE_ACTIVE
46 # The remote connection is closed.
47 REMOTE_CLOSED = Cproton::PN_REMOTE_CLOSED
48
49 # Bitmask for the local-only flags.
50 LOCAL_MASK = Cproton::PN_LOCAL_UNINIT | Cproton::PN_LOCAL_ACTIVE | Cproton::PN_LOCAL_CLOSED
51
52 # Bitmask for the remote-only flags.
53 REMOTE_MASK = Cproton::PN_REMOTE_UNINIT | Cproton::PN_REMOTE_ACTIVE | Cproton::PN_REMOTE_CLOSED
54
55 # @private
56 def condition; remote_condition || local_condition; end
57 # @private
58 def remote_condition; Condition.convert(_remote_condition); end
59 # @private
60 def local_condition; Condition.convert(_local_condition); end
61
62 # Return the transport associated with this endpoint.
63 #
64 # @return [Transport] The transport.
65 #
66 def transport
67 self.connection.transport
68 end
69
70 # @return [WorkQueue] the work queue for work on this endpoint.
71 def work_queue() connection.work_queue; end
72
73 # @private
74 # @return [Bool] true if {#state} has all the bits of `mask` set
75 def check_state(mask) (self.state & mask) == mask; end
76
77 # @return [Bool] true if endpoint has sent and received a CLOSE frame
78 def closed?() check_state(LOCAL_CLOSED | REMOTE_CLOSED); end
79
80 # @return [Bool] true if endpoint has sent and received an OPEN frame
81 def open?() check_state(LOCAL_ACTIVE | REMOTE_ACTIVE); end
82
83 def local_uninit?
84 check_state(LOCAL_UNINIT)
85 end
86
87 def local_open?
88 check_state(LOCAL_ACTIVE)
89 end
90
91 def local_closed?
92 check_state(LOCAL_CLOSED)
93 end
94
95 def remote_uninit?
96 check_state(REMOTE_UNINIT)
97 end
98
99 def remote_open?
100 check_state(REMOTE_ACTIVE)
101 end
102
103 def remote_closed?
104 check_state(REMOTE_CLOSED)
105 end
106
107 alias local_active? local_open?
108 alias remote_active? remote_open?
109
110 end
111 end