Skip to content

Commit 72a34fc

Browse files
committed
Add CaptureStream class with close and isOpen methods
1 parent 85394ee commit 72a34fc

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.github.doblon8.openpnp.capture;
2+
3+
import static io.github.doblon8.openpnp.capture.bindings.openpnp_capture.Cap_closeStream;
4+
import static io.github.doblon8.openpnp.capture.bindings.openpnp_capture.Cap_isOpenStream;
5+
6+
public class CaptureStream {
7+
private final CaptureContext context;
8+
private final int id;
9+
10+
public CaptureStream(CaptureContext context, int id) {
11+
this.context = context;
12+
this.id = id;
13+
}
14+
15+
/**
16+
* Check if a stream is open, i.e. is capturing data.
17+
*
18+
* @return true if the stream is open, false otherwise.
19+
*/
20+
public boolean isOpen() {
21+
var result = Cap_isOpenStream(context.getSegment(), id);
22+
return result == 1;
23+
}
24+
25+
/**
26+
* Close a capture stream.
27+
*
28+
* @throws CaptureException if an error occurs while closing the capture stream.
29+
*/
30+
public void close() {
31+
int result = Cap_closeStream(context.getSegment(), id);
32+
CaptureResult captureResult = CaptureResult.values()[result];
33+
if (captureResult != CaptureResult.OK) {
34+
throw new CaptureException("Error closing capture stream: " + result);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)