12#include <QtCore/QStandardPaths>
14QGC_LOGGING_CATEGORY(ComponentInformationManagerLog,
"ComponentInformation.ComponentInformationManager")
18 , _requestTypeStateMachine(this, this)
19 , _cachedFileDownload(new
QGCCachedFileDownload(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/QGCCompInfoFileDownloadCache"), this))
23 qCDebug(ComponentInformationManagerLog) <<
this;
24 qCDebug(ComponentInformationManagerLog) <<
"Cache location:" << QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String(
"/QGCCompInfoCache");
26 _compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_GENERAL] =
new CompInfoGeneral (MAV_COMP_ID_AUTOPILOT1, vehicle,
this);
27 _compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_PARAMETER] =
new CompInfoParam (MAV_COMP_ID_AUTOPILOT1, vehicle,
this);
28 _compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_EVENTS] =
new CompInfoEvents (MAV_COMP_ID_AUTOPILOT1, vehicle,
this);
29 _compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_ACTUATORS] =
new CompInfoActuators (MAV_COMP_ID_AUTOPILOT1, vehicle,
this);
33 _wireProgressTracking();
35 setInitialState(_stateRequestGeneral);
40 qCDebug(ComponentInformationManagerLog) <<
this;
43void ComponentInformationManager::_createStates()
47 QStringLiteral(
"RequestGeneral"),
51 registerState(_stateRequestGeneral);
54 _stateUpdateUri = addFunctionState(
55 QStringLiteral(
"UpdateUri"),
56 [
this]() { _updateAllUri(); }
61 QStringLiteral(
"RequestParam"),
63 [
this]() {
return !_isCompTypeSupported(COMP_METADATA_TYPE_PARAMETER); },
66 qCDebug(ComponentInformationManagerLog) <<
"Skipping parameter metadata, not supported";
69 registerState(_stateRequestParam);
73 QStringLiteral(
"RequestEvents"),
75 [
this]() {
return !_isCompTypeSupported(COMP_METADATA_TYPE_EVENTS); },
78 qCDebug(ComponentInformationManagerLog) <<
"Skipping events metadata, not supported";
81 registerState(_stateRequestEvents);
85 QStringLiteral(
"RequestActuators"),
87 [
this]() {
return !_isCompTypeSupported(COMP_METADATA_TYPE_ACTUATORS); },
90 qCDebug(ComponentInformationManagerLog) <<
"Skipping actuators metadata, not supported";
93 registerState(_stateRequestActuators);
96 _stateComplete = addFunctionState(
97 QStringLiteral(
"Complete"),
98 [
this]() { _signalComplete(); }
102 _stateFinal = addFinalState(QStringLiteral(
"Final"));
105void ComponentInformationManager::_wireTransitions()
129void ComponentInformationManager::_wireProgressTracking()
132 _currentStateIndex = 0;
137 _currentStateIndex = 1;
141 _stateRequestParam->setOnEntry([
this]() {
142 _currentStateIndex = 2;
147 _currentStateIndex = 3;
152 _currentStateIndex = 4;
157 _currentStateIndex = 5;
162void ComponentInformationManager::_updateProgress()
172 return static_cast<float>(_currentStateIndex) /
static_cast<float>(_stateCount);
177 qCDebug(ComponentInformationManagerLog) << Q_FUNC_INFO;
179 _requestAllCompleteFn = requestAllCompletFn;
180 _requestAllCompleteFnData = requestAllCompleteFnData;
194 qCDebug(ComponentInformationManagerLog) << Q_FUNC_INFO;
199 _requestTypeStateMachine.
request(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_GENERAL]);
202void ComponentInformationManager::_updateAllUri()
204 qCDebug(ComponentInformationManagerLog) << Q_FUNC_INFO;
206 CompInfoGeneral* general = qobject_cast<CompInfoGeneral*>(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_GENERAL]);
207 for (
auto& compInfo : _compInfoMap[MAV_COMP_ID_AUTOPILOT1]) {
214 qCDebug(ComponentInformationManagerLog) << Q_FUNC_INFO;
217 _requestTypeStateMachine.
request(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_PARAMETER]);
222 qCDebug(ComponentInformationManagerLog) << Q_FUNC_INFO;
225 _requestTypeStateMachine.
request(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_EVENTS]);
230 qCDebug(ComponentInformationManagerLog) << Q_FUNC_INFO;
233 _requestTypeStateMachine.
request(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_ACTUATORS]);
236void ComponentInformationManager::_signalComplete()
238 qCDebug(ComponentInformationManagerLog) << Q_FUNC_INFO;
240 if (_requestAllCompleteFn) {
241 (*_requestAllCompleteFn)(_requestAllCompleteFnData);
242 _requestAllCompleteFn =
nullptr;
243 _requestAllCompleteFnData =
nullptr;
247bool ComponentInformationManager::_isCompTypeSupported(COMP_METADATA_TYPE type)
const
249 CompInfoGeneral* general = qobject_cast<CompInfoGeneral*>(_compInfoMap[MAV_COMP_ID_AUTOPILOT1][COMP_METADATA_TYPE_GENERAL]);
255 if (!_compInfoMap.contains(compId)) {
257 _compInfoMap[compId][COMP_METADATA_TYPE_PARAMETER] =
new CompInfoParam(compId, vehicle(),
this);
259 return qobject_cast<CompInfoParam*>(_compInfoMap[compId][COMP_METADATA_TYPE_PARAMETER]);
264 return _compInfoMap.contains(compId) && _compInfoMap[compId].contains(COMP_METADATA_TYPE_GENERAL) ? qobject_cast<CompInfoGeneral*>(_compInfoMap[compId][COMP_METADATA_TYPE_GENERAL]) :
nullptr;
267QString ComponentInformationManager::_getFileCacheTag(
int compInfoType, uint32_t crc,
bool isTranslation)
269 return QString::asprintf(
"%08x_%02i_%i", crc, compInfoType, (
int)isTranslation);
Cached file download with time-based expiration and fallback support.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void connectToCompletion(typename QtPrivate::FunctionPointer< Func >::Object *sender, Func signal)
bool isMetaDataTypeSupported(COMP_METADATA_TYPE metadataType)
void setUris(CompInfo &compInfo) const
void setOnEntry(EntryCallback callback)
Set a callback to be invoked when the state is entered.
QGroundControl specific state machine with enhanced error handling.
void start()
Start the state machine with debug logging.
void connectToCompletion(typename QtPrivate::FunctionPointer< Func >::Object *sender, Func signal)
void skipped()
Emitted when skip predicate returns true and the state is skipped.