Skip to content

Commit

Permalink
Cleaned up APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Dec 21, 2023
1 parent bb5cf22 commit 763424e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
21 changes: 20 additions & 1 deletion examples/tv-casting-app/linux/simple-app-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * ca
}

// read an attribute
matter::casting::memory::Strong<matter::casting::clusters::media_playback::MediaPlaybackCluster> mediaPlaybackCluster =
/*matter::casting::memory::Strong<matter::casting::clusters::media_playback::MediaPlaybackCluster> mediaPlaybackCluster =
endpoints[index]->GetCluster<matter::casting::clusters::media_playback::MediaPlaybackCluster>();
if (mediaPlaybackCluster != nullptr)
{
Expand All @@ -150,6 +150,25 @@ void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * ca
{
ChipLogProgress(AppServer, "currentStateAttribute was nullpr");
}
}*/

// subscribe to an attribute
matter::casting::memory::Strong<matter::casting::clusters::media_playback::MediaPlaybackCluster> mediaPlaybackCluster =
endpoints[index]->GetCluster<matter::casting::clusters::media_playback::MediaPlaybackCluster>();
if (mediaPlaybackCluster != nullptr)
{
matter::casting::core::Attribute<chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo> *
currentStateAttribute = static_cast<
matter::casting::core::Attribute<chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo> *>(
mediaPlaybackCluster->GetAttribute(chip::app::Clusters::MediaPlayback::Attributes::CurrentState::Id));
if (currentStateAttribute != nullptr)
{
currentStateAttribute->Subscribe(nullptr, OnCurrentStateReadSuccess, OnCurrentStateReadFailure, 0, 1);
}
else
{
ChipLogProgress(AppServer, "currentStateAttribute was nullpr");
}
}
}
else
Expand Down
18 changes: 4 additions & 14 deletions examples/tv-casting-app/tv-casting-common/core/Attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,12 @@ class Attribute
CHIP_ERROR err = mediaClusterBase.template WriteAttribute<TypeInfo>(
_attributeContext->mRequestData, _attributeContext,
// Write success handler
[](void * context, typename TypeInfo::DecodableArgType response) {
[](void * context) {
WriteAttributeContext<typename TypeInfo::Type> * _attributeContext =
static_cast<WriteAttributeContext<typename TypeInfo::Type> *>(context);
ChipLogProgress(AppServer, "<Attribute>::Write() success");
Attribute<TypeInfo> * _attribute = static_cast<Attribute<TypeInfo> *>(_attributeContext->mAttribute);
_attribute->value = response;
if (_attribute->hasValue)
{
_attributeContext->mSuccessCb(_attributeContext->mClientContext,
chip::MakeOptional(_attribute->value), response);
}
else
{
_attribute->hasValue = true;
_attributeContext->mSuccessCb(_attributeContext->mClientContext, chip::NullOptional, response);
}
_attributeContext->mSuccessCb(_attributeContext->mClientContext);
delete _attributeContext;
},
// Write failure handler
Expand Down Expand Up @@ -243,7 +233,7 @@ class Attribute
if (endpoint)
{
SubscribeAttributeContext<typename TypeInfo::DecodableArgType> * attributeContext =
new SubscribeAttributeContext<typename TypeInfo::DecodableArgType>(this, endpoint, context, successCb, failureCb);
new SubscribeAttributeContext<typename TypeInfo::DecodableArgType>(this, endpoint, context, successCb, failureCb, minIntervalFloorSeconds, maxIntervalCeilingSeconds);

endpoint->GetCastingPlayer()->FindOrEstablishSession(
attributeContext,
Expand Down Expand Up @@ -287,7 +277,7 @@ class Attribute
_attributeContext->mFailureCb(_attributeContext->mClientContext, error);
delete _attributeContext;
},
_attributeContext->minIntervalFloorSeconds, _attributeContext->maxIntervalCeilingSeconds,
_attributeContext->mMinIntervalFloorSeconds, _attributeContext->mMaxIntervalCeilingSeconds,
nullptr /* SubscriptionEstablishedCallback */, nullptr /* ResubscriptionAttemptCallback */,
true /* aIsFabricFiltered */, true /* aKeepPreviousSubscriptions */);

Expand Down

0 comments on commit 763424e

Please sign in to comment.