Commit bb0ea2f8e7d8fffa575b291004e4426138c7bb1a
1 parent
87412eb0
Add qpdfjob_register_progress_reporter
Showing
8 changed files
with
53 additions
and
9 deletions
ChangeLog
| 1 | 1 | 2022-06-18 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | |
| 3 | + * Add QPDFJob::registerProgressReporter, making it possible to | |
| 4 | + override the progress reporter that is used when --progress (or | |
| 5 | + the equivalent) is configured with QPDFJob. This is | |
| 6 | + qpdfjob_register_progress_reporter in the C API. | |
| 7 | + | |
| 3 | 8 | * Add examples that show how to capture QPDFJob's output by |
| 4 | 9 | configuring the default logger (qpdfjob-save-attachment.cc, |
| 5 | 10 | qpdfjob-c-save-attachment.c). Fixes #691. | ... | ... |
TODO
| ... | ... | @@ -14,9 +14,7 @@ Next: |
| 14 | 14 | |
| 15 | 15 | Pending changes: |
| 16 | 16 | |
| 17 | -* Allow users to supply a custom progress reporter for QPDFJob. If one | |
| 18 | - is provided, use it instead of creating one. Then expose to the C | |
| 19 | - API. Consider also exposing a way to set a new logger and to get the | |
| 17 | +* Consider also exposing a way to set a new logger and to get the | |
| 20 | 18 | logger from QPDF and QPDFJob in the C API. |
| 21 | 19 | * Check about runpath in the linux-bin distribution. I think the |
| 22 | 20 | appimage build specifically is setting the runpath, which is | ... | ... |
include/qpdf/qpdfjob-c.h
| ... | ... | @@ -125,6 +125,16 @@ extern "C" { |
| 125 | 125 | QPDF_DLL |
| 126 | 126 | int qpdfjob_run(qpdfjob_handle j); |
| 127 | 127 | |
| 128 | + /* Allow specification of a custom progress reporter. The progress | |
| 129 | + * reporter is only used if progress is otherwise requested (with | |
| 130 | + * the --progress option or "progress": "" in the JSON). | |
| 131 | + */ | |
| 132 | + QPDF_DLL | |
| 133 | + void qpdfjob_register_progress_reporter( | |
| 134 | + qpdfjob_handle j, | |
| 135 | + void (*report_progress)(int percent, void* data), | |
| 136 | + void* data); | |
| 137 | + | |
| 128 | 138 | #ifdef __cplusplus |
| 129 | 139 | } |
| 130 | 140 | #endif | ... | ... |
libqpdf/qpdfjob-c.cc
| ... | ... | @@ -120,3 +120,12 @@ int qpdfjob_run_from_json(char const* json) |
| 120 | 120 | }); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | +void | |
| 124 | +qpdfjob_register_progress_reporter( | |
| 125 | + qpdfjob_handle j, | |
| 126 | + void (*report_progress)(int percent, void* data), | |
| 127 | + void* data) | |
| 128 | +{ | |
| 129 | + j->j.registerProgressReporter( | |
| 130 | + std::bind(report_progress, std::placeholders::_1, data)); | |
| 131 | +} | ... | ... |
manual/release-notes.rst
| ... | ... | @@ -186,8 +186,8 @@ For a detailed list of changes, please see the file |
| 186 | 186 | - Add new ``Pipeline`` type ``Pl_String`` to append to a |
| 187 | 187 | ``std::string``. |
| 188 | 188 | |
| 189 | - - Add methods to QUtil for converting PDF timestamps and QPDFTime | |
| 190 | - objects to ISO-8601 timestamps. | |
| 189 | + - Add methods to ``QUtil`` for converting PDF timestamps and | |
| 190 | + ``QPDFTime`` objects to ISO-8601 timestamps. | |
| 191 | 191 | |
| 192 | 192 | - Enhance JSON class to better support incrementally reading and |
| 193 | 193 | writing large amounts of data without having to keep everything |
| ... | ... | @@ -200,6 +200,12 @@ For a detailed list of changes, please see the file |
| 200 | 200 | interface offers more flexibility than the old interface, which |
| 201 | 201 | remains available. |
| 202 | 202 | |
| 203 | + - Add ``QPDFJob::registerProgressReporter`` and | |
| 204 | + ``qpdfjob_register_progress_reporter`` to allow a custom | |
| 205 | + progress reporter to be used with ``QPDFJob``. The ``QPDFJob`` | |
| 206 | + object must be configured to report progress (via command-line | |
| 207 | + argument or otherwise) for this to be used. | |
| 208 | + | |
| 203 | 209 | - Other changes |
| 204 | 210 | |
| 205 | 211 | - In JSON v1 mode, the ``"objects"`` key now reflects the repaired | ... | ... |
qpdf/qpdfjob-ctest.c
| ... | ... | @@ -21,17 +21,29 @@ wide_test() |
| 21 | 21 | #endif // QPDF_NO_WCHAR_T |
| 22 | 22 | |
| 23 | 23 | static void |
| 24 | +custom_progress(int progress, void* data) | |
| 25 | +{ | |
| 26 | + printf("%s: write progress: %d%%\n", (char const*)data, progress); | |
| 27 | +} | |
| 28 | + | |
| 29 | +static void | |
| 24 | 30 | run_tests() |
| 25 | 31 | { |
| 26 | 32 | /* Be sure to use a different output file for each test. */ |
| 33 | + qpdfjob_handle j = NULL; | |
| 27 | 34 | |
| 28 | - char const* argv[5]; | |
| 35 | + char const* argv[6]; | |
| 29 | 36 | argv[0] = "qpdfjob"; |
| 30 | 37 | argv[1] = "minimal.pdf"; |
| 31 | 38 | argv[2] = "a.pdf"; |
| 32 | 39 | argv[3] = "--deterministic-id"; |
| 33 | - argv[4] = NULL; | |
| 34 | - assert(qpdfjob_run_from_argv(argv) == 0); | |
| 40 | + argv[4] = "--progress"; | |
| 41 | + argv[5] = NULL; | |
| 42 | + j = qpdfjob_init(); | |
| 43 | + qpdfjob_register_progress_reporter(j, custom_progress, (void*)"potato"); | |
| 44 | + assert(qpdfjob_initialize_from_argv(j, argv) == 0); | |
| 45 | + assert(qpdfjob_run(j) == 0); | |
| 46 | + qpdfjob_cleanup(&j); | |
| 35 | 47 | printf("argv test passed\n"); |
| 36 | 48 | |
| 37 | 49 | assert(qpdfjob_run_from_json("{\n\ | ... | ... |
qpdf/qtest/qpdf/qpdfjob-ctest.out
qpdf/qtest/qpdfjob.test
| ... | ... | @@ -100,7 +100,8 @@ $td->runtest("json output from job", |
| 100 | 100 | $td->NORMALIZE_NEWLINES); |
| 101 | 101 | |
| 102 | 102 | $td->runtest("C job API", |
| 103 | - {$td->COMMAND => "qpdfjob-ctest"}, | |
| 103 | + {$td->COMMAND => "qpdfjob-ctest", | |
| 104 | + $td->FILTER => "perl filter-progress.pl"}, | |
| 104 | 105 | {$td->FILE => "qpdfjob-ctest.out", $td->EXIT_STATUS => 0}, |
| 105 | 106 | $td->NORMALIZE_NEWLINES); |
| 106 | 107 | foreach my $i (['a.pdf', 1], ['b.pdf', 2], ['c.pdf', 3]) | ... | ... |