All checks were successful
Build ptprnt / build (push) Successful in 3m49s
88 lines
2.6 KiB
C++
88 lines
2.6 KiB
C++
/*
|
|
ptrnt - print labels on linux
|
|
Copyright (C) 2025 Moritz Martinius
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "interface/IPrinterDriver.hpp"
|
|
#include "libusbwrap/UsbDeviceFactory.hpp"
|
|
|
|
namespace ptprnt::core {
|
|
|
|
/**
|
|
* @brief Core service for printer operations
|
|
*
|
|
* Provides the core library functionality for:
|
|
* - Detecting printers
|
|
* - Selecting printers
|
|
* - Building and printing labels
|
|
*/
|
|
class PrinterService {
|
|
public:
|
|
PrinterService();
|
|
~PrinterService() = default;
|
|
|
|
PrinterService(const PrinterService&) = delete;
|
|
PrinterService& operator=(const PrinterService&) = delete;
|
|
PrinterService(PrinterService&&) = delete;
|
|
PrinterService& operator=(PrinterService&&) = delete;
|
|
|
|
/**
|
|
* @brief Initialize USB device factory
|
|
* @return true on success, false on failure
|
|
*/
|
|
bool initialize();
|
|
|
|
/**
|
|
* @brief Detect all compatible printers
|
|
* @return Vector of detected printers
|
|
*/
|
|
std::vector<std::shared_ptr<IPrinterDriver>> detectPrinters();
|
|
|
|
/**
|
|
* @brief Select a printer by name or auto-detect
|
|
* @param printerName Printer driver name, or "auto" for first detected
|
|
* @return Printer driver, or nullptr if not found
|
|
*/
|
|
std::shared_ptr<IPrinterDriver> selectPrinter(const std::string& printerName);
|
|
|
|
/**
|
|
* @brief Get the currently selected printer
|
|
* @return Current printer, or nullptr if none selected
|
|
*/
|
|
[[nodiscard]] std::shared_ptr<IPrinterDriver> getCurrentPrinter() const { return mCurrentPrinter; }
|
|
|
|
/**
|
|
* @brief Print a label
|
|
* @param label The label to print
|
|
* @return true on success, false on failure
|
|
*/
|
|
bool printLabel(std::unique_ptr<graphics::ILabel> label);
|
|
|
|
private:
|
|
libusbwrap::UsbDeviceFactory mUsbDeviceFactory;
|
|
std::vector<std::shared_ptr<IPrinterDriver>> mDetectedPrinters;
|
|
std::shared_ptr<IPrinterDriver> mCurrentPrinter;
|
|
};
|
|
|
|
} // namespace ptprnt::core
|