File: querier_impl.h

package info (click to toggle)
android-platform-tools 34.0.5-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 150,900 kB
  • sloc: cpp: 805,786; java: 293,500; ansic: 128,288; xml: 127,491; python: 41,481; sh: 14,245; javascript: 9,665; cs: 3,846; asm: 2,049; makefile: 1,917; yacc: 440; awk: 368; ruby: 183; sql: 140; perl: 88; lex: 67
file content (84 lines) | stat: -rw-r--r-- 2,964 bytes parent folder | download | duplicates (11)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2019 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 DISCOVERY_DNSSD_IMPL_QUERIER_IMPL_H_
#define DISCOVERY_DNSSD_IMPL_QUERIER_IMPL_H_

#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "absl/hash/hash.h"
#include "absl/strings/string_view.h"
#include "discovery/dnssd/impl/constants.h"
#include "discovery/dnssd/impl/conversion_layer.h"
#include "discovery/dnssd/impl/dns_data_graph.h"
#include "discovery/dnssd/impl/instance_key.h"
#include "discovery/dnssd/impl/service_key.h"
#include "discovery/dnssd/public/dns_sd_instance_endpoint.h"
#include "discovery/dnssd/public/dns_sd_querier.h"
#include "discovery/mdns/mdns_record_changed_callback.h"
#include "discovery/mdns/mdns_records.h"
#include "discovery/mdns/public/mdns_service.h"

namespace openscreen {
namespace discovery {

class NetworkInterfaceConfig;
class ReportingClient;

class QuerierImpl : public DnsSdQuerier, public MdnsRecordChangedCallback {
 public:
  // |querier|, |task_runner|, and |network_config| must outlive the QuerierImpl
  // instance constructed.
  QuerierImpl(MdnsService* querier,
              TaskRunner* task_runner,
              ReportingClient* reporting_client,
              const NetworkInterfaceConfig* network_config);
  ~QuerierImpl() override;

  bool IsQueryRunning(const std::string& service) const;

  // DnsSdQuerier overrides.
  void StartQuery(const std::string& service, Callback* callback) override;
  void StopQuery(const std::string& service, Callback* callback) override;
  void ReinitializeQueries(const std::string& service) override;

  // MdnsRecordChangedCallback overrides.
  std::vector<PendingQueryChange> OnRecordChanged(
      const MdnsRecord& record,
      RecordChangedEvent event) override;

 private:
  friend class QuerierImplTesting;

  // Applies the provided record change to the underlying |graph_| instance.
  ErrorOr<std::vector<PendingQueryChange>> ApplyRecordChanges(
      const MdnsRecord& record,
      RecordChangedEvent event);

  // Informs all relevant callbacks of the provided changes.
  void InvokeChangeCallbacks(std::vector<DnsSdInstanceEndpoint> created,
                             std::vector<DnsSdInstanceEndpoint> updated,
                             std::vector<DnsSdInstanceEndpoint> deleted);

  // Graph of underlying mDNS Record and their associations with each-other.
  std::unique_ptr<DnsDataGraph> graph_;

  // Map from the (service, domain) pairs currently being queried for to the
  // callbacks to call when new InstanceEndpoints are available.
  std::map<ServiceKey, std::vector<Callback*>> callback_map_;

  MdnsService* const mdns_querier_;
  TaskRunner* const task_runner_;

  ReportingClient* reporting_client_;
};

}  // namespace discovery
}  // namespace openscreen

#endif  // DISCOVERY_DNSSD_IMPL_QUERIER_IMPL_H_