Skip to content

Commit

Permalink
Remove DeviceProxy pointer in ClusterBase (project-chip#19673)
Browse files Browse the repository at this point in the history
* Remove DeviceProxy pointer in ClusterBase

* Fix Darwin build.

* Fix Darwin threading issue.

* Generated files

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
kghost and bzbarsky-apple authored Jul 6, 2022
1 parent 5b603f3 commit 342ba68
Show file tree
Hide file tree
Showing 60 changed files with 6,814 additions and 3,990 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ using namespace chip::app::Clusters;
{{#chip_client_clusters includeAll=true}}

@interface MTRTest{{asUpperCamelCase name}} ()
@property (readonly) chip::Controller::{{asUpperCamelCase name}}Cluster cppCluster;
// Must only touch cppCluster on the Matter queue.
@property (readonly) chip::Controller::{{asUpperCamelCase name}}Cluster * cppCluster;
@end

@implementation MTRTest{{asUpperCamelCase name}}

- (chip::Controller::ClusterBase *)getCluster
- (chip::Controller::{{asUpperCamelCase name}}Cluster **) cppClusterSlot
{
return &_cppCluster;
}
Expand All @@ -56,7 +57,7 @@ using namespace chip::app::Clusters;
{{>encode_value target="cppValue" source="value" cluster=parent.name errorCode="return CHIP_ERROR_INVALID_ARGUMENT;" depth=0}}
auto successFn = Callback<{{>callbackName}}CallbackType>::FromCancelable(success);
auto failureFn = Callback<DefaultFailureCallbackType>::FromCancelable(failure);
return self.cppCluster.WriteAttribute<TypeInfo>(cppValue, successFn->mContext, successFn->mCall, failureFn->mCall);
return self.cppCluster->WriteAttribute<TypeInfo>(cppValue, successFn->mContext, successFn->mCall, failureFn->mCall);
});
}

Expand Down
18 changes: 4 additions & 14 deletions examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,8 @@ void CastingServer::ReadServerClusters(EndpointId endpointId)
return;
}

chip::Controller::DescriptorCluster cluster;
CHIP_ERROR err = cluster.Associate(operationalDeviceProxy, endpointId);
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Associate() failed: %" CHIP_ERROR_FORMAT, err.Format());
return;
}
chip::Controller::DescriptorCluster cluster(*operationalDeviceProxy->GetExchangeManager(),
operationalDeviceProxy->GetSecureSession().Value(), endpointId);

TargetEndpointInfo * endpointInfo = mTargetVideoPlayerInfo.GetOrAddEndpoint(endpointId);

Expand Down Expand Up @@ -193,13 +188,8 @@ CHIP_ERROR CastingServer::ContentLauncherLaunchURL(const char * contentUrl, cons
return CHIP_ERROR_PEER_NODE_NOT_FOUND;
}

ContentLauncherCluster cluster;
CHIP_ERROR err = cluster.Associate(operationalDeviceProxy, kTvEndpoint);
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Associate() failed: %" CHIP_ERROR_FORMAT, err.Format());
return err;
}
ContentLauncherCluster cluster(*operationalDeviceProxy->GetExchangeManager(),
operationalDeviceProxy->GetSecureSession().Value(), kTvEndpoint);
CastingServer::GetInstance()->mLaunchURLResponseCallback = launchURLResponseCallback;
LaunchURL::Type request;
request.contentURL = chip::CharSpan::fromCharString(contentUrl);
Expand Down
7 changes: 3 additions & 4 deletions scripts/idl/generators/java/ChipClustersCpp.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ using namespace chip::Controller;
JNI_METHOD(jlong, {{cluster.name | capitalcase}}Cluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId)
{
chip::DeviceLayer::StackLock lock;
{{cluster.name | capitalcase}}Cluster * cppCluster = new {{cluster.name | capitalcase}}Cluster();

cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
DeviceProxy * device = reinterpret_cast<DeviceProxy *>(devicePtr);
{{cluster.name | capitalcase}}Cluster * cppCluster = new {{cluster.name | capitalcase}}Cluster(*device->GetExchangeManager(), device->GetSecureSession().Value(), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down Expand Up @@ -210,4 +209,4 @@ JNI_METHOD(void, {{cluster.name}}Cluster, subscribe{{attr.definition.name | capi
}

{%- endif -%}
{% endfor %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ using namespace chip::Controller;
JNI_METHOD(jlong, DemoClusterCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId)
{
chip::DeviceLayer::StackLock lock;
DemoClusterCluster * cppCluster = new DemoClusterCluster();

cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
DeviceProxy * device = reinterpret_cast<DeviceProxy *>(devicePtr);
DemoClusterCluster * cppCluster = new DemoClusterCluster(*device->GetExchangeManager(), device->GetSecureSession().Value(), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ using namespace chip::Controller;
JNI_METHOD(jlong, DemoClusterCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId)
{
chip::DeviceLayer::StackLock lock;
DemoClusterCluster * cppCluster = new DemoClusterCluster();

cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
DeviceProxy * device = reinterpret_cast<DeviceProxy *>(devicePtr);
DemoClusterCluster * cppCluster = new DemoClusterCluster(*device->GetExchangeManager(), device->GetSecureSession().Value(), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ using namespace chip::Controller;
JNI_METHOD(jlong, MyClusterCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId)
{
chip::DeviceLayer::StackLock lock;
MyClusterCluster * cppCluster = new MyClusterCluster();

cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
DeviceProxy * device = reinterpret_cast<DeviceProxy *>(devicePtr);
MyClusterCluster * cppCluster = new MyClusterCluster(*device->GetExchangeManager(), device->GetSecureSession().Value(), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ using namespace chip::Controller;
JNI_METHOD(jlong, FirstCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId)
{
chip::DeviceLayer::StackLock lock;
FirstCluster * cppCluster = new FirstCluster();

cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
DeviceProxy * device = reinterpret_cast<DeviceProxy *>(devicePtr);
FirstCluster * cppCluster = new FirstCluster(*device->GetExchangeManager(), device->GetSecureSession().Value(), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ using namespace chip::Controller;
JNI_METHOD(jlong, SecondCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId)
{
chip::DeviceLayer::StackLock lock;
SecondCluster * cppCluster = new SecondCluster();

cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
DeviceProxy * device = reinterpret_cast<DeviceProxy *>(devicePtr);
SecondCluster * cppCluster = new SecondCluster(*device->GetExchangeManager(), device->GetSecureSession().Value(), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ using namespace chip::Controller;
JNI_METHOD(jlong, ThirdCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId)
{
chip::DeviceLayer::StackLock lock;
ThirdCluster * cppCluster = new ThirdCluster();

cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
DeviceProxy * device = reinterpret_cast<DeviceProxy *>(devicePtr);
ThirdCluster * cppCluster = new ThirdCluster(*device->GetExchangeManager(), device->GetSecureSession().Value(), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ using namespace chip::Controller;
JNI_METHOD(jlong, MyClusterCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId)
{
chip::DeviceLayer::StackLock lock;
MyClusterCluster * cppCluster = new MyClusterCluster();

cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
DeviceProxy * device = reinterpret_cast<DeviceProxy *>(devicePtr);
MyClusterCluster * cppCluster = new MyClusterCluster(*device->GetExchangeManager(), device->GetSecureSession().Value(), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/app-platform/ContentAppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ CHIP_ERROR ContentAppPlatform::ManageClientAccess(OperationalDeviceProxy * targe
ChipLogProgress(Controller, "Attempting to update Binding list");
BindingListType bindingList(bindings.data(), bindings.size());

chip::Controller::BindingCluster cluster;
ReturnErrorOnFailure(cluster.Associate(targetDeviceProxy, kTargetBindingClusterEndpointId));
chip::Controller::BindingCluster cluster(*targetDeviceProxy->GetExchangeManager(),
targetDeviceProxy->GetSecureSession().Value(), kTargetBindingClusterEndpointId);

ReturnErrorOnFailure(
cluster.WriteAttribute<Binding::Attributes::Binding::TypeInfo>(bindingList, nullptr, successCb, failureCb));
Expand Down
12 changes: 6 additions & 6 deletions src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,8 @@ CHIP_ERROR DefaultOTARequestor::SendQueryImageRequest(OperationalDeviceProxy & d
args.location.SetValue(CharSpan("XX", strlen("XX")));
}

Controller::OtaSoftwareUpdateProviderCluster cluster;
cluster.Associate(&deviceProxy, mProviderLocation.Value().endpoint);
Controller::OtaSoftwareUpdateProviderCluster cluster(*deviceProxy.GetExchangeManager(), deviceProxy.GetSecureSession().Value(),
mProviderLocation.Value().endpoint);

return cluster.InvokeCommand(args, this, OnQueryImageResponse, OnQueryImageFailure);
}
Expand Down Expand Up @@ -845,8 +845,8 @@ CHIP_ERROR DefaultOTARequestor::SendApplyUpdateRequest(OperationalDeviceProxy &
args.updateToken = mUpdateToken;
args.newVersion = mTargetVersion;

Controller::OtaSoftwareUpdateProviderCluster cluster;
cluster.Associate(&deviceProxy, mProviderLocation.Value().endpoint);
Controller::OtaSoftwareUpdateProviderCluster cluster(*deviceProxy.GetExchangeManager(), deviceProxy.GetSecureSession().Value(),
mProviderLocation.Value().endpoint);

return cluster.InvokeCommand(args, this, OnApplyUpdateResponse, OnApplyUpdateFailure);
}
Expand All @@ -860,8 +860,8 @@ CHIP_ERROR DefaultOTARequestor::SendNotifyUpdateAppliedRequest(OperationalDevice
args.updateToken = mUpdateToken;
args.softwareVersion = mCurrentVersion;

Controller::OtaSoftwareUpdateProviderCluster cluster;
cluster.Associate(&deviceProxy, mProviderLocation.Value().endpoint);
Controller::OtaSoftwareUpdateProviderCluster cluster(*deviceProxy.GetExchangeManager(), deviceProxy.GetSecureSession().Value(),
mProviderLocation.Value().endpoint);

// There is no response for a notify so consider this OTA complete. Clear the provider location and reset any states to indicate
// so.
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/templates/app/CHIPClusters.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Controller {
class DLL_EXPORT {{asUpperCamelCase name}}Cluster : public ClusterBase
{
public:
{{asUpperCamelCase name}}Cluster() : ClusterBase(app::Clusters::{{asUpperCamelCase name}}::Id) {}
{{asUpperCamelCase name}}Cluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, app::Clusters::{{asUpperCamelCase name}}::Id, endpoint) {}
~{{asUpperCamelCase name}}Cluster() {}
};

Expand Down
5 changes: 1 addition & 4 deletions src/controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ config("config") {
static_library("controller") {
output_name = "libChipController"

sources = [
"CHIPCluster.cpp",
"CHIPCluster.h",
]
sources = [ "CHIPCluster.h" ]

if (chip_controller) {
sources += [
Expand Down
51 changes: 0 additions & 51 deletions src/controller/CHIPCluster.cpp

This file was deleted.

Loading

0 comments on commit 342ba68

Please sign in to comment.