Browse Source

[sensors-plus] Add Qt to plugin. OMP#OS-17084

merge-requests/27/head
Vitaliy Zarubin 2 years ago
parent
commit
3a0c1b01d8
  1. 37
      example/app_run.sh
  2. 1
      example/aurora/rpm/ru.auroraos.flutter_example_packages.spec
  3. 2
      example/lib/packages/sensors_plus/package.dart
  4. 20
      example/lib/packages/sensors_plus/page.dart
  5. 21
      example/pubspec.lock
  6. 6
      example/pubspec.yaml
  7. 10
      packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt
  8. 19
      packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h
  9. 65
      packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp
  10. 4
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart
  11. 4
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart
  12. 4
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart

37
example/app_run.sh

@ -1,42 +1,7 @@
#!/bin/bash #!/bin/bash
## Copyright (c) 2023. Open Mobile Platform LLC. # SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
## License: Proprietary.
##
## SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru>
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
## Contact: https://community.omprussia.ru/open-source
##
## This file is part of the Aurora OS Application Template project.
##
## Redistribution and use in source and binary forms,
## with or without modification, are permitted provided
## that the following conditions are met:
##
## * Redistributions of source code must retain the above copyright notice,
## this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright notice,
## this list of conditions and the following disclaimer
## in the documentation and/or other materials provided with the distribution.
## * Neither the name of the copyright holder nor the names of its contributors
## may be used to endorse or promote products derived from this software
## without specific prior written permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
## FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
## IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
## OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
## LOSS OF USE, DATA, OR PROFITS;
## OR BUSINESS INTERRUPTION)
## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE)
## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## Build example, sign rpm, upload/install/run rpm to device ## Build example, sign rpm, upload/install/run rpm to device

1
example/aurora/rpm/ru.auroraos.flutter_example_packages.spec

@ -11,6 +11,7 @@ Source0: %{name}-%{version}.tar.zst
BuildRequires: cmake BuildRequires: cmake
BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(flutter-embedder) BuildRequires: pkgconfig(flutter-embedder)
BuildRequires: pkgconfig(sensord-qt5)
%description %description
%{summary}. %{summary}.

2
example/lib/packages/sensors_plus/package.dart

@ -18,7 +18,7 @@ final packageSensorsPlus = PackagePage(
гироскопа и магнитометра. гироскопа и магнитометра.
''', ''',
version: '3.0.2', version: '3.0.2',
isPlatformDependent: false, isPlatformDependent: true,
page: () => SensorsPlusPage(), page: () => SensorsPlusPage(),
init: () { init: () {
GetIt.instance.registerFactory<SensorsPlusModel>(() => SensorsPlusModel()); GetIt.instance.registerFactory<SensorsPlusModel>(() => SensorsPlusModel());

20
example/lib/packages/sensors_plus/page.dart

@ -7,6 +7,8 @@ import 'package:flutter_example_packages/widgets/base/export.dart';
import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart'; import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart';
import 'package:flutter_example_packages/widgets/layouts/block_layout.dart'; import 'package:flutter_example_packages/widgets/layouts/block_layout.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:sensors_plus/sensors_plus.dart';
import 'package:sensors_plus_aurora/sensors_plus_aurora.dart';
import 'model.dart'; import 'model.dart';
import 'package.dart'; import 'package.dart';
@ -23,6 +25,24 @@ class SensorsPlusPage extends AppStatefulWidget {
} }
class _SensorsPlusPageState extends AppState<SensorsPlusPage> { class _SensorsPlusPageState extends AppState<SensorsPlusPage> {
@override
void initState() {
super.initState();
/// Listen change
// accelerometerEvents.listen((AccelerometerEvent event) {
// debugPrint(event.toString());
// },
// onError: (error) {
// debugPrint(error.toString());
// },
// cancelOnError: true,
// );
SensorsPlusAurora().listenSensor().then((value) => debugPrint('yes'));
}
@override @override
Widget buildWide( Widget buildWide(
BuildContext context, BuildContext context,

21
example/pubspec.lock

@ -812,6 +812,27 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.0.0"
sensors_plus:
dependency: "direct main"
description:
name: sensors_plus
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.3"
sensors_plus_aurora:
dependency: "direct main"
description:
path: "../packages/sensors_plus/sensors_plus_aurora"
relative: true
source: path
version: "0.0.1"
sensors_plus_platform_interface:
dependency: transitive
description:
name: sensors_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
shared_preferences: shared_preferences:
dependency: "direct main" dependency: "direct main"
description: description:

6
example/pubspec.yaml

@ -154,6 +154,12 @@ dependencies:
ref: master ref: master
path: packages/sqflite/sqflite_aurora path: packages/sqflite/sqflite_aurora
## https://pub.dev/packages/sensors_plus
sensors_plus: ^3.0.3
## https://os-git.omprussia.ru/non-oss/flutter/flutter-plugins/-/tree/master/packages/sensors_plus/sensors_plus_aurora
sensors_plus_aurora:
path: ../packages/sensors_plus/sensors_plus_aurora
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: sdk:

10
packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt

@ -15,12 +15,20 @@ set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi")
set(CMAKE_CXX_FLAGS_RELEASE "-O3") set(CMAKE_CXX_FLAGS_RELEASE "-O3")
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
find_package(Qt5 COMPONENTS Core Network DBus REQUIRED)
pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder)
pkg_check_modules(SensordQt5 REQUIRED IMPORTED_TARGET sensord-qt5)
add_library(${PLUGIN_NAME} SHARED sensors_plus_aurora_plugin.cpp) add_library(${PLUGIN_NAME} SHARED sensors_plus_aurora_plugin.cpp)
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden AUTOMOC ON)
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder)
target_link_libraries(${PLUGIN_NAME} PUBLIC Qt5::Core Qt5::Network Qt5::DBus)
target_link_libraries(${PLUGIN_NAME} PUBLIC PkgConfig::SensordQt5)
target_include_directories(${PLUGIN_NAME} PRIVATE ${FLUTTER_DIR})
target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME})
target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL) target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL)

19
packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h

@ -9,15 +9,30 @@
#include <flutter/plugin-interface.h> #include <flutter/plugin-interface.h>
#include <sensors_plus_aurora/globals.h> #include <sensors_plus_aurora/globals.h>
class PLUGIN_EXPORT SensorsPlusAuroraPlugin final : public PluginInterface #include <QtCore>
#include <datatypes/unsigned.h>
#include <abstractsensor_i.h>
class PLUGIN_EXPORT SensorsPlusAuroraPlugin final
: public QObject
, public PluginInterface
{ {
Q_OBJECT
public: public:
void RegisterWithRegistrar(PluginRegistrar &registrar) override; void RegisterWithRegistrar(PluginRegistrar &registrar) override;
public slots:
void receivedData(const Unsigned &data);
private: private:
void onMethodCall(const MethodCall &call); void onMethodCall(const MethodCall &call);
void onGetPlatformVersion(const MethodCall &call); void onListenSensor(const MethodCall &call);
void unimplemented(const MethodCall &call); void unimplemented(const MethodCall &call);
private:
AbstractSensorChannelInterface *m_iface = nullptr;
}; };
#endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H */ #endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H */

65
packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp

@ -5,7 +5,18 @@
#include <sensors_plus_aurora/sensors_plus_aurora_plugin.h> #include <sensors_plus_aurora/sensors_plus_aurora_plugin.h>
#include <flutter/method-channel.h> #include <flutter/method-channel.h>
#include <sys/utsname.h> #include <QDebug>
#include <sensormanagerinterface.h>
#include <orientationsensor_i.h>
static AbstractSensorChannelInterface *iface;
namespace {
constexpr auto METHOD_LISTEN_SENSOR = "listenSensor";
} /* namespace */
void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar &registrar) void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{ {
@ -18,26 +29,62 @@ void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call)
{ {
const auto &method = call.GetMethod(); const auto &method = call.GetMethod();
if (method == "getPlatformVersion") { if (method == "listenSensor") {
onGetPlatformVersion(call); onListenSensor(call);
return; return;
} }
unimplemented(call); unimplemented(call);
} }
void SensorsPlusAuroraPlugin::onGetPlatformVersion(const MethodCall &call) void SensorsPlusAuroraPlugin::onListenSensor(const MethodCall &call)
{ {
utsname uname_data{}; if (iface != nullptr) {
uname(&uname_data); unimplemented(call);
return;
}
SensorManagerInterface &sm = SensorManagerInterface::instance();
if (!sm.isValid()) {
qDebug() << "Failed to create SensorManagerInterface";
exit(0);
}
QDBusReply<bool> reply(sm.loadPlugin("orientationsensor"));
if (!reply.isValid() || !reply.value()) {
qDebug() << "Failed to load plugin";
exit(0);
}
std::string preamble = "Aurora (Linux): "; sm.registerSensorInterface<OrientationSensorChannelInterface>("orientationsensor");
std::string version = preamble + uname_data.version;
call.SendSuccessResponse(version); iface = OrientationSensorChannelInterface::interface("orientationsensor");
qDebug() << "iface -> " << iface->thread();
if (!iface) {
qDebug() << "Cannot get OrientationSensorChannelInterface";
exit(0);
}
connect(iface, SIGNAL(orientationChanged(const Unsigned&)),
this, SLOT(receivedData(const Unsigned&)));
qDebug() << "Created sensor: " << iface->description();
iface->start();
qDebug() << "Received data start";
unimplemented(call);
}
void SensorsPlusAuroraPlugin::receivedData(const Unsigned &data)
{
qDebug() << "receivedData: " << data.x();
} }
void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call)
{ {
call.SendSuccessResponse(nullptr); call.SendSuccessResponse(nullptr);
} }
#include "moc_sensors_plus_aurora_plugin.cpp"

4
packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart

@ -2,7 +2,7 @@
import 'sensors_plus_aurora_platform_interface.dart'; import 'sensors_plus_aurora_platform_interface.dart';
class SensorsPlusAurora { class SensorsPlusAurora {
Future<String?> getPlatformVersion() { Future<String?> listenSensor() {
return SensorsPlusAuroraPlatform.instance.getPlatformVersion(); return SensorsPlusAuroraPlatform.instance.listenSensor();
} }
} }

4
packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart

@ -10,8 +10,8 @@ class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform {
final methodChannel = const MethodChannel('sensors_plus_aurora'); final methodChannel = const MethodChannel('sensors_plus_aurora');
@override @override
Future<String?> getPlatformVersion() async { Future<String?> listenSensor() async {
final version = await methodChannel.invokeMethod<String>('getPlatformVersion'); final version = await methodChannel.invokeMethod<String>('listenSensor');
return version; return version;
} }
} }

4
packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart

@ -23,7 +23,7 @@ abstract class SensorsPlusAuroraPlatform extends PlatformInterface {
_instance = instance; _instance = instance;
} }
Future<String?> getPlatformVersion() { Future<String?> listenSensor() {
throw UnimplementedError('platformVersion() has not been implemented.'); throw UnimplementedError('listenSensor() has not been implemented.');
} }
} }

Loading…
Cancel
Save