DeviceScanner.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2023 Project CHIP Authors
  3. * All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #pragma once
  19. #include <platform/CHIPDeviceBuildConfig.h>
  20. #if CHIP_DEVICE_LAYER_TARGET_DARWIN
  21. #include <controller/CHIPDeviceController.h>
  22. #include <lib/dnssd/platform/Dnssd.h>
  23. #include <unordered_map>
  24. #include <vector>
  25. #if CONFIG_NETWORK_LAYER_BLE
  26. #include <platform/Darwin/BleScannerDelegate.h>
  27. #endif // CONFIG_NETWORK_LAYER_BLE
  28. struct DeviceScannerResult
  29. {
  30. chip::Controller::SetUpCodePairerParameters mParams;
  31. chip::VendorId mVendorId;
  32. uint16_t mProductId;
  33. uint16_t mDiscriminator;
  34. chip::Optional<chip::Dnssd::CommonResolutionData> mResolutionData;
  35. };
  36. class DeviceScanner : public chip::Dnssd::CommissioningResolveDelegate,
  37. public chip::Dnssd::DnssdBrowseDelegate
  38. #if CONFIG_NETWORK_LAYER_BLE
  39. ,
  40. public chip::DeviceLayer::BleScannerDelegate
  41. #endif // CONFIG_NETWORK_LAYER_BLE
  42. {
  43. public:
  44. CHIP_ERROR Start();
  45. CHIP_ERROR Stop();
  46. CHIP_ERROR Get(uint16_t index, chip::RendezvousParameters & params);
  47. CHIP_ERROR Get(uint16_t index, chip::Dnssd::CommonResolutionData & resolutionData);
  48. void Log() const;
  49. /////////// CommissioningResolveDelegate Interface /////////
  50. void OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData) override;
  51. /////////// DnssdBrowseDelegate Interface /////////
  52. void OnBrowseAdd(chip::Dnssd::DnssdService service) override;
  53. void OnBrowseRemove(chip::Dnssd::DnssdService service) override;
  54. void OnBrowseStop(CHIP_ERROR error) override;
  55. #if CONFIG_NETWORK_LAYER_BLE
  56. /////////// BleScannerDelegate Interface /////////
  57. void OnBleScanAdd(BLE_CONNECTION_OBJECT connObj, const chip::Ble::ChipBLEDeviceIdentificationInfo & info) override;
  58. void OnBleScanRemove(BLE_CONNECTION_OBJECT connObj) override;
  59. #endif // CONFIG_NETWORK_LAYER_BLE
  60. private:
  61. std::unordered_map<std::string, std::map<chip::Inet::InterfaceId::PlatformType, std::vector<DeviceScannerResult>>>
  62. mDiscoveredResults;
  63. };
  64. DeviceScanner & GetDeviceScanner();
  65. #endif // CHIP_DEVICE_LAYER_TARGET_DARWIN