Commit 1eb2f208ecfffd44c934f7ff3fa42189c206541d

Authored by Jay Berkenbilt
1 parent eae75dbe

Use Pl_Function in qpdflogger C API implementation

Showing 1 changed file with 7 additions and 38 deletions
libqpdf/qpdflogger-c.cc
1 1 #include <qpdf/qpdflogger-c.h>
2 2  
3 3 #include <qpdf/Pipeline.hh>
  4 +#include <qpdf/Pl_Function.hh>
4 5 #include <qpdf/QIntC.hh>
5 6 #include <qpdf/QPDFLogger.hh>
6 7 #include <functional>
... ... @@ -14,43 +15,6 @@ struct _qpdflogger_handle
14 15 std::shared_ptr<QPDFLogger> l;
15 16 };
16 17  
17   -namespace
18   -{
19   - class FunctionPipeline: public Pipeline
20   - {
21   - public:
22   - FunctionPipeline(char const* identifier, qpdf_log_fn_t fn, void* udata);
23   - virtual ~FunctionPipeline() = default;
24   -
25   - virtual void write(unsigned char const* buf, size_t len) override;
26   - virtual void finish() override;
27   -
28   - private:
29   - qpdf_log_fn_t fn;
30   - void* udata;
31   - };
32   -}; // namespace
33   -
34   -FunctionPipeline::FunctionPipeline(
35   - char const* identifier, qpdf_log_fn_t fn, void* udata) :
36   - Pipeline(identifier, nullptr),
37   - fn(fn),
38   - udata(udata)
39   -{
40   -}
41   -
42   -void
43   -FunctionPipeline::write(unsigned char const* buf, size_t len)
44   -{
45   - fn(reinterpret_cast<char const*>(buf), QIntC::to_ulong(len), udata);
46   -}
47   -
48   -void
49   -FunctionPipeline::finish()
50   -{
51   - // Nothing needed
52   -}
53   -
54 18 _qpdflogger_handle::_qpdflogger_handle(std::shared_ptr<QPDFLogger> l) :
55 19 l(l)
56 20 {
... ... @@ -92,7 +56,12 @@ set_log_dest(
92 56 method(l->discard());
93 57 break;
94 58 case qpdf_log_dest_custom:
95   - method(std::make_shared<FunctionPipeline>(identifier, fn, udata));
  59 + method(std::make_shared<Pl_Function>(
  60 + identifier,
  61 + nullptr,
  62 + [fn, udata](unsigned char const* data, size_t len) {
  63 + fn(reinterpret_cast<char const*>(data), len, udata);
  64 + }));
96 65 break;
97 66 }
98 67 }
... ...