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 #include "discovery/dnssd/impl/service_instance.h"
6
7 #include <utility>
8
9 #include "discovery/common/config.h"
10 #include "discovery/mdns/public/mdns_service.h"
11 #include "platform/api/task_runner.h"
12
13 namespace openscreen {
14 namespace discovery {
15
ServiceInstance(TaskRunner * task_runner,ReportingClient * reporting_client,const Config & config,const InterfaceInfo & network_info)16 ServiceInstance::ServiceInstance(TaskRunner* task_runner,
17 ReportingClient* reporting_client,
18 const Config& config,
19 const InterfaceInfo& network_info)
20 : task_runner_(task_runner),
21 mdns_service_(MdnsService::Create(task_runner,
22 reporting_client,
23 config,
24 network_info)),
25 network_config_(network_info.index,
26 network_info.GetIpAddressV4(),
27 network_info.GetIpAddressV6()) {
28 if (config.enable_querying) {
29 querier_ = std::make_unique<QuerierImpl>(
30 mdns_service_.get(), task_runner_, reporting_client, &network_config_);
31 }
32 if (config.enable_publication) {
33 publisher_ = std::make_unique<PublisherImpl>(
34 mdns_service_.get(), reporting_client, task_runner_, &network_config_);
35 }
36 }
37
~ServiceInstance()38 ServiceInstance::~ServiceInstance() {
39 OSP_DCHECK(task_runner_->IsRunningOnTaskRunner());
40 }
41
42 } // namespace discovery
43 } // namespace openscreen
44