Skip to content

Commit

Permalink
WIP: remove DeviceProxy pointer in ClusterBase
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost committed Jun 16, 2022
1 parent 3963c1b commit 54ebf42
Show file tree
Hide file tree
Showing 41 changed files with 1,732 additions and 752 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@ using namespace chip::app::Clusters;
{{#chip_client_clusters includeAll=true}}

@interface CHIPTest{{asUpperCamelCase name}} ()
std::unique_ptr<chip::Controller::{{asUpperCamelCase name}}Cluster> _cppCluster;
@property (readonly) chip::Controller::{{asUpperCamelCase name}}Cluster cppCluster;
@end

@implementation CHIPTest{{asUpperCamelCase name}}

- (chip::Controller::ClusterBase *)getCluster
- (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(EndpointId)endpoint queue:(dispatch_queue_t)queue
{
return &_cppCluster;
if (self = [super initWithQueue:queue]) {
if (device == nullptr) {
return nil;
}

_cppCluster.reset(device, endpoint);
}
return self;
}

- chip::Controller::{{asUpperCamelCase name}}Cluster cppCluster
{
return *_cppCluster.get();
}

{{#chip_server_cluster_attributes}}
Expand Down
16 changes: 2 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,7 @@ 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, endpointId);

TargetEndpointInfo * endpointInfo = mTargetVideoPlayerInfo.GetOrAddEndpoint(endpointId);

Expand Down Expand Up @@ -193,13 +187,7 @@ 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, kTvEndpoint);
CastingServer::GetInstance()->mLaunchURLResponseCallback = launchURLResponseCallback;
LaunchURL::Type request;
request.contentURL = chip::CharSpan::fromCharString(contentUrl);
Expand Down
6 changes: 2 additions & 4 deletions scripts/idl/generators/java/ChipClustersCpp.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ 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);
{{cluster.name | capitalcase}}Cluster * cppCluster = new {{cluster.name | capitalcase}}Cluster(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down Expand Up @@ -210,4 +208,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,7 @@ 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);
DemoClusterCluster * cppCluster = new DemoClusterCluster(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ 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);
DemoClusterCluster * cppCluster = new DemoClusterCluster(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ 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);
MyClusterCluster * cppCluster = new MyClusterCluster(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ 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);
FirstCluster * cppCluster = new FirstCluster(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ 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);
SecondCluster * cppCluster = new SecondCluster(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ 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);
ThirdCluster * cppCluster = new ThirdCluster(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ 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);
MyClusterCluster * cppCluster = new MyClusterCluster(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId);
return reinterpret_cast<jlong>(cppCluster);
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/app-platform/ContentAppPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ 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, kTargetBindingClusterEndpointId);

ReturnErrorOnFailure(
cluster.WriteAttribute<Binding::Attributes::Binding::TypeInfo>(bindingList, nullptr, successCb, failureCb));
Expand Down
9 changes: 3 additions & 6 deletions src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,7 @@ 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, mProviderLocation.Value().endpoint);

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

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

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

Controller::OtaSoftwareUpdateProviderCluster cluster;
cluster.Associate(&deviceProxy, mProviderLocation.Value().endpoint);
Controller::OtaSoftwareUpdateProviderCluster cluster(&deviceProxy, 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
3 changes: 2 additions & 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,8 @@ namespace Controller {
class DLL_EXPORT {{asUpperCamelCase name}}Cluster : public ClusterBase
{
public:
{{asUpperCamelCase name}}Cluster() : ClusterBase(app::Clusters::{{asUpperCamelCase name}}::Id) {}
{{asUpperCamelCase name}}Cluster(DeviceProxy * device, EndpointId endpoint) : ClusterBase(*device->GetExchangeManager(), device->GetSecureSession().Value(), app::Clusters::{{asUpperCamelCase name}}::Id, endpoint) {}
//{{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 54ebf42

Please sign in to comment.