Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2021 Project CHIP Authors
4 : * All rights reserved.
5 : *
6 : * Licensed under the Apache License, Version 2.0 (the "License");
7 : * you may not use this file except in compliance with the License.
8 : * You may obtain a copy of the License at
9 : *
10 : * http://www.apache.org/licenses/LICENSE-2.0
11 : *
12 : * Unless required by applicable law or agreed to in writing, software
13 : * distributed under the License is distributed on an "AS IS" BASIS,
14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : * See the License for the specific language governing permissions and
16 : * limitations under the License.
17 : */
18 :
19 : #pragma once
20 :
21 : #include <app/ConcreteEventPath.h>
22 : #include <app/util/basic-types.h>
23 : #include <lib/core/CHIPCore.h>
24 :
25 : namespace chip {
26 : namespace app {
27 : struct EventPathParams
28 : {
29 0 : EventPathParams(EndpointId aEndpointId, ClusterId aClusterId, EventId aEventId, bool aUrgentEvent = false) :
30 0 : mClusterId(aClusterId), mEventId(aEventId), mEndpointId(aEndpointId), mIsUrgentEvent(aUrgentEvent)
31 0 : {}
32 0 : EventPathParams() {}
33 : bool IsSamePath(const EventPathParams & other) const
34 : {
35 : return other.mEndpointId == mEndpointId && other.mClusterId == mClusterId && other.mEventId == mEventId;
36 : }
37 :
38 893 : bool IsWildcardPath() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardEventId(); }
39 :
40 : // For event, an event id can only be interpreted if the cluster id is known.
41 511 : bool IsValidEventPath() const { return !(HasWildcardClusterId() && !HasWildcardEventId()); }
42 :
43 4196 : inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; }
44 4675 : inline bool HasWildcardClusterId() const { return mClusterId == kInvalidClusterId; }
45 3846 : inline bool HasWildcardEventId() const { return mEventId == kInvalidEventId; }
46 : inline void SetWildcardEndpointId() { mEndpointId = kInvalidEndpointId; }
47 : inline void SetWildcardClusterId() { mClusterId = kInvalidClusterId; }
48 : inline void SetWildcardEventId() { mEventId = kInvalidEventId; }
49 :
50 2261 : bool IsEventPathSupersetOf(const ConcreteEventPath & other) const
51 : {
52 2261 : VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
53 2236 : VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
54 2229 : VerifyOrReturnError(HasWildcardEventId() || mEventId == other.mEventId, false);
55 :
56 2185 : return true;
57 : }
58 :
59 : ClusterId mClusterId = kInvalidClusterId; // uint32
60 : EventId mEventId = kInvalidEventId; // uint32
61 : EndpointId mEndpointId = kInvalidEndpointId; // uint16
62 : bool mIsUrgentEvent = false; // uint8
63 : };
64 : } // namespace app
65 : } // namespace chip
|