Skip to content

Commit 477978f

Browse files
Addressed comments by sharadb-amazon
1 parent 0ed7d51 commit 477978f

22 files changed

+290
-127
lines changed

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/ConnectionCallbacks.java

+24-7
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,40 @@
1313
*/
1414
package com.matter.casting.support;
1515

16-
/** @brief A container struct for User Directed Commissioning (UDC) callbacks. */
16+
/** @brief A container class for User Directed Commissioning (UDC) callbacks. */
1717
public class ConnectionCallbacks {
1818

19-
/** (Required) The callback called when the connection is established successfully. */
19+
/** The callback called when the connection is established successfully. */
2020
public final MatterCallback<Void> onSuccess;
2121

22-
/** (Required) The callback called with MatterError when the connection is fails to establish. */
22+
/** The callback called with MatterError when the connection is fails to establish. */
2323
public final MatterCallback<MatterError> onFailure;
2424

2525
/**
26-
* (Optional) The callback called when the Client/Commissionee receives a CommissionerDeclaration
27-
* message from the CastingPlayer/Commissioner. This callback is needed to support UDC features
28-
* where a reply from the Commissioner is expected. It provides information indicating the
29-
* Commissioner’s pre-commissioning state.
26+
* The callback called when the Client/Commissionee receives a CommissionerDeclaration message
27+
* from the CastingPlayer/Commissioner. This callback is needed to support UDC features where a
28+
* reply from the Commissioner is expected. It provides information indicating the Commissioner’s
29+
* pre-commissioning state.
3030
*/
3131
public MatterCallback<CommissionerDeclaration> onCommissionerDeclaration;
3232

33+
/**
34+
* The constructor for ConnectionCallbacks, the container class for User Directed Commissioning
35+
* (UDC) callbacks.
36+
*
37+
* @param onSuccess (Required) The callback called when the connection is established
38+
* successfully.
39+
* @param onFailure (Required) The callback called with MatterError when the connection is fails
40+
* to establish.
41+
* @param onCommissionerDeclaration (Optional) The callback called when the Client/Commissionee
42+
* receives a CommissionerDeclaration message from the CastingPlayer/Commissioner. This
43+
* callback is needed to support UDC features where a reply from the Commissioner is expected.
44+
* It provides information indicating the Commissioner’s pre-commissioning state.
45+
* <p>For example: During CastingPlayer/Commissioner-Generated passcode commissioning, the
46+
* Commissioner replies with a CommissionerDeclaration message with PasscodeDialogDisplayed
47+
* and CommissionerPasscode set to true. Given these Commissioner state details, the client is
48+
* expected to perform some actions and responf accrdingly.
49+
*/
3350
public ConnectionCallbacks(
3451
MatterCallback<Void> onSuccess,
3552
MatterCallback<MatterError> onFailure,

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/IdentificationDeclarationOptions.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
/**
2121
* This class contains the optional parameters used in the IdentificationDeclaration Message, sent
22-
* by the Commissionee to the Commissioner. The options specify information relating to the
23-
* requested UDC commissioning session.
22+
* by the Commissionee (CastingApp) to the Commissioner (CastingPlayer). The options specify
23+
* information relating to the requested UDC commissioning session.
2424
*/
2525
public class IdentificationDeclarationOptions {
2626
private final String TAG = IdentificationDeclarationOptions.class.getSimpleName();

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

+7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ class MatterCastingPlayerJNI
5050
private:
5151
friend MatterCastingPlayerJNI & MatterCastingPlayerJNIMgr();
5252
static MatterCastingPlayerJNI sInstance;
53+
54+
// Handles the connection complete event and calls the ConnectionCallbacks onSuccess or onFailure callback provided by the Java
55+
// client. This callback is called by the cpp layer when the connection process has ended, regardless of whether it was
56+
// successful or not.
5357
static void ConnectCallback(CHIP_ERROR err, CastingPlayer * playerPtr);
58+
// Handles the Commissioner Declaration event and calls the ConnectionCallbacks onCommissionerDeclaration callback provided by
59+
// the Java client. This callback is called by the cpp layer when the Commissionee receives a CommissionerDeclaration message
60+
// from the CastingPlayer/Commissioner.
5461
static void CommissionerDeclarationCallback(const chip::Transport::PeerAddress & source,
5562
chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration cd);
5663
};

examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
39589F162B91556B00BE040C /* MCInteractionModelStructs.h in Headers */ = {isa = PBXBuildFile; fileRef = 39589F152B91556B00BE040C /* MCInteractionModelStructs.h */; };
1313
39589F182B91557700BE040C /* MCInteractionModelStructs.mm in Sources */ = {isa = PBXBuildFile; fileRef = 39589F172B91557700BE040C /* MCInteractionModelStructs.mm */; };
1414
395BF6AF2C18EC7C00C73CE2 /* MCTargetAppInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 395BF6AE2C18EC7C00C73CE2 /* MCTargetAppInfo.mm */; };
15+
397099D92C2255FE00B34428 /* MCCastingApp_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 397099D82C2255FE00B34428 /* MCCastingApp_Internal.h */; };
1516
399BCE1E2C13CBAD0075AA85 /* MCTargetAppInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 399BCE1D2C13CBAD0075AA85 /* MCTargetAppInfo.h */; };
1617
39BF57C52B8CFF790081653C /* MCAttributeObjects.h in Headers */ = {isa = PBXBuildFile; fileRef = 39BF57C42B8CFF790081653C /* MCAttributeObjects.h */; };
1718
39BF57C72B8CFFB90081653C /* MCAttributeObjects.mm in Sources */ = {isa = PBXBuildFile; fileRef = 39BF57C62B8CFFB90081653C /* MCAttributeObjects.mm */; };
@@ -96,6 +97,7 @@
9697
39589F152B91556B00BE040C /* MCInteractionModelStructs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCInteractionModelStructs.h; sourceTree = "<group>"; };
9798
39589F172B91557700BE040C /* MCInteractionModelStructs.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCInteractionModelStructs.mm; sourceTree = "<group>"; };
9899
395BF6AE2C18EC7C00C73CE2 /* MCTargetAppInfo.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCTargetAppInfo.mm; sourceTree = "<group>"; };
100+
397099D82C2255FE00B34428 /* MCCastingApp_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCastingApp_Internal.h; sourceTree = "<group>"; };
99101
399049A62B9FC4ED000C91F0 /* MCCommandPayloads_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCommandPayloads_Internal.h; sourceTree = "<group>"; };
100102
399BCE1D2C13CBAD0075AA85 /* MCTargetAppInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCTargetAppInfo.h; sourceTree = "<group>"; };
101103
39BF57C42B8CFF790081653C /* MCAttributeObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAttributeObjects.h; sourceTree = "<group>"; };
@@ -275,6 +277,7 @@
275277
395241F42B854EA700F7DB91 /* zap-generated */,
276278
3CCB87202869085400771BAD /* MatterTvCastingBridge.h */,
277279
3CF71C092A992D0D003A5CE5 /* MCCastingApp.h */,
280+
397099D82C2255FE00B34428 /* MCCastingApp_Internal.h */,
278281
3CF71C0B2A992D25003A5CE5 /* MCCastingApp.mm */,
279282
3C2346222B362B9500FA276E /* MCCastingPlayerDiscovery.h */,
280283
3C2346242B362BBB00FA276E /* MCCastingPlayerDiscovery.mm */,
@@ -347,6 +350,7 @@
347350
39BF57CD2B8FC0EF0081653C /* MCClusterObjects.h in Headers */,
348351
39D4D2502B97942D00BF3CFE /* MCCommandObjects.h in Headers */,
349352
3C621CA52B605A6A005CDBA3 /* MCAttribute.h in Headers */,
353+
397099D92C2255FE00B34428 /* MCCastingApp_Internal.h in Headers */,
350354
3CD73F1C2A9E8396009D82D1 /* MCCommissionableDataProvider.h in Headers */,
351355
3C4F521E2B4F4B3B00BB8A10 /* MCEndpoint_Internal.h in Headers */,
352356
39BF57C92B8D66540081653C /* NSStringSpanConversion.h in Headers */,

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

-10
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@
4242
*/
4343
- (NSError * _Nullable)initializeWithDataSource:(id<MCDataSource> _Nonnull)dataSource;
4444

45-
/**
46-
* @brief Updates the MCCommissionableDataProvider stored in this CastingApp with the new CommissionableData
47-
* to be used for the next commissioning session. Calling this function is mandatory for the
48-
* Casting Player/Commissioner-Generated passcode commissioning flow, since the commissioning session's PAKE
49-
* verifier needs to be updated with the user entered passcode.
50-
*
51-
* @param newCommissionableData the new MCCommissionableData to be used for the next commissioning session.
52-
*/
53-
- (NSError * _Nullable)updateCommissionableDataProvider:(MCCommissionableData * _Nonnull)newCommissionableData;
54-
5545
/**
5646
* @brief (async) Starts the Matter server that the MCCastingApp runs on and registers all the necessary delegates
5747
*/

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
#import "MCCastingApp.h"
18+
#import "MCCastingApp_Internal.h"
1919

2020
#import "MCCommissionableDataProvider.h"
2121
#import "MCCommonCaseDeviceServerInitParamsProvider.h"
@@ -43,8 +43,7 @@ @interface MCCastingApp ()
4343
// queue used to perform all work performed by the MatterTvCastingBridge
4444
@property (atomic) dispatch_queue_t workQueue;
4545

46-
// used to update the commissionableDataProvider post initialization, this is necessary for the
47-
// Commissioner-Generated passcode commissioning feature.
46+
// Client defiend data source used to initialize the MCCommissionableDataProvider and, if needed, update the MCCommissionableDataProvider post initialization. This is necessary for the Commissioner-Generated passcode commissioning feature.
4847
@property (nonatomic, strong) id<MCDataSource> dataSource;
4948

5049
@end
@@ -74,6 +73,7 @@ - (dispatch_queue_t)getClientQueue
7473
- (NSError *)initializeWithDataSource:(id)dataSource
7574
{
7675
ChipLogProgress(AppServer, "MCCastingApp.initializeWithDataSource() called");
76+
// store the data source provided by the client
7777
_dataSource = dataSource;
7878

7979
// get the clientQueue
@@ -109,14 +109,10 @@ - (NSError *)initializeWithDataSource:(id)dataSource
109109
return [MCErrorUtils NSErrorFromChipError:CHIP_NO_ERROR];
110110
}
111111

112-
- (NSError *)updateCommissionableDataProvider:(MCCommissionableData *)newCommissionableData
112+
- (NSError *)updateCommissionableDataProvider
113113
{
114114
ChipLogProgress(AppServer, "MCCastingApp.UpdateCommissionableDataProvider() called");
115115

116-
if (_dataSource) {
117-
[_dataSource update:newCommissionableData];
118-
}
119-
120116
_commissionableDataProvider = new matter::casting::support::MCCommissionableDataProvider();
121117
VerifyOrReturnValue(_commissionableDataProvider->Initialize(_dataSource) == CHIP_NO_ERROR,
122118
[MCErrorUtils NSErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#import "MCCastingApp.h"
19+
20+
#import <Foundation/Foundation.h>
21+
22+
#ifndef MCCastingApp_Internal_h
23+
#define MCCastingApp_Internal_h
24+
25+
@interface MCCastingApp ()
26+
27+
/**
28+
* @brief (Private internal method) Updates the MCCommissionableDataProvider stored in this CastingApp with the updated CommissionableData
29+
* to be used for the next commissioning session. Calling this function is mandatory for the
30+
* Casting Player/Commissioner-Generated passcode commissioning flow, since the commissioning session's PAKE
31+
* verifier needs to be updated with the user entered passcode.
32+
*/
33+
- (NSError *)updateCommissionableDataProvider;
34+
35+
@end
36+
37+
#endif /* MCCastingApp_Internal_h */

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

+32-13
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* expected to perform some actions, detailed in the continueConnecting() API below, and then
5151
* call the continueConnecting() API to complete the process.
5252
* @param timeout time (in sec) to keep the commissioning window open, if commissioning is required.
53-
* Needs to be >= CastingPlayer.kMinCommissioningWindowTimeoutSec.
53+
* Needs to be >= MCCastingPlayer.kMinCommissioningWindowTimeoutSec.
5454
* @param identificationDeclarationOptions (Optional) Parameters in the IdentificationDeclaration
5555
* message sent by the Commissionee to the Commissioner. These parameters specify the
5656
* information relating to the requested commissioning session.
@@ -60,26 +60,45 @@
6060
* list of optional parameters.
6161
* <p>Furthermore, attributes (such as VendorId) describe the TargetApp/Endpoint that the client
6262
* wants to interact with after commissioning. If this value is passed in,
63-
* verifyOrEstablishConnection() will force UDC, in case the desired TargetApp is not found in
63+
* verifyOrEstablishConnection() will force UDC, in case the desired TargetApp is not found in
6464
* the on-device cached information/CastingStore.
6565
* @return nil if request submitted successfully, otherwise a NSError object corresponding to the error.
6666
*/
67-
- (NSError *)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _Nonnull)connectionCallbacks
68-
timeout:(long)timeout
69-
identificationDeclarationOptions:(MCIdentificationDeclarationOptions * _Nullable)identificationDeclarationOptions;
67+
- (NSError * _Nullable)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _Nonnull)connectionCallbacks
68+
timeout:(long)timeout
69+
identificationDeclarationOptions:(MCIdentificationDeclarationOptions * _Nullable)identificationDeclarationOptions;
7070

7171
/**
72-
* @brief The simplified version of the verifyOrEstablishConnectionWithCallbacks() API above.
72+
* @brief Verifies that a connection exists with this CastingPlayer, or triggers a new
73+
* commissioning session request. If the CastingApp does not have the nodeId and fabricIndex
74+
* of this CastingPlayer cached on disk, this will execute the User Directed Commissioning
75+
* (UDC) process by sending an IdentificationDeclaration message to the Commissioner. This method will run verifyOrEstablishConnection() with a default timeout of MCCastingPlayer.kMinCommissioningWindowTimeoutSec.
76+
* @param identificationDeclarationOptions (Optional) Parameters in the IdentificationDeclaration
77+
* message sent by the Commissionee to the Commissioner. These parameters specify the
78+
* information relating to the requested commissioning session.
79+
* <p>For example: To invoke the CastingPlayer/Commissioner-Generated passcode commissioning
80+
* flow, the client would call this API with IdentificationDeclarationOptions containing
81+
* CommissionerPasscode set to true. See IdentificationDeclarationOptions.java for a complete
82+
* list of optional parameters.
83+
* <p>Furthermore, attributes (such as VendorId) describe the TargetApp/Endpoint that the client
84+
* wants to interact with after commissioning. If this value is passed in,
85+
* verifyOrEstablishConnection() will force UDC, in case the desired TargetApp is not found in
86+
* the on-device cached information/CastingStore.
7387
* @return nil if request submitted successfully, otherwise a NSError object corresponding to the error.
88+
* @see verifyOrEstablishConnectionWithCallbacks:timeout:identificationDeclarationOptions:
7489
*/
75-
- (NSError *)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _Nonnull)connectionCallbacks
76-
identificationDeclarationOptions:(MCIdentificationDeclarationOptions * _Nullable)identificationDeclarationOptions;
90+
- (NSError * _Nullable)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _Nonnull)connectionCallbacks
91+
identificationDeclarationOptions:(MCIdentificationDeclarationOptions * _Nullable)identificationDeclarationOptions;
7792

7893
/**
79-
* @brief The simplified version of the verifyOrEstablishConnectionWithCallbacks() API above.
94+
* @brief Verifies that a connection exists with this CastingPlayer, or triggers a new
95+
* commissioning session request. If the CastingApp does not have the nodeId and fabricIndex
96+
* of this CastingPlayer cached on disk, this will execute the User Directed Commissioning
97+
* (UDC) process by sending an IdentificationDeclaration message to the Commissioner. This method will run verifyOrEstablishConnection() with a default timeout of MCCastingPlayer.kMinCommissioningWindowTimeoutSec and MCIdentificationDeclarationOptions initailized with the defualt values.
8098
* @return nil if request submitted successfully, otherwise a NSError object corresponding to the error.
99+
* @see verifyOrEstablishConnectionWithCallbacks:timeout:identificationDeclarationOptions:
81100
*/
82-
- (NSError *)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _Nonnull)connectionCallbacks;
101+
- (NSError * _Nullable)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _Nonnull)connectionCallbacks;
83102

84103
/**
85104
* @brief This is a continuation of the CastingPlayer/Commissioner-Generated passcode
@@ -97,13 +116,13 @@
97116
* <p>5. Client prompted user to input Passcode from Commissioner.
98117
* <p>6. Client has updated the CastingApp's MCCommissionableDataProvider with the user entered
99118
* passcode via the following function call:
100-
* MCCastingApp.updateCommissionableDataProvider(MCCommissionableData). This updates the
119+
* MCDataSource.update(MCCommissionableData). This updates the
101120
* commissioning session's PAKE verifier with the user entered passcode.
102121
* <p>Note: The same connectionCallbacks and commissioningWindowTimeoutSec parameters passed
103122
* into verifyOrEstablishConnection() will be used.
104123
* @return nil if request submitted successfully, otherwise a NSError object corresponding to the error.
105124
*/
106-
- (NSError *)continueConnecting;
125+
- (NSError * _Nullable)continueConnecting;
107126

108127
/**
109128
* @brief This cancels the CastingPlayer/Commissioner-Generated passcode commissioning flow
@@ -117,7 +136,7 @@
117136
* VerifyOrEstablishConnection() API above since no connection is established.
118137
* @return nil if request submitted successfully, otherwise a NSError object corresponding to the error.
119138
*/
120-
- (NSError *)stopConnecting;
139+
- (NSError * _Nullable)stopConnecting;
121140

122141
/**
123142
* @brief Sets the internal connection state of this MCCastingPlayer to "disconnected"

0 commit comments

Comments
 (0)