-
Notifications
You must be signed in to change notification settings - Fork 277
[AI Task] [Tizen.Network.WiFi] Consolidate GetFound*/GetWiFiConfigurations into EnumerateForeach<T> helper #7680
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,97 +181,67 @@ internal SafeWiFiManagerHandle GetSafeHandle() | |
| } | ||
|
|
||
|
|
||
| internal IEnumerable<WiFiAP> GetFoundAPs() | ||
| // Shared "native foreach -> List<T>" collector for the GetFound*/ | ||
| // GetWiFiConfigurations methods. Each call site supplies only what | ||
| // differs: the operation name and privilege (for CheckReturnValue), | ||
| // the native foreach function, and how to wrap a native item handle | ||
| // into its managed type. | ||
| private List<T> EnumerateForeach<T>(string opName, string privilege, | ||
| Func<SafeWiFiManagerHandle, Interop.WiFi.HandleCallback, IntPtr, int> nativeForeach, | ||
| Func<IntPtr, T> wrap) | ||
| { | ||
| Log.Info(Globals.LogTag, "GetFoundAPs"); | ||
| List<WiFiAP> apList = new List<WiFiAP>(); | ||
| Interop.WiFi.HandleCallback callback = (IntPtr apHandle, IntPtr userData) => | ||
| Log.Info(Globals.LogTag, opName); | ||
| List<T> list = new List<T>(); | ||
| Interop.WiFi.HandleCallback callback = (IntPtr handle, IntPtr userData) => | ||
| { | ||
| if (apHandle != IntPtr.Zero) | ||
| if (handle != IntPtr.Zero) | ||
| { | ||
| IntPtr clonedHandle; | ||
| Interop.WiFi.AP.Clone(out clonedHandle, apHandle); | ||
| WiFiAP apItem = new WiFiAP(clonedHandle); | ||
| apList.Add(apItem); | ||
| list.Add(wrap(handle)); | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| int ret = Interop.WiFi.GetForeachFoundAPs(GetSafeHandle(), callback, IntPtr.Zero); | ||
| CheckReturnValue(ret, "GetForeachFoundAPs", PrivilegeNetworkGet); | ||
|
|
||
| return apList; | ||
| int ret = nativeForeach(GetSafeHandle(), callback, IntPtr.Zero); | ||
| CheckReturnValue(ret, opName, privilege); | ||
| return list; | ||
| } | ||
|
|
||
| internal IEnumerable<WiFiAP> GetFoundSpecificAPs() | ||
| { | ||
| Log.Info(Globals.LogTag, "GetFoundSpecificAPs"); | ||
| List<WiFiAP> apList = new List<WiFiAP>(); | ||
| Interop.WiFi.HandleCallback callback = (IntPtr apHandle, IntPtr userData) => | ||
| { | ||
| if (apHandle != IntPtr.Zero) | ||
| internal IEnumerable<WiFiAP> GetFoundAPs() => | ||
| EnumerateForeach("GetForeachFoundAPs", PrivilegeNetworkGet, | ||
| (wifi, cb, ud) => Interop.WiFi.GetForeachFoundAPs(wifi, cb, ud), | ||
| apHandle => | ||
| { | ||
| IntPtr clonedHandle; | ||
| Interop.WiFi.AP.Clone(out clonedHandle, apHandle); | ||
| WiFiAP apItem = new WiFiAP(clonedHandle); | ||
| apList.Add(apItem); | ||
| return true; | ||
| } | ||
| return false; | ||
|
|
||
| }; | ||
|
|
||
| int ret = Interop.WiFi.GetForeachFoundSpecificAPs(GetSafeHandle(), callback, IntPtr.Zero); | ||
| CheckReturnValue(ret, "GetForeachFoundSpecificAPs", PrivilegeNetworkGet); | ||
|
|
||
| return apList; | ||
| } | ||
|
|
||
| internal IEnumerable<WiFiAP> GetFoundBssids() | ||
| { | ||
| Log.Info(Globals.LogTag, "GetFoundBssids"); | ||
| List<WiFiAP> apList = new List<WiFiAP>(); | ||
| Interop.WiFi.HandleCallback callback = (IntPtr apHandle, IntPtr userData) => | ||
| { | ||
| if (apHandle != IntPtr.Zero) | ||
| Interop.WiFi.AP.Clone(out IntPtr clonedHandle, apHandle); | ||
| return new WiFiAP(clonedHandle); | ||
| }); | ||
|
Comment on lines
+229
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value of apHandle =>
{
int ret = Interop.WiFi.AP.Clone(out IntPtr clonedHandle, apHandle);
if (ret != (int)WiFiError.None)
{
WiFiErrorFactory.ThrowWiFiException(ret, "Failed to clone AP handle");
}
return new WiFiAP(clonedHandle);
}); |
||
|
|
||
| internal IEnumerable<WiFiAP> GetFoundSpecificAPs() => | ||
| EnumerateForeach("GetForeachFoundSpecificAPs", PrivilegeNetworkGet, | ||
| (wifi, cb, ud) => Interop.WiFi.GetForeachFoundSpecificAPs(wifi, cb, ud), | ||
| apHandle => | ||
| { | ||
| IntPtr clonedHandle; | ||
| Interop.WiFi.AP.Clone(out clonedHandle, apHandle); | ||
| WiFiAP apItem = new WiFiAP(clonedHandle); | ||
| apList.Add(apItem); | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| int ret = Interop.WiFi.GetForeachFoundBssids(GetSafeHandle(), callback, IntPtr.Zero); | ||
| CheckReturnValue(ret, "GetForeachFoundBssids", PrivilegeNetworkGet); | ||
|
|
||
| return apList; | ||
| } | ||
|
|
||
| internal IEnumerable<WiFiConfiguration> GetWiFiConfigurations() | ||
| { | ||
| Log.Debug(Globals.LogTag, "GetWiFiConfigurations"); | ||
| List<WiFiConfiguration> configList = new List<WiFiConfiguration>(); | ||
| Interop.WiFi.HandleCallback callback = (IntPtr configHandle, IntPtr userData) => | ||
| { | ||
| if (configHandle != IntPtr.Zero) | ||
| Interop.WiFi.AP.Clone(out IntPtr clonedHandle, apHandle); | ||
| return new WiFiAP(clonedHandle); | ||
| }); | ||
|
Comment on lines
+242
to
+250
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value of apHandle =>
{
int ret = Interop.WiFi.AP.Clone(out IntPtr clonedHandle, apHandle);
if (ret != (int)WiFiError.None)
{
WiFiErrorFactory.ThrowWiFiException(ret, "Failed to clone AP handle");
}
return new WiFiAP(clonedHandle);
}); |
||
|
|
||
| internal IEnumerable<WiFiAP> GetFoundBssids() => | ||
| EnumerateForeach("GetForeachFoundBssids", PrivilegeNetworkGet, | ||
| (wifi, cb, ud) => Interop.WiFi.GetForeachFoundBssids(wifi, cb, ud), | ||
| apHandle => | ||
| { | ||
| IntPtr clonedConfig; | ||
| Interop.WiFi.Config.Clone(configHandle, out clonedConfig); | ||
| WiFiConfiguration configItem = new WiFiConfiguration(clonedConfig); | ||
| configList.Add(configItem); | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| int ret = Interop.WiFi.Config.GetForeachConfiguration(GetSafeHandle(), callback, IntPtr.Zero); | ||
| CheckReturnValue(ret, "GetForeachConfiguration", PrivilegeNetworkProfile); | ||
| return configList; | ||
| } | ||
| Interop.WiFi.AP.Clone(out IntPtr clonedHandle, apHandle); | ||
| return new WiFiAP(clonedHandle); | ||
| }); | ||
|
Comment on lines
+255
to
+263
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value of apHandle =>
{
int ret = Interop.WiFi.AP.Clone(out IntPtr clonedHandle, apHandle);
if (ret != (int)WiFiError.None)
{
WiFiErrorFactory.ThrowWiFiException(ret, "Failed to clone AP handle");
}
return new WiFiAP(clonedHandle);
}); |
||
|
|
||
| internal IEnumerable<WiFiConfiguration> GetWiFiConfigurations() => | ||
| EnumerateForeach("GetForeachConfiguration", PrivilegeNetworkProfile, | ||
| (wifi, cb, ud) => Interop.WiFi.Config.GetForeachConfiguration(wifi, cb, ud), | ||
| configHandle => | ||
| { | ||
| Interop.WiFi.Config.Clone(configHandle, out IntPtr clonedConfig); | ||
| return new WiFiConfiguration(clonedConfig); | ||
| }); | ||
|
Comment on lines
+268
to
+276
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value of configHandle =>
{
int ret = Interop.WiFi.Config.Clone(configHandle, out IntPtr clonedConfig);
if (ret != (int)WiFiError.None)
{
WiFiErrorFactory.ThrowWiFiException(ret, "Failed to clone WiFi configuration");
}
return new WiFiConfiguration(clonedConfig);
}); |
||
|
|
||
| internal void SaveWiFiNetworkConfiguration(WiFiConfiguration config) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propagating managed exceptions through native code boundaries (P/Invoke) can lead to undefined behavior, native crashes, or silent failures. Since the
wrapdelegate can throw exceptions (e.g., if cloning fails or during object construction), it is highly recommended to catch any exceptions inside the callback, stop the iteration, and safely rethrow the captured exception after the native foreach method returns.