From 1eb2f208ecfffd44c934f7ff3fa42189c206541d Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 19 Jun 2022 09:12:37 -0400 Subject: [PATCH] Use Pl_Function in qpdflogger C API implementation --- libqpdf/qpdflogger-c.cc | 45 +++++++---------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/libqpdf/qpdflogger-c.cc b/libqpdf/qpdflogger-c.cc index 46fd9fba..4640c83b 100644 --- a/libqpdf/qpdflogger-c.cc +++ b/libqpdf/qpdflogger-c.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -14,43 +15,6 @@ struct _qpdflogger_handle std::shared_ptr l; }; -namespace -{ - class FunctionPipeline: public Pipeline - { - public: - FunctionPipeline(char const* identifier, qpdf_log_fn_t fn, void* udata); - virtual ~FunctionPipeline() = default; - - virtual void write(unsigned char const* buf, size_t len) override; - virtual void finish() override; - - private: - qpdf_log_fn_t fn; - void* udata; - }; -}; // namespace - -FunctionPipeline::FunctionPipeline( - char const* identifier, qpdf_log_fn_t fn, void* udata) : - Pipeline(identifier, nullptr), - fn(fn), - udata(udata) -{ -} - -void -FunctionPipeline::write(unsigned char const* buf, size_t len) -{ - fn(reinterpret_cast(buf), QIntC::to_ulong(len), udata); -} - -void -FunctionPipeline::finish() -{ - // Nothing needed -} - _qpdflogger_handle::_qpdflogger_handle(std::shared_ptr l) : l(l) { @@ -92,7 +56,12 @@ set_log_dest( method(l->discard()); break; case qpdf_log_dest_custom: - method(std::make_shared(identifier, fn, udata)); + method(std::make_shared( + identifier, + nullptr, + [fn, udata](unsigned char const* data, size_t len) { + fn(reinterpret_cast(data), len, udata); + })); break; } }