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 <map> 20 #include <string> 21 22 #include "cj_request_ffi.h" 23 #include "constant.h" 24 #include "napi_base_context.h" 25 #include "request_common.h" 26 27 namespace OHOS::CJSystemapi::Request { 28 29 using OHOS::Request::Action; 30 using OHOS::Request::Config; 31 using OHOS::Request::ExceptionError; 32 using OHOS::Request::ExceptionErrorCode; 33 using OHOS::Request::FileSpec; 34 using OHOS::Request::Filter; 35 using OHOS::Request::FormItem; 36 using OHOS::Request::Mode; 37 using OHOS::Request::State; 38 using OHOS::Request::TaskInfo; 39 40 class CJRequestImpl { 41 public: 42 CJRequestImpl() = default; 43 ~CJRequestImpl() = default; 44 45 static RetReqData CreateTask(OHOS::AbilityRuntime::Context *context, CConfig *ffiConfig); 46 static RetTask GetTask(OHOS::AbilityRuntime::Context *context, std::string taskId, 47 RequestNativeOptionCString &cToken); 48 static void FreeTask(std::string taskId); 49 static RetError RemoveTask(std::string taskId); 50 static RetTaskInfo ShowTask(std::string taskId); 51 static RetTaskInfo TouchTask(std::string taskId, const char *token); 52 static RetTaskArr SearchTask(CFilter &filter); 53 static ExceptionError Convert2Filter(CFilter &filter, Filter &out); 54 static RetError ProgressOn(char *event, std::string taskId, void *callback); 55 static RetError ProgressOff(char *event, std::string taskId, void *callback); 56 static RetError TaskStart(std::string taskId); 57 static RetError TaskPause(std::string taskId); 58 static RetError TaskResume(std::string taskId); 59 static RetError TaskStop(std::string taskId); 60 61 static RetError Convert2RetErr(ExceptionErrorCode code); 62 static RetError Convert2RetErr(ExceptionError &err); 63 static std::map<std::string, std::string> ConvertCArr2Map(const CHashStrArr *cheaders); 64 static void Convert2Config(CConfig *config, Config &out); 65 static CTaskInfo Convert2CTaskInfo(TaskInfo &task); 66 static RequestCArrString Convert2CStringArray(std::vector<std::string> &tids); 67 68 static Filter Convert2Filter(CFilter &filter); 69 static void Convert2CConfig(Config &config, CConfig &out); 70 static CConfigDataTypeUion Convert2RequestData(Action action, std::string &data, const std::vector<FileSpec> &files, 71 const std::vector<FormItem> &forms); 72 static std::string ParseBundle(RequestNativeOptionCString &bundle); 73 static int64_t ParseBefore(RequestNativeOptionInt64 &before); 74 static int64_t ParseAfter(RequestNativeOptionInt64 &after, int64_t before); 75 static State ParseState(RequestNativeOptionUInt32 &state); 76 static Action ParseAction(RequestNativeOptionUInt32 &action); 77 static Mode ParseMode(RequestNativeOptionUInt32 &mode); 78 79 static ExceptionError ParseToken(RequestNativeOptionCString &cToken, std::string &out); 80 81 private: 82 static RetError TaskExec(std::string execType, std::string taskId); 83 }; 84 85 } // namespace OHOS::CJSystemapi::Request 86 87 #endif // OHOS_REQUEST_CJ_REQUEST_IMPL_H