From 7fcffc3a35a1ade9a1643721dcaf45b2407a0530 Mon Sep 17 00:00:00 2001 From: jennerl Date: Thu, 15 Apr 2021 13:04:07 -0500 Subject: [PATCH] renamed qt dir to services for all of the platform-sdk service interface classes --- src/Airmap/qt/advisory.cpp | 36 -------- src/Airmap/qt/advisory.h | 29 ------ src/Airmap/qt/aircrafts.cpp | 36 -------- src/Airmap/qt/aircrafts.h | 32 ------- src/Airmap/qt/airspaces.cpp | 27 ------ src/Airmap/qt/airspaces.h | 31 ------- src/Airmap/qt/authenticator.cpp | 38 -------- src/Airmap/qt/authenticator.h | 37 -------- src/Airmap/qt/client.cpp | 166 ---------------------------------- src/Airmap/qt/client.h | 65 ------------- src/Airmap/qt/dispatcher.cpp | 62 ------------- src/Airmap/qt/dispatcher.h | 53 ----------- src/Airmap/qt/flight_plans.cpp | 60 ------------ src/Airmap/qt/flight_plans.h | 36 -------- src/Airmap/qt/flights.cpp | 88 ------------------ src/Airmap/qt/flights.h | 40 -------- src/Airmap/qt/logger.cpp | 78 ---------------- src/Airmap/qt/logger.h | 57 ------------ src/Airmap/qt/pilots.cpp | 86 ------------------ src/Airmap/qt/pilots.h | 41 --------- src/Airmap/qt/rulesets.cpp | 53 ----------- src/Airmap/qt/rulesets.h | 31 ------- src/Airmap/qt/status.cpp | 34 ------- src/Airmap/qt/status.h | 32 ------- src/Airmap/qt/telemetry.cpp | 20 ---- src/Airmap/qt/telemetry.h | 31 ------- src/Airmap/qt/traffic.cpp | 52 ----------- src/Airmap/qt/traffic.h | 54 ----------- src/Airmap/qt/types.cpp | 79 ---------------- src/Airmap/qt/types.h | 67 -------------- src/Airmap/services/advisory.cpp | 36 ++++++++ src/Airmap/services/advisory.h | 29 ++++++ src/Airmap/services/aircrafts.cpp | 36 ++++++++ src/Airmap/services/aircrafts.h | 32 +++++++ src/Airmap/services/airspaces.cpp | 27 ++++++ src/Airmap/services/airspaces.h | 31 +++++++ src/Airmap/services/authenticator.cpp | 38 ++++++++ src/Airmap/services/authenticator.h | 37 ++++++++ src/Airmap/services/client.cpp | 166 ++++++++++++++++++++++++++++++++++ src/Airmap/services/client.h | 65 +++++++++++++ src/Airmap/services/dispatcher.cpp | 62 +++++++++++++ src/Airmap/services/dispatcher.h | 53 +++++++++++ src/Airmap/services/flight_plans.cpp | 60 ++++++++++++ src/Airmap/services/flight_plans.h | 36 ++++++++ src/Airmap/services/flights.cpp | 88 ++++++++++++++++++ src/Airmap/services/flights.h | 40 ++++++++ src/Airmap/services/logger.cpp | 78 ++++++++++++++++ src/Airmap/services/logger.h | 57 ++++++++++++ src/Airmap/services/pilots.cpp | 86 ++++++++++++++++++ src/Airmap/services/pilots.h | 41 +++++++++ src/Airmap/services/rulesets.cpp | 53 +++++++++++ src/Airmap/services/rulesets.h | 31 +++++++ src/Airmap/services/status.cpp | 34 +++++++ src/Airmap/services/status.h | 32 +++++++ src/Airmap/services/telemetry.cpp | 20 ++++ src/Airmap/services/telemetry.h | 31 +++++++ src/Airmap/services/traffic.cpp | 52 +++++++++++ src/Airmap/services/traffic.h | 54 +++++++++++ src/Airmap/services/types.cpp | 79 ++++++++++++++++ src/Airmap/services/types.h | 67 ++++++++++++++ 60 files changed, 1551 insertions(+), 1551 deletions(-) delete mode 100644 src/Airmap/qt/advisory.cpp delete mode 100644 src/Airmap/qt/advisory.h delete mode 100644 src/Airmap/qt/aircrafts.cpp delete mode 100644 src/Airmap/qt/aircrafts.h delete mode 100644 src/Airmap/qt/airspaces.cpp delete mode 100644 src/Airmap/qt/airspaces.h delete mode 100644 src/Airmap/qt/authenticator.cpp delete mode 100644 src/Airmap/qt/authenticator.h delete mode 100644 src/Airmap/qt/client.cpp delete mode 100644 src/Airmap/qt/client.h delete mode 100644 src/Airmap/qt/dispatcher.cpp delete mode 100644 src/Airmap/qt/dispatcher.h delete mode 100644 src/Airmap/qt/flight_plans.cpp delete mode 100644 src/Airmap/qt/flight_plans.h delete mode 100644 src/Airmap/qt/flights.cpp delete mode 100644 src/Airmap/qt/flights.h delete mode 100644 src/Airmap/qt/logger.cpp delete mode 100644 src/Airmap/qt/logger.h delete mode 100644 src/Airmap/qt/pilots.cpp delete mode 100644 src/Airmap/qt/pilots.h delete mode 100644 src/Airmap/qt/rulesets.cpp delete mode 100644 src/Airmap/qt/rulesets.h delete mode 100644 src/Airmap/qt/status.cpp delete mode 100644 src/Airmap/qt/status.h delete mode 100644 src/Airmap/qt/telemetry.cpp delete mode 100644 src/Airmap/qt/telemetry.h delete mode 100644 src/Airmap/qt/traffic.cpp delete mode 100644 src/Airmap/qt/traffic.h delete mode 100644 src/Airmap/qt/types.cpp delete mode 100644 src/Airmap/qt/types.h create mode 100644 src/Airmap/services/advisory.cpp create mode 100644 src/Airmap/services/advisory.h create mode 100644 src/Airmap/services/aircrafts.cpp create mode 100644 src/Airmap/services/aircrafts.h create mode 100644 src/Airmap/services/airspaces.cpp create mode 100644 src/Airmap/services/airspaces.h create mode 100644 src/Airmap/services/authenticator.cpp create mode 100644 src/Airmap/services/authenticator.h create mode 100644 src/Airmap/services/client.cpp create mode 100644 src/Airmap/services/client.h create mode 100644 src/Airmap/services/dispatcher.cpp create mode 100644 src/Airmap/services/dispatcher.h create mode 100644 src/Airmap/services/flight_plans.cpp create mode 100644 src/Airmap/services/flight_plans.h create mode 100644 src/Airmap/services/flights.cpp create mode 100644 src/Airmap/services/flights.h create mode 100644 src/Airmap/services/logger.cpp create mode 100644 src/Airmap/services/logger.h create mode 100644 src/Airmap/services/pilots.cpp create mode 100644 src/Airmap/services/pilots.h create mode 100644 src/Airmap/services/rulesets.cpp create mode 100644 src/Airmap/services/rulesets.h create mode 100644 src/Airmap/services/status.cpp create mode 100644 src/Airmap/services/status.h create mode 100644 src/Airmap/services/telemetry.cpp create mode 100644 src/Airmap/services/telemetry.h create mode 100644 src/Airmap/services/traffic.cpp create mode 100644 src/Airmap/services/traffic.h create mode 100644 src/Airmap/services/types.cpp create mode 100644 src/Airmap/services/types.h diff --git a/src/Airmap/qt/advisory.cpp b/src/Airmap/qt/advisory.cpp deleted file mode 100644 index f0d548f..0000000 --- a/src/Airmap/qt/advisory.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#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_airmap([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_airmap([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_airmap([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 deleted file mode 100644 index 82c64e9..0000000 --- a/src/Airmap/qt/advisory.h +++ /dev/null @@ -1,29 +0,0 @@ -#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 deleted file mode 100644 index 1b8bd2f..0000000 --- a/src/Airmap/qt/aircrafts.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#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_airmap([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_airmap([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_airmap([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 deleted file mode 100644 index 4bf8461..0000000 --- a/src/Airmap/qt/aircrafts.h +++ /dev/null @@ -1,32 +0,0 @@ -#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 deleted file mode 100644 index 3915913..0000000 --- a/src/Airmap/qt/airspaces.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#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_airmap([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_airmap([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 deleted file mode 100644 index 619b0df..0000000 --- a/src/Airmap/qt/airspaces.h +++ /dev/null @@ -1,31 +0,0 @@ -#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 deleted file mode 100644 index c715e21..0000000 --- a/src/Airmap/qt/authenticator.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#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_airmap([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_airmap([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_airmap([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 deleted file mode 100644 index 729cb63..0000000 --- a/src/Airmap/qt/authenticator.h +++ /dev/null @@ -1,37 +0,0 @@ -#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 deleted file mode 100644 index c27814d..0000000 --- a/src/Airmap/qt/client.cpp +++ /dev/null @@ -1,166 +0,0 @@ -#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 deleted file mode 100644 index aec7b85..0000000 --- a/src/Airmap/qt/client.h +++ /dev/null @@ -1,65 +0,0 @@ -#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 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() override; - - // 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 deleted file mode 100644 index 789d92d..0000000 --- a/src/Airmap/qt/dispatcher.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#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; -} - -airmap::qt::Dispatcher::Dispatcher(const std::shared_ptr& context) - : to_qt_{ToQt::create()}, context_{context} { -} - -void airmap::qt::Dispatcher::dispatch_to_qt(const std::function& task) { - to_qt_->dispatch(task); -} - -void airmap::qt::Dispatcher::dispatch_to_airmap(const std::function& task) { - context_->schedule_in(task); -} - -// From QObject diff --git a/src/Airmap/qt/dispatcher.h b/src/Airmap/qt/dispatcher.h deleted file mode 100644 index f57d3f9..0000000 --- a/src/Airmap/qt/dispatcher.h +++ /dev/null @@ -1,53 +0,0 @@ -#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; - }; - - explicit Dispatcher(const std::shared_ptr& context); - - void dispatch_to_qt(const Task& task); - void dispatch_to_airmap(const Task& task); - - private: - std::shared_ptr to_qt_; - std::shared_ptr context_; -}; - -} // 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 deleted file mode 100644 index 6f0a68a..0000000 --- a/src/Airmap/qt/flight_plans.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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 deleted file mode 100644 index 8e124f7..0000000 --- a/src/Airmap/qt/flight_plans.h +++ /dev/null @@ -1,36 +0,0 @@ -#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 deleted file mode 100644 index abdcc02..0000000 --- a/src/Airmap/qt/flights.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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 deleted file mode 100644 index c03d1e4..0000000 --- a/src/Airmap/qt/flights.h +++ /dev/null @@ -1,40 +0,0 @@ -#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 deleted file mode 100644 index b4c7678..0000000 --- a/src/Airmap/qt/logger.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#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 deleted file mode 100644 index 63ecaa5..0000000 --- a/src/Airmap/qt/logger.h +++ /dev/null @@ -1,57 +0,0 @@ -#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 deleted file mode 100644 index 1971f3d..0000000 --- a/src/Airmap/qt/pilots.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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 deleted file mode 100644 index 37c97ad..0000000 --- a/src/Airmap/qt/pilots.h +++ /dev/null @@ -1,41 +0,0 @@ -#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 deleted file mode 100644 index f08104d..0000000 --- a/src/Airmap/qt/rulesets.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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 deleted file mode 100644 index 613ec7f..0000000 --- a/src/Airmap/qt/rulesets.h +++ /dev/null @@ -1,31 +0,0 @@ -#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 deleted file mode 100644 index da2a58b..0000000 --- a/src/Airmap/qt/status.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#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_airmap([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_airmap([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_airmap([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 deleted file mode 100644 index 6b8138e..0000000 --- a/src/Airmap/qt/status.h +++ /dev/null @@ -1,32 +0,0 @@ -#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 deleted file mode 100644 index ca565c9..0000000 --- a/src/Airmap/qt/telemetry.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#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_airmap([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 deleted file mode 100644 index 13a5e9a..0000000 --- a/src/Airmap/qt/telemetry.h +++ /dev/null @@ -1,31 +0,0 @@ -#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 deleted file mode 100644 index 6281ef7..0000000 --- a/src/Airmap/qt/traffic.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#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_airmap([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 deleted file mode 100644 index e4fa980..0000000 --- a/src/Airmap/qt/traffic.h +++ /dev/null @@ -1,54 +0,0 @@ -#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 deleted file mode 100644 index 90e5f23..0000000 --- a/src/Airmap/qt/types.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#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 deleted file mode 100644 index 5fb3aef..0000000 --- a/src/Airmap/qt/types.h +++ /dev/null @@ -1,67 +0,0 @@ -#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_ diff --git a/src/Airmap/services/advisory.cpp b/src/Airmap/services/advisory.cpp new file mode 100644 index 0000000..f0d548f --- /dev/null +++ b/src/Airmap/services/advisory.cpp @@ -0,0 +1,36 @@ +#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_airmap([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_airmap([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_airmap([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/services/advisory.h b/src/Airmap/services/advisory.h new file mode 100644 index 0000000..82c64e9 --- /dev/null +++ b/src/Airmap/services/advisory.h @@ -0,0 +1,29 @@ +#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/services/aircrafts.cpp b/src/Airmap/services/aircrafts.cpp new file mode 100644 index 0000000..1b8bd2f --- /dev/null +++ b/src/Airmap/services/aircrafts.cpp @@ -0,0 +1,36 @@ +#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_airmap([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_airmap([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_airmap([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/services/aircrafts.h b/src/Airmap/services/aircrafts.h new file mode 100644 index 0000000..4bf8461 --- /dev/null +++ b/src/Airmap/services/aircrafts.h @@ -0,0 +1,32 @@ +#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/services/airspaces.cpp b/src/Airmap/services/airspaces.cpp new file mode 100644 index 0000000..3915913 --- /dev/null +++ b/src/Airmap/services/airspaces.cpp @@ -0,0 +1,27 @@ +#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_airmap([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_airmap([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/services/airspaces.h b/src/Airmap/services/airspaces.h new file mode 100644 index 0000000..619b0df --- /dev/null +++ b/src/Airmap/services/airspaces.h @@ -0,0 +1,31 @@ +#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/services/authenticator.cpp b/src/Airmap/services/authenticator.cpp new file mode 100644 index 0000000..c715e21 --- /dev/null +++ b/src/Airmap/services/authenticator.cpp @@ -0,0 +1,38 @@ +#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_airmap([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_airmap([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_airmap([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/services/authenticator.h b/src/Airmap/services/authenticator.h new file mode 100644 index 0000000..729cb63 --- /dev/null +++ b/src/Airmap/services/authenticator.h @@ -0,0 +1,37 @@ +#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/services/client.cpp b/src/Airmap/services/client.cpp new file mode 100644 index 0000000..c27814d --- /dev/null +++ b/src/Airmap/services/client.cpp @@ -0,0 +1,166 @@ +#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/services/client.h b/src/Airmap/services/client.h new file mode 100644 index 0000000..aec7b85 --- /dev/null +++ b/src/Airmap/services/client.h @@ -0,0 +1,65 @@ +#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 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() override; + + // 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/services/dispatcher.cpp b/src/Airmap/services/dispatcher.cpp new file mode 100644 index 0000000..789d92d --- /dev/null +++ b/src/Airmap/services/dispatcher.cpp @@ -0,0 +1,62 @@ +#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; +} + +airmap::qt::Dispatcher::Dispatcher(const std::shared_ptr& context) + : to_qt_{ToQt::create()}, context_{context} { +} + +void airmap::qt::Dispatcher::dispatch_to_qt(const std::function& task) { + to_qt_->dispatch(task); +} + +void airmap::qt::Dispatcher::dispatch_to_airmap(const std::function& task) { + context_->schedule_in(task); +} + +// From QObject diff --git a/src/Airmap/services/dispatcher.h b/src/Airmap/services/dispatcher.h new file mode 100644 index 0000000..f57d3f9 --- /dev/null +++ b/src/Airmap/services/dispatcher.h @@ -0,0 +1,53 @@ +#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; + }; + + explicit Dispatcher(const std::shared_ptr& context); + + void dispatch_to_qt(const Task& task); + void dispatch_to_airmap(const Task& task); + + private: + std::shared_ptr to_qt_; + std::shared_ptr context_; +}; + +} // namespace qt +} // namespace airmap + +#endif // AIRMAP_QT_DISPATCHER_H_ diff --git a/src/Airmap/services/flight_plans.cpp b/src/Airmap/services/flight_plans.cpp new file mode 100644 index 0000000..6f0a68a --- /dev/null +++ b/src/Airmap/services/flight_plans.cpp @@ -0,0 +1,60 @@ +#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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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/services/flight_plans.h b/src/Airmap/services/flight_plans.h new file mode 100644 index 0000000..8e124f7 --- /dev/null +++ b/src/Airmap/services/flight_plans.h @@ -0,0 +1,36 @@ +#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/services/flights.cpp b/src/Airmap/services/flights.cpp new file mode 100644 index 0000000..abdcc02 --- /dev/null +++ b/src/Airmap/services/flights.cpp @@ -0,0 +1,88 @@ +#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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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/services/flights.h b/src/Airmap/services/flights.h new file mode 100644 index 0000000..c03d1e4 --- /dev/null +++ b/src/Airmap/services/flights.h @@ -0,0 +1,40 @@ +#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/services/logger.cpp b/src/Airmap/services/logger.cpp new file mode 100644 index 0000000..b4c7678 --- /dev/null +++ b/src/Airmap/services/logger.cpp @@ -0,0 +1,78 @@ +#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/services/logger.h b/src/Airmap/services/logger.h new file mode 100644 index 0000000..63ecaa5 --- /dev/null +++ b/src/Airmap/services/logger.h @@ -0,0 +1,57 @@ +#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/services/pilots.cpp b/src/Airmap/services/pilots.cpp new file mode 100644 index 0000000..1971f3d --- /dev/null +++ b/src/Airmap/services/pilots.cpp @@ -0,0 +1,86 @@ +#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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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/services/pilots.h b/src/Airmap/services/pilots.h new file mode 100644 index 0000000..37c97ad --- /dev/null +++ b/src/Airmap/services/pilots.h @@ -0,0 +1,41 @@ +#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/services/rulesets.cpp b/src/Airmap/services/rulesets.cpp new file mode 100644 index 0000000..f08104d --- /dev/null +++ b/src/Airmap/services/rulesets.cpp @@ -0,0 +1,53 @@ +#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_airmap([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_airmap([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_airmap([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_airmap([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_airmap([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/services/rulesets.h b/src/Airmap/services/rulesets.h new file mode 100644 index 0000000..613ec7f --- /dev/null +++ b/src/Airmap/services/rulesets.h @@ -0,0 +1,31 @@ +#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/services/status.cpp b/src/Airmap/services/status.cpp new file mode 100644 index 0000000..da2a58b --- /dev/null +++ b/src/Airmap/services/status.cpp @@ -0,0 +1,34 @@ +#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_airmap([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_airmap([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_airmap([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/services/status.h b/src/Airmap/services/status.h new file mode 100644 index 0000000..6b8138e --- /dev/null +++ b/src/Airmap/services/status.h @@ -0,0 +1,32 @@ +#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/services/telemetry.cpp b/src/Airmap/services/telemetry.cpp new file mode 100644 index 0000000..ca565c9 --- /dev/null +++ b/src/Airmap/services/telemetry.cpp @@ -0,0 +1,20 @@ +#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_airmap([this, sp = shared_from_this(), flight, key, updates]() { + sp->client_->telemetry().submit_updates(flight, key, updates); + }); +} diff --git a/src/Airmap/services/telemetry.h b/src/Airmap/services/telemetry.h new file mode 100644 index 0000000..13a5e9a --- /dev/null +++ b/src/Airmap/services/telemetry.h @@ -0,0 +1,31 @@ +#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/services/traffic.cpp b/src/Airmap/services/traffic.cpp new file mode 100644 index 0000000..6281ef7 --- /dev/null +++ b/src/Airmap/services/traffic.cpp @@ -0,0 +1,52 @@ +#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_airmap([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/services/traffic.h b/src/Airmap/services/traffic.h new file mode 100644 index 0000000..e4fa980 --- /dev/null +++ b/src/Airmap/services/traffic.h @@ -0,0 +1,54 @@ +#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/services/types.cpp b/src/Airmap/services/types.cpp new file mode 100644 index 0000000..90e5f23 --- /dev/null +++ b/src/Airmap/services/types.cpp @@ -0,0 +1,79 @@ +#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/services/types.h b/src/Airmap/services/types.h new file mode 100644 index 0000000..5fb3aef --- /dev/null +++ b/src/Airmap/services/types.h @@ -0,0 +1,67 @@ +#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_