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_EXTENSION_CALLBACK_STUB_H 17 #define PRINT_EXTENSION_CALLBACK_STUB_H 18 19 #include <memory> 20 21 #include "iprint_extension_callback.h" 22 #include "iremote_stub.h" 23 #include "print_job.h" 24 #include "printer_capability.h" 25 26 namespace OHOS::Print { 27 using PrintExtCallback = bool (*)(); 28 using PrintJobCallback = bool (*)(const PrintJob&); 29 using PrinterCallback = bool (*)(const std::string&); 30 using PrinterCapabilityCallback = bool (*)(const std::string&, PrinterCapability&); 31 32 class PrintExtensionCallbackStub : public IRemoteStub<IPrintExtensionCallback> { 33 public: 34 explicit PrintExtensionCallbackStub(); 35 virtual ~PrintExtensionCallbackStub() = default; 36 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 37 bool OnCallback() override; 38 bool OnCallback(const std::string &printerId) override; 39 bool OnCallback(const PrintJob &job) override; 40 bool OnCallback(const std::string &printerId, PrinterCapability &cap) override; 41 42 void SetExtCallback(PrintExtCallback cb); 43 void SetPrintJobCallback(PrintJobCallback cb); 44 void SetPrinterCallback(PrinterCallback cb); 45 void SetCapabilityCallback(PrinterCapabilityCallback cb); 46 47 private: 48 bool HandleExtCallback(MessageParcel &data, MessageParcel &reply); 49 bool HandlePrinterCallback(MessageParcel &data, MessageParcel &reply); 50 bool HandlePrintJobCallback(MessageParcel &data, MessageParcel &reply); 51 bool HandleCapabilityCallback(MessageParcel &data, MessageParcel &reply); 52 void dataReadJob(MessageParcel &data, PrintJob &job); 53 54 private: 55 using PRINT_EXT_HANDLER = bool (PrintExtensionCallbackStub::*)(MessageParcel &, MessageParcel &); 56 PrintExtCallback extCb_; 57 PrintJobCallback jobCb_; 58 PrinterCallback cb_; 59 PrinterCapabilityCallback capability_; 60 std::map<uint32_t, PRINT_EXT_HANDLER> cmdMap_; 61 }; 62 } // namespace OHOS::Print 63 #endif // PRINT_EXTCB_STUB_H 64