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
inputstreamthread.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Lauri Laanmets (Proekspert AS) <lauri.laanmets@eesti.ee>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <QtCore/QLoggingCategory>
6#include <QtCore/QJniEnvironment>
7
11
13
14Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
15
20
22{
23 QMutexLocker lock(&m_mutex);
24
25 javaInputStreamThread = QJniObject::construct<QtJniTypes::QtBtInputStreamThread>();
26 if (!javaInputStreamThread.isValid() || !m_socket_p->inputStream.isValid())
27 return false;
28
29 javaInputStreamThread.callMethod<void>("setInputStream",
30 m_socket_p->inputStream.object<QtJniTypes::InputStream>());
31 javaInputStreamThread.setField<jlong>("qtObject", reinterpret_cast<long>(this));
32 javaInputStreamThread.setField<jboolean>("logEnabled", QT_BT_ANDROID().isDebugEnabled());
33
34 javaInputStreamThread.callMethod<void>("start");
35
36 return true;
37}
38
40{
41 QMutexLocker locker(&m_mutex);
42 return m_socket_p->rxBuffer.size();
43}
44
46{
47 QMutexLocker locker(&m_mutex);
48 return m_socket_p->rxBuffer.canReadLine();
49}
50
52{
53 QMutexLocker locker(&m_mutex);
54
55 if (!m_socket_p->rxBuffer.isEmpty())
56 return m_socket_p->rxBuffer.read(data, maxSize);
57
58 return 0;
59}
60
61//inside the java thread
63{
64 QMutexLocker lock(&m_mutex);
65
66 if (!expectClosure)
67 emit errorOccurred(errorCode);
68 else
69 emit errorOccurred(-1); // magic error, -1 means error was expected due to expected close()
70}
71
72//inside the java thread
73void InputStreamThread::javaReadyRead(jbyteArray buffer, int bufferLength)
74{
76
77 QMutexLocker lock(&m_mutex);
78 char *writePtr = m_socket_p->rxBuffer.reserve(bufferLength);
79 env->GetByteArrayRegion(buffer, 0, bufferLength, reinterpret_cast<jbyte*>(writePtr));
81}
82
84{
85 QMutexLocker lock(&m_mutex);
86 expectClosure = true;
87}
88
void errorOccurred(int errorCode)
void javaThreadErrorOccurred(int errorCode)
qint64 bytesAvailable() const
qint64 readData(char *data, qint64 maxSize)
void javaReadyRead(jbyteArray buffer, int bufferLength)
\inmodule QtCore
\inmodule QtCore
Definition qmutex.h:313
\inmodule QtCore
Definition qobject.h:103
qsizetype read(char *target, qsizetype size)
char * reserve(qsizetype size)
Combined button and popup list for selecting options.
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint buffer
#define emit
long long qint64
Definition qtypes.h:60
QTcpSocket * socket
[1]
QReadWriteLock lock
[0]