1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SYS_INSTALLER_STREAM_UPDATE_H 17 #define SYS_INSTALLER_STREAM_UPDATE_H 18 19 #include "stream_status_manager.h" 20 #include "updater/updater.h" 21 #include "bin_chunk_update.h" 22 #include "ring_buffer.h" 23 #include <atomic> 24 25 namespace OHOS { 26 namespace SysInstaller { 27 28 class StreamInstallProcesser { 29 DISALLOW_COPY_MOVE(StreamInstallProcesser); 30 public: 31 static StreamInstallProcesser &GetInstance(); SetStatusManager(std::shared_ptr<StreamStatusManager> statusManager)32 void SetStatusManager(std::shared_ptr<StreamStatusManager> statusManager) 33 { 34 statusManager_ = statusManager; 35 } 36 37 bool IsRunning(); 38 int32_t Start(); 39 void Stop(); 40 int32_t ProcessStreamData(const uint8_t *buffer, uint32_t size); 41 void UpdateResult(UpdateStatus updateStatus, int dealLen, const std::string &resultMsg); 42 43 private: 44 StreamInstallProcesser() = default; 45 ~StreamInstallProcesser() = default; 46 void ThreadExecuteFunc(); 47 void ThreadExitProc(); 48 49 private: 50 Updater::RingBuffer ringBuffer_; 51 52 std::shared_ptr<StreamStatusManager> statusManager_ {}; 53 std::shared_ptr<Updater::BinChunkUpdate> binChunkUpdate_ {}; 54 std::atomic<bool> isExitThread_ = false; 55 std::thread *pComsumeThread_ { nullptr }; 56 bool isRunning_ = false; 57 }; 58 } // SysInstaller 59 } // namespace OHOS 60 #endif // SYS_INSTALLER_STREAM_UPDATE_H 61