Skip to content

Commit

Permalink
Addressed comments by sharadb-amazon, added CP field to CastingStore
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Apr 18, 2024
1 parent a62b7fe commit 33ffe7a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ private String getCastingPlayerButtonText(CastingPlayer player) {
aux += (aux.isEmpty() ? "" : ", ") + "Resolved IP?: " + (player.getIpAddresses().size() > 0);
aux +=
(aux.isEmpty() ? "" : ", ")
+ "Commissioner Passcode Supported?: "
+ (player.isCommissionerPasscodeSupported());
+ "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,7 +49,7 @@ public interface CastingPlayer {

long getDeviceType();

boolean isCommissionerPasscodeSupported();
short getCommissionerPasscode();

List<Endpoint> getEndpoints();

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

public MatterCastingPlayer(
Expand All @@ -61,7 +61,7 @@ public MatterCastingPlayer(
int productId,
int vendorId,
long deviceType,
boolean commissionerPasscodeSupported) {
short commissionerPasscode) {
this.connected = connected;
this.deviceId = deviceId;
this.hostName = hostName;
Expand All @@ -72,7 +72,7 @@ public MatterCastingPlayer(
this.productId = productId;
this.vendorId = vendorId;
this.deviceType = deviceType;
this.commissionerPasscodeSupported = commissionerPasscodeSupported;
this.commissionerPasscode = commissionerPasscode;
}

/**
Expand Down Expand Up @@ -135,8 +135,8 @@ public long getDeviceType() {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,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;IIIJZ)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 @@ -158,12 +158,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()), static_cast<jboolean>(player->IsCommissionerPasscodeSupported()));
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
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void CastingPlayer::LogDetail() const
{
ChipLogDetail(AppServer, "\tDevice Type: %" PRIu32, mAttributes.deviceType);
}
ChipLogDetail(AppServer, "\tCommissioner Passcode feature supported: %u", mAttributes.commissionerPasscode);
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 @@ -114,11 +114,6 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
*/
bool IsConnected() const { return mConnectionState == CASTING_PLAYER_CONNECTED; }

/**
* @return true if this CastingPlayer supports the Commissioner-Generated Passcode feature.
*/
bool IsCommissionerPasscodeSupported() const { return mAttributes.commissionerPasscode != 0; }

/**
* @brief Verifies that a connection exists with this CastingPlayer, or triggers a new session
* request. If the CastingApp does not have the nodeId and fabricIndex of this CastingPlayer cached on disk,
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 == kCastingCommissionerPasscodeTag)
{
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(kCastingCommissionerPasscodeTag), 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,
kCastingCommissionerPasscodeTag,
kCastingPlayerHostNameTag,

kCastingPlayerEndpointsContainerTag,
Expand Down

0 comments on commit 33ffe7a

Please sign in to comment.