From c0e5446cb4eae1e0998b222fec8c4b48d677a964 Mon Sep 17 00:00:00 2001 From: jennerl Date: Thu, 8 Apr 2021 11:29:57 -0500 Subject: [PATCH] moved QT-interfacing code from AirMap's platform-sdk lib into QGC --- QGCExternalLibs.pri | 4 +- qgroundcontrol.pro | 35 +++++++- src/Airmap/AirMapManager.h | 4 +- src/Airmap/AirMapSharedState.h | 2 +- src/Airmap/qt/advisory.cpp | 48 +++++++++++ src/Airmap/qt/advisory.h | 41 +++++++++ src/Airmap/qt/aircrafts.cpp | 48 +++++++++++ src/Airmap/qt/aircrafts.h | 44 ++++++++++ src/Airmap/qt/airspaces.cpp | 39 +++++++++ src/Airmap/qt/airspaces.h | 43 ++++++++++ src/Airmap/qt/authenticator.cpp | 50 +++++++++++ src/Airmap/qt/authenticator.h | 49 +++++++++++ src/Airmap/qt/client.cpp | 178 ++++++++++++++++++++++++++++++++++++++++ src/Airmap/qt/client.h | 77 +++++++++++++++++ src/Airmap/qt/dispatcher.cpp | 86 +++++++++++++++++++ src/Airmap/qt/dispatcher.h | 75 +++++++++++++++++ src/Airmap/qt/flight_plans.cpp | 72 ++++++++++++++++ src/Airmap/qt/flight_plans.h | 48 +++++++++++ src/Airmap/qt/flights.cpp | 100 ++++++++++++++++++++++ src/Airmap/qt/flights.h | 52 ++++++++++++ src/Airmap/qt/logger.cpp | 90 ++++++++++++++++++++ src/Airmap/qt/logger.h | 69 ++++++++++++++++ src/Airmap/qt/pilots.cpp | 98 ++++++++++++++++++++++ src/Airmap/qt/pilots.h | 53 ++++++++++++ src/Airmap/qt/rulesets.cpp | 65 +++++++++++++++ src/Airmap/qt/rulesets.h | 43 ++++++++++ src/Airmap/qt/status.cpp | 46 +++++++++++ src/Airmap/qt/status.h | 44 ++++++++++ src/Airmap/qt/telemetry.cpp | 32 ++++++++ src/Airmap/qt/telemetry.h | 43 ++++++++++ src/Airmap/qt/traffic.cpp | 64 +++++++++++++++ src/Airmap/qt/traffic.h | 66 +++++++++++++++ src/Airmap/qt/types.cpp | 91 ++++++++++++++++++++ src/Airmap/qt/types.h | 79 ++++++++++++++++++ 34 files changed, 1971 insertions(+), 7 deletions(-) create mode 100644 src/Airmap/qt/advisory.cpp create mode 100644 src/Airmap/qt/advisory.h create mode 100644 src/Airmap/qt/aircrafts.cpp create mode 100644 src/Airmap/qt/aircrafts.h create mode 100644 src/Airmap/qt/airspaces.cpp create mode 100644 src/Airmap/qt/airspaces.h create mode 100644 src/Airmap/qt/authenticator.cpp create mode 100644 src/Airmap/qt/authenticator.h create mode 100644 src/Airmap/qt/client.cpp create mode 100644 src/Airmap/qt/client.h create mode 100644 src/Airmap/qt/dispatcher.cpp create mode 100644 src/Airmap/qt/dispatcher.h create mode 100644 src/Airmap/qt/flight_plans.cpp create mode 100644 src/Airmap/qt/flight_plans.h create mode 100644 src/Airmap/qt/flights.cpp create mode 100644 src/Airmap/qt/flights.h create mode 100644 src/Airmap/qt/logger.cpp create mode 100644 src/Airmap/qt/logger.h create mode 100644 src/Airmap/qt/pilots.cpp create mode 100644 src/Airmap/qt/pilots.h create mode 100644 src/Airmap/qt/rulesets.cpp create mode 100644 src/Airmap/qt/rulesets.h create mode 100644 src/Airmap/qt/status.cpp create mode 100644 src/Airmap/qt/status.h create mode 100644 src/Airmap/qt/telemetry.cpp create mode 100644 src/Airmap/qt/telemetry.h create mode 100644 src/Airmap/qt/traffic.cpp create mode 100644 src/Airmap/qt/traffic.h create mode 100644 src/Airmap/qt/types.cpp create mode 100644 src/Airmap/qt/types.h diff --git a/QGCExternalLibs.pri b/QGCExternalLibs.pri index 85618c0..3b09a0e 100644 --- a/QGCExternalLibs.pri +++ b/QGCExternalLibs.pri @@ -1,4 +1,4 @@ -################################################################################ + ################################################################################ # # (c) 2009-2020 QGROUNDCONTROL PROJECT # @@ -245,7 +245,7 @@ contains (DEFINES, DISABLE_AIRMAP) { } } else:LinuxBuild { #-- Download and install platform-sdk libs and headers iff they're not already in the build directory - AIRMAP_PLATFORM_SDK_URL = "https://github.com/airmap/platform-sdk/releases/download/v1.1/airmap-platform-sdk-1.1.0-Linux.deb" + AIRMAP_PLATFORM_SDK_URL = "https://github.com/airmap/platform-sdk/releases/download/2.0/airmap-platform-sdk-1.1.0-Linux.deb" AIRMAP_PLATFORM_SDK_FILENAME = "airmap-platform-sdk.deb" AIRMAP_PLATFORM_SDK_INSTALL_PREFIX = "airmap-platform-sdk" diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index d9af7fb..4d0b61c 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -219,7 +219,7 @@ LinuxBuild { CONFIG += qt \ thread \ - c++11 + c++14 DebugBuild { CONFIG -= qtquickcompiler @@ -1333,7 +1333,8 @@ contains (DEFINES, QGC_AIRMAP_ENABLED) { src/Airmap/airmap.qrc INCLUDEPATH += \ - src/Airmap + src/Airmap \ + src/Airmap/qt HEADERS += \ src/Airmap/AirMapAdvisoryManager.h \ @@ -1349,6 +1350,21 @@ contains (DEFINES, QGC_AIRMAP_ENABLED) { src/Airmap/AirMapVehicleManager.h \ src/Airmap/AirMapWeatherInfoManager.h \ src/Airmap/LifetimeChecker.h \ + src/Airmap/qt/advisory.h \ + src/Airmap/qt/aircrafts.h \ + src/Airmap/qt/airspaces.h \ + src/Airmap/qt/authenticator.h \ + src/Airmap/qt/client.h \ + src/Airmap/qt/dispatcher.h \ + src/Airmap/qt/flight_plans.h \ + src/Airmap/qt/flights.h \ + src/Airmap/qt/logger.h \ + src/Airmap/qt/pilots.h \ + src/Airmap/qt/rulesets.h \ + src/Airmap/qt/status.h \ + src/Airmap/qt/telemetry.h \ + src/Airmap/qt/traffic.h \ + src/Airmap/qt/types.h \ SOURCES += \ src/Airmap/AirMapAdvisoryManager.cc \ @@ -1363,6 +1379,21 @@ contains (DEFINES, QGC_AIRMAP_ENABLED) { src/Airmap/AirMapTrafficMonitor.cc \ src/Airmap/AirMapVehicleManager.cc \ src/Airmap/AirMapWeatherInfoManager.cc \ + src/Airmap/qt/advisory.cpp \ + src/Airmap/qt/aircrafts.cpp \ + src/Airmap/qt/airspaces.cpp \ + src/Airmap/qt/authenticator.cpp \ + src/Airmap/qt/client.cpp \ + src/Airmap/qt/dispatcher.cpp \ + src/Airmap/qt/flight_plans.cpp \ + src/Airmap/qt/flights.cpp \ + src/Airmap/qt/logger.cpp \ + src/Airmap/qt/pilots.cpp \ + src/Airmap/qt/rulesets.cpp \ + src/Airmap/qt/status.cpp \ + src/Airmap/qt/telemetry.cpp \ + src/Airmap/qt/traffic.cpp \ + src/Airmap/qt/types.cpp \ #-- Do we have an API key? exists(src/Airmap/Airmap_api_key.h) { diff --git a/src/Airmap/AirMapManager.h b/src/Airmap/AirMapManager.h index a473371..bc5c653 100644 --- a/src/Airmap/AirMapManager.h +++ b/src/Airmap/AirMapManager.h @@ -13,8 +13,8 @@ #include "AirspaceManager.h" #include "QGCLoggingCategory.h" -#include -#include +#include +#include #include diff --git a/src/Airmap/AirMapSharedState.h b/src/Airmap/AirMapSharedState.h index 7c16e9c..e2cfc6c 100644 --- a/src/Airmap/AirMapSharedState.h +++ b/src/Airmap/AirMapSharedState.h @@ -14,7 +14,7 @@ #include "AirspaceManager.h" -#include +#include /** * @class AirMapSharedState diff --git a/src/Airmap/qt/advisory.cpp b/src/Airmap/qt/advisory.cpp new file mode 100644 index 0000000..5b951e5 --- /dev/null +++ b/src/Airmap/qt/advisory.cpp @@ -0,0 +1,48 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::Advisory::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new Advisory{dispatcher, client}}; +} + +airmap::qt::Advisory::Advisory(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Advisory::for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->advisory().for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Advisory::search(const Search::Parameters& parameters, const Search::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->advisory().search(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Advisory::report_weather(const ReportWeather::Parameters& parameters, + const ReportWeather::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->advisory().report_weather(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/advisory.h b/src/Airmap/qt/advisory.h new file mode 100644 index 0000000..257fcc6 --- /dev/null +++ b/src/Airmap/qt/advisory.h @@ -0,0 +1,41 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_ADVISORY_H_ +#define AIRMAP_QT_ADVISORY_H_ + +#include +#include +#include "dispatcher.h" + +namespace airmap { +namespace qt { + +class Advisory : public airmap::Advisory, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) override; + void search(const Search::Parameters& parameters, const Search::Callback& cb) override; + void report_weather(const ReportWeather::Parameters& parameters, const ReportWeather::Callback& cb) override; + + private: + explicit Advisory(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_ADVISORY_H_ diff --git a/src/Airmap/qt/aircrafts.cpp b/src/Airmap/qt/aircrafts.cpp new file mode 100644 index 0000000..c5b4664 --- /dev/null +++ b/src/Airmap/qt/aircrafts.cpp @@ -0,0 +1,48 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::Aircrafts::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new Aircrafts{dispatcher, client}}; +} + +airmap::qt::Aircrafts::Aircrafts(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Aircrafts::manufacturers(const Manufacturers::Parameters& parameters, + const Manufacturers::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->aircrafts().manufacturers(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Aircrafts::models(const Models::Parameters& parameters, const Models::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->aircrafts().models(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Aircrafts::model_for_id(const ModelForId::Parameters& parameters, const ModelForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->aircrafts().model_for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/aircrafts.h b/src/Airmap/qt/aircrafts.h new file mode 100644 index 0000000..a53d44d --- /dev/null +++ b/src/Airmap/qt/aircrafts.h @@ -0,0 +1,44 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_AIRCRAFTS_H_ +#define AIRMAP_QT_AIRCRAFTS_H_ + +#include +#include +#include + +#include +#include + +namespace airmap { +namespace qt { + +class Aircrafts : public airmap::Aircrafts, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void manufacturers(const Manufacturers::Parameters& parameters, const Manufacturers::Callback& cb) override; + void models(const Models::Parameters& parameters, const Models::Callback& cb) override; + void model_for_id(const ModelForId::Parameters& parameters, const ModelForId::Callback& cb) override; + + private: + explicit Aircrafts(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_AIRCRAFTS_H_ diff --git a/src/Airmap/qt/airspaces.cpp b/src/Airmap/qt/airspaces.cpp new file mode 100644 index 0000000..0a5bff0 --- /dev/null +++ b/src/Airmap/qt/airspaces.cpp @@ -0,0 +1,39 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::Airspaces::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new Airspaces{dispatcher, client}}; +} + +airmap::qt::Airspaces::Airspaces(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Airspaces::search(const Search::Parameters& parameters, const Search::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->airspaces().search(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Airspaces::for_ids(const ForIds::Parameters& parameters, const ForIds::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->airspaces().for_ids(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/airspaces.h b/src/Airmap/qt/airspaces.h new file mode 100644 index 0000000..4eafa6a --- /dev/null +++ b/src/Airmap/qt/airspaces.h @@ -0,0 +1,43 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_AIRSPACES_H_ +#define AIRMAP_QT_AIRSPACES_H_ + +#include +#include +#include + +#include + +namespace airmap { +namespace qt { + +class Airspaces : public airmap::Airspaces, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void search(const Search::Parameters& parameters, const Search::Callback& cb) override; + void for_ids(const ForIds::Parameters& parameters, const ForIds::Callback& cb) override; + + private: + explicit Airspaces(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_AIRSPACES_H_ diff --git a/src/Airmap/qt/authenticator.cpp b/src/Airmap/qt/authenticator.cpp new file mode 100644 index 0000000..3067f1a --- /dev/null +++ b/src/Airmap/qt/authenticator.cpp @@ -0,0 +1,50 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::Authenticator::create( + const std::shared_ptr& dispatcher, const std::shared_ptr& client) { + return std::shared_ptr{new Authenticator{dispatcher, client}}; +} + +airmap::qt::Authenticator::Authenticator(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Authenticator::authenticate_with_password(const AuthenticateWithPassword::Params& parameters, + const AuthenticateWithPassword::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->authenticator().authenticate_with_password(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Authenticator::authenticate_anonymously(const AuthenticateAnonymously::Params& parameters, + const AuthenticateAnonymously::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->authenticator().authenticate_anonymously(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Authenticator::renew_authentication(const RenewAuthentication::Params& parameters, + const RenewAuthentication::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->authenticator().renew_authentication(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/authenticator.h b/src/Airmap/qt/authenticator.h new file mode 100644 index 0000000..5112fcb --- /dev/null +++ b/src/Airmap/qt/authenticator.h @@ -0,0 +1,49 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_AUTHENTICATOR_H_ +#define AIRMAP_QT_AUTHENTICATOR_H_ + +#include +#include +#include + +#include + +namespace airmap { +namespace qt { + +class Authenticator : public airmap::Authenticator, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void authenticate_with_password(const AuthenticateWithPassword::Params& params, + const AuthenticateWithPassword::Callback& cb) override; + + void authenticate_anonymously(const AuthenticateAnonymously::Params& params, + const AuthenticateAnonymously::Callback& cb) override; + + void renew_authentication(const RenewAuthentication::Params& params, + const RenewAuthentication::Callback& cb) override; + + private: + explicit Authenticator(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_AUTHENTICATOR_H_ diff --git a/src/Airmap/qt/client.cpp b/src/Airmap/qt/client.cpp new file mode 100644 index 0000000..3fe2f55 --- /dev/null +++ b/src/Airmap/qt/client.cpp @@ -0,0 +1,178 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace { + +class ContextRunner { + public: + explicit ContextRunner(const std::shared_ptr& context) : context_{context} { + } + + void start() { + worker_ = std::thread{[this]() { context_->run(); }}; + } + + void stop() { + context_->stop(); + if (worker_.joinable()) + worker_.join(); + } + + const std::shared_ptr& context() const { + return context_; + } + + private: + std::shared_ptr context_; + std::thread worker_; +}; + +} // namespace + +struct airmap::qt::Client::Private { + explicit Private(const Client::Configuration& configuration, const std::shared_ptr& context_runner, + const std::shared_ptr& dispatcher, const std::shared_ptr& client) + : configuration_{configuration}, + context_runner_{context_runner}, + dispatcher_{dispatcher}, + client_{client}, + advisory_{airmap::qt::Advisory::create(dispatcher_, client_)}, + aircrafts_{airmap::qt::Aircrafts::create(dispatcher_, client_)}, + airspaces_{airmap::qt::Airspaces::create(dispatcher_, client_)}, + authenticator_{airmap::qt::Authenticator::create(dispatcher_, client_)}, + flight_plans_{airmap::qt::FlightPlans::create(dispatcher_, client_)}, + flights_{airmap::qt::Flights::create(dispatcher_, client_)}, + pilots_{airmap::qt::Pilots::create(dispatcher_, client_)}, + rulesets_{airmap::qt::RuleSets::create(dispatcher_, client_)}, + status_{airmap::qt::Status::create(dispatcher_, client_)}, + telemetry_{airmap::qt::Telemetry::create(dispatcher_, client_)}, + traffic_{airmap::qt::Traffic::create(dispatcher_, client_)} { + } + + ~Private() { + context_runner_->stop(); + } + + Client::Configuration configuration_; + std::shared_ptr context_runner_; + std::shared_ptr dispatcher_; + std::shared_ptr client_; + std::shared_ptr advisory_; + std::shared_ptr aircrafts_; + std::shared_ptr airspaces_; + std::shared_ptr authenticator_; + std::shared_ptr flight_plans_; + std::shared_ptr flights_; + std::shared_ptr pilots_; + std::shared_ptr rulesets_; + std::shared_ptr status_; + std::shared_ptr telemetry_; + std::shared_ptr traffic_; +}; + +void airmap::qt::Client::create(const Client::Configuration& configuration, const std::shared_ptr& logger, + QObject* parent, const CreateCallback& cb) { + register_types(); + + auto result = Context::create(logger); + auto dispatcher = std::make_shared(result.value()); + + if (!result) { + dispatcher->dispatch_to_qt([result, cb]() { cb(CreateResult{result.error()}); }); + } else { + auto cr = std::make_shared(result.value()); + + cr->context()->create_client_with_configuration( + configuration, [dispatcher, configuration, parent, cr, cb](const auto& result) { + dispatcher->dispatch_to_qt([dispatcher, configuration, parent, cr, result, cb]() { + if (result) { + cb(CreateResult{new Client{ + std::unique_ptr{new Private{configuration, cr, dispatcher, result.value()}}, parent}}); + } else { + cb(CreateResult{result.error()}); + } + }); + }); + + cr->start(); + } +} + +airmap::qt::Client::Client(std::unique_ptr&& d, QObject* parent) : QObject{parent}, d_{std::move(d)} { +} + +airmap::qt::Client::~Client() = default; + +// From airmap::Client +airmap::Authenticator& airmap::qt::Client::authenticator() { + return *d_->authenticator_; +} + +airmap::Advisory& airmap::qt::Client::advisory() { + return *d_->advisory_; +} + +airmap::Aircrafts& airmap::qt::Client::aircrafts() { + return *d_->aircrafts_; +} + +airmap::Airspaces& airmap::qt::Client::airspaces() { + return *d_->airspaces_; +} + +airmap::FlightPlans& airmap::qt::Client::flight_plans() { + return *d_->flight_plans_; +} + +airmap::Flights& airmap::qt::Client::flights() { + return *d_->flights_; +} + +airmap::Pilots& airmap::qt::Client::pilots() { + return *d_->pilots_; +} + +airmap::RuleSets& airmap::qt::Client::rulesets() { + return *d_->rulesets_; +} + +airmap::Status& airmap::qt::Client::status() { + return *d_->status_; +} + +airmap::Telemetry& airmap::qt::Client::telemetry() { + return *d_->telemetry_; +} + +airmap::Traffic& airmap::qt::Client::traffic() { + return *d_->traffic_; +} diff --git a/src/Airmap/qt/client.h b/src/Airmap/qt/client.h new file mode 100644 index 0000000..b718a1c --- /dev/null +++ b/src/Airmap/qt/client.h @@ -0,0 +1,77 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_CLIENT_H_ +#define AIRMAP_QT_CLIENT_H_ + +#include +#include +#include +#include +#include +#include + +#include + +namespace airmap { +/// @namespace namespace qt bundles up types and functions that help with integrating AirMap functionality +/// into Qt-based applications and libraries. +namespace qt { + +/// Client implements the airmap::Client interface, bridging over between +/// the Qt event loop and the native event loop of the native airmap::Client. +/// +/// All callback invocations that might happen in the context of a Client instance +/// are dispatched to the Qt applications' main thread. +class AIRMAP_EXPORT Client : public QObject, public airmap::Client { + public: + using CreateResult = Outcome; + using CreateCallback = std::function; + + /// create creates a new Client instance with parent 'parent', logging to 'logger', using the config + /// 'configuration'. The result of the request is reported to 'cb', on the thread that issued the create request. + /// + /// Please note that this function must be called on Qt's main thread as event dispatching between different + /// event loops to the Qt world is set up here. + static void create(const Client::Configuration& configuration, const std::shared_ptr& logger, QObject* parent, + const CreateCallback& cb); + + ~Client(); + + // From airmap::Client + Authenticator& authenticator() override; + Advisory& advisory() override; + Aircrafts& aircrafts() override; + Airspaces& airspaces() override; + FlightPlans& flight_plans() override; + Flights& flights() override; + Pilots& pilots() override; + RuleSets& rulesets() override; + Status& status() override; + Telemetry& telemetry() override; + Traffic& traffic() override; + + private: + /// @cond + struct Private; + Client(std::unique_ptr&& d, QObject* parent); + std::unique_ptr d_; + /// @endcond +}; + +} // namespace qt +} // namespace airmap + +/// @example qt/client.cpp +/// Illustrates how to use airmap::qt::Client, airmap::qt::DispatchingLogger and airmap::qt::Logger. + +#endif // AIRMAP_QT_CLIENT_H_ diff --git a/src/Airmap/qt/dispatcher.cpp b/src/Airmap/qt/dispatcher.cpp new file mode 100644 index 0000000..6051572 --- /dev/null +++ b/src/Airmap/qt/dispatcher.cpp @@ -0,0 +1,86 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +#include +#include + +#include + +QEvent::Type airmap::qt::Dispatcher::Event::registered_type() { + static const Type rt = static_cast(registerEventType()); + return rt; +} + +airmap::qt::Dispatcher::Event::Event(const std::function& task) : QEvent{registered_type()}, task_{task} { +} + +void airmap::qt::Dispatcher::Event::dispatch() { + task_(); +} + +std::shared_ptr airmap::qt::Dispatcher::ToQt::create() { + return std::shared_ptr{new ToQt{}}; +} + +airmap::qt::Dispatcher::ToQt::ToQt() { +} + +void airmap::qt::Dispatcher::ToQt::dispatch(const Task& task) { + auto sp = shared_from_this(); + + QCoreApplication::postEvent(this, new Event{[sp, task]() { task(); }}); +} + +bool airmap::qt::Dispatcher::ToQt::event(QEvent* event) { + assert(QCoreApplication::instance()); + assert(QThread::currentThread() == QCoreApplication::instance()->thread()); + + if (event->type() == Event::registered_type()) { + event->accept(); + + if (auto e = dynamic_cast(event)) { + e->dispatch(); + } + + return true; + } + + return false; +} + +std::shared_ptr airmap::qt::Dispatcher::ToNative::create( + const std::shared_ptr& context) { + return std::shared_ptr{new ToNative{context}}; +} + +airmap::qt::Dispatcher::ToNative::ToNative(const std::shared_ptr& context) : context_{context} { +} + +void airmap::qt::Dispatcher::ToNative::dispatch(const Task& task) { + context_->dispatch(task); +} + +airmap::qt::Dispatcher::Dispatcher(const std::shared_ptr& context) + : to_qt_{ToQt::create()}, to_native_{ToNative::create(context)} { +} + +void airmap::qt::Dispatcher::dispatch_to_qt(const std::function& task) { + to_qt_->dispatch(task); +} + +void airmap::qt::Dispatcher::dispatch_to_native(const std::function& task) { + to_native_->dispatch(task); +} + +// From QObject diff --git a/src/Airmap/qt/dispatcher.h b/src/Airmap/qt/dispatcher.h new file mode 100644 index 0000000..6b9bbaa --- /dev/null +++ b/src/Airmap/qt/dispatcher.h @@ -0,0 +1,75 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_DISPATCHER_H_ +#define AIRMAP_QT_DISPATCHER_H_ + +#include + +#include +#include + +#include +#include +namespace airmap { +namespace qt { + +class Dispatcher : public QObject { + public: + class Event : public QEvent { + public: + static Type registered_type(); + + explicit Event(const std::function& task); + void dispatch(); + + private: + std::function task_; + }; + + using Task = std::function; + + class ToQt : public QObject, public std::enable_shared_from_this { + public: + static std::shared_ptr create(); + void dispatch(const Task& task); + + private: + ToQt(); + // From QObject + bool event(QEvent* event) override; + }; + + class ToNative : public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& context); + void dispatch(const Task& task); + + private: + explicit ToNative(const std::shared_ptr& context); + std::shared_ptr context_; + }; + + explicit Dispatcher(const std::shared_ptr& context); + + void dispatch_to_qt(const Task& task); + void dispatch_to_native(const Task& task); + + private: + std::shared_ptr to_qt_; + std::shared_ptr to_native_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_DISPATCHER_H_ diff --git a/src/Airmap/qt/flight_plans.cpp b/src/Airmap/qt/flight_plans.cpp new file mode 100644 index 0000000..45d8b2b --- /dev/null +++ b/src/Airmap/qt/flight_plans.cpp @@ -0,0 +1,72 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::FlightPlans::create( + const std::shared_ptr& dispatcher, const std::shared_ptr& client) { + return std::shared_ptr{new FlightPlans{dispatcher, client}}; +} + +airmap::qt::FlightPlans::FlightPlans(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::FlightPlans::for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flight_plans().for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::FlightPlans::create_by_polygon(const Create::Parameters& parameters, const Create::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flight_plans().create_by_polygon(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::FlightPlans::update(const Update::Parameters& parameters, const Update::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flight_plans().update(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::FlightPlans::delete_(const Delete::Parameters& parameters, const Delete::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flight_plans().delete_(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::FlightPlans::render_briefing(const RenderBriefing::Parameters& parameters, + const RenderBriefing::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flight_plans().render_briefing(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::FlightPlans::submit(const Submit::Parameters& parameters, const Submit::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flight_plans().submit(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/flight_plans.h b/src/Airmap/qt/flight_plans.h new file mode 100644 index 0000000..94b7d91 --- /dev/null +++ b/src/Airmap/qt/flight_plans.h @@ -0,0 +1,48 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_FLIGHT_PLANS_H_ +#define AIRMAP_QT_FLIGHT_PLANS_H_ + +#include +#include +#include + +#include + +namespace airmap { +namespace qt { + +/// FlightPlans provides functionality for managing flight plans. +class FlightPlans : public airmap::FlightPlans, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) override; + void create_by_polygon(const Create::Parameters& parameters, const Create::Callback& cb) override; + void update(const Update::Parameters& parameters, const Update::Callback& cb) override; + void delete_(const Delete::Parameters& parameters, const Delete::Callback& cb) override; + void render_briefing(const RenderBriefing::Parameters& parameters, const RenderBriefing::Callback& cb) override; + void submit(const Submit::Parameters& parameters, const Submit::Callback& cb) override; + + private: + explicit FlightPlans(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_FLIGHT_PLANS_H_ diff --git a/src/Airmap/qt/flights.cpp b/src/Airmap/qt/flights.cpp new file mode 100644 index 0000000..7e9f833 --- /dev/null +++ b/src/Airmap/qt/flights.cpp @@ -0,0 +1,100 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::Flights::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new Flights{dispatcher, client}}; +} + +airmap::qt::Flights::Flights(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Flights::search(const Search::Parameters& parameters, const Search::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().search(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Flights::for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Flights::create_flight_by_point(const CreateFlight::Parameters& parameters, + const CreateFlight::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().create_flight_by_point(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Flights::create_flight_by_path(const CreateFlight::Parameters& parameters, + const CreateFlight::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().create_flight_by_path(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Flights::create_flight_by_polygon(const CreateFlight::Parameters& parameters, + const CreateFlight::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().create_flight_by_polygon(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Flights::end_flight(const EndFlight::Parameters& parameters, const EndFlight::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().end_flight(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Flights::delete_flight(const DeleteFlight::Parameters& parameters, const DeleteFlight::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().delete_flight(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Flights::start_flight_communications(const StartFlightCommunications::Parameters& parameters, + const StartFlightCommunications::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().start_flight_communications(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Flights::end_flight_communications(const EndFlightCommunications::Parameters& parameters, + const EndFlightCommunications::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->flights().end_flight_communications(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/flights.h b/src/Airmap/qt/flights.h new file mode 100644 index 0000000..9cc7934 --- /dev/null +++ b/src/Airmap/qt/flights.h @@ -0,0 +1,52 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_FLIGHTS_H_ +#define AIRMAP_QT_FLIGHTS_H_ + +#include +#include +#include + +#include + +namespace airmap { +namespace qt { + +class Flights : public airmap::Flights, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void search(const Search::Parameters& parameters, const Search::Callback& cb) override; + void for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) override; + void create_flight_by_point(const CreateFlight::Parameters& parameters, const CreateFlight::Callback& cb) override; + void create_flight_by_path(const CreateFlight::Parameters& parameters, const CreateFlight::Callback& cb) override; + void create_flight_by_polygon(const CreateFlight::Parameters& parameters, const CreateFlight::Callback& cb) override; + void end_flight(const EndFlight::Parameters& parameters, const EndFlight::Callback& cb) override; + void delete_flight(const DeleteFlight::Parameters& parameters, const DeleteFlight::Callback& cb) override; + void start_flight_communications(const StartFlightCommunications::Parameters& parameters, + const StartFlightCommunications::Callback& cb) override; + void end_flight_communications(const EndFlightCommunications::Parameters& parameters, + const EndFlightCommunications::Callback& cb) override; + + private: + explicit Flights(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_FLIGHTS_H_ diff --git a/src/Airmap/qt/logger.cpp b/src/Airmap/qt/logger.cpp new file mode 100644 index 0000000..3d95577 --- /dev/null +++ b/src/Airmap/qt/logger.cpp @@ -0,0 +1,90 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +#include + +struct airmap::qt::Logger::Private { + QLoggingCategory logging_category{"airmap"}; +}; + +struct airmap::qt::DispatchingLogger::Private { + std::shared_ptr next; + std::shared_ptr dispatcher; +}; + +airmap::qt::Logger::Logger() : d_{new Private{}} { +} +airmap::qt::Logger::~Logger() { +} + +QLoggingCategory& airmap::qt::Logger::logging_category() { + static QLoggingCategory lc{"airmap"}; + return lc; +} + +void airmap::qt::Logger::log(Severity severity, const char* message, const char*) { + switch (severity) { + case Severity::debug: + qCDebug(logging_category(), "%s", message); + break; + case Severity::info: + qCInfo(logging_category(), "%s", message); + break; + case Severity::error: + qCWarning(logging_category(), "%s", message); + break; + default: + break; + } +} + +bool airmap::qt::Logger::should_log(Severity severity, const char*, const char*) { + switch (severity) { + case Severity::debug: + return logging_category().isDebugEnabled(); + case Severity::info: + return logging_category().isInfoEnabled(); + case Severity::error: + return logging_category().isWarningEnabled(); + default: + break; + } + + return true; +} + +airmap::qt::DispatchingLogger::DispatchingLogger(const std::shared_ptr& next) + : d_{new Private{next, Dispatcher::ToQt::create()}} { +} + +airmap::qt::DispatchingLogger::~DispatchingLogger() { +} + +void airmap::qt::DispatchingLogger::log(Severity severity, const char* message, const char* component) { + std::string cmessage{message}; + std::string ccomponent{component}; + auto cnext{d_->next}; + + d_->dispatcher->dispatch([severity, cmessage, ccomponent, cnext] { + if (cnext->should_log(severity, cmessage.c_str(), ccomponent.c_str())) + cnext->log(severity, cmessage.c_str(), ccomponent.c_str()); + }); +} + +bool airmap::qt::DispatchingLogger::should_log(Severity, const char*, const char*) { + // We have to accept all incoming log messages and postpone + // the actual evaluation of should_log in the context of next until we + // run on the correct thread. + return true; +} diff --git a/src/Airmap/qt/logger.h b/src/Airmap/qt/logger.h new file mode 100644 index 0000000..0fff35a --- /dev/null +++ b/src/Airmap/qt/logger.h @@ -0,0 +1,69 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_LOGGER_H_ +#define AIRMAP_QT_LOGGER_H_ + +#include +#include + +#include + +#include + +namespace airmap { +namespace qt { + +/// Logger is an airmap::Logger implementation that uses to +/// Qt's logging facilities. +class AIRMAP_EXPORT Logger : public airmap::Logger { + public: + /// logging_category returns a QLoggingCategory instance + /// that enables calling code to fine-tune logging behavior of a Logger instance. + QLoggingCategory& logging_category(); + + /// Logger initializes a new instance. + Logger(); + /// ~Logger cleans up all resources held by a Logger instance. + ~Logger(); + + // From airmap::Logger + void log(Severity severity, const char* message, const char* component) override; + bool should_log(Severity severity, const char* message, const char* component) override; + + private: + struct Private; + std::unique_ptr d_; +}; + +/// DispatchingLogger is an airmap::Logger implementation that dispatches to Qt's main +/// event loop for logger invocation +class AIRMAP_EXPORT DispatchingLogger : public airmap::Logger { + public: + /// DispatchingLogger initializes a new instance with 'next'. + DispatchingLogger(const std::shared_ptr& next); + /// ~DispatchingLogging cleans up all resources held a DispatchingLogger instance. + ~DispatchingLogger(); + + // From airmap::Logger + void log(Severity severity, const char* message, const char* component) override; + bool should_log(Severity severity, const char* message, const char* component) override; + + private: + struct Private; + std::unique_ptr d_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_LOGGER_H_ diff --git a/src/Airmap/qt/pilots.cpp b/src/Airmap/qt/pilots.cpp new file mode 100644 index 0000000..439075d --- /dev/null +++ b/src/Airmap/qt/pilots.cpp @@ -0,0 +1,98 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::Pilots::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new Pilots{dispatcher, client}}; +} + +airmap::qt::Pilots::Pilots(const std::shared_ptr& dispatcher, const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Pilots::authenticated(const Authenticated::Parameters& parameters, const Authenticated::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().authenticated(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Pilots::for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Pilots::update_for_id(const UpdateForId::Parameters& parameters, const UpdateForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().update_for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Pilots::start_verify_pilot_phone_for_id(const StartVerifyPilotPhoneForId::Parameters& parameters, + const StartVerifyPilotPhoneForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().start_verify_pilot_phone_for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Pilots::finish_verify_pilot_phone_for_id(const FinishVerifyPilotPhoneForId::Parameters& parameters, + const FinishVerifyPilotPhoneForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().finish_verify_pilot_phone_for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Pilots::aircrafts(const Aircrafts::Parameters& parameters, const Aircrafts::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().aircrafts(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Pilots::add_aircraft(const AddAircraft::Parameters& parameters, const AddAircraft::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().add_aircraft(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Pilots::delete_aircraft(const DeleteAircraft::Parameters& parameters, + const DeleteAircraft::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().delete_aircraft(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Pilots::update_aircraft(const UpdateAircraft::Parameters& parameters, + const UpdateAircraft::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->pilots().update_aircraft(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/pilots.h b/src/Airmap/qt/pilots.h new file mode 100644 index 0000000..8fc183c --- /dev/null +++ b/src/Airmap/qt/pilots.h @@ -0,0 +1,53 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_PILOTS_H_ +#define AIRMAP_QT_PILOTS_H_ + +#include + +#include +#include + +#include + +namespace airmap { +namespace qt { + +class Pilots : public airmap::Pilots, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void authenticated(const Authenticated::Parameters& parameters, const Authenticated::Callback& cb) override; + void for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) override; + void update_for_id(const UpdateForId::Parameters& parameters, const UpdateForId::Callback& cb) override; + void start_verify_pilot_phone_for_id(const StartVerifyPilotPhoneForId::Parameters& parameters, + const StartVerifyPilotPhoneForId::Callback& cb) override; + void finish_verify_pilot_phone_for_id(const FinishVerifyPilotPhoneForId::Parameters& parameters, + const FinishVerifyPilotPhoneForId::Callback& cb) override; + void aircrafts(const Aircrafts::Parameters& parameters, const Aircrafts::Callback& cb) override; + void add_aircraft(const AddAircraft::Parameters& parameters, const AddAircraft::Callback& cb) override; + void delete_aircraft(const DeleteAircraft::Parameters& parameters, const DeleteAircraft::Callback& cb) override; + void update_aircraft(const UpdateAircraft::Parameters& parameters, const UpdateAircraft::Callback& cb) override; + + private: + explicit Pilots(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_PILOTS_H_ diff --git a/src/Airmap/qt/rulesets.cpp b/src/Airmap/qt/rulesets.cpp new file mode 100644 index 0000000..255a4a2 --- /dev/null +++ b/src/Airmap/qt/rulesets.cpp @@ -0,0 +1,65 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::RuleSets::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new RuleSets{dispatcher, client}}; +} + +airmap::qt::RuleSets::RuleSets(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::RuleSets::search(const Search::Parameters& parameters, const Search::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->rulesets().search(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::RuleSets::for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->rulesets().for_id(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::RuleSets::fetch_rules(const FetchRules::Parameters& parameters, const FetchRules::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->rulesets().fetch_rules(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::RuleSets::evaluate_rulesets(const EvaluateRules::Parameters& parameters, + const EvaluateRules::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->rulesets().evaluate_rulesets(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::RuleSets::evaluate_flight_plan(const EvaluateFlightPlan::Parameters& parameters, + const EvaluateFlightPlan::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->rulesets().evaluate_flight_plan(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/rulesets.h b/src/Airmap/qt/rulesets.h new file mode 100644 index 0000000..1cab6e2 --- /dev/null +++ b/src/Airmap/qt/rulesets.h @@ -0,0 +1,43 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_RULESETS_H_ +#define AIRMAP_QT_RULESETS_H_ + +#include +#include +#include + +namespace airmap { +namespace qt { + +class RuleSets : public airmap::RuleSets, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void search(const Search::Parameters& parameters, const Search::Callback& cb) override; + void for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) override; + void fetch_rules(const FetchRules::Parameters& parameters, const FetchRules::Callback& cb) override; + void evaluate_rulesets(const EvaluateRules::Parameters& parameters, const EvaluateRules::Callback& cb) override; + void evaluate_flight_plan(const EvaluateFlightPlan::Parameters& parameters, const EvaluateFlightPlan::Callback& cb) override; + + private: + explicit RuleSets(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_RULESETS_H_ diff --git a/src/Airmap/qt/status.cpp b/src/Airmap/qt/status.cpp new file mode 100644 index 0000000..b804d9d --- /dev/null +++ b/src/Airmap/qt/status.cpp @@ -0,0 +1,46 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::Status::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new Status{dispatcher, client}}; +} + +airmap::qt::Status::Status(const std::shared_ptr& dispatcher, const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Status::get_status_by_point(const GetStatus::Parameters& parameters, const GetStatus::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->status().get_status_by_point(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Status::get_status_by_path(const GetStatus::Parameters& parameters, const GetStatus::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->status().get_status_by_path(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} + +void airmap::qt::Status::get_status_by_polygon(const GetStatus::Parameters& parameters, const GetStatus::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->status().get_status_by_polygon(parameters, [this, sp, cb](const auto& result) { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + }); + }); +} diff --git a/src/Airmap/qt/status.h b/src/Airmap/qt/status.h new file mode 100644 index 0000000..47545eb --- /dev/null +++ b/src/Airmap/qt/status.h @@ -0,0 +1,44 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_STATUS_H_ +#define AIRMAP_QT_STATUS_H_ + +#include +#include +#include + +#include + +namespace airmap { +namespace qt { + +class Status : public airmap::Status, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void get_status_by_point(const GetStatus::Parameters& parameters, const GetStatus::Callback& cb) override; + void get_status_by_path(const GetStatus::Parameters& parameters, const GetStatus::Callback& cb) override; + void get_status_by_polygon(const GetStatus::Parameters& parameters, const GetStatus::Callback& cb) override; + + private: + explicit Status(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_STATUS_H_ diff --git a/src/Airmap/qt/telemetry.cpp b/src/Airmap/qt/telemetry.cpp new file mode 100644 index 0000000..dccd5bb --- /dev/null +++ b/src/Airmap/qt/telemetry.cpp @@ -0,0 +1,32 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +#include + +std::shared_ptr airmap::qt::Telemetry::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new Telemetry{dispatcher, client}}; +} + +airmap::qt::Telemetry::Telemetry(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Telemetry::submit_updates(const Flight& flight, const std::string& key, + const std::initializer_list& updates) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), flight, key, updates]() { + sp->client_->telemetry().submit_updates(flight, key, updates); + }); +} diff --git a/src/Airmap/qt/telemetry.h b/src/Airmap/qt/telemetry.h new file mode 100644 index 0000000..d606348 --- /dev/null +++ b/src/Airmap/qt/telemetry.h @@ -0,0 +1,43 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_TELEMETRY_H_ +#define AIRMAP_QT_TELEMETRY_H_ + +#include +#include +#include + +#include + +namespace airmap { +namespace qt { + +class Telemetry : public airmap::Telemetry, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + void submit_updates(const Flight& flight, const std::string& key, + const std::initializer_list& updates) override; + + private: + explicit Telemetry(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_TELEMETRY_H_ diff --git a/src/Airmap/qt/traffic.cpp b/src/Airmap/qt/traffic.cpp new file mode 100644 index 0000000..ca03050 --- /dev/null +++ b/src/Airmap/qt/traffic.cpp @@ -0,0 +1,64 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +std::shared_ptr airmap::qt::Traffic::Monitor::create( + const std::shared_ptr& dispatcher, const std::shared_ptr& native) { + return std::shared_ptr{new Monitor{dispatcher, native}}; +} + +airmap::qt::Traffic::Monitor::Monitor(const std::shared_ptr& dispatcher, + const std::shared_ptr& native) + : dispatcher_{dispatcher}, native_{native} { +} + +void airmap::qt::Traffic::Monitor::subscribe(const std::shared_ptr& subscriber) { + dispatcher_->dispatch_to_qt([this, sp = shared_from_this(), subscriber] { sp->subscribers_.insert(subscriber); }); +} + +void airmap::qt::Traffic::Monitor::unsubscribe( + const std::shared_ptr& subscriber) { + dispatcher_->dispatch_to_qt([this, sp = shared_from_this(), subscriber] { sp->subscribers_.erase(subscriber); }); +} + +void airmap::qt::Traffic::Monitor::handle_update(Update::Type type, const std::vector& update) { + dispatcher_->dispatch_to_qt([this, sp = shared_from_this(), type, update]() { + for (const auto& subscriber : sp->subscribers_) + subscriber->handle_update(type, update); + }); +} + +std::shared_ptr airmap::qt::Traffic::create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) { + return std::shared_ptr{new Traffic{dispatcher, client}}; +} + +airmap::qt::Traffic::Traffic(const std::shared_ptr& dispatcher, + const std::shared_ptr& client) + : dispatcher_{dispatcher}, client_{client} { +} + +void airmap::qt::Traffic::monitor(const Monitor::Params& parameters, const Monitor::Callback& cb) { + dispatcher_->dispatch_to_native([this, sp = shared_from_this(), parameters, cb]() { + sp->client_->traffic().monitor(parameters, [this, sp, parameters, cb](const auto& result) { + if (result) { + auto m = result.value(); + auto mm = Monitor::create(sp->dispatcher_, m); + m->subscribe(mm); + sp->dispatcher_->dispatch_to_qt([sp, mm, cb]() { cb(Monitor::Result{mm}); }); + } else { + sp->dispatcher_->dispatch_to_qt([sp, result, cb]() { cb(result); }); + } + }); + }); +} diff --git a/src/Airmap/qt/traffic.h b/src/Airmap/qt/traffic.h new file mode 100644 index 0000000..e049119 --- /dev/null +++ b/src/Airmap/qt/traffic.h @@ -0,0 +1,66 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_TRAFFIC_H_ +#define AIRMAP_QT_TRAFFIC_H_ + +#include + +#include + +#include +#include + +namespace airmap { +namespace qt { + +class Traffic : public airmap::Traffic, public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& client); + + class Monitor : public airmap::Traffic::Monitor, + public airmap::Traffic::Monitor::Subscriber, + public std::enable_shared_from_this { + public: + static std::shared_ptr create(const std::shared_ptr& dispatcher, + const std::shared_ptr& native); + + // From airmap::Traffic::Monitor + void subscribe(const std::shared_ptr& subscriber) override; + void unsubscribe(const std::shared_ptr& subscriber) override; + // From airmap::Traffic::Monitor::Subscriber + void handle_update(Update::Type type, const std::vector& update) override; + + private: + explicit Monitor(const std::shared_ptr& dispatcher, + const std::shared_ptr& native); + + std::shared_ptr dispatcher_; + std::shared_ptr native_; + std::set> subscribers_; + }; + + // From airmap::Traffic + void monitor(const Monitor::Params& params, const Monitor::Callback& cb) override; + + private: + explicit Traffic(const std::shared_ptr& dispatcher, const std::shared_ptr& client); + + std::shared_ptr dispatcher_; + std::shared_ptr client_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_TRAFFIC_H_ diff --git a/src/Airmap/qt/types.cpp b/src/Airmap/qt/types.cpp new file mode 100644 index 0000000..36b3ec3 --- /dev/null +++ b/src/Airmap/qt/types.cpp @@ -0,0 +1,91 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include + +namespace { + +template +inline void register_type_once(const char* name) { + static const int id = qRegisterMetaType(name); + (void)id; +} + +template +inline void register_type_once() { + static const int id = qRegisterMetaType(); + (void)id; +} + +} // namespace + +void airmap::qt::register_types() { + register_type_once("Aircraft"); + register_type_once("Airspace"); + register_type_once("Credentials"); + register_type_once("DateTime"); + register_type_once("Error"); + register_type_once("FlightPlan"); + register_type_once("Flight"); + register_type_once("Geometry"); + register_type_once("Pilot"); + register_type_once("Rule"); + register_type_once("RuleSet"); + register_type_once("RuleSet::Rule"); + register_type_once("Status::Advisory"); + register_type_once("Status::Wind"); + register_type_once("Status::Weather"); + register_type_once("Status::Report"); + register_type_once("Telemetry::Position"); + register_type_once("Telemetry::Speed"); + register_type_once("Telemetry::Attitude"); + register_type_once("Telemetry::Barometer"); + register_type_once>("Optional"); + register_type_once("Token::Type"); + register_type_once("Token::Anonymous"); + register_type_once("Token::OAuth"); + register_type_once("Token::Refreshed"); + register_type_once("Token"); + register_type_once("Traffic::Update::Type"); + register_type_once("Traffic::Update"); + register_type_once("Version"); + + register_type_once("airmap::Aircraft"); + register_type_once("airmap::Airspace"); + register_type_once("airmap::Credentials"); + register_type_once("airmap::DateTime"); + register_type_once("airmap::Error"); + register_type_once("airmap::FlightPlan"); + register_type_once("airmap::Flight"); + register_type_once("airmap::Geometry"); + register_type_once("airmap::Pilot"); + register_type_once("airmap::Rule"); + register_type_once("airmap::RuleSet"); + register_type_once("airmap::RuleSet::Rule"); + register_type_once("airmap::Advisory"); + register_type_once("airmap::Wind"); + register_type_once("airmap::Weather"); + register_type_once("airmap::Report"); + register_type_once("airmap::Telemetry::Position"); + register_type_once("airmap::Telemetry::Speed"); + register_type_once("airmap::Telemetry::Attitude"); + register_type_once("airmap::Telemetry::Barometer"); + register_type_once>("airmap::Optional"); + register_type_once("airmap::Token::Type"); + register_type_once("airmap::Token::Anonymous"); + register_type_once("airmap::Token::OAuth"); + register_type_once("airmap::Token::Refreshed"); + register_type_once("airmap::Token"); + register_type_once("airmap::Traffic::Update::Type"); + register_type_once("airmap::Traffic::Update"); + register_type_once("airmap::Version"); +} diff --git a/src/Airmap/qt/types.h b/src/Airmap/qt/types.h new file mode 100644 index 0000000..006dea4 --- /dev/null +++ b/src/Airmap/qt/types.h @@ -0,0 +1,79 @@ +// AirMap Platform SDK +// Copyright © 2018 AirMap, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef AIRMAP_QT_TYPES_H_ +#define AIRMAP_QT_TYPES_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +Q_DECLARE_METATYPE(airmap::Aircraft) +Q_DECLARE_METATYPE(airmap::Airspace) +Q_DECLARE_METATYPE(airmap::Credentials) +Q_DECLARE_METATYPE(airmap::DateTime) +Q_DECLARE_METATYPE(airmap::Error) +Q_DECLARE_METATYPE(airmap::FlightPlan) +Q_DECLARE_METATYPE(airmap::Flight) +Q_DECLARE_METATYPE(airmap::Geometry) +Q_DECLARE_METATYPE(airmap::Pilot) +Q_DECLARE_METATYPE(airmap::Rule) +Q_DECLARE_METATYPE(airmap::RuleSet) +Q_DECLARE_METATYPE(airmap::RuleSet::Rule) +Q_DECLARE_METATYPE(airmap::Status::Advisory) +Q_DECLARE_METATYPE(airmap::Status::Wind) +Q_DECLARE_METATYPE(airmap::Status::Weather) +Q_DECLARE_METATYPE(airmap::Status::Report) +Q_DECLARE_METATYPE(airmap::Telemetry::Position) +Q_DECLARE_METATYPE(airmap::Telemetry::Speed) +Q_DECLARE_METATYPE(airmap::Telemetry::Attitude) +Q_DECLARE_METATYPE(airmap::Telemetry::Barometer) +Q_DECLARE_METATYPE(airmap::Optional) +Q_DECLARE_METATYPE(airmap::Token::Type) +Q_DECLARE_METATYPE(airmap::Token::Anonymous) +Q_DECLARE_METATYPE(airmap::Token::OAuth) +Q_DECLARE_METATYPE(airmap::Token::Refreshed) +Q_DECLARE_METATYPE(airmap::Token) +Q_DECLARE_METATYPE(airmap::Traffic::Update::Type) +Q_DECLARE_METATYPE(airmap::Traffic::Update) +Q_DECLARE_METATYPE(airmap::Version) + +namespace airmap { +namespace qt { + +/// register_types makes airmap::* types known to the Qt type system. +/// +/// This function has to be called at least once to be able to use airmap::* +/// types in queued signal-slot connections. +AIRMAP_EXPORT void register_types(); + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_TYPES_H_