Debian Codegraph @

ruby/lib/core/disposition.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 class Disposition
22 include Util::Deprecation
23
24 # @private
25 PROTON_METHOD_PREFIX = "pn_disposition"
26 # @private
27 extend Util::SWIGClassHelper
28
29 # States of a message transfer
30 module State
31 # Message was successfully processed by the receiver
32 ACCEPTED = Cproton::PN_ACCEPTED
33
34 # Message rejected as invalid and unprocessable by the receiver.
35 REJECTED = Cproton::PN_REJECTED
36
37 # Message was not (and will not be) processed by the receiver, but may be
38 # acceptable if re-delivered to another receiver
39 RELEASED = Cproton::PN_RELEASED
40 # Like {RELEASED}, but there are modifications (see {Tracker#modifications})
41 # that must be applied to the message by the {Sender} before re-delivering it.
42 MODIFIED = Cproton::PN_MODIFIED
43
44 # Partial message data received. Only used during link recovery.
45 RECEIVED = Cproton::PN_RECEIVED
46
47 module ClassMethods
48 def name_of(state) Cproton::pn_disposition_type_name(state); end
49 end
50 extend ClassMethods
51 def self.included(klass) klass.extend ClassMethods; end
52 end
53 include State
54
55 attr_reader :impl
56
57 # @private
58 def initialize(impl, local)
59 deprecated self.class, Delivery
60 @impl = impl
61 @local = local
62 @data = nil
63 @condition = nil
64 @annotations = nil
65 end
66
67 # @!attribute section_number
68 #
69 # @return [Integer] The section number of the disposition.
70 #
71 proton_set_get :section_number
72
73 # @!attribute section_offset
74 #
75 # @return [Integer] The section offset of the disposition.
76 #
77 proton_set_get :section_offset
78
79 # @!attribute failed?
80 #
81 # @return [Boolean] The failed flag.
82 #
83 proton_set_is :failed
84
85 # @!attribute undeliverable?
86 #
87 # @return [Boolean] The undeliverable flag.
88 #
89 proton_set_is :undeliverable
90
91 # Sets the data for the disposition.
92 #
93 # @param data [Codec::Data] The data.
94 #
95 # @raise [AttributeError] If the disposition is remote.
96 #
97 def data=(data)
98 raise AttributeError.new("data attribute is read-only") unless @local
99 @data = data
100 end
101
102 # Returns the data for the disposition.
103 #
104 # @return [Codec::Data] The data.
105 #
106 def data
107 if @local
108 @data
109 else
110 Codec::Data.to_object(Cproton.pn_disposition_data(@impl))
111 end
112 end
113
114 # Sets the annotations for the disposition.
115 #
116 # @param annotations [Codec::Data] The annotations.
117 #
118 # @raise [AttributeError] If the disposition is remote.
119 #
120 def annotations=(annotations)
121 raise AttributeError.new("annotations attribute is read-only") unless @local
122 @annotations = annotations
123 end
124
125 # Returns the annotations for the disposition.
126 #
127 # @return [Codec::Data] The annotations.
128 #
129 def annotations
130 if @local
131 @annotations
132 else
133 Codec::Data.to_object(Cproton.pn_disposition_annotations(@impl))
134 end
135 end
136
137 # Sets the condition for the disposition.
138 #
139 # @param condition [Codec::Data] The condition.
140 #
141 # @raise [AttributeError] If the disposition is remote.
142 #
143 def condition=(condition)
144 raise AttributeError.new("condition attribute is read-only") unless @local
145 @condition = condition
146 end
147
148 # Returns the condition of the disposition.
149 #
150 # @return [Codec::Data] The condition of the disposition.
151 #
152 def condition
153 if @local
154 @condition
155 else
156 Condition.convert(Cproton.pn_disposition_condition(@impl))
157 end
158 end
159
160 end
161
162 end