Skip to content

Commit

Permalink
Fixing style issues 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Jun 20, 2024
1 parent 477978f commit a04cbde
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
* @brief Verifies that a connection exists with this CastingPlayer, or triggers a new
* commissioning session request. If the CastingApp does not have the nodeId and fabricIndex
* of this CastingPlayer cached on disk, this will execute the User Directed Commissioning
* (UDC) process by sending an IdentificationDeclaration message to the Commissioner. This method will run verifyOrEstablishConnection() with a default timeout of MCCastingPlayer.kMinCommissioningWindowTimeoutSec.
* (UDC) process by sending an IdentificationDeclaration message to the Commissioner. This method
* will run verifyOrEstablishConnection() with a default timeout of
* MCCastingPlayer.kMinCommissioningWindowTimeoutSec.
* @param identificationDeclarationOptions (Optional) Parameters in the IdentificationDeclaration
* message sent by the Commissionee to the Commissioner. These parameters specify the
* information relating to the requested commissioning session.
Expand All @@ -94,7 +96,10 @@
* @brief Verifies that a connection exists with this CastingPlayer, or triggers a new
* commissioning session request. If the CastingApp does not have the nodeId and fabricIndex
* of this CastingPlayer cached on disk, this will execute the User Directed Commissioning
* (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.
* (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.
* @return nil if request submitted successfully, otherwise a NSError object corresponding to the error.
* @see verifyOrEstablishConnectionWithCallbacks:timeout:identificationDeclarationOptions:
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ - (NSError *)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _
dispatch_sync(workQueue, ^{
matter::casting::core::IdentificationDeclarationOptions cppIdOptions = [self setupCppIdOptions:identificationDeclarationOptions];

// Handles the connection complete event and calls the MCConnectionCallbacks connectionCompleteCallback callback provided by the Swift client. This callback is called by the cpp layer when the connection process has ended, regardless of whether it was successful or not.
// Handles the connection complete event and calls the MCConnectionCallbacks connectionCompleteCallback callback provided by
// the Swift client. This callback is called by the cpp layer when the connection process has ended, regardless of whether it
// was successful or not.
void (^connectCallback)(CHIP_ERROR, matter::casting::core::CastingPlayer *) = ^(CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer) {
ChipLogProgress(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCallbacks() connectCallback() called");
dispatch_queue_t clientQueue = [[MCCastingApp getSharedInstance] getClientQueue];
Expand All @@ -90,15 +92,20 @@ - (NSError *)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _
}
});
};
// Handles the Commissioner Declaration event and calls the MCConnectionCallbacks commissionerDeclarationCallback callback provided by the Swift client. This callback is called by the cpp layer when the Commissionee receives a CommissionerDeclaration message from the CastingPlayer/Commissioner.
void (^commissionerDeclarationCallback)(const chip::Transport::PeerAddress & source, const chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration cppCommissionerDeclaration) = ^(const chip::Transport::PeerAddress & source, const chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration cppCommissionerDeclaration) {
// Handles the Commissioner Declaration event and calls the MCConnectionCallbacks commissionerDeclarationCallback callback
// provided by the Swift client. This callback is called by the cpp layer when the Commissionee receives a
// CommissionerDeclaration message from the CastingPlayer/Commissioner.
void (^commissionerDeclarationCallback)(const chip::Transport::PeerAddress & source, const chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration cppCommissionerDeclaration) = ^(const chip::Transport::PeerAddress &
source,
const chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration cppCommissionerDeclaration) {
ChipLogProgress(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCallbacks() commissionerDeclarationCallback() called with cpp CommissionerDeclaration message");
dispatch_queue_t clientQueue = [[MCCastingApp getSharedInstance] getClientQueue];
dispatch_async(clientQueue, ^{
if (connectionCallbacks.commissionerDeclarationCallback) {
// convert cppCommissionerDeclaration to a shared_ptr<CommissionerDeclaration> and pass it to the client callback
auto cppCommissionerDeclarationPtr = std::make_shared<chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration>(cppCommissionerDeclaration);
MCCommissionerDeclaration * objcCommissionerDeclaration = [[MCCommissionerDeclaration alloc] initWithCppCommissionerDeclaration:cppCommissionerDeclarationPtr];
MCCommissionerDeclaration * objcCommissionerDeclaration = [[MCCommissionerDeclaration alloc]
initWithCppCommissionerDeclaration:cppCommissionerDeclarationPtr];
connectionCallbacks.commissionerDeclarationCallback(objcCommissionerDeclaration);
} else {
ChipLogError(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCallbacks() commissionerDeclarationCallback(), client failed to set the optional commissionerDeclarationCallback() callback");
Expand Down Expand Up @@ -134,7 +141,8 @@ - (NSError *)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _
- (NSError *)continueConnecting
{
ChipLogProgress(AppServer, "MCCastingPlayer.continueConnecting() called");
VerifyOrReturnValue([[MCCastingApp getSharedInstance] isRunning], [MCErrorUtils NSErrorFromChipError:CHIP_ERROR_INCORRECT_STATE], ChipLogError(AppServer, "MCCastingPlayer.continueConnecting() MCCastingApp NOT running"));
VerifyOrReturnValue([[MCCastingApp getSharedInstance] isRunning], [MCErrorUtils NSErrorFromChipError:CHIP_ERROR_INCORRECT_STATE],
ChipLogError(AppServer, "MCCastingPlayer.continueConnecting() MCCastingApp NOT running"));

ChipLogProgress(AppServer, "MCCastingPlayer.continueConnecting() calling MCCastingApp.updateCommissionableDataProvider()");
NSError * updateError = [[MCCastingApp getSharedInstance] updateCommissionableDataProvider];
Expand All @@ -146,7 +154,8 @@ - (NSError *)continueConnecting
err = _cppCastingPlayer->ContinueConnecting();
});
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "MCCastingPlayer.continueConnecting() call to cppCastingPlayer->ContinueConnecting() failed due to %" CHIP_ERROR_FORMAT, err.Format());
ChipLogError(AppServer, "MCCastingPlayer.continueConnecting() call to cppCastingPlayer->ContinueConnecting() failed due to %" CHIP_ERROR_FORMAT,
err.Format());
return [MCErrorUtils NSErrorFromChipError:err];
}
return nil;
Expand All @@ -163,7 +172,8 @@ - (NSError *)stopConnecting
err = _cppCastingPlayer->StopConnecting();
});
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "MCCastingPlayer.continueConnecting() call to cppCastingPlayer->StopConnecting() failed due to %" CHIP_ERROR_FORMAT, err.Format());
ChipLogError(AppServer, "MCCastingPlayer.continueConnecting() call to cppCastingPlayer->StopConnecting() failed due to %" CHIP_ERROR_FORMAT,
err.Format());
return [MCErrorUtils NSErrorFromChipError:err];
}
return nil;
Expand Down Expand Up @@ -205,7 +215,8 @@ + (MCCastingPlayer * _Nullable)getTargetCastingPlayer
- (NSString * _Nonnull)description
{
return [NSString stringWithFormat:@"%@ with Product ID: %hu and Vendor ID: %hu. Resolved IPAddr?: %@. Supports Commissioner-Generated Passcode?: %@.",
self.deviceName, self.productId, self.vendorId, self.ipAddresses != nil && self.ipAddresses.count > 0 ? @"YES" : @"NO", self.supportsCommissionerGeneratedPasscode ? @"YES" : @"NO"];
self.deviceName, self.productId, self.vendorId, self.ipAddresses != nil && self.ipAddresses.count > 0 ? @"YES" : @"NO",
self.supportsCommissionerGeneratedPasscode ? @"YES" : @"NO"];
}

- (NSString * _Nonnull)identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,26 @@
@interface MCConnectionCallbacks : NSObject

/**
* @param connectionCompleteCallback (Required) The callback called when the connection process has ended, regardless of whether it was successful or not.
* @param commissionerDeclarationCallback (Optional) The callback called when the Client/Commissionee receives a CommissionerDeclaration message from the CastingPlayer/Commissioner. This callback is needed to support UDC features where a reply from the Commissioner is expected. It provides information indicating the Commissioner’s pre-commissioning state.
* @param connectionCompleteCallback (Required) The callback called when the connection process
* has ended, regardless of whether it was successful or not.
* @param commissionerDeclarationCallback (Optional) The callback called when the Client/Commissionee
* receives a CommissionerDeclaration message from the CastingPlayer/Commissioner. This callback is
* needed to support UDC features where a reply from the Commissioner is expected. It provides information
* indicating the Commissioner’s pre-commissioning state.
*
* For example: During CastingPlayer/Commissioner-Generated passcode commissioning, the Commissioner replies with a CommissionerDeclaration message with PasscodeDialogDisplayed and CommissionerPasscode set to true. Given these Commissioner state details, the client is expected to perform some actions and responf accrdingly.
* For example: During CastingPlayer/Commissioner-Generated passcode commissioning, the Commissioner
* replies with a CommissionerDeclaration message with PasscodeDialogDisplayed and CommissionerPasscode
* set to true. Given these Commissioner state details, the client is expected to perform some actions
* and responf accrdingly.
*
* @return A new instance of MCConnectionCallbacks.
*/
- (instancetype _Nonnull)initWithCallbacks:(void (^_Nonnull)(NSError * _Nonnull))connectionCompleteCallback
commissionerDeclarationCallback:(void (^_Nullable)(MCCommissionerDeclaration * _Nonnull))commissionerDeclarationCallback;

/**
* The callback called when the connection process has ended, regardless of whether it was successful or not.
* The callback called when the connection process has ended, regardless of whether it was
* successful or not.
*/
@property void (^_Nullable connectionCompleteCallback)(NSError * _Nonnull);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

/**
* This class contains the optional parameters used in the IdentificationDeclaration Message, sent
* by the Commissionee (CastingApp) to the Commissioner (CastingPlayer). The options specify information relating to the
* requested UDC commissioning session.
* by the Commissionee (CastingApp) to the Commissioner (CastingPlayer). The options specify
* information relating to the requested UDC commissioning session.
*/
@interface MCIdentificationDeclarationOptions : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ class MCConnectionExampleViewModel: ObservableObject {
self.displayPasscodeInputDialog(on: topViewController, continueConnecting: { passcode in
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Continuing to connect with user entered MCCastingPlayer/Commissioner-Generated passcode: \(passcode)")

// Update the CommissionableData in the client defined MCAppParametersDataSource with the user entered CastingPlayer/Commissioner-Generated setup passcode. This is mandatory for the Commissioner-Generated passcode commissioning flow since the commissioning session's PAKE verifier needs to be updated with the entered passcode. Get the singleton instane of the MCInitializationExample.
// Update the CommissionableData in the client defined MCAppParametersDataSource with the user
// entered CastingPlayer/Commissioner-Generated setup passcode. This is mandatory for the
// Commissioner-Generated passcode commissioning flow since the commissioning session's PAKE
// verifier needs to be updated with the entered passcode. Get the singleton instane of the
// MCInitializationExample.
let initializationExample = MCInitializationExample.shared
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback calling MCInitializationExample.getAppParametersDataSource()")
if let dataSource = initializationExample.getAppParametersDataSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class MCInitializationExample {
let Log = Logger(subsystem: "com.matter.casting",
category: "MCInitializationExample")

// We store the client defined instance of the MCAppParametersDataSource passed to CastingApp.initialize(). MCAppParametersDataSource may need to be updated by the client in case of the Casting Player/Commissioner-Generated passcode commissioning flow.
// We store the client defined instance of the MCAppParametersDataSource passed to CastingApp.initialize().
// MCAppParametersDataSource may need to be updated by the client in case of the Casting
// Player/Commissioner-Generated passcode commissioning flow.
private var appParametersDataSource: MCAppParametersDataSource?

private init() {
Expand Down

0 comments on commit a04cbde

Please sign in to comment.