-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the client side of timed write. (#12567)
Fixes that had to be made alongside the main change: 1) Fix chip-tool to use the templated WriteAttribute for its command-line writes so we can actually pass in the timeout optional parameter for testing. 2) Factor some code for dealing with timed interactions out of CommandSender into TimedRequest so WriteClient can share it. 3) Fix the OnError signature for WriteClient::Callback to take a StatusIB, so we can properly communicate errors back and actually test for them in YAML.
- Loading branch information
1 parent
eeeed82
commit 1351880
Showing
25 changed files
with
2,350 additions
and
2,030 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "TimedRequest.h" | ||
|
||
#include <app/MessageDef/TimedRequestMessage.h> | ||
#include <app/StatusResponse.h> | ||
#include <protocols/interaction_model/Constants.h> | ||
#include <system/TLVPacketBufferBackingStore.h> | ||
#include <transport/SessionManager.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
|
||
using namespace Protocols::InteractionModel; | ||
using namespace Messaging; | ||
|
||
CHIP_ERROR TimedRequest::Send(ExchangeContext * aExchangeContext, uint16_t aTimeoutMs) | ||
{ | ||
// The payload is an anonymous struct (2 bytes) containing a single | ||
// 16-bit integer with a context tag (1 control byte, 1 byte tag, at | ||
// most 2 bytes for the integer). Use MessagePacketBuffer::New to | ||
// account for other message-global overheads (MIC, etc). | ||
System::PacketBufferHandle payload = MessagePacketBuffer::New(6); | ||
VerifyOrReturnError(!payload.IsNull(), CHIP_ERROR_NO_MEMORY); | ||
|
||
System::PacketBufferTLVWriter writer; | ||
writer.Init(std::move(payload)); | ||
|
||
TimedRequestMessage::Builder builder; | ||
ReturnErrorOnFailure(builder.Init(&writer)); | ||
|
||
builder.TimeoutMs(aTimeoutMs); | ||
ReturnErrorOnFailure(builder.GetError()); | ||
|
||
ReturnErrorOnFailure(writer.Finalize(&payload)); | ||
|
||
return aExchangeContext->SendMessage(MsgType::TimedRequest, std::move(payload), SendMessageFlags::kExpectResponse); | ||
} | ||
|
||
CHIP_ERROR TimedRequest::HandleResponse(const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload, | ||
StatusIB & aStatusIB) | ||
{ | ||
VerifyOrReturnError(aPayloadHeader.HasMessageType(MsgType::StatusResponse), CHIP_ERROR_INVALID_MESSAGE_TYPE); | ||
|
||
ReturnErrorOnFailure(StatusResponse::ProcessStatusResponse(std::move(aPayload), aStatusIB)); | ||
|
||
VerifyOrReturnError(aStatusIB.mStatus == Status::Success, CHIP_ERROR_IM_STATUS_CODE_RECEIVED); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/MessageDef/StatusIB.h> | ||
#include <lib/core/CHIPError.h> | ||
#include <messaging/ExchangeContext.h> | ||
#include <system/SystemPacketBuffer.h> | ||
#include <transport/raw/MessageHeader.h> | ||
|
||
#include <cstdint> | ||
|
||
namespace chip { | ||
namespace app { | ||
class TimedRequest | ||
{ | ||
public: | ||
// Send a timed request with the given timeout value on the given exchange. | ||
static CHIP_ERROR Send(Messaging::ExchangeContext * aExchangeContext, uint16_t aTimeoutMs); | ||
|
||
// Handle a response message (which may not actually be a StatusResponse, | ||
// but came in after we sent a timed request). | ||
static CHIP_ERROR HandleResponse(const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload, | ||
StatusIB & aStatusIB); | ||
}; | ||
|
||
} // namespace app | ||
} // namespace chip |
Oops, something went wrong.