Commit 3433b541 authored by Don Gagne's avatar Don Gagne
Browse files

Remove as many Singletons as possible

Instead us a Toolbox concept which hangs off of QGCApplication
parent ec1e8c2f
......@@ -24,12 +24,13 @@
#include "ViewWidgetController.h"
#include "MultiVehicleManager.h"
#include "UAS.h"
#include "QGCApplication.h"
ViewWidgetController::ViewWidgetController(void) :
_autopilot(NULL),
_uas(NULL)
{
connect(MultiVehicleManager::instance(), &MultiVehicleManager::parameterReadyVehicleAvailableChanged, this, &ViewWidgetController::_vehicleAvailable);
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::parameterReadyVehicleAvailableChanged, this, &ViewWidgetController::_vehicleAvailable);
}
void ViewWidgetController::_vehicleAvailable(bool available)
......@@ -41,7 +42,7 @@ void ViewWidgetController::_vehicleAvailable(bool available)
}
if (available) {
Vehicle* vehicle = MultiVehicleManager::instance()->activeVehicle();
Vehicle* vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
_uas = vehicle->uas();
_autopilot = vehicle->autopilotPlugin();
......@@ -51,5 +52,5 @@ void ViewWidgetController::_vehicleAvailable(bool available)
}
Q_INVOKABLE void ViewWidgetController::checkForVehicle(void)
{
_vehicleAvailable(MultiVehicleManager::instance()->activeVehicle());
_vehicleAvailable(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
}
......@@ -46,27 +46,20 @@ This file is part of the QGROUNDCONTROL project
#include "QGCMessageBox.h"
#include "QGCApplication.h"
#include "SerialPortIds.h"
#include "QGCApplication.h"
IMPLEMENT_QGC_SINGLETON(LinkManager, LinkManager)
QGC_LOGGING_CATEGORY(LinkManagerLog, "LinkManagerLog")
/**
* @brief Private singleton constructor
*
* This class implements the singleton design pattern and has therefore only a private constructor.
**/
LinkManager::LinkManager(QObject* parent)
: QGCSingleton(parent)
LinkManager::LinkManager(QGCApplication* app)
: QGCTool(app)
, _configUpdateSuspended(false)
, _configurationsLoaded(false)
, _connectionsSuspended(false)
, _mavlinkChannelsUsedBitMask(0)
, _nullSharedLink(NULL)
, _mavlinkProtocol(NULL)
{
#ifndef __ios__
connect(&_portListTimer, &QTimer::timeout, this, &LinkManager::_updateConfigurationList);
_portListTimer.start(1000);
#endif
}
LinkManager::~LinkManager()
......@@ -80,6 +73,18 @@ LinkManager::~LinkManager()
Q_ASSERT_X(_links.count() == 0, "LinkManager", "LinkManager::_shutdown should have been called previously");
}
void LinkManager::setToolbox(QGCToolbox *toolbox)
{
QGCTool::setToolbox(toolbox);
_mavlinkProtocol = _toolbox->mavlinkProtocol();
#ifndef __ios__
connect(&_portListTimer, &QTimer::timeout, this, &LinkManager::_updateConfigurationList);
_portListTimer.start(1000);
#endif
}
LinkInterface* LinkManager::createConnectedLink(LinkConfiguration* config)
{
Q_ASSERT(config);
......@@ -149,16 +154,15 @@ void LinkManager::_addLink(LinkInterface* link)
// MainWindow may be around when doing things like running unit tests
if (MainWindow::instance()) {
connect(link, &LinkInterface::communicationError, qgcApp(), &QGCApplication::criticalMessageBoxOnMainThread);
connect(link, &LinkInterface::communicationError, _app, &QGCApplication::criticalMessageBoxOnMainThread);
}
MAVLinkProtocol* mavlink = MAVLinkProtocol::instance();
connect(link, &LinkInterface::bytesReceived, mavlink, &MAVLinkProtocol::receiveBytes);
connect(link, &LinkInterface::connected, mavlink, &MAVLinkProtocol::linkConnected);
connect(link, &LinkInterface::disconnected, mavlink, &MAVLinkProtocol::linkDisconnected);
mavlink->resetMetadataForLink(link);
connect(link, &LinkInterface::bytesReceived, _mavlinkProtocol, &MAVLinkProtocol::receiveBytes);
connect(link, &LinkInterface::connected, _mavlinkProtocol, &MAVLinkProtocol::linkConnected);
connect(link, &LinkInterface::disconnected, _mavlinkProtocol, &MAVLinkProtocol::linkDisconnected);
_mavlinkProtocol->resetMetadataForLink(link);
connect(link, &LinkInterface::connected, this, &LinkManager::_linkConnected);
connect(link, &LinkInterface::connected, this, &LinkManager::_linkConnected);
connect(link, &LinkInterface::disconnected, this, &LinkManager::_linkDisconnected);
}
......
......@@ -34,6 +34,7 @@ This file is part of the PIXHAWK project
#include "LinkConfiguration.h"
#include "LinkInterface.h"
#include "QGCLoggingCategory.h"
#include "QGCToolbox.h"
// Links
#ifndef __ios__
......@@ -48,12 +49,11 @@ This file is part of the PIXHAWK project
#endif
#include "ProtocolInterface.h"
#include "QGCSingleton.h"
#include "MAVLinkProtocol.h"
Q_DECLARE_LOGGING_CATEGORY(LinkManagerLog)
class LinkManagerTest;
class QGCApplication;
/// Manage communication links
///
......@@ -61,16 +61,16 @@ class LinkManagerTest;
/// links and takes care of connecting them as well assigning the correct
/// protocol instance to transport the link data into the application.
class LinkManager : public QGCSingleton
class LinkManager : public QGCTool
{
Q_OBJECT
DECLARE_QGC_SINGLETON(LinkManager, LinkManager)
/// Unit Test has access to private constructor/destructor
friend class LinkManagerTest;
public:
LinkManager(QGCApplication* app);
~LinkManager();
/*!
Add a new link configuration setting to the list
......@@ -144,6 +144,9 @@ public:
void _deleteLink(LinkInterface* link);
void _addLink(LinkInterface* link);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
signals:
void newLink(LinkInterface* link);
void linkDeleted(LinkInterface* link);
......@@ -156,10 +159,6 @@ private slots:
void _linkDisconnected(void);
private:
/// All access to LinkManager is through LinkManager::instance
LinkManager(QObject* parent = NULL);
~LinkManager();
virtual void _shutdown(void);
bool _connectionsSuspendedMsg(void);
......@@ -186,6 +185,8 @@ private:
uint32_t _mavlinkChannelsUsedBitMask;
SharedLinkInterface _nullSharedLink;
MAVLinkProtocol* _mavlinkProtocol;
};
#endif
......@@ -23,6 +23,7 @@
#include "LogReplayLink.h"
#include "LinkManager.h"
#include "QGCApplication.h"
#include <QFileInfo>
#include <QtEndian>
......@@ -101,7 +102,7 @@ LogReplayLink::~LogReplayLink(void)
bool LogReplayLink::_connect(void)
{
// Disallow replay when any links are connected
if (LinkManager::instance()->anyConnectedLinks()) {
if (qgcApp()->toolbox()->linkManager()->anyConnectedLinks()) {
emit communicationError(_errorTitle, "You must close all connections prior to replaying a log.");
return false;
}
......@@ -366,9 +367,9 @@ void LogReplayLink::_readNextLogEntry(void)
void LogReplayLink::_play(void)
{
// FIXME: With move to link I don't think this is needed any more? Except for the replay widget handling multi-uas?
LinkManager::instance()->setConnectionsSuspended(tr("Connect not allowed during Flight Data replay."));
qgcApp()->toolbox()->linkManager()->setConnectionsSuspended(tr("Connect not allowed during Flight Data replay."));
#ifndef __mobile__
MAVLinkProtocol::instance()->suspendLogForReplay(true);
qgcApp()->toolbox()->mavlinkProtocol()->suspendLogForReplay(true);
#endif
// Make sure we aren't at the end of the file, if we are, reset to the beginning and play from there.
......@@ -398,9 +399,9 @@ void LogReplayLink::_play(void)
void LogReplayLink::_pause(void)
{
LinkManager::instance()->setConnectionsAllowed();
qgcApp()->toolbox()->linkManager()->setConnectionsAllowed();
#ifndef __mobile__
MAVLinkProtocol::instance()->suspendLogForReplay(false);
qgcApp()->toolbox()->mavlinkProtocol()->suspendLogForReplay(false);
#endif
_readTickTimer.stop();
......
......@@ -30,7 +30,7 @@
#include "MultiVehicleManager.h"
Q_DECLARE_METATYPE(mavlink_message_t)
IMPLEMENT_QGC_SINGLETON(MAVLinkProtocol, MAVLinkProtocol)
QGC_LOGGING_CATEGORY(MAVLinkProtocolLog, "MAVLinkProtocolLog")
#ifndef __mobile__
......@@ -42,53 +42,30 @@ const char* MAVLinkProtocol::_logFileExtension = "mavlink"; ///< Ext
* The default constructor will create a new MAVLink object sending heartbeats at
* the MAVLINK_HEARTBEAT_DEFAULT_RATE to all connected links.
*/
MAVLinkProtocol::MAVLinkProtocol(QObject* parent) :
QGCSingleton(parent),
m_multiplexingEnabled(false),
m_authEnabled(false),
m_enable_version_check(true),
m_paramRetransmissionTimeout(350),
m_paramRewriteTimeout(500),
m_paramGuardEnabled(true),
m_actionGuardEnabled(false),
m_actionRetransmissionTimeout(100),
versionMismatchIgnore(false),
systemId(QGC::defaultSystemId),
MAVLinkProtocol::MAVLinkProtocol(QGCApplication* app)
: QGCTool(app)
, m_multiplexingEnabled(false)
, m_authEnabled(false)
, m_enable_version_check(true)
, m_paramRetransmissionTimeout(350)
, m_paramRewriteTimeout(500)
, m_paramGuardEnabled(true)
, m_actionGuardEnabled(false)
, m_actionRetransmissionTimeout(100)
, versionMismatchIgnore(false)
, systemId(QGC::defaultSystemId)
#ifndef __mobile__
_logSuspendError(false),
_logSuspendReplay(false),
_logWasArmed(false),
_tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)),
, _logSuspendError(false)
, _logSuspendReplay(false)
, _logWasArmed(false)
, _tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension))
#endif
_linkMgr(LinkManager::instance()),
_heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE),
_heartbeatsEnabled(true)
, _heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE)
, _heartbeatsEnabled(true)
, _linkMgr(NULL)
, _multiVehicleManager(NULL)
{
qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
m_authKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
loadSettings();
// All the *Counter variables are not initialized here, as they should be initialized
// on a per-link basis before those links are used. @see resetMetadataForLink().
// Initialize the list for tracking dropped messages to invalid.
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < 256; j++)
{
lastIndex[i][j] = -1;
}
}
// Start heartbeat timer, emitting a heartbeat at the configured rate
connect(&_heartbeatTimer, &QTimer::timeout, this, &MAVLinkProtocol::sendHeartbeat);
_heartbeatTimer.start(1000/_heartbeatRate);
connect(this, &MAVLinkProtocol::protocolStatusMessage, qgcApp(), &QGCApplication::criticalMessageBoxOnMainThread);
connect(this, &MAVLinkProtocol::saveTempFlightDataLog, qgcApp(), &QGCApplication::saveTempFlightDataLogOnMainThread);
emit versionCheckChanged(m_enable_version_check);
}
MAVLinkProtocol::~MAVLinkProtocol()
......@@ -100,6 +77,40 @@ MAVLinkProtocol::~MAVLinkProtocol()
#endif
}
void MAVLinkProtocol::setToolbox(QGCToolbox *toolbox)
{
QGCTool::setToolbox(toolbox);
_linkMgr = _toolbox->linkManager();
_multiVehicleManager = _toolbox->multiVehicleManager();
qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
m_authKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
loadSettings();
// All the *Counter variables are not initialized here, as they should be initialized
// on a per-link basis before those links are used. @see resetMetadataForLink().
// Initialize the list for tracking dropped messages to invalid.
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < 256; j++)
{
lastIndex[i][j] = -1;
}
}
// Start heartbeat timer, emitting a heartbeat at the configured rate
connect(&_heartbeatTimer, &QTimer::timeout, this, &MAVLinkProtocol::sendHeartbeat);
_heartbeatTimer.start(1000/_heartbeatRate);
connect(this, &MAVLinkProtocol::protocolStatusMessage, _app, &QGCApplication::criticalMessageBoxOnMainThread);
connect(this, &MAVLinkProtocol::saveTempFlightDataLog, _app, &QGCApplication::saveTempFlightDataLogOnMainThread);
emit versionCheckChanged(m_enable_version_check);
}
void MAVLinkProtocol::loadSettings()
{
// Load defaults from settings
......@@ -185,7 +196,7 @@ void MAVLinkProtocol::_linkStatusChanged(LinkInterface* link, bool connected)
}
// Use the same shared pointer as LinkManager
_connectedLinks.append(LinkManager::instance()->sharedPointerForLink(link));
_connectedLinks.append(_linkMgr->sharedPointerForLink(link));
#ifndef __mobile__
if (_connectedLinks.count() == 1) {
......@@ -235,7 +246,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
// Since receiveBytes signals cross threads we can end up with signals in the queue
// that come through after the link is disconnected. For these we just drop the data
// since the link is closed.
if (!LinkManager::instance()->containsLink(link)) {
if (!_linkMgr->containsLink(link)) {
return;
}
......@@ -356,7 +367,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
// Notify the vehicle manager of the heartbeat. This will create/update vehicles as needed.
mavlink_heartbeat_t heartbeat;
mavlink_msg_heartbeat_decode(&message, &heartbeat);
if (!MultiVehicleManager::instance()->notifyHeartbeatInfo(link, message.sysid, heartbeat)) {
if (!_multiVehicleManager->notifyHeartbeatInfo(link, message.sysid, heartbeat)) {
continue;
}
}
......@@ -667,7 +678,7 @@ void MAVLinkProtocol::_stopLogging(void)
{
if (_closeLogFile()) {
// If the signals are not connected it means we are running a unit test. In that case just delete log files
if (_logWasArmed && qgcApp()->promptFlightDataSave()) {
if (_logWasArmed && _app->promptFlightDataSave()) {
emit saveTempFlightDataLog(_tempLogFile.fileName());
} else {
QFile::remove(_tempLogFile.fileName());
......
......@@ -43,9 +43,11 @@ This file is part of the QGROUNDCONTROL project
#include "QGCMAVLink.h"
#include "QGC.h"
#include "QGCTemporaryFile.h"
#include "QGCSingleton.h"
#include "QGCToolbox.h"
class LinkManager;
class MultiVehicleManager;
class QGCApplication;
Q_DECLARE_LOGGING_CATEGORY(MAVLinkProtocolLog)
......@@ -56,13 +58,14 @@ Q_DECLARE_LOGGING_CATEGORY(MAVLinkProtocolLog)
* for more information, please see the official website.
* @ref http://pixhawk.ethz.ch/software/mavlink/
**/
class MAVLinkProtocol : public QGCSingleton
class MAVLinkProtocol : public QGCTool
{
Q_OBJECT
DECLARE_QGC_SINGLETON(MAVLinkProtocol, MAVLinkProtocol)
public:
MAVLinkProtocol(QGCApplication* app);
~MAVLinkProtocol();
/** @brief Get the human-friendly name of this protocol */
QString getName();
/** @brief Get the system id of this application */
......@@ -145,6 +148,9 @@ public:
/// Suspend/Restart logging during replay.
void suspendLogForReplay(bool suspend);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
public slots:
/** @brief Receive bytes from a communication interface */
void receiveBytes(LinkInterface* link, QByteArray b);
......@@ -279,9 +285,6 @@ signals:
void saveTempFlightDataLog(QString tempLogfile);
private:
MAVLinkProtocol(QObject* parent = NULL);
~MAVLinkProtocol();
void _linkStatusChanged(LinkInterface* link, bool connected);
#ifndef __mobile__
......@@ -303,11 +306,12 @@ private:
/// This way Link deletion works correctly.
QList<SharedLinkInterface> _connectedLinks;
LinkManager* _linkMgr;
QTimer _heartbeatTimer; ///< Timer to emit heartbeats
int _heartbeatRate; ///< Heartbeat rate, controls the timer interval
bool _heartbeatsEnabled; ///< Enabled/disable heartbeat emission
LinkManager* _linkMgr;
MultiVehicleManager* _multiVehicleManager;
};
#endif // MAVLINKPROTOCOL_H_
......@@ -23,6 +23,7 @@
#include "MockLink.h"
#include "QGCLoggingCategory.h"
#include "QGCApplication.h"
#include <QTimer>
#include <QDebug>
......@@ -76,7 +77,7 @@ const char* MockConfiguration::_vehicleTypeKey = "VehicleType";
const char* MockConfiguration::_sendStatusTextKey = "SendStatusText";
MockLink::MockLink(MockConfiguration* config)
: _missionItemHandler(this)
: _missionItemHandler(this, qgcApp()->toolbox()->mavlinkProtocol())
, _name("MockLink")
, _connected(false)
, _vehicleSystemId(128) // FIXME: Pull from eventual parameter manager
......
......@@ -28,11 +28,12 @@
QGC_LOGGING_CATEGORY(MockLinkMissionItemHandlerLog, "MockLinkMissionItemHandlerLog")
MockLinkMissionItemHandler::MockLinkMissionItemHandler(MockLink* mockLink)
MockLinkMissionItemHandler::MockLinkMissionItemHandler(MockLink* mockLink, MAVLinkProtocol* mavlinkProtocol)
: _mockLink(mockLink)
, _missionItemResponseTimer(NULL)
, _failureMode(FailNone)
, _sendHomePositionOnEmptyList(false)
, _mavlinkProtocol(mavlinkProtocol)
{
Q_ASSERT(mockLink);
}
......@@ -234,8 +235,8 @@ void MockLinkMissionItemHandler::_requestNextMissionItem(int sequenceNumber)
mavlink_message_t message;
mavlink_mission_request_t missionRequest;
missionRequest.target_system = MAVLinkProtocol::instance()->getSystemId();
missionRequest.target_component = MAVLinkProtocol::instance()->getComponentId();
missionRequest.target_system = _mavlinkProtocol->getSystemId();
missionRequest.target_component = _mavlinkProtocol->getComponentId();
missionRequest.seq = sequenceNumber;
mavlink_msg_mission_request_encode(_mockLink->vehicleId(), MAV_COMP_ID_MISSIONPLANNER, &message, &missionRequest);
......@@ -258,8 +259,8 @@ void MockLinkMissionItemHandler::_sendAck(MAV_MISSION_RESULT ackType)
mavlink_message_t message;
mavlink_mission_ack_t missionAck;
missionAck.target_system = MAVLinkProtocol::instance()->getSystemId();
missionAck.target_component = MAVLinkProtocol::instance()->getComponentId();
missionAck.target_system = _mavlinkProtocol->getSystemId();
missionAck.target_component = _mavlinkProtocol->getComponentId();
missionAck.type = ackType;
mavlink_msg_mission_ack_encode(_mockLink->vehicleId(), MAV_COMP_ID_MISSIONPLANNER, &message, &missionAck);
......
......@@ -30,6 +30,7 @@
#include "QGCMAVLink.h"
#include "QGCLoggingCategory.h"
#include "MAVLinkProtocol.h"
class MockLink;
......@@ -40,7 +41,7 @@ class MockLinkMissionItemHandler : public QObject
Q_OBJECT
public:
MockLinkMissionItemHandler(MockLink* mockLink);
MockLinkMissionItemHandler(MockLink* mockLink, MAVLinkProtocol* mavlinkProtocol);
~MockLinkMissionItemHandler();
// Prepares for destruction on correct thread
......@@ -111,10 +112,11 @@ private:
typedef QMap<uint16_t, mavlink_mission_item_t> MissionList_t;
MissionList_t _missionItems;
QTimer* _missionItemResponseTimer;
FailureMode_t _failureMode;
bool _failureFirstTimeOnly;
bool _sendHomePositionOnEmptyList;
QTimer* _missionItemResponseTimer;
FailureMode_t _failureMode;
bool _failureFirstTimeOnly;
bool _sendHomePositionOnEmptyList;
MAVLinkProtocol* _mavlinkProtocol;
};
#endif
......@@ -46,6 +46,7 @@ This file is part of the QGROUNDCONTROL project
#include "QGCFileDialog.h"
#include "QGCMessageBox.h"
#include "HomePositionManager.h"
#include "QGCApplication.h"
// FlightGear _fgProcess start and connection is quite fragile. Uncomment the define below to get higher level of debug output
// for tracking down problems.
......@@ -957,11 +958,11 @@ bool QGCFlightGearLink::connectSimulation()
}
// We start out at our home position
_fgArgList << QString("--lat=%1").arg(HomePositionManager::instance()->getHomeLatitude());
_fgArgList << QString("--lon=%1").arg(HomePositionManager::instance()->getHomeLongitude());
_fgArgList << QString("--lat=%1").arg(qgcApp()->toolbox()->homePositionManager()->getHomeLatitude());
_fgArgList << QString("--lon=%1").arg(qgcApp()->toolbox()->homePositionManager()->getHomeLongitude());
// The altitude is not set because an altitude not equal to the ground altitude leads to a non-zero default throttle in flightgear
// Without the altitude-setting the aircraft is positioned on the ground
//_fgArgList << QString("--altitude=%1").arg(HomePositionManager::instance()->getHomeAltitude());
//_fgArgList << QString("--altitude=%1").arg(qgcApp()->toolbox()->homePositionManager()->getHomeAltitude());
#ifdef DEBUG_FLIGHTGEAR_CONNECT
// This tell FlightGear to output highest debug level of log output. Handy for debuggin failures by looking at the FG
......
......@@ -133,7 +133,7 @@ bool SerialLink::_disconnect(void)
}
#ifdef __android__
LinkManager::instance()->suspendConfigurationUpdates(false);
qgcApp()->toolbox()->linkManager()->suspendConfigurationUpdates(false);
#endif
return true;
}
......@@ -150,7 +150,7 @@ bool SerialLink::_connect(void)
_disconnect();
#ifdef __android__
LinkManager::instance()->suspendConfigurationUpdates(true);
qgcApp()->toolbox()->linkManager()->suspendConfigurationUpdates(true);
#endif
// Initialize the connection
......
......@@ -38,7 +38,7 @@ Mouse6dofInput::Mouse6dofInput(Mouse3DInput* mouseInput) :
bValue(0.0),
cValue(0.0)
{
connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &Mouse6dofInput::_activeVehicleChanged);
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &Mouse6dofInput::_activeVehicleChanged);
// Connect 3DxWare SDK MotionEvent
connect(mouseInput, SIGNAL(Move3d(std::vector<float>&)), this, SLOT(motion3DMouse(std::vector<float>&)));
......@@ -63,7 +63,7 @@ Mouse6dofInput::Mouse6dofInput(QWidget* parent) :
bValue(0.0),
cValue(0.0)
{
connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &Mouse6dofInput::_activeVehicleChanged);
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &Mouse6dofInput::_activeVehicleChanged);
if (!mouseActive)
{
......@@ -137,7 +137,7 @@ void Mouse6dofInput::_activeVehicleChanged(Vehicle* vehicle)
void Mouse6dofInput::init()
{
// Make sure active UAS is set
_activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle());
_activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
}
void Mouse6dofInput::run()
......
......@@ -27,14 +27,14 @@
#include "FileManagerTest.h"
#include "MultiVehicleManager.h"
#include "UAS.h"
#include "QGCApplication.h"
//UT_REGISTER_TEST(FileManagerTest)
FileManagerTest::FileManagerTest(void) :
_mockLink(NULL),
_fileServer(NULL),
_fileManager(NULL),
_multiSpy(NULL)
FileManagerTest::FileManagerTest(void)
: _fileServer(NULL)
, _fileManager(NULL)
, _multiSpy(NULL)
{
}
......@@ -44,24 +44,12 @@ void FileManagerTest::init(void)
{
UnitTest::init();
_mockLink = new MockLink();
Q_CHECK_PTR(_mockLink);
LinkManager::instance()->_addLink(_mockLink);
LinkManager::instance()->connectLink(_mockLink);
_connectMockLink();
_fileServer = _mockLink->getFileServer();
QVERIFY(_fileServer != NULL);
// Wait or the Vehicle to show up
MultiVehicleManager* vehicleManager = MultiVehicleManager::instance();
QSignalSpy spyVehicleCreate(vehicleManager, SIGNAL(activeVehicleChanged(Vehicle*)));
if (!vehicleManager->activeVehicle()) {
QCOMPARE(spyVehicleCreate.wait(10000), true);
}
UASInterface* uas = vehicleManager->activeVehicle()->uas();
QVERIFY(uas != NULL);
_fileManager = uas->getFileManager();
_fileManager = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->uas()->getFileManager();
QVERIFY(_fileManager != NULL);
Q_ASSERT(_multiSpy == NULL);
......@@ -89,9 +77,9 @@ void FileManagerTest::cleanup(void)
// Disconnecting the link will prompt for log file save
setExpectedFileDialog(getSaveFileName, QStringList());
LinkManager::instance()->disconnectLink(_mockLink);
_disconnectMockLink();
_fileServer = NULL;
_mockLink = NULL;
_fileManager = NULL;
delete _multiSpy;
......
......@@ -76,7 +76,6 @@ private:
static const uint8_t _systemIdQGC = 255;
static const uint8_t _systemIdServer = 128;
MockLink* _mockLink;
MockLinkFileServer* _fileServer;
FileManager* _fileManager;
......
......@@ -28,6 +28,7 @@
#include "LinkManagerTest.h"
#include "MockLink.h"
#include "QGCApplication.h"
UT_REGISTER_TEST(LinkManagerTest)
......@@ -45,7 +46,7 @@ void LinkManagerTest::init(void)
Q_ASSERT(_linkMgr == NULL);
Q_ASSERT(_multiSpy == NULL);
_linkMgr = new LinkManager(NULL /* no parent */);
_linkMgr = qgcApp()->toolbox()->linkManager();
Q_CHECK_PTR(_linkMgr);
_rgSignals[newLinkSignalIndex] = SIGNAL(newLink(LinkInterface*));
......@@ -60,9 +61,6 @@ void LinkManagerTest::cleanup(void)
Q_ASSERT(_linkMgr);
Q_ASSERT(_multiSpy);
_linkMgr->_shutdown();
delete _linkMgr;
delete _multiSpy;
_linkMgr = NULL;
......@@ -77,12 +75,11 @@ void LinkManagerTest::_add_test(void)
Q_ASSERT(_linkMgr);
Q_ASSERT(_linkMgr->getLinks().count() == 0);
MockLink* link = new MockLink();
_linkMgr->_addLink(link);
_connectMockLink();
QList<LinkInterface*> links = _linkMgr->getLinks();
QCOMPARE(links.count(), 1);
QCOMPARE(dynamic_cast<MockLink*>(links[0]), link);
QCOMPARE(dynamic_cast<MockLink*>(links[0]), _mockLink);
}
void LinkManagerTest::_delete_test(void)
......@@ -90,9 +87,8 @@ void LinkManagerTest::_delete_test(void)
Q_ASSERT(_linkMgr);
Q_ASSERT(_linkMgr->getLinks().count() == 0);
MockLink* link = new MockLink();
_linkMgr->_addLink(link);
_linkMgr->_deleteLink(link);
_connectMockLink();
_disconnectMockLink();
QCOMPARE(_linkMgr->getLinks().count(), 0);
}
......@@ -103,9 +99,8 @@ void LinkManagerTest::_addSignals_test(void)
Q_ASSERT(_linkMgr->getLinks().count() == 0);
Q_ASSERT(_multiSpy->checkNoSignals() == true);
MockLink* link = new MockLink();
_linkMgr->_addLink(link);
_connectMockLink();
QCOMPARE(_multiSpy->checkOnlySignalByMask(newLinkSignalMask), true);
QSignalSpy* spy = _multiSpy->getSpyByIndex(newLinkSignalIndex);
......@@ -115,7 +110,7 @@ void LinkManagerTest::_addSignals_test(void)
QObject* object = qvariant_cast<QObject *>(signalArgs[0]);
QVERIFY(object != NULL);
MockLink* signalLink = qobject_cast<MockLink*>(object);
QCOMPARE(signalLink, link);
QCOMPARE(signalLink, _mockLink);
}
void LinkManagerTest::_deleteSignals_test(void)
......@@ -124,11 +119,9 @@ void LinkManagerTest::_deleteSignals_test(void)
Q_ASSERT(_linkMgr->getLinks().count() == 0);
Q_ASSERT(_multiSpy->checkNoSignals() == true);
MockLink* link = new MockLink();
_linkMgr->_addLink(link);
_connectMockLink();
_multiSpy->clearAllSignals();
_linkMgr->_deleteLink(link);
_disconnectMockLink();
QCOMPARE(_multiSpy->checkOnlySignalByMask(linkDeletedSignalMask), true);
QSignalSpy* spy = _multiSpy->getSpyByIndex(linkDeletedSignalIndex);
......
......@@ -31,56 +31,18 @@
#include "QGCMessageBox.h"
#include "MultiVehicleManager.h"
UT_REGISTER_TEST(MainWindowTest)
MainWindowTest::MainWindowTest(void) :
_mainWindow()
{
}
void MainWindowTest::init(void)
{
UnitTest::init();
_mainWindow = MainWindow::_create();
Q_CHECK_PTR(_mainWindow);
}
void MainWindowTest::cleanup(void)
{
_mainWindow->close();
QTest::qWait(200);
delete _mainWindow;
UnitTest::cleanup();
}
// FIXME: Temporarily turned off
//UT_REGISTER_TEST(MainWindowTest)
void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot)
{
LinkManager* linkMgr = LinkManager::instance();
Q_CHECK_PTR(linkMgr);
MockLink* link = new MockLink();
Q_CHECK_PTR(link);
link->setFirmwareType(autopilot);
LinkManager::instance()->_addLink(link);
linkMgr->connectLink(link);
// Wait for the Vehicle to work it's way through the various threads
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(activeVehicleChanged(Vehicle*)));
QCOMPARE(spyVehicle.wait(5000), true);
_createMainWindow();
_connectMockLink(autopilot);
// On MainWindow close we should get a message box telling the user to disconnect first. Cancel should do nothing.
setExpectedMessageBox(QGCMessageBox::Cancel);
_mainWindow->close();
QTest::qWait(1000); // Need to allow signals to move between threads
_closeMainWindow(true /* cancelExpected */);
checkExpectedMessageBox();
linkMgr->disconnectLink(link);
QTest::qWait(1000); // Need to allow signals to move between threads
}
void MainWindowTest::_connectWindowClosePX4_test(void) {
......
......@@ -36,20 +36,12 @@ class MainWindowTest : public UnitTest
{
Q_OBJECT
public:
MainWindowTest(void);
private slots:
void init(void);
void cleanup(void);
void _connectWindowClosePX4_test(void);
void _connectWindowCloseGeneric_test(void);
private:
void _connectWindowClose_test(MAV_AUTOPILOT autopilot);
MainWindow* _mainWindow;
};
#endif
......@@ -92,7 +92,7 @@ void MavlinkLogTest::_bootLogDetectionCancel_test(void)
setExpectedFileDialog(getSaveFileName, QStringList());
// Kick the protocol to check for lost log files and wait for signals to move through
connect(this, &MavlinkLogTest::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles);
connect(this, &MavlinkLogTest::checkForLostLogFiles, qgcApp()->toolbox()->mavlinkProtocol(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles();
QTest::qWait(1000);
......@@ -112,7 +112,7 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void)
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
// Kick the protocol to check for lost log files and wait for signals to move through
connect(this, &MavlinkLogTest::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles);
connect(this, &MavlinkLogTest::checkForLostLogFiles, qgcApp()->toolbox()->mavlinkProtocol(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles();
QTest::qWait(1000);
......@@ -129,7 +129,7 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void)
_createTempLogFile(true);
// Kick the protocol to check for lost log files and wait for signals to move through
connect(this, &MavlinkLogTest::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles);
connect(this, &MavlinkLogTest::checkForLostLogFiles, qgcApp()->toolbox()->mavlinkProtocol(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles();
QTest::qWait(1000);
......@@ -138,23 +138,12 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void)
void MavlinkLogTest::_connectLogWorker(bool arm)
{
LinkManager* linkMgr = LinkManager::instance();
Q_CHECK_PTR(linkMgr);
MockLink* link = new MockLink();
Q_CHECK_PTR(link);
LinkManager::instance()->_addLink(link);
linkMgr->connectLink(link);
// Wait for the uas to work it's way through the various threads
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(activeVehicleChanged(Vehicle*)));
QCOMPARE(spyVehicle.wait(5000), true);
_connectMockLink();
QDir logSaveDir;
if (arm) {
MultiVehicleManager::instance()->activeVehicle()->setArmed(true);
qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->setArmed(true);
QTest::qWait(1500); // Wait long enough for heartbeat to come through
// On Disconnect: We should get a getSaveFileName dialog.
......@@ -163,8 +152,7 @@ void MavlinkLogTest::_connectLogWorker(bool arm)
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
}
linkMgr->disconnectLink(link);
QTest::qWait(1000); // Need to allow signals to move between threads
_disconnectMockLink();
if (arm) {
checkExpectedFileDialog();
......
......@@ -24,6 +24,7 @@
#include "PX4RCCalibrationTest.h"
#include "RadioComponentController.h"
#include "MultiVehicleManager.h"
#include "QGCApplication.h"
/// @file
/// @brief QRadioComponentController Widget unit test
......@@ -149,18 +150,9 @@ void RadioConfigTest::init(void)
{
UnitTest::init();
_mockLink = new MockLink();
Q_CHECK_PTR(_mockLink);
LinkManager::instance()->_addLink(_mockLink);
LinkManager::instance()->connectLink(_mockLink);
_connectMockLink();
// Wait for the Vehicle to get created
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
QCOMPARE(spyVehicle.wait(5000), true);
QVERIFY(MultiVehicleManager::instance()->parameterReadyVehicleAvailable());
QVERIFY(MultiVehicleManager::instance()->activeVehicle());
_autopilot = MultiVehicleManager::instance()->activeVehicle()->autopilotPlugin();
_autopilot = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->autopilotPlugin();
Q_ASSERT(_autopilot);
// This will instatiate the widget with an active uas with ready parameters
......@@ -192,8 +184,6 @@ void RadioConfigTest::cleanup(void)
// Disconnecting the link will prompt for log file save
setExpectedFileDialog(getSaveFileName, QStringList());
LinkManager::instance()->disconnectLink(_mockLink);
UnitTest::cleanup();
}
......
......@@ -94,7 +94,6 @@ private:
void _validateParameters(void);
MockLink* _mockLink;
AutoPilotPlugin* _autopilot;
QGCQmlWidgetHolder* _calWidget;
......
Supports Markdown
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