diff --git a/example/app_run.sh b/example/app_run.sh index 4457e55..1a7744b 100755 --- a/example/app_run.sh +++ b/example/app_run.sh @@ -1,42 +1,7 @@ #!/bin/bash -## Copyright (c) 2023. Open Mobile Platform LLC. -## License: Proprietary. -## -## SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC # 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 diff --git a/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec b/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec index 2c965f8..560769d 100644 --- a/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec +++ b/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec @@ -11,6 +11,7 @@ Source0: %{name}-%{version}.tar.zst BuildRequires: cmake BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(flutter-embedder) +BuildRequires: pkgconfig(sensord-qt5) %description %{summary}. diff --git a/example/lib/packages/sensors_plus/package.dart b/example/lib/packages/sensors_plus/package.dart index a4a065f..76c2b77 100644 --- a/example/lib/packages/sensors_plus/package.dart +++ b/example/lib/packages/sensors_plus/package.dart @@ -18,7 +18,7 @@ final packageSensorsPlus = PackagePage( гироскопа и магнитометра. ''', version: '3.0.2', - isPlatformDependent: false, + isPlatformDependent: true, page: () => SensorsPlusPage(), init: () { GetIt.instance.registerFactory(() => SensorsPlusModel()); diff --git a/example/lib/packages/sensors_plus/page.dart b/example/lib/packages/sensors_plus/page.dart index d2ffe96..8a1c6ee 100644 --- a/example/lib/packages/sensors_plus/page.dart +++ b/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/layouts/block_layout.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 'package.dart'; @@ -23,6 +25,24 @@ class SensorsPlusPage extends AppStatefulWidget { } class _SensorsPlusPageState extends AppState { + + @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 Widget buildWide( BuildContext context, diff --git a/example/pubspec.lock b/example/pubspec.lock index ce03bd3..a27313f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -812,6 +812,27 @@ packages: url: "https://pub.dartlang.org" source: hosted 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: dependency: "direct main" description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6312323..372c6d5 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -154,6 +154,12 @@ dependencies: ref: master 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: flutter_test: sdk: diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt b/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt index fce5f12..3b554a9 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt +++ b/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") find_package(PkgConfig REQUIRED) +find_package(Qt5 COMPONENTS Core Network DBus REQUIRED) + 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) +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} 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/${PROJECT_NAME}) + target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL) diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h index a429249..0403b1c 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h @@ -9,15 +9,30 @@ #include #include -class PLUGIN_EXPORT SensorsPlusAuroraPlugin final : public PluginInterface +#include + +#include +#include + +class PLUGIN_EXPORT SensorsPlusAuroraPlugin final + : public QObject + , public PluginInterface { + Q_OBJECT + public: void RegisterWithRegistrar(PluginRegistrar ®istrar) override; +public slots: + void receivedData(const Unsigned &data); + private: void onMethodCall(const MethodCall &call); - void onGetPlatformVersion(const MethodCall &call); + void onListenSensor(const MethodCall &call); void unimplemented(const MethodCall &call); + +private: + AbstractSensorChannelInterface *m_iface = nullptr; }; #endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H */ diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp index 20224e0..89e7d23 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp @@ -5,7 +5,18 @@ #include #include -#include +#include + +#include +#include + +static AbstractSensorChannelInterface *iface; + +namespace { + +constexpr auto METHOD_LISTEN_SENSOR = "listenSensor"; + +} /* namespace */ void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) { @@ -18,26 +29,62 @@ void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) { const auto &method = call.GetMethod(); - if (method == "getPlatformVersion") { - onGetPlatformVersion(call); + if (method == "listenSensor") { + onListenSensor(call); return; } unimplemented(call); } -void SensorsPlusAuroraPlugin::onGetPlatformVersion(const MethodCall &call) +void SensorsPlusAuroraPlugin::onListenSensor(const MethodCall &call) { - utsname uname_data{}; - uname(&uname_data); + if (iface != nullptr) { + unimplemented(call); + return; + } + + SensorManagerInterface &sm = SensorManagerInterface::instance(); + if (!sm.isValid()) { + qDebug() << "Failed to create SensorManagerInterface"; + exit(0); + } + + QDBusReply reply(sm.loadPlugin("orientationsensor")); + if (!reply.isValid() || !reply.value()) { + qDebug() << "Failed to load plugin"; + exit(0); + } - std::string preamble = "Aurora (Linux): "; - std::string version = preamble + uname_data.version; + sm.registerSensorInterface("orientationsensor"); - 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) { call.SendSuccessResponse(nullptr); } + +#include "moc_sensors_plus_aurora_plugin.cpp" diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart index bb338af..4c2003a 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart @@ -2,7 +2,7 @@ import 'sensors_plus_aurora_platform_interface.dart'; class SensorsPlusAurora { - Future getPlatformVersion() { - return SensorsPlusAuroraPlatform.instance.getPlatformVersion(); + Future listenSensor() { + return SensorsPlusAuroraPlatform.instance.listenSensor(); } } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart index 3276f07..dbd3a52 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart +++ b/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'); @override - Future getPlatformVersion() async { - final version = await methodChannel.invokeMethod('getPlatformVersion'); + Future listenSensor() async { + final version = await methodChannel.invokeMethod('listenSensor'); return version; } } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart index b3f71e4..728a052 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart @@ -23,7 +23,7 @@ abstract class SensorsPlusAuroraPlatform extends PlatformInterface { _instance = instance; } - Future getPlatformVersion() { - throw UnimplementedError('platformVersion() has not been implemented.'); + Future listenSensor() { + throw UnimplementedError('listenSensor() has not been implemented.'); } }