Skip to content

Commit 2f039ed

Browse files
Addressed comments by sharadb-amazon
1 parent a94d74e commit 2f039ed

File tree

8 files changed

+228
-103
lines changed

8 files changed

+228
-103
lines changed

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ JNI_METHOD(jobject, verifyOrEstablishConnection)
5353
CastingPlayer * castingPlayer = support::convertCastingPlayerFromJavaToCpp(thiz);
5454
VerifyOrReturnValue(castingPlayer != nullptr, support::convertMatterErrorFromCppToJava(CHIP_ERROR_INVALID_ARGUMENT));
5555

56+
matter::casting::core::IdentificationDeclarationOptions idOptions;
57+
58+
// TODO: In the following PRs. Replace EndpointFilter Java class with IdentificationDeclarationOptions Java class.
5659
matter::casting::core::EndpointFilter desiredEndpointFilter;
5760
if (desiredEndpointFilterJavaObject != nullptr)
5861
{
62+
chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
63+
5964
// Convert the EndpointFilter Java class to a C++ EndpointFilter
6065
jclass endpointFilterJavaClass = env->GetObjectClass(desiredEndpointFilterJavaObject);
6166
jfieldID vendorIdFieldId = env->GetFieldID(endpointFilterJavaClass, "vendorId", "Ljava/lang/Integer;");
@@ -66,23 +71,26 @@ JNI_METHOD(jobject, verifyOrEstablishConnection)
6671
// "Ljava/util/List;");
6772

6873
// Value of 0 means unspecified
69-
desiredEndpointFilter.vendorId = vendorIdIntegerObject != nullptr
74+
targetAppInfo.vendorId = vendorIdIntegerObject != nullptr
7075
? static_cast<uint16_t>(env->CallIntMethod(
7176
vendorIdIntegerObject, env->GetMethodID(env->GetObjectClass(vendorIdIntegerObject), "intValue", "()I")))
7277
: 0;
73-
desiredEndpointFilter.productId = productIdIntegerObject != nullptr
78+
targetAppInfo.productId = productIdIntegerObject != nullptr
7479
? static_cast<uint16_t>(env->CallIntMethod(
7580
productIdIntegerObject, env->GetMethodID(env->GetObjectClass(productIdIntegerObject), "intValue", "()I")))
7681
: 0;
77-
// TODO: In following PRs. Translate the Java requiredDeviceTypes list to a C++ requiredDeviceTypes vector. For now we're
78-
// passing an empty list of DeviceTypeStruct.
82+
83+
CHIP_ERROR result = idOptions.addTargetAppInfo(targetAppInfo);
84+
if (result != CHIP_NO_ERROR)
85+
{
86+
ChipLogError(AppServer, "MatterCastingPlayer-JNI::verifyOrEstablishConnection() failed to add targetAppInfo: %" CHIP_ERROR_FORMAT, result.Format());
87+
}
7988
}
8089

8190
MatterCastingPlayerJNIMgr().mConnectionSuccessHandler.SetUp(env, jSuccessCallback);
8291
MatterCastingPlayerJNIMgr().mConnectionFailureHandler.SetUp(env, jFailureCallback);
8392

84-
// TODO: In the following PRs. Removed desiredEndpointFilter to fix Android app build issue. Replace desiredEndpointFilter with
85-
// optional IdentificationDeclarationOptions. Add optional CommissionerDeclarationHandler callback parameter.
93+
// TODO: In the following PRs. Add optional CommissionerDeclarationHandler callback parameter.
8694
castingPlayer->VerifyOrEstablishConnection(
8795
[](CHIP_ERROR err, CastingPlayer * playerPtr) {
8896
ChipLogProgress(AppServer, "MatterCastingPlayer-JNI::verifyOrEstablishConnection() ConnectCallback called");
@@ -99,7 +107,7 @@ JNI_METHOD(jobject, verifyOrEstablishConnection)
99107
MatterCastingPlayerJNIMgr().mConnectionFailureHandler.Handle(err);
100108
}
101109
},
102-
static_cast<unsigned long long int>(commissioningWindowTimeoutSec));
110+
static_cast<unsigned long long int>(commissioningWindowTimeoutSec), idOptions);
103111
return support::convertMatterErrorFromCppToJava(CHIP_NO_ERROR);
104112
}
105113

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,30 @@ - (void)verifyOrEstablishConnectionWithCompletionBlock:(void (^_Nonnull)(NSError
5252

5353
dispatch_queue_t workQueue = [[MCCastingApp getSharedInstance] getWorkQueue];
5454
dispatch_sync(workQueue, ^{
55+
matter::casting::core::IdentificationDeclarationOptions idOptions;
56+
57+
// TODO: In the following PRs. Replace EndpointFilter objC class with IdentificationDeclarationOptions objC class.
5558
__block matter::casting::core::EndpointFilter cppDesiredEndpointFilter;
5659
if (desiredEndpointFilter != nil) {
57-
cppDesiredEndpointFilter.vendorId = desiredEndpointFilter.vendorId;
58-
cppDesiredEndpointFilter.productId = desiredEndpointFilter.productId;
60+
chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
61+
targetAppInfo.vendorId = desiredEndpointFilter.vendorId;
62+
targetAppInfo.productId = desiredEndpointFilter.productId;
63+
64+
CHIP_ERROR result = idOptions.addTargetAppInfo(targetAppInfo);
65+
if (result != CHIP_NO_ERROR)
66+
{
67+
ChipLogError(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCompletionBlock failed to add targetAppInfo: %" CHIP_ERROR_FORMAT, result.Format());
68+
}
5969
}
6070

61-
// TODO: In the following PRs. Removed desiredEndpointFilter to fix iOS app build issue. Replace desiredEndpointFilter with optional IdentificationDeclarationOptions. Add optional CommissionerDeclarationHandler callback parameter.
71+
// TODO: In the following PRs. Add optional CommissionerDeclarationHandler callback parameter.
6272
_cppCastingPlayer->VerifyOrEstablishConnection(
6373
[completion](CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer) {
6474
dispatch_queue_t clientQueue = [[MCCastingApp getSharedInstance] getClientQueue];
6575
dispatch_async(clientQueue, ^{
6676
completion(err == CHIP_NO_ERROR ? nil : [MCErrorUtils NSErrorFromChipError:err]);
6777
});
68-
}, timeout);
78+
}, timeout, idOptions);
6979
});
7080
}
7181

examples/tv-casting-app/linux/simple-app-helper.cpp

+27-8
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter
4949
if (commissionersCount == 0)
5050
{
5151
ChipLogProgress(AppServer, "Select discovered Casting Player (start index = 0) to request commissioning");
52+
ChipLogProgress(AppServer, "Include the cgp flag to attempt the Commissioner-Generated Passcode commissioning flow");
5253

53-
ChipLogProgress(AppServer, "Example: cast request 0");
54+
ChipLogProgress(AppServer, "Example1: cast request 0");
55+
ChipLogProgress(AppServer, "Example2: cast request 0 cgp");
5456
}
5557
ChipLogProgress(AppServer, "Discovered CastingPlayer #%d", commissionersCount);
5658
++commissionersCount;
@@ -221,13 +223,13 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
221223
}
222224
if (strcmp(argv[0], "discover") == 0)
223225
{
224-
ChipLogProgress(AppServer, "discover");
226+
ChipLogProgress(AppServer, "CommandHandler() discover");
225227

226228
return matter::casting::core::CastingPlayerDiscovery::GetInstance()->StartDiscovery(kTargetPlayerDeviceType);
227229
}
228230
if (strcmp(argv[0], "stop-discovery") == 0)
229231
{
230-
ChipLogProgress(AppServer, "stop-discovery");
232+
ChipLogProgress(AppServer, "CommandHandler() stop-discovery");
231233
return matter::casting::core::CastingPlayerDiscovery::GetInstance()->StopDiscovery();
232234
}
233235
if (strcmp(argv[0], "request") == 0)
@@ -246,12 +248,27 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
246248
std::shared_ptr<matter::casting::core::CastingPlayer> targetCastingPlayer = castingPlayers.at(index);
247249

248250
matter::casting::core::IdentificationDeclarationOptions idOptions;
249-
idOptions.mNumTargetAppInfos = 1;
250-
idOptions.mTargetAppInfos[0].vendorId = kDesiredEndpointVendorId;
251-
// Attempt Commissioner-Generated Passcode commissioning flow only if the CastingPlayer indicates support for it.
252-
if (targetCastingPlayer->GetSupportsCommissionerGeneratedPasscode())
251+
if (argc == 3)
253252
{
254-
idOptions.mCommissionerPasscode = true;
253+
if (strcmp(argv[2], "cgp") == 0)
254+
{
255+
// Attempt Commissioner-Generated Passcode (cgp) commissioning flow only if the CastingPlayer indicates support for it.
256+
if (targetCastingPlayer->GetSupportsCommissionerGeneratedPasscode())
257+
{
258+
ChipLogProgress(AppServer, "CommandHandler() request %lu cgp. Attempting the Commissioner-Generated Passcode commissioning flow", index);
259+
idOptions.mCommissionerPasscode = true;
260+
} else
261+
{
262+
ChipLogError(AppServer, "CommandHandler() request %lu cgp. Selected CastingPLayer does not support the Commissioner-Generated Passcode commissioning flow", index);
263+
}
264+
}
265+
}
266+
chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
267+
targetAppInfo.vendorId = kDesiredEndpointVendorId;
268+
CHIP_ERROR result = idOptions.addTargetAppInfo(targetAppInfo);
269+
if (result != CHIP_NO_ERROR)
270+
{
271+
ChipLogError(AppServer, "CommandHandler() request, failed to add targetAppInfo: %" CHIP_ERROR_FORMAT, result.Format());
255272
}
256273

257274
targetCastingPlayer->VerifyOrEstablishConnection(ConnectionHandler, matter::casting::core::kCommissioningWindowTimeoutSec,
@@ -291,6 +308,8 @@ CHIP_ERROR PrintAllCommands()
291308
streamer_printf(sout, " stop-discovery Stop Discovery of Casting Players. Usage: cast stop-discovery\r\n");
292309
streamer_printf(
293310
sout, " request <index> Request connecting to discovered Casting Player with [index]. Usage: cast request 0\r\n");
311+
streamer_printf(
312+
sout, " request <index> cgp Request connecting to discovered Casting Player with [index] using the Commissioner-Generated Passcode commissioning flow. Usage: cast request 0 cgp\r\n");
294313
streamer_printf(sout, "\r\n");
295314

296315
return CHIP_NO_ERROR;

examples/tv-casting-app/linux/simple-app-helper.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "core/CastingPlayer.h"
2222
#include "core/CastingPlayerDiscovery.h"
23+
#include "core/IdentificationDeclarationOptions.h"
2324
#include "core/Types.h"
2425
#include <platform/CHIPDeviceLayer.h>
2526

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp

+25-17
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void CastingPlayer::VerifyOrEstablishConnection(ConnectCallback onCompleted, uns
6666
if (it != cachedCastingPlayers.end())
6767
{
6868
unsigned index = (unsigned int) std::distance(cachedCastingPlayers.begin(), it);
69-
if (ContainsDesiredTargetApp(&cachedCastingPlayers[index], idOptions.mTargetAppInfos, idOptions.mNumTargetAppInfos))
69+
if (ContainsDesiredTargetApp(&cachedCastingPlayers[index], idOptions.getTargetAppInfoList()))
7070
{
7171
ChipLogProgress(
7272
AppServer,
@@ -166,17 +166,35 @@ void CastingPlayer::RegisterEndpoint(const memory::Strong<Endpoint> endpoint)
166166
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
167167
CHIP_ERROR CastingPlayer::SendUserDirectedCommissioningRequest()
168168
{
169-
ChipLogProgress(AppServer, "CastingPlayer::SendUserDirectedCommissioningRequest() creating IdentificationDeclaration message");
169+
ChipLogProgress(AppServer, "CastingPlayer::SendUserDirectedCommissioningRequest()");
170170
chip::Inet::IPAddress * ipAddressToUse = GetIpAddressForUDCRequest();
171171
VerifyOrReturnValue(ipAddressToUse != nullptr, CHIP_ERROR_INCORRECT_STATE,
172172
ChipLogError(AppServer, "No IP Address found to send UDC request to"));
173173

174174
ReturnErrorOnFailure(support::ChipDeviceEventHandler::SetUdcStatus(true));
175175

176+
chip::Protocols::UserDirectedCommissioning::IdentificationDeclaration id = buildIdentificationDeclarationMessage();
177+
178+
// TODO: In the following PRs. Implement handler for CommissionerDeclaration messages and expose messages to higher layers for
179+
// Linux, Android and iOS.
180+
chip::Server::GetInstance().GetUserDirectedCommissioningClient()->SetCommissionerDeclarationHandler(
181+
mCommissionerDeclarationHandler);
182+
183+
ReturnErrorOnFailure(chip::Server::GetInstance().SendUserDirectedCommissioningRequest(
184+
chip::Transport::PeerAddress::UDP(*ipAddressToUse, mAttributes.port, mAttributes.interfaceId), id));
185+
186+
return CHIP_NO_ERROR;
187+
}
188+
189+
chip::Protocols::UserDirectedCommissioning::IdentificationDeclaration CastingPlayer::buildIdentificationDeclarationMessage()
190+
{
191+
ChipLogProgress(AppServer, "CastingPlayer::buildIdentificationDeclarationMessage() building IdentificationDeclaration message");
176192
chip::Protocols::UserDirectedCommissioning::IdentificationDeclaration id;
177-
for (size_t i = 0; i < mIdOptions.mNumTargetAppInfos; i++)
193+
194+
std::vector<chip::Protocols::UserDirectedCommissioning::TargetAppInfo> mTargetAppInfos = mIdOptions.getTargetAppInfoList();
195+
for (size_t i = 0; i < mTargetAppInfos.size(); i++)
178196
{
179-
id.AddTargetAppInfo(mIdOptions.mTargetAppInfos[i]);
197+
id.AddTargetAppInfo(mTargetAppInfos[i]);
180198
}
181199
id.SetNoPasscode(mIdOptions.mNoPasscode);
182200
id.SetCdUponPasscodeDialog(mIdOptions.mCdUponPasscodeDialog);
@@ -194,15 +212,7 @@ CHIP_ERROR CastingPlayer::SendUserDirectedCommissioningRequest()
194212
}
195213
}
196214

197-
// TODO: In the following PRs. Implement handler for CommissionerDeclaration messages and expose messages to higher layers for
198-
// Linux, Android and iOS.
199-
chip::Server::GetInstance().GetUserDirectedCommissioningClient()->SetCommissionerDeclarationHandler(
200-
mCommissionerDeclarationHandler);
201-
202-
ReturnErrorOnFailure(chip::Server::GetInstance().SendUserDirectedCommissioningRequest(
203-
chip::Transport::PeerAddress::UDP(*ipAddressToUse, mAttributes.port, mAttributes.interfaceId), id));
204-
205-
return CHIP_NO_ERROR;
215+
return id;
206216
}
207217

208218
chip::Inet::IPAddress * CastingPlayer::GetIpAddressForUDCRequest()
@@ -244,12 +254,10 @@ void CastingPlayer::FindOrEstablishSession(void * clientContext, chip::OnDeviceC
244254
connectionContext->mOnConnectionFailureCallback);
245255
}
246256

247-
bool CastingPlayer::ContainsDesiredTargetApp(core::CastingPlayer * cachedCastingPlayer,
248-
chip::Protocols::UserDirectedCommissioning::TargetAppInfo * desiredTargetApps,
249-
uint8_t numTargetApps)
257+
bool CastingPlayer::ContainsDesiredTargetApp(core::CastingPlayer * cachedCastingPlayer, std::vector<chip::Protocols::UserDirectedCommissioning::TargetAppInfo> desiredTargetApps)
250258
{
251259
std::vector<memory::Strong<Endpoint>> cachedEndpoints = cachedCastingPlayer->GetEndpoints();
252-
for (size_t i = 0; i < numTargetApps; i++)
260+
for (size_t i = 0; i < desiredTargetApps.size(); i++)
253261
{
254262
for (const auto & cachedEndpoint : cachedEndpoints)
255263
{

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h

+14-67
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
#pragma once
2020

21+
#include "CommissionerDeclarationHandler.h"
2122
#include "Endpoint.h"
23+
#include "IdentificationDeclarationOptions.h"
2224
#include "Types.h"
2325
#include "support/ChipDeviceEventHandler.h"
2426
#include "support/EndpointListLoader.h"
@@ -69,65 +71,6 @@ class CastingPlayerAttributes
6971
chip::FabricIndex fabricIndex = 0;
7072
};
7173

72-
/**
73-
* This class contains the optional parameters used in the IdentificationDeclaration Message, sent by the Commissionee to the
74-
* Commissioner. The options specify information relating to the requested UDC commissioning session.
75-
*/
76-
class IdentificationDeclarationOptions
77-
{
78-
public:
79-
constexpr static size_t kMaxTargetAppInfos = 10;
80-
uint8_t mNumTargetAppInfos = 0; // The number of TargetAppInfos included.
81-
/**
82-
* Feature: Target Content Application
83-
* The set of content app Vendor IDs (and optionally, Product IDs) that can be used for authentication.
84-
* Also, if TargetAppInfo is passed in, VerifyOrEstablishConnection() will force User Directed Commissioning, in case the
85-
* desired TargetApp is not found in the on-device CastingStore.
86-
*/
87-
chip::Protocols::UserDirectedCommissioning::TargetAppInfo mTargetAppInfos[kMaxTargetAppInfos];
88-
89-
/**
90-
* Feature: Target Content Application
91-
* Flag to instruct the Commissioner not to display a Passcode input dialog, and instead send a CommissionerDeclaration message
92-
* if a commissioning Passcode is needed.
93-
*/
94-
bool mNoPasscode = false;
95-
/**
96-
* Feature: Coordinate Passcode Dialogs
97-
* Flag to instruct the Commissioner to send a CommissionerDeclaration message when the Passcode input dialog on the
98-
* Commissioner has been shown to the user.
99-
*/
100-
bool mCdUponPasscodeDialog = false;
101-
/**
102-
* Feature: Commissioner-Generated Passcode
103-
* Flag to instruct the Commissioner to use the Commissioner-generated Passcode for commissioning.
104-
*/
105-
bool mCommissionerPasscode = false;
106-
/**
107-
* Feature: Commissioner-Generated Passcode
108-
* Flag to indicate whether or not the Commissionee has obtained the Commissioner Passcode from the user and is therefore ready
109-
* for commissioning.
110-
*/
111-
bool mCommissionerPasscodeReady = false;
112-
/**
113-
* Feature: Coordinate Passcode Dialogs
114-
* Flag to indicate when the Commissionee user has decided to exit the commissioning process.
115-
*/
116-
bool mCancelPasscode = false;
117-
};
118-
119-
// TODO: In the following PRs. This is work in progress. Break out to a seperate cpp file.
120-
class CommissionerDeclarationHandler : public chip::Protocols::UserDirectedCommissioning::CommissionerDeclarationHandler
121-
{
122-
public:
123-
void OnCommissionerDeclarationMessage(const chip::Transport::PeerAddress & source,
124-
chip::Protocols::UserDirectedCommissioning::CommissionerDeclaration cd) override
125-
{
126-
ChipLogProgress(AppServer, "CastingPlayer::CommissionerDeclarationHandler::OnCommissionerDeclarationMessage() called");
127-
cd.DebugLog();
128-
}
129-
};
130-
13174
class Endpoint;
13275

13376
/**
@@ -155,7 +98,10 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
15598
CastingPlayer(CastingPlayerAttributes playerAttributes)
15699
{
157100
mAttributes = playerAttributes;
158-
mCommissionerDeclarationHandler = new CommissionerDeclarationHandler();
101+
}
102+
~CastingPlayer()
103+
{
104+
delete mCommissionerDeclarationHandler;
159105
}
160106

161107
/**
@@ -272,7 +218,7 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
272218
* for commissioning.
273219
*/
274220
bool mUdcCommissionerPasscodeReady = false;
275-
CommissionerDeclarationHandler * mCommissionerDeclarationHandler;
221+
CommissionerDeclarationHandler * mCommissionerDeclarationHandler = new CommissionerDeclarationHandler();
276222
static CastingPlayer * mTargetCastingPlayer;
277223
unsigned long long int mCommissioningWindowTimeoutSec = kCommissioningWindowTimeoutSec;
278224
ConnectCallback mOnCompleted = {};
@@ -283,6 +229,11 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
283229
*/
284230
CHIP_ERROR SendUserDirectedCommissioningRequest();
285231

232+
/**
233+
* @brief Builds an IdentificationDeclaration message to be sent to this CastingPlayer
234+
*/
235+
chip::Protocols::UserDirectedCommissioning::IdentificationDeclaration buildIdentificationDeclarationMessage();
236+
286237
/**
287238
* @brief Selects an IP Address to send the UDC request to.
288239
* Prioritizes IPV4 addresses over IPV6.
@@ -294,13 +245,9 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
294245

295246
/**
296247
* @brief Checks if the cachedCastingPlayer contains at least one Endpoint/TargetApp described in the desiredTargetApps list.
297-
* @return true - cachedCastingPlayer contains at least one endpoints with matching (non-default) values as described in the
298-
* desiredTargetApps list, false otherwise.
299-
* @param numTargetApps Specifies the number of TargetAppInfos passed in the desiredTargetApps array.
248+
* @return true - cachedCastingPlayer contains at least one endpoints with matching (non-default) values for vendorID and productID as described in the desiredTargetApps list, false otherwise.
300249
*/
301-
bool ContainsDesiredTargetApp(core::CastingPlayer * cachedCastingPlayer,
302-
chip::Protocols::UserDirectedCommissioning::TargetAppInfo * desiredTargetApps,
303-
uint8_t numTargetApps);
250+
bool ContainsDesiredTargetApp(core::CastingPlayer * cachedCastingPlayer, std::vector<chip::Protocols::UserDirectedCommissioning::TargetAppInfo> desiredTargetApps);
304251

305252
// ChipDeviceEventHandler handles chip::DeviceLayer::ChipDeviceEvent events and helps the CastingPlayer class commission with
306253
// and connect to a CastingPlayer

0 commit comments

Comments
 (0)