Skip to content

Commit

Permalink
Address items in 14279 (#14666)
Browse files Browse the repository at this point in the history
* Address 14279

* Remove CreateBindingWithCallback from CHIPDeviceController, fix commissioning regression in tv-app

* address comments

* first step in moving post-commissioning casting app work such as binding config to ContentAppPlatform

* fix build
  • Loading branch information
chrisdecenzo authored and pull[bot] committed Oct 17, 2023
1 parent d7a593a commit 1943920
Show file tree
Hide file tree
Showing 16 changed files with 402 additions and 133 deletions.
95 changes: 64 additions & 31 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
* limitations under the License.
*/

#include <iostream>
#include <thread>

#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>

Expand Down Expand Up @@ -49,6 +46,7 @@
#if defined(ENABLE_CHIP_SHELL)
#include <CommissioneeShellCommands.h>
#include <lib/shell/Engine.h>
#include <thread>
#endif

#if defined(PW_RPC_ENABLED)
Expand All @@ -63,6 +61,7 @@ using namespace chip::Credentials;
using namespace chip::DeviceLayer;
using namespace chip::Inet;
using namespace chip::Transport;
using namespace chip::app::Clusters;

#if defined(ENABLE_CHIP_SHELL)
using chip::Shell::Engine;
Expand Down Expand Up @@ -223,7 +222,7 @@ MyCommissionerCallback gCommissionerCallback;
MyServerStorageDelegate gServerStorage;
SimpleFabricStorage gFabricStorage;
ExampleOperationalCredentialsIssuer gOpCredsIssuer;
NodeId gLocalId = kPlaceholderNodeId;
NodeId gLocalId = kMaxOperationalNodeId;

CHIP_ERROR InitCommissioner()
{
Expand Down Expand Up @@ -296,7 +295,9 @@ CHIP_ERROR ShutdownCommissioner()
class PairingCommand : public Controller::DevicePairingDelegate, public Controller::DeviceAddressUpdateDelegate
{
public:
PairingCommand(){};
PairingCommand() :
mOnDeviceConnectedCallback(OnDeviceConnectedFn, this),
mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this){};

/////////// DevicePairingDelegate Interface /////////
void OnStatusUpdate(Controller::DevicePairingDelegate::Status status) override;
Expand All @@ -309,10 +310,14 @@ class PairingCommand : public Controller::DevicePairingDelegate, public Controll

CHIP_ERROR UpdateNetworkAddress();

/* Callback when command results in success */
static void OnSuccessResponse(void * context, const chip::app::DataModel::NullObjectType &);
/* Callback when command results in failure */
static void OnFailureResponse(void * context, CHIP_ERROR error);
private:
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);

chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
};

PairingCommand gPairingCommand;
Expand Down Expand Up @@ -371,41 +376,69 @@ void PairingCommand::OnPairingDeleted(CHIP_ERROR err)
}
}

void PairingCommand::OnSuccessResponse(void * context, const chip::app::DataModel::NullObjectType &)
{
ChipLogProgress(Controller, "OnSuccessResponse");
}

void PairingCommand::OnFailureResponse(void * context, CHIP_ERROR error)
{
ChipLogProgress(Controller, "OnFailureResponse");
}

void PairingCommand::OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err)
{
if (err == CHIP_NO_ERROR)
{
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
ChipLogProgress(AppServer, "Device commissioning completed with success - getting OperationalDeviceProxy");

gCommissioner.GetConnectedDevice(nodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
#else // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
ChipLogProgress(AppServer, "Device commissioning completed with success");
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
}
else
{
ChipLogProgress(AppServer, "Device commissioning Failure: %s", ErrorStr(err));
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
if (cdc != nullptr)
{
cdc->CommissioningFailed(err);
}
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
}
}

// TODO:
// - this code needs to be conditional based upon Content App Platform enablement
// - the endpointId chosen should come from the App Platform (determined based upon vid/pid of node)
// - the cluster(s) chosen should come from the App Platform
constexpr EndpointId kBindingClusterEndpoint = 0;
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED

GroupId groupId = kUndefinedGroupId;
EndpointId endpointId = 1;
ClusterId clusterId = kInvalidClusterId;
void PairingCommand::OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device)
{
ChipLogProgress(Controller, "OnDeviceConnectedFn");
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();

gCommissioner.CreateBindingWithCallback(nodeId, kBindingClusterEndpoint, gLocalId, groupId, endpointId, clusterId,
OnSuccessResponse, OnFailureResponse);
if (device == nullptr)
{
ChipLogProgress(AppServer, "No OperationalDeviceProxy returned from OnDeviceConnectedFn");
if (cdc != nullptr)
{
cdc->CommissioningFailed(CHIP_ERROR_INCORRECT_STATE);
}
return;
}
else

if (cdc != nullptr)
{
ChipLogProgress(AppServer, "Device commissioning Failure: %s", ErrorStr(err));
// TODO: get from DAC!
UDCClientState * udc = cdc->GetUDCClientState();
uint16_t vendorId = (udc == nullptr ? 0 : udc->GetVendorId());
uint16_t productId = (udc == nullptr ? 0 : udc->GetProductId());
cdc->CommissioningSucceeded(vendorId, productId, gRemoteId, device);
}
}

void PairingCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
{
ChipLogProgress(Controller, "OnDeviceConnectionFailureFn - attempt to get OperationalDeviceProxy failed");
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
{
cdc->CommissioningFailed(err);
}
}

#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED

CHIP_ERROR CommissionerPairOnNetwork(uint32_t pincode, uint16_t disc, Transport::PeerAddress address)
{
RendezvousParameters params = RendezvousParameters().SetSetupPINCode(pincode).SetDiscriminator(disc).SetPeerAddress(address);
Expand Down
3 changes: 0 additions & 3 deletions examples/platform/linux/AppMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

#pragma once

#include <iostream>
#include <thread>

#include <controller/CHIPDeviceController.h>
#include <controller/CommissionerDiscoveryController.h>
#include <lib/core/CHIPError.h>
Expand Down
5 changes: 3 additions & 2 deletions examples/tv-app/linux/AppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ CHIP_ERROR ContentAppFactoryImpl::LookupCatalogVendorApp(uint16_t vendorId, uint
return CHIP_NO_ERROR;
}

CHIP_ERROR ContentAppFactoryImpl::ConvertToPlatformCatalogVendorApp(CatalogVendorApp sourceApp, CatalogVendorApp * destinationApp)
CHIP_ERROR ContentAppFactoryImpl::ConvertToPlatformCatalogVendorApp(const CatalogVendorApp & sourceApp,
CatalogVendorApp * destinationApp)
{
destinationApp->catalogVendorId = GetPlatformCatalogVendorId();
std::string appId(sourceApp.applicationId);
Expand All @@ -185,7 +186,7 @@ CHIP_ERROR ContentAppFactoryImpl::ConvertToPlatformCatalogVendorApp(CatalogVendo
return CHIP_NO_ERROR;
}

ContentApp * ContentAppFactoryImpl::LoadContentApp(CatalogVendorApp vendorApp)
ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vendorApp)
{
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: LoadContentAppByAppId catalogVendorId=%d applicationId=%s ",
vendorApp.catalogVendorId, vendorApp.applicationId);
Expand Down
6 changes: 3 additions & 3 deletions examples/tv-app/linux/AppImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
CHIP_ERROR LookupCatalogVendorApp(uint16_t vendorId, uint16_t productId, CatalogVendorApp * destinationApp) override;

// Lookup ContentApp for this catalog id / app id and load it
ContentApp * LoadContentApp(CatalogVendorApp vendorApp) override;
ContentApp * LoadContentApp(const CatalogVendorApp & vendorApp) override;

// Gets the catalog vendor ID used by this platform
uint16_t GetPlatformCatalogVendorId() override;

// Converts application (any catalog) into the platform's catalog Vendor
// and then writes it to destinationApp
CHIP_ERROR ConvertToPlatformCatalogVendorApp(CatalogVendorApp sourceApp, CatalogVendorApp * destinationApp) override;
CHIP_ERROR ConvertToPlatformCatalogVendorApp(const CatalogVendorApp & sourceApp, CatalogVendorApp * destinationApp) override;

protected:
ContentAppImpl mContentApps[APP_LIBRARY_SIZE] = { ContentAppImpl("Vendor1", 1, "App1", 11, "Version1", "34567890"),
ContentAppImpl("Vendor2", 2222, "App2", 22, "Version2", "34567890"),
ContentAppImpl("Vendor2", 65521, "App2", 32768, "Version2", "20202021"),
ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021"),
ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2",
"20202021") };
Expand Down
62 changes: 58 additions & 4 deletions examples/tv-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include <app/app-platform/ContentAppPlatform.h>
#include <app/util/af.h>

#include <iostream>

#include "include/account-login/AccountLoginManager.h"
#include "include/application-basic/ApplicationBasicManager.h"
#include "include/application-launcher/ApplicationLauncherManager.h"
Expand Down Expand Up @@ -81,17 +79,26 @@ void ApplicationInit() {}
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
class MyUserPrompter : public UserPrompter
{
// TODO: tv should override this with a dialog prompt
// tv should override this with a dialog prompt
inline void PromptForCommissionOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
{
return;
}

// TODO: tv should override this with a dialog prompt
// tv should override this with a dialog prompt
inline void PromptForCommissionPincode(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
{
return;
}

// tv should override this with a dialog prompt
inline void PromptCommissioningSucceeded(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
{
return;
}

// tv should override this with a dialog prompt
inline void PromptCommissioningFailed(const char * commissioneeName, CHIP_ERROR error) override { return; }
};

MyUserPrompter gMyUserPrompter;
Expand All @@ -106,6 +113,52 @@ class MyPincodeService : public PincodeService
}
};
MyPincodeService gMyPincodeService;

class MyPostCommissioningListener : public PostCommissioningListener
{
void CommissioningCompleted(uint16_t vendorId, uint16_t productId, NodeId nodeId, OperationalDeviceProxy * device) override
{

// TODO:
// - the endpointId chosen should come from the App Platform (determined based upon vid/pid of node)
// - the cluster(s) chosen should come from the App Platform
constexpr EndpointId kBindingClusterEndpoint = 0;

GroupId groupId = kUndefinedGroupId;
EndpointId endpointId = 1;
ClusterId clusterId = kInvalidClusterId;

ChipLogProgress(Controller, "Attempting to create Binding");

ContentAppPlatform::GetInstance().CreateBindingWithCallback(device, kBindingClusterEndpoint, nodeId, groupId, endpointId,
clusterId, OnSuccessResponse, OnFailureResponse);
}

/* Callback when command results in success */
static void OnSuccessResponse(void * context, const chip::app::DataModel::NullObjectType &)
{
ChipLogProgress(Controller, "OnSuccessResponse - Binding Add Successfully");
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
if (cdc != nullptr)
{
cdc->PostCommissioningSucceeded();
}
}

/* Callback when command results in failure */
static void OnFailureResponse(void * context, CHIP_ERROR error)
{
ChipLogProgress(Controller, "OnFailureResponse - Binding Add Failed");
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
if (cdc != nullptr)
{
cdc->PostCommissioningFailed(error);
}
}
};

MyPostCommissioningListener gMyPostCommissioningListener;

#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED

int main(int argc, char * argv[])
Expand All @@ -126,6 +179,7 @@ int main(int argc, char * argv[])
{
cdc->SetPincodeService(&gMyPincodeService);
cdc->SetUserPrompter(&gMyUserPrompter);
cdc->SetPostCommissioningListener(&gMyPostCommissioningListener);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
Expand Down
2 changes: 0 additions & 2 deletions src/app/app-platform/ContentApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/app-platform/ContentAppPlatform.h>
#include <cstdio>
#include <inttypes.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/CHIPArgParser.hpp>
Expand Down
5 changes: 0 additions & 5 deletions src/app/app-platform/ContentApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
#include <app/clusters/media-playback-server/media-playback-delegate.h>
#include <app/clusters/target-navigator-server/target-navigator-delegate.h>
#include <app/util/attribute-storage.h>
#include <functional>
#include <list>
#include <stdbool.h>
#include <stdint.h>
#include <string>

namespace chip {
namespace AppPlatform {
Expand Down
Loading

0 comments on commit 1943920

Please sign in to comment.