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