Commit 1703a30c authored by Gus Grubba's avatar Gus Grubba

c++ ownership and memory guards

parent d2964086
...@@ -118,6 +118,7 @@ QGCCameraControl::QGCCameraControl(const mavlink_camera_information_t *info, Veh ...@@ -118,6 +118,7 @@ QGCCameraControl::QGCCameraControl(const mavlink_camera_information_t *info, Veh
, _cameraMode(CAM_MODE_UNDEFINED) , _cameraMode(CAM_MODE_UNDEFINED)
, _video_status(VIDEO_CAPTURE_STATUS_UNDEFINED) , _video_status(VIDEO_CAPTURE_STATUS_UNDEFINED)
{ {
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
memcpy(&_info, info, sizeof(mavlink_camera_information_t)); memcpy(&_info, info, sizeof(mavlink_camera_information_t));
connect(this, &QGCCameraControl::dataReady, this, &QGCCameraControl::_dataReady); connect(this, &QGCCameraControl::dataReady, this, &QGCCameraControl::_dataReady);
_vendor = QString((const char*)(void*)&info->vendor_name[0]); _vendor = QString((const char*)(void*)&info->vendor_name[0]);
...@@ -533,6 +534,7 @@ QGCCameraControl::_loadSettings(const QDomNodeList nodeList) ...@@ -533,6 +534,7 @@ QGCCameraControl::_loadSettings(const QDomNodeList nodeList)
} }
//-- Build metadata //-- Build metadata
FactMetaData* metaData = new FactMetaData(factType, factName, this); FactMetaData* metaData = new FactMetaData(factType, factName, this);
QQmlEngine::setObjectOwnership(metaData, QQmlEngine::CppOwnership);
metaData->setShortDescription(description); metaData->setShortDescription(description);
metaData->setLongDescription(description); metaData->setLongDescription(description);
//-- Options (enums) //-- Options (enums)
...@@ -560,6 +562,7 @@ QGCCameraControl::_loadSettings(const QDomNodeList nodeList) ...@@ -560,6 +562,7 @@ QGCCameraControl::_loadSettings(const QDomNodeList nodeList)
if(exclusions.size()) { if(exclusions.size()) {
qCDebug(CameraControlLogVerbose) << "New exclusions:" << factName << optValue << exclusions; qCDebug(CameraControlLogVerbose) << "New exclusions:" << factName << optValue << exclusions;
QGCCameraOptionExclusion* pExc = new QGCCameraOptionExclusion(this, factName, optValue, exclusions); QGCCameraOptionExclusion* pExc = new QGCCameraOptionExclusion(this, factName, optValue, exclusions);
QQmlEngine::setObjectOwnership(pExc, QQmlEngine::CppOwnership);
_valueExclusions.append(pExc); _valueExclusions.append(pExc);
} }
//-- Check for range rules //-- Check for range rules
...@@ -589,9 +592,11 @@ QGCCameraControl::_loadSettings(const QDomNodeList nodeList) ...@@ -589,9 +592,11 @@ QGCCameraControl::_loadSettings(const QDomNodeList nodeList)
} else { } else {
_nameToFactMetaDataMap[factName] = metaData; _nameToFactMetaDataMap[factName] = metaData;
Fact* pFact = new Fact(_compID, factName, factType, this); Fact* pFact = new Fact(_compID, factName, factType, this);
QQmlEngine::setObjectOwnership(pFact, QQmlEngine::CppOwnership);
pFact->setMetaData(metaData); pFact->setMetaData(metaData);
pFact->_containerSetRawValue(metaData->rawDefaultValue()); pFact->_containerSetRawValue(metaData->rawDefaultValue());
QGCCameraParamIO* pIO = new QGCCameraParamIO(this, pFact, _vehicle); QGCCameraParamIO* pIO = new QGCCameraParamIO(this, pFact, _vehicle);
QQmlEngine::setObjectOwnership(pIO, QQmlEngine::CppOwnership);
_paramIO[factName] = pIO; _paramIO[factName] = pIO;
_addFact(pFact, factName); _addFact(pFact, factName);
} }
...@@ -695,8 +700,12 @@ void ...@@ -695,8 +700,12 @@ void
QGCCameraControl::_requestAllParameters() QGCCameraControl::_requestAllParameters()
{ {
//-- Reset receive list //-- Reset receive list
foreach(QString pramName, _paramIO.keys()) { foreach(QString paramName, _paramIO.keys()) {
_paramIO[pramName]->setParamRequest(); if(_paramIO[paramName]) {
_paramIO[paramName]->setParamRequest();
} else {
qCritical() << "QGCParamIO is NULL" << paramName;
}
} }
MAVLinkProtocol* mavlink = qgcApp()->toolbox()->mavlinkProtocol(); MAVLinkProtocol* mavlink = qgcApp()->toolbox()->mavlinkProtocol();
mavlink_message_t msg; mavlink_message_t msg;
...@@ -729,7 +738,11 @@ QGCCameraControl::handleParamAck(const mavlink_param_ext_ack_t& ack) ...@@ -729,7 +738,11 @@ QGCCameraControl::handleParamAck(const mavlink_param_ext_ack_t& ack)
qCWarning(CameraControlLog) << "Received PARAM_EXT_ACK for unknown param:" << paramName; qCWarning(CameraControlLog) << "Received PARAM_EXT_ACK for unknown param:" << paramName;
return; return;
} }
_paramIO[paramName]->handleParamAck(ack); if(_paramIO[paramName]) {
_paramIO[paramName]->handleParamAck(ack);
} else {
qCritical() << "QGCParamIO is NULL" << paramName;
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -741,7 +754,11 @@ QGCCameraControl::handleParamValue(const mavlink_param_ext_value_t& value) ...@@ -741,7 +754,11 @@ QGCCameraControl::handleParamValue(const mavlink_param_ext_value_t& value)
qCWarning(CameraControlLog) << "Received PARAM_EXT_VALUE for unknown param:" << paramName; qCWarning(CameraControlLog) << "Received PARAM_EXT_VALUE for unknown param:" << paramName;
return; return;
} }
_paramIO[paramName]->handleParamValue(value); if(_paramIO[paramName]) {
_paramIO[paramName]->handleParamValue(value);
} else {
qCritical() << "QGCParamIO is NULL" << paramName;
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
......
...@@ -21,6 +21,7 @@ QGCCameraParamIO::QGCCameraParamIO(QGCCameraControl *control, Fact* fact, Vehicl ...@@ -21,6 +21,7 @@ QGCCameraParamIO::QGCCameraParamIO(QGCCameraControl *control, Fact* fact, Vehicl
, _requestRetries(0) , _requestRetries(0)
, _done(false) , _done(false)
{ {
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
_paramWriteTimer.setSingleShot(true); _paramWriteTimer.setSingleShot(true);
_paramWriteTimer.setInterval(1000); _paramWriteTimer.setInterval(1000);
_paramRequestTimer.setSingleShot(true); _paramRequestTimer.setSingleShot(true);
...@@ -94,10 +95,10 @@ void ...@@ -94,10 +95,10 @@ void
QGCCameraParamIO::_sendParameter() QGCCameraParamIO::_sendParameter()
{ {
//-- TODO: We should use something other than mavlink_param_union_t for PARAM_EXT_SET //-- TODO: We should use something other than mavlink_param_union_t for PARAM_EXT_SET
mavlink_param_ext_set_t p; mavlink_param_ext_set_t p;
memset(&p, 0, sizeof(mavlink_param_ext_set_t));
mavlink_param_union_t union_value; mavlink_param_union_t union_value;
mavlink_message_t msg; mavlink_message_t msg;
memset(&p, 0, sizeof(mavlink_param_ext_set_t));
FactMetaData::ValueType_t factType = _fact->type(); FactMetaData::ValueType_t factType = _fact->type();
p.param_type = _mavParamType; p.param_type = _mavParamType;
switch (factType) { switch (factType) {
...@@ -247,6 +248,9 @@ QGCCameraParamIO::_paramRequestTimeout() ...@@ -247,6 +248,9 @@ QGCCameraParamIO::_paramRequestTimeout()
} else { } else {
//-- Request it again //-- Request it again
qCDebug(CameraIOLog) << "Param request retry:" << _fact->name(); qCDebug(CameraIOLog) << "Param request retry:" << _fact->name();
char param_id[MAVLINK_MSG_PARAM_EXT_REQUEST_READ_FIELD_PARAM_ID_LEN + 1];
memset(param_id, 0, sizeof(param_id));
strncpy(param_id, _fact->name().toStdString().c_str(), MAVLINK_MSG_PARAM_EXT_REQUEST_READ_FIELD_PARAM_ID_LEN);
mavlink_message_t msg; mavlink_message_t msg;
mavlink_msg_param_ext_request_read_pack_chan( mavlink_msg_param_ext_request_read_pack_chan(
_pMavlink->getSystemId(), _pMavlink->getSystemId(),
...@@ -255,7 +259,7 @@ QGCCameraParamIO::_paramRequestTimeout() ...@@ -255,7 +259,7 @@ QGCCameraParamIO::_paramRequestTimeout()
&msg, &msg,
_vehicle->id(), _vehicle->id(),
_control->compID(), _control->compID(),
_fact->name().toStdString().c_str(), param_id,
-1); -1);
_vehicle->sendMessageOnLink(_vehicle->priorityLink(), msg); _vehicle->sendMessageOnLink(_vehicle->priorityLink(), msg);
_paramRequestTimer.start(); _paramRequestTimer.start();
......
...@@ -16,6 +16,7 @@ QGCCameraManager::QGCCameraManager(Vehicle *vehicle) ...@@ -16,6 +16,7 @@ QGCCameraManager::QGCCameraManager(Vehicle *vehicle)
, _vehicleReadyState(false) , _vehicleReadyState(false)
, _currentTask(0) , _currentTask(0)
{ {
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
qCDebug(CameraManagerLog) << "QGCCameraManager Created"; qCDebug(CameraManagerLog) << "QGCCameraManager Created";
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::parameterReadyVehicleAvailableChanged, this, &QGCCameraManager::_vehicleReady); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::parameterReadyVehicleAvailableChanged, this, &QGCCameraManager::_vehicleReady);
connect(_vehicle, &Vehicle::mavlinkMessageReceived, this, &QGCCameraManager::_mavlinkMessageReceived); connect(_vehicle, &Vehicle::mavlinkMessageReceived, this, &QGCCameraManager::_mavlinkMessageReceived);
...@@ -121,6 +122,7 @@ QGCCameraManager::_handleCameraInfo(const mavlink_message_t& message) ...@@ -121,6 +122,7 @@ QGCCameraManager::_handleCameraInfo(const mavlink_message_t& message)
qCDebug(CameraManagerLog) << "_handleCameraInfo:" << (const char*)(void*)&info.model_name[0] << (const char*)(void*)&info.vendor_name[0]; qCDebug(CameraManagerLog) << "_handleCameraInfo:" << (const char*)(void*)&info.model_name[0] << (const char*)(void*)&info.vendor_name[0];
QGCCameraControl* pCamera = _vehicle->firmwarePlugin()->createCameraControl(&info, _vehicle, message.compid, this); QGCCameraControl* pCamera = _vehicle->firmwarePlugin()->createCameraControl(&info, _vehicle, message.compid, this);
if(pCamera) { if(pCamera) {
QQmlEngine::setObjectOwnership(pCamera, QQmlEngine::CppOwnership);
_cameras.append(pCamera); _cameras.append(pCamera);
emit camerasChanged(); emit camerasChanged();
} }
......
...@@ -31,7 +31,7 @@ Fact::Fact(QObject* parent) ...@@ -31,7 +31,7 @@ Fact::Fact(QObject* parent)
FactMetaData* metaData = new FactMetaData(_type, this); FactMetaData* metaData = new FactMetaData(_type, this);
setMetaData(metaData); setMetaData(metaData);
// Better sage than sorry on object ownership // Better safe than sorry on object ownership
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
} }
......
...@@ -139,9 +139,9 @@ UAS::UAS(MAVLinkProtocol* protocol, Vehicle* vehicle, FirmwarePluginManager * fi ...@@ -139,9 +139,9 @@ UAS::UAS(MAVLinkProtocol* protocol, Vehicle* vehicle, FirmwarePluginManager * fi
#ifndef __mobile__ #ifndef __mobile__
connect(_vehicle, &Vehicle::mavlinkMessageReceived, &fileManager, &FileManager::receiveMessage); connect(_vehicle, &Vehicle::mavlinkMessageReceived, &fileManager, &FileManager::receiveMessage);
color = UASInterface::getNextColor();
#endif #endif
color = UASInterface::getNextColor();
} }
/** /**
......
...@@ -61,6 +61,7 @@ public: ...@@ -61,6 +61,7 @@ public:
* @return The next color in the color map. The map holds 20 colors and starts from the beginning * @return The next color in the color map. The map holds 20 colors and starts from the beginning
* if the colors are exceeded. * if the colors are exceeded.
*/ */
#if !defined(__mobile__)
static QColor getNextColor() { static QColor getNextColor() {
/* Create color map */ /* Create color map */
static QList<QColor> colors = QList<QColor>() static QList<QColor> colors = QList<QColor>()
...@@ -91,6 +92,7 @@ public: ...@@ -91,6 +92,7 @@ public:
nextColor++; nextColor++;
return colors[nextColor];//return the next color return colors[nextColor];//return the next color
} }
#endif
virtual QMap<int, QString> getComponents() = 0; virtual QMap<int, QString> getComponents() = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment