Skip to content

Commit

Permalink
Update code per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarkov committed May 16, 2024
1 parent ca5ffb4 commit 45a5202
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 13 deletions.
4 changes: 3 additions & 1 deletion examples/tv-app/tv-common/include/AppTv.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
KeypadInputDelegate * GetKeypadInputDelegate() override { return &mKeypadInputDelegate; };
MediaPlaybackDelegate * GetMediaPlaybackDelegate() override { return &mMediaPlaybackDelegate; };
TargetNavigatorDelegate * GetTargetNavigatorDelegate() override { return &mTargetNavigatorDelegate; };
bool MatchesPidVid(uint16_t productId, uint16_t vendorId) { return vendorId == mApplicationBasicDelegate.HandleGetVendorId() && productId == mApplicationBasicDelegate.HandleGetProductId(); }

protected:
ApplicationBasicManager mApplicationBasicDelegate;
Expand Down Expand Up @@ -139,7 +140,8 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory

void AddAdminVendorId(uint16_t vendorId);

void AddContentApp(uint16_t vendorId, uint16_t productId);
void InstallContentApp(uint16_t vendorId, uint16_t productId);
void UninstallContentApp(uint16_t vendorId, uint16_t productId);

protected:
std::vector<std::unique_ptr<ContentAppImpl>> mContentApps;
Expand Down
44 changes: 42 additions & 2 deletions examples/tv-app/tv-common/shell/AppTvShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,28 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv)

return CHIP_NO_ERROR;
}
else if (strcmp(argv[0], "add") == 0)
else if (strcmp(argv[0], "install") == 0)
{
if (argc < 2)
{
return PrintAllCommands();
}
char * eptr;

uint16_t vid = (uint16_t) strtol(argv[1], &eptr, 10);
uint16_t pid = 0;
if (argc >= 3)
{
pid = (uint16_t) strtol(argv[2], &eptr, 10);
}
ContentAppFactoryImpl * factory = GetContentAppFactoryImpl();
factory->InstallContentApp(vid, pid);

ChipLogProgress(DeviceLayer, "installed an app");

return CHIP_NO_ERROR;
}
else if (strcmp(argv[0], "uninstall") == 0)
{
if (argc < 2)
{
Expand All @@ -258,7 +279,26 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv)
pid = (uint16_t) strtol(argv[2], &eptr, 10);
}
ContentAppFactoryImpl * factory = GetContentAppFactoryImpl();
factory->AddContentApp(vid, pid);
factory->UninstallContentApp(vid, pid);

ChipLogProgress(DeviceLayer, "uninstalled an app");

return CHIP_NO_ERROR;
}
else if (strcmp(argv[0], "add") == 0)
{
if (argc < 2)
{
return PrintAllCommands();
}
char * eptr;

uint16_t vid = (uint16_t) strtol(argv[1], &eptr, 10);
uint16_t pid = 0;
if (argc >= 3)
{
pid = (uint16_t) strtol(argv[2], &eptr, 10);
}
ContentAppPlatform::GetInstance().LoadContentAppByClient(vid, pid);

ChipLogProgress(DeviceLayer, "added app");
Expand Down
33 changes: 27 additions & 6 deletions examples/tv-app/tv-common/src/AppTv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend

for (auto & contentApp : mContentApps) {


auto app = contentApp.get();

ChipLogProgress(DeviceLayer, " Looking next=%s ", app->GetApplicationBasicDelegate()->GetCatalogVendorApp()->applicationId);
Expand All @@ -572,7 +571,7 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)
mAdminVendorIds.push_back(vendorId);
}

void ContentAppFactoryImpl::AddContentApp(uint16_t vendorId, uint16_t productId)
void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId)
{
if (vendorId == 1 && productId == 11) {
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1", "34567890"));
Expand All @@ -587,6 +586,28 @@ void ContentAppFactoryImpl::AddContentApp(uint16_t vendorId, uint16_t productId)
}
}

void ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId)
{
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: RemoveContentApp vendorId=%d productId=%d ",
vendorId, productId);

int index = 0;
for (auto & contentApp : mContentApps) {

auto app = contentApp.get();

ChipLogProgress(DeviceLayer, "Looking next vid=%d pid=%d", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId());

if (app->MatchesPidVid(productId, vendorId)) {
ChipLogProgress(DeviceLayer, "Found an app. vid=%d pid=%d. Uninstalling it.", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId());
mContentApps.erase(mContentApps.begin() + index);
return;
}

index++;
}
}

Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege(uint16_t vendorId)
{
for (size_t i = 0; i < mAdminVendorIds.size(); ++i)
Expand Down Expand Up @@ -643,10 +664,10 @@ CHIP_ERROR AppTvInit()
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
ContentAppPlatform::GetInstance().SetupAppPlatform();
ContentAppPlatform::GetInstance().SetContentAppFactory(&gFactory);
gFactory.AddContentApp((uint16_t)1, (uint16_t)11);
// gFactory.AddContentApp((uint16_t)65521, (uint16_t)32768);
gFactory.AddContentApp((uint16_t)9050, (uint16_t)22);
gFactory.AddContentApp((uint16_t)1111, (uint16_t)22);
gFactory.InstallContentApp((uint16_t)1, (uint16_t)11);
gFactory.InstallContentApp((uint16_t)65521, (uint16_t)32768);
gFactory.InstallContentApp((uint16_t)9050, (uint16_t)22);
gFactory.InstallContentApp((uint16_t)1111, (uint16_t)22);
uint16_t value;
if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value) != CHIP_NO_ERROR)
{
Expand Down
11 changes: 7 additions & 4 deletions src/controller/CommissionerDiscoveryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,21 @@ void CommissionerDiscoveryController::InternalOk()
if (!isContentAppInstalled) {
ChipLogDetail(AppServer, "UX InternalOk: app not installed.");

// TODO: send CDC message that user is prompted to install the app
// prompt user to install missing app
CommissionerDeclaration cd;
cd.SetErrorCode(CommissionerDeclaration::CdError::kAppInstallConsentPending);
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));

// dialog
ChipLogDetail(Controller,
"------PROMPT USER: %s is requesting to install app on this TV. [" ChipLogFormatMEI "," ChipLogFormatMEI "]",
client->GetDeviceName(), ChipLogValueMEI(client->GetVendorId()), ChipLogValueMEI(client->GetProductId()));
"------PROMPT USER: %s is requesting to install app on this TV. vendorId=%d, productId=%d",
client->GetDeviceName(), client->GetVendorId(), client->GetProductId());

if (mUserPrompter != nullptr)
{
mUserPrompter->PromptForAppInstallOKPermission(client->GetVendorId(), client->GetProductId(), client->GetDeviceName());
}
ChipLogDetail(Controller, "------Via Shell Enter: app add <pid> <vid>");
ChipLogDetail(Controller, "------Via Shell Enter: app install <pid> <vid>");
// TODO: force user to send again "cast request <id>" command?
return;
}
Expand Down

0 comments on commit 45a5202

Please sign in to comment.