Improve restart server behaviour and bluetooth clean uo
This commit is contained in:
parent
ccf1c10913
commit
d294d93871
@ -395,12 +395,8 @@ void BluetoothServer::stop()
|
|||||||
{
|
{
|
||||||
if (connected() && m_controller) {
|
if (connected() && m_controller) {
|
||||||
m_controller->disconnectFromDevice();
|
m_controller->disconnectFromDevice();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!running())
|
|
||||||
return;
|
|
||||||
|
|
||||||
qCDebug(dcBluetoothServer()) << "-------------------------------------";
|
qCDebug(dcBluetoothServer()) << "-------------------------------------";
|
||||||
qCDebug(dcBluetoothServer()) << "Stopping bluetooth server.";
|
qCDebug(dcBluetoothServer()) << "Stopping bluetooth server.";
|
||||||
qCDebug(dcBluetoothServer()) << "-------------------------------------";
|
qCDebug(dcBluetoothServer()) << "-------------------------------------";
|
||||||
|
|||||||
@ -78,7 +78,11 @@ void Core::setPlatformName(const QString &name)
|
|||||||
void Core::run()
|
void Core::run()
|
||||||
{
|
{
|
||||||
// Start the networkmanager service
|
// Start the networkmanager service
|
||||||
|
if (!m_networkManager->available()) {
|
||||||
m_networkManager->start();
|
m_networkManager->start();
|
||||||
|
} else {
|
||||||
|
evaluateNetworkManagerState(m_networkManager->state());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Core(QObject *parent) :
|
Core::Core(QObject *parent) :
|
||||||
@ -93,8 +97,6 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::~Core()
|
Core::~Core()
|
||||||
@ -120,20 +122,33 @@ void Core::evaluateNetworkManagerState(const NetworkManager::NetworkManagerState
|
|||||||
stopService();
|
stopService();
|
||||||
break;
|
break;
|
||||||
case NetworkManager::NetworkManagerStateConnectedSite:
|
case NetworkManager::NetworkManagerStateConnectedSite:
|
||||||
// We somehow in the network
|
// We are somehow in the network
|
||||||
stopService();
|
stopService();
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
|
case NetworkManager::NetworkManagerStateUnknown:
|
||||||
|
case NetworkManager::NetworkManagerStateAsleep:
|
||||||
|
case NetworkManager::NetworkManagerStateDisconnected:
|
||||||
|
case NetworkManager::NetworkManagerStateConnectedLocal:
|
||||||
// Everything else is not connected, start the service
|
// Everything else is not connected, start the service
|
||||||
|
if (m_networkManager->available())
|
||||||
startService();
|
startService();
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qCDebug(dcApplication()) << "Ignoring networkmanager state" << state;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::startService()
|
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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Verify if we have a wireless network available
|
// Verify if we have a wireless network available
|
||||||
if (!m_networkManager->wirelessAvailable()) {
|
if (!m_networkManager->wirelessAvailable()) {
|
||||||
|
|||||||
@ -99,6 +99,9 @@ int main(int argc, char *argv[])
|
|||||||
platformNameOption.setDefaultValue("nymea-box");
|
platformNameOption.setDefaultValue("nymea-box");
|
||||||
parser.addOption(platformNameOption);
|
parser.addOption(platformNameOption);
|
||||||
|
|
||||||
|
QCommandLineOption testingOption(QStringList() << "t" << "testing", "Advertise the bluetoothserver alyways for testing.");
|
||||||
|
parser.addOption(testingOption);
|
||||||
|
|
||||||
parser.process(application);
|
parser.process(application);
|
||||||
|
|
||||||
// Enable debug categories
|
// Enable debug categories
|
||||||
@ -114,6 +117,7 @@ int main(int argc, char *argv[])
|
|||||||
qCDebug(dcApplication()) << "=====================================";
|
qCDebug(dcApplication()) << "=====================================";
|
||||||
qCDebug(dcApplication()) << "Advertising name:" << parser.value(advertiseNameOption);
|
qCDebug(dcApplication()) << "Advertising name:" << parser.value(advertiseNameOption);
|
||||||
qCDebug(dcApplication()) << "Platform name:" << parser.value(platformNameOption);
|
qCDebug(dcApplication()) << "Platform name:" << parser.value(platformNameOption);
|
||||||
|
qCDebug(dcApplication()) << "Testing mode:" << (parser.isSet(testingOption) ? "enabled" : "disabled");
|
||||||
|
|
||||||
// Start core
|
// Start core
|
||||||
Core::instance()->setAdvertiseName(parser.value(advertiseNameOption));
|
Core::instance()->setAdvertiseName(parser.value(advertiseNameOption));
|
||||||
|
|||||||
Reference in New Issue
Block a user