Line data Source code
1 : /* 2 : * 3 : * Copyright (c) 2021-2022 Project CHIP Authors 4 : * 5 : * Licensed under the Apache License, Version 2.0 (the "License"); 6 : * you may not use this file except in compliance with the License. 7 : * You may obtain a copy of the License at 8 : * 9 : * http://www.apache.org/licenses/LICENSE-2.0 10 : * 11 : * Unless required by applicable law or agreed to in writing, software 12 : * distributed under the License is distributed on an "AS IS" BASIS, 13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 : * See the License for the specific language governing permissions and 15 : * limitations under the License. 16 : */ 17 : 18 : #pragma once 19 : 20 : #include <lib/core/DataModelTypes.h> 21 : #include <lib/core/NodeId.h> 22 : 23 : namespace chip { 24 : 25 : /* NOTE: PeerId should be only used by mDNS, because it contains a compressed fabric id which is not unique, and the compressed 26 : * fabric id is only used for mDNS announcement. ScopedNodeId which contains a node id and fabirc index, should be used in prefer of 27 : * PeerId. ScopedNodeId is locally unique. 28 : */ 29 : // TODO: remove PeerId usage outside lib/dns, move PeerId into lib/dns 30 : /// A peer is identified by a node id within a compressed fabric ID 31 : class PeerId 32 : { 33 : public: 34 0 : PeerId() {} 35 0 : PeerId(CompressedFabricId compressedFabricId, NodeId nodeId) : mNodeId(nodeId), mCompressedFabricId(compressedFabricId) {} 36 : 37 28 : NodeId GetNodeId() const { return mNodeId; } 38 51 : PeerId & SetNodeId(NodeId id) 39 : { 40 51 : mNodeId = id; 41 51 : return *this; 42 : } 43 : 44 19 : CompressedFabricId GetCompressedFabricId() const { return mCompressedFabricId; } 45 51 : PeerId & SetCompressedFabricId(CompressedFabricId id) 46 : { 47 51 : mCompressedFabricId = id; 48 51 : return *this; 49 : } 50 : 51 0 : bool operator==(const PeerId & other) const 52 : { 53 0 : return (mNodeId == other.mNodeId) && (mCompressedFabricId == other.mCompressedFabricId); 54 : } 55 0 : bool operator!=(const PeerId & other) const 56 : { 57 0 : return (mNodeId != other.mNodeId) || (mCompressedFabricId != other.mCompressedFabricId); 58 : } 59 : 60 : private: 61 : NodeId mNodeId = kUndefinedNodeId; 62 : 63 : CompressedFabricId mCompressedFabricId = kUndefinedCompressedFabricId; 64 : }; 65 : 66 : } // namespace chip