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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ static_library("app") {
"MessageDef/ReportData.h",
"MessageDef/StatusElement.cpp",
"MessageDef/StatusElement.h",
"ReadClient.cpp",
"ReadHandler.cpp",
"decoder.cpp",
"encoder.cpp",
]
Expand Down
5 changes: 3 additions & 2 deletions src/app/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CHIP_ERROR Command::Init(Messaging::ExchangeManager * apExchangeMgr)
{
CHIP_ERROR err = CHIP_NO_ERROR;
// Error if already initialized.
VerifyOrExit(apExchangeMgr != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mpExchangeMgr == nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mpExchangeCtx == nullptr, err = CHIP_ERROR_INCORRECT_STATE);

Expand All @@ -57,7 +58,7 @@ CHIP_ERROR Command::Reset()
if (mCommandMessageBuf.IsNull())
{
// TODO: Calculate the packet buffer size
mCommandMessageBuf = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLength);
mCommandMessageBuf = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes);
VerifyOrExit(!mCommandMessageBuf.IsNull(), err = CHIP_ERROR_NO_MEMORY);
}

Expand Down Expand Up @@ -141,7 +142,7 @@ void Command::Shutdown()

chip::TLV::TLVWriter & Command::CreateCommandDataElementTLVWriter()
{
mCommandDataBuf = chip::System::PacketBufferHandle::New(chip::app::kMaxSecureSduLength);
mCommandDataBuf = chip::System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes);
if (mCommandDataBuf.IsNull())
{
ChipLogDetail(DataManagement, "Unable to allocate packet buffer");
Expand Down
2 changes: 1 addition & 1 deletion src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CHIP_ERROR CommandHandler::SendCommandResponse()
err = FinalizeCommandsMessage();
SuccessOrExit(err);

VerifyOrExit(mpExchangeCtx != NULL, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::InvokeCommandResponse, std::move(mCommandMessageBuf),
Messaging::SendFlags(Messaging::SendMessageFlags::kNone));
SuccessOrExit(err);
Expand Down
3 changes: 1 addition & 2 deletions src/app/CommandSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CHIP_ERROR CommandSender::SendCommandRequest(NodeId aNodeId, Transport::AdminId
// TODO: Hard code keyID to 0 to unblock IM end-to-end test. Complete solution is tracked in issue:4451
mpExchangeCtx = mpExchangeMgr->NewContext({ aNodeId, 0, aAdminId }, this);
VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_NO_MEMORY);
mpExchangeCtx->SetResponseTimeout(kImMesssageTimeout);
mpExchangeCtx->SetResponseTimeout(kImMessageTimeoutMsec);

err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::InvokeCommandRequest, std::move(mCommandMessageBuf),
Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse));
Expand Down Expand Up @@ -92,7 +92,6 @@ void CommandSender::OnMessageReceived(Messaging::ExchangeContext * apExchangeCon

exit:
Reset();
return;
}

void CommandSender::OnResponseTimeout(Messaging::ExchangeContext * apExchangeContext)
Expand Down
82 changes: 82 additions & 0 deletions src/app/InteractionModelDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file defines the delegate the SDK consumer needs to implement to receive notifications from the interaction model.
*
*/

#pragma once

#include <core/CHIPCore.h>
#include <messaging/ExchangeContext.h>
#include <system/SystemPacketBuffer.h>

namespace chip {
namespace app {
class ReadClient;
struct EventPathParams;

/**
* @brief
* This class defines the API for a delegate that an SDK consumer can use to interface with the interaction model.
*/
class InteractionModelDelegate
{
public:
/**
* Notification that the interaction model has received a list of events in response to a Read request and that list
* of events needs to be processed.
* @param[in] apExchangeContext An exchange context that represents the exchange the Report Data came in on.
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
* This can be used to recover the NodeId of the node that sent the Report Data.
* It is managed externally and should not be closed by the SDK consumer.
* @param[in] apEventListReader TLV reader positioned at the list that contains the events. The
* implementation of EventStreamReceived is expected to call Next() on the reader to
* advance it to the first element of the list, then process the elements from beginning to the
* end. The callee is expected to consume all events.
*
* @retval # CHIP_ERROR_NOT_IMPLEMENTED if not implemented
*/
virtual CHIP_ERROR EventStreamReceived(const Messaging::ExchangeContext * apExchangeContext, TLV::TLVReader * apEventListReader)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

/**
* Notification that the last message for a Report Data action for the given ReadClient has been received and processed.
* @param[in] apReadClient A current readClient which can identify the read to the consumer, particularly during
* multiple read interactions
* @retval # CHIP_ERROR_NOT_IMPLEMENTED if not implemented
*/
virtual CHIP_ERROR ReportProcessed(const ReadClient * apReadClient) { return CHIP_ERROR_NOT_IMPLEMENTED; }

/**
* Notification that a read attempt encountered an asynchronous failure.
* @param[in] apReadClient A current readClient which can identify the read to the consumer, particularly during
* multiple read interactions
* @param[in] aError A error that could be CHIP_ERROR_TIMEOUT when read client fails to receive, or other error when
* fail to process report data.
* @retval # CHIP_ERROR_NOT_IMPLEMENTED if not implemented
*/
virtual CHIP_ERROR ReportError(const ReadClient * apReadClient, CHIP_ERROR aError) { return CHIP_ERROR_NOT_IMPLEMENTED; }

virtual ~InteractionModelDelegate() = default;
};

} // namespace app
} // namespace chip
Loading