OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_BASE_NET_UTIL_WIN_H_ | |
6 #define NET_BASE_NET_UTIL_WIN_H_ | |
7 | |
8 // This file is only used for testing. | |
pauljensen
2014/09/23 14:03:55
This is not accurate as this file is used by net_u
hubbe
2014/09/23 17:37:50
Comment updated.
| |
9 | |
10 #include <wlanapi.h> | |
11 | |
12 #include "base/win/scoped_handle.h" | |
13 #include "net/base/net_export.h" | |
14 | |
15 namespace net { | |
pauljensen
2014/09/23 14:03:55
this should also be within "namespace internal {"
hubbe
2014/09/23 17:37:50
Done
| |
16 | |
17 struct NET_EXPORT WlanApi { | |
18 typedef DWORD (WINAPI *WlanOpenHandleFunc)( | |
19 DWORD, VOID*, DWORD*, HANDLE*); | |
20 typedef DWORD (WINAPI *WlanEnumInterfacesFunc)( | |
21 HANDLE, VOID*, WLAN_INTERFACE_INFO_LIST**); | |
22 typedef DWORD (WINAPI *WlanQueryInterfaceFunc)( | |
23 HANDLE, const GUID*, WLAN_INTF_OPCODE, VOID*, DWORD*, VOID**, | |
24 WLAN_OPCODE_VALUE_TYPE*); | |
25 typedef DWORD (WINAPI *WlanSetInterfaceFunc)( | |
26 HANDLE, const GUID*, WLAN_INTF_OPCODE, DWORD, const VOID*, VOID*); | |
27 typedef VOID (WINAPI *WlanFreeMemoryFunc)(VOID*); | |
28 typedef DWORD (WINAPI *WlanCloseHandleFunc)(HANDLE, VOID*); | |
29 | |
30 WlanApi(); | |
31 static WlanApi& GetInstance(); | |
32 | |
33 template <typename T> | |
34 DWORD OpenHandle(DWORD client_version, DWORD* cur_version, T* handle) const { | |
35 HANDLE temp_handle; | |
36 DWORD result = open_handle_func(client_version, NULL, cur_version, | |
37 &temp_handle); | |
38 if (result != ERROR_SUCCESS) | |
39 return result; | |
40 handle->Set(temp_handle); | |
41 return ERROR_SUCCESS; | |
42 } | |
43 | |
44 HMODULE module; | |
45 WlanOpenHandleFunc open_handle_func; | |
46 WlanEnumInterfacesFunc enum_interfaces_func; | |
47 WlanQueryInterfaceFunc query_interface_func; | |
48 WlanSetInterfaceFunc set_interface_func; | |
49 WlanFreeMemoryFunc free_memory_func; | |
50 WlanCloseHandleFunc close_handle_func; | |
51 bool initialized; | |
52 }; | |
53 | |
54 struct WlanApiHandleTraits { | |
55 typedef HANDLE Handle; | |
56 | |
57 static bool CloseHandle(HANDLE handle) { | |
58 return WlanApi::GetInstance().close_handle_func(handle, NULL) == | |
59 ERROR_SUCCESS; | |
60 } | |
61 static bool IsHandleValid(HANDLE handle) { | |
62 return base::win::HandleTraits::IsHandleValid(handle); | |
63 } | |
64 static HANDLE NullHandle() { | |
65 return base::win::HandleTraits::NullHandle(); | |
66 } | |
67 }; | |
68 | |
69 typedef base::win::GenericScopedHandle< | |
70 WlanApiHandleTraits, | |
71 base::win::DummyVerifierTraits> WlanHandle; | |
72 | |
73 struct WlanApiDeleter { | |
74 inline void operator()(void* ptr) const { | |
75 WlanApi::GetInstance().free_memory_func(ptr); | |
76 } | |
77 }; | |
78 | |
79 } // namespace net | |
80 | |
81 #endif // NET_BASE_NET_UTIL_WIN_H_ | |
OLD | NEW |