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_impl.h"
17 
18 #include "ohos_adapter/bridge/ark_print_document_adapter_adapter_wrapper.h"
19 
20 #include "base/bridge/ark_web_bridge_macros.h"
21 
22 namespace OHOS::ArkWeb {
23 
ArkPrintManagerAdapterImpl(NWeb::PrintManagerAdapter & ref)24 ArkPrintManagerAdapterImpl::ArkPrintManagerAdapterImpl(NWeb::PrintManagerAdapter& ref) : real_(ref) {}
25 
StartPrint(const ArkWebStringVector & arkFileList,const ArkWebUint32Vector & arkFdList,ArkWebString & arkTaskId)26 int32_t ArkPrintManagerAdapterImpl::StartPrint(
27     const ArkWebStringVector& arkFileList, const ArkWebUint32Vector& arkFdList, ArkWebString& arkTaskId)
28 {
29     std::vector<std::string> fileList = ArkWebStringVectorStructToClass(arkFileList);
30     std::vector<uint32_t> fdList = ArkWebBasicVectorStructToClass<uint32_t, ArkWebUint32Vector>(arkFdList);
31     std::string taskId;
32     int32_t result = real_.StartPrint(fileList, fdList, taskId);
33     arkTaskId = ArkWebStringClassToStruct(taskId);
34     return result;
35 }
36 
Print(const ArkWebString & printJobName,const ArkWebRefPtr<ArkPrintDocumentAdapterAdapter> listener,const ArkPrintAttributesAdapter & printAttributes)37 int32_t ArkPrintManagerAdapterImpl::Print(const ArkWebString& printJobName,
38     const ArkWebRefPtr<ArkPrintDocumentAdapterAdapter> listener, const ArkPrintAttributesAdapter& printAttributes)
39 {
40     std::string str = ArkWebStringStructToClass(printJobName);
41 
42     if (CHECK_REF_PTR_IS_NULL(listener)) {
43         return real_.Print(str, nullptr, printAttributes);
44     }
45 
46     return real_.Print(str, std::make_shared<ArkPrintDocumentAdapterAdapterWrapper>(listener), printAttributes);
47 }
48 
Print(const ArkWebString & printJobName,const ArkWebRefPtr<ArkPrintDocumentAdapterAdapter> listener,const ArkPrintAttributesAdapter & printAttributes,void * contextToken)49 int32_t ArkPrintManagerAdapterImpl::Print(const ArkWebString& printJobName,
50     const ArkWebRefPtr<ArkPrintDocumentAdapterAdapter> listener, const ArkPrintAttributesAdapter& printAttributes,
51     void* contextToken)
52 {
53     std::string str = ArkWebStringStructToClass(printJobName);
54 
55     if (CHECK_REF_PTR_IS_NULL(listener)) {
56         return real_.Print(str, nullptr, printAttributes, contextToken);
57     }
58 
59     return real_.Print(
60         str, std::make_shared<ArkPrintDocumentAdapterAdapterWrapper>(listener), printAttributes, contextToken);
61 }
62 
63 } // namespace OHOS::ArkWeb
64