Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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")
11class 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 boolean logEnabled = false;
18 private static final String TAG = "QtBluetooth";
19 private InputStream m_inputStream = null;
20
21 //error codes
22 static final int QT_MISSING_INPUT_STREAM = 0;
23 static final int QT_READ_FAILED = 1;
24 static final int QT_THREAD_INTERRUPTED = 2;
25
26 QtBluetoothInputStreamThread()
27 {
28 setName("QtBtInputStreamThread");
29 }
30
31 void setInputStream(InputStream stream)
32 {
33 m_inputStream = stream;
34 }
35
36 @Override
37 public void run()
38 {
39 if (m_inputStream == null) {
40 errorOccurred(qtObject, QT_MISSING_INPUT_STREAM);
41 return;
42 }
43
44 byte[] buffer = new byte[1000];
45 int bytesRead;
46
47 try {
48 while (!isInterrupted()) {
49 //this blocks until we see incoming data
50 //or close() on related BluetoothSocket is called
51 bytesRead = m_inputStream.read(buffer);
52 readyData(qtObject, buffer, bytesRead);
53 }
54
55 errorOccurred(qtObject, QT_THREAD_INTERRUPTED);
56 } catch (IOException ex) {
57 if (logEnabled)
58 Log.d(TAG, "InputStream.read() failed:" + ex.toString());
59 ex.printStackTrace();
60 errorOccurred(qtObject, QT_READ_FAILED);
61 }
62
63 if (logEnabled)
64 Log.d(TAG, "Leaving input stream thread");
65 }
66
67 static native void errorOccurred(long qtObject, int errorCode);
68 static native void readyData(long qtObject, byte[] buffer, int bufferLength);
69}
QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, Function &&f, Args &&...args)
EGLStreamKHR stream
#define TAG(x)
EGLContext EGLenum EGLClientBuffer buffer