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