Add once mode

This commit is contained in:
Simon Stürz 2018-11-22 10:07:26 +01:00
parent 3746b3d515
commit fe9a4c6048
6 changed files with 46 additions and 7 deletions

1
debian/changelog vendored
View File

@ -1,6 +1,7 @@
nymea-networkmanager (0.3.0) stretch; urgency=medium
* Add access point mode for creating wireless access points
* Add once mode
-- Simon Stürz <simon.stuerz@guh.io> Mon, 29 Oct 2018 14:46:56 +0100

View File

@ -71,6 +71,12 @@ QList<WiredNetworkDevice *> NetworkManager::wiredNetworkDevices() const
return m_wiredNetworkDevices.values();
}
/*! Returns the \l{NetworkSettings} from this \l{NetworkManager}. */
NetworkSettings *NetworkManager::networkSettings() const
{
return m_networkSettings;
}
/*! Returns the \l{NetworkDevice} with the given \a interface from this \l{NetworkManager}. If there is no such \a interface returns nullptr. */
NetworkDevice *NetworkManager::getNetworkDevice(const QString &interface)
{

View File

@ -41,8 +41,8 @@ class NetworkManager : public QObject
{
Q_OBJECT
Q_ENUMS(NetworkManagerState)
Q_ENUMS(NetworkManagerConnectivityState)
Q_ENUMS(NetworkManagerError)
Q_ENUMS(NetworkManagerConnectivityState)
public:
enum NetworkManagerState {
@ -90,6 +90,7 @@ public:
QList<WirelessNetworkDevice *> wirelessNetworkDevices() const;
QList<WiredNetworkDevice *> wiredNetworkDevices() const;
NetworkSettings *networkSettings() const;
NetworkDevice *getNetworkDevice(const QString &interface);
// Properties

View File

@ -118,6 +118,14 @@ void Core::run()
case ModeOffline:
evaluateNetworkManagerState(m_networkManager->state());
break;
case ModeOnce:
if (m_networkManager->networkSettings()->connections().isEmpty()) {
qCDebug(dcApplication()) << "Start the bluetooth service because of \"once\" mode and there is currenlty no network configured yet.";
startService();
} else {
qCDebug(dcApplication()) << "Not starting the bluetooth service because of \"once\" mode. There are" << m_networkManager->networkSettings()->connections().count() << "network configurations.";
}
break;
}
}
@ -257,6 +265,14 @@ void Core::onBluetoothServerRunningChanged(bool running)
case ModeOffline:
evaluateNetworkManagerState(m_networkManager->state());
break;
case ModeOnce:
if (m_networkManager->networkSettings()->connections().isEmpty()) {
qCDebug(dcApplication()) << "Start the bluetooth service because of \"once\" mode and there is currenlty no network configured yet.";
startService();
} else {
qCDebug(dcApplication()) << "Not starting the bluetooth service because of \"once\" mode. There are" << m_networkManager->networkSettings()->connections().count() << "network configurations.";
}
break;
}
}
}
@ -304,6 +320,14 @@ void Core::onNetworkManagerAvailableChanged(const bool &available)
case ModeOffline:
evaluateNetworkManagerState(m_networkManager->state());
break;
case ModeOnce:
if (m_networkManager->networkSettings()->connections().isEmpty()) {
qCDebug(dcApplication()) << "Start the bluetooth service because of \"once\" mode and there is currenlty no network configured yet.";
startService();
} else {
qCDebug(dcApplication()) << "Not starting the bluetooth service because of \"once\" mode. There are" << m_networkManager->networkSettings()->connections().count() << "network configurations.";
}
break;
}
}
@ -362,6 +386,9 @@ void Core::onWirelessDeviceBitRateChanged(int bitRate)
void Core::onWirelessDeviceModeChanged(WirelessNetworkDevice::Mode mode)
{
qCDebug(dcApplication()) << "Wireless device mode" << mode;
// TODO: check what to do if in ap mode
m_bluetoothServer->onWirelessDeviceModeChanged(mode);
}

View File

@ -36,6 +36,7 @@ public:
enum Mode {
ModeAlways,
ModeOffline,
ModeOnce,
ModeStart
};
Q_ENUM(Mode)

View File

@ -90,7 +90,7 @@ int main(int argc, char *argv[])
Application application(argc, argv);
application.setApplicationName("nymea-networkmanager");
application.setOrganizationName("nymea");
application.setApplicationVersion("0.2.0");
application.setApplicationVersion("0.3.0");
// Command line parser
QCommandLineParser parser;
@ -115,9 +115,10 @@ int main(int argc, char *argv[])
parser.addOption(timeoutOption);
QCommandLineOption modeOption(QStringList() << "m" << "mode", "Run the daemon in a specific mode. Default is \"offline\".\n\n" \
"- offline: this mode starts the bluetooth server once the device is offline and not connected to any LAN network.\n\n" \
"- always: this mode enables the bluetooth server as long the application is running.\n\n" \
"- start: this mode starts the bluetooth server for 3 minutes on start and shuts down after a connection.\n\n", "offline | always | start");
"- offline: this mode starts the bluetooth server once the device is offline and not connected to any LAN network.\n\n" \
"- once: this mode starts the bluetooth server only if no network configuration exists. Once a network connection exists the server will never start again.\n\n" \
"- always: this mode enables the bluetooth server as long the application is running.\n\n" \
"- start: this mode starts the bluetooth server for 3 minutes on start and shuts down after a connection.\n\n", "offline | once | always | start");
parser.addOption(modeOption);
parser.process(application);
@ -141,8 +142,6 @@ int main(int argc, char *argv[])
if (QFileInfo::exists(configLocation + fileName)) {
qCDebug(dcApplication) << "Using configuration file from:" << configLocation + fileName;
QSettings settings(configLocation + fileName, QSettings::IniFormat);
qCDebug(dcApplication()) << "Fooo" << settings.allKeys() << settings.childGroups();
if (settings.contains("Mode")) {
if (settings.value("Mode").toString().toLower() == "offline") {
@ -151,6 +150,8 @@ int main(int argc, char *argv[])
mode = Core::ModeAlways;
} else if (settings.value("Mode").toString().toLower() == "start") {
mode = Core::ModeStart;
} else if (settings.value("Mode").toString().toLower() == "once") {
mode = Core::ModeOnce;
} else {
qCWarning(dcApplication()).noquote() << QString("The config file's mode \"%1\" does not match the allowed modes.").arg(settings.value("Mode").toString());
}
@ -176,6 +177,8 @@ int main(int argc, char *argv[])
mode = Core::ModeAlways;
} else if (parser.value(modeOption).toLower() == "start") {
mode = Core::ModeStart;
} else if (parser.value(modeOption).toLower() == "once") {
mode = Core::ModeOnce;
} else {
qCWarning(dcApplication()).noquote() << QString("The given mode \"%1\" does not match the allowed modes.").arg(parser.value(modeOption));
parser.showHelp(1);