Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace enum with enum class #32909

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/platform/Linux/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ bool ConnectivityManagerImpl::_IsWiFiStationConnected()

std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);

if (mWpaSupplicant.state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED)
if (mWpaSupplicant.state != GDBusWpaSupplicant::WpaState::INTERFACE_CONNECTED)
{
ChipLogProgress(DeviceLayer, "wpa_supplicant: _IsWiFiStationConnected: interface not connected");
return false;
Expand Down Expand Up @@ -238,7 +238,7 @@ bool ConnectivityManagerImpl::_IsWiFiStationProvisioned()

std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);

if (mWpaSupplicant.state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED)
if (mWpaSupplicant.state != GDBusWpaSupplicant::WpaState::INTERFACE_CONNECTED)
{
ChipLogProgress(DeviceLayer, "wpa_supplicant: _IsWiFiStationProvisioned: interface not connected");
return false;
Expand All @@ -257,7 +257,7 @@ void ConnectivityManagerImpl::_ClearWiFiStationProvision()
{
std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);

if (mWpaSupplicant.state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED)
if (mWpaSupplicant.state != GDBusWpaSupplicant::WpaState::INTERFACE_CONNECTED)
{
ChipLogProgress(DeviceLayer, "wpa_supplicant: _ClearWiFiStationProvision: interface not connected");
return;
Expand All @@ -280,8 +280,8 @@ bool ConnectivityManagerImpl::_CanStartWiFiScan()
{
std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);

bool ret = mWpaSupplicant.state == GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED &&
mWpaSupplicant.scanState == GDBusWpaSupplicant::WIFI_SCANNING_IDLE;
bool ret = mWpaSupplicant.state == GDBusWpaSupplicant::WpaState::INTERFACE_CONNECTED &&
mWpaSupplicant.scanState == GDBusWpaSupplicant::WpaScanningState::IDLE;

return ret;
}
Expand Down Expand Up @@ -507,7 +507,7 @@ void ConnectivityManagerImpl::_OnWpaInterfaceProxyReady(GObject * sourceObject,
if (iface != nullptr && err == nullptr)
{
mWpaSupplicant.iface = iface;
mWpaSupplicant.state = GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::INTERFACE_CONNECTED;
ChipLogProgress(DeviceLayer, "wpa_supplicant: connected to wpa_supplicant interface proxy");

g_signal_connect(
Expand All @@ -527,7 +527,7 @@ void ConnectivityManagerImpl::_OnWpaInterfaceProxyReady(GObject * sourceObject,
ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to create wpa_supplicant interface proxy %s: %s",
mWpaSupplicant.interfacePath, err ? err->message : "unknown error");

mWpaSupplicant.state = GDBusWpaSupplicant::WPA_NOT_CONNECTED;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::NOT_CONNECTED;
}

// We need to stop auto scan or it will block our network scan.
Expand Down Expand Up @@ -584,7 +584,7 @@ void ConnectivityManagerImpl::_OnWpaInterfaceReady(GObject * sourceObject, GAsyn
&err.GetReceiver());
if (result)
{
mWpaSupplicant.state = GDBusWpaSupplicant::WPA_GOT_INTERFACE_PATH;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::GOT_INTERFACE_PATH;
ChipLogProgress(DeviceLayer, "wpa_supplicant: WiFi interface: %s", mWpaSupplicant.interfacePath);

wpa_fi_w1_wpa_supplicant1_interface_proxy_new_for_bus(
Expand Down Expand Up @@ -623,7 +623,7 @@ void ConnectivityManagerImpl::_OnWpaInterfaceReady(GObject * sourceObject, GAsyn

if (result)
{
mWpaSupplicant.state = GDBusWpaSupplicant::WPA_GOT_INTERFACE_PATH;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::GOT_INTERFACE_PATH;
ChipLogProgress(DeviceLayer, "wpa_supplicant: WiFi interface: %s", mWpaSupplicant.interfacePath);

Platform::CopyString(sWiFiIfName, CHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME);
Expand All @@ -649,7 +649,7 @@ void ConnectivityManagerImpl::_OnWpaInterfaceReady(GObject * sourceObject, GAsyn
ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to create interface %s: %s",
CHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME, error ? error->message : "unknown error");

mWpaSupplicant.state = GDBusWpaSupplicant::WPA_NO_INTERFACE_PATH;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::NO_INTERFACE_PATH;

if (mWpaSupplicant.interfacePath)
{
Expand All @@ -676,7 +676,7 @@ void ConnectivityManagerImpl::_OnWpaInterfaceAdded(WpaFiW1Wpa_supplicant1 * prox
mWpaSupplicant.interfacePath = const_cast<gchar *>(path);
if (mWpaSupplicant.interfacePath)
{
mWpaSupplicant.state = GDBusWpaSupplicant::WPA_GOT_INTERFACE_PATH;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::GOT_INTERFACE_PATH;
ChipLogProgress(DeviceLayer, "wpa_supplicant: WiFi interface added: %s", mWpaSupplicant.interfacePath);

wpa_fi_w1_wpa_supplicant1_interface_proxy_new_for_bus(
Expand Down Expand Up @@ -710,7 +710,7 @@ void ConnectivityManagerImpl::_OnWpaInterfaceRemoved(WpaFiW1Wpa_supplicant1 * pr
{
ChipLogProgress(DeviceLayer, "wpa_supplicant: WiFi interface removed: %s", StringOrNullMarker(path));

mWpaSupplicant.state = GDBusWpaSupplicant::WPA_NO_INTERFACE_PATH;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::NO_INTERFACE_PATH;

if (mWpaSupplicant.interfacePath)
{
Expand All @@ -730,7 +730,7 @@ void ConnectivityManagerImpl::_OnWpaInterfaceRemoved(WpaFiW1Wpa_supplicant1 * pr
mWpaSupplicant.bss = nullptr;
}

mWpaSupplicant.scanState = GDBusWpaSupplicant::WIFI_SCANNING_IDLE;
mWpaSupplicant.scanState = GDBusWpaSupplicant::WpaScanningState::IDLE;
}
}

Expand All @@ -747,7 +747,7 @@ void ConnectivityManagerImpl::_OnWpaProxyReady(GObject * sourceObject, GAsyncRes
mWpaSupplicant.proxy = wpa_fi_w1_wpa_supplicant1_proxy_new_for_bus_finish(res, &err.GetReceiver());
if (mWpaSupplicant.proxy != nullptr && err.get() == nullptr)
{
mWpaSupplicant.state = GDBusWpaSupplicant::WPA_CONNECTED;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::CONNECTED;
ChipLogProgress(DeviceLayer, "wpa_supplicant: connected to wpa_supplicant proxy");

g_signal_connect(
Expand All @@ -773,7 +773,7 @@ void ConnectivityManagerImpl::_OnWpaProxyReady(GObject * sourceObject, GAsyncRes
{
ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to create wpa_supplicant proxy %s",
err ? err->message : "unknown error");
mWpaSupplicant.state = GDBusWpaSupplicant::WPA_NOT_CONNECTED;
mWpaSupplicant.state = GDBusWpaSupplicant::WpaState::NOT_CONNECTED;
}
}

Expand All @@ -793,7 +793,7 @@ bool ConnectivityManagerImpl::IsWiFiManagementStarted()
{
std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);

bool ret = mWpaSupplicant.state == GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED;
bool ret = mWpaSupplicant.state == GDBusWpaSupplicant::WpaState::INTERFACE_CONNECTED;

return ret;
}
Expand Down Expand Up @@ -1322,7 +1322,7 @@ CHIP_ERROR ConnectivityManagerImpl::CommitConfig()

std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);

if (mWpaSupplicant.state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED)
if (mWpaSupplicant.state != GDBusWpaSupplicant::WpaState::INTERFACE_CONNECTED)
{
ChipLogError(DeviceLayer, "wpa_supplicant: CommitConfig: interface proxy not connected");
return CHIP_ERROR_INCORRECT_STATE;
Expand Down Expand Up @@ -1391,7 +1391,7 @@ CHIP_ERROR ConnectivityManagerImpl::GetWiFiSecurityType(SecurityTypeEnum & secur

std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);

if (mWpaSupplicant.state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED)
if (mWpaSupplicant.state != GDBusWpaSupplicant::WpaState::INTERFACE_CONNECTED)
{
ChipLogError(DeviceLayer, "wpa_supplicant: GetWiFiSecurityType: interface proxy not connected");
return CHIP_ERROR_INCORRECT_STATE;
Expand Down
24 changes: 12 additions & 12 deletions src/platform/Linux/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,25 @@ namespace DeviceLayer {
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
struct GDBusWpaSupplicant
{
enum WpaState
enum class WpaState
{
INIT,
WPA_CONNECTING,
WPA_CONNECTED,
WPA_NOT_CONNECTED,
WPA_NO_INTERFACE_PATH,
WPA_GOT_INTERFACE_PATH,
WPA_INTERFACE_CONNECTED,
CONNECTING,
CONNECTED,
NOT_CONNECTED,
NO_INTERFACE_PATH,
GOT_INTERFACE_PATH,
INTERFACE_CONNECTED,
};

enum WpaScanning
enum class WpaScanningState
{
WIFI_SCANNING_IDLE,
WIFI_SCANNING,
IDLE,
SCANNING,
};

WpaState state = INIT;
WpaScanning scanState = WIFI_SCANNING_IDLE;
WpaState state = WpaState::INIT;
WpaScanningState scanState = WpaScanningState::IDLE;
WpaFiW1Wpa_supplicant1 * proxy = nullptr;
WpaFiW1Wpa_supplicant1Interface * iface = nullptr;
WpaFiW1Wpa_supplicant1BSS * bss = nullptr;
Expand Down
14 changes: 7 additions & 7 deletions src/platform/Linux/bluez/ChipDeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ CHIP_ERROR ChipDeviceScanner::Init(BluezAdapter1 * adapter, ChipDeviceScannerDel
mAdapter.reset(reinterpret_cast<BluezAdapter1 *>(g_object_ref(adapter)));
mDelegate = delegate;

mScannerState = ChipDeviceScannerState::SCANNER_INITIALIZED;
mScannerState = ChipDeviceScannerState::INITIALIZED;

return CHIP_NO_ERROR;
}

void ChipDeviceScanner::Shutdown()
{
VerifyOrReturn(mScannerState != ChipDeviceScannerState::SCANNER_UNINITIALIZED);
VerifyOrReturn(mScannerState != ChipDeviceScannerState::UNINITIALIZED);

StopScan();

Expand All @@ -86,13 +86,13 @@ void ChipDeviceScanner::Shutdown()
},
this);

mScannerState = ChipDeviceScannerState::SCANNER_UNINITIALIZED;
mScannerState = ChipDeviceScannerState::UNINITIALIZED;
}

CHIP_ERROR ChipDeviceScanner::StartScan()
{
assertChipStackLockedByCurrentThread();
VerifyOrReturnError(mScannerState != ChipDeviceScannerState::SCANNER_SCANNING, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mScannerState != ChipDeviceScannerState::SCANNING, CHIP_ERROR_INCORRECT_STATE);

mCancellable.reset(g_cancellable_new());
CHIP_ERROR err = PlatformMgrImpl().GLibMatterContextInvokeSync(
Expand All @@ -104,7 +104,7 @@ CHIP_ERROR ChipDeviceScanner::StartScan()
return err;
}

mScannerState = ChipDeviceScannerState::SCANNER_SCANNING;
mScannerState = ChipDeviceScannerState::SCANNING;
ChipLogDetail(Ble, "ChipDeviceScanner has started scanning!");

return CHIP_NO_ERROR;
Expand All @@ -113,7 +113,7 @@ CHIP_ERROR ChipDeviceScanner::StartScan()
CHIP_ERROR ChipDeviceScanner::StopScan()
{
assertChipStackLockedByCurrentThread();
VerifyOrReturnError(mScannerState == ChipDeviceScannerState::SCANNER_SCANNING, CHIP_NO_ERROR);
VerifyOrReturnError(mScannerState == ChipDeviceScannerState::SCANNING, CHIP_NO_ERROR);

CHIP_ERROR err = PlatformMgrImpl().GLibMatterContextInvokeSync(
+[](ChipDeviceScanner * self) { return self->StopScanImpl(); }, this);
Expand All @@ -124,7 +124,7 @@ CHIP_ERROR ChipDeviceScanner::StopScan()
}

// Stop scanning and return to initialization state
mScannerState = ChipDeviceScannerState::SCANNER_INITIALIZED;
mScannerState = ChipDeviceScannerState::INITIALIZED;

ChipLogDetail(Ble, "ChipDeviceScanner has stopped scanning!");

Expand Down
12 changes: 6 additions & 6 deletions src/platform/Linux/bluez/ChipDeviceScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ class ChipDeviceScanner : public BluezObjectManagerAdapterNotificationsDelegate
CHIP_ERROR StopScan();

/// Check if the scanner is active
bool IsScanning() const { return mScannerState == ChipDeviceScannerState::SCANNER_SCANNING; }
bool IsScanning() const { return mScannerState == ChipDeviceScannerState::SCANNING; }

/// Members that implement virtual methods on BluezObjectManagerAdapterNotificationsDelegate
void OnDeviceAdded(BluezDevice1 & device) override;
void OnDevicePropertyChanged(BluezDevice1 & device, GVariant * changedProps, const char * const * invalidatedProps) override;
void OnDeviceRemoved(BluezDevice1 & device) override {}

private:
enum ChipDeviceScannerState
enum class ChipDeviceScannerState
{
SCANNER_UNINITIALIZED,
SCANNER_INITIALIZED,
SCANNER_SCANNING
UNINITIALIZED,
INITIALIZED,
SCANNING
};

CHIP_ERROR StartScanImpl();
Expand All @@ -108,7 +108,7 @@ class ChipDeviceScanner : public BluezObjectManagerAdapterNotificationsDelegate
GAutoPtr<BluezAdapter1> mAdapter;

ChipDeviceScannerDelegate * mDelegate = nullptr;
ChipDeviceScannerState mScannerState = ChipDeviceScannerState::SCANNER_UNINITIALIZED;
ChipDeviceScannerState mScannerState = ChipDeviceScannerState::UNINITIALIZED;
GAutoPtr<GCancellable> mCancellable;
};

Expand Down
Loading