• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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 DISCOVERY_DNSSD_PUBLIC_DNS_SD_QUERIER_H_
6 #define DISCOVERY_DNSSD_PUBLIC_DNS_SD_QUERIER_H_
7 
8 #include "discovery/dnssd/public/dns_sd_instance_endpoint.h"
9 
10 namespace openscreen {
11 namespace discovery {
12 
13 class DnsSdQuerier {
14  public:
15   // TODO(rwkeane): Add support for expiring records in addition to deleting
16   // them.
17   class Callback {
18    public:
19     virtual ~Callback() = default;
20 
21     // Callback fired when a new InstanceEndpoint is created.
22     // NOTE: This callback may not modify the DnsSdQuerier instance from which
23     // it is called.
24     virtual void OnEndpointCreated(
25         const DnsSdInstanceEndpoint& new_endpoint) = 0;
26 
27     // Callback fired when an existing InstanceEndpoint is updated.
28     // NOTE: This callback may not modify the DnsSdQuerier instance from which
29     // it is called.
30     virtual void OnEndpointUpdated(
31         const DnsSdInstanceEndpoint& modified_endpoint) = 0;
32 
33     // Callback fired when an existing InstanceEndpoint is deleted.
34     // NOTE: This callback may not modify the DnsSdQuerier instance from which
35     // it is called.
36     virtual void OnEndpointDeleted(
37         const DnsSdInstanceEndpoint& old_endpoint) = 0;
38   };
39 
40   virtual ~DnsSdQuerier() = default;
41 
42   // Begins a new query. The provided callback will be called whenever new
43   // information about the provided (service, domain) pair becomes available.
44   // The Callback provided is expected to persist until the StopQuery method is
45   // called or this instance is destroyed.
46   // NOTE: The provided service value is expected to be valid, as defined by the
47   // IsServiceValid() method.
48   // NOTE: The callback must be called on the TaskRunner thread.
49   virtual void StartQuery(const std::string& service, Callback* cb) = 0;
50 
51   // Stops an already running query.
52   // NOTE: The provided service value is expected to be valid, as defined by the
53   // IsServiceValid() method.
54   virtual void StopQuery(const std::string& service, Callback* cb) = 0;
55 
56   // Re-initializes the process of service discovery for the provided service
57   // id. All ongoing queries for this domain are restarted and any previously
58   // received query results are discarded.
59   virtual void ReinitializeQueries(const std::string& service) = 0;
60 };
61 
62 }  // namespace discovery
63 }  // namespace openscreen
64 
65 #endif  // DISCOVERY_DNSSD_PUBLIC_DNS_SD_QUERIER_H_
66