HDevThread.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*****************************************************************************
  2. * HDevThread.h
  3. *****************************************************************************
  4. *
  5. * Project: Halcon/C++
  6. * Description: Helper class for export of HDevelop's parallel
  7. * language extensions.
  8. *
  9. * (c) 2014-2022 by MVTec Software GmbH
  10. * www.mvtec.com
  11. *
  12. *****************************************************************************
  13. *
  14. *
  15. *****************************************************************************/
  16. #ifndef HCPP_DEV_THREAD_H
  17. #define HCPP_DEV_THREAD_H
  18. #include "HalconCpp.h"
  19. namespace HalconCpp
  20. {
  21. class LIntExport HDevThreadContext
  22. {
  23. public:
  24. HDevThreadContext();
  25. ~HDevThreadContext();
  26. void* GetHandle() const
  27. {
  28. return mContextHandle;
  29. }
  30. private:
  31. void* mContextHandle;
  32. };
  33. class HDevInputParam;
  34. class HDevOutputParam;
  35. class LIntExport HDevThread
  36. {
  37. public:
  38. // Manage threads and procedure calls
  39. explicit HDevThread(const HDevThreadContext& context, const void* proc,
  40. Hlong num_in, Hlong num_out);
  41. ~HDevThread();
  42. void Start();
  43. void ParStart(HTuple* par_handle);
  44. static void ParJoin(const HTuple& par_handles);
  45. void Exit(void);
  46. void CallProc();
  47. bool IsDirectCall() const
  48. {
  49. return mDirectCall;
  50. }
  51. // Store copy of input parameter value in thread-specific context
  52. void SetInputIconicParamObject(Hlong par_index, const HObject& obj);
  53. void SetInputIconicParamVector(Hlong par_index, const HObjectVector& vector);
  54. void SetInputCtrlParamTuple(Hlong par_index, const HTuple& tuple);
  55. void SetInputCtrlParamVector(Hlong par_index, const HTupleVector& vector);
  56. // Access thread-specific copy of input value
  57. const HObject& GetInputIconicParamObject(Hlong par_index) const;
  58. const HObjectVector& GetInputIconicParamVector(Hlong par_index) const;
  59. const HTuple& GetInputCtrlParamTuple(Hlong par_index) const;
  60. const HTupleVector& GetInputCtrlParamVector(Hlong par_index) const;
  61. // Bind variable reference to output parameter
  62. void BindOutputIconicParamObject(Hlong par_index, bool global, HObject* obj);
  63. void BindOutputIconicParamVector(Hlong par_index, bool global,
  64. HObjectVector* vector,
  65. HTuple index = HTuple());
  66. void BindOutputCtrlParamTuple(Hlong par_index, bool global, HTuple* obj);
  67. void BindOutputCtrlParamVector(Hlong par_index, bool global,
  68. HTupleVector* vector,
  69. HTuple index = HTuple());
  70. // Store result of procedure call into bound output variables
  71. void StoreOutputIconicParamObject(Hlong par_index, const HObject& obj);
  72. void StoreOutputIconicParamVector(Hlong par_index,
  73. const HObjectVector& vector);
  74. void StoreOutputCtrlParamTuple(Hlong par_index, const HTuple& tuple);
  75. void StoreOutputCtrlParamVector(Hlong par_index, const HTupleVector& vector);
  76. protected:
  77. void* mThreadHandle;
  78. const void* mProc;
  79. bool mDirectCall;
  80. Hlong mNumParamsInput;
  81. Hlong mNumParamsOutput;
  82. HDevInputParam** mParamsInput;
  83. HDevOutputParam** mParamsOutput;
  84. };
  85. } // namespace HalconCpp
  86. #endif