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