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.Disposition;
14 
15 import hunt.proton.amqp.Binary;
16 import hunt.proton.amqp.UnsignedInteger;
17 import hunt.proton.amqp.transport.Role;
18 import hunt.proton.amqp.transport.FrameBody;
19 import hunt.proton.amqp.transport.DeliveryState;
20 import hunt.logging;
21 import hunt.Boolean;
22 
23 class Disposition : FrameBody
24 {
25     private Role _role ;//= Role.SENDER;
26     private UnsignedInteger _first;
27     private UnsignedInteger _last;
28     private Boolean _settled;
29     private DeliveryState _state;
30     private Boolean _batchable;
31 
32     this() {
33         _role = Role.SENDER;
34         _settled = new Boolean(false);
35         _batchable = new Boolean(false);
36     }
37 
38     this(Disposition other)
39     {
40         this._role = other.getRole();
41         this._first = other.getFirst();
42         this._last = other.getLast();
43         this._settled = other.getSettled();
44         this._state = other.getState();
45         this._batchable = other.getBatchable();
46     }
47 
48     public Role getRole()
49     {
50         return _role;
51     }
52 
53     public void setRole(Role role)
54     {
55         if(role is null)
56         {
57             logError("Role cannot be null");
58         }
59         _role = role;
60     }
61 
62     public UnsignedInteger getFirst()
63     {
64         return _first;
65     }
66 
67     public void setFirst(UnsignedInteger first)
68     {
69         if( first is null )
70         {
71             logError("the first field is mandatory");
72         }
73 
74         _first = first;
75     }
76 
77     public UnsignedInteger getLast()
78     {
79         return _last;
80     }
81 
82     public void setLast(UnsignedInteger last)
83     {
84         _last = last;
85     }
86 
87     public Boolean getSettled()
88     {
89         return _settled;
90     }
91 
92     public void setSettled(Boolean settled)
93     {
94         _settled = settled;
95     }
96 
97     public DeliveryState getState()
98     {
99         return _state;
100     }
101 
102     public void setState(DeliveryState state)
103     {
104         _state = state;
105     }
106 
107     public Boolean getBatchable()
108     {
109         return _batchable;
110     }
111 
112     public void setBatchable(Boolean batchable)
113     {
114         _batchable = batchable;
115     }
116 
117     //override
118     public void invoke(E)(FrameBodyHandler!E handler, Binary payload, E context)
119     {
120         handler.handleDisposition(this, payload, context);
121     }
122 
123 
124     public FrameBody copy()
125     {
126         return new Disposition(this);
127     }
128 }