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 16 #ifndef OHOS_REQUEST_CJ_REQUEST_IMPL_H 17 #define OHOS_REQUEST_CJ_REQUEST_IMPL_H 18 19 #include <string> 20 #include <map> 21 #include "napi_base_context.h" 22 #include "cj_request_ffi.h" 23 #include "constant.h" 24 #include "js_common.h" 25 26 namespace OHOS::CJSystemapi::Request { 27 28 using OHOS::Request::ExceptionError; 29 using OHOS::Request::ExceptionErrorCode; 30 using OHOS::Request::Config; 31 32 class CJRequestImpl { 33 public: 34 CJRequestImpl() = default; 35 ~CJRequestImpl() = default; 36 37 static RetReqData CreateTask(OHOS::AbilityRuntime::Context* context, CConfig *ffiConfig); 38 static RetError RemoveTask(std::string taskId); 39 static void FreeTask(std::string taskId); 40 static RetError ProgressOn(char *event, std::string taskId, void (*callback)(CProgress progress)); 41 static RetError ProgressOff(char *event, std::string taskId, void *callback); 42 static RetError TaskStart(std::string taskId); 43 static RetError TaskPause(std::string taskId); 44 static RetError TaskResume(std::string taskId); 45 static RetError TaskStop(std::string taskId); 46 47 static RetError Convert2RetErr(ExceptionErrorCode code); 48 static RetError Convert2RetErr(ExceptionError &err); 49 static std::map<std::string, std::string> ConvertCArr2Map(const CHashStrArr *cheaders); 50 static void Convert2Config(CConfig *config, Config &out); 51 private: 52 static RetError TaskExec(std::string execType, std::string taskId); 53 }; 54 55 } // namespace OHOS::CJSystemapi::Request 56 57 #endif // OHOS_REQUEST_CJ_REQUEST_IMPL_H