Skip to content

Commit

Permalink
Cleanup tv bindings, ACLs, fix tv-casting-app commissioning breakage (#…
Browse files Browse the repository at this point in the history
…16331)

* tv bindings

* fix CI tests

* fix merge bug

* address feedback

* address feedback
  • Loading branch information
chrisdecenzo authored and pull[bot] committed Apr 1, 2022
1 parent 7fc071e commit 1715051
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 72 deletions.
358 changes: 327 additions & 31 deletions examples/tv-casting-app/linux/main.cpp

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/access/examples/ExampleAccessControlDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,6 @@ class EntryStorage
static constexpr uint8_t kTagPrivilege = 4;
static constexpr uint8_t kTagSubjects = 5;
static constexpr uint8_t kTagTargets = 6;
// This value was chosen to be large enough to contain the data, but has not been fine-tuned.
static const size_t kStorageBufferSize = 192;

CHIP_ERROR Serialize(chip::PersistentStorageDelegate * storage, const char * key)
{
Expand Down Expand Up @@ -602,6 +600,13 @@ class EntryStorage
static constexpr size_t kMaxSubjects = CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_SUBJECTS_PER_ENTRY;
static constexpr size_t kMaxTargets = CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_TARGETS_PER_ENTRY;

static constexpr uint8_t kApproxSizeSubject = 9;
static constexpr uint8_t kApproxSizeTarget = 8;
static constexpr uint8_t kApproxSizeEntry = 4;
// This value was chosen to be large enough to contain the data, but has not been fine-tuned.
static const size_t kStorageBufferSize =
kEntriesPerFabric * (kApproxSizeEntry + kApproxSizeSubject * kMaxSubjects + kApproxSizeTarget * kMaxTargets);

bool mInUse;
FabricIndex mFabricIndex;
AuthMode mAuthMode;
Expand Down
9 changes: 5 additions & 4 deletions src/app/app-platform/ContentAppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ constexpr EndpointId kTargetBindingClusterEndpointId = 0;
constexpr EndpointId kLocalVideoPlayerEndpointId = 1;
constexpr EndpointId kLocalSpeakerEndpointId = 2;
constexpr ClusterId kNoClusterIdSpecified = kInvalidClusterId;
constexpr ClusterId kClusterIdDescriptor = 0x001d;
constexpr ClusterId kClusterIdOnOff = 0x0006;
constexpr ClusterId kClusterIdWakeOnLAN = 0x0503;
// constexpr ClusterId kClusterIdChannel = 0x0504;
Expand Down Expand Up @@ -425,7 +426,7 @@ CHIP_ERROR ContentAppPlatform::ManageClientAccess(OperationalDeviceProxy * targe

/**
* Here we are creating a single ACL entry containing:
* a) selection of clusters on video player endpoint (7 targets)
* a) selection of clusters on video player endpoint (8 targets)
* b) speaker endpoint (1 target)
* c) selection of content app endpoints (0 to many)
* d) single subject which is the casting app
Expand All @@ -438,9 +439,9 @@ CHIP_ERROR ContentAppPlatform::ManageClientAccess(OperationalDeviceProxy * targe

ChipLogProgress(Controller, "Create video player endpoint ACL and binding");
{
std::list<ClusterId> allowedClusterList = { kClusterIdOnOff, kClusterIdWakeOnLAN, kClusterIdMediaPlayback,
kClusterIdLowPower, kClusterIdKeypadInput, kClusterIdContentLauncher,
kClusterIdAudioOutput };
std::list<ClusterId> allowedClusterList = { kClusterIdDescriptor, kClusterIdOnOff, kClusterIdWakeOnLAN,
kClusterIdMediaPlayback, kClusterIdLowPower, kClusterIdKeypadInput,
kClusterIdContentLauncher, kClusterIdAudioOutput };

for (const auto & clusterId : allowedClusterList)
{
Expand Down
9 changes: 0 additions & 9 deletions src/app/clusters/bindings/BindingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,6 @@ void BindingManager::FabricRemoved(CompressedFabricId compressedFabricId, Fabric
mInitParams.mCASESessionManager->ReleaseSessionsForFabric(compressedFabricId);
}

CHIP_ERROR BindingManager::NotifyBindingAdded(const EmberBindingTableEntry & binding)
{
if (mBindingAddedHandler)
{
mBindingAddedHandler(binding);
}
return CHIP_NO_ERROR;
}

CHIP_ERROR BindingManager::NotifyBoundClusterChanged(EndpointId endpoint, ClusterId cluster, void * context)
{
VerifyOrReturnError(mInitParams.mFabricTable != nullptr, CHIP_ERROR_INCORRECT_STATE);
Expand Down
17 changes: 0 additions & 17 deletions src/app/clusters/bindings/BindingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ struct BindingManagerInitParams
PersistentStorageDelegate * mStorage = nullptr;
};

using BindingAddedHandler = void (*)(const EmberBindingTableEntry & binding);

/**
*
* The BindingManager class manages the connections for unicast bindings and notifies the application
Expand All @@ -71,15 +69,6 @@ class BindingManager
{}

void RegisterBoundDeviceChangedHandler(BoundDeviceChangedHandler handler) { mBoundDeviceChangedHandler = handler; }
CHIP_ERROR RegisterBindingAddedHandler(BindingAddedHandler handler)
{
if (mBindingAddedHandler == nullptr)
{
mBindingAddedHandler = handler;
return CHIP_NO_ERROR;
}
return CHIP_ERROR_INCORRECT_STATE;
}

CHIP_ERROR Init(const BindingManagerInitParams & params);

Expand Down Expand Up @@ -113,11 +102,6 @@ class BindingManager
*/
CHIP_ERROR NotifyBoundClusterChanged(EndpointId endpoint, ClusterId cluster, void * context);

/*
* Notify the BindingAddedHandler that a binding was added.
*/
CHIP_ERROR NotifyBindingAdded(const EmberBindingTableEntry & binding);

static BindingManager & GetInstance() { return sBindingManager; }

private:
Expand All @@ -134,7 +118,6 @@ class BindingManager
PendingNotificationMap mPendingNotificationMap;
BoundDeviceChangedHandler mBoundDeviceChangedHandler;
BindingManagerInitParams mInitParams;
BindingAddedHandler mBindingAddedHandler;

Callback::Callback<OnDeviceConnected> mOnConnectedCallback;
Callback::Callback<OnDeviceConnectionFailure> mOnConnectionFailureCallback;
Expand Down
13 changes: 12 additions & 1 deletion src/app/clusters/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class BindingTableAccess : public AttributeAccessInterface
private:
CHIP_ERROR ReadBindingTable(EndpointId endpoint, AttributeValueEncoder & encoder);
CHIP_ERROR WriteBindingTable(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder);

CHIP_ERROR NotifyBindingsChanged();
};

BindingTableAccess gAttrAccess;
Expand Down Expand Up @@ -191,6 +193,7 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
{
CreateBindingEntry(iter.GetValue(), path.mEndpointId);
}
LogErrorOnFailure(NotifyBindingsChanged());
return CHIP_NO_ERROR;
}
else if (path.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)
Expand All @@ -202,10 +205,19 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
CreateBindingEntry(target, path.mEndpointId);
LogErrorOnFailure(NotifyBindingsChanged());
return CHIP_NO_ERROR;
}
return CHIP_IM_GLOBAL_STATUS(UnsupportedWrite);
}

CHIP_ERROR BindingTableAccess::NotifyBindingsChanged()
{
DeviceLayer::ChipDeviceEvent event;
event.Type = DeviceLayer::DeviceEventType::kBindingsChangedViaCluster;
return chip::DeviceLayer::PlatformMgr().PostEvent(&event);
}

} // namespace

void MatterBindingPluginServerInitCallback()
Expand All @@ -228,5 +240,4 @@ void AddBindingEntry(const EmberBindingTableEntry & entry)
}

BindingTable::GetInstance().Add(entry);
BindingManager::GetInstance().NotifyBindingAdded(entry);
}
5 changes: 5 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ enum PublicEventTypes
* Signals that DNS-SD platform layer was initialized and is ready to operate.
*/
kDnssdPlatformInitialized,

/**
* Signals that bindings were updated.
*/
kBindingsChangedViaCluster,
};

/**
Expand Down
17 changes: 9 additions & 8 deletions src/include/platform/PlatformManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ class PlatformManager
CHIP_ERROR GetSupportedCalendarTypes(
AttributeList<app::Clusters::TimeFormatLocalization::CalendarType, kMaxCalendarTypes> & supportedCalendarTypes);

/*
* PostEvent can be called safely on any thread without locking the stack.
* When called from a thread that is not doing the stack work item
* processing, the event might get dispatched (on the work item processing
* thread) before PostEvent returns.
*/
[[nodiscard]] CHIP_ERROR PostEvent(const ChipDeviceEvent * event);
void PostEventOrDie(const ChipDeviceEvent * event);

private:
bool mInitialized = false;
PlatformManagerDelegate * mDelegate = nullptr;
Expand Down Expand Up @@ -239,14 +248,6 @@ class PlatformManager
friend class Internal::GenericConfigurationManagerImpl;
friend class System::PlatformEventing;

/*
* PostEvent can be called safely on any thread without locking the stack.
* When called from a thread that is not doing the stack work item
* processing, the event might get dispatched (on the work item processing
* thread) before PostEvent returns.
*/
[[nodiscard]] CHIP_ERROR PostEvent(const ChipDeviceEvent * event);
void PostEventOrDie(const ChipDeviceEvent * event);
void DispatchEvent(const ChipDeviceEvent * event);
CHIP_ERROR StartChipTimer(System::Clock::Timeout duration);

Expand Down

0 comments on commit 1715051

Please sign in to comment.