-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathBDXDownloader.h
76 lines (61 loc) · 2.7 KB
/
BDXDownloader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
*
* 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.
*/
/* This file contains a definition for a class that implements OTADownloader and downloads CHIP OTA images using the BDX protocol.
* It should not execute any logic that is application specific.
*/
// TODO: unit tests
#pragma once
#include "OTADownloader.h"
#include <lib/core/CHIPError.h>
#include <protocols/bdx/BdxTransferSession.h>
#include <system/SystemPacketBuffer.h>
#include <transport/raw/MessageHeader.h>
namespace chip {
class BDXDownloader : public chip::OTADownloader
{
public:
// A delegate for passing messages to/from BDXDownloader and some messaging layer. This is mainly to make BDXDownloader more
// easily unit-testable.
class MessagingDelegate
{
public:
virtual CHIP_ERROR SendMessage(const chip::bdx::TransferSession::OutputEvent & msgEvent) = 0;
virtual ~MessagingDelegate() {}
};
BDXDownloader() : chip::OTADownloader() {}
// To be called when there is an incoming message to handle (of any protocol type)
void OnMessageReceived(const chip::PayloadHeader & payloadHeader, chip::System::PacketBufferHandle msg);
void SetMessageDelegate(MessagingDelegate * delegate) { mMsgDelegate = delegate; }
// Initialize a BDX transfer session but will not proceed until OnPreparedForDownload() is called.
CHIP_ERROR SetBDXParams(const chip::bdx::TransferSession::TransferInitData & bdxInitData);
// OTADownloader Overrides
CHIP_ERROR BeginPrepareDownload() override;
CHIP_ERROR OnPreparedForDownload(CHIP_ERROR status) override;
void OnDownloadTimeout() override;
// BDX does not provide a mechanism for the driver of a transfer to gracefully end the exchange, so it will abort the transfer
// instead.
void EndDownload(CHIP_ERROR reason = CHIP_NO_ERROR) override;
CHIP_ERROR FetchNextData() override;
// TODO: override SkipData
private:
void PollTransferSession();
CHIP_ERROR HandleBdxEvent(const chip::bdx::TransferSession::OutputEvent & outEvent);
chip::bdx::TransferSession mBdxTransfer;
MessagingDelegate * mMsgDelegate;
};
} // namespace chip