1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 
13 module hunt.proton.amqp.transport.Attach;
14 
15 
16 import hunt.proton.amqp.Binary;
17 import hunt.proton.amqp.Symbol;
18 import hunt.proton.amqp.UnsignedInteger;
19 import hunt.proton.amqp.UnsignedLong;
20 import hunt.proton.amqp.transport.FrameBody;
21 import hunt.proton.amqp.transport.Role;
22 import hunt.proton.amqp.transport.SenderSettleMode;
23 import hunt.proton.amqp.transport.ReceiverSettleMode;
24 import hunt.proton.amqp.transport.Source;
25 import hunt.proton.amqp.transport.Target;
26 import hunt.Object;
27 import hunt.logging;
28 import hunt.collection.Map;
29 import hunt.collection.LinkedHashMap;
30 import hunt.String;
31 import hunt.Boolean;
32 import hunt.collection.List;
33 import std.conv:to;
34 
35 class Attach : FrameBody
36 {
37     private String _name;
38     private UnsignedInteger _handle;
39     private Role _role ;//= Role.SENDER;
40     private SenderSettleMode _sndSettleMode ;
41     private ReceiverSettleMode _rcvSettleMode ;
42     private Source _source;
43     private Target _target;
44     private Map!(Symbol,Object) _unsettled;
45     private Boolean _incompleteUnsettled;
46     private UnsignedInteger _initialDeliveryCount;
47     private UnsignedLong _maxMessageSize;
48     private List!Symbol _offeredCapabilities;
49     private List!Symbol _desiredCapabilities;
50     private Map!(Symbol,Object) _properties;
51 
52     this() {
53         _sndSettleMode = SenderSettleMode.MIXED;
54         _rcvSettleMode = ReceiverSettleMode.FIRST;
55         _role = Role.SENDER;
56         _desiredCapabilities = null;
57         _offeredCapabilities = null;
58         _properties = null;
59         _unsettled = null;
60        _incompleteUnsettled = new Boolean(false);
61     }
62 
63     this(Attach other)
64     {
65         this._name = other.getName();
66         this._handle = other.getHandle();
67         this._role = other.getRole();
68         this._sndSettleMode = other.getSndSettleMode();
69         this._rcvSettleMode = other.getRcvSettleMode();
70         if (other._source !is null) {
71             this._source = other.getSource().copy();
72         }
73         if (other._target !is null) {
74             this._target = other.getTarget().copy();
75         }
76         if (other._unsettled !is null) {
77             this._unsettled = new LinkedHashMap!(Symbol,Object)(other.getUnsettled());
78         }
79         this._incompleteUnsettled = other.getIncompleteUnsettled();
80         this._initialDeliveryCount = other.getInitialDeliveryCount();
81         this._maxMessageSize = other.getMaxMessageSize();
82         if (other.getOfferedCapabilities() !is null) {
83             this._offeredCapabilities = other.getOfferedCapabilities();
84         }
85         if (other.getDesiredCapabilities() !is null) {
86             this._desiredCapabilities = other.getDesiredCapabilities();
87         }
88         if (other.getProperties() !is null) {
89             this._properties = new LinkedHashMap!(Symbol,Object)(other.getProperties());
90         }
91     }
92 
93     public String getName()
94     {
95         return _name;
96     }
97 
98     public void setName(String name)
99     {
100         if( name is null )
101         {
102             logError("the name field is mandatory");
103         }
104 
105         _name = name;
106     }
107 
108     public UnsignedInteger getHandle()
109     {
110         return _handle;
111     }
112 
113     public void setHandle(UnsignedInteger handle)
114     {
115         if( handle is null )
116         {
117             logError("the handle field is mandatory");
118         }
119 
120         _handle = handle;
121     }
122 
123     public Role getRole()
124     {
125         return _role;
126     }
127 
128     public void setRole(Role role)
129     {
130         if(role is null)
131         {
132             logError("Role cannot be null");
133         }
134         _role = role;
135     }
136 
137     public SenderSettleMode getSndSettleMode()
138     {
139         return _sndSettleMode;
140     }
141 
142     public void setSndSettleMode(SenderSettleMode sndSettleMode)
143     {
144         _sndSettleMode = sndSettleMode is null ? SenderSettleMode.MIXED : sndSettleMode;
145     }
146 
147     public ReceiverSettleMode getRcvSettleMode()
148     {
149         return _rcvSettleMode;
150     }
151 
152     public void setRcvSettleMode(ReceiverSettleMode rcvSettleMode)
153     {
154         _rcvSettleMode = rcvSettleMode is null ? ReceiverSettleMode.FIRST : rcvSettleMode;
155     }
156 
157     public Source getSource()
158     {
159         return _source;
160     }
161 
162     public void setSource(Source source)
163     {
164         _source = source;
165     }
166 
167     public Target getTarget()
168     {
169         return _target;
170     }
171 
172     public void setTarget(Target target)
173     {
174         _target = target;
175     }
176 
177     public Map!(Symbol,Object) getUnsettled()
178     {
179         return _unsettled;
180     }
181 
182     public void setUnsettled(Map!(Symbol,Object) unsettled)
183     {
184         _unsettled = unsettled;
185     }
186 
187     public Boolean getIncompleteUnsettled()
188     {
189         return _incompleteUnsettled;
190     }
191 
192     public void setIncompleteUnsettled(Boolean incompleteUnsettled)
193     {
194         _incompleteUnsettled = incompleteUnsettled;
195     }
196 
197     public UnsignedInteger getInitialDeliveryCount()
198     {
199         return _initialDeliveryCount;
200     }
201 
202     public void setInitialDeliveryCount(UnsignedInteger initialDeliveryCount)
203     {
204         _initialDeliveryCount = initialDeliveryCount;
205     }
206 
207     public UnsignedLong getMaxMessageSize()
208     {
209         return _maxMessageSize;
210     }
211 
212     public void setMaxMessageSize(UnsignedLong maxMessageSize)
213     {
214         _maxMessageSize = maxMessageSize;
215     }
216 
217     public List!Symbol getOfferedCapabilities()
218     {
219         return _offeredCapabilities;
220     }
221 
222     public void setOfferedCapabilities(List!Symbol offeredCapabilities)
223     {
224         _offeredCapabilities = offeredCapabilities;
225     }
226 
227     public List!Symbol getDesiredCapabilities()
228     {
229         return _desiredCapabilities;
230     }
231 
232     public void setDesiredCapabilities(List!Symbol desiredCapabilities)
233     {
234         _desiredCapabilities = desiredCapabilities;
235     }
236 
237     public Map!(Symbol,Object) getProperties()
238     {
239         return _properties;
240     }
241 
242     public void setProperties(Map!(Symbol,Object) properties)
243     {
244         _properties = properties;
245     }
246 
247     //override
248     public void invoke(E)(FrameBodyHandler!E handler, Binary payload, E context)
249     {
250         handler.handleAttach(this, payload, context);
251     }
252 
253 
254     override
255     string toString()
256     {
257         string att = "Attach{" ~ 
258             "name=" ~ _name.value ~
259             ", handle=" ~ (to!string(_handle.intValue)) ~
260             ", role=" ~ (to!string(_role.ordinal)) ~
261             ", sndSettleMode=" ~ (to!string(_sndSettleMode.getValue.intValue)) ~
262             ", rcvSettleMode=" ~ (to!string(_rcvSettleMode.getValue.intValue) )~
263             ", source="  ~ (_source is null ? "null" : _source.toString()) ~
264             ", target="  ~ (_target is null ? "null" : _target.toString()) ~
265             ", unsettled=" ~ (_unsettled is null ? "null" : _unsettled.toString()) ~
266             ", incompleteUnsettled=" ~  (_incompleteUnsettled is null ? "null" : _incompleteUnsettled.toString()) ~
267             ", initialDeliveryCount=" ~ ( _initialDeliveryCount is null ? "null": _initialDeliveryCount.toString()) ~
268             ", maxMessageSize=" ~ (_maxMessageSize is null ? "null" :  _maxMessageSize.toString()) ~
269             ", offeredCapabilities=" ~ (_offeredCapabilities is null ? "null" : _offeredCapabilities.toString()) ~
270             ", desiredCapabilities=" ~ (_desiredCapabilities is null ? "null" : _desiredCapabilities.toString()) ~
271             ", properties=" ~ (_properties is null? "null": _properties.toString()) ~
272             '}';
273 
274         return att;
275     }
276 
277     public FrameBody copy()
278     {
279         return new Attach(this);
280     }
281 }