Add testing mode

This commit is contained in:
Simon Stürz 2018-05-11 14:09:19 +02:00
parent d294d93871
commit 065376e06d
3 changed files with 38 additions and 2 deletions

View File

@ -75,6 +75,16 @@ void Core::setPlatformName(const QString &name)
m_platformName = name; m_platformName = name;
} }
bool Core::testingEnabled() const
{
return m_testing;
}
void Core::setTestingEnabled(bool testing)
{
m_testing = testing;
}
void Core::run() void Core::run()
{ {
// Start the networkmanager service // Start the networkmanager service
@ -97,6 +107,7 @@ Core::Core(QObject *parent) :
connect(m_bluetoothServer, &BluetoothServer::connectedChanged, this, &Core::onBluetoothServerConnectedChanged); connect(m_bluetoothServer, &BluetoothServer::connectedChanged, this, &Core::onBluetoothServerConnectedChanged);
m_nymeaService = new NymeadService(false, this); m_nymeaService = new NymeadService(false, this);
connect(m_nymeaService, &NymeadService::availableChanged, this, &Core::onNymeaServiceAvailableChanged);
} }
Core::~Core() Core::~Core()
@ -116,6 +127,12 @@ Core::~Core()
void Core::evaluateNetworkManagerState(const NetworkManager::NetworkManagerState &state) void Core::evaluateNetworkManagerState(const NetworkManager::NetworkManagerState &state)
{ {
if (m_testing && m_networkManager->available()) {
startService();
return;
}
switch (state) { switch (state) {
case NetworkManager::NetworkManagerStateConnectedGlobal: case NetworkManager::NetworkManagerStateConnectedGlobal:
// We are online // We are online
@ -143,8 +160,6 @@ void Core::evaluateNetworkManagerState(const NetworkManager::NetworkManagerState
void Core::startService() void Core::startService()
{ {
qCDebug(dcApplication()) << "Start service";
if (!m_networkManager->available()) { if (!m_networkManager->available()) {
qCWarning(dcApplication()) << "Could not start services. There is no network manager available."; qCWarning(dcApplication()) << "Could not start services. There is no network manager available.";
return; return;
@ -159,6 +174,8 @@ void Core::startService()
if (m_bluetoothServer->running()) if (m_bluetoothServer->running())
return; return;
qCDebug(dcApplication()) << "Start service";
// Disable bluetooth on nymea in order to not crash with client connections // Disable bluetooth on nymea in order to not crash with client connections
m_nymeaService->enableBluetooth(false); m_nymeaService->enableBluetooth(false);
@ -171,6 +188,10 @@ void Core::startService()
void Core::stopService() void Core::stopService()
{ {
if (m_testing) {
return;
}
if (m_bluetoothServer->running()) if (m_bluetoothServer->running())
qCDebug(dcApplication()) << "Stop bluetooth service"; qCDebug(dcApplication()) << "Stop bluetooth service";
@ -209,3 +230,11 @@ void Core::onNetworkManagerStateChanged(const NetworkManager::NetworkManagerStat
qCDebug(dcApplication()) << state; qCDebug(dcApplication()) << state;
evaluateNetworkManagerState(state); evaluateNetworkManagerState(state);
} }
void Core::onNymeaServiceAvailableChanged(bool available)
{
if (available && m_bluetoothServer->running()) {
// Check if the bluetooth server is running, disable nymea bt functionality in that case
m_nymeaService->enableBluetooth(false);
}
}

View File

@ -45,6 +45,9 @@ public:
QString platformName() const; QString platformName() const;
void setPlatformName(const QString &name); void setPlatformName(const QString &name);
bool testingEnabled() const;
void setTestingEnabled(bool testing);
void run(); void run();
private: private:
@ -59,6 +62,7 @@ private:
QString m_advertiseName; QString m_advertiseName;
QString m_platformName; QString m_platformName;
bool m_testing = false;
void evaluateNetworkManagerState(const NetworkManager::NetworkManagerState &state); void evaluateNetworkManagerState(const NetworkManager::NetworkManagerState &state);
@ -72,6 +76,8 @@ private slots:
void onNetworkManagerAvailableChanged(const bool &available); void onNetworkManagerAvailableChanged(const bool &available);
void onNetworkManagerStateChanged(const NetworkManager::NetworkManagerState &state); void onNetworkManagerStateChanged(const NetworkManager::NetworkManagerState &state);
void onNymeaServiceAvailableChanged(bool available);
}; };
#endif // CORE_H #endif // CORE_H

View File

@ -122,6 +122,7 @@ int main(int argc, char *argv[])
// Start core // Start core
Core::instance()->setAdvertiseName(parser.value(advertiseNameOption)); Core::instance()->setAdvertiseName(parser.value(advertiseNameOption));
Core::instance()->setPlatformName(parser.value(platformNameOption)); Core::instance()->setPlatformName(parser.value(platformNameOption));
Core::instance()->setTestingEnabled(parser.isSet(testingOption));
Core::instance()->run(); Core::instance()->run();
return application.exec(); return application.exec();