• 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(const std::string &printJobName_, const sptr<IPrintCallback> &printAdapterCallback_,
35         const std::shared_ptr<PrintAttributes> &printAttributes_, const sptr<IRemoteObject> &callerToken_);
36     ~PrintTask();
37 
38     uint32_t Start();
39     uint32_t StartPrintAdapter();
40     void Stop();
41     const std::string &GetId() const;
42     static napi_value On(napi_env env, napi_callback_info info);
43     static napi_value Off(napi_env env, napi_callback_info info);
44 
45     bool IsSupportType(const std::string &type) const;
46 
47 private:
48     struct TaskEventContext : public PrintAsyncCall::Context {
49         std::string type = "";
50         std::string taskId = "";
51         sptr<IPrintCallback> callback = nullptr;
52         bool result = false;
53         napi_status status = napi_generic_failure;
TaskEventContextTaskEventContext54         TaskEventContext() : Context(nullptr, nullptr) {};
TaskEventContextTaskEventContext55         TaskEventContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) {};
~TaskEventContextTaskEventContext56         virtual ~TaskEventContext() {};
57     };
58 
59     std::string taskId_;
60     std::vector<std::string> fileList_;
61     std::vector<uint32_t> fdList_;
62     std::map<std::string, bool> supportEvents_;
63     uint32_t pathType_ = 0;
64     sptr<IRemoteObject> callerToken_ = nullptr;
65     std::string printJobName_;
66     sptr<IPrintCallback> printAdapterCallback_ = nullptr;
67     std::shared_ptr<PrintAttributes> printAttributes_ = nullptr;
68     enum FilePathType {
69         FD_UNDEFINED,
70         FD_PATH,
71         FILE_PATH,
72         FILE_PATH_ABSOLUTED
73     };
74 };
75 }  // namespace OHOS::Print
76 #endif  // PRINT_TASK_H
77