Skip to content

Commit

Permalink
Update Logic per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarkov committed May 17, 2024
1 parent 45a5202 commit 3b23b5b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
5 changes: 3 additions & 2 deletions examples/tv-app/tv-common/include/AppTv.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
uint16_t productId) override;

void AddAdminVendorId(uint16_t vendorId);

// Add the app to the list of mContentApps
void InstallContentApp(uint16_t vendorId, uint16_t productId);
void UninstallContentApp(uint16_t vendorId, uint16_t productId);
// Remove the app from the list of mContentApps
bool UninstallContentApp(uint16_t vendorId, uint16_t productId);

protected:
std::vector<std::unique_ptr<ContentAppImpl>> mContentApps;
Expand Down
8 changes: 6 additions & 2 deletions examples/tv-app/tv-common/shell/AppTvShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,13 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv)
pid = (uint16_t) strtol(argv[2], &eptr, 10);
}
ContentAppFactoryImpl * factory = GetContentAppFactoryImpl();
factory->UninstallContentApp(vid, pid);
bool isAppUninstalled = factory->UninstallContentApp(vid, pid);

ChipLogProgress(DeviceLayer, "uninstalled an app");
if (isAppUninstalled) {
ChipLogProgress(DeviceLayer, "uninstalled an app");
} else {
ChipLogProgress(DeviceLayer, "app not found.");
}

return CHIP_NO_ERROR;
}
Expand Down
15 changes: 8 additions & 7 deletions examples/tv-app/tv-common/src/AppTv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ MyPasscodeService gMyPasscodeService;

class MyAppInstallationService : public AppInstallationService
{
// TODO: rename the method
// intentionally ambigiously named, need to find a better method name
bool HasContentApp(uint16_t vendorId, uint16_t productId) override
bool LookupTargetContentApp(uint16_t vendorId, uint16_t productId) override
{
return ContentAppPlatform::GetInstance().LoadContentAppByClient(vendorId, productId) != nullptr;
}
Expand Down Expand Up @@ -573,6 +571,8 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)

void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId)
{
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: InstallContentApp vendorId=%d productId=%d ",
vendorId, productId);
if (vendorId == 1 && productId == 11) {
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1", "34567890"));
} else if (vendorId == 65521 && productId == 32768) {
Expand All @@ -586,9 +586,9 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc
}
}

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

int index = 0;
Expand All @@ -599,13 +599,14 @@ void ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod
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());
ChipLogProgress(DeviceLayer, "Found an app vid=%d pid=%d. Uninstalling it.", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId());
mContentApps.erase(mContentApps.begin() + index);
return;
return true;
}

index++;
}
return false;
}

Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege(uint16_t vendorId)
Expand Down
7 changes: 2 additions & 5 deletions src/controller/CommissionerDiscoveryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,10 @@ void CommissionerDiscoveryController::InternalOk()
return;
}

bool isContentAppInstalled = mAppInstallationService->HasContentApp(client->GetVendorId(), client->GetProductId());

if (!isContentAppInstalled) {
if (!mAppInstallationService->LookupTargetContentApp(client->GetVendorId(), client->GetProductId())) {
ChipLogDetail(AppServer, "UX InternalOk: app not installed.");

// prompt user to install missing app
// notify client that app will be installed
CommissionerDeclaration cd;
cd.SetErrorCode(CommissionerDeclaration::CdError::kAppInstallConsentPending);
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
Expand All @@ -240,7 +238,6 @@ void CommissionerDiscoveryController::InternalOk()
mUserPrompter->PromptForAppInstallOKPermission(client->GetVendorId(), client->GetProductId(), client->GetDeviceName());
}
ChipLogDetail(Controller, "------Via Shell Enter: app install <pid> <vid>");
// TODO: force user to send again "cast request <id>" command?
return;
}

Expand Down
10 changes: 4 additions & 6 deletions src/controller/CommissionerDiscoveryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class DLL_EXPORT PasscodeService
public:
/**
* @brief
* Called to determine if the given target app is available to the commissionee with the given given
* Called to determine if the given target app is available to the commissionee with the given
* vendorId/productId, and if so, return the passcode.
*
* This will be called by the main chip thread so any blocking work should be moved to a separate thread.
Expand Down Expand Up @@ -225,18 +225,16 @@ class DLL_EXPORT AppInstallationService
public:
/**
* @brief
* Called to get the setup passcode from the content app corresponding to the given vendorId/productId.
* Called to check if the given target app is available to the commissione with th given
* vendorId/productId
*
* This will be called by the main chip thread so any blocking work should be moved to a separate thread.
*
* After attempting to obtain the passcode, implementor should call HandleContentAppPasscodeResponse();
*
* @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee.
* @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee.
* @param[in] rotatingId The rotatingId in the DNS-SD advertisement of the requesting commissionee.
*
*/
virtual bool HasContentApp(uint16_t vendorId, uint16_t productId) = 0;
virtual bool LookupTargetContentApp(uint16_t vendorId, uint16_t productId) = 0;

virtual ~AppInstallationService() = default;
};
Expand Down

0 comments on commit 3b23b5b

Please sign in to comment.