1 /** 2 * Copyright (c) 2024 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 #ifndef TESTRAWFILE_RAWFILE_REQUEST_H 16 #define TESTRAWFILE_RAWFILE_REQUEST_H 17 18 #include <bits/alltypes.h> 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, const ArkWeb_ResourceHandler *resourceHandler, 29 const NativeResourceManager *resourceManager); 30 ~RawfileRequest(); 31 32 void Start(); 33 void Stop(); 34 void ReadRawfileDataOnWorkerThread(); 35 resourceHandler()36 const ArkWeb_ResourceHandler *resourceHandler() { return resourceHandler_; } resourceRequest()37 const ArkWeb_ResourceRequest *resourceRequest() { return resourceRequest_; } resourceManager()38 const NativeResourceManager *resourceManager() { return resourceManager_; } response()39 ArkWeb_Response *response() { return response_; } stream()40 ArkWeb_HttpBodyStream *stream() { return stream_; } rawfilePath()41 const std::string rawfilePath() { return rawfilePath_; } 42 43 void DidReceiveResponse(); 44 void DidReceiveData(const uint8_t *buffer, int64_t bufLen); 45 void DidFinish(); 46 void DidFailWithError(ArkWeb_NetError errorCode); 47 48 int32_t releaseString(); 49 int32_t releaseByteArray(); 50 int32_t destroyHttpBodyStream(); 51 int32_t setHeaderByName(); 52 53 int32_t getRequestHeaderList(); reqUrl()54 const std::string reqUrl() { return reqUrl_; }; haveBodyStream()55 int32_t haveBodyStream() { return haveBodyStream_; }; isInit()56 int32_t isInit() { return isInit_; }; isRead()57 int32_t isRead() { return isRead_; }; haveResponse()58 int32_t haveResponse() { return haveResponse_; }; haveResourceHandler()59 int32_t haveResourceHandler() { return haveResourceHandler_; }; 60 61 private: 62 const ArkWeb_ResourceRequest *resourceRequest_{nullptr}; 63 const ArkWeb_ResourceHandler *resourceHandler_{nullptr}; 64 const NativeResourceManager *resourceManager_{nullptr}; 65 ArkWeb_Response *response_; 66 bool stopped_{false}; 67 std::string rawfilePath_; 68 ArkWeb_HttpBodyStream *stream_{nullptr}; 69 std::mutex mutex_; 70 71 std::string reqUrl_{"test"}; 72 int32_t haveBodyStream_{-1}; 73 int32_t isInit_{-1}; 74 int32_t isRead_{-1}; 75 int32_t haveResponse_{-1}; 76 int32_t haveResourceHandler_{-1}; 77 78 }; 79 80 #endif //TESTRAWFILE_RAWFILE_REQUEST_H 81 82