From 7e42c52ee95590f258b33168f6bd3cae4846cb3c Mon Sep 17 00:00:00 2001 From: birkholz-cubert Date: Tue, 3 Jun 2025 13:21:13 +0200 Subject: [PATCH 1/4] added functions stubs for handle management in cpp wrapper --- interface/cuvis.hpp | 89 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/interface/cuvis.hpp b/interface/cuvis.hpp index a9cc8fb..dfcccd6 100644 --- a/interface/cuvis.hpp +++ b/interface/cuvis.hpp @@ -898,7 +898,19 @@ namespace cuvis * */ void refresh(); - private: + /** @brief Expert: Return the current handle of the wrapper class */ + CUVIS_MESU get_handle() const; + /** @brief Expert: Create a copy of the current handle of the wrapper class and return it. + * This handle needs to be also freed before the resource will be released by the sdk. + */ + CUVIS_MESU get_handle_copy() const; + + public: + /** @brief Expert: Create a wrapper class around a handle. + * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. + * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. + * Most of the time this is not necesarry and the wrapper class can be copied just as well + */ Measurement(CUVIS_MESU handle); @@ -972,6 +984,21 @@ namespace cuvis */ std::string get_id() const; + /** @brief Expert: Return the current handle of the wrapper class */ + CUVIS_CALIB get_handle() const; + /** @brief Expert: Create a copy of the current handle of the wrapper class and return it. + * This handle needs to be also freed before the resource will be released by the sdk. + */ + CUVIS_CALIB get_handle_copy() const; + + public: + /** @brief Expert: Create a wrapper class around a handle. + * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. + * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. + * Most of the time this is not necesarry and the wrapper class can be copied just as well + */ + Calibration(CUVIS_CALIB handle); + private: std::shared_ptr _calib; }; @@ -1010,6 +1037,21 @@ namespace cuvis */ CUVIS_OPERATION_MODE get_operation_mode() const; + /** @brief Expert: Return the current handle of the wrapper class */ + CUVIS_SESSION_FILE get_handle() const; + /** @brief Expert: Create a copy of the current handle of the wrapper class and return it. + * This handle needs to be also freed before the resource will be released by the sdk. + */ + CUVIS_SESSION_FILE get_handle_copy() const; + + public: + /** @brief Expert: Create a wrapper class around a handle. + * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. + * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. + * Most of the time this is not necesarry and the wrapper class can be copied just as well + */ + SessionFile(CUVIS_SESSION_FILE handle); + private: std::shared_ptr _session; }; @@ -1090,6 +1132,21 @@ namespace cuvis */ std::string get_calib_id() const; + /** @brief Expert: Return the current handle of the wrapper class */ + CUVIS_PROC_CONT get_handle() const; + /** @brief Expert: Create a copy of the current handle of the wrapper class and return it. + * This handle needs to be also freed before the resource will be released by the sdk. + */ + CUVIS_PROC_CONT get_handle_copy() const; + + public: + /** @brief Expert: Create a wrapper class around a handle. + * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. + * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. + * Most of the time this is not necesarry and the wrapper class can be copied just as well + */ + ProcessingContext(CUVIS_PROC_CONT handle); + private: std::shared_ptr _procCont; ProcessingArgs _procArgs; @@ -1260,7 +1317,21 @@ namespace cuvis ACQ_STUB_1b(component_integration_time_factor, cuvis_comp_integration_time_factor, double, double); #undef ACQ_STUB_1b + + /** @brief Expert: Return the current handle of the wrapper class */ CUVIS_ACQ_CONT get_handle() const; + /** @brief Expert: Create a copy of the current handle of the wrapper class and return it. + * This handle needs to be also freed before the resource will be released by the sdk. + */ + CUVIS_ACQ_CONT get_handle_copy() const; + + public: + /** @brief Expert: Create a wrapper class around a handle. + * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. + * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. + * Most of the time this is not necesarry and the wrapper class can be copied just as well + */ + AcquisitionContext(CUVIS_ACQ_CONT handle); private: std::shared_ptr _acqCont; @@ -1283,6 +1354,21 @@ namespace cuvis Viewer(ViewArgs const& args); view_data_t apply(Measurement const& mesu); + /** @brief Expert: Return the current handle of the wrapper class */ + CUVIS_VIEWER get_handle() const; + /** @brief Expert: Create a copy of the current handle of the wrapper class and return it. + * This handle needs to be also freed before the resource will be released by the sdk. + */ + CUVIS_VIEWER get_handle_copy() const; + + public: + /** @brief Expert: Create a wrapper class around a handle. + * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. + * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. + * Most of the time this is not necesarry and the wrapper class can be copied just as well + */ + Viewer(CUVIS_VIEWER handle); + private: std::shared_ptr _viewer; static view_data_t create_view_data(CUVIS_VIEW); @@ -1532,7 +1618,6 @@ namespace cuvis }; get_flag(CUVIS_MESU_FLAG_OVERILLUMINATED, CUVIS_MESU_FLAG_OVERILLUMINATED_KEY); - get_flag(CUVIS_MESU_FLAG_PAN_OVERILLUMINATED, CUVIS_MESU_FLAG_PAN_OVERILLUMINATED_KEY); get_flag(CUVIS_MESU_FLAG_POOR_REFERENCE, CUVIS_MESU_FLAG_POOR_REFERENCE_KEY); get_flag(CUVIS_MESU_FLAG_POOR_WHITE_BALANCING, CUVIS_MESU_FLAG_POOR_WHITE_BALANCING_KEY); get_flag(CUVIS_MESU_FLAG_DARK_INTTIME, CUVIS_MESU_FLAG_DARK_INTTIME_KEY); From 62684e03d0aea6eb02baa83276ab2b70133aeafa Mon Sep 17 00:00:00 2001 From: birkholz-cubert Date: Tue, 3 Jun 2025 13:47:37 +0200 Subject: [PATCH 2/4] added implementation to fuction stubs --- interface/cuvis.hpp | 98 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 8 deletions(-) diff --git a/interface/cuvis.hpp b/interface/cuvis.hpp index dfcccd6..0d653d7 100644 --- a/interface/cuvis.hpp +++ b/interface/cuvis.hpp @@ -906,7 +906,7 @@ namespace cuvis CUVIS_MESU get_handle_copy() const; public: - /** @brief Expert: Create a wrapper class around a handle. + /** @brief Expert: Create a wrapper class around a handle. * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. * Most of the time this is not necesarry and the wrapper class can be copied just as well @@ -992,7 +992,7 @@ namespace cuvis CUVIS_CALIB get_handle_copy() const; public: - /** @brief Expert: Create a wrapper class around a handle. + /** @brief Expert: Create a wrapper class around a handle. * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. * Most of the time this is not necesarry and the wrapper class can be copied just as well @@ -1045,7 +1045,7 @@ namespace cuvis CUVIS_SESSION_FILE get_handle_copy() const; public: - /** @brief Expert: Create a wrapper class around a handle. + /** @brief Expert: Create a wrapper class around a handle. * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. * Most of the time this is not necesarry and the wrapper class can be copied just as well @@ -1140,7 +1140,7 @@ namespace cuvis CUVIS_PROC_CONT get_handle_copy() const; public: - /** @brief Expert: Create a wrapper class around a handle. + /** @brief Expert: Create a wrapper class around a handle. * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. * Most of the time this is not necesarry and the wrapper class can be copied just as well @@ -1326,7 +1326,7 @@ namespace cuvis CUVIS_ACQ_CONT get_handle_copy() const; public: - /** @brief Expert: Create a wrapper class around a handle. + /** @brief Expert: Create a wrapper class around a handle. * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. * Most of the time this is not necesarry and the wrapper class can be copied just as well @@ -1362,7 +1362,7 @@ namespace cuvis CUVIS_VIEWER get_handle_copy() const; public: - /** @brief Expert: Create a wrapper class around a handle. + /** @brief Expert: Create a wrapper class around a handle. * This only allowed once per handle, otherwise the handle could be freed before all instances of the wrapper class are deleted. * This can be useful if a previously a handle has been copied and now should be wrapped at another place in a program. * Most of the time this is not necesarry and the wrapper class can be copied just as well @@ -1545,6 +1545,7 @@ namespace cuvis refresh(); } + inline Measurement::Measurement(CUVIS_MESU handle) : _gps_data(std::make_shared()), _string_data(std::make_shared()), @@ -1762,6 +1763,15 @@ namespace cuvis return res; } + inline CUVIS_MESU Measurement::get_handle() const { return *_mesu; } + + inline CUVIS_MESU Measurement::get_handle_copy() const + { + CUVIS_MESU new_handle; + chk(cuvis_measurement_copy_handle(*_mesu, &new_handle)); + return new_handle; + } + inline std::string Calibration::get_id() const { CUVIS_CHAR id[CUVIS_MAXBUF]; @@ -1827,6 +1837,23 @@ namespace cuvis delete handle; }); } + + inline Calibration::Calibration(CUVIS_CALIB handle) + : _calib(std::shared_ptr(new CUVIS_CALIB{handle}, [](CUVIS_CALIB* handle) { + cuvis_calib_free(handle); + delete handle; + })) + {} + + inline CUVIS_CALIB Calibration::get_handle() const { return *_calib; } + + inline CUVIS_CALIB Calibration::get_handle_copy() const + { + CUVIS_CALIB new_handle; + chk(cuvis_calib_copy_handle(*_calib, &new_handle)); + return new_handle; + } + inline ProcessingContext::ProcessingContext(Calibration const& calib) { CUVIS_PROC_CONT procCont; @@ -1857,6 +1884,13 @@ namespace cuvis }); } + inline ProcessingContext::ProcessingContext(CUVIS_CALIB handle) + : _procCont(std::shared_ptr(new CUVIS_PROC_CONT{handle}, [](CUVIS_PROC_CONT* handle) { + cuvis_proc_cont_free(handle); + delete handle; + })) + {} + inline Measurement& ProcessingContext::apply(Measurement& mesu) const { chk(cuvis_proc_cont_apply(*_procCont, *mesu._mesu)); @@ -1925,6 +1959,15 @@ namespace cuvis inline ProcessingArgs const& ProcessingContext::get_processingArgs() const { return _procArgs; } + inline CUVIS_PROC_CONT ProcessingContext::get_handle() const { return *_procCont; } + + inline CUVIS_PROC_CONT ProcessingContext::get_handle_copy() const + { + CUVIS_PROC_CONT new_handle; + chk(cuvis_proc_cont_copy_handle(*_procCont, &new_handle)); + return new_handle; + } + inline Worker::Worker(WorkerArgs const& args) : _worker_poll_thread_run(false) { @@ -2205,6 +2248,22 @@ namespace cuvis }); } + inline Viewer::Viewer(CUVIS_VIEWER handle) + : _viewer(std::shared_ptr(new CUVIS_VIEWER{handle}, [](CUVIS_VIEWER* handle) { + cuvis_viewer_free(handle); + delete handle; + })) + {} + + inline CUVIS_VIEWER Viewer::get_handle() const { return *_viewer; } + + inline CUVIS_VIEWER Viewer::get_handle_copy() const + { + CUVIS_VIEWER new_handle; + chk(cuvis_viewer_copy_handle(*_viewer, &new_handle)); + return new_handle; + } + inline Viewer::view_data_t Viewer::apply(Measurement const& mesu) { CUVIS_VIEW current_view; @@ -2278,8 +2337,6 @@ namespace cuvis } inline AcquisitionContext::~AcquisitionContext() { reset_state_change_callback(); } - inline CUVIS_ACQ_CONT AcquisitionContext::get_handle() const { return *_acqCont; } - inline AcquisitionContext::AcquisitionContext(Calibration const& calib) : _state_poll_thread_run(false) { CUVIS_ACQ_CONT acqCont; @@ -2301,6 +2358,22 @@ namespace cuvis }); } + inline AcquisitionContext::AcquisitionContext(CUVIS_VIEWER handle) + : _acqCont(std::shared_ptr(new CUVIS_ACQ_CONT{handle}, [](CUVIS_ACQ_CONT* handle) { + cuvis_acq_cont_free(handle); + delete handle; + })) + {} + + inline CUVIS_ACQ_CONT AcquisitionContext::get_handle() const { return *_acqCont; } + + inline CUVIS_ACQ_CONT AcquisitionContext::get_handle_copy() const + { + CUVIS_ACQ_CONT new_handle; + chk(cuvis_acq_cont_copy_handle(*_acqCont, &new_handle)); + return new_handle; + } + inline void AcquisitionContext::register_state_change_callback(state_callback_t callback, bool output_initial_state) { @@ -2785,6 +2858,15 @@ namespace cuvis return op_mode; } + inline CUVIS_SESSION_FILE SessionFile::get_handle() const { return *_session; } + + inline CUVIS_SESSION_FILE SessionFile::get_handle_copy() const + { + CUVIS_SESSION_FILE new_handle; + chk(cuvis_session_file_copy_handle(*_session, &new_handle)); + return new_handle; + } + template inline data_t const& common_image_t::get(std::size_t x, std::size_t y, std::size_t z) const { From 80e937a004ee0d82db21cec9c6b374f6e8b5823d Mon Sep 17 00:00:00 2001 From: birkholz-cubert Date: Tue, 10 Jun 2025 10:20:04 +0200 Subject: [PATCH 3/4] removed unwanted delete --- interface/cuvis.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/cuvis.hpp b/interface/cuvis.hpp index 54d5866..0edf27e 100644 --- a/interface/cuvis.hpp +++ b/interface/cuvis.hpp @@ -1619,6 +1619,7 @@ namespace cuvis }; get_flag(CUVIS_MESU_FLAG_OVERILLUMINATED, CUVIS_MESU_FLAG_OVERILLUMINATED_KEY); + get_flag(CUVIS_MESU_FLAG_PAN_OVERILLUMINATED, CUVIS_MESU_FLAG_PAN_OVERILLUMINATED_KEY); get_flag(CUVIS_MESU_FLAG_POOR_REFERENCE, CUVIS_MESU_FLAG_POOR_REFERENCE_KEY); get_flag(CUVIS_MESU_FLAG_POOR_WHITE_BALANCING, CUVIS_MESU_FLAG_POOR_WHITE_BALANCING_KEY); get_flag(CUVIS_MESU_FLAG_DARK_INTTIME, CUVIS_MESU_FLAG_DARK_INTTIME_KEY); From 02745ed37ba081c2e08e4bae9501acfcfc660622 Mon Sep 17 00:00:00 2001 From: birkholz-cubert Date: Tue, 10 Jun 2025 10:20:56 +0200 Subject: [PATCH 4/4] wip --- interface/cuvis.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/cuvis.hpp b/interface/cuvis.hpp index 0edf27e..53150dc 100644 --- a/interface/cuvis.hpp +++ b/interface/cuvis.hpp @@ -1619,7 +1619,7 @@ namespace cuvis }; get_flag(CUVIS_MESU_FLAG_OVERILLUMINATED, CUVIS_MESU_FLAG_OVERILLUMINATED_KEY); - get_flag(CUVIS_MESU_FLAG_PAN_OVERILLUMINATED, CUVIS_MESU_FLAG_PAN_OVERILLUMINATED_KEY); + get_flag(CUVIS_MESU_FLAG_PAN_OVERILLUMINATED, CUVIS_MESU_FLAG_PAN_OVERILLUMINATED_KEY); get_flag(CUVIS_MESU_FLAG_POOR_REFERENCE, CUVIS_MESU_FLAG_POOR_REFERENCE_KEY); get_flag(CUVIS_MESU_FLAG_POOR_WHITE_BALANCING, CUVIS_MESU_FLAG_POOR_WHITE_BALANCING_KEY); get_flag(CUVIS_MESU_FLAG_DARK_INTTIME, CUVIS_MESU_FLAG_DARK_INTTIME_KEY);