Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReadClient and ReaderHandler and interactionModelDelegate #5198

Conversation

yunhanw-google
Copy link
Contributor

@yunhanw-google yunhanw-google commented Mar 6, 2021

Problem:
Need read client to send IM read request and process report and read handler to process
read request, need interaction model delegate to notify zcl the actions
in corresponse for particular IM callback.

Summary of Changes:
-- Add read client to send IM read request and process report.
-- Add read handler to process read request
-- Add interaction model delgate to notify when each IM event stream is received and
all reports have been received and so on.

Note: This is PR splited from large PR #4800

@boring-cyborg boring-cyborg bot added the app label Mar 6, 2021
@todo
Copy link

todo bot commented Mar 6, 2021

Add status report support and correspond handler in ReadHandler, particular for situation when there

// TODO: Add status report support and correspond handler in ReadHandler, particular for situation when there
// are multiple reports
}
if (nullptr != mpDelegate && !moreChunkedMessages)
{
inParam.Clear();
outParam.Clear();
mpDelegate->HandleIMCallBack(chip::app::InteractionModelDelegate::CallbackId::kReportProcessed, inParam, outParam);
}
exit:


This comment was generated by todo based on a TODO comment in 5d72c9e in #5198. cc @yunhanw-google.

src/app/InteractionModelDelegate.h Outdated Show resolved Hide resolved
src/app/InteractionModelEngine.cpp Outdated Show resolved Hide resolved
src/app/ReadClient.cpp Show resolved Hide resolved
@woody-apple
Copy link
Contributor

@vivien-apple ?

Copy link
Contributor

@mspang mspang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about unit tests for this code?

src/app/InteractionModelDelegate.h Outdated Show resolved Hide resolved
@yunhanw-google
Copy link
Contributor Author

What about unit tests for this code?

Done, thanks

@yunhanw-google yunhanw-google force-pushed the feature/add_im_read_client_handler branch 3 times, most recently from 5e20828 to 476df57 Compare March 11, 2021 06:31
@yunhanw-google yunhanw-google force-pushed the feature/add_im_read_client_handler branch 3 times, most recently from 1054770 to 3e2dc7c Compare March 17, 2021 20:25
@todo
Copy link

todo bot commented Mar 17, 2021

Fix the below check after the above status report is implemented.

// Todo: Fix the below check after the above status report is implemented.
if (nullptr != apExchangeContext)
{
apExchangeContext->Abort();
}
}
void InteractionModelEngine::OnInvokeCommandRequest(Messaging::ExchangeContext * apExchangeContext,
const PacketHeader & aPacketHeader, const PayloadHeader & aPayloadHeader,
System::PacketBufferHandle aPayload)
{


This comment was generated by todo based on a Todo comment in 3e2dc7c in #5198. cc @yunhanw-google.

src/app/InteractionModelDelegate.h Outdated Show resolved Hide resolved
src/app/InteractionModelDelegate.h Outdated Show resolved Hide resolved
src/app/InteractionModelDelegate.h Outdated Show resolved Hide resolved
src/app/InteractionModelDelegate.h Outdated Show resolved Hide resolved
src/app/InteractionModelEngine.h Outdated Show resolved Hide resolved
src/app/ReadHandler.h Outdated Show resolved Hide resolved
src/app/ReadHandler.h Outdated Show resolved Hide resolved
src/app/ReadHandler.cpp Outdated Show resolved Hide resolved
src/app/ReadHandler.cpp Outdated Show resolved Hide resolved
src/app/ReadHandler.cpp Outdated Show resolved Hide resolved
@yunhanw-google yunhanw-google force-pushed the feature/add_im_read_client_handler branch from 46470ea to 3a9ced4 Compare March 17, 2021 21:29
@todo
Copy link

todo bot commented Mar 17, 2021

Once status report support is added, we would shutdown only when there is error

//Todo: Once status report support is added, we would shutdown only when there is error
exit:
Shutdown();
return err;
}
CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle aPayload)
{
CHIP_ERROR err = CHIP_NO_ERROR;
System::PacketBufferTLVReader reader;


This comment was generated by todo based on a Todo comment in 3a9ced4 in #5198. cc @yunhanw-google.

@yunhanw-google yunhanw-google force-pushed the feature/add_im_read_client_handler branch from 3a9ced4 to eea899c Compare March 17, 2021 22:24
@todo
Copy link

todo bot commented Mar 17, 2021

Once status report support is added, we would shutdown only when there is error or when this is last chunk of report

//Todo: Once status report support is added, we would shutdown only when there is error or when this is last chunk of report
exit:
Shutdown();
return err;
}
CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle aPayload)
{
CHIP_ERROR err = CHIP_NO_ERROR;
System::PacketBufferTLVReader reader;


This comment was generated by todo based on a Todo comment in eea899c in #5198. cc @yunhanw-google.

@yunhanw-google yunhanw-google force-pushed the feature/add_im_read_client_handler branch 2 times, most recently from 70c9662 to 5d4e632 Compare March 17, 2021 23:07
Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I think this hangs together now, but I've been thinking about this and I have two architectural concerns:

  1. I question the desirability of a reusable ReadClient and the attendant lifetime-management complexity being foisted on the SDK consumer. There are various things we could do to make this better, and some of them can probably be done on top of this PR, so I'm not going to block it, but I think we should very seriously think about something that would be both safer and easier to use.

For example, we could have a ReadClientHandle that allows move-construction and move-assignment only, except from inside the IM engine. The handle would point to a client and vice versa, with destructors cleaning up the references, and the move stuff on handle updating them. You could compare a handle to a client pointer, and you could shut the client down via the handle, but that's all you could do with a handle. When the client is done, it would shut itself down and null out the handle. This would guarantee that (a) you don't have to worry about shutting down the read client unless you want to terminate an in-progress read and (b) you can't mess up and shut down a different read from the one you meant to shut down because you kept a pointer to something around past a certain point. Please strongly consider filing a followup bug on this.

  1. I am very worried about exposing the raw TLV to SDK consumers. The TLV reader API is not particularly easy to use, unfortunately. Again, I guess we can do this for the moment, but it seems to me that we're eventually going to want a nicer API. What the size cost of that would be is a hard question, but I would really like something safer to use than "here, read some tlv; good luck", especially when the rules around reading TLV are not well-internalized even by CHIP developers and are not well-described in the spec.

src/app/InteractionModelDelegate.h Outdated Show resolved Hide resolved
src/app/InteractionModelEngine.h Outdated Show resolved Hide resolved
src/app/ReadClient.h Outdated Show resolved Hide resolved
src/app/ReadClient.h Outdated Show resolved Hide resolved
src/app/ReadClient.h Outdated Show resolved Hide resolved
@yunhanw-google
Copy link
Contributor Author

#5446
#5447

OK. I think this hangs together now, but I've been thinking about this and I have two architectural concerns:

  1. I question the desirability of a reusable ReadClient and the attendant lifetime-management complexity being foisted on the SDK consumer. There are various things we could do to make this better, and some of them can probably be done on top of this PR, so I'm not going to block it, but I think we should very seriously think about something that would be both safer and easier to use.

For example, we could have a ReadClientHandle that allows move-construction and move-assignment only, except from inside the IM engine. The handle would point to a client and vice versa, with destructors cleaning up the references, and the move stuff on handle updating them. You could compare a handle to a client pointer, and you could shut the client down via the handle, but that's all you could do with a handle. When the client is done, it would shut itself down and null out the handle. This would guarantee that (a) you don't have to worry about shutting down the read client unless you want to terminate an in-progress read and (b) you can't mess up and shut down a different read from the one you meant to shut down because you kept a pointer to something around past a certain point. Please strongly consider filing a followup bug on this.

  1. I am very worried about exposing the raw TLV to SDK consumers. The TLV reader API is not particularly easy to use, unfortunately. Again, I guess we can do this for the moment, but it seems to me that we're eventually going to want a nicer API. What the size cost of that would be is a hard question, but I would really like something safer to use than "here, read some tlv; good luck", especially when the rules around reading TLV are not well-internalized even by CHIP developers and are not well-described in the spec.

Problem:
Need read client to send IM read request and process report and read handler to process
read request, need interaction model delegate to notify zcl the actions
in corresponse for particular IM callback.

Summary of Changes:
-- Add read client to send IM read request and process report.
-- Add read handler to process read request
-- Add interaction model delgate to notify when each IM event stream is received and
all reports have been received and so on.
@yunhanw-google yunhanw-google force-pushed the feature/add_im_read_client_handler branch from 66be4f4 to 84001c7 Compare March 18, 2021 16:00
{
Uninitialized = 0, //< The handler has not been initialized
Initialized, //< The handler has been initialized and is ready
Reportable, //< The handler has received read request and is waiting for the data to send to be available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

jimlyall-q pushed a commit to jimlyall-q/connectedhomeip that referenced this pull request Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants