1 /*
2  * Copyright (c) 2023 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_MANAGER_ADAPTER_IMPL_H
17 #define PRINT_MANAGER_ADAPTER_IMPL_H
18 
19 #include "print_manager_adapter.h"
20 
21 #if defined(NWEB_PRINT_ENABLE)
22 #include "iprint_callback.h"
23 #include "print_callback.h"
24 #include "print_manager_client.h"
25 #endif
26 
27 namespace OHOS::NWeb {
28 
29 #if defined(NWEB_PRINT_ENABLE)
30 class PrintDocumentAdapterImpl : public OHOS::Print::PrintDocumentAdapter {
31 public:
32     PrintDocumentAdapterImpl(const std::shared_ptr<PrintDocumentAdapterAdapter> cb);
33 
34     void onStartLayoutWrite(const std::string& jobId, const OHOS::Print::PrintAttributes& oldAttrs,
35         const OHOS::Print::PrintAttributes& newAttrs, uint32_t fd,
36         std::function<void(std::string, uint32_t)> writeResultCallback) override;
37 
38     void onJobStateChanged(const std::string& jobId, uint32_t state) override;
39 
40 private:
41     PrintAttributesAdapter ConvertPrintingParameters(Print::PrintAttributes attrs);
42 
43     std::shared_ptr<PrintDocumentAdapterAdapter> cb_;
44 };
45 #endif
46 
47 class PrintWriteResultCallbackAdapterImpl : public PrintWriteResultCallbackAdapter {
48 public:
49     PrintWriteResultCallbackAdapterImpl(std::function<void(std::string, uint32_t)>& cb);
50 
51     void WriteResultCallback(std::string jobId, uint32_t code) override;
52 
53 private:
54     std::function<void(std::string, uint32_t)> cb_;
55 };
56 
57 class PrintManagerAdapterImpl : public PrintManagerAdapter {
58 public:
59     static PrintManagerAdapterImpl& GetInstance();
60 
61     ~PrintManagerAdapterImpl() override = default;
62 
63     int32_t StartPrint(
64         const std::vector<std::string>& fileList, const std::vector<uint32_t>& fdList, std::string& taskId) override;
65 
66     int32_t Print(const std::string& printJobName, const std::shared_ptr<PrintDocumentAdapterAdapter> listener,
67         const PrintAttributesAdapter& printAttributes) override;
68 
69     int32_t Print(const std::string& printJobName, const std::shared_ptr<PrintDocumentAdapterAdapter> listener,
70         const PrintAttributesAdapter& printAttributes, void* contextToken) override;
71 
72 private:
73     PrintManagerAdapterImpl() = default;
74 
75     PrintManagerAdapterImpl(const PrintManagerAdapterImpl& other) = delete;
76 
77     PrintManagerAdapterImpl& operator=(const PrintManagerAdapterImpl&) = delete;
78 };
79 
80 } // namespace OHOS::NWeb
81 
82 #endif // PRINT_MANAGER_ADAPTER_IMPL_H
83