Skip to content

Commit

Permalink
Pass the ReadClient to ReadClient::Callback::OnDone. (#18740)
Browse files Browse the repository at this point in the history
This allows a single callback to be used across multiple read clients
as needed, and is symmetric with how WriteClient and CommandSender work.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 20, 2022
1 parent 629a9da commit 1258416
Show file tree
Hide file tree
Showing 23 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ReportCommand : public InteractionModelReports, public ModelCommand, publi
mError = error;
}

void OnDone() override
void OnDone(chip::app::ReadClient *) override
{
InteractionModelReports::Shutdown();
SetCommandExitStatus(mError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac
mError = error;
}

void OnDone() override
void OnDone(chip::app::ReadClient *) override
{
mReadClient.reset();
SetCommandExitStatus(mError);
Expand Down
2 changes: 1 addition & 1 deletion src/app/BufferedReadCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BufferedReadCallback : public ReadClient::Callback
return mCallback.OnEventData(aEventHeader, apData, apStatus);
}

void OnDone() override { return mCallback.OnDone(); }
void OnDone(ReadClient * apReadClient) override { return mCallback.OnDone(apReadClient); }
void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override
{
mCallback.OnSubscriptionEstablished(aSubscriptionId);
Expand Down
4 changes: 2 additions & 2 deletions src/app/ClusterStateCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,10 @@ class ClusterStateCache : protected ReadClient::Callback

void OnEventData(const EventHeader & aEventHeader, TLV::TLVReader * apData, const StatusIB * apStatus) override;

void OnDone() override
void OnDone(ReadClient * apReadClient) override
{
mRequestPathSet.clear();
return mCallback.OnDone();
return mCallback.OnDone(apReadClient);
}

void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override
Expand Down
2 changes: 1 addition & 1 deletion src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void ReadClient::Close(CHIP_ERROR aError)
StopResubscription();
}

mpCallback.OnDone();
mpCallback.OnDone(this);
}

const char * ReadClient::GetStateStr() const
Expand Down
8 changes: 5 additions & 3 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,19 @@ class ReadClient : public Messaging::ExchangeDelegate
virtual void OnError(CHIP_ERROR aError) {}

/**
* OnDone will be called when ReadClient has finished all work and is safe to destroy and free the
* allocated CommandSender object.
* OnDone will be called when ReadClient has finished all work and it is
* safe to destroy and free the allocated ReadClient object and any
* other objects associated with the Read or Subscribe interaction.
*
* This function will:
* - Always be called exactly *once* for a given ReadClient instance.
* - Be called even in error circumstances.
* - Only be called after a successful call to SendRequest has been
* made, when the read completes or the subscription is shut down.
*
* @param[in] apReadClient the ReadClient for the completed interaction.
*/
virtual void OnDone() = 0;
virtual void OnDone(ReadClient * apReadClient) = 0;

/**
* This function is invoked when using SendAutoResubscribeRequest, where the ReadClient was configured to auto re-subscribe
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestBufferedReadCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class DataSeriesValidator : public BufferedReadCallback::Callback
void OnReportBegin() override;
void OnReportEnd() override;
void OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) override;
void OnDone() override {}
void OnDone(ReadClient *) override {}

std::vector<ValidationInstruction> mInstructionList;
uint32_t mCurrentInstruction = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestClusterStateCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class CacheValidator : public ClusterStateCache::Callback
Clusters::TestCluster::Attributes::TypeInfo::DecodableType clusterValue;

private:
void OnDone() override {}
void OnDone(ReadClient *) override {}
void OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) override
{
ChipLogProgress(DataManagement, "\t\t -- Validating OnAttributeData callback");
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class MockInteractionModelApp : public chip::app::ReadClient::Callback
mReadError = true;
}

void OnDone() override {}
void OnDone(chip::app::ReadClient *) override {}

void OnDeallocatePaths(chip::app::ReadPrepareParams && aReadPrepareParams) override
{
Expand Down
7 changes: 6 additions & 1 deletion src/app/tests/integration/chip_im_initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,13 @@ class MockInteractionModelApp : public ::chip::app::CommandSender::Callback,

void OnError(CHIP_ERROR aError) override { printf("ReadError with err %" CHIP_ERROR_FORMAT, aError.Format()); }

void OnDone() override
void OnDone(chip::app::ReadClient * apReadClient) override
{
if (apReadClient != mReadClient.get())
{
printf("Unexpected read client.");
}

if (!mReadClient->IsSubscriptionType())
{
HandleReadComplete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ void InteractionModel::OnError(CHIP_ERROR error)
OnResponse(status, nullptr);
}

void InteractionModel::OnDone()
void InteractionModel::OnDone(ReadClient * aReadClient)
{
// TODO: Keep track of multiple read/subscribe interactions, clear out the
// right thing here.
mReadClient.reset();
ContinueOnChipMainThread(CHIP_NO_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class InteractionModel : public InteractionModelReports,
void OnEventData(const chip::app::EventHeader & eventHeader, chip::TLV::TLVReader * data,
const chip::app::StatusIB * status) override;
void OnError(CHIP_ERROR error) override;
void OnDone() override;
void OnDone(chip::app::ReadClient * aReadClient) override;
void OnSubscriptionEstablished(chip::SubscriptionId subscriptionId) override;

/////////// WriteClient Callback Interface /////////
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ void DeviceCommissioner::OnDeviceConnectionFailureFn(void * context, PeerId peer
}

// ClusterStateCache::Callback impl
void DeviceCommissioner::OnDone()
void DeviceCommissioner::OnDone(app::ReadClient *)
{
CHIP_ERROR err;
CHIP_ERROR return_err = CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
DevicePairingDelegate * GetPairingDelegate() const { return mPairingDelegate; }

// ClusterStateCache::Callback impl
void OnDone() override;
void OnDone(app::ReadClient *) override;

// Commissioner will establish new device connections after PASE.
OperationalDeviceProxy * GetDeviceSession(const PeerId & peerId) override;
Expand Down
4 changes: 2 additions & 2 deletions src/controller/TypedReadCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class TypedReadAttributeCallback final : public app::ReadClient::Callback

void OnError(CHIP_ERROR aError) override { mOnError(nullptr, aError); }

void OnDone() override { mOnDone(this); }
void OnDone(app::ReadClient *) override { mOnDone(this); }

void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override
{
Expand Down Expand Up @@ -173,7 +173,7 @@ class TypedReadEventCallback final : public app::ReadClient::Callback

void OnError(CHIP_ERROR aError) override { mOnError(nullptr, aError); }

void OnDone() override { mOnDone(this); }
void OnDone(app::ReadClient *) override { mOnDone(this); }

void OnDeallocatePaths(chip::app::ReadPrepareParams && aReadPrepareParams) override
{
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/AndroidCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void ReportCallback::OnError(CHIP_ERROR aError)
ReportError(nullptr, aError);
}

void ReportCallback::OnDone()
void ReportCallback::OnDone(app::ReadClient *)
{
JniReferences::GetInstance().GetEnvForCurrentThread()->DeleteGlobalRef(mWrapperCallbackRef);
}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/AndroidCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct ReportCallback : public app::ReadClient::Callback

void OnError(CHIP_ERROR aError) override;

void OnDone() override;
void OnDone(app::ReadClient *) override;

void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override;

Expand Down
2 changes: 1 addition & 1 deletion src/controller/python/chip/clusters/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class ReadClientCallback : public ReadClient::Callback

void OnReportEnd() override { gOnReportEndCallback(mAppContext); }

void OnDone() override
void OnDone(ReadClient *) override
{
gOnReadDoneCallback(mAppContext);

Expand Down
2 changes: 1 addition & 1 deletion src/controller/tests/TestEventCaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class TestReadCallback : public app::ClusterStateCache::Callback
{
public:
TestReadCallback() : mClusterCacheAdapter(*this) {}
void OnDone() {}
void OnDone(app::ReadClient *) {}

app::ClusterStateCache mClusterCacheAdapter;
};
Expand Down
4 changes: 2 additions & 2 deletions src/controller/tests/TestEventChunking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class TestReadCallback : public app::ReadClient::Callback

void OnEventData(const app::EventHeader & aEventHeader, TLV::TLVReader * apData, const app::StatusIB * apStatus) override;

void OnDone() override;
void OnDone(app::ReadClient * apReadClient) override;

void OnReportEnd() override { mOnReportEnd = true; }

Expand Down Expand Up @@ -222,7 +222,7 @@ void TestReadCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::T
mEventCount++;
}

void TestReadCallback::OnDone() {}
void TestReadCallback::OnDone(app::ReadClient *) {}

class TestAttrAccess : public app::AttributeAccessInterface
{
Expand Down
6 changes: 3 additions & 3 deletions src/controller/tests/TestReadChunking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class TestReadCallback : public app::ReadClient::Callback
void OnAttributeData(const app::ConcreteDataAttributePath & aPath, TLV::TLVReader * apData,
const app::StatusIB & aStatus) override;

void OnDone() override;
void OnDone(app::ReadClient * apReadClient) override;

void OnReportEnd() override { mOnReportEnd = true; }

Expand Down Expand Up @@ -198,7 +198,7 @@ void TestReadCallback::OnAttributeData(const app::ConcreteDataAttributePath & aP
mAttributeCount++;
}

void TestReadCallback::OnDone() {}
void TestReadCallback::OnDone(app::ReadClient *) {}

class TestMutableAttrAccess
{
Expand Down Expand Up @@ -295,7 +295,7 @@ class TestMutableReadCallback : public app::ReadClient::Callback
void OnAttributeData(const app::ConcreteDataAttributePath & aPath, TLV::TLVReader * apData,
const app::StatusIB & aStatus) override;

void OnDone() override {}
void OnDone(app::ReadClient *) override {}

void OnReportBegin() override { mAttributeCount = 0; }

Expand Down
4 changes: 2 additions & 2 deletions src/controller/tests/data_model/TestRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class MockInteractionModelApp : public chip::app::ClusterStateCache::Callback
mReadError = true;
}

void OnDone() override {}
void OnDone(app::ReadClient *) override {}

void OnDeallocatePaths(chip::app::ReadPrepareParams && aReadPrepareParams) override
{
Expand Down Expand Up @@ -2052,7 +2052,7 @@ class TestReadCallback : public app::ReadClient::Callback
}
}

void OnDone() override { mOnDone++; }
void OnDone(app::ReadClient *) override { mOnDone++; }

void OnReportEnd() override { mOnReportEnd++; }

Expand Down
6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/CHIPDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ - (instancetype)initWithDevice:(chip::DeviceProxy *)device

void OnError(CHIP_ERROR aError) override;

void OnDone() override;
void OnDone(ReadClient * aReadClient) override;

void OnDeallocatePaths(ReadPrepareParams && aReadPrepareParams) override;

Expand Down Expand Up @@ -789,7 +789,7 @@ void OnAttributeData(

void OnError(CHIP_ERROR aError) override { mOnError(nullptr, aError); }

void OnDone() override { mOnDone(this); }
void OnDone(ReadClient *) override { mOnDone(this); }

void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override
{
Expand Down Expand Up @@ -1487,7 +1487,7 @@ - (instancetype)initWithPath:(const ConcreteEventPath &)path

void SubscriptionCallback::OnError(CHIP_ERROR aError) { ReportError([CHIPError errorForCHIPErrorCode:aError]); }

void SubscriptionCallback::OnDone()
void SubscriptionCallback::OnDone(ReadClient *)
{
if (mOnDoneHandler) {
mOnDoneHandler();
Expand Down

0 comments on commit 1258416

Please sign in to comment.