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 #include "ohos_adapter/bridge/ark_print_manager_adapter_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_print_document_adapter_adapter_impl.h"
19
20 #include "base/bridge/ark_web_bridge_macros.h"
21
22 namespace OHOS::ArkWeb {
23
ArkPrintManagerAdapterWrapper(ArkWebRefPtr<ArkPrintManagerAdapter> ref)24 ArkPrintManagerAdapterWrapper::ArkPrintManagerAdapterWrapper(ArkWebRefPtr<ArkPrintManagerAdapter> ref) : ctocpp_(ref) {}
25
StartPrint(const std::vector<std::string> & fileList,const std::vector<uint32_t> & fdList,std::string & taskId)26 int32_t ArkPrintManagerAdapterWrapper::StartPrint(
27 const std::vector<std::string>& fileList, const std::vector<uint32_t>& fdList, std::string& taskId)
28 {
29 if (!ctocpp_) {
30 return -1;
31 }
32 ArkWebStringVector arkFileList = ArkWebStringVectorClassToStruct(fileList);
33 ArkWebUint32Vector arkFdList = ArkWebBasicVectorClassToStruct<uint32_t, ArkWebUint32Vector>(fdList);
34 ArkWebString arkTaskId;
35 int32_t result = ctocpp_->StartPrint(arkFileList, arkFdList, arkTaskId);
36 taskId = ArkWebStringStructToClass(arkTaskId);
37 ArkWebStringStructRelease(arkTaskId);
38 ArkWebStringVectorStructRelease(arkFileList);
39 ArkWebBasicVectorStructRelease(arkFdList);
40 return result;
41 }
42
Print(const std::string & printJobName,const std::shared_ptr<NWeb::PrintDocumentAdapterAdapter> listener,const NWeb::PrintAttributesAdapter & printAttributes)43 int32_t ArkPrintManagerAdapterWrapper::Print(const std::string& printJobName,
44 const std::shared_ptr<NWeb::PrintDocumentAdapterAdapter> listener,
45 const NWeb::PrintAttributesAdapter& printAttributes)
46 {
47 if (!ctocpp_) {
48 return -1;
49 }
50
51 ArkWebString str = ArkWebStringClassToStruct(printJobName);
52 int32_t result;
53 if (CHECK_SHARED_PTR_IS_NULL(listener)) {
54 result = ctocpp_->Print(str, nullptr, printAttributes);
55 } else {
56 result = ctocpp_->Print(str, new ArkPrintDocumentAdapterAdapterImpl(listener), printAttributes);
57 }
58
59 ArkWebStringStructRelease(str);
60 return result;
61 }
62
Print(const std::string & printJobName,const std::shared_ptr<NWeb::PrintDocumentAdapterAdapter> listener,const NWeb::PrintAttributesAdapter & printAttributes,void * contextToken)63 int32_t ArkPrintManagerAdapterWrapper::Print(const std::string& printJobName,
64 const std::shared_ptr<NWeb::PrintDocumentAdapterAdapter> listener,
65 const NWeb::PrintAttributesAdapter& printAttributes, void* contextToken)
66 {
67 if (!ctocpp_) {
68 return -1;
69 }
70
71 ArkWebString str = ArkWebStringClassToStruct(printJobName);
72 int32_t result;
73
74 if (CHECK_SHARED_PTR_IS_NULL(listener)) {
75 result = ctocpp_->Print(str, nullptr, printAttributes, contextToken);
76 } else {
77 result = ctocpp_->Print(str, new ArkPrintDocumentAdapterAdapterImpl(listener), printAttributes, contextToken);
78 }
79
80 ArkWebStringStructRelease(str);
81 return result;
82 }
83
84 } // namespace OHOS::ArkWeb
85