CVB++ 15.0
cancellation_token_source.hpp
1#pragma once
2
3#include "cancellation_token.hpp"
4
5namespace Cvb
6{
7
8CVB_BEGIN_INLINE_NS
9
10template <>
11inline HandleGuard<CancellationTokenSource>::HandleGuard(void* handle) noexcept
12 : HandleGuard<CancellationTokenSource>(handle, [](void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
13{
14}
15
17
20{
21 public:
22
24
28 : handle_(nullptr)
29 {
30 CExports::CVCANCELLATIONTOKENSOURCE sourceHandle = nullptr;
31 CExports::CVCANCELLATIONTOKEN tokenHandle = nullptr;
32 CVB_CALL_CAPI_CHECKED(CVCCreateCancellationToken(sourceHandle, tokenHandle));
33 handle_ = HandleGuard<CancellationTokenSource>(sourceHandle);
34 token_ = std::make_shared<CancellationToken>(HandleGuard<CancellationToken>(tokenHandle), CancellationToken::PrivateTag{});
35 }
36
38
44 void* Handle() const noexcept
45 {
46 return handle_.Handle();
47 }
48
50
54 CancellationTokenPtr Token() const noexcept
55 {
56 return token_;
57 }
58
60
65 void Cancel()
66 {
67 CVB_CALL_CAPI_CHECKED(CVCCancellationTokenSourceCancel(Handle()));
68 }
69
70 private:
71
72 HandleGuard<CancellationTokenSource> handle_;
74};
75
76CVB_END_INLINE_NS
77
78}
Provides tokens and signals tokens cancellation.
Definition: cancellation_token_source.hpp:20
CancellationTokenPtr Token() const noexcept
Get a token for this source.
Definition: cancellation_token_source.hpp:54
CancellationTokenSource()
Default constructor.
Definition: cancellation_token_source.hpp:27
void Cancel()
Signals the tokens cancellation.
Definition: cancellation_token_source.hpp:65
void * Handle() const noexcept
Classic API image handle.
Definition: cancellation_token_source.hpp:44
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24