1 /* 2 * Copyright (c) 2024 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 VENDOR_PPD_DRIVER_H 17 #define VENDOR_PPD_DRIVER_H 18 19 #include <vector> 20 #include <mutex> 21 #include "vendor_driver_base.h" 22 #include "vendor_manager.h" 23 24 namespace OHOS { 25 namespace Print { 26 27 class VendorPpdDriver : public VendorDriverBase { 28 public: 29 VendorPpdDriver(); 30 ~VendorPpdDriver(); 31 bool Init(IPrinterVendorManager *manager) override; 32 void UnInit() override; 33 std::string GetVendorName() override; 34 int32_t OnPrinterDiscovered(const std::string &vendorName, const PrinterInfo &printerInfo) override; 35 bool QueryProperty(const std::string &printerId, const std::string &key, std::string &value) override; 36 void OnStartDiscovery() override; 37 void OnStopDiscovery() override; 38 bool OnQueryCapability(const std::string &printerId, int timeout) override; 39 void UpdateAllPrinterStatus() override; 40 41 private: 42 std::string QueryPpdName(const std::string &makeAndModel); 43 void DiscoverBackendPrinters(); 44 void DiscoveryProcess(); 45 bool WaitNext(); 46 bool TryConnectByPpdDriver(const PrinterInfo &printerInfo); 47 48 private: 49 std::string connectingVendorGroup; 50 std::shared_ptr<PrinterInfo> connectingPrinterInfo; 51 std::mutex updateDiscoveryMutex_; 52 std::map<std::string, bool> discoveredPrinters_; 53 bool isDiscovering_ = false; 54 std::thread discoveryThread_; 55 std::mutex discoveryStateChangeMutex_; 56 std::mutex waitDiscoveryMutex_; 57 std::condition_variable waitDiscoveryCondition_; 58 }; 59 } // namespace Print 60 } // namespace OHOS 61 #endif // VENDOR_PPD_DRIVER_H