• 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_PUBLISHER_H_
6 #define DISCOVERY_DNSSD_PUBLIC_DNS_SD_PUBLISHER_H_
7 
8 #include <string>
9 
10 #include "discovery/dnssd/public/dns_sd_instance.h"
11 #include "platform/base/error.h"
12 
13 namespace openscreen {
14 namespace discovery {
15 
16 class DnsSdInstanceEndpoint;
17 
18 class DnsSdPublisher {
19  public:
20   class Client {
21    public:
22     virtual ~Client() = default;
23 
24     // Callback called when an endpoint is successfully claimed and published
25     // via the Register() method. These values are expected to only differ in
26     // the DnsSdInstance::instance_id() field, or to be equal. This callback is
27     // purely for informational purposes and the caller is not required to act
28     // on it.
29     virtual void OnEndpointClaimed(
30         const DnsSdInstance& requested_instance,
31         const DnsSdInstanceEndpoint& claimed_endpoint) = 0;
32   };
33 
34   virtual ~DnsSdPublisher() = default;
35 
36   // Publishes the PTR, SRV, TXT, A, and AAAA records provided in the
37   // DnsSdInstance. If the record already exists, an error with code
38   // kItemAlreadyExists is returned. On success, Error::None is returned.
39   // NOTE: Some embedders may return errors on other conditions (for instance,
40   // android will return an error if the resulting TXT record has values not
41   // encodable with UTF8).
42   virtual Error Register(const DnsSdInstance& instance, Client* client) = 0;
43 
44   // Updates the TXT, A, and AAAA records associated with the provided record,
45   // if any changes have occurred. The instance and domain names must match
46   // those of a previously published record. If either this is not true, no
47   // changes have occurred, or additional embedder-specific requirements have
48   // been violated, an error is returned. Else, Error::None is returned.
49   virtual Error UpdateRegistration(const DnsSdInstance& instance) = 0;
50 
51   // Unpublishes any PTR, SRV, TXT, A, and AAAA records associated with this
52   // service id, where the service id is the second part of the
53   // <instance>.<service>.<domain> domain name as described in RFC 6763. If no
54   // such records are published, this operation will be a no-op. Returns the
55   // number of records which were removed, or an error code on error.
56   virtual ErrorOr<int> DeregisterAll(const std::string& service) = 0;
57 };
58 
59 }  // namespace discovery
60 }  // namespace openscreen
61 
62 #endif  // DISCOVERY_DNSSD_PUBLIC_DNS_SD_PUBLISHER_H_
63