From 340ac67bd551855a470ae0658cfbc716483803f6 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Tue, 9 Nov 2021 16:18:54 -0500 Subject: [PATCH 01/12] Introduce ota-requestor.h containing Requestor API declarations --- .../clusters/ota-requestor/ota-requestor.h | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/app/clusters/ota-requestor/ota-requestor.h diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h new file mode 100644 index 00000000000000..b18a65a88ddb64 --- /dev/null +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -0,0 +1,109 @@ +/* + * + * 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. + * Applications and platforms 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. + virtual bool AllowImageDownload() = 0; + + // Notify the application that the download is complete and the image can be applied + virtual void ImageReadyToBeApplied() = 0; +}; + +// 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 { +public: + // Handler for the AnnounceOTAProvider command + virtual bool HandleAnnounceOTAProvider(commandData_t) = 0; + + // Handler for the QueryImageResponse command + virtual bool HandleQueryImageResponse(commandData_t) = 0; +}; + +// This class implements all of the core logic of the OTA Requestor +class OTARequestor : public OTARequestorInterface { +public: + // Application interface declarations start + + // Application directs the Requestor to start the Image Query process + // and download and apply the new image if available + void TriggerImmediateQuery(); + + // Application interface declarations end + +private: + OTARequestorDriver *driver; +}; + +// 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. + 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 + // (probably should not actually apply the image) + virtual CHIP_ERROR Finalize() = 0; + + virtual chip::Optional PercentComplete() = 0; + + // Clean up the download which could mean erasing everything that was written, + // releasing buffers, etc. + virtual CHIP_ERROR Abort() = 0; +}; + +// A class that abstracts the image download functionality from the particular +// protocol used for that (BDX or possibly HTTPS) +class OTADownloader : public BlockWriter { +public: + + // API declarations start + + // Application calls this method to direct OTADownloader to begin the download + void BeginDownload(); + + // Platform calls this method upon the completion of PrepareDownload() processing + void OnDownloadPrepared(); + + // Platform calls this method upon the completion of ProcessBlock() processing + void OnBlockProcessed(action); + + // API declarations end + + // Invoked by an incoming block + void HandleBlock(); +}; + + From 69b31edd0ecd2564590c32b47208712115582682 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Wed, 10 Nov 2021 09:53:06 -0500 Subject: [PATCH 02/12] Split OTA Requestor class declarations into multiple headers --- .../clusters/ota-requestor/ota-downloader.h | 52 +++++++++++++ .../ota-requestor/ota-image-processor.h | 72 +++++++++++++++++ .../ota-requestor/ota-requestor-driver.h | 42 ++++++++++ .../ota-requestor/ota-requestor-interface.h | 36 +++++++++ .../clusters/ota-requestor/ota-requestor.h | 78 ++----------------- 5 files changed, 208 insertions(+), 72 deletions(-) create mode 100644 src/app/clusters/ota-requestor/ota-downloader.h create mode 100644 src/app/clusters/ota-requestor/ota-image-processor.h create mode 100644 src/app/clusters/ota-requestor/ota-requestor-driver.h create mode 100644 src/app/clusters/ota-requestor/ota-requestor-interface.h diff --git a/src/app/clusters/ota-requestor/ota-downloader.h b/src/app/clusters/ota-requestor/ota-downloader.h new file mode 100644 index 00000000000000..1efe8edb95e686 --- /dev/null +++ b/src/app/clusters/ota-requestor/ota-downloader.h @@ -0,0 +1,52 @@ +/* + * + * 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 + +#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 { +public: + + // API declarations start + + // Application calls this method to direct OTADownloader to begin the download + void BeginDownload(); + + // Platform calls this method upon the completion of PrepareDownload() processing + void OnDownloadPrepared(); + + // Platform calls this method upon the completion of ProcessBlock() processing + void OnBlockProcessed(action); + + // API declarations end + + // Invoked by an incoming block + void HandleBlock(); +}; + + diff --git a/src/app/clusters/ota-requestor/ota-image-processor.h b/src/app/clusters/ota-requestor/ota-image-processor.h new file mode 100644 index 00000000000000..761ba68ca953fb --- /dev/null +++ b/src/app/clusters/ota-requestor/ota-image-processor.h @@ -0,0 +1,72 @@ +/* + * + * 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 + + +// 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. + 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 + // (probably should not actually apply the image) + virtual CHIP_ERROR Finalize() = 0; + + virtual chip::Optional PercentComplete() = 0; + + // Clean up the download which could mean erasing everything that was written, + // releasing buffers, etc. + virtual CHIP_ERROR Abort() = 0; +}; + +// A class that abstracts the image download functionality from the particular +// protocol used for that (BDX or possibly HTTPS) +class OTADownloader : public BlockWriter { +public: + + // API declarations start + + // Application calls this method to direct OTADownloader to begin the download + void BeginDownload(); + + // Platform calls this method upon the completion of PrepareDownload() processing + void OnDownloadPrepared(); + + // Platform calls this method upon the completion of ProcessBlock() processing + void OnBlockProcessed(action); + + // API declarations end + + // Invoked by an incoming block + void HandleBlock(); +}; + + diff --git a/src/app/clusters/ota-requestor/ota-requestor-driver.h b/src/app/clusters/ota-requestor/ota-requestor-driver.h new file mode 100644 index 00000000000000..34bc27ee47c784 --- /dev/null +++ b/src/app/clusters/ota-requestor/ota-requestor-driver.h @@ -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 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 AllowImageDownload() = 0; + + // Notify the application that the download is complete and the image can be applied + virtual void ImageDownloadComplete() = 0; +}; + + + + diff --git a/src/app/clusters/ota-requestor/ota-requestor-interface.h b/src/app/clusters/ota-requestor/ota-requestor-interface.h new file mode 100644 index 00000000000000..5d6f4bce4927ac --- /dev/null +++ b/src/app/clusters/ota-requestor/ota-requestor-interface.h @@ -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 { +public: + // Handler for the AnnounceOTAProvider command + virtual bool HandleAnnounceOTAProvider(commandData_t) = 0; + + // Handler for the QueryImageResponse command + virtual bool HandleQueryImageResponse(commandData_t) = 0; +}; + diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h index b18a65a88ddb64..424b3360c2fffa 100644 --- a/src/app/clusters/ota-requestor/ota-requestor.h +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -17,42 +17,21 @@ */ /* This file contains the declarations for the Matter OTA Requestor implementation and API. - * Applications and platforms implementing the OTA Requestor functionality must include this - * file + * 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. - virtual bool AllowImageDownload() = 0; - - // Notify the application that the download is complete and the image can be applied - virtual void ImageReadyToBeApplied() = 0; -}; - -// 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 { -public: - // Handler for the AnnounceOTAProvider command - virtual bool HandleAnnounceOTAProvider(commandData_t) = 0; +#include +#include - // Handler for the QueryImageResponse command - virtual bool HandleQueryImageResponse(commandData_t) = 0; -}; +#pragma once -// This class implements all of the core logic of the OTA Requestor +// This class implements all of the core logic of the OTA Requestor class OTARequestor : public OTARequestorInterface { public: // Application interface declarations start // Application directs the Requestor to start the Image Query process - // and download and apply the new image if available + // and download the new image if available void TriggerImmediateQuery(); // Application interface declarations end @@ -61,49 +40,4 @@ class OTARequestor : public OTARequestorInterface { OTARequestorDriver *driver; }; -// 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. - 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 - // (probably should not actually apply the image) - virtual CHIP_ERROR Finalize() = 0; - - virtual chip::Optional PercentComplete() = 0; - - // Clean up the download which could mean erasing everything that was written, - // releasing buffers, etc. - virtual CHIP_ERROR Abort() = 0; -}; - -// A class that abstracts the image download functionality from the particular -// protocol used for that (BDX or possibly HTTPS) -class OTADownloader : public BlockWriter { -public: - - // API declarations start - - // Application calls this method to direct OTADownloader to begin the download - void BeginDownload(); - - // Platform calls this method upon the completion of PrepareDownload() processing - void OnDownloadPrepared(); - - // Platform calls this method upon the completion of ProcessBlock() processing - void OnBlockProcessed(action); - - // API declarations end - - // Invoked by an incoming block - void HandleBlock(); -}; - From 5d41f87bb9e719406c04fac1a65d605c1c291880 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 10 Nov 2021 14:53:44 +0000 Subject: [PATCH 03/12] Restyled by whitespace --- src/app/clusters/ota-requestor/ota-downloader.h | 2 -- src/app/clusters/ota-requestor/ota-image-processor.h | 2 -- src/app/clusters/ota-requestor/ota-requestor-driver.h | 4 ---- src/app/clusters/ota-requestor/ota-requestor-interface.h | 1 - src/app/clusters/ota-requestor/ota-requestor.h | 2 -- 5 files changed, 11 deletions(-) diff --git a/src/app/clusters/ota-requestor/ota-downloader.h b/src/app/clusters/ota-requestor/ota-downloader.h index 1efe8edb95e686..a38134c7bfc962 100644 --- a/src/app/clusters/ota-requestor/ota-downloader.h +++ b/src/app/clusters/ota-requestor/ota-downloader.h @@ -48,5 +48,3 @@ class OTADownloader : public BlockWriter { // Invoked by an incoming block void HandleBlock(); }; - - diff --git a/src/app/clusters/ota-requestor/ota-image-processor.h b/src/app/clusters/ota-requestor/ota-image-processor.h index 761ba68ca953fb..12c0f31425eb0f 100644 --- a/src/app/clusters/ota-requestor/ota-image-processor.h +++ b/src/app/clusters/ota-requestor/ota-image-processor.h @@ -68,5 +68,3 @@ class OTADownloader : public BlockWriter { // Invoked by an incoming block void HandleBlock(); }; - - diff --git a/src/app/clusters/ota-requestor/ota-requestor-driver.h b/src/app/clusters/ota-requestor/ota-requestor-driver.h index 34bc27ee47c784..5b244a03fa499d 100644 --- a/src/app/clusters/ota-requestor/ota-requestor-driver.h +++ b/src/app/clusters/ota-requestor/ota-requestor-driver.h @@ -36,7 +36,3 @@ class OTARequestorDriver { // Notify the application that the download is complete and the image can be applied virtual void ImageDownloadComplete() = 0; }; - - - - diff --git a/src/app/clusters/ota-requestor/ota-requestor-interface.h b/src/app/clusters/ota-requestor/ota-requestor-interface.h index 5d6f4bce4927ac..80b6a3590172cd 100644 --- a/src/app/clusters/ota-requestor/ota-requestor-interface.h +++ b/src/app/clusters/ota-requestor/ota-requestor-interface.h @@ -33,4 +33,3 @@ class OTARequestorInterface { // Handler for the QueryImageResponse command virtual bool HandleQueryImageResponse(commandData_t) = 0; }; - diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h index 424b3360c2fffa..bc1ce684360f11 100644 --- a/src/app/clusters/ota-requestor/ota-requestor.h +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -39,5 +39,3 @@ class OTARequestor : public OTARequestorInterface { private: OTARequestorDriver *driver; }; - - From 9d09e678c4b3afaeba0f56a42c95369aee2540d3 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 10 Nov 2021 14:53:45 +0000 Subject: [PATCH 04/12] Restyled by clang-format --- src/app/clusters/ota-requestor/ota-downloader.h | 4 ++-- src/app/clusters/ota-requestor/ota-image-processor.h | 8 ++++---- src/app/clusters/ota-requestor/ota-requestor-driver.h | 3 ++- src/app/clusters/ota-requestor/ota-requestor-interface.h | 3 ++- src/app/clusters/ota-requestor/ota-requestor.h | 7 ++++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/app/clusters/ota-requestor/ota-downloader.h b/src/app/clusters/ota-requestor/ota-downloader.h index a38134c7bfc962..5dbd19119e13a7 100644 --- a/src/app/clusters/ota-requestor/ota-downloader.h +++ b/src/app/clusters/ota-requestor/ota-downloader.h @@ -29,9 +29,9 @@ // A class that abstracts the image download functionality from the particular // protocol used for that (BDX or possibly HTTPS) -class OTADownloader : public BlockWriter { +class OTADownloader : public BlockWriter +{ public: - // API declarations start // Application calls this method to direct OTADownloader to begin the download diff --git a/src/app/clusters/ota-requestor/ota-image-processor.h b/src/app/clusters/ota-requestor/ota-image-processor.h index 12c0f31425eb0f..5b05dbe7a32403 100644 --- a/src/app/clusters/ota-requestor/ota-image-processor.h +++ b/src/app/clusters/ota-requestor/ota-image-processor.h @@ -23,12 +23,12 @@ #pragma once - // 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 { +class OTAImageProcessor +{ public: // Open file, find block of space in persistent memory, or allocate a buffer, etc. virtual CHIP_ERROR PrepareDownload() = 0; @@ -49,9 +49,9 @@ class OTAImageProcessor { // A class that abstracts the image download functionality from the particular // protocol used for that (BDX or possibly HTTPS) -class OTADownloader : public BlockWriter { +class OTADownloader : public BlockWriter +{ public: - // API declarations start // Application calls this method to direct OTADownloader to begin the download diff --git a/src/app/clusters/ota-requestor/ota-requestor-driver.h b/src/app/clusters/ota-requestor/ota-requestor-driver.h index 5b244a03fa499d..9b9426200efec9 100644 --- a/src/app/clusters/ota-requestor/ota-requestor-driver.h +++ b/src/app/clusters/ota-requestor/ota-requestor-driver.h @@ -26,7 +26,8 @@ // 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 { +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 diff --git a/src/app/clusters/ota-requestor/ota-requestor-interface.h b/src/app/clusters/ota-requestor/ota-requestor-interface.h index 80b6a3590172cd..b05c8ef3ed79e5 100644 --- a/src/app/clusters/ota-requestor/ota-requestor-interface.h +++ b/src/app/clusters/ota-requestor/ota-requestor-interface.h @@ -25,7 +25,8 @@ // 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 { +class OTARequestorInterface +{ public: // Handler for the AnnounceOTAProvider command virtual bool HandleAnnounceOTAProvider(commandData_t) = 0; diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h index bc1ce684360f11..61ff69c7fe476b 100644 --- a/src/app/clusters/ota-requestor/ota-requestor.h +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -20,13 +20,14 @@ * Applications implementing the OTA Requestor functionality must include this file. */ -#include #include +#include #pragma once // This class implements all of the core logic of the OTA Requestor -class OTARequestor : public OTARequestorInterface { +class OTARequestor : public OTARequestorInterface +{ public: // Application interface declarations start @@ -37,5 +38,5 @@ class OTARequestor : public OTARequestorInterface { // Application interface declarations end private: - OTARequestorDriver *driver; + OTARequestorDriver * driver; }; From d26a61f3ebb6e843933182ab9188db2360698e83 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Wed, 10 Nov 2021 14:58:57 -0500 Subject: [PATCH 05/12] Clean up comments and function names --- .../ota-requestor/ota-image-processor.h | 23 ------------------- .../ota-requestor/ota-requestor-driver.h | 2 +- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/src/app/clusters/ota-requestor/ota-image-processor.h b/src/app/clusters/ota-requestor/ota-image-processor.h index 5b05dbe7a32403..e61fa31ab06968 100644 --- a/src/app/clusters/ota-requestor/ota-image-processor.h +++ b/src/app/clusters/ota-requestor/ota-image-processor.h @@ -37,7 +37,6 @@ class OTAImageProcessor virtual CHIP_ERROR ProcessBlock(ByteSpan & data) = 0; // Close file, close persistent storage, etc - // (probably should not actually apply the image) virtual CHIP_ERROR Finalize() = 0; virtual chip::Optional PercentComplete() = 0; @@ -46,25 +45,3 @@ class OTAImageProcessor // releasing buffers, etc. virtual CHIP_ERROR Abort() = 0; }; - -// A class that abstracts the image download functionality from the particular -// protocol used for that (BDX or possibly HTTPS) -class OTADownloader : public BlockWriter -{ -public: - // API declarations start - - // Application calls this method to direct OTADownloader to begin the download - void BeginDownload(); - - // Platform calls this method upon the completion of PrepareDownload() processing - void OnDownloadPrepared(); - - // Platform calls this method upon the completion of ProcessBlock() processing - void OnBlockProcessed(action); - - // API declarations end - - // Invoked by an incoming block - void HandleBlock(); -}; diff --git a/src/app/clusters/ota-requestor/ota-requestor-driver.h b/src/app/clusters/ota-requestor/ota-requestor-driver.h index 9b9426200efec9..786c49c27c6715 100644 --- a/src/app/clusters/ota-requestor/ota-requestor-driver.h +++ b/src/app/clusters/ota-requestor/ota-requestor-driver.h @@ -32,7 +32,7 @@ class OTARequestorDriver // 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 AllowImageDownload() = 0; + virtual bool CheckImageDownloadAllowed() = 0; // Notify the application that the download is complete and the image can be applied virtual void ImageDownloadComplete() = 0; From 76a08937628c3c2920682f351acdc60ec36bb09d Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 11 Nov 2021 09:10:54 -0500 Subject: [PATCH 06/12] Misc API format changes based on PR comments --- .../clusters/ota-requestor/ota-downloader.h | 22 +++++++++++++------ .../ota-requestor/ota-requestor-interface.h | 8 +++++-- .../clusters/ota-requestor/ota-requestor.h | 5 ++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/app/clusters/ota-requestor/ota-downloader.h b/src/app/clusters/ota-requestor/ota-downloader.h index 5dbd19119e13a7..553d87d6ea5aff 100644 --- a/src/app/clusters/ota-requestor/ota-downloader.h +++ b/src/app/clusters/ota-requestor/ota-downloader.h @@ -29,22 +29,30 @@ // A class that abstracts the image download functionality from the particular // protocol used for that (BDX or possibly HTTPS) -class OTADownloader : public BlockWriter -{ +class OTADownloader { public: // API declarations start // Application calls this method to direct OTADownloader to begin the download - void BeginDownload(); + void virtual BeginDownload(); // Platform calls this method upon the completion of PrepareDownload() processing - void OnDownloadPrepared(); + void virtual OnPreparedForDownload(); + + // Action parameter type for the OnBlockProcessed() + enum blockActionType { + kGetNext, + kEnd + }; // Platform calls this method upon the completion of ProcessBlock() processing - void OnBlockProcessed(action); + void virtual OnBlockProcessed(blockActionType action); + + // A setter for the delegate class pointer + void setImageProcessorDelegate(OTAImageProcessor *delegate) // API declarations end - // Invoked by an incoming block - void HandleBlock(); +private: + OTAImageProcessor *imageProcessorDelegate; }; diff --git a/src/app/clusters/ota-requestor/ota-requestor-interface.h b/src/app/clusters/ota-requestor/ota-requestor-interface.h index b05c8ef3ed79e5..8b3983e6d58160 100644 --- a/src/app/clusters/ota-requestor/ota-requestor-interface.h +++ b/src/app/clusters/ota-requestor/ota-requestor-interface.h @@ -29,8 +29,12 @@ class OTARequestorInterface { public: // Handler for the AnnounceOTAProvider command - virtual bool HandleAnnounceOTAProvider(commandData_t) = 0; + virtual bool HandleAnnounceOTAProvider(ip::app::CommandHandler *commandObj, + const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData ch) = 0; // Handler for the QueryImageResponse command - virtual bool HandleQueryImageResponse(commandData_t) = 0; + virtual bool HandleQueryImageResponse(void * context, uint8_t status, uint32_t delayedActionTime, CharSpan imageURI, + uint32_t softwareVersion, CharSpan softwareVersionString, ByteSpan updateToken, + bool userConsentNeeded, ByteSpan metadataForRequester) = 0; }; diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h index 61ff69c7fe476b..6ad517e7b6b529 100644 --- a/src/app/clusters/ota-requestor/ota-requestor.h +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -35,8 +35,11 @@ class OTARequestor : public OTARequestorInterface // and download the new image if available void TriggerImmediateQuery(); + // A setter for the delegate class pointer + void setOtaRequestorDriver(OTARequestorDriver *driver); + // Application interface declarations end private: - OTARequestorDriver * driver; + OTARequestorDriver *otaRequestorDriver; }; From 04d32ce61e803b935c0bdd7c98e8d3087085b12f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 11 Nov 2021 14:11:57 +0000 Subject: [PATCH 07/12] Restyled by clang-format --- .../clusters/ota-requestor/ota-downloader.h | 19 ++++++++++--------- .../ota-requestor/ota-requestor-interface.h | 6 +++--- .../clusters/ota-requestor/ota-requestor.h | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/app/clusters/ota-requestor/ota-downloader.h b/src/app/clusters/ota-requestor/ota-downloader.h index 553d87d6ea5aff..dc934a46977572 100644 --- a/src/app/clusters/ota-requestor/ota-downloader.h +++ b/src/app/clusters/ota-requestor/ota-downloader.h @@ -29,7 +29,8 @@ // A class that abstracts the image download functionality from the particular // protocol used for that (BDX or possibly HTTPS) -class OTADownloader { +class OTADownloader +{ public: // API declarations start @@ -40,19 +41,19 @@ class OTADownloader { void virtual OnPreparedForDownload(); // Action parameter type for the OnBlockProcessed() - enum blockActionType { - kGetNext, - kEnd + enum blockActionType + { + kGetNext, + kEnd }; // Platform calls this method upon the completion of ProcessBlock() processing - void virtual OnBlockProcessed(blockActionType action); + void virtual OnBlockProcessed(blockActionType action); // A setter for the delegate class pointer - void setImageProcessorDelegate(OTAImageProcessor *delegate) + void setImageProcessorDelegate(OTAImageProcessor * delegate) - // API declarations end + // API declarations end -private: - OTAImageProcessor *imageProcessorDelegate; + private : OTAImageProcessor * imageProcessorDelegate; }; diff --git a/src/app/clusters/ota-requestor/ota-requestor-interface.h b/src/app/clusters/ota-requestor/ota-requestor-interface.h index 8b3983e6d58160..cc710df01c1fb6 100644 --- a/src/app/clusters/ota-requestor/ota-requestor-interface.h +++ b/src/app/clusters/ota-requestor/ota-requestor-interface.h @@ -29,9 +29,9 @@ class OTARequestorInterface { public: // Handler for the AnnounceOTAProvider command - virtual bool HandleAnnounceOTAProvider(ip::app::CommandHandler *commandObj, - const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData ch) = 0; + virtual bool HandleAnnounceOTAProvider( + ip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData ch) = 0; // Handler for the QueryImageResponse command virtual bool HandleQueryImageResponse(void * context, uint8_t status, uint32_t delayedActionTime, CharSpan imageURI, diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h index 6ad517e7b6b529..0aee767a7928bd 100644 --- a/src/app/clusters/ota-requestor/ota-requestor.h +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -36,10 +36,10 @@ class OTARequestor : public OTARequestorInterface void TriggerImmediateQuery(); // A setter for the delegate class pointer - void setOtaRequestorDriver(OTARequestorDriver *driver); + void setOtaRequestorDriver(OTARequestorDriver * driver); // Application interface declarations end private: - OTARequestorDriver *otaRequestorDriver; + OTARequestorDriver * otaRequestorDriver; }; From 730dd745bb869993070e86e4c7a5ab8c82e7785a Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 11 Nov 2021 16:54:45 -0500 Subject: [PATCH 08/12] Rename some classes and methods --- src/app/clusters/ota-requestor/ota-downloader.h | 4 ++-- src/app/clusters/ota-requestor/ota-image-processor.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/clusters/ota-requestor/ota-downloader.h b/src/app/clusters/ota-requestor/ota-downloader.h index dc934a46977572..e0300b7e64f25e 100644 --- a/src/app/clusters/ota-requestor/ota-downloader.h +++ b/src/app/clusters/ota-requestor/ota-downloader.h @@ -51,9 +51,9 @@ class OTADownloader void virtual OnBlockProcessed(blockActionType action); // A setter for the delegate class pointer - void setImageProcessorDelegate(OTAImageProcessor * delegate) + void SetImageProcessorDelegate(OTAImageProcessorDriver * delegate) // API declarations end - private : OTAImageProcessor * imageProcessorDelegate; + private : OTAImageProcessorDriver * imageProcessorDelegate; }; diff --git a/src/app/clusters/ota-requestor/ota-image-processor.h b/src/app/clusters/ota-requestor/ota-image-processor.h index e61fa31ab06968..b9a7ee9856c261 100644 --- a/src/app/clusters/ota-requestor/ota-image-processor.h +++ b/src/app/clusters/ota-requestor/ota-image-processor.h @@ -27,7 +27,7 @@ // 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 +class OTAImageProcessorDriver { public: // Open file, find block of space in persistent memory, or allocate a buffer, etc. From dd0fed13cf577bb0854c9957e2bde5678fee6102 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 11 Nov 2021 16:56:17 -0500 Subject: [PATCH 09/12] Rename a method --- src/app/clusters/ota-requestor/ota-requestor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h index 0aee767a7928bd..2c414061155c6a 100644 --- a/src/app/clusters/ota-requestor/ota-requestor.h +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -36,7 +36,7 @@ class OTARequestor : public OTARequestorInterface void TriggerImmediateQuery(); // A setter for the delegate class pointer - void setOtaRequestorDriver(OTARequestorDriver * driver); + void SetOtaRequestorDriver(OTARequestorDriver * driver); // Application interface declarations end From 952e748f20d391c94c823de1dc341be6199643eb Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 11 Nov 2021 20:27:56 -0500 Subject: [PATCH 10/12] Renaming avd vairious formatting changes --- src/app/clusters/ota-requestor/ota-downloader.h | 13 +++++++------ .../ota-requestor/ota-requestor-interface.h | 5 ++++- src/app/clusters/ota-requestor/ota-requestor.h | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/app/clusters/ota-requestor/ota-downloader.h b/src/app/clusters/ota-requestor/ota-downloader.h index e0300b7e64f25e..06e841e027f976 100644 --- a/src/app/clusters/ota-requestor/ota-downloader.h +++ b/src/app/clusters/ota-requestor/ota-downloader.h @@ -23,7 +23,7 @@ * must include this file */ -#include +#include "ota-image-processor.h" #pragma once @@ -41,19 +41,20 @@ class OTADownloader void virtual OnPreparedForDownload(); // Action parameter type for the OnBlockProcessed() - enum blockActionType + enum BlockActionType { kGetNext, kEnd }; // Platform calls this method upon the completion of ProcessBlock() processing - void virtual OnBlockProcessed(blockActionType action); + void virtual OnBlockProcessed(BlockActionType action); // A setter for the delegate class pointer - void SetImageProcessorDelegate(OTAImageProcessorDriver * delegate) + void SetImageProcessorDelegate(OTAImageProcessorDriver * delegate); - // API declarations end + // API declarations end - private : OTAImageProcessorDriver * imageProcessorDelegate; +private : + OTAImageProcessorDriver * mImageProcessorDelegate; }; diff --git a/src/app/clusters/ota-requestor/ota-requestor-interface.h b/src/app/clusters/ota-requestor/ota-requestor-interface.h index cc710df01c1fb6..a6c5c592d67d63 100644 --- a/src/app/clusters/ota-requestor/ota-requestor-interface.h +++ b/src/app/clusters/ota-requestor/ota-requestor-interface.h @@ -30,11 +30,14 @@ class OTARequestorInterface public: // Handler for the AnnounceOTAProvider command virtual bool HandleAnnounceOTAProvider( - ip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::OtaSoftwareUpdateRequestor::Commands::AnnounceOtaProvider::DecodableType & commandData ch) = 0; // Handler for the QueryImageResponse command virtual bool HandleQueryImageResponse(void * context, uint8_t status, uint32_t delayedActionTime, CharSpan imageURI, uint32_t softwareVersion, CharSpan softwareVersionString, ByteSpan updateToken, bool userConsentNeeded, ByteSpan metadataForRequester) = 0; + + // Handler for the ApplyUpdateResponse command + virtual bool HandleApplyUpdateResponse(ApplyUpdateResponse::DecodableType); }; diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h index 2c414061155c6a..9493cec0204c39 100644 --- a/src/app/clusters/ota-requestor/ota-requestor.h +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -20,8 +20,8 @@ * Applications implementing the OTA Requestor functionality must include this file. */ -#include -#include +#include "ota-requestor-driver.h" +#include "ota-requestor-interface.h" #pragma once @@ -41,5 +41,5 @@ class OTARequestor : public OTARequestorInterface // Application interface declarations end private: - OTARequestorDriver * otaRequestorDriver; + OTARequestorDriver * mOtaRequestorDriver; }; From 7ad32e2765f8578e7a431057adb0232c5421a815 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 12 Nov 2021 01:28:33 +0000 Subject: [PATCH 11/12] Restyled by clang-format --- src/app/clusters/ota-requestor/ota-downloader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/ota-requestor/ota-downloader.h b/src/app/clusters/ota-requestor/ota-downloader.h index 06e841e027f976..1039a5994c14c3 100644 --- a/src/app/clusters/ota-requestor/ota-downloader.h +++ b/src/app/clusters/ota-requestor/ota-downloader.h @@ -55,6 +55,6 @@ class OTADownloader // API declarations end -private : +private: OTAImageProcessorDriver * mImageProcessorDelegate; }; From d8ea864f03f498d0a7437f002a6922a44bef404d Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Fri, 12 Nov 2021 07:22:10 -0500 Subject: [PATCH 12/12] Add an API declaration --- src/app/clusters/ota-requestor/ota-requestor.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/clusters/ota-requestor/ota-requestor.h b/src/app/clusters/ota-requestor/ota-requestor.h index 9493cec0204c39..4cfacba97b64f1 100644 --- a/src/app/clusters/ota-requestor/ota-requestor.h +++ b/src/app/clusters/ota-requestor/ota-requestor.h @@ -35,6 +35,10 @@ class OTARequestor : public OTARequestorInterface // and download the new image if available void TriggerImmediateQuery(); + // Application directs the Requestor to abort any processing related to + // the image update + void AbortImageUpdate(); + // A setter for the delegate class pointer void SetOtaRequestorDriver(OTARequestorDriver * driver);