Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QtBluetoothInputStreamThread.java
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4package org.qtproject.qt.android.bluetooth;
5
6import java.io.InputStream;
7import java.io.IOException;
8import android.util.Log;
9
10@SuppressWarnings("WeakerAccess")
11public class QtBluetoothInputStreamThread extends Thread
12{
13 /* Pointer to the Qt object that "owns" the Java object */
14 @SuppressWarnings("CanBeFinal")
15 long qtObject = 0;
16 @SuppressWarnings("CanBeFinal")
17 public boolean logEnabled = false;
18 private static final String TAG = "QtBluetooth";
19 private InputStream m_inputStream = null;
20
21 //error codes
22 public static final int QT_MISSING_INPUT_STREAM = 0;
23 public static final int QT_READ_FAILED = 1;
24 public static final int QT_THREAD_INTERRUPTED = 2;
25
27 {
28 setName("QtBtInputStreamThread");
29 }
30
31 public void setInputStream(InputStream stream)
32 {
33 m_inputStream = stream;
34 }
35
36 public void run()
37 {
38 if (m_inputStream == null) {
39 errorOccurred(qtObject, QT_MISSING_INPUT_STREAM);
40 return;
41 }
42
43 byte[] buffer = new byte[1000];
44 int bytesRead;
45
46 try {
47 while (!isInterrupted()) {
48 //this blocks until we see incoming data
49 //or close() on related BluetoothSocket is called
50 bytesRead = m_inputStream.read(buffer);
51 readyData(qtObject, buffer, bytesRead);
52 }
53
54 errorOccurred(qtObject, QT_THREAD_INTERRUPTED);
55 } catch (IOException ex) {
56 if (logEnabled)
57 Log.d(TAG, "InputStream.read() failed:" + ex.toString());
58 ex.printStackTrace();
59 errorOccurred(qtObject, QT_READ_FAILED);
60 }
61
62 if (logEnabled)
63 Log.d(TAG, "Leaving input stream thread");
64 }
65
66 public static native void errorOccurred(long qtObject, int errorCode);
67 public static native void readyData(long qtObject, byte[] buffer, int bufferLength);
68}
static native void readyData(long qtObject, byte[] buffer, int bufferLength)
static native void errorOccurred(long qtObject, int errorCode)
employee setName("Richard Schmit")
EGLStreamKHR stream
#define TAG(x)
GLenum GLuint buffer