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_MANAGER_CLIENT_H 17 #define PRINT_MANAGER_CLIENT_H 18 19 #include <condition_variable> 20 #include <map> 21 #include <mutex> 22 23 #include "iprint_callback.h" 24 #include "iprint_service.h" 25 #include "iremote_object.h" 26 #include "print_extension_callback_stub.h" 27 #include "print_extension_info.h" 28 #include "print_job.h" 29 #include "print_sa_death_recipient.h" 30 #include "printer_info.h" 31 #include "refbase.h" 32 33 namespace OHOS::Print { 34 class PrintManagerClient : public RefBase { 35 public: 36 PrintManagerClient(); 37 ~PrintManagerClient(); 38 static sptr<PrintManagerClient> GetInstance(); 39 40 void OnRemoteSaDied(const wptr<IRemoteObject> &object); 41 42 int32_t StartPrint(const std::vector<std::string> &fileList, 43 const std::vector<uint32_t> &fdList, std::string &taskId); 44 int32_t StopPrint(const std::string &taskId); 45 int32_t StartPrint(const std::vector<std::string> &fileList, const std::vector<uint32_t> &fdList, 46 std::string &taskId, const sptr<IRemoteObject> &token); 47 int32_t QueryAllExtension(std::vector<PrintExtensionInfo> &extensionInfos); 48 int32_t StartDiscoverPrinter(const std::vector<std::string> &extensionList); 49 int32_t StopDiscoverPrinter(); 50 int32_t AddPrinters(const std::vector<PrinterInfo> &printerInfos); 51 int32_t RemovePrinters(const std::vector<std::string> &printerIds); 52 int32_t UpdatePrinters(const std::vector<PrinterInfo> &printerInfos); 53 int32_t ConnectPrinter(const std::string &printerId); 54 int32_t DisconnectPrinter(const std::string &printerId); 55 int32_t StartPrintJob(const PrintJob &jobinfo); 56 int32_t CancelPrintJob(const std::string &jobId); 57 int32_t UpdatePrinterState(const std::string &printerId, uint32_t state); 58 int32_t UpdatePrintJobState(const std::string &jobId, uint32_t state, uint32_t subState); 59 int32_t UpdateExtensionInfo(const std::string &extensionId); 60 int32_t RequestPreview(const PrintJob &jobinfo, std::string &previewResult); 61 int32_t QueryPrinterCapability(const std::string &printerId); 62 int32_t QueryAllPrintJob(std::vector<PrintJob> &printJobs); 63 int32_t QueryPrintJobById(std::string &printJobId, PrintJob &printjob); 64 int32_t AddPrinterToCups(const std::string &printerUri, const std::string &printerName); 65 int32_t QueryPrinterCapabilityByUri(const std::string &printerUri, PrinterCapability &printerCaps); 66 67 int32_t On(const std::string &taskId, const std::string &type, const sptr<IPrintCallback> &listener); 68 int32_t Off(const std::string &taskId, const std::string &type); 69 70 int32_t RegisterExtCallback(const std::string &extensionId, uint32_t callbackId, PrintExtCallback cb); 71 int32_t RegisterExtCallback(const std::string &extensionId, uint32_t callbackId, PrintJobCallback cb); 72 int32_t RegisterExtCallback(const std::string &extensionId, uint32_t callbackId, PrinterCallback cb); 73 int32_t RegisterExtCallback(const std::string &extensionId, uint32_t callbackId, PrinterCapabilityCallback cb); 74 int32_t UnregisterAllExtCallback(const std::string &extensionId); 75 int32_t LoadExtSuccess(const std::string &extensionId); 76 77 void LoadServerSuccess(); 78 void LoadServerFail(); 79 void SetProxy(const sptr<IRemoteObject> &obj); 80 void ResetProxy(); 81 82 private: 83 bool LoadServer(); 84 bool GetPrintServiceProxy(); 85 86 private: 87 static std::mutex instanceLock_; 88 static sptr<PrintManagerClient> instance_; 89 std::mutex proxyLock_; 90 sptr<IPrintService> printServiceProxy_; 91 sptr<PrintSaDeathRecipient> deathRecipient_; 92 93 std::map<std::string, sptr<PrintExtensionCallbackStub>> extCallbackMap_; 94 95 std::mutex loadMutex_; 96 std::mutex conditionMutex_; 97 std::condition_variable syncCon_; 98 bool ready_ = false; 99 static constexpr int LOAD_SA_TIMEOUT_MS = 15000; 100 }; 101 } // namespace OHOS::Print 102 #endif // PRINT_MANAGER_CLIENT_H 103