Improve restart server behaviour and bluetooth clean uo

This commit is contained in:
Simon Stürz 2018-05-11 13:30:19 +02:00
parent ccf1c10913
commit d294d93871
3 changed files with 26 additions and 11 deletions

View File

@ -395,12 +395,8 @@ void BluetoothServer::stop()
{
if (connected() && m_controller) {
m_controller->disconnectFromDevice();
return;
}
if (!running())
return;
qCDebug(dcBluetoothServer()) << "-------------------------------------";
qCDebug(dcBluetoothServer()) << "Stopping bluetooth server.";
qCDebug(dcBluetoothServer()) << "-------------------------------------";

View File

@ -78,7 +78,11 @@ void Core::setPlatformName(const QString &name)
void Core::run()
{
// Start the networkmanager service
m_networkManager->start();
if (!m_networkManager->available()) {
m_networkManager->start();
} else {
evaluateNetworkManagerState(m_networkManager->state());
}
}
Core::Core(QObject *parent) :
@ -93,8 +97,6 @@ Core::Core(QObject *parent) :
connect(m_bluetoothServer, &BluetoothServer::connectedChanged, this, &Core::onBluetoothServerConnectedChanged);
m_nymeaService = new NymeadService(false, this);
}
Core::~Core()
@ -120,20 +122,33 @@ void Core::evaluateNetworkManagerState(const NetworkManager::NetworkManagerState
stopService();
break;
case NetworkManager::NetworkManagerStateConnectedSite:
// We somehow in the network
// We are somehow in the network
stopService();
break;
default:
case NetworkManager::NetworkManagerStateUnknown:
case NetworkManager::NetworkManagerStateAsleep:
case NetworkManager::NetworkManagerStateDisconnected:
case NetworkManager::NetworkManagerStateConnectedLocal:
// Everything else is not connected, start the service
startService();
if (m_networkManager->available())
startService();
break;
default:
qCDebug(dcApplication()) << "Ignoring networkmanager state" << state;
break;
}
}
void Core::startService()
{
if (!m_networkManager->available())
qCDebug(dcApplication()) << "Start service";
if (!m_networkManager->available()) {
qCWarning(dcApplication()) << "Could not start services. There is no network manager available.";
return;
}
// Verify if we have a wireless network available
if (!m_networkManager->wirelessAvailable()) {

View File

@ -99,6 +99,9 @@ int main(int argc, char *argv[])
platformNameOption.setDefaultValue("nymea-box");
parser.addOption(platformNameOption);
QCommandLineOption testingOption(QStringList() << "t" << "testing", "Advertise the bluetoothserver alyways for testing.");
parser.addOption(testingOption);
parser.process(application);
// Enable debug categories
@ -114,6 +117,7 @@ int main(int argc, char *argv[])
qCDebug(dcApplication()) << "=====================================";
qCDebug(dcApplication()) << "Advertising name:" << parser.value(advertiseNameOption);
qCDebug(dcApplication()) << "Platform name:" << parser.value(platformNameOption);
qCDebug(dcApplication()) << "Testing mode:" << (parser.isSet(testingOption) ? "enabled" : "disabled");
// Start core
Core::instance()->setAdvertiseName(parser.value(advertiseNameOption));