cli-parser-cleanup (#15)
All checks were successful
Build ptprnt / build (push) Successful in 3m50s
All checks were successful
Build ptprnt / build (push) Successful in 3m50s
Reviewed-on: moritz/ptouch-prnt#15
This commit was merged in pull request #15.
This commit is contained in:
89
src/core/PrinterService.hpp
Normal file
89
src/core/PrinterService.hpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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/IPrinterService.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
#include "printers/interface/IPrinterDriver.hpp"
|
||||
|
||||
namespace ptprnt::core {
|
||||
|
||||
/**
|
||||
* @brief Core service for printer operations
|
||||
*
|
||||
* Concrete implementation of IPrinterService.
|
||||
* Provides the core library functionality for:
|
||||
* - Detecting printers
|
||||
* - Selecting printers
|
||||
* - Building and printing labels
|
||||
*/
|
||||
class PrinterService : public IPrinterService {
|
||||
public:
|
||||
PrinterService();
|
||||
~PrinterService() override = 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() override;
|
||||
|
||||
/**
|
||||
* @brief Detect all compatible printers
|
||||
* @return Vector of detected printers
|
||||
*/
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> detectPrinters() override;
|
||||
|
||||
/**
|
||||
* @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) override;
|
||||
|
||||
/**
|
||||
* @brief Get the currently selected printer
|
||||
* @return Current printer, or nullptr if none selected
|
||||
*/
|
||||
[[nodiscard]] std::shared_ptr<IPrinterDriver> getCurrentPrinter() const override { 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) override;
|
||||
|
||||
private:
|
||||
libusbwrap::UsbDeviceFactory mUsbDeviceFactory;
|
||||
std::vector<std::shared_ptr<IPrinterDriver>> mDetectedPrinters;
|
||||
std::shared_ptr<IPrinterDriver> mCurrentPrinter;
|
||||
};
|
||||
|
||||
} // namespace ptprnt::core
|
||||
Reference in New Issue
Block a user