Коммит 87b89afc создал по автору Denis Glazkov's avatar Denis Glazkov
Просмотр файлов

[feature] Implement workmanager_aurora plugin.

владелец fd7b8733
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
include:
- project: 'oss/flutter/gitlab-ci-configuration'
file: '/plugins/.plugin-ci-mono-repo.yml'
image:
name: os-registry.omprussia.ru/oss/flutter/docker-flutter:0.3.0-main
# The 3-Clause BSD License
_Copyright (C) 2024. Open Mobile Platform LLC._
Redistribution and use in source and binary forms,
with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain
the above copyright notice, this list of conditions and the following disclaimer.
2. 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.
3. 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.
# workmanager_aurora
The Aurora implementation of the [workmanager](https://pub.dev/packages/workmanager).
## Features
## Getting started
- registerOneOffTask
- registerPeriodicTask
- cancelByUniqueName
- cancelByTag
- cancelAll
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
## Limitations
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
1. Dart entry point for handling tasks should be called `callbackDispatcher`.
2. One-off tasks do not try to restart on error (no backoff support).
3. The constraints are set in the application's desktop file, not through the dart code.
4. Initial delay in periodic tasks is not supported.
5. Periodic tasks are started immediately upon registration.
7. Minimum frequency of periodic tasks is 15 minutes.
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://os-git.omprussia.ru/oss/flutter/flutter-community-plugins/workmanager_aurora.git
git branch -M master
git push -uf origin master
```
## Usage
## Integrate with your tools
This package is not an _endorsed_ implementation of `workmanager`.
Therefore, you have to include `workmanager_aurora` alongside `workmanager` as dependencies in your `pubspec.yaml` file.
- [ ] [Set up project integrations](https://os-git.omprussia.ru/oss/flutter/flutter-community-plugins/workmanager_aurora/-/settings/integrations)
**pubspec.yaml**
## Collaborate with your team
```yaml
dependencies:
workmanager: ^0.5.2
workmanager_aurora:
git:
url: https://gitlab.com/omprussia/flutter/flutter-community-plugins/workmanager_aurora.git
ref: aurora-0.0.1
```
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
**CMakeLists.txt**
## Test and Deploy
```
find_package(Qt5 COMPONENTS Core REQUIRED)
target_link_libraries(${BINARY_NAME} PRIVATE Qt5::Core)
```
Use the built-in continuous integration in GitLab.
***main.cpp**
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
```desktop
#include <flutter/application.h>
#include <flutter/flutter_compatibility_qt.h> // <- Enable Qt
***
#include "generated_plugin_registrant.h"
# Editing this README
int main(int argc, char *argv[]) {
aurora::Initialize(argc, argv);
aurora::EnableQtCompatibility(); // <- Enable Qt
aurora::RegisterPlugins();
aurora::Launch();
return 0;
}
```
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
***.desktop**
## Suggestions for a good README
In Aurora OS, background tasks need to be declared in a desktop file.
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
The mandatory field is `Type`, where you should specify `worker` for one-of tasks and `periodic` for periodic tasks.
## Name
Choose a self-explaining name for your project.
You can also optionally specify the permissions that your background task needs through an enumeration in the `Permissions` field.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
```desktop
[X-Task <ONE_OF_TASK_NAME>]
Type=worker
Permissions=
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
[X-Task <PERIODIC_TASK_NAME>]
Type=periodic
Permissions=Location
```
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
You can also optionally specify the conditions of the background task. For example, if your background task requires the Internet, you can specify the following in the `Conditions` field:
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
```desktop
[X-Task <PERIODIC_TASK_WITH_INTERNET_NAME>]
Type=periodic
Permissions=Internet
Conditions=internet
```
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
***.spec**
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
```spec
BuildRequires: pkgconfig(appdir-cpp)
BuildRequires: pkgconfig(runtime-manager-qt5)
BuildRequires: pkgconfig(nemonotifications-qt5)
```
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
***.dart**
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
```dart
import 'package:workmanager/workmanager.dart';
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
@pragma('vm:entry-point')
void callbackDispatcher() {
Workmanager().executeTask((task, inputData) {
switch (task) {
case "SimpleTask":
print("Background task started: $task");
break;
default:
return Future.value(false);
}
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
return Future.value(true);
});
}
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
void main() {
WidgetsFlutterBinding.ensureInitialized();
## License
For open source projects, say how it is licensed.
Workmanager().initialize(callbackDispatcher, isInDebugMode: true);
Workmanager().registerOneOffTask("unique-task-id", "SimpleTask");
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
runApp(MyApp());
}
```
# SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
# SPDX-License-Identifier: BSD-3-Clause
include: package:flutter_lints/flutter.yaml
# SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
# SPDX-License-Identifier: BSD-3-Clause
# CMAKE_SYSTEM_PROCESSOR - CPU architecture name (armv7l, aarch64, x86_64)
# CMAKE_BUILD_TYPE - Build mode (debug, profile, release)
# PSDK_VERSION - Build psdk exact version
# PSDK_MAJOR - Build psdk major version
cmake_minimum_required(VERSION 3.10)
set(PROJECT_NAME workmanager_aurora)
set(PLUGIN_NAME workmanager_aurora_platform_plugin)
project(${PROJECT_NAME} LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
find_package(PkgConfig REQUIRED)
pkg_check_modules(AppDir REQUIRED IMPORTED_TARGET appdir-cpp)
pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder)
pkg_check_modules(RuntimeManager REQUIRED IMPORTED_TARGET runtime-manager-qt5)
pkg_check_modules(Notifications REQUIRED IMPORTED_TARGET nemonotifications-qt5)
add_library(${PLUGIN_NAME} SHARED
src/workmanager_aurora_plugin.cpp
src/cache.cpp
src/cached_task.cpp
src/debugger.cpp
src/foreground_channel.cpp
src/thumbnails.cpp
src/background_channel.cpp
)
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
target_link_libraries(${PLUGIN_NAME} PRIVATE
PkgConfig::AppDir
PkgConfig::FlutterEmbedder
PkgConfig::RuntimeManager
PkgConfig::Notifications
)
target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL)
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_BACKGROUND_CHANNEL_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_BACKGROUND_CHANNEL_H
#include "cache.h"
#include "types.h"
#include "debugger.h"
class BackgroundChannel
{
public:
explicit BackgroundChannel(PluginRegistrar *registrar);
private:
void on_method_call(const MethodCall &call, UniqueMethodResult result);
void background_channel_initialized(const EncodableValue *args, UniqueMethodResult result);
void unimplemented(const EncodableValue *args, UniqueMethodResult result);
std::unique_ptr<MethodChannel> m_channel;
Cache m_cache;
Debugger m_debugger;
};
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_BACKGROUND_CHANNEL_H */
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_CACHE_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_CACHE_H
#include "cached_task.h"
#include <filesystem>
#include <optional>
#include <vector>
class Cache
{
public:
Cache();
void add_task(const CachedTask &task);
void remove_task(const std::string &unique_name);
std::optional<CachedTask> query_task_with_unique_name(const std::string &unique_name);
std::vector<CachedTask> query_tasks_with_tag(const std::string &tag);
std::vector<CachedTask> query_all_tasks();
private:
std::filesystem::path m_directory_path;
};
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_CACHE_H */
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_CACHED_TASK_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_CACHED_TASK_H
#include <filesystem>
#include <optional>
#include <string>
class CachedTask
{
public:
enum Type {
OneOf = 0,
Periodic,
};
CachedTask(std::string unique_name,
std::string name,
Type type,
std::optional<std::string> tag = std::nullopt);
static std::optional<CachedTask> read_from_file(const std::filesystem::path &path);
void save_to_file(const std::filesystem::path &path) const;
const std::string &unique_name() const;
const std::string &name() const;
Type type() const;
const std::optional<std::string> &tag() const;
private:
std::string m_unique_name;
std::string m_name;
Type m_type;
std::optional<std::string> m_tag;
};
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_CACHED_TASK_H */
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_DEBUGGER_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_DEBUGGER_H
#include <workmanager_aurora/thumbnails.h>
#include <ctime>
#include <string>
class Debugger
{
public:
void notify_about_task_completion(time_t elapsed_time, const std::string &name, bool result);
void notify_about_task_start(time_t started_at,
const std::string &name,
const std::string &input_data);
private:
Thumbnails m_thumbnails;
};
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_DEBUGGER_H */
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_FOREGROUND_CHANNEL_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_FOREGROUND_CHANNEL_H
#include "cache.h"
#include "debugger.h"
#include "types.h"
class ForegroundChannel
{
public:
explicit ForegroundChannel(PluginRegistrar *registrar);
private:
void on_method_call(const MethodCall &call, UniqueMethodResult result);
void initialize(const EncodableValue *args, UniqueMethodResult result);
void register_one_off_task(const EncodableValue *args, UniqueMethodResult result);
void register_periodic_task(const EncodableValue *args, UniqueMethodResult result);
void cancel_task_by_unique_name(const EncodableValue *args, UniqueMethodResult result);
void cancel_task_by_tag(const EncodableValue *args, UniqueMethodResult result);
void cancel_all_tasks(const EncodableValue *args, UniqueMethodResult result);
void unimplemented(const EncodableValue *args, UniqueMethodResult result);
void cancel_cached_tasks(const std::vector<CachedTask> &cached_tasks, UniqueMethodResult result);
std::unique_ptr<MethodChannel> m_channel;
Cache m_cache;
Debugger m_debugger;
};
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_FOREGROUND_CHANNEL_H */
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_GLOBALS_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_GLOBALS_H
#ifdef PLUGIN_IMPL
#define PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define PLUGIN_EXPORT
#endif
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_GLOBALS_H */
Это отличие свёрнуто
Это отличие свёрнуто
Это отличие свёрнуто
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_THUMBNAILS_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_THUMBNAILS_H
#include <filesystem>
enum ThumbnailKind
{
Man = 0,
Party,
Construction,
};
class Thumbnails
{
public:
Thumbnails();
std::filesystem::path generate(ThumbnailKind kind);
private:
std::filesystem::path m_directory_path;
};
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_THUMBNAILS_H */
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_TYPES_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_TYPES_H
#include <flutter/encodable_value.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar.h>
#include <flutter/standard_method_codec.h>
#include <flutter/method_result_functions.h>
using EncodableMap = flutter::EncodableMap;
using EncodableValue = flutter::EncodableValue;
using MethodCall = flutter::MethodCall<EncodableValue>;
using MethodChannel = flutter::MethodChannel<EncodableValue>;
using MethodInvocationResultFuncs = flutter::MethodResultFunctions<>;
using MethodResult = flutter::MethodResult<EncodableValue>;
using Plugin = flutter::Plugin;
using PluginRegistrar = flutter::PluginRegistrar;
using SharedMethodResult = std::shared_ptr<MethodResult>;
using StandardMethodCodec = flutter::StandardMethodCodec;
using UniqueMethodResult = std::unique_ptr<MethodResult>;
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_TYPES_H */
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_H
#define FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_H
#include "background_channel.h"
#include "foreground_channel.h"
#include "globals.h"
#include "types.h"
class PLUGIN_EXPORT WorkmanagerAuroraPlugin final: public Plugin
{
public:
WorkmanagerAuroraPlugin(std::unique_ptr<ForegroundChannel> foreground_channel,
std::unique_ptr<BackgroundChannel> background_channel);
static void RegisterWithRegistrar(PluginRegistrar *registrar);
private:
std::unique_ptr<ForegroundChannel> m_foreground_channel;
std::unique_ptr<BackgroundChannel> m_background_channel;
};
#endif /* FLUTTER_PLUGIN_WORKMANAGER_PLUGIN_H */
/*
* SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <workmanager_aurora/background_channel.h>
#include <flutter/flutter_aurora.h>
#include <flutter/flutter_logger.h>
namespace {
std::optional<std::string> argument_from_entry_point_args(const std::string &key)
{
std::vector<const char *> entry_point_args = aurora::GetDartEntryPointArgs();
for (size_t i = 0; i < entry_point_args.size(); ++i) {
if (i == entry_point_args.size() - 1) {
break;
}
if (std::string_view(entry_point_args[i]) == key) {
return entry_point_args[i + 1];
}
}
return std::nullopt;
}
} /* namespace */
BackgroundChannel::BackgroundChannel(PluginRegistrar *registrar)
: m_channel(std::make_unique<MethodChannel>(
registrar->messenger(),
"be.tramckrijte.workmanager/background_channel_work_manager",
&StandardMethodCodec::GetInstance()))
{
m_channel->SetMethodCallHandler([this](const MethodCall &call, UniqueMethodResult result) {
on_method_call(call, std::move(result));
});
}
void BackgroundChannel::on_method_call(const MethodCall &call, UniqueMethodResult result)
{
if (call.method_name() == "backgroundChannelInitialized") {
background_channel_initialized(call.arguments(), std::move(result));
} else {
unimplemented(call.arguments(), std::move(result));
}
}
void BackgroundChannel::background_channel_initialized(const EncodableValue *,
UniqueMethodResult result)
{
result->Success(true);
auto started_at = std::time(nullptr);
auto unique_name = argument_from_entry_point_args("--wm-unique-name");
if (!unique_name) {
logerr << "couldn't parse unique task name from dart entry point arguments" << std::endl;
aurora::Exit(1);
}
auto cached_task = m_cache.query_task_with_unique_name(*unique_name);
if (!cached_task) {
logerr << "couldn't find cached task with the '" << *unique_name << "' unique name"
<< std::endl;
aurora::Exit(1);
}
auto input_data = argument_from_entry_point_args("--wm-input-data").value_or("{}");
auto debug = argument_from_entry_point_args("--wm-debug-mode").has_value();
auto on_success =
[this, debug, started_at, cached_task = *cached_task](const EncodableValue *reply) {
auto completed_at = std::time(nullptr);
auto elapsed_time_seconds = -1;
if (started_at != (time_t) (-1) && completed_at != (time_t) (-1)) {
elapsed_time_seconds = completed_at - started_at;
}
if (cached_task.type() == CachedTask::Type::OneOf) {
m_cache.remove_task(cached_task.unique_name());
}
if (!std::holds_alternative<bool>(*reply)) {
logerr << "unexpected reply type when calling the onResultSend() workmanager method"
<< std::endl;
aurora::Exit(1);
}
auto result = std::get<bool>(*reply);
auto exit_code = result ? 0 : 1;
if (debug) {
m_debugger.notify_about_task_completion(elapsed_time_seconds,
cached_task.name(),
result);
}
aurora::Exit(exit_code);
};
auto on_error = [](const std::string &code, const std::string &message, const EncodableValue *) {
logerr << "error when calling the onResultSend() workmanager method (" << code << ": "
<< message << ")" << std::endl;
aurora::Exit(1);
};
auto on_unimplemented = []() {
logerr << "the onResultSend() method not implemented in the workmanager" << std::endl;
aurora::Exit(1);
};
/* clang-format off */
m_channel->InvokeMethod(
"onResultSend",
std::make_unique<EncodableValue>(EncodableMap{
{"be.tramckrijte.workmanager.DART_TASK", cached_task->name()},
{"be.tramckrijte.workmanager.INPUT_DATA", input_data},
}),
std::make_unique<MethodInvocationResultFuncs>(
on_success,
on_error,
on_unimplemented
)
);
/* clang-format on */
}
void BackgroundChannel::unimplemented(const EncodableValue *, UniqueMethodResult response)
{
response->NotImplemented();
}
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать