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

v1.3 Commissioner Passcode field for Linux and Android tv-casting-apps #33038

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ private String getCastingPlayerButtonText(CastingPlayer player) {
? (aux.isEmpty() ? "" : ", ") + "Device Type: " + player.getDeviceType()
: "";
aux += (aux.isEmpty() ? "" : ", ") + "Resolved IP?: " + (player.getIpAddresses().size() > 0);
aux +=
(aux.isEmpty() ? "" : ", ")
+ "Commissioner Passcode: "
+ (player.getCommissionerPasscode());

aux = aux.isEmpty() ? aux : "\n" + aux;
return main + aux;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface CastingPlayer {

long getDeviceType();

short getCommissionerPasscode();

List<Endpoint> getEndpoints();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class MatterCastingPlayer implements CastingPlayer {
private int productId;
private int vendorId;
private long deviceType;
private short commissionerPasscode;
protected long _cppCastingPlayer;

public MatterCastingPlayer(
Expand All @@ -59,7 +60,8 @@ public MatterCastingPlayer(
int port,
int productId,
int vendorId,
long deviceType) {
long deviceType,
short commissionerPasscode) {
this.connected = connected;
this.deviceId = deviceId;
this.hostName = hostName;
Expand All @@ -70,6 +72,7 @@ public MatterCastingPlayer(
this.productId = productId;
this.vendorId = vendorId;
this.deviceType = deviceType;
this.commissionerPasscode = commissionerPasscode;
}

/**
Expand Down Expand Up @@ -131,6 +134,11 @@ public long getDeviceType() {
return this.deviceType;
}

@Override
public short getCommissionerPasscode() {
return this.commissionerPasscode;
}

@Override
public native List<Endpoint> getEndpoints();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::Strong<core::
// Get the constructor for the com/matter/casting/core/MatterCastingPlayer Java class
jmethodID constructor =
env->GetMethodID(matterCastingPlayerJavaClass, "<init>",
"(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJ)V");
"(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJS)V");
if (constructor == nullptr)
{
ChipLogError(AppServer, "convertCastingPlayerFromCppToJava() could not locate MatterCastingPlayer Java class constructor");
Expand Down Expand Up @@ -182,11 +182,11 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::Strong<core::

// Create a new instance of the MatterCastingPlayer Java class
jobject jMatterCastingPlayer = nullptr;
jMatterCastingPlayer = env->NewObject(matterCastingPlayerJavaClass, constructor, static_cast<jboolean>(player->IsConnected()),
env->NewStringUTF(player->GetId()), env->NewStringUTF(player->GetHostName()),
env->NewStringUTF(player->GetDeviceName()), env->NewStringUTF(player->GetInstanceName()),
jIpAddressList, (jint) (player->GetPort()), (jint) (player->GetProductId()),
(jint) (player->GetVendorId()), (jlong) (player->GetDeviceType()));
jMatterCastingPlayer = env->NewObject(
matterCastingPlayerJavaClass, constructor, static_cast<jboolean>(player->IsConnected()), env->NewStringUTF(player->GetId()),
env->NewStringUTF(player->GetHostName()), env->NewStringUTF(player->GetDeviceName()),
env->NewStringUTF(player->GetInstanceName()), jIpAddressList, (jint) (player->GetPort()), (jint) (player->GetProductId()),
(jint) (player->GetVendorId()), (jlong) (player->GetDeviceType()), static_cast<jbyte>(player->GetCommissionerPasscode()));
if (jMatterCastingPlayer == nullptr)
{
ChipLogError(AppServer, "convertCastingPlayerFromCppToJava(): Could not create MatterCastingPlayer Java object");
Expand Down
3 changes: 2 additions & 1 deletion examples/tv-casting-app/linux/simple-app-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DiscoveryDelegateImpl * DiscoveryDelegateImpl::GetInstance()

void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player)
{
ChipLogProgress(AppServer, "DiscoveryDelegateImpl::HandleOnAdded() called");
if (commissionersCount == 0)
{
ChipLogProgress(AppServer, "Select discovered Casting Player (start index = 0) to request commissioning");
Expand All @@ -58,7 +59,7 @@ void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter

void DiscoveryDelegateImpl::HandleOnUpdated(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player)
{
ChipLogProgress(AppServer, "Updated CastingPlayer with ID: %s", player->GetId());
ChipLogProgress(AppServer, "DiscoveryDelegateImpl::HandleOnUpdated() Updated CastingPlayer with ID: %s", player->GetId());
}

void InvokeContentLauncherLaunchURL(matter::casting::memory::Strong<matter::casting::core::Endpoint> endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ bool CastingPlayer::ContainsDesiredEndpoint(core::CastingPlayer * cachedCastingP

void CastingPlayer::LogDetail() const
{
ChipLogProgress(AppServer, "CastingPlayer::LogDetail() called");
if (strlen(mAttributes.id) != 0)
{
ChipLogDetail(AppServer, "\tID: %s", mAttributes.id);
Expand Down Expand Up @@ -281,6 +282,7 @@ void CastingPlayer::LogDetail() const
{
ChipLogDetail(AppServer, "\tDevice Type: %" PRIu32, mAttributes.deviceType);
}
ChipLogDetail(AppServer, "\tCommissioner Passcode: %u", mAttributes.commissionerPasscode);
if (mAttributes.nodeId > 0)
{
ChipLogDetail(AppServer, "\tNode ID: 0x" ChipLogFormatX64, ChipLogValueX64(mAttributes.nodeId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ class CastingPlayerAttributes
char deviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {};
char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {};
char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {};
unsigned int numIPs; // number of valid IP addresses
unsigned int numIPs; // Number of valid IP addresses
chip::Inet::IPAddress ipAddresses[chip::Dnssd::CommonResolutionData::kMaxIPAddresses];
chip::Inet::InterfaceId interfaceId;
uint16_t port;
uint16_t productId;
uint16_t vendorId;
uint32_t deviceType;
uint8_t commissionerPasscode = 0; // Indicates whether a CastingPlayer supports the Commissioner-Generated Passcode feature.

chip::NodeId nodeId = 0;
chip::FabricIndex fabricIndex = 0;
Expand Down Expand Up @@ -182,6 +183,8 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>

uint32_t GetDeviceType() const { return mAttributes.deviceType; }

uint8_t GetCommissionerPasscode() const { return mAttributes.commissionerPasscode; }

chip::NodeId GetNodeId() const { return mAttributes.nodeId; }

chip::FabricIndex GetFabricIndex() const { return mAttributes.fabricIndex; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover
{
attributes.ipAddresses[j] = nodeData.resolutionData.ipAddress[j];
}
attributes.interfaceId = nodeData.resolutionData.interfaceId;
attributes.port = nodeData.resolutionData.port;
attributes.productId = nodeData.nodeData.productId;
attributes.vendorId = nodeData.nodeData.vendorId;
attributes.deviceType = nodeData.nodeData.deviceType;
attributes.interfaceId = nodeData.resolutionData.interfaceId;
attributes.port = nodeData.resolutionData.port;
attributes.productId = nodeData.nodeData.productId;
attributes.vendorId = nodeData.nodeData.vendorId;
attributes.deviceType = nodeData.nodeData.deviceType;
attributes.commissionerPasscode = nodeData.nodeData.commissionerPasscode;

memory::Strong<CastingPlayer> player = std::make_shared<CastingPlayer>(attributes);

Expand Down
10 changes: 10 additions & 0 deletions examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ std::vector<core::CastingPlayer> CastingStore::ReadAll()
continue;
}

if (castingPlayerContainerTagNum == kCastingPlayerCommissionerPasscodeTag)
{
err = reader.Get(attributes.commissionerPasscode);
VerifyOrReturnValue(err == CHIP_NO_ERROR, std::vector<core::CastingPlayer>(),
ChipLogError(AppServer, "TLVReader.Get failed %" CHIP_ERROR_FORMAT, err.Format()));
continue;
}

if (castingPlayerContainerTagNum == kCastingPlayerPortTag)
{
err = reader.Get(attributes.port);
Expand Down Expand Up @@ -472,6 +480,8 @@ CHIP_ERROR CastingStore::WriteAll(std::vector<core::CastingPlayer> castingPlayer
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerVendorIdTag), castingPlayer.GetVendorId()));
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerProductIdTag), castingPlayer.GetProductId()));
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerDeviceTypeIdTag), castingPlayer.GetDeviceType()));
ReturnErrorOnFailure(
tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerCommissionerPasscodeTag), castingPlayer.GetCommissionerPasscode()));
ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerPortTag), castingPlayer.GetPort()));
ReturnErrorOnFailure(tlvWriter.PutBytes(chip::TLV::ContextTag(kCastingPlayerInstanceNameTag),
(const uint8_t *) castingPlayer.GetInstanceName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CastingStore : public chip::FabricTable::Delegate
kCastingPlayerPortTag,
kCastingPlayerInstanceNameTag,
kCastingPlayerDeviceNameTag,
kCastingPlayerCommissionerPasscodeTag,
kCastingPlayerHostNameTag,

kCastingPlayerEndpointsContainerTag,
Expand Down
Loading