Commit bc5e8b9f authored by Vyacheslav Koscheev's avatar Vyacheslav Koscheev

switch from JniObjectLinker to TJniObjectLinker

parent 82920949
......@@ -40,6 +40,7 @@
#include <QAndroidQPAPluginGap.h>
#include <QtCore/QSharedPointer>
#include <QtCore/QMutexLocker>
#include "TJniObjectLinker.h"
......@@ -74,8 +75,11 @@ static const JNINativeMethod methods[] = {
};
JNI_LINKER_IMPL(QAndroidCompass, "ru/dublgis/androidcompass/CompassProvider", methods)
QAndroidCompass::QAndroidCompass()
: JniObjectLinker(reinterpret_cast<void*>(this), "ru/dublgis/androidcompass/CompassProvider", methods, sizeof(methods))
: jniLinker_(new JniObjectLinker(this))
{
}
......@@ -88,22 +92,18 @@ QAndroidCompass::~QAndroidCompass()
void QAndroidCompass::start(int32_t delayUs /*= -1*/, int32_t latencyUs /*= -1*/)
{
QJniObject * hdl = handler();
if (Q_NULLPTR != hdl)
if (isJniReady())
{
hdl->callParamVoid("start", "II", static_cast<jint>(delayUs), static_cast<jint>(latencyUs));
jni()->callParamVoid("start", "II", static_cast<jint>(delayUs), static_cast<jint>(latencyUs));
}
}
void QAndroidCompass::stop()
{
QJniObject * hdl = handler();
if (Q_NULLPTR != hdl)
if (isJniReady())
{
hdl->callVoid("stop");
jni()->callVoid("stop");
}
}
......
......@@ -40,11 +40,13 @@
#include <QtCore/QScopedPointer>
#include <QtCore/QWeakPointer>
#include <QtCore/QMutex>
#include "JniObjectLinker.h"
#include "IJniObjectLinker.h"
class QAndroidCompass : public JniObjectLinker
class QAndroidCompass
{
JNI_LINKER_DECL(QAndroidCompass)
public:
class AzimuthListener
{
......@@ -65,7 +67,6 @@ private:
void setAzimuth(float azimuth);
private:
QScopedPointer<QJniObject> handler_;
QWeakPointer<AzimuthListener> azimuth_listener_;
QMutex send_mutex_;
......
......@@ -36,6 +36,7 @@
#include "QAndroidBatteryDataProvider.h"
#include <QAndroidQPAPluginGap.h>
#include "TJniObjectLinker.h"
namespace Mobility {
......@@ -64,11 +65,12 @@ static const JNINativeMethod methods[] = {
};
JNI_LINKER_IMPL(QAndroidBatteryDataProvider, "ru/dublgis/androidhelpers/mobility/BatteryListener", methods)
QAndroidBatteryDataProvider::QAndroidBatteryDataProvider(QObject * parent)
: QObject(parent)
, JniObjectLinker(reinterpret_cast<void*>(this), "ru/dublgis/androidhelpers/mobility/BatteryListener", methods, sizeof(methods))
, jniLinker_(new JniObjectLinker(this))
{
}
......@@ -80,20 +82,18 @@ QAndroidBatteryDataProvider::~QAndroidBatteryDataProvider()
void QAndroidBatteryDataProvider::start()
{
QJniObject * hdl = handler();
if (Q_NULLPTR != hdl)
if (isJniReady())
{
hdl->callBool("start");
jni()->callBool("start");
}
}
void QAndroidBatteryDataProvider::stop()
{
QJniObject * hdl = handler();
if (Q_NULLPTR != hdl)
if (isJniReady())
{
hdl->callVoid("stop");
jni()->callVoid("stop");
}
}
......
......@@ -38,13 +38,14 @@
#include <QtCore/QObject>
#include <QJniHelpers.h>
#include "JniObjectLinker.h"
#include "IJniObjectLinker.h"
namespace Mobility {
class QAndroidBatteryDataProvider : public QObject, public JniObjectLinker
class QAndroidBatteryDataProvider : public QObject
{
Q_OBJECT
JNI_LINKER_DECL(QAndroidBatteryDataProvider)
public:
QAndroidBatteryDataProvider(QObject * parent = 0);
......
......@@ -38,6 +38,7 @@
#include "QAndroidCellDataProvider.h"
#include <QAndroidQPAPluginGap.h>
#include "TJniObjectLinker.h"
namespace Mobility {
......@@ -67,11 +68,12 @@ static const JNINativeMethod methods[] = {
};
JNI_LINKER_IMPL(QAndroidCellDataProvider, "ru/dublgis/androidhelpers/mobility/CellListener", methods)
QAndroidCellDataProvider::QAndroidCellDataProvider(QObject * parent /*= 0*/) :
QObject(parent)
, JniObjectLinker(reinterpret_cast<void*>(this), "ru/dublgis/androidhelpers/mobility/CellListener", methods, sizeof(methods))
QAndroidCellDataProvider::QAndroidCellDataProvider(QObject * parent /*= 0*/)
: QObject(parent)
, jniLinker_(new JniObjectLinker(this))
{
}
......@@ -83,13 +85,19 @@ QAndroidCellDataProvider::~QAndroidCellDataProvider()
void QAndroidCellDataProvider::start()
{
handler()->callBool("start");
if (isJniReady())
{
jni()->callBool("start");
}
}
void QAndroidCellDataProvider::stop()
{
handler()->callVoid("stop");
if (isJniReady())
{
jni()->callVoid("stop");
}
}
......
......@@ -40,15 +40,16 @@
#include <QtCore/QObject>
#include <QJniHelpers.h>
#include "JniObjectLinker.h"
#include "IJniObjectLinker.h"
#include "CellData.h"
namespace Mobility {
class QAndroidCellDataProvider : public QObject, public JniObjectLinker
class QAndroidCellDataProvider : public QObject
{
Q_OBJECT
JNI_LINKER_DECL(QAndroidCellDataProvider)
public:
QAndroidCellDataProvider(QObject * parent = 0);
......
......@@ -38,6 +38,7 @@
#include "QAndroidWifiDataProvider.h"
#include <QAndroidQPAPluginGap.h>
#include "TJniObjectLinker.h"
namespace Mobility {
......@@ -68,9 +69,12 @@ static const JNINativeMethod methods[] = {
};
QAndroidWifiDataProvider::QAndroidWifiDataProvider(QObject * parent /*= 0*/) :
QObject(parent)
, JniObjectLinker(reinterpret_cast<void*>(this), "ru/dublgis/androidhelpers/mobility/WifiListener", methods, sizeof(methods))
JNI_LINKER_IMPL(QAndroidWifiDataProvider, "ru/dublgis/androidhelpers/mobility/WifiListener", methods)
QAndroidWifiDataProvider::QAndroidWifiDataProvider(QObject * parent /*= 0*/)
: QObject(parent)
, jniLinker_(new JniObjectLinker(this))
, started_(false)
{
}
......@@ -88,13 +92,20 @@ void QAndroidWifiDataProvider::start()
return;
}
started_ = handler()->callBool("start");
if (isJniReady())
{
started_ = jni()->callBool("start");
}
}
void QAndroidWifiDataProvider::stop()
{
handler()->callVoid("stop");
if (isJniReady())
{
jni()->callVoid("stop");
}
started_ = false;
}
......@@ -107,7 +118,12 @@ void QAndroidWifiDataProvider::scanUpdate()
QString QAndroidWifiDataProvider::getSignalsData()
{
return handler()->callString("getLastWifiScanResultsTable");
if (isJniReady())
{
return jni()->callString("getLastWifiScanResultsTable");
}
return QString::null;
}
......
......@@ -40,15 +40,16 @@
#include <QtCore/QObject>
#include <QJniHelpers.h>
#include "JniObjectLinker.h"
#include "IJniObjectLinker.h"
#include "WifiData.h"
namespace Mobility {
class QAndroidWifiDataProvider : public QObject, public JniObjectLinker
class QAndroidWifiDataProvider : public QObject
{
Q_OBJECT
JNI_LINKER_DECL(QAndroidWifiDataProvider)
public:
QAndroidWifiDataProvider(QObject * parent = 0);
......
......@@ -37,6 +37,9 @@
#include "QAndroidAction.h"
#include <QAndroidQPAPluginGap.h>
#include "TJniObjectLinker.h"
static const JNINativeMethod methods[] = {
......@@ -44,9 +47,12 @@ static const JNINativeMethod methods[] = {
};
QAndroidAction::QAndroidAction(QObject * parent) :
QObject(parent)
, JniObjectLinker(reinterpret_cast<void*>(this), "ru/dublgis/androidhelpers/Action", methods, sizeof(methods))
JNI_LINKER_IMPL(QAndroidAction, "ru/dublgis/androidhelpers/Action", methods)
QAndroidAction::QAndroidAction(QObject * parent)
: QObject(parent)
, jniLinker_(new JniObjectLinker(this))
{}
......@@ -56,9 +62,8 @@ QAndroidAction::~QAndroidAction()
void QAndroidAction::openLocationSourceSettings()
{
QJniObject * h = handler();
if (h)
if (isJniReady())
{
h->callVoid("openLocationSourceSettings");
jni()->callVoid("openLocationSourceSettings");
}
}
......@@ -38,12 +38,13 @@
#include <QtCore/QObject>
#include <QJniHelpers.h>
#include "JniObjectLinker.h"
#include "IJniObjectLinker.h"
class QAndroidAction : public QObject, public JniObjectLinker
class QAndroidAction : public QObject
{
Q_OBJECT
JNI_LINKER_DECL(QAndroidAction)
public:
QAndroidAction(QObject * parent = 0);
......
......@@ -37,6 +37,7 @@
#include <QAndroidQPAPluginGap.h>
#include <QJniHelpers.h>
#include "QNmeaListener.h"
#include "TJniObjectLinker.h"
static const char c_full_class_name[] = "ru/dublgis/androidgpslocation/NmeaListener";
......@@ -69,20 +70,33 @@ Q_DECL_EXPORT void JNICALL Java_NmeaListener_OnNmeaReceivedNative(JNIEnv * env,
}
}
static const JNINativeMethod methods[] = {
{"getActivity", "()Landroid/app/Activity;", (void*)QAndroidQPAPluginGap::getActivity},
{"getContext", "()Landroid/content/Context;", (void*)QAndroidQPAPluginGap::getCurrentContext},
{"OnNmeaReceivedNative", "(JJLjava/lang/String;)V", (void*)Java_NmeaListener_OnNmeaReceivedNative},
};
JNI_LINKER_IMPL(QNmeaListener, c_full_class_name, methods)
QNmeaListener::QNmeaListener(QObject * parent)
: QObject(parent)
, JniObjectLinker(reinterpret_cast<void*>(this), c_full_class_name, methods, sizeof(methods))
, jniLinker_(new JniObjectLinker(this))
{
handler()->callVoid("StartListening");
if (isJniReady())
{
jni()->callVoid("StartListening");
}
}
QNmeaListener::~QNmeaListener()
{
handler()->callVoid("StopListening");
if (isJniReady())
{
jni()->callVoid("StopListening");
}
}
......@@ -36,14 +36,15 @@
#pragma once
#include <QtCore/QObject>
#include "JniObjectLinker.h"
#include "IJniObjectLinker.h"
/*!
* Class for receiving NMEA sentences from the GPS.
*/
class QNmeaListener : public QObject, public JniObjectLinker
class QNmeaListener : public QObject
{
Q_OBJECT
JNI_LINKER_DECL(QNmeaListener)
public:
QNmeaListener(QObject * parent);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment