• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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 CAST_SENDER_PUBLIC_CAST_APP_DISCOVERY_SERVICE_H_
6 #define CAST_SENDER_PUBLIC_CAST_APP_DISCOVERY_SERVICE_H_
7 
8 #include <vector>
9 
10 #include "cast/common/public/service_info.h"
11 
12 namespace openscreen {
13 namespace cast {
14 
15 class CastMediaSource;
16 
17 // Interface for app discovery for Cast devices.
18 class CastAppDiscoveryService {
19  public:
20   using AvailabilityCallback =
21       std::function<void(const CastMediaSource& source,
22                          const std::vector<ServiceInfo>& devices)>;
23 
24   class Subscription {
25    public:
26     Subscription(CastAppDiscoveryService* discovery_service, uint32_t id);
27     Subscription(Subscription&&) noexcept;
28     Subscription(Subscription&) = delete;
29     Subscription& operator=(Subscription&&);
30     Subscription& operator=(const Subscription&) = delete;
31     ~Subscription();
32 
33     void Reset();
34 
35    private:
36     friend class CastAppDiscoveryService;
37 
38     void Swap(Subscription& other);
39 
40     CastAppDiscoveryService* discovery_service_;
41     uint32_t id_;
42   };
43 
44   virtual ~CastAppDiscoveryService() = default;
45 
46   // Adds an availability query for |source|. Results will be continuously
47   // returned via |callback| until the returned Subscription is destroyed by the
48   // caller.  If there are cached results available, |callback| will be invoked
49   // before this method returns.  |callback| may be invoked with an empty list
50   // if all devices respond to the respective queries with "unavailable" or
51   // don't respond before a timeout.  |callback| may be invoked successively
52   // with the same list.
53   virtual Subscription StartObservingAvailability(
54       const CastMediaSource& source,
55       AvailabilityCallback callback) = 0;
56 
57   // Refreshes the state of app discovery in the service. It is suitable to call
58   // this method when the user initiates a user gesture.
59   virtual void Refresh() = 0;
60 
61  private:
62   virtual void RemoveAvailabilityCallback(uint32_t id) = 0;
63 };
64 
65 }  // namespace cast
66 }  // namespace openscreen
67 
68 #endif  // CAST_SENDER_PUBLIC_CAST_APP_DISCOVERY_SERVICE_H_
69