chromium/third_party/openscreen/src/cast/sender/cast_app_availability_tracker.h

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CAST_SENDER_CAST_APP_AVAILABILITY_TRACKER_H_
#define CAST_SENDER_CAST_APP_AVAILABILITY_TRACKER_H_

#include <map>
#include <string>
#include <vector>

#include "cast/sender/channel/message_util.h"
#include "cast/sender/public/cast_media_source.h"
#include "platform/api/time.h"

namespace openscreen::cast {

// Tracks receiver queries and their extracted Cast app IDs and their
// availabilities on discovered receivers.
// Example usage:
///
// (1) A page is interested in a Cast URL (e.g. by creating a
// PresentationRequest with the URL) like "cast:foo". To register the source to
// be tracked:
//   CastAppAvailabilityTracker tracker;
//   auto source = CastMediaSource::From("cast:foo");
//   auto new_app_ids = tracker.RegisterSource(source.value());
//
// (2) The set of app IDs returned by the tracker can then be used by the caller
// to send an app availability request to each of the discovered receivers.
//
// (3) Once the caller knows the availability value for a (receiver, app) pair,
// it may inform the tracker to update its results:
//   auto affected_sources =
//       tracker.UpdateAppAvailability(receiver_id, app_id, {availability,
//       now});
//
// (4) The tracker returns a subset of discovered sources that were affected by
// the update. The caller can then call |GetAvailableReceivers()| to get the
// updated results for each affected source.
//
// (5a): At any time, the caller may call |RemoveResultsForReceiver()| to remove
// cached results pertaining to the receiver, when it detects that a receiver is
// removed or no longer valid.
//
// (5b): At any time, the caller may call |GetAvailableReceivers()| (even before
// the source is registered) to determine if there are cached results available.
class CastAppAvailabilityTracker {};

}  // namespace openscreen::cast

#endif  // CAST_SENDER_CAST_APP_AVAILABILITY_TRACKER_H_