Commit d3bb0daf authored by Tristan Matthews's avatar Tristan Matthews

* #9911: simplify network manager state reporting

parent 497f205c
......@@ -30,20 +30,23 @@
#include "networkmanager.h"
#include "../manager.h"
#include "array_size.h"
#include "logger.h"
const std::string NetworkManager::statesString[] = {"unknown", "asleep",
"connecting", "connected",
"disconnected", "unknown",};
namespace {
const char *stateAsString(uint32_t state)
{
static const char * STATES[] = {"unknown", "asleep", "connecting",
"connected", "disconnected"};
std::string NetworkManager::stateAsString(const uint32_t &state)
{
return statesString[state < 6 ? state : 5];
const size_t idx = state < ARRAYSIZE(STATES) ? state : 0;
return STATES[idx];
}
}
void NetworkManager::StateChanged(const uint32_t &state)
{
WARN("Network state changed: %s", stateAsString(state).c_str());
WARN("Network state changed: %s", stateAsString(state));
}
void NetworkManager::PropertiesChanged(const std::map<std::string, ::DBus::Variant> &argin0)
......
......@@ -45,7 +45,6 @@ class NetworkManager : public org::freedesktop::NetworkManager_proxy,
NetworkManager(DBus::Connection &, const DBus::Path &, const char*);
void StateChanged(const uint32_t &state);
void PropertiesChanged(const std::map<std::string, ::DBus::Variant> &argin0);
std::string stateAsString(const uint32_t &state);
private:
enum NMState {
......@@ -55,8 +54,6 @@ class NetworkManager : public org::freedesktop::NetworkManager_proxy,
NM_STATE_CONNECTED,
NM_STATE_DISCONNECTED
};
static const std::string statesString[];
};
#endif
Markdown is supported
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