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

Introduce header files for the OTA Requestor API declarations #11605

Merged
merged 13 commits into from
Nov 12, 2021
50 changes: 50 additions & 0 deletions src/app/clusters/ota-requestor/ota-downloader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
*
* 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 the declarations for the OTADownloader class which
* abstracts the image download functionality from the particular protocol
* used for it.
* Applications and platforms implementing the OTA Requestor functionality
* must include this file
*/

#include <ota-image-processor.h>
selissia marked this conversation as resolved.
Show resolved Hide resolved

#pragma once

// A class that abstracts the image download functionality from the particular
// protocol used for that (BDX or possibly HTTPS)
class OTADownloader : public BlockWriter
selissia marked this conversation as resolved.
Show resolved Hide resolved
{
public:
selissia marked this conversation as resolved.
Show resolved Hide resolved
// API declarations start

// Application calls this method to direct OTADownloader to begin the download
void BeginDownload();
selissia marked this conversation as resolved.
Show resolved Hide resolved

// Platform calls this method upon the completion of PrepareDownload() processing
void OnDownloadPrepared();
selissia marked this conversation as resolved.
Show resolved Hide resolved

// Platform calls this method upon the completion of ProcessBlock() processing
void OnBlockProcessed(action);
selissia marked this conversation as resolved.
Show resolved Hide resolved

// API declarations end
selissia marked this conversation as resolved.
Show resolved Hide resolved

// Invoked by an incoming block
void HandleBlock();
selissia marked this conversation as resolved.
Show resolved Hide resolved
};
47 changes: 47 additions & 0 deletions src/app/clusters/ota-requestor/ota-image-processor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* 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 the declarations for OTAImageProcessor, a platform-agnostic
* interface for processing downloaded chunks of OTA image data.
* Each platform should provide an implementation of this interface.
*/

#pragma once

selissia marked this conversation as resolved.
Show resolved Hide resolved
// This is a platform-agnostic interface for processing downloaded
// chunks of OTA image data (data could be raw image data meant for flash or
// metadata). Each platform should provide an implementation of this
// interface.
class OTAImageProcessor
{
public:
// Open file, find block of space in persistent memory, or allocate a buffer, etc.
selissia marked this conversation as resolved.
Show resolved Hide resolved
virtual CHIP_ERROR PrepareDownload() = 0;

// Must not be a blocking call to support cases that require IO to elements such as // external peripherals/radios
virtual CHIP_ERROR ProcessBlock(ByteSpan & data) = 0;

// Close file, close persistent storage, etc
virtual CHIP_ERROR Finalize() = 0;

virtual chip::Optional<uint8_t> PercentComplete() = 0;

// Clean up the download which could mean erasing everything that was written,
// releasing buffers, etc.
virtual CHIP_ERROR Abort() = 0;
};
selissia marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions src/app/clusters/ota-requestor/ota-requestor-driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* 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 the declaration for the OTARequestorDriver class, an interface
* that abstracts the OTA-related business logic out of the Requestor functionality in
* the Matter SDK. Applications implementing the OTA Requestor functionality must include
* this file.
*/

#pragma once

// Interface class to abstract the OTA-related business logic. Each application
// must implement this interface. All calls must be non-blocking unless stated otherwise
class OTARequestorDriver
{
public:
// A call into the application logic to give it a chance to allow or stop the Requestor
// from proceeding with actual image download. Returning TRUE will allow the download
// to proceed, returning FALSE will abort the download process.
virtual bool CheckImageDownloadAllowed() = 0;
holbrookt marked this conversation as resolved.
Show resolved Hide resolved

// Notify the application that the download is complete and the image can be applied
virtual void ImageDownloadComplete() = 0;
};
36 changes: 36 additions & 0 deletions src/app/clusters/ota-requestor/ota-requestor-interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
*
* 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 the declaration for the OTA Requestor interface.
* Any implementation of the OTA Requestor (e.g. the OTARequestor class) must implement
* this interface.
*/

#pragma once

// Interface class to connect the OTA Software Update Requestor cluster command processing
// with the core OTA Requestor logic. The OTARequestor class implements this interface
class OTARequestorInterface
{
selissia marked this conversation as resolved.
Show resolved Hide resolved
public:
selissia marked this conversation as resolved.
Show resolved Hide resolved
// Handler for the AnnounceOTAProvider command
virtual bool HandleAnnounceOTAProvider(commandData_t) = 0;
selissia marked this conversation as resolved.
Show resolved Hide resolved

// Handler for the QueryImageResponse command
virtual bool HandleQueryImageResponse(commandData_t) = 0;
};
selissia marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 42 additions & 0 deletions src/app/clusters/ota-requestor/ota-requestor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* 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 the declarations for the Matter OTA Requestor implementation and API.
selissia marked this conversation as resolved.
Show resolved Hide resolved
* Applications implementing the OTA Requestor functionality must include this file.
*/

#include <ota-requestor-driver.h>
#include <ota-requestor-interface.h>

#pragma once

// This class implements all of the core logic of the OTA Requestor
class OTARequestor : public OTARequestorInterface
selissia marked this conversation as resolved.
Show resolved Hide resolved
{
public:
// Application interface declarations start

// Application directs the Requestor to start the Image Query process
// and download the new image if available
void TriggerImmediateQuery();
selissia marked this conversation as resolved.
Show resolved Hide resolved

// Application interface declarations end

private:
OTARequestorDriver * driver;
};