Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2021 Project CHIP Authors
4 : * All rights reserved.
5 : *
6 : * Licensed under the Apache License, Version 2.0 (the "License");
7 : * you may not use this file except in compliance with the License.
8 : * You may obtain a copy of the License at
9 : *
10 : * http://www.apache.org/licenses/LICENSE-2.0
11 : *
12 : * Unless required by applicable law or agreed to in writing, software
13 : * distributed under the License is distributed on an "AS IS" BASIS,
14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : * See the License for the specific language governing permissions and
16 : * limitations under the License.
17 : */
18 :
19 : #include "TimedRequest.h"
20 :
21 : #include <app/MessageDef/TimedRequestMessage.h>
22 : #include <app/StatusResponse.h>
23 : #include <protocols/interaction_model/Constants.h>
24 : #include <system/TLVPacketBufferBackingStore.h>
25 : #include <transport/SessionManager.h>
26 :
27 : namespace chip {
28 : namespace app {
29 :
30 : using namespace Protocols::InteractionModel;
31 : using namespace Messaging;
32 :
33 0 : CHIP_ERROR TimedRequest::Send(ExchangeContext * aExchangeContext, uint16_t aTimeoutMs)
34 : {
35 : // The payload is an anonymous struct (2 bytes) containing a single
36 : // 16-bit integer with two context tag (1 control byte, 1 byte tag, at
37 : // most 2 bytes for the timeout integer and 1 control byte, 1 byte tag, one byte for InteractionModelRevision). Use
38 : // MessagePacketBuffer::New to account for other message-global overheads (MIC, etc).
39 0 : System::PacketBufferHandle payload = MessagePacketBuffer::New(9);
40 0 : VerifyOrReturnError(!payload.IsNull(), CHIP_ERROR_NO_MEMORY);
41 :
42 0 : System::PacketBufferTLVWriter writer;
43 0 : writer.Init(std::move(payload));
44 :
45 0 : TimedRequestMessage::Builder builder;
46 0 : ReturnErrorOnFailure(builder.Init(&writer));
47 :
48 0 : builder.TimeoutMs(aTimeoutMs);
49 0 : ReturnErrorOnFailure(builder.GetError());
50 :
51 0 : ReturnErrorOnFailure(writer.Finalize(&payload));
52 :
53 0 : return aExchangeContext->SendMessage(MsgType::TimedRequest, std::move(payload), SendMessageFlags::kExpectResponse);
54 0 : }
55 :
56 : } // namespace app
57 : } // namespace chip
|