Skip to content

Commit

Permalink
Add initial event wildcard support (#12145)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored and pull[bot] committed Jul 20, 2023
1 parent b083f6f commit 1919601
Show file tree
Hide file tree
Showing 25 changed files with 237 additions and 199 deletions.
2 changes: 1 addition & 1 deletion src/app/AttributePathExpandIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool AttributePathExpandIterator::Next()
if (mEndpointIndex == UINT16_MAX)
{
// Special case: If this is a concrete path, we just return its value as-is.
if (!mpClusterInfo->HasWildcard())
if (!mpClusterInfo->HasAttributeWildcard())
{
mOutputPath.mEndpointId = mpClusterInfo->mEndpointId;
mOutputPath.mClusterId = mpClusterInfo->mClusterId;
Expand Down
52 changes: 0 additions & 52 deletions src/app/AttributePathParams.cpp

This file was deleted.

5 changes: 1 addition & 4 deletions src/app/AttributePathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <app/util/basic-types.h>

#include <app/ClusterInfo.h>
#include <app/MessageDef/AttributePathIB.h>

namespace chip {
namespace app {
Expand Down Expand Up @@ -51,9 +50,7 @@ struct AttributePathParams

AttributePathParams() {}

CHIP_ERROR BuildAttributePath(AttributePathIB::Builder & aBuilder) const;

bool HasWildcard() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId(); }
bool HasAttributeWildcard() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId(); }

/**
* SPEC 8.9.2.2
Expand Down
2 changes: 1 addition & 1 deletion src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ static_library("app") {
sources = [
"AttributePathExpandIterator.cpp",
"AttributePathExpandIterator.h",
"AttributePathParams.cpp",
"AttributePathParams.h",
"BufferedReadCallback.cpp",
"CASESessionManager.cpp",
Expand All @@ -49,6 +48,7 @@ static_library("app") {
"DeviceProxy.cpp",
"DeviceProxy.h",
"EventManagement.cpp",
"EventPathParams.h",
"InteractionModelEngine.cpp",
"MessageDef/ArrayBuilder.cpp",
"MessageDef/ArrayParser.cpp",
Expand Down
17 changes: 15 additions & 2 deletions src/app/ClusterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <app/ConcreteAttributePath.h>
#include <app/ConcreteEventPath.h>
#include <app/util/basic-types.h>
#include <assert.h>
#include <lib/core/Optional.h>
Expand All @@ -38,7 +39,7 @@ struct ClusterInfo
private:
// Allow AttributePathParams access these constants.
friend struct AttributePathParams;
friend struct ConcreteEventPath;
friend struct EventPathParams;

// The ClusterId, AttributeId and EventId are MEIs,
// 0xFFFF is not a valid manufacturer code, thus 0xFFFF'FFFF is not a valid MEI
Expand Down Expand Up @@ -68,15 +69,27 @@ struct ClusterInfo
return true;
}

bool HasWildcard() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId(); }
bool IsEventPathSupersetOf(const ConcreteEventPath & other) const
{
VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
VerifyOrReturnError(HasWildcardEventId() || mEventId == other.mEventId, false);

return true;
}

bool HasAttributeWildcard() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardAttributeId(); }
bool HasEventWildcard() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardEventId(); }
/**
* Check that the path meets some basic constraints of an attribute path: If list index is not wildcard, then field id must not
* be wildcard. This does not verify that the attribute being targeted is actually of list type when the list index is not
* wildcard.
*/
bool IsValidAttributePath() const { return HasWildcardListIndex() || !HasWildcardAttributeId(); }

// For event, an event id can only be interpreted if the cluster id is known.
bool IsValidEventPath() const { return !(HasWildcardClusterId() && !HasWildcardEventId()); }

inline bool HasWildcardNodeId() const { return mNodeId == kUndefinedNodeId; }
inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; }
inline bool HasWildcardClusterId() const { return mClusterId == kInvalidClusterId; }
Expand Down
5 changes: 0 additions & 5 deletions src/app/ConcreteEventPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#pragma once

#include <app/ClusterInfo.h>
#include <app/util/basic-types.h>

namespace chip {
Expand Down Expand Up @@ -51,10 +50,6 @@ struct ConcreteEventPath
return mEndpointId == other.mEndpointId && mClusterId == other.mClusterId && mEventId == other.mEventId;
}

bool IsValidEventPath() const { return !HasWildcardEventId(); }

inline bool HasWildcardEventId() const { return mEventId == ClusterInfo::kInvalidEventId; }

EndpointId mEndpointId = 0;
ClusterId mClusterId = 0;
EventId mEventId = 0;
Expand Down
10 changes: 4 additions & 6 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,18 @@ CHIP_ERROR EventManagement::CopyEvent(const TLVReader & aReader, TLVWriter & aWr

static bool IsInterestedEventPaths(EventLoadOutContext * eventLoadOutContext, const EventEnvelopeContext & event)
{
ClusterInfo * interestedEventPaths = eventLoadOutContext->mpInterestedEventPaths;
if (eventLoadOutContext->mCurrentEventNumber < eventLoadOutContext->mStartingEventNumber)
{
return false;
}
while (interestedEventPaths != nullptr)
ConcreteEventPath path(event.mEndpointId, event.mClusterId, event.mEventId);
for (auto * interestedPath = eventLoadOutContext->mpInterestedEventPaths; interestedPath != nullptr;
interestedPath = interestedPath->mpNext)
{
// TODO: Support wildcard event path
if (interestedEventPaths->mNodeId == event.mNodeId && interestedEventPaths->mEndpointId == event.mEndpointId &&
interestedEventPaths->mClusterId == event.mClusterId && interestedEventPaths->mEventId == event.mEventId)
if (interestedPath->IsEventPathSupersetOf(path))
{
return true;
}
interestedEventPaths = interestedEventPaths->mpNext;
}
return false;
}
Expand Down
28 changes: 17 additions & 11 deletions src/app/EventPathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,33 @@

#include <app/util/basic-types.h>

#include <app/ClusterInfo.h>

namespace chip {
namespace app {
struct EventPathParams
{
EventPathParams(NodeId aNodeId, EndpointId aEndpointId, ClusterId aClusterId, EventId aEventId, bool aIsUrgent) :
mNodeId(aNodeId), mEndpointId(aEndpointId), mClusterId(aClusterId), mEventId(aEventId), mIsUrgent(aIsUrgent)
{}
EventPathParams(EndpointId aEndpointId, ClusterId aClusterId, EventId aEventId) :
EventPathParams(0, aEndpointId, aClusterId, aEventId, false)
mEndpointId(aEndpointId), mClusterId(aClusterId), mEventId(aEventId)
{}
EventPathParams() {}
bool IsSamePath(const EventPathParams & other) const
{
return other.mNodeId == mNodeId && other.mEndpointId == mEndpointId && other.mClusterId == mClusterId &&
other.mEventId == mEventId;
return other.mEndpointId == mEndpointId && other.mClusterId == mClusterId && other.mEventId == mEventId;
}
NodeId mNodeId = 0;
EndpointId mEndpointId = 0;
ClusterId mClusterId = 0;
EventId mEventId = 0;
bool mIsUrgent = false;

bool HasEventWildcard() const { return HasWildcardEndpointId() || HasWildcardClusterId() || HasWildcardEventId(); }

// For event, an event id can only be interpreted if the cluster id is known.
bool IsValidEventPath() const { return !(HasWildcardClusterId() && !HasWildcardEventId()); }

inline bool HasWildcardEndpointId() const { return mEndpointId == kInvalidEndpointId; }
inline bool HasWildcardClusterId() const { return mClusterId == ClusterInfo::kInvalidClusterId; }
inline bool HasWildcardEventId() const { return mEventId == ClusterInfo::kInvalidEventId; }

EndpointId mEndpointId = kInvalidEndpointId;
ClusterId mClusterId = ClusterInfo::kInvalidClusterId;
EventId mEventId = ClusterInfo::kInvalidEventId;
};
} // namespace app
} // namespace chip
31 changes: 29 additions & 2 deletions src/app/MessageDef/AttributePathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,32 @@ AttributePathIB::Builder & AttributePathIB::Builder::EndOfAttributePathIB()
EndOfContainer();
return *this;
}
}; // namespace app
}; // namespace chip

CHIP_ERROR AttributePathIB::Builder::Encode(const AttributePathParams & aAttributePathParams)
{
if (!(aAttributePathParams.HasWildcardEndpointId()))
{
Endpoint(aAttributePathParams.mEndpointId);
}

if (!(aAttributePathParams.HasWildcardClusterId()))
{
Cluster(aAttributePathParams.mClusterId);
}

if (!(aAttributePathParams.HasWildcardAttributeId()))
{
Attribute(aAttributePathParams.mAttributeId);
}

if (!(aAttributePathParams.HasWildcardListIndex()))
{
ListIndex(aAttributePathParams.mListIndex);
}

EndOfAttributePathIB();
return GetError();
}

} // namespace app
} // namespace chip
5 changes: 4 additions & 1 deletion src/app/MessageDef/AttributePathIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ListParser.h"

#include <app/AppBuildConfig.h>
#include <app/AttributePathParams.h>
#include <app/util/basic-types.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPTLV.h>
Expand Down Expand Up @@ -192,7 +193,9 @@ class Builder : public ListBuilder
* @return A reference to *this
*/
AttributePathIB::Builder & EndOfAttributePathIB();

CHIP_ERROR Encode(const AttributePathParams & aAttributePathParams);
};
}; // namespace AttributePathIB
} // namespace AttributePathIB
} // namespace app
} // namespace chip
1 change: 0 additions & 1 deletion src/app/MessageDef/EventDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ CHIP_ERROR EventDataIB::Parser::ProcessEventPath(EventPathIB::Parser & aEventPat
err = aEventPath.GetEvent(&(aConcreteEventPath.mEventId));
VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_IM_MALFORMED_EVENT_PATH);

VerifyOrReturnError(aConcreteEventPath.IsValidEventPath(), CHIP_ERROR_IM_MALFORMED_EVENT_PATH);
return CHIP_NO_ERROR;
}

Expand Down
29 changes: 22 additions & 7 deletions src/app/MessageDef/EventPathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines EventPath parser and builder in CHIP interaction model
*
*/

#include "EventPathIB.h"

Expand Down Expand Up @@ -222,5 +217,25 @@ EventPathIB::Builder & EventPathIB::Builder::EndOfEventPathIB()
return *this;
}

}; // namespace app
}; // namespace chip
CHIP_ERROR EventPathIB::Builder::Encode(const EventPathParams & aEventPathParams)
{
if (!(aEventPathParams.HasWildcardEndpointId()))
{
Endpoint(aEventPathParams.mEndpointId);
}

if (!(aEventPathParams.HasWildcardClusterId()))
{
Cluster(aEventPathParams.mClusterId);
}

if (!(aEventPathParams.HasWildcardEventId()))
{
Event(aEventPathParams.mEventId);
}

EndOfEventPathIB();
return GetError();
}
} // namespace app
} // namespace chip
8 changes: 3 additions & 5 deletions src/app/MessageDef/EventPathIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file defines EventPath parser and builder in CHIP interaction model
*
*/

#pragma once

#include "ListBuilder.h"
#include "ListParser.h"

#include <app/AppBuildConfig.h>
#include <app/EventPathParams.h>
#include <app/util/basic-types.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPTLV.h>
Expand Down Expand Up @@ -175,6 +171,8 @@ class Builder : public ListBuilder
* @return A reference to *this
*/
EventPathIB::Builder & EndOfEventPathIB();

CHIP_ERROR Encode(const EventPathParams & aEventPathParams);
};
} // namespace EventPathIB
} // namespace app
Expand Down
Loading

0 comments on commit 1919601

Please sign in to comment.