Skip to content

feat: Adds Progress and Cancel API support#195

Merged
gpeacock merged 4 commits intomainfrom
feature/progress-cancel
Mar 30, 2026
Merged

feat: Adds Progress and Cancel API support#195
gpeacock merged 4 commits intomainfrom
feature/progress-cancel

Conversation

@gpeacock
Copy link
Copy Markdown
Member

Update progress/cancel API to published c2pa-rs 0.78.7

Bump c2pa-rs dependency from pre-release 0.78.4 to published 0.78.7; bump project to 0.18.3
Replace C2paProgressPhase (C unscoped enum) with c2pa::ProgressPhase scoped enum class in the public API; add static_asserts to catch any future C/C++ enum divergence at compile time
Fix trampoline signature to match published ABI (const void*, int return, enum-typed phase)
Update tests and remove stale @note Requires c2pa-rs >= 0.79.0 comments
Add progress/cancel section to context-settings.md

Exposes the progress/cancel feature added to c2pa-rs in PR #1927
(merged to main 2026-03-24, not yet on crates.io).

Public API additions (c2pa.hpp):
- `c2pa::ProgressCallbackFunc` — std::function alias for the callback.
  Signature: `bool(C2paProgressPhase phase, uint32_t step, uint32_t total)`.
  Return false to request cancellation.
- `Context::ContextBuilder::with_progress_callback(ProgressCallbackFunc)`
  Attaches a progress callback to the context being built. Chainable with
  with_settings(), with_json(), and with_signer(). The heap-allocated
  std::function is owned by the resulting Context and freed on destruction.
- `Context::cancel() noexcept`
  Requests cancellation of the current in-progress operation. Safe to call
  from another thread.

Implementation (c2pa_context.cpp):
- `progress_callback_trampoline` — static C-compatible trampoline that
  forwards (user_data, phase, step, total) to the stored std::function.
- `ContextBuilder::pending_callback_` — unique_ptr holding the heap-allocated
  callback between with_progress_callback() and create_context().
- `Context::callback_owner_` — void* that takes ownership of the raw pointer
  on create_context(); deleted in ~Context() and forwarded by move ops.

Tests (context.test.cpp):
- ProgressCallback_InvokedDuringSigning / _InvokedDuringReading
- ProgressCallback_StepAndTotalValues
- ProgressCallback_ReturnFalseCancels
- ProgressCallback_CancelMethodAbortsOperation
- CancelWithoutCallback_IsNoOp
- ProgressCallback_ChainWithSettings
- ProgressCallback_SurvivesContextMove / _SurvivesBuilderMove

Requires: c2pa-rs >= 0.79.0 built from source (C2PA_BUILD_FROM_SOURCE=ON)
pointing to a c2pa-rs checkout containing the progress/cancel feature.

Made-with: Cursor
Bump c2pa-rs dependency from pre-release 0.78.4 to published 0.78.7; bump project to 0.18.3
Replace C2paProgressPhase (C unscoped enum) with c2pa::ProgressPhase scoped enum class in the public API; add static_asserts to catch any future C/C++ enum divergence at compile time
Fix trampoline signature to match published ABI (const void*, int return, enum-typed phase)
Update tests and remove stale @note Requires c2pa-rs >= 0.79.0 comments
Add progress/cancel section to context-settings.md
@gpeacock gpeacock requested a review from tmathern March 28, 2026 01:06
@gpeacock gpeacock merged commit 13a0b5f into main Mar 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants