Skip to content

Commit 1280960

Browse files
authored
Merge branch 'master' into nodiscard_prep
2 parents 7fd2f46 + 6251801 commit 1280960

34 files changed

+474
-115
lines changed

examples/dishwasher-app/silabs/include/ElectricalEnergyMeasurementInstance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "AppConfig.h"
2222
#include "AppEvent.h"
2323
#include "ElectricalPowerMeasurementDelegate.h"
24+
#include <app/clusters/electrical-energy-measurement-server/ElectricalEnergyMeasurementCluster.h>
2425
#include <app/clusters/electrical-energy-measurement-server/electrical-energy-measurement-server.h>
2526
#include <cmsis_os2.h>
2627

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,10 @@ MatterError verifyOrEstablishConnection(
177177
* @returns A String representation of the CastingPlayer's current connectation.
178178
*/
179179
String getConnectionStateNative();
180+
181+
/**
182+
* @brief Removes any fabric associated with this player in order to cause the UDC flow when
183+
* verifyOrEstablishConnection is called
184+
*/
185+
void removeFabric();
180186
}

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterCastingPlayer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ public MatterError continueConnecting() {
269269
@Override
270270
public native void disconnect();
271271

272+
@Override
273+
public native void removeFabric();
274+
272275
/**
273276
* @brief Get CastingPlayer's current ConnectionState.
274277
* @throws IllegalArgumentException or NullPointerException when native layer returns invalid

examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/MatterCastingPlayer-JNI.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ JNI_METHOD(void, disconnect)
165165
castingPlayer->Disconnect();
166166
}
167167

168+
JNI_METHOD(void, removeFabric)
169+
(JNIEnv * env, jobject thiz)
170+
{
171+
chip::DeviceLayer::StackLock lock;
172+
ChipLogProgress(AppServer, "MatterCastingPlayer-JNI::removeFabric()");
173+
174+
core::CastingPlayer * castingPlayer = support::convertCastingPlayerFromJavaToCpp(thiz);
175+
VerifyOrReturn(castingPlayer != nullptr,
176+
ChipLogError(AppServer, "MatterCastingPlayer-JNI::removeFabric() castingPlayer == nullptr"));
177+
178+
castingPlayer->RemoveFabric();
179+
}
180+
168181
JNI_METHOD(jstring, getConnectionStateNative)
169182
(JNIEnv * env, jobject thiz)
170183
{

examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ typedef enum {
158158
*/
159159
- (void)disconnect;
160160

161+
/**
162+
* @brief Removes any fabric associated with this player in order to cause the UDC flow when
163+
* verifyOrEstablishConnection is called
164+
*/
165+
- (void)removeFabric;
166+
161167
/**
162168
* @brief Get the CastingPlayer's connection state
163169
* @param state The current connection state that will be return.

examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ - (void)disconnect
190190
});
191191
}
192192

193+
- (void)removeFabric
194+
{
195+
ChipLogProgress(AppServer, "MCCastingPlayer.removeFabric() called");
196+
VerifyOrReturn([[MCCastingApp getSharedInstance] isRunning], ChipLogError(AppServer, "MCCastingPlayer.removeFabric() MCCastingApp NOT running"));
197+
198+
dispatch_queue_t workQueue = [[MCCastingApp getSharedInstance] getWorkQueue];
199+
dispatch_sync(workQueue, ^{
200+
_cppCastingPlayer->RemoveFabric();
201+
});
202+
}
203+
193204
- (NSError * _Nullable)getConnectionState:(MCCastingPlayerConnectionState * _Nonnull)state;
194205
{
195206
ChipLogProgress(AppServer, "MCCastingPlayer.getConnectionState() called");

examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ __attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/AP
168168
*/
169169
- (void)disconnect:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler;
170170

171+
/*!
172+
@brief Removes any fabric associated with this player in order to cause the UDC flow when verifyOrEstablishConnection is called.
173+
174+
@param clientQueue Queue to invoke callbacks on
175+
176+
@param requestSentHandler Called after the request has been sent
177+
*/
178+
- (void)removeFabric:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler;
179+
171180
/*!
172181
@brief Purge data cached by the Matter casting library
173182

examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,18 @@ - (void)disconnect:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nu
339339
});
340340
}
341341

342+
- (void)removeFabric:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler
343+
{
344+
ChipLogProgress(AppServer, "CastingServerBridge().removeFabric() called");
345+
MCCastingPlayer * castingPlayer = [MCCastingPlayer getTargetCastingPlayer];
346+
if (castingPlayer != nil) {
347+
[castingPlayer removeFabric];
348+
}
349+
dispatch_async(clientQueue, ^{
350+
requestSentHandler();
351+
});
352+
}
353+
342354
- (void)purgeCache:(dispatch_queue_t _Nonnull)clientQueue responseHandler:(void (^)(MatterError * _Nonnull))responseHandler
343355
{
344356
ChipLogProgress(AppServer, "CastingServerBridge().purgeCache() called");

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -119,40 +119,71 @@ void CastingPlayer::VerifyOrEstablishConnection(ConnectionCallbacks connectionCa
119119
ChipLogProgress(
120120
AppServer,
121121
"CastingPlayer::VerifyOrEstablishConnection() Attempting to Re-establish CASE with cached CastingPlayer");
122+
123+
// Preserve the IP addresses from the discovered CastingPlayer before overwriting with cached data
124+
unsigned int discoveredNumIPs = mAttributes.numIPs;
125+
chip::Inet::IPAddress discoveredIpAddresses[chip::Dnssd::CommonResolutionData::kMaxIPAddresses];
126+
for (unsigned int i = 0; i < discoveredNumIPs; i++)
127+
{
128+
discoveredIpAddresses[i] = mAttributes.ipAddresses[i];
129+
}
130+
chip::Inet::InterfaceId discoveredInterfaceId = mAttributes.interfaceId;
131+
122132
*this = cachedCastingPlayers[index];
123133
mConnectionState = CASTING_PLAYER_CONNECTING;
124134
mOnCompleted = connectionCallbacks.mOnConnectionComplete;
125135
mCommissioningWindowTimeoutSec = commissioningWindowTimeoutSec;
126136

127-
FindOrEstablishSession(
128-
nullptr,
129-
[](void * context, chip::Messaging::ExchangeManager & exchangeMgr, const chip::SessionHandle & sessionHandle) {
130-
ChipLogProgress(AppServer,
131-
"CastingPlayer::VerifyOrEstablishConnection() FindOrEstablishSession Connection to "
132-
"CastingPlayer successful");
133-
CastingPlayer::GetTargetCastingPlayer()->mConnectionState = CASTING_PLAYER_CONNECTED;
134-
135-
// this async call will Load all the endpoints with their respective attributes into the TargetCastingPlayer
136-
// persist the TargetCastingPlayer information into the CastingStore and call mOnCompleted()
137-
support::EndpointListLoader::GetInstance()->Initialize(&exchangeMgr, &sessionHandle);
138-
support::EndpointListLoader::GetInstance()->Load();
139-
},
140-
[](void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error) {
141-
ChipLogError(AppServer,
142-
"CastingPlayer::VerifyOrEstablishConnection() FindOrEstablishSession Connection to "
143-
"CastingPlayer failed");
144-
CastingPlayer::GetTargetCastingPlayer()->mConnectionState = CASTING_PLAYER_NOT_CONNECTED;
145-
CHIP_ERROR e = support::CastingStore::GetInstance()->Delete(*CastingPlayer::GetTargetCastingPlayer());
146-
if (e != CHIP_NO_ERROR)
147-
{
148-
ChipLogError(AppServer, "CastingStore::Delete() failed. Err: %" CHIP_ERROR_FORMAT, e.Format());
149-
}
150-
151-
VerifyOrReturn(CastingPlayer::GetTargetCastingPlayer()->mOnCompleted);
152-
CastingPlayer::GetTargetCastingPlayer()->mOnCompleted(error, nullptr);
153-
mTargetCastingPlayer.reset();
154-
});
155-
return; // FindOrEstablishSession called. Return early.
137+
// Restore the IP addresses from the discovered CastingPlayer
138+
mAttributes.numIPs = discoveredNumIPs;
139+
for (unsigned int i = 0; i < discoveredNumIPs; i++)
140+
{
141+
mAttributes.ipAddresses[i] = discoveredIpAddresses[i];
142+
}
143+
mAttributes.interfaceId = discoveredInterfaceId;
144+
ChipLogProgress(AppServer, "Restored discovered CastingPlayer numIPs: %u", mAttributes.numIPs);
145+
146+
// make sure to copy fields passed in which are needed for UDC
147+
mIdOptions = idOptions;
148+
mClientProvidedCommissionerDeclarationCallback = connectionCallbacks.mCommissionerDeclarationCallback != nullptr;
149+
150+
// don't attempt to connect with the cached CastingPlayer if the nodeId is not set
151+
// instead, fall through to trigger UDC
152+
if (mAttributes.nodeId != 0)
153+
{
154+
FindOrEstablishSession(
155+
nullptr,
156+
[](void * context, chip::Messaging::ExchangeManager & exchangeMgr,
157+
const chip::SessionHandle & sessionHandle) {
158+
ChipLogProgress(AppServer,
159+
"CastingPlayer::VerifyOrEstablishConnection() FindOrEstablishSession Connection to "
160+
"CastingPlayer successful");
161+
CastingPlayer::GetTargetCastingPlayer()->mConnectionState = CASTING_PLAYER_CONNECTED;
162+
163+
// this async call will Load all the endpoints with their respective attributes into the
164+
// TargetCastingPlayer.
165+
//
166+
// persist the TargetCastingPlayer information into the CastingStore and call mOnCompleted()
167+
support::EndpointListLoader::GetInstance()->Initialize(&exchangeMgr, &sessionHandle);
168+
support::EndpointListLoader::GetInstance()->Load();
169+
},
170+
[](void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error) {
171+
ChipLogError(AppServer,
172+
"CastingPlayer::VerifyOrEstablishConnection() FindOrEstablishSession Connection to "
173+
"CastingPlayer failed");
174+
CastingPlayer::GetTargetCastingPlayer()->mConnectionState = CASTING_PLAYER_NOT_CONNECTED;
175+
CHIP_ERROR e = support::CastingStore::GetInstance()->Delete(*CastingPlayer::GetTargetCastingPlayer());
176+
if (e != CHIP_NO_ERROR)
177+
{
178+
ChipLogError(AppServer, "CastingStore::Delete() failed. Err: %" CHIP_ERROR_FORMAT, e.Format());
179+
}
180+
181+
VerifyOrReturn(CastingPlayer::GetTargetCastingPlayer()->mOnCompleted);
182+
CastingPlayer::GetTargetCastingPlayer()->mOnCompleted(error, nullptr);
183+
mTargetCastingPlayer.reset();
184+
});
185+
return; // FindOrEstablishSession called. Return early.
186+
}
156187
}
157188
}
158189
}
@@ -315,6 +346,20 @@ void CastingPlayer::Disconnect()
315346
CastingPlayerDiscovery::GetInstance()->ClearCastingPlayersInternal();
316347
}
317348

349+
void CastingPlayer::RemoveFabric()
350+
{
351+
ChipLogProgress(AppServer, "CastingPlayer::RemoveFabric()");
352+
chip::Server::GetInstance().GetFabricTable().Delete(mAttributes.fabricIndex);
353+
mAttributes.fabricIndex = 0;
354+
mAttributes.nodeId = 0;
355+
356+
CHIP_ERROR err = support::CastingStore::GetInstance()->AddOrUpdate(*this);
357+
if (err != CHIP_NO_ERROR)
358+
{
359+
ChipLogError(AppServer, "CastingStore::AddOrUpdate() failed. Err: %" CHIP_ERROR_FORMAT, err.Format());
360+
}
361+
}
362+
318363
void CastingPlayer::RegisterEndpoint(const memory::Strong<Endpoint> endpoint)
319364
{
320365
ChipLogProgress(AppServer, "CastingPlayer::RegisterEndpoint() EndpointID: %d, VendorID: %d, ProductID: %d", endpoint->GetId(),

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
222222
*/
223223
void Disconnect();
224224

225+
/**
226+
* @brief Removes any fabric associated with this player in order to cause the UDC flow when
227+
* verifyOrEstablishConnection is called
228+
*
229+
* @note This method will set nodeId and fabricIndex to 0.
230+
*/
231+
void RemoveFabric();
232+
225233
/**
226234
* @brief Find an existing session for this CastingPlayer, or trigger a new session
227235
* request.

0 commit comments

Comments
 (0)