Skip to content

Commit

Permalink
Read type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Dec 20, 2023
1 parent c2eac3d commit b3ce7c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions examples/tv-casting-app/linux/simple-app-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void OnLaunchURLFailure(void * context, CHIP_ERROR error)
}

void OnCurrentStateReadSuccess(void * context,
chip::Optional<chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo::Type> before,
chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo::Type after)
chip::Optional<chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo::DecodableArgType> before,
chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo::DecodableArgType after)
{
ChipLogProgress(AppServer, "OnCurrentStateReadSuccess");
/* ChipLogProgress(AppServer, "OnCurrentStateReadSuccess with response: %.*s",
Expand Down
36 changes: 18 additions & 18 deletions examples/tv-casting-app/tv-casting-common/core/Attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ namespace core {

using WriteAttributeCallback = std::function<void(void * context, CHIP_ERROR)>;

template <typename T>
using ReadResponseSuccessCallbackFn = std::function<void(void * context, chip::Optional<T> before, T after)>;
template <typename TypeInfoDecodableArgType>
using ReadResponseSuccessCallbackFn = std::function<void(void * context, chip::Optional<TypeInfoDecodableArgType> before, TypeInfoDecodableArgType after)>;
using ReadResponseFailureCallbackFn = std::function<void(void * context, CHIP_ERROR err)>;

template <typename T>
template <typename TypeInfoDecodableArgType>
struct ReadAttributeContext
{
ReadAttributeContext(void * attribute, memory::Strong<core::Endpoint> endpoint, void * clientContext,
ReadResponseSuccessCallbackFn<typename T::DecodableArgType> successCb,
ReadResponseSuccessCallbackFn<TypeInfoDecodableArgType> successCb,
ReadResponseFailureCallbackFn failureCb, bool aIsFabricFiltered) :
mEndpoint(endpoint),
mClientContext(clientContext), mSuccessCb(successCb), mFailureCb(failureCb), mAIsFabricFiltered(aIsFabricFiltered)
Expand All @@ -49,20 +49,20 @@ struct ReadAttributeContext
void * mAttribute;
memory::Strong<core::Endpoint> mEndpoint;
void * mClientContext;
ReadResponseSuccessCallbackFn<typename T::DecodableArgType> mSuccessCb;
ReadResponseSuccessCallbackFn<TypeInfoDecodableArgType> mSuccessCb;
ReadResponseFailureCallbackFn mFailureCb;
bool mAIsFabricFiltered = true;
};

class BaseCluster;

template <typename T>
template <typename TypeInfo>
class Attribute
{
private:
memory::Weak<BaseCluster> mCluster;
bool hasValue = false;
typename T::DecodableArgType value;
typename TypeInfo::DecodableArgType value;

protected:
memory::Strong<BaseCluster> GetCluster() const { return mCluster.lock(); }
Expand All @@ -76,34 +76,34 @@ class Attribute
Attribute(Attribute & other) = delete;
void operator=(const Attribute &) = delete;

chip::Optional<T> GetValue() { return hasValue ? chip::MakeOptional(value) : chip::NullOptional; }
chip::Optional<typename TypeInfo::DecodableArgType> GetValue() { return hasValue ? chip::MakeOptional(value) : chip::NullOptional; }

void Read(void * context, ReadResponseSuccessCallbackFn<typename T::DecodableArgType> successCb,
void Read(void * context, ReadResponseSuccessCallbackFn<typename TypeInfo::DecodableArgType> successCb,
ReadResponseFailureCallbackFn failureCb, bool aIsFabricFiltered = true)
{
memory::Strong<core::Endpoint> endpoint = GetCluster()->GetEndpoint().lock();
if (endpoint)
{
ReadAttributeContext<T> * readAttributeContext =
new ReadAttributeContext<T>(this, endpoint, context, successCb, failureCb, aIsFabricFiltered);
ReadAttributeContext<typename TypeInfo::DecodableArgType> * readAttributeContext =
new ReadAttributeContext<typename TypeInfo::DecodableArgType>(this, endpoint, context, successCb, failureCb, aIsFabricFiltered);

endpoint->GetCastingPlayer()->FindOrEstablishSession(
readAttributeContext,
// FindOrEstablishSession success handler
[](void * context, chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle) {
ReadAttributeContext<T> * _readAttributeContext = static_cast<ReadAttributeContext<T> *>(context);
ReadAttributeContext<typename TypeInfo::DecodableArgType> * _readAttributeContext = static_cast<ReadAttributeContext<typename TypeInfo::DecodableArgType> *>(context);
ChipLogProgress(AppServer, "<Attribute>::Read() Found or established session");

// Read attribute
support::MediaClusterBase mediaClusterBase(exchangeMgr, sessionHandle,
_readAttributeContext->mEndpoint->GetId());
CHIP_ERROR err = mediaClusterBase.template ReadAttribute<T>(
CHIP_ERROR err = mediaClusterBase.template ReadAttribute<TypeInfo>(
_readAttributeContext,
// Read success handler
[](void * context, typename T::DecodableArgType response) {
ReadAttributeContext<T> * _readAttributeContext = static_cast<ReadAttributeContext<T> *>(context);
[](void * context, typename TypeInfo::DecodableArgType response) {
ReadAttributeContext<typename TypeInfo::DecodableArgType> * _readAttributeContext = static_cast<ReadAttributeContext<typename TypeInfo::DecodableArgType> *>(context);
ChipLogProgress(AppServer, "<Attribute>::Read() success");
Attribute<T> * _attribute = static_cast<Attribute<T> *>(_readAttributeContext->mAttribute);
Attribute<TypeInfo> * _attribute = static_cast<Attribute<TypeInfo> *>(_readAttributeContext->mAttribute);
_attribute->value = response;
if (_attribute->hasValue)
{
Expand All @@ -120,7 +120,7 @@ class Attribute
},
// Read failure handler
[](void * context, CHIP_ERROR error) {
ReadAttributeContext<T> * _readAttributeContext = static_cast<ReadAttributeContext<T> *>(context);
ReadAttributeContext<typename TypeInfo::DecodableArgType> * _readAttributeContext = static_cast<ReadAttributeContext<typename TypeInfo::DecodableArgType> *>(context);
ChipLogError(AppServer,
"<Attribute>::Read() failure response on EndpointId: %d with error: "
"%" CHIP_ERROR_FORMAT,
Expand All @@ -143,7 +143,7 @@ class Attribute
},
// FindOrEstablishSession failure handler
[](void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error) {
ReadAttributeContext<T> * _readAttributeContext = static_cast<ReadAttributeContext<T> *>(context);
ReadAttributeContext<typename TypeInfo::DecodableArgType> * _readAttributeContext = static_cast<ReadAttributeContext<typename TypeInfo::DecodableArgType> *>(context);
ChipLogError(AppServer,
"<Attribute>::Read() failure in retrieving session info for peerId.nodeId: "
"0x" ChipLogFormatX64 ", peer.fabricIndex: %d with error: %" CHIP_ERROR_FORMAT,
Expand Down

0 comments on commit b3ce7c0

Please sign in to comment.