message_stream_lookup.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2021 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. #ifndef ASH_QUICK_PAIR_MESSAGE_STREAM_MESSAGE_STREAM_LOOKUP_H_
  5. #define ASH_QUICK_PAIR_MESSAGE_STREAM_MESSAGE_STREAM_LOOKUP_H_
  6. #include <string>
  7. #include "base/observer_list_types.h"
  8. namespace ash {
  9. namespace quick_pair {
  10. class MessageStream;
  11. // Exposes a MessageStream instance to consumers for a specific device, if
  12. // available. Observes the BluetoothAdapter for devices connected and
  13. // disconnect and opens and closes RFCOMM channels to the device as
  14. // appropriate, and creates and maintains MessageStream instances for each
  15. // device.
  16. class MessageStreamLookup {
  17. public:
  18. // For immediate consumption of MessageStream upon creation, use the
  19. // observer model to retrieve the MessageStream when the socket connects.
  20. class Observer : public base::CheckedObserver {
  21. public:
  22. virtual void OnMessageStreamConnected(const std::string& device_address,
  23. MessageStream* message_stream) = 0;
  24. };
  25. virtual ~MessageStreamLookup() = default;
  26. virtual void AddObserver(Observer* observer) = 0;
  27. virtual void RemoveObserver(Observer* observer) = 0;
  28. // To retrieve an existing instance of a MessageStream, retrieve an instance
  29. // this way.
  30. virtual MessageStream* GetMessageStream(
  31. const std::string& device_address) = 0;
  32. };
  33. } // namespace quick_pair
  34. } // namespace ash
  35. #endif // ASH_QUICK_PAIR_MESSAGE_STREAM_MESSAGE_STREAM_LOOKUP_H_