propane 3.10.0-java → 3.11.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/wrapper/maven-wrapper.properties +1 -1
- data/CHANGELOG.md +2 -0
- data/README.md +7 -7
- data/lib/propane/app.rb +2 -5
- data/lib/propane/helper_methods.rb +6 -6
- data/lib/propane/version.rb +1 -1
- data/lib/{propane-3.10.0.jar → propane-3.11.0.jar} +0 -0
- data/pom.rb +6 -6
- data/pom.xml +6 -6
- data/propane.gemspec +3 -3
- data/src/main/java/monkstone/noise/OpenSimplex2F.java +838 -737
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +8 -13
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +14 -28
- data/src/main/java/processing/awt/PImageAWT.java +6 -4
- data/src/main/java/processing/core/PApplet.java +71 -59
- data/src/main/java/processing/core/PImage.java +14 -14
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13 -13
- data/src/main/java/processing/opengl/PShader.java +1 -6
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +6 -6
- data/{lib/java/processing/opengl → src/main/resources}/cursors/arrow.png +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/cursors/cross.png +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/cursors/hand.png +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/cursors/license.txt +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/cursors/move.png +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/cursors/text.png +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/cursors/wait.png +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/ColorFrag.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/ColorVert.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/LightFrag.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/LightVert.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/LineFrag.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/LineVert.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/MaskFrag.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/PointFrag.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/PointVert.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/TexFrag.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/TexLightFrag.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/TexLightVert.glsl +0 -0
- data/{lib/java/processing/opengl → src/main/resources}/shaders/TexVert.glsl +0 -0
- data/test/test_helper.rb +1 -0
- data/vendors/Rakefile +1 -1
- metadata +29 -155
- data/lib/java/japplemenubar/JAppleMenuBar.java +0 -88
- data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/lib/java/monkstone/ColorUtil.java +0 -127
- data/lib/java/monkstone/MathToolModule.java +0 -287
- data/lib/java/monkstone/PropaneLibrary.java +0 -46
- data/lib/java/monkstone/core/LibraryProxy.java +0 -136
- data/lib/java/monkstone/fastmath/DegLutTables.java +0 -111
- data/lib/java/monkstone/fastmath/Deglut.java +0 -71
- data/lib/java/monkstone/fastmath/package-info.java +0 -6
- data/lib/java/monkstone/filechooser/Chooser.java +0 -39
- data/lib/java/monkstone/noise/FastTerrain.java +0 -874
- data/lib/java/monkstone/noise/Noise.java +0 -90
- data/lib/java/monkstone/noise/NoiseGenerator.java +0 -75
- data/lib/java/monkstone/noise/NoiseMode.java +0 -28
- data/lib/java/monkstone/noise/OpenSimplex2F.java +0 -881
- data/lib/java/monkstone/noise/OpenSimplex2S.java +0 -1106
- data/lib/java/monkstone/noise/SmoothTerrain.java +0 -1099
- data/lib/java/monkstone/slider/CustomHorizontalSlider.java +0 -164
- data/lib/java/monkstone/slider/CustomVerticalSlider.java +0 -178
- data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +0 -145
- data/lib/java/monkstone/slider/SimpleSlider.java +0 -166
- data/lib/java/monkstone/slider/SimpleVerticalSlider.java +0 -157
- data/lib/java/monkstone/slider/Slider.java +0 -61
- data/lib/java/monkstone/slider/SliderBar.java +0 -245
- data/lib/java/monkstone/slider/SliderGroup.java +0 -56
- data/lib/java/monkstone/slider/WheelHandler.java +0 -35
- data/lib/java/monkstone/vecmath/GfxRender.java +0 -86
- data/lib/java/monkstone/vecmath/JRender.java +0 -56
- data/lib/java/monkstone/vecmath/ShapeRender.java +0 -87
- data/lib/java/monkstone/vecmath/package-info.java +0 -20
- data/lib/java/monkstone/vecmath/vec2/Vec2.java +0 -802
- data/lib/java/monkstone/vecmath/vec2/package-info.java +0 -6
- data/lib/java/monkstone/vecmath/vec3/Vec3.java +0 -727
- data/lib/java/monkstone/vecmath/vec3/package-info.java +0 -6
- data/lib/java/monkstone/videoevent/CaptureEvent.java +0 -27
- data/lib/java/monkstone/videoevent/MovieEvent.java +0 -32
- data/lib/java/monkstone/videoevent/package-info.java +0 -20
- data/lib/java/processing/awt/PGraphicsJava2D.java +0 -3040
- data/lib/java/processing/awt/PImageAWT.java +0 -377
- data/lib/java/processing/awt/PShapeJava2D.java +0 -387
- data/lib/java/processing/awt/PSurfaceAWT.java +0 -1581
- data/lib/java/processing/awt/ShimAWT.java +0 -581
- data/lib/java/processing/core/PApplet.java +0 -15156
- data/lib/java/processing/core/PConstants.java +0 -523
- data/lib/java/processing/core/PFont.java +0 -1126
- data/lib/java/processing/core/PGraphics.java +0 -8600
- data/lib/java/processing/core/PImage.java +0 -3377
- data/lib/java/processing/core/PMatrix.java +0 -208
- data/lib/java/processing/core/PMatrix2D.java +0 -562
- data/lib/java/processing/core/PMatrix3D.java +0 -890
- data/lib/java/processing/core/PShape.java +0 -3561
- data/lib/java/processing/core/PShapeOBJ.java +0 -483
- data/lib/java/processing/core/PShapeSVG.java +0 -2016
- data/lib/java/processing/core/PStyle.java +0 -63
- data/lib/java/processing/core/PSurface.java +0 -198
- data/lib/java/processing/core/PSurfaceNone.java +0 -431
- data/lib/java/processing/core/PVector.java +0 -1066
- data/lib/java/processing/core/ThinkDifferent.java +0 -115
- data/lib/java/processing/data/DoubleDict.java +0 -850
- data/lib/java/processing/data/DoubleList.java +0 -928
- data/lib/java/processing/data/FloatDict.java +0 -847
- data/lib/java/processing/data/FloatList.java +0 -936
- data/lib/java/processing/data/IntDict.java +0 -807
- data/lib/java/processing/data/IntList.java +0 -936
- data/lib/java/processing/data/JSONArray.java +0 -1260
- data/lib/java/processing/data/JSONObject.java +0 -2282
- data/lib/java/processing/data/JSONTokener.java +0 -435
- data/lib/java/processing/data/LongDict.java +0 -802
- data/lib/java/processing/data/LongList.java +0 -937
- data/lib/java/processing/data/Sort.java +0 -46
- data/lib/java/processing/data/StringDict.java +0 -613
- data/lib/java/processing/data/StringList.java +0 -800
- data/lib/java/processing/data/Table.java +0 -4936
- data/lib/java/processing/data/TableRow.java +0 -198
- data/lib/java/processing/data/XML.java +0 -1156
- data/lib/java/processing/dxf/RawDXF.java +0 -404
- data/lib/java/processing/event/Event.java +0 -125
- data/lib/java/processing/event/KeyEvent.java +0 -70
- data/lib/java/processing/event/MouseEvent.java +0 -114
- data/lib/java/processing/event/TouchEvent.java +0 -57
- data/lib/java/processing/javafx/PGraphicsFX2D.java +0 -32
- data/lib/java/processing/javafx/PSurfaceFX.java +0 -173
- data/lib/java/processing/net/Client.java +0 -744
- data/lib/java/processing/net/Server.java +0 -388
- data/lib/java/processing/opengl/FontTexture.java +0 -378
- data/lib/java/processing/opengl/FrameBuffer.java +0 -513
- data/lib/java/processing/opengl/LinePath.java +0 -627
- data/lib/java/processing/opengl/LineStroker.java +0 -681
- data/lib/java/processing/opengl/PGL.java +0 -3483
- data/lib/java/processing/opengl/PGraphics2D.java +0 -615
- data/lib/java/processing/opengl/PGraphics3D.java +0 -281
- data/lib/java/processing/opengl/PGraphicsOpenGL.java +0 -13753
- data/lib/java/processing/opengl/PJOGL.java +0 -2008
- data/lib/java/processing/opengl/PShader.java +0 -1484
- data/lib/java/processing/opengl/PShapeOpenGL.java +0 -5269
- data/lib/java/processing/opengl/PSurfaceJOGL.java +0 -1385
- data/lib/java/processing/opengl/Texture.java +0 -1696
- data/lib/java/processing/opengl/VertexBuffer.java +0 -88
- data/lib/java/processing/pdf/PGraphicsPDF.java +0 -581
- data/lib/java/processing/svg/PGraphicsSVG.java +0 -378
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +0 -27
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +0 -32
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +0 -34
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +0 -33
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +0 -151
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +0 -32
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +0 -100
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +0 -40
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +0 -32
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +0 -56
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +0 -37
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +0 -37
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +0 -157
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +0 -38
@@ -1,744 +0,0 @@
|
|
1
|
-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
-
|
3
|
-
/*
|
4
|
-
Client - basic network client implementation
|
5
|
-
Part of the Processing project - http://processing.org
|
6
|
-
|
7
|
-
Copyright (c) 2004-2007 Ben Fry and Casey Reas
|
8
|
-
The previous version of this code was developed by Hernando Barragan
|
9
|
-
|
10
|
-
This library is free software; you can redistribute it and/or
|
11
|
-
modify it under the terms of the GNU Lesser General Public
|
12
|
-
License as published by the Free Software Foundation; either
|
13
|
-
version 2.1 of the License, or (at your option) any later version.
|
14
|
-
|
15
|
-
This library is distributed in the hope that it will be useful,
|
16
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
18
|
-
Lesser General Public License for more details.
|
19
|
-
|
20
|
-
You should have received a copy of the GNU Lesser General
|
21
|
-
Public License along with this library; if not, write to the
|
22
|
-
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
23
|
-
Boston, MA 02111-1307 USA
|
24
|
-
*/
|
25
|
-
|
26
|
-
package processing.net;
|
27
|
-
import processing.core.*;
|
28
|
-
|
29
|
-
import java.io.*;
|
30
|
-
import java.lang.reflect.*;
|
31
|
-
import java.net.*;
|
32
|
-
|
33
|
-
/**
|
34
|
-
* ( begin auto-generated from Client.xml )
|
35
|
-
*
|
36
|
-
* A client connects to a server and sends data back and forth. If anything
|
37
|
-
* goes wrong with the connection, for example the host is not there or is
|
38
|
-
* listening on a different port, an exception is thrown.
|
39
|
-
*
|
40
|
-
*
|
41
|
-
* @webref net
|
42
|
-
* @brief The client class is used to create client Objects which connect to a server to exchange data.
|
43
|
-
* @instanceName client any variable of type Client
|
44
|
-
* @usage Application
|
45
|
-
* @see_external LIB_net/clientEvent
|
46
|
-
*/
|
47
|
-
public class Client implements Runnable {
|
48
|
-
|
49
|
-
protected static final int MAX_BUFFER_SIZE = 1 << 27; // 128 MB
|
50
|
-
|
51
|
-
PApplet parent;
|
52
|
-
Method clientEventMethod;
|
53
|
-
Method disconnectEventMethod;
|
54
|
-
|
55
|
-
volatile Thread thread;
|
56
|
-
Socket socket;
|
57
|
-
int port;
|
58
|
-
String host;
|
59
|
-
|
60
|
-
public InputStream input;
|
61
|
-
public OutputStream output;
|
62
|
-
|
63
|
-
final Object bufferLock = new Object[0];
|
64
|
-
|
65
|
-
byte buffer[] = new byte[32768];
|
66
|
-
int bufferIndex;
|
67
|
-
int bufferLast;
|
68
|
-
|
69
|
-
boolean disposeRegistered = false;
|
70
|
-
|
71
|
-
|
72
|
-
/**
|
73
|
-
* @param parent typically use "this"
|
74
|
-
* @param host address of the server
|
75
|
-
* @param port port to read/write from on the server
|
76
|
-
*/
|
77
|
-
public Client(PApplet parent, String host, int port) {
|
78
|
-
this.parent = parent;
|
79
|
-
this.host = host;
|
80
|
-
this.port = port;
|
81
|
-
|
82
|
-
try {
|
83
|
-
socket = new Socket(this.host, this.port);
|
84
|
-
input = socket.getInputStream();
|
85
|
-
output = socket.getOutputStream();
|
86
|
-
|
87
|
-
thread = new Thread(this);
|
88
|
-
thread.start();
|
89
|
-
|
90
|
-
parent.registerMethod("dispose", this);
|
91
|
-
disposeRegistered = true;
|
92
|
-
|
93
|
-
// reflection to check whether host sketch has a call for
|
94
|
-
// public void clientEvent(processing.net.Client)
|
95
|
-
// which would be called each time an event comes in
|
96
|
-
try {
|
97
|
-
clientEventMethod =
|
98
|
-
parent.getClass().getMethod("clientEvent", Client.class);
|
99
|
-
} catch (Exception e) {
|
100
|
-
// no such method, or an error.. which is fine, just ignore
|
101
|
-
}
|
102
|
-
// do the same for disconnectEvent(Client c);
|
103
|
-
try {
|
104
|
-
disconnectEventMethod =
|
105
|
-
parent.getClass().getMethod("disconnectEvent", Client.class);
|
106
|
-
} catch (Exception e) {
|
107
|
-
// no such method, or an error.. which is fine, just ignore
|
108
|
-
}
|
109
|
-
|
110
|
-
} catch (IOException e) {
|
111
|
-
|
112
|
-
dispose();
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
|
117
|
-
/**
|
118
|
-
* @param socket any object of type Socket
|
119
|
-
* @throws IOException
|
120
|
-
*/
|
121
|
-
public Client(PApplet parent, Socket socket) throws IOException {
|
122
|
-
this.parent = parent;
|
123
|
-
this.socket = socket;
|
124
|
-
|
125
|
-
input = socket.getInputStream();
|
126
|
-
output = socket.getOutputStream();
|
127
|
-
|
128
|
-
thread = new Thread(this);
|
129
|
-
thread.start();
|
130
|
-
|
131
|
-
// reflection to check whether host sketch has a call for
|
132
|
-
// public void clientEvent(processing.net.Client)
|
133
|
-
// which would be called each time an event comes in
|
134
|
-
try {
|
135
|
-
clientEventMethod =
|
136
|
-
parent.getClass().getMethod("clientEvent", Client.class);
|
137
|
-
} catch (Exception e) {
|
138
|
-
// no such method, or an error.. which is fine, just ignore
|
139
|
-
}
|
140
|
-
// do the same for disconnectEvent(Client c);
|
141
|
-
try {
|
142
|
-
disconnectEventMethod =
|
143
|
-
parent.getClass().getMethod("disconnectEvent", Client.class);
|
144
|
-
} catch (Exception e) {
|
145
|
-
// no such method, or an error.. which is fine, just ignore
|
146
|
-
}
|
147
|
-
}
|
148
|
-
|
149
|
-
|
150
|
-
/**
|
151
|
-
* ( begin auto-generated from Client_stop.xml )
|
152
|
-
*
|
153
|
-
* Disconnects from the server. Use to shut the connection when you're
|
154
|
-
* finished with the Client.
|
155
|
-
*
|
156
|
-
*
|
157
|
-
* @webref client:client
|
158
|
-
* @brief Disconnects from the server
|
159
|
-
* @usage application
|
160
|
-
*/
|
161
|
-
public void stop() {
|
162
|
-
if (disconnectEventMethod != null && thread != null){
|
163
|
-
try {
|
164
|
-
disconnectEventMethod.invoke(parent, this);
|
165
|
-
} catch (Exception e) {
|
166
|
-
Throwable cause = e;
|
167
|
-
// unwrap the exception if it came from the user code
|
168
|
-
if (e instanceof InvocationTargetException && e.getCause() != null) {
|
169
|
-
cause = e.getCause();
|
170
|
-
}
|
171
|
-
cause.printStackTrace();
|
172
|
-
disconnectEventMethod = null;
|
173
|
-
}
|
174
|
-
}
|
175
|
-
if (disposeRegistered) {
|
176
|
-
parent.unregisterMethod("dispose", this);
|
177
|
-
disposeRegistered = false;
|
178
|
-
}
|
179
|
-
dispose();
|
180
|
-
}
|
181
|
-
|
182
|
-
|
183
|
-
/**
|
184
|
-
* Disconnect from the server: internal use only.
|
185
|
-
* <P>
|
186
|
-
* This should only be called by the internal functions in PApplet,
|
187
|
-
* use stop() instead from within your own applets.
|
188
|
-
*/
|
189
|
-
public void dispose() {
|
190
|
-
thread = null;
|
191
|
-
try {
|
192
|
-
if (input != null) {
|
193
|
-
input.close();
|
194
|
-
input = null;
|
195
|
-
}
|
196
|
-
} catch (Exception e) {
|
197
|
-
|
198
|
-
}
|
199
|
-
|
200
|
-
try {
|
201
|
-
if (output != null) {
|
202
|
-
output.close();
|
203
|
-
output = null;
|
204
|
-
}
|
205
|
-
} catch (Exception e) {
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
try {
|
210
|
-
if (socket != null) {
|
211
|
-
socket.close();
|
212
|
-
socket = null;
|
213
|
-
}
|
214
|
-
} catch (Exception e) {
|
215
|
-
|
216
|
-
}
|
217
|
-
}
|
218
|
-
|
219
|
-
|
220
|
-
@Override
|
221
|
-
public void run() {
|
222
|
-
byte[] readBuffer;
|
223
|
-
{ // make the read buffer same size as socket receive buffer so that
|
224
|
-
// we don't waste cycles calling listeners when there is more data waiting
|
225
|
-
int readBufferSize = 1 << 16; // 64 KB (default socket receive buffer size)
|
226
|
-
try {
|
227
|
-
readBufferSize = socket.getReceiveBufferSize();
|
228
|
-
} catch (SocketException ignore) { }
|
229
|
-
readBuffer = new byte[readBufferSize];
|
230
|
-
}
|
231
|
-
while (Thread.currentThread() == thread) {
|
232
|
-
try {
|
233
|
-
while (input != null) {
|
234
|
-
int readCount;
|
235
|
-
|
236
|
-
// try to read a byte using a blocking read.
|
237
|
-
// An exception will occur when the sketch is exits.
|
238
|
-
try {
|
239
|
-
readCount = input.read(readBuffer, 0, readBuffer.length);
|
240
|
-
} catch (SocketException e) {
|
241
|
-
System.err.println("Client SocketException: " + e.getMessage());
|
242
|
-
// the socket had a problem reading so don't try to read from it again.
|
243
|
-
stop();
|
244
|
-
return;
|
245
|
-
}
|
246
|
-
|
247
|
-
// read returns -1 if end-of-stream occurs (for example if the host disappears)
|
248
|
-
if (readCount == -1) {
|
249
|
-
System.err.println("Client got end-of-stream.");
|
250
|
-
stop();
|
251
|
-
return;
|
252
|
-
}
|
253
|
-
|
254
|
-
synchronized (bufferLock) {
|
255
|
-
int freeBack = buffer.length - bufferLast;
|
256
|
-
if (readCount > freeBack) {
|
257
|
-
// not enough space at the back
|
258
|
-
int bufferLength = bufferLast - bufferIndex;
|
259
|
-
byte[] targetBuffer = buffer;
|
260
|
-
if (bufferLength + readCount > buffer.length) {
|
261
|
-
// can't fit even after compacting, resize the buffer
|
262
|
-
// find the next power of two which can fit everything in
|
263
|
-
int newSize = Integer.highestOneBit(bufferLength + readCount - 1) << 1;
|
264
|
-
if (newSize > MAX_BUFFER_SIZE) {
|
265
|
-
// buffer is full because client is not reading (fast enough)
|
266
|
-
System.err.println("Client: can't receive more data, buffer is full. " +
|
267
|
-
"Make sure you read the data from the client.");
|
268
|
-
stop();
|
269
|
-
return;
|
270
|
-
}
|
271
|
-
targetBuffer = new byte[newSize];
|
272
|
-
}
|
273
|
-
// compact the buffer (either in-place or into the new bigger buffer)
|
274
|
-
System.arraycopy(buffer, bufferIndex, targetBuffer, 0, bufferLength);
|
275
|
-
bufferLast -= bufferIndex;
|
276
|
-
bufferIndex = 0;
|
277
|
-
buffer = targetBuffer;
|
278
|
-
}
|
279
|
-
// copy all newly read bytes into the buffer
|
280
|
-
System.arraycopy(readBuffer, 0, buffer, bufferLast, readCount);
|
281
|
-
bufferLast += readCount;
|
282
|
-
}
|
283
|
-
|
284
|
-
// now post an event
|
285
|
-
if (clientEventMethod != null) {
|
286
|
-
try {
|
287
|
-
clientEventMethod.invoke(parent, this);
|
288
|
-
} catch (Exception e) {
|
289
|
-
System.err.println("error, disabling clientEvent() for " + host);
|
290
|
-
Throwable cause = e;
|
291
|
-
// unwrap the exception if it came from the user code
|
292
|
-
if (e instanceof InvocationTargetException && e.getCause() != null) {
|
293
|
-
cause = e.getCause();
|
294
|
-
}
|
295
|
-
cause.printStackTrace();
|
296
|
-
clientEventMethod = null;
|
297
|
-
}
|
298
|
-
}
|
299
|
-
}
|
300
|
-
} catch (IOException e) {
|
301
|
-
//errorMessage("run", e);
|
302
|
-
|
303
|
-
}
|
304
|
-
}
|
305
|
-
}
|
306
|
-
|
307
|
-
|
308
|
-
/**
|
309
|
-
* ( begin auto-generated from Client_active.xml )
|
310
|
-
*
|
311
|
-
* Returns true if this client is still active and hasn't run
|
312
|
-
* into any trouble.
|
313
|
-
*
|
314
|
-
*
|
315
|
-
* @webref client:client
|
316
|
-
* @brief Returns true if this client is still active
|
317
|
-
* @usage application
|
318
|
-
*/
|
319
|
-
public boolean active() {
|
320
|
-
return (thread != null);
|
321
|
-
}
|
322
|
-
|
323
|
-
|
324
|
-
/**
|
325
|
-
* ( begin auto-generated from Client_ip.xml )
|
326
|
-
*
|
327
|
-
* Returns the IP address of the computer to which the Client is attached.
|
328
|
-
*
|
329
|
-
*
|
330
|
-
* @webref client:client
|
331
|
-
* @usage application
|
332
|
-
* @brief Returns the IP address of the machine as a String
|
333
|
-
*/
|
334
|
-
public String ip() {
|
335
|
-
if (socket != null){
|
336
|
-
return socket.getInetAddress().getHostAddress();
|
337
|
-
}
|
338
|
-
return null;
|
339
|
-
}
|
340
|
-
|
341
|
-
|
342
|
-
/**
|
343
|
-
* ( begin auto-generated from Client_available.xml )
|
344
|
-
*
|
345
|
-
* Returns the number of bytes available. When any client has bytes
|
346
|
-
* available from the server, it returns the number of bytes.
|
347
|
-
*
|
348
|
-
*
|
349
|
-
* @webref client:client
|
350
|
-
* @usage application
|
351
|
-
* @brief Returns the number of bytes in the buffer waiting to be read
|
352
|
-
*/
|
353
|
-
public int available() {
|
354
|
-
synchronized (bufferLock) {
|
355
|
-
return (bufferLast - bufferIndex);
|
356
|
-
}
|
357
|
-
}
|
358
|
-
|
359
|
-
|
360
|
-
/**
|
361
|
-
* ( begin auto-generated from Client_clear.xml )
|
362
|
-
*
|
363
|
-
* Empty the buffer, removes all the data stored there.
|
364
|
-
*
|
365
|
-
*
|
366
|
-
* @webref client:client
|
367
|
-
* @usage application
|
368
|
-
* @brief Clears the buffer
|
369
|
-
*/
|
370
|
-
public void clear() {
|
371
|
-
synchronized (bufferLock) {
|
372
|
-
bufferLast = 0;
|
373
|
-
bufferIndex = 0;
|
374
|
-
}
|
375
|
-
}
|
376
|
-
|
377
|
-
|
378
|
-
/**
|
379
|
-
* ( begin auto-generated from Client_read.xml )
|
380
|
-
*
|
381
|
-
* Returns a number between 0 and 255 for the next byte that's waiting in
|
382
|
-
* the buffer. Returns -1 if there is no byte, although this should be
|
383
|
-
* avoided by first cheacking <b>available()</b> to see if any data is available.
|
384
|
-
*
|
385
|
-
*
|
386
|
-
* @webref client:client
|
387
|
-
* @usage application
|
388
|
-
* @brief Returns a value from the buffer
|
389
|
-
*/
|
390
|
-
public int read() {
|
391
|
-
synchronized (bufferLock) {
|
392
|
-
if (bufferIndex == bufferLast) return -1;
|
393
|
-
|
394
|
-
int outgoing = buffer[bufferIndex++] & 0xff;
|
395
|
-
if (bufferIndex == bufferLast) { // rewind
|
396
|
-
bufferIndex = 0;
|
397
|
-
bufferLast = 0;
|
398
|
-
}
|
399
|
-
return outgoing;
|
400
|
-
}
|
401
|
-
}
|
402
|
-
|
403
|
-
|
404
|
-
/**
|
405
|
-
* ( begin auto-generated from Client_readChar.xml )
|
406
|
-
*
|
407
|
-
* Returns the next byte in the buffer as a char. Returns -1 or 0xffff if
|
408
|
-
* nothing is there.
|
409
|
-
*
|
410
|
-
*
|
411
|
-
* @webref client:client
|
412
|
-
* @usage application
|
413
|
-
* @brief Returns the next byte in the buffer as a char
|
414
|
-
*/
|
415
|
-
public char readChar() {
|
416
|
-
synchronized (bufferLock) {
|
417
|
-
if (bufferIndex == bufferLast) return (char) (-1);
|
418
|
-
return (char) read();
|
419
|
-
}
|
420
|
-
}
|
421
|
-
|
422
|
-
|
423
|
-
/**
|
424
|
-
* ( begin auto-generated from Client_readBytes.xml )
|
425
|
-
*
|
426
|
-
* Reads a group of bytes from the buffer. The version with no parameters
|
427
|
-
* returns a byte array of all data in the buffer. This is not efficient,
|
428
|
-
* but is easy to use. The version with the <b>byteBuffer</b> parameter is
|
429
|
-
* more memory and time efficient. It grabs the data in the buffer and puts
|
430
|
-
* it into the byte array passed in and returns an int value for the number
|
431
|
-
* of bytes read. If more bytes are available than can fit into the
|
432
|
-
* <b>byteBuffer</b>, only those that fit are read.
|
433
|
-
*
|
434
|
-
*
|
435
|
-
* <h3>Advanced</h3>
|
436
|
-
* Return a byte array of anything that's in the serial buffer.
|
437
|
-
* Not particularly memory/speed efficient, because it creates
|
438
|
-
* a byte array on each read, but it's easier to use than
|
439
|
-
* readBytes(byte b[]) (see below).
|
440
|
-
*
|
441
|
-
* @webref client:client
|
442
|
-
* @usage application
|
443
|
-
* @brief Reads everything in the buffer
|
444
|
-
*/
|
445
|
-
public byte[] readBytes() {
|
446
|
-
synchronized (bufferLock) {
|
447
|
-
if (bufferIndex == bufferLast) return null;
|
448
|
-
|
449
|
-
int length = bufferLast - bufferIndex;
|
450
|
-
byte outgoing[] = new byte[length];
|
451
|
-
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
452
|
-
|
453
|
-
bufferIndex = 0; // rewind
|
454
|
-
bufferLast = 0;
|
455
|
-
return outgoing;
|
456
|
-
}
|
457
|
-
}
|
458
|
-
|
459
|
-
|
460
|
-
/**
|
461
|
-
* <h3>Advanced</h3>
|
462
|
-
* Return a byte array of anything that's in the serial buffer
|
463
|
-
* up to the specified maximum number of bytes.
|
464
|
-
* Not particularly memory/speed efficient, because it creates
|
465
|
-
* a byte array on each read, but it's easier to use than
|
466
|
-
* readBytes(byte b[]) (see below).
|
467
|
-
*
|
468
|
-
* @param max the maximum number of bytes to read
|
469
|
-
*/
|
470
|
-
public byte[] readBytes(int max) {
|
471
|
-
synchronized (bufferLock) {
|
472
|
-
if (bufferIndex == bufferLast) return null;
|
473
|
-
|
474
|
-
int length = bufferLast - bufferIndex;
|
475
|
-
if (length > max) length = max;
|
476
|
-
byte outgoing[] = new byte[length];
|
477
|
-
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
478
|
-
|
479
|
-
bufferIndex += length;
|
480
|
-
if (bufferIndex == bufferLast) {
|
481
|
-
bufferIndex = 0; // rewind
|
482
|
-
bufferLast = 0;
|
483
|
-
}
|
484
|
-
|
485
|
-
return outgoing;
|
486
|
-
}
|
487
|
-
}
|
488
|
-
|
489
|
-
|
490
|
-
/**
|
491
|
-
* <h3>Advanced</h3>
|
492
|
-
* Grab whatever is in the serial buffer, and stuff it into a
|
493
|
-
* byte buffer passed in by the user. This is more memory/time
|
494
|
-
* efficient than readBytes() returning a byte[] array.
|
495
|
-
*
|
496
|
-
* Returns an int for how many bytes were read. If more bytes
|
497
|
-
* are available than can fit into the byte array, only those
|
498
|
-
* that will fit are read.
|
499
|
-
*
|
500
|
-
* @param bytebuffer passed in byte array to be altered
|
501
|
-
*/
|
502
|
-
public int readBytes(byte bytebuffer[]) {
|
503
|
-
synchronized (bufferLock) {
|
504
|
-
if (bufferIndex == bufferLast) return 0;
|
505
|
-
|
506
|
-
int length = bufferLast - bufferIndex;
|
507
|
-
if (length > bytebuffer.length) length = bytebuffer.length;
|
508
|
-
System.arraycopy(buffer, bufferIndex, bytebuffer, 0, length);
|
509
|
-
|
510
|
-
bufferIndex += length;
|
511
|
-
if (bufferIndex == bufferLast) {
|
512
|
-
bufferIndex = 0; // rewind
|
513
|
-
bufferLast = 0;
|
514
|
-
}
|
515
|
-
return length;
|
516
|
-
}
|
517
|
-
}
|
518
|
-
|
519
|
-
|
520
|
-
/**
|
521
|
-
* ( begin auto-generated from Client_readBytesUntil.xml )
|
522
|
-
*
|
523
|
-
* Reads from the port into a buffer of bytes up to and including a
|
524
|
-
* particular character. If the character isn't in the buffer, 'null' is
|
525
|
-
* returned. The version with no <b>byteBuffer</b> parameter returns a byte
|
526
|
-
* array of all data up to and including the <b>interesting</b> byte. This
|
527
|
-
* is not efficient, but is easy to use. The version with the
|
528
|
-
* <b>byteBuffer</b> parameter is more memory and time efficient. It grabs
|
529
|
-
* the data in the buffer and puts it into the byte array passed in and
|
530
|
-
* returns an int value for the number of bytes read. If the byte buffer is
|
531
|
-
* not large enough, -1 is returned and an error is printed to the message
|
532
|
-
* area. If nothing is in the buffer, 0 is returned.
|
533
|
-
*
|
534
|
-
*
|
535
|
-
* @webref client:client
|
536
|
-
* @usage application
|
537
|
-
* @brief Reads from the buffer of bytes up to and including a particular character
|
538
|
-
* @param interesting character designated to mark the end of the data
|
539
|
-
*/
|
540
|
-
public byte[] readBytesUntil(int interesting) {
|
541
|
-
byte what = (byte)interesting;
|
542
|
-
|
543
|
-
synchronized (bufferLock) {
|
544
|
-
if (bufferIndex == bufferLast) return null;
|
545
|
-
|
546
|
-
int found = -1;
|
547
|
-
for (int k = bufferIndex; k < bufferLast; k++) {
|
548
|
-
if (buffer[k] == what) {
|
549
|
-
found = k;
|
550
|
-
break;
|
551
|
-
}
|
552
|
-
}
|
553
|
-
if (found == -1) return null;
|
554
|
-
|
555
|
-
int length = found - bufferIndex + 1;
|
556
|
-
byte outgoing[] = new byte[length];
|
557
|
-
System.arraycopy(buffer, bufferIndex, outgoing, 0, length);
|
558
|
-
|
559
|
-
bufferIndex += length;
|
560
|
-
if (bufferIndex == bufferLast) {
|
561
|
-
bufferIndex = 0; // rewind
|
562
|
-
bufferLast = 0;
|
563
|
-
}
|
564
|
-
return outgoing;
|
565
|
-
}
|
566
|
-
}
|
567
|
-
|
568
|
-
|
569
|
-
/**
|
570
|
-
* <h3>Advanced</h3>
|
571
|
-
* Reads from the serial port into a buffer of bytes until a
|
572
|
-
* particular character. If the character isn't in the serial
|
573
|
-
* buffer, then 'null' is returned.
|
574
|
-
*
|
575
|
-
* If outgoing[] is not big enough, then -1 is returned,
|
576
|
-
* and an error message is printed on the console.
|
577
|
-
* If nothing is in the buffer, zero is returned.
|
578
|
-
* If 'interesting' byte is not in the buffer, then 0 is returned.
|
579
|
-
*
|
580
|
-
* @param byteBuffer passed in byte array to be altered
|
581
|
-
*/
|
582
|
-
public int readBytesUntil(int interesting, byte byteBuffer[]) {
|
583
|
-
byte what = (byte)interesting;
|
584
|
-
|
585
|
-
synchronized (bufferLock) {
|
586
|
-
if (bufferIndex == bufferLast) return 0;
|
587
|
-
|
588
|
-
int found = -1;
|
589
|
-
for (int k = bufferIndex; k < bufferLast; k++) {
|
590
|
-
if (buffer[k] == what) {
|
591
|
-
found = k;
|
592
|
-
break;
|
593
|
-
}
|
594
|
-
}
|
595
|
-
if (found == -1) return 0;
|
596
|
-
|
597
|
-
int length = found - bufferIndex + 1;
|
598
|
-
if (length > byteBuffer.length) {
|
599
|
-
System.err.println("readBytesUntil() byte buffer is" +
|
600
|
-
" too small for the " + length +
|
601
|
-
" bytes up to and including char " + interesting);
|
602
|
-
return -1;
|
603
|
-
}
|
604
|
-
//byte outgoing[] = new byte[length];
|
605
|
-
System.arraycopy(buffer, bufferIndex, byteBuffer, 0, length);
|
606
|
-
|
607
|
-
bufferIndex += length;
|
608
|
-
if (bufferIndex == bufferLast) {
|
609
|
-
bufferIndex = 0; // rewind
|
610
|
-
bufferLast = 0;
|
611
|
-
}
|
612
|
-
return length;
|
613
|
-
}
|
614
|
-
}
|
615
|
-
|
616
|
-
|
617
|
-
/**
|
618
|
-
* ( begin auto-generated from Client_readString.xml )
|
619
|
-
*
|
620
|
-
* Returns the all the data from the buffer as a String. This method
|
621
|
-
* assumes the incoming characters are ASCII. If you want to transfer
|
622
|
-
* Unicode data, first convert the String to a byte stream in the
|
623
|
-
* representation of your choice (i.e. UTF8 or two-byte Unicode data), and
|
624
|
-
* send it as a byte array.
|
625
|
-
*
|
626
|
-
*
|
627
|
-
* @webref client:client
|
628
|
-
* @usage application
|
629
|
-
* @brief Returns the buffer as a String
|
630
|
-
*/
|
631
|
-
public String readString() {
|
632
|
-
byte b[] = readBytes();
|
633
|
-
if (b == null) return null;
|
634
|
-
return new String(b);
|
635
|
-
}
|
636
|
-
|
637
|
-
|
638
|
-
/**
|
639
|
-
* ( begin auto-generated from Client_readStringUntil.xml )
|
640
|
-
*
|
641
|
-
* Combination of <b>readBytesUntil()</b> and <b>readString()</b>. Returns
|
642
|
-
* <b>null</b> if it doesn't find what you're looking for.
|
643
|
-
*
|
644
|
-
*
|
645
|
-
* <h3>Advanced</h3>
|
646
|
-
* <p/>
|
647
|
-
* If you want to move Unicode data, you can first convert the
|
648
|
-
* String to a byte stream in the representation of your choice
|
649
|
-
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
650
|
-
*
|
651
|
-
* @webref client:client
|
652
|
-
* @usage application
|
653
|
-
* @brief Returns the buffer as a String up to and including a particular character
|
654
|
-
* @param interesting character designated to mark the end of the data
|
655
|
-
*/
|
656
|
-
public String readStringUntil(int interesting) {
|
657
|
-
byte b[] = readBytesUntil(interesting);
|
658
|
-
if (b == null) return null;
|
659
|
-
return new String(b);
|
660
|
-
}
|
661
|
-
|
662
|
-
|
663
|
-
/**
|
664
|
-
* ( begin auto-generated from Client_write.xml )
|
665
|
-
*
|
666
|
-
* Writes data to a server specified when constructing the client.
|
667
|
-
*
|
668
|
-
*
|
669
|
-
* @webref client:client
|
670
|
-
* @usage application
|
671
|
-
* @brief Writes bytes, chars, ints, bytes[], Strings
|
672
|
-
* @param data data to write
|
673
|
-
*/
|
674
|
-
public void write(int data) { // will also cover char
|
675
|
-
try {
|
676
|
-
output.write(data & 0xff); // for good measure do the &
|
677
|
-
output.flush(); // hmm, not sure if a good idea
|
678
|
-
|
679
|
-
} catch (Exception e) { // null pointer or serial port dead
|
680
|
-
//errorMessage("write", e);
|
681
|
-
//e.printStackTrace();
|
682
|
-
//dispose();
|
683
|
-
//disconnect(e);
|
684
|
-
|
685
|
-
stop();
|
686
|
-
}
|
687
|
-
}
|
688
|
-
|
689
|
-
|
690
|
-
public void write(byte data[]) {
|
691
|
-
try {
|
692
|
-
output.write(data);
|
693
|
-
output.flush(); // hmm, not sure if a good idea
|
694
|
-
|
695
|
-
} catch (Exception e) { // null pointer or serial port dead
|
696
|
-
//errorMessage("write", e);
|
697
|
-
//e.printStackTrace();
|
698
|
-
//disconnect(e);
|
699
|
-
|
700
|
-
stop();
|
701
|
-
}
|
702
|
-
}
|
703
|
-
|
704
|
-
|
705
|
-
/**
|
706
|
-
* <h3>Advanced</h3>
|
707
|
-
* Write a String to the output. Note that this doesn't account
|
708
|
-
* for Unicode (two bytes per char), nor will it send UTF8
|
709
|
-
* characters.. It assumes that you mean to send a byte buffer
|
710
|
-
* (most often the case for networking and serial i/o) and
|
711
|
-
* will only use the bottom 8 bits of each char in the string.
|
712
|
-
* (Meaning that internally it uses String.getBytes)
|
713
|
-
*
|
714
|
-
* If you want to move Unicode data, you can first convert the
|
715
|
-
* String to a byte stream in the representation of your choice
|
716
|
-
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
717
|
-
*/
|
718
|
-
public void write(String data) {
|
719
|
-
write(data.getBytes());
|
720
|
-
}
|
721
|
-
|
722
|
-
|
723
|
-
/**
|
724
|
-
* Handle disconnect due to an Exception being thrown.
|
725
|
-
*/
|
726
|
-
/*
|
727
|
-
protected void disconnect(Exception e) {
|
728
|
-
dispose();
|
729
|
-
if (e != null) {
|
730
|
-
e.printStackTrace();
|
731
|
-
}
|
732
|
-
}
|
733
|
-
*/
|
734
|
-
|
735
|
-
|
736
|
-
/**
|
737
|
-
* General error reporting, all corralled here just in case
|
738
|
-
* I think of something slightly more intelligent to do.
|
739
|
-
*/
|
740
|
-
//public void errorMessage(String where, Exception e) {
|
741
|
-
//parent.die("Error inside Client." + where + "()", e);
|
742
|
-
//e.printStackTrace(System.err);
|
743
|
-
//}
|
744
|
-
}
|