AirMapManager.h 2.32 KB
Newer Older
1 2
/****************************************************************************
 *
3
 *   (c) 2017 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10
#pragma once
11 12 13

#include "QGCToolbox.h"
#include "QGCLoggingCategory.h"
14
#include "AirspaceManagement.h"
15

16 17
#include <airmap/qt/logger.h>
#include <airmap/qt/types.h>
18

19
Q_DECLARE_LOGGING_CATEGORY(AirMapManagerLog)
20

21 22 23
class AirMapSharedState;

//-----------------------------------------------------------------------------
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/**
 * @class LifetimeChecker
 * Base class which helps to check if an object instance still exists.
 * A subclass can take a weak pointer from _instance and then check if the object was deleted.
 * This is used in callbacks that access 'this', but the instance might already be deleted (e.g. vehicle disconnect).
 */
class LifetimeChecker
{
public:
    LifetimeChecker() : _instance(this, [](void*){}) { }
    virtual ~LifetimeChecker() = default;

protected:
    std::shared_ptr<LifetimeChecker> _instance;
};

40
//-----------------------------------------------------------------------------
41
/**
42 43
 * @class AirMapManager
 * AirMap implementation of AirspaceManager
44
 */
45

46 47 48 49 50 51
class AirMapManager : public AirspaceManager
{
    Q_OBJECT
    
public:
    AirMapManager(QGCApplication* app, QGCToolbox* toolbox);
52
    virtual ~AirMapManager();
53

54
    void setToolbox (QGCToolbox* toolbox) override;
55

56 57 58 59
    AirspaceVehicleManager*         instantiateVehicle                      (const Vehicle& vehicle) override;
    AirspaceRestrictionProvider*    instantiateRestrictionProvider          () override;
    AirspaceRulesetsProvider*       instantiateRulesetsProvider             () override;
    AirspaceWeatherInfoProvider*    instatiateAirspaceWeatherInfoProvider   () override;
60

61
    QString name            () const override { return "AirMap"; }
62

63
private slots:
64 65
    void _error             (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);
    void _settingsChanged   ();
66 67

private:
68 69 70
    AirMapSharedState                               _shared;
    std::shared_ptr<airmap::qt::Logger>             _logger;
    std::shared_ptr<airmap::qt::DispatchingLogger>  _dispatchingLogger;
71 72
};

73