1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.rxtx;
17
18 import io.netty.buffer.ByteBufAllocator;
19 import io.netty.channel.ChannelOption;
20 import io.netty.channel.DefaultChannelConfig;
21 import io.netty.channel.MessageSizeEstimator;
22 import io.netty.channel.RecvByteBufAllocator;
23
24 import java.util.Map;
25
26 import static io.netty.channel.rxtx.RxtxChannelOption.*;
27
28
29
30
31
32
33 @Deprecated
34 final class DefaultRxtxChannelConfig extends DefaultChannelConfig implements RxtxChannelConfig {
35
36 private volatile int baudrate = 115200;
37 private volatile boolean dtr;
38 private volatile boolean rts;
39 private volatile Stopbits stopbits = Stopbits.STOPBITS_1;
40 private volatile Databits databits = Databits.DATABITS_8;
41 private volatile Paritybit paritybit = Paritybit.NONE;
42 private volatile int waitTime;
43 private volatile int readTimeout = 1000;
44
45 DefaultRxtxChannelConfig(RxtxChannel channel) {
46 super(channel);
47 }
48
49 @Override
50 public Map<ChannelOption<?>, Object> getOptions() {
51 return getOptions(super.getOptions(), BAUD_RATE, DTR, RTS, STOP_BITS, DATA_BITS, PARITY_BIT, WAIT_TIME);
52 }
53
54 @SuppressWarnings("unchecked")
55 @Override
56 public <T> T getOption(ChannelOption<T> option) {
57 if (option == BAUD_RATE) {
58 return (T) Integer.valueOf(getBaudrate());
59 }
60 if (option == DTR) {
61 return (T) Boolean.valueOf(isDtr());
62 }
63 if (option == RTS) {
64 return (T) Boolean.valueOf(isRts());
65 }
66 if (option == STOP_BITS) {
67 return (T) getStopbits();
68 }
69 if (option == DATA_BITS) {
70 return (T) getDatabits();
71 }
72 if (option == PARITY_BIT) {
73 return (T) getParitybit();
74 }
75 if (option == WAIT_TIME) {
76 return (T) Integer.valueOf(getWaitTimeMillis());
77 }
78 if (option == READ_TIMEOUT) {
79 return (T) Integer.valueOf(getReadTimeout());
80 }
81 return super.getOption(option);
82 }
83
84 @Override
85 public <T> boolean setOption(ChannelOption<T> option, T value) {
86 validate(option, value);
87
88 if (option == BAUD_RATE) {
89 setBaudrate((Integer) value);
90 } else if (option == DTR) {
91 setDtr((Boolean) value);
92 } else if (option == RTS) {
93 setRts((Boolean) value);
94 } else if (option == STOP_BITS) {
95 setStopbits((Stopbits) value);
96 } else if (option == DATA_BITS) {
97 setDatabits((Databits) value);
98 } else if (option == PARITY_BIT) {
99 setParitybit((Paritybit) value);
100 } else if (option == WAIT_TIME) {
101 setWaitTimeMillis((Integer) value);
102 } else if (option == READ_TIMEOUT) {
103 setReadTimeout((Integer) value);
104 } else {
105 return super.setOption(option, value);
106 }
107 return true;
108 }
109
110 @Override
111 public RxtxChannelConfig setBaudrate(final int baudrate) {
112 this.baudrate = baudrate;
113 return this;
114 }
115
116 @Override
117 public RxtxChannelConfig setStopbits(final Stopbits stopbits) {
118 this.stopbits = stopbits;
119 return this;
120 }
121
122 @Override
123 public RxtxChannelConfig setDatabits(final Databits databits) {
124 this.databits = databits;
125 return this;
126 }
127
128 @Override
129 public RxtxChannelConfig setParitybit(final Paritybit paritybit) {
130 this.paritybit = paritybit;
131 return this;
132 }
133
134 @Override
135 public int getBaudrate() {
136 return baudrate;
137 }
138
139 @Override
140 public Stopbits getStopbits() {
141 return stopbits;
142 }
143
144 @Override
145 public Databits getDatabits() {
146 return databits;
147 }
148
149 @Override
150 public Paritybit getParitybit() {
151 return paritybit;
152 }
153
154 @Override
155 public boolean isDtr() {
156 return dtr;
157 }
158
159 @Override
160 public RxtxChannelConfig setDtr(final boolean dtr) {
161 this.dtr = dtr;
162 return this;
163 }
164
165 @Override
166 public boolean isRts() {
167 return rts;
168 }
169
170 @Override
171 public RxtxChannelConfig setRts(final boolean rts) {
172 this.rts = rts;
173 return this;
174 }
175
176 @Override
177 public int getWaitTimeMillis() {
178 return waitTime;
179 }
180
181 @Override
182 public RxtxChannelConfig setWaitTimeMillis(final int waitTimeMillis) {
183 if (waitTimeMillis < 0) {
184 throw new IllegalArgumentException("Wait time must be >= 0");
185 }
186 waitTime = waitTimeMillis;
187 return this;
188 }
189
190 @Override
191 public RxtxChannelConfig setReadTimeout(int readTimeout) {
192 if (readTimeout < 0) {
193 throw new IllegalArgumentException("readTime must be >= 0");
194 }
195 this.readTimeout = readTimeout;
196 return this;
197 }
198
199 @Override
200 public int getReadTimeout() {
201 return readTimeout;
202 }
203
204 @Override
205 public RxtxChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
206 super.setConnectTimeoutMillis(connectTimeoutMillis);
207 return this;
208 }
209
210 @Override
211 public RxtxChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
212 super.setMaxMessagesPerRead(maxMessagesPerRead);
213 return this;
214 }
215
216 @Override
217 public RxtxChannelConfig setWriteSpinCount(int writeSpinCount) {
218 super.setWriteSpinCount(writeSpinCount);
219 return this;
220 }
221
222 @Override
223 public RxtxChannelConfig setAllocator(ByteBufAllocator allocator) {
224 super.setAllocator(allocator);
225 return this;
226 }
227
228 @Override
229 public RxtxChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
230 super.setRecvByteBufAllocator(allocator);
231 return this;
232 }
233
234 @Override
235 public RxtxChannelConfig setAutoRead(boolean autoRead) {
236 super.setAutoRead(autoRead);
237 return this;
238 }
239
240 @Override
241 public RxtxChannelConfig setAutoClose(boolean autoClose) {
242 super.setAutoClose(autoClose);
243 return this;
244 }
245
246 @Override
247 public RxtxChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
248 super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
249 return this;
250 }
251
252 @Override
253 public RxtxChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
254 super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
255 return this;
256 }
257
258 @Override
259 public RxtxChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
260 super.setMessageSizeEstimator(estimator);
261 return this;
262 }
263 }