• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 PRINT_TASK_H
17 #define PRINT_TASK_H
18 
19 #include <map>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "iremote_object.h"
25 #include "iprint_callback.h"
26 #include "napi/native_api.h"
27 #include "napi/native_common.h"
28 #include "print_async_call.h"
29 
30 namespace OHOS::Print {
31 class PrintTask {
32 public:
33     explicit PrintTask(const std::vector<std::string> &fileList, const sptr<IRemoteObject> &callerToken_);
34     ~PrintTask();
35 
36     uint32_t Start();
37     void Stop();
38     const std::string &GetId() const;
39     static napi_value On(napi_env env, napi_callback_info info);
40     static napi_value Off(napi_env env, napi_callback_info info);
41 
42     bool IsSupportType(const std::string &type) const;
43 
44 private:
45     struct TaskEventContext : public PrintAsyncCall::Context {
46         std::string type = "";
47         std::string taskId = "";
48         sptr<IPrintCallback> callback = nullptr;
49         bool result = false;
50         napi_status status = napi_generic_failure;
TaskEventContextTaskEventContext51         TaskEventContext() : Context(nullptr, nullptr) {};
TaskEventContextTaskEventContext52         TaskEventContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) {};
~TaskEventContextTaskEventContext53         virtual ~TaskEventContext() {};
54     };
55 
56     std::string taskId_;
57     std::vector<std::string> fileList_;
58     std::vector<uint32_t> fdList_;
59     std::map<std::string, bool> supportEvents_;
60     uint32_t pathType_ = 0;
61     sptr<IRemoteObject> callerToken_;
62     enum FilePathType {
63         FD_UNDEFINED,
64         FD_PATH,
65         FILE_PATH,
66         FILE_PATH_ABSOLUTED
67     };
68 };
69 }  // namespace OHOS::Print
70 #endif  // PRINT_TASK_H
71