cancellation_token.hpp
1 #pragma once
2 
3 #include "global.hpp"
4 
5 namespace Cvb
6 {
7 
8 CVB_BEGIN_INLINE_NS
9 
10 template <>
11 inline HandleGuard<CancellationToken>::HandleGuard(void* handle) noexcept
12  : HandleGuard<CancellationToken>(handle, [](void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
13 {
14 }
15 
17 
20 {
21  friend class CancellationTokenSource;
22  struct PrivateTag {};
23 
24 public:
25 
26  CancellationToken(HandleGuard<CancellationToken>&& guard, PrivateTag) noexcept
27  : handle_(std::move(guard))
28  {
29  }
30 
32 
38  void* Handle() const noexcept
39  {
40  return handle_.Handle();
41  }
42 
44 
48  bool IsCanceled() const noexcept
49  {
50  CExports::cvbbool_t status = false;
51  CVB_CALL_CAPI(CVCCancellationTokenIsCanceled(Handle(), status));
52  // suppress VC waring
53  return status != 0;
54  }
55 
56 private:
57 
58  HandleGuard<CancellationToken> handle_;
59 
60 };
61 
62 CVB_END_INLINE_NS
63 
64 }
Provides tokens and signals tokens cancellation.
Definition: cancellation_token_source.hpp:19
bool IsCanceled() const noexcept
Check if token has been canceled.
Definition: cancellation_token.hpp:48
Root namespace for the Image Manager interface.
Definition: version.hpp:11
void * Handle() const noexcept
Classic API image handle.
Definition: cancellation_token.hpp:38
A token to enable cancellation on wait operations.
Definition: cancellation_token.hpp:19