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 RAWFILE_REQUEST_H 17 #define RAWFILE_REQUEST_H 18 19 #include <mutex> 20 #include <string> 21 22 #include <rawfile/raw_file_manager.h> 23 #include "web/arkweb_scheme_handler.h" 24 #include "web/arkweb_net_error_list.h" 25 26 class RawfileRequest { 27 public: 28 RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, 29 const ArkWeb_ResourceHandler *resourceHandler, 30 const NativeResourceManager* resourceManager); 31 ~RawfileRequest(); 32 33 void Start(); 34 void Stop(); 35 void ReadRawfileDataOnWorkerThread(); 36 resourceHandler()37 const ArkWeb_ResourceHandler *resourceHandler() { return resourceHandler_; } resourceRequest()38 const ArkWeb_ResourceRequest *resourceRequest() { return resourceRequest_; } resourceManager()39 const NativeResourceManager *resourceManager() { return resourceManager_; } response()40 ArkWeb_Response *response() { return response_; } stream()41 ArkWeb_HttpBodyStream *stream() { return stream_; } RawfilePath()42 const std::string RawfilePath() { return rawfilePath_; } 43 44 void DidReceiveResponse(); 45 void DidReceiveData(const uint8_t *buffer, int64_t bufLen); 46 void DidFinish(); 47 void DidFailWithError(ArkWeb_NetError errorCode); 48 49 private: 50 const ArkWeb_ResourceRequest *resourceRequest_{nullptr}; 51 const ArkWeb_ResourceHandler *resourceHandler_{nullptr}; 52 const NativeResourceManager *resourceManager_{nullptr}; 53 ArkWeb_Response *response_; 54 bool stopped_{false}; 55 std::string rawfilePath_; 56 ArkWeb_HttpBodyStream *stream_{nullptr}; 57 std::mutex mutex_; 58 }; 59 60 #endif // RAWFILE_REQUEST_H