aboutsummaryrefslogtreecommitdiff
path: root/cast/sender/public/cast_app_discovery_service.h
blob: 2e095b6dc0b686fe00fae9136fba683e75556007 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CAST_SENDER_PUBLIC_CAST_APP_DISCOVERY_SERVICE_H_
#define CAST_SENDER_PUBLIC_CAST_APP_DISCOVERY_SERVICE_H_

#include <vector>

#include "cast/common/public/receiver_info.h"

namespace openscreen {
namespace cast {

class CastMediaSource;

// Interface for app discovery for Cast receivers.
class CastAppDiscoveryService {
 public:
  using AvailabilityCallback =
      std::function<void(const CastMediaSource& source,
                         const std::vector<ReceiverInfo>& receivers)>;

  class Subscription {
   public:
    Subscription(CastAppDiscoveryService* discovery_service, uint32_t id);
    Subscription(Subscription&&) noexcept;
    Subscription(Subscription&) = delete;
    Subscription& operator=(Subscription&&);
    Subscription& operator=(const Subscription&) = delete;
    ~Subscription();

    void Reset();

   private:
    friend class CastAppDiscoveryService;

    void Swap(Subscription& other);

    CastAppDiscoveryService* discovery_service_;
    uint32_t id_;
  };

  virtual ~CastAppDiscoveryService() = default;

  // Adds an availability query for |source|. Results will be continuously
  // returned via |callback| until the returned Subscription is destroyed by the
  // caller.  If there are cached results available, |callback| will be invoked
  // before this method returns.  |callback| may be invoked with an empty list
  // if all receivers respond to the respective queries with "unavailable" or
  // don't respond before a timeout.  |callback| may be invoked successively
  // with the same list.
  virtual Subscription StartObservingAvailability(
      const CastMediaSource& source,
      AvailabilityCallback callback) = 0;

  // Refreshes the state of app discovery in the service. It is suitable to call
  // this method when the user initiates a user gesture.
  virtual void Refresh() = 0;

 private:
  virtual void RemoveAvailabilityCallback(uint32_t id) = 0;
};

}  // namespace cast
}  // namespace openscreen

#endif  // CAST_SENDER_PUBLIC_CAST_APP_DISCOVERY_SERVICE_H_