2022-06-18 17:38:36 +00:00
|
|
|
#include <qpdf/qpdflogger-c.h>
|
|
|
|
|
2022-09-09 12:03:21 +00:00
|
|
|
#include <qpdf/qpdflogger-c_impl.hh>
|
|
|
|
|
2022-06-18 17:38:36 +00:00
|
|
|
#include <qpdf/Pipeline.hh>
|
2022-06-19 13:12:37 +00:00
|
|
|
#include <qpdf/Pl_Function.hh>
|
2022-06-18 17:38:36 +00:00
|
|
|
#include <qpdf/QPDFLogger.hh>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
_qpdflogger_handle::_qpdflogger_handle(std::shared_ptr<QPDFLogger> l) :
|
|
|
|
l(l)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdflogger_handle
|
|
|
|
qpdflogger_default_logger()
|
|
|
|
{
|
|
|
|
return new _qpdflogger_handle(QPDFLogger::defaultLogger());
|
|
|
|
}
|
|
|
|
|
2022-09-09 12:03:21 +00:00
|
|
|
qpdflogger_handle
|
|
|
|
qpdflogger_create()
|
|
|
|
{
|
|
|
|
return new _qpdflogger_handle(QPDFLogger::create());
|
|
|
|
}
|
|
|
|
|
2022-06-18 17:38:36 +00:00
|
|
|
void
|
|
|
|
qpdflogger_cleanup(qpdflogger_handle* l)
|
|
|
|
{
|
|
|
|
delete *l;
|
|
|
|
*l = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_log_dest(
|
|
|
|
QPDFLogger* l,
|
|
|
|
std::function<void(std::shared_ptr<Pipeline>)> method,
|
|
|
|
qpdf_log_dest_e dest,
|
|
|
|
char const* identifier,
|
|
|
|
qpdf_log_fn_t fn,
|
|
|
|
void* udata)
|
|
|
|
{
|
|
|
|
switch (dest) {
|
|
|
|
case qpdf_log_dest_default:
|
|
|
|
method(nullptr);
|
|
|
|
break;
|
|
|
|
case qpdf_log_dest_stdout:
|
|
|
|
method(l->standardOutput());
|
|
|
|
break;
|
|
|
|
case qpdf_log_dest_stderr:
|
|
|
|
method(l->standardError());
|
|
|
|
break;
|
|
|
|
case qpdf_log_dest_discard:
|
|
|
|
method(l->discard());
|
|
|
|
break;
|
|
|
|
case qpdf_log_dest_custom:
|
2022-09-08 21:34:22 +00:00
|
|
|
method(std::make_shared<Pl_Function>(identifier, nullptr, fn, udata));
|
2022-06-18 17:38:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_log_dest(
|
|
|
|
QPDFLogger* l,
|
|
|
|
void (QPDFLogger::*method)(std::shared_ptr<Pipeline>),
|
|
|
|
qpdf_log_dest_e dest,
|
|
|
|
char const* identifier,
|
|
|
|
qpdf_log_fn_t fn,
|
|
|
|
void* udata)
|
|
|
|
{
|
|
|
|
set_log_dest(
|
2023-05-21 17:35:09 +00:00
|
|
|
l, std::bind(std::mem_fn(method), l, std::placeholders::_1), dest, identifier, fn, udata);
|
2022-06-18 17:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-05-21 17:35:09 +00:00
|
|
|
qpdflogger_set_info(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
|
2022-06-18 17:38:36 +00:00
|
|
|
{
|
2023-05-21 17:35:09 +00:00
|
|
|
set_log_dest(l->l.get(), &QPDFLogger::setInfo, dest, "info logger", fn, udata);
|
2022-06-18 17:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-05-21 17:35:09 +00:00
|
|
|
qpdflogger_set_warn(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
|
2022-06-18 17:38:36 +00:00
|
|
|
{
|
2023-05-21 17:35:09 +00:00
|
|
|
set_log_dest(l->l.get(), &QPDFLogger::setWarn, dest, "warn logger", fn, udata);
|
2022-06-18 17:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-05-21 17:35:09 +00:00
|
|
|
qpdflogger_set_error(qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata)
|
2022-06-18 17:38:36 +00:00
|
|
|
{
|
2023-05-21 17:35:09 +00:00
|
|
|
set_log_dest(l->l.get(), &QPDFLogger::setError, dest, "error logger", fn, udata);
|
2022-06-18 17:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qpdflogger_set_save(
|
2023-05-21 17:35:09 +00:00
|
|
|
qpdflogger_handle l, qpdf_log_dest_e dest, qpdf_log_fn_t fn, void* udata, int only_if_not_set)
|
2022-06-18 17:38:36 +00:00
|
|
|
{
|
|
|
|
auto method = std::bind(
|
2023-05-21 17:35:09 +00:00
|
|
|
std::mem_fn(&QPDFLogger::setSave), l->l.get(), std::placeholders::_1, only_if_not_set);
|
2022-06-18 17:38:36 +00:00
|
|
|
set_log_dest(l->l.get(), method, dest, "save logger", fn, udata);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qpdflogger_save_to_standard_output(qpdflogger_handle l, int only_if_not_set)
|
|
|
|
{
|
2023-05-21 17:35:09 +00:00
|
|
|
qpdflogger_set_save(l, qpdf_log_dest_stdout, nullptr, nullptr, only_if_not_set);
|
2022-06-18 17:38:36 +00:00
|
|
|
}
|
2022-09-09 12:03:21 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qpdflogger_equal(qpdflogger_handle l1, qpdflogger_handle l2)
|
|
|
|
{
|
|
|
|
return l1->l.get() == l2->l.get();
|
|
|
|
}
|