Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux tv-casting-app v1.3 Commissioner-Generated passcode flow #33479

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "core/CastingApp.h" // from tv-casting-common
#include "core/CastingPlayer.h" // from tv-casting-common
#include "core/CastingPlayerDiscovery.h" // from tv-casting-common
#include "core/ConnectionCallbacks.h" // from tv-casting-common

#include <app/clusters/bindings/BindingManager.h>
#include <app/server/Server.h>
Expand Down Expand Up @@ -92,24 +93,36 @@ JNI_METHOD(jobject, verifyOrEstablishConnection)
MatterCastingPlayerJNIMgr().mConnectionSuccessHandler.SetUp(env, jSuccessCallback);
MatterCastingPlayerJNIMgr().mConnectionFailureHandler.SetUp(env, jFailureCallback);

// TODO: In the following PRs. Add optional CommissionerDeclarationHandler callback parameter.
castingPlayer->VerifyOrEstablishConnection(
[](CHIP_ERROR err, CastingPlayer * playerPtr) {
ChipLogProgress(AppServer, "MatterCastingPlayer-JNI::verifyOrEstablishConnection() ConnectCallback called");
if (err == CHIP_NO_ERROR)
{
ChipLogProgress(AppServer, "MatterCastingPlayer-JNI:: Connected to Casting Player with device ID: %s",
playerPtr->GetId());
MatterCastingPlayerJNIMgr().mConnectionSuccessHandler.Handle(nullptr);
}
else
{
ChipLogError(AppServer, "MatterCastingPlayer-JNI:: ConnectCallback, connection error: %" CHIP_ERROR_FORMAT,
err.Format());
MatterCastingPlayerJNIMgr().mConnectionFailureHandler.Handle(err);
}
},
static_cast<unsigned long long int>(commissioningWindowTimeoutSec), idOptions);
auto connectCallback = [](CHIP_ERROR err, CastingPlayer * playerPtr) {
ChipLogProgress(AppServer, "MatterCastingPlayer-JNI::verifyOrEstablishConnection() ConnectCallback()");
if (err == CHIP_NO_ERROR)
{
ChipLogProgress(AppServer,
"MatterCastingPlayer-JNI::verifyOrEstablishConnection() ConnectCallback() Connected to Casting Player "
"with device ID: %s",
playerPtr->GetId());
// The Java jSuccessCallback is expecting a Void v callback parameter which translates to a nullptr. When calling the
// Java method from C++ via JNI, passing nullptr is equivalent to passing a Void object in Java.
MatterCastingPlayerJNIMgr().mConnectionSuccessHandler.Handle(nullptr);
pgregorr-amazon marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
ChipLogError(
AppServer,
"MatterCastingPlayer-JNI::verifyOrEstablishConnection() ConnectCallback() Connection error: %" CHIP_ERROR_FORMAT,
err.Format());
MatterCastingPlayerJNIMgr().mConnectionFailureHandler.Handle(err);
}
};

// TODO: In the following PRs. Add optional CommissionerDeclarationHandler callback parameter for the Commissioner-Generated
// passcode commissioning flow.
matter::casting::core::ConnectionCallbacks connectionCallbacks;
connectionCallbacks.mOnConnectionComplete = connectCallback;

// TODO: Verify why commissioningWindowTimeoutSec is a "unsigned long long int" type. Seems too big.
castingPlayer->VerifyOrEstablishConnection(connectionCallbacks,
static_cast<unsigned long long int>(commissioningWindowTimeoutSec), idOptions);
pgregorr-amazon marked this conversation as resolved.
Show resolved Hide resolved
return support::convertMatterErrorFromCppToJava(CHIP_NO_ERROR);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#import "MCEndpoint_Internal.h"
#import "MCErrorUtils.h"

#import "core/CastingPlayer.h"
#import "core/CastingPlayer.h" // from tv-casting-common
#import "core/ConnectionCallbacks.h" // from tv-casting-common

#import <Foundation/Foundation.h>

Expand All @@ -47,7 +48,7 @@ - (void)verifyOrEstablishConnectionWithCompletionBlock:(void (^_Nonnull)(NSError

- (void)verifyOrEstablishConnectionWithCompletionBlock:(void (^_Nonnull)(NSError * _Nullable))completion timeout:(long long)timeout desiredEndpointFilter:(MCEndpointFilter * _Nullable)desiredEndpointFilter
{
ChipLogProgress(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCompletionBlock called");
ChipLogProgress(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCompletionBlock() called");
VerifyOrReturn([[MCCastingApp getSharedInstance] isRunning], ChipLogError(AppServer, "MCCastingApp NOT running"));

dispatch_queue_t workQueue = [[MCCastingApp getSharedInstance] getWorkQueue];
Expand All @@ -63,18 +64,23 @@ - (void)verifyOrEstablishConnectionWithCompletionBlock:(void (^_Nonnull)(NSError

CHIP_ERROR result = idOptions.addTargetAppInfo(targetAppInfo);
if (result != CHIP_NO_ERROR) {
ChipLogError(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCompletionBlock failed to add targetAppInfo: %" CHIP_ERROR_FORMAT, result.Format());
ChipLogError(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCompletionBlock() failed to add targetAppInfo: %" CHIP_ERROR_FORMAT, result.Format());
}
}

// TODO: In the following PRs. Add optional CommissionerDeclarationHandler callback parameter.
_cppCastingPlayer->VerifyOrEstablishConnection(
[completion](CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer) {
dispatch_queue_t clientQueue = [[MCCastingApp getSharedInstance] getClientQueue];
dispatch_async(clientQueue, ^{
completion(err == CHIP_NO_ERROR ? nil : [MCErrorUtils NSErrorFromChipError:err]);
});
}, timeout, idOptions);
void (^connectCallback)(CHIP_ERROR, matter::casting::core::CastingPlayer *) = ^(CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer) {
ChipLogProgress(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCompletionBlock() ConnectCallback()");
dispatch_queue_t clientQueue = [[MCCastingApp getSharedInstance] getClientQueue];
dispatch_async(clientQueue, ^{
completion(err == CHIP_NO_ERROR ? nil : [MCErrorUtils NSErrorFromChipError:err]);
});
};

matter::casting::core::ConnectionCallbacks connectionCallbacks;
connectionCallbacks.mOnConnectionComplete = connectCallback;

// TODO: In the following PRs. Add optional CommissionerDeclarationHandler callback parameter for the Commissioner-Generated passcode commissioning flow.
_cppCastingPlayer->VerifyOrEstablishConnection(connectionCallbacks, timeout, idOptions);
});
}

Expand Down
Loading
Loading