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_MDNS_MDNS_RECORD_CHANGED_CALLBACK_H_
6 #define DISCOVERY_MDNS_MDNS_RECORD_CHANGED_CALLBACK_H_
7 
8 #include <vector>
9 
10 #include "discovery/mdns/mdns_records.h"
11 #include "util/osp_logging.h"
12 
13 namespace openscreen {
14 namespace discovery {
15 
16 enum class RecordChangedEvent {
17   kCreated,
18   kUpdated,
19   kExpired,
20 };
21 
22 class MdnsRecordChangedCallback;
23 
24 struct PendingQueryChange {
25   enum ChangeType { kStartQuery, kStopQuery };
26   DomainName name;
27   DnsType dns_type;
28   DnsClass dns_class;
29   MdnsRecordChangedCallback* callback;
30   ChangeType change_type;
31 };
32 
33 class MdnsRecordChangedCallback {
34  public:
35   virtual ~MdnsRecordChangedCallback() = default;
36 
37   // Called when |record| has been changed.
38   // NOTE: This callback may not modify the instance from which it is called.
39   // The return value of this function must be the set of all record changes to
40   // be made once the operation completes.
41   virtual std::vector<PendingQueryChange> OnRecordChanged(
42       const MdnsRecord& record,
43       RecordChangedEvent event) = 0;
44 };
45 
46 inline std::ostream& operator<<(std::ostream& output,
47                                 RecordChangedEvent event) {
48   switch (event) {
49     case RecordChangedEvent::kCreated:
50       return output << "Create";
51     case RecordChangedEvent::kUpdated:
52       return output << "Update";
53     case RecordChangedEvent::kExpired:
54       return output << "Expiry";
55   }
56   OSP_NOTREACHED();
57 }
58 
59 }  // namespace discovery
60 }  // namespace openscreen
61 
62 #endif  // DISCOVERY_MDNS_MDNS_RECORD_CHANGED_CALLBACK_H_
63