gasync_context.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2019 Intel Corporation
  6. #ifndef OPENCV_GAPI_GASYNC_CONTEXT_HPP
  7. #define OPENCV_GAPI_GASYNC_CONTEXT_HPP
  8. #if !defined(GAPI_STANDALONE)
  9. # include <opencv2/core/cvdef.h>
  10. #else // Without OpenCV
  11. # include <opencv2/gapi/own/cvdefs.hpp>
  12. #endif // !defined(GAPI_STANDALONE)
  13. #include <opencv2/gapi/own/exports.hpp>
  14. namespace cv {
  15. namespace gapi{
  16. /**
  17. * @brief This namespace contains experimental G-API functionality,
  18. * functions or structures in this namespace are subjects to change or
  19. * removal in the future releases. This namespace also contains
  20. * functions which API is not stabilized yet.
  21. */
  22. namespace wip {
  23. /**
  24. * @brief A class to group async requests to cancel them in a single shot.
  25. *
  26. * GAsyncContext is passed as an argument to async() and async_apply() functions
  27. */
  28. class GAPI_EXPORTS GAsyncContext{
  29. std::atomic<bool> cancelation_requested = {false};
  30. public:
  31. /**
  32. * @brief Start cancellation process for an associated request.
  33. *
  34. * User still has to wait for each individual request (either via callback or according std::future object) to make sure it actually canceled.
  35. *
  36. * @return true if it was a first request to cancel the context
  37. */
  38. bool cancel();
  39. /**
  40. * @brief Returns true if cancellation was requested for this context.
  41. *
  42. * @return true if cancellation was requested for this context
  43. */
  44. bool isCanceled() const;
  45. };
  46. class GAPI_EXPORTS GAsyncCanceled : public std::exception {
  47. public:
  48. virtual const char* what() const noexcept CV_OVERRIDE;
  49. };
  50. } // namespace wip
  51. } // namespace gapi
  52. } // namespace cv
  53. #endif //OPENCV_GAPI_GASYNC_CONTEXT_HPP