• 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_IMPL_SERVICE_DISPATCHER_H_
6 #define DISCOVERY_DNSSD_IMPL_SERVICE_DISPATCHER_H_
7 
8 #include <memory>
9 
10 #include "discovery/dnssd/impl/querier_impl.h"
11 #include "discovery/dnssd/impl/service_instance.h"
12 #include "discovery/dnssd/public/dns_sd_querier.h"
13 #include "discovery/dnssd/public/dns_sd_service.h"
14 
15 namespace openscreen {
16 
17 class TaskRunner;
18 
19 namespace discovery {
20 
21 struct Config;
22 class ReportingClient;
23 
24 class ServiceDispatcher final : public DnsSdPublisher,
25                                 public DnsSdQuerier,
26                                 public DnsSdService {
27  public:
28   ServiceDispatcher(TaskRunner* task_runner,
29                     ReportingClient* reporting_client,
30                     const Config& config);
31   ~ServiceDispatcher() override;
32 
33   // DnsSdService overrides.
GetQuerier()34   DnsSdQuerier* GetQuerier() override { return querier_; }
GetPublisher()35   DnsSdPublisher* GetPublisher() override { return publisher_; }
36 
37  private:
38   // DnsSdQuerier overrides.
39   void StartQuery(const std::string& service, Callback* cb) override;
40   void StopQuery(const std::string& service, Callback* cb) override;
41   void ReinitializeQueries(const std::string& service) override;
42 
43   // DnsSdPublisher overrides.
44   Error Register(const DnsSdInstance& instance, Client* client) override;
45   Error UpdateRegistration(const DnsSdInstance& instance) override;
46   ErrorOr<int> DeregisterAll(const std::string& service) override;
47 
48   std::vector<std::unique_ptr<ServiceInstance>> service_instances_;
49 
50   TaskRunner* const task_runner_;
51 
52   // Pointers either to this instance or to nullptr depending whether the below
53   // types are supported.
54   DnsSdPublisher* const publisher_;
55   DnsSdQuerier* const querier_;
56 };
57 
58 }  // namespace discovery
59 }  // namespace openscreen
60 
61 #endif  // DISCOVERY_DNSSD_IMPL_SERVICE_DISPATCHER_H_
62