ComponentInformationManager.h 3.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/****************************************************************************
 *
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

#include "QGCLoggingCategory.h"
#include "QGCMAVLink.h"
#include "StateMachine.h"

Q_DECLARE_LOGGING_CATEGORY(ComponentInformationManagerLog)

class Vehicle;
class ComponentInformationManager;
20 21 22
class CompInfo;
class CompInfoParam;
class CompInfoVersion;
23

24 25
class RequestMetaDataTypeStateMachine : public StateMachine
{
26 27
    Q_OBJECT

28 29 30
public:
    RequestMetaDataTypeStateMachine(ComponentInformationManager* compMgr);

31 32 33
    void        request     (CompInfo* compInfo);
    QString     typeToString(void);
    CompInfo*   compInfo    (void) { return _compInfo; }
34 35 36 37 38 39

    // Overrides from StateMachine
    int             stateCount      (void) const final;
    const StateFn*  rgStates        (void) const final;
    void            statesCompleted (void) const final;

40
private slots:
41 42 43 44 45
    void    _ftpDownloadCompleteMetaDataJson    (const QString& file, const QString& errorMsg);
    void    _ftpDownloadCompleteTranslationJson (const QString& file, const QString& errorMsg);
    void    _httpDownloadCompleteMetaDataJson   (QString remoteFile, QString localFile, QString errorMsg);
    void    _httpDownloadCompleteTranslationJson(QString remoteFile, QString localFile, QString errorMsg);
    QString _downloadCompleteJsonWorker         (const QString& jsonFileName, const QString& inflatedFileName);
46

47 48 49 50
private:
    static void _stateRequestCompInfo           (StateMachine* stateMachine);
    static void _stateRequestMetaDataJson       (StateMachine* stateMachine);
    static void _stateRequestTranslationJson    (StateMachine* stateMachine);
51
    static void _stateRequestComplete           (StateMachine* stateMachine);
52 53
    static bool _uriIsFTP                       (const QString& uri);

54

55 56
    ComponentInformationManager*    _compMgr                    = nullptr;
    CompInfo*                       _compInfo                   = nullptr;
57 58
    QString                         _jsonMetadataFileName;
    QString                         _jsonTranslationFileName;
59

60 61
    static StateFn  _rgStates[];
    static int      _cStates;
62 63 64 65
};

class ComponentInformationManager : public StateMachine
{
66 67
    Q_OBJECT

68 69 70 71 72
public:
    ComponentInformationManager(Vehicle* vehicle);

    typedef void (*RequestAllCompleteFn)(void* requestAllCompleteFnData);

73 74 75 76
    void                requestAllComponentInformation  (RequestAllCompleteFn requestAllCompletFn, void * requestAllCompleteFnData);
    Vehicle*            vehicle                         (void) { return _vehicle; }
    CompInfoParam*      compInfoParam                   (uint8_t compId);
    CompInfoVersion*    compInfoVersion                 (uint8_t compId);
77 78 79 80 81 82

    // Overrides from StateMachine
    int             stateCount  (void) const final;
    const StateFn*  rgStates    (void) const final;

private:
83 84
    void _stateRequestCompInfoComplete  (void);
    bool _isCompTypeSupported           (COMP_METADATA_TYPE type);
85

86 87 88 89 90 91 92 93 94
    static void _stateRequestCompInfoVersion        (StateMachine* stateMachine);
    static void _stateRequestCompInfoParam          (StateMachine* stateMachine);
    static void _stateRequestAllCompInfoComplete    (StateMachine* stateMachine);

    Vehicle*                        _vehicle                    = nullptr;
    RequestMetaDataTypeStateMachine _requestTypeStateMachine;
    RequestAllCompleteFn            _requestAllCompleteFn       = nullptr;
    void*                           _requestAllCompleteFnData   = nullptr;

95 96
    QMap<uint8_t /* compId */, QMap<COMP_METADATA_TYPE, CompInfo*>> _compInfoMap;

97 98
    static StateFn                  _rgStates[];
    static int                      _cStates;
99 100

    friend class RequestMetaDataTypeStateMachine;
101
};