From 43fa0cb2a7452b94d0dabaa710bead000bd19d00 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 12:11:16 +0100 Subject: [PATCH 01/24] Added SAL headers. --- power_overwhelming/CMakeLists.txt | 8 +++----- .../power_overwhelming/power_overwhelming_api.h | 4 ++++ third_party/CMakeLists.txt | 12 ++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/power_overwhelming/CMakeLists.txt b/power_overwhelming/CMakeLists.txt index cae91934..a1cafe0c 100644 --- a/power_overwhelming/CMakeLists.txt +++ b/power_overwhelming/CMakeLists.txt @@ -56,11 +56,9 @@ target_include_directories(${PROJECT_NAME} PRIVATE $) -target_link_libraries(${PROJECT_NAME} PRIVATE - nlohmann_json - adl - nvml - tinkerforge) +target_link_libraries(${PROJECT_NAME} + PUBLIC salieri + PRIVATE adl nlohmann_json nvml tinkerforge) if (WIN32) target_link_libraries(${PROJECT_NAME} PUBLIC Ws2_32) diff --git a/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h b/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h index 7ddd3992..4dd33fc9 100644 --- a/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h +++ b/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h @@ -17,3 +17,7 @@ #define POWER_OVERWHELMING_API #endif /* defined(WIN32) */ + + +// Empty SAL annotations for rancid platforms. +#include "salieri.h" diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index b51c878f..8225f542 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -58,6 +58,18 @@ set(RsHmc8015Include ${RsHmc8015Dir} PARENT_SCOPE) set(RsRtxDir ${CMAKE_CURRENT_SOURCE_DIR}/rsrtx-cvi-1.4.0) set(RsRtxInclude ${RsRtxDir} PARENT_SCOPE) +# SAL annotations +FetchContent_Declare(salieri + URL "https://github.com/nemequ/salieri/archive/refs/heads/master.zip" +) +FetchContent_MakeAvailable(salieri) +add_library(salieri INTERFACE IMPORTED GLOBAL) +set_target_properties(salieri PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${salieri_SOURCE_DIR}") + +mark_as_advanced(FORCE + FETCHCONTENT_SOURCE_DIR_SALIERI + FETCHCONTENT_UPDATES_DISCONNECTED_SALIERI) + # Tinkerforge API set(TinkerforgeDir ${CMAKE_CURRENT_SOURCE_DIR}/tinkerforge_c_bindings_2_1_32/source) file(GLOB_RECURSE TinkerforgeHeaderFiles "${TinkerforgeDir}/*.h" "${TinkerforgeDir}/*.inl") From 3143a34c89c32c371cd88300c6836d4f2a4dd024 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 12:17:10 +0100 Subject: [PATCH 02/24] measurement annotations. --- .../include/power_overwhelming/measurement.h | 46 +++++++++++-------- power_overwhelming/src/measurement.cpp | 29 +++++++----- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/measurement.h b/power_overwhelming/include/power_overwhelming/measurement.h index e3c0ad44..9584eef7 100644 --- a/power_overwhelming/include/power_overwhelming/measurement.h +++ b/power_overwhelming/include/power_overwhelming/measurement.h @@ -48,35 +48,45 @@ namespace power_overwhelming { /// Initialises a new instance. /// /// The name of the sensor from which the - /// measurement originates. - /// - /// - /// - /// - measurement(const char_type *sensor, const timestamp_type timestamp, - const value_type voltage, const value_type current, - const value_type power); + /// measurement originates, which must be a non-nullptr string. + /// + /// The timestamp of the sensor. The unit is + /// defined by the configuration of the sensor. + /// The measured voltage in Volts. + /// The measured current in Amperes. + /// The measured power in Watts. + measurement(_In_z_ const char_type *sensor, + _In_ const timestamp_type timestamp, + _In_ const value_type voltage, + _In_ const value_type current, + _In_ const value_type power); /// /// Initialises a new instance. /// /// The name of the sensor from which the /// measurement originates. - /// - /// - /// - measurement(const char_type *sensor, const timestamp_type timestamp, - const value_type voltage, const value_type current); + /// The timestamp of the sensor. The unit is + /// defined by the configuration of the sensor. + /// The measured voltage in Volts. + /// The measured current in Amperes. + measurement(_In_z_ const char_type *sensor, + _In_ const timestamp_type timestamp, + _In_ const value_type voltage, + _In_ const value_type current); /// /// Initialises a new instance. /// /// The name of the sensor from which the /// measurement originates. - /// + /// The timestamp of the sensor. The unit is + /// defined by the configuration of the sensor. /// - measurement(const char_type *sensor, const timestamp_type timestamp, - const value_type power); + /// The measured power in Watts. + measurement(_In_z_ const char_type *sensor, + _In_ const timestamp_type timestamp, + _In_ const value_type power); /// /// Clone . @@ -128,7 +138,7 @@ namespace power_overwhelming { /// Gets the name of the sensor the measurement comes from. /// /// - inline const char_type *sensor(void) const noexcept { + inline _Ret_z_ const char_type *sensor(void) const noexcept { return this->_sensor; } @@ -184,7 +194,7 @@ namespace power_overwhelming { /// A callback for s that are received /// asynchronously. /// - typedef void (*measurement_callback)(const measurement&, void *); + typedef void (*measurement_callback)(const measurement&, _In_opt_ void *); } /* namespace power_overwhelming */ } /* namespace visus */ diff --git a/power_overwhelming/src/measurement.cpp b/power_overwhelming/src/measurement.cpp index 572968ce..d33db869 100644 --- a/power_overwhelming/src/measurement.cpp +++ b/power_overwhelming/src/measurement.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/measurement.h" @@ -20,9 +20,12 @@ visus::power_overwhelming::measurement::invalid_value /* * visus::power_overwhelming::measurement::measurement */ -visus::power_overwhelming::measurement::measurement(const char_type *sensor, - const timestamp_type timestamp, const value_type voltage, - const value_type current, const value_type power) +visus::power_overwhelming::measurement::measurement( + _In_z_ const char_type *sensor, + _In_ const timestamp_type timestamp, + _In_ const value_type voltage, + _In_ const value_type current, + _In_ const value_type power) :_current(current), _power(power), _sensor(nullptr), _timestamp(timestamp), _voltage(voltage) { if (sensor == nullptr) { @@ -39,9 +42,11 @@ visus::power_overwhelming::measurement::measurement(const char_type *sensor, /* * visus::power_overwhelming::measurement::measurement */ -visus::power_overwhelming::measurement::measurement(const char_type *sensor, - const timestamp_type timestamp, const value_type voltage, - const value_type current) +visus::power_overwhelming::measurement::measurement( + _In_z_ const char_type *sensor, + _In_ const timestamp_type timestamp, + _In_ const value_type voltage, + _In_ const value_type current) :_current(current), _power(invalid_value), _sensor(nullptr), _timestamp(timestamp), _voltage(voltage) { if (sensor == nullptr) { @@ -66,8 +71,10 @@ visus::power_overwhelming::measurement::measurement(const char_type *sensor, /* * visus::power_overwhelming::measurement::measurement */ -visus::power_overwhelming::measurement::measurement(const char_type *sensor, - const timestamp_type timestamp, const value_type power) +visus::power_overwhelming::measurement::measurement( + _In_z_ const char_type *sensor, + _In_ const timestamp_type timestamp, + _In_z_ const value_type power) :_current(invalid_value), _power(power), _sensor(nullptr), _timestamp(timestamp), _voltage(invalid_value) { if (sensor == nullptr) { From 3aa957869852a88c8ab184490eb34587d9a9eb82 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 12:19:16 +0100 Subject: [PATCH 03/24] Annotated sensor. --- power_overwhelming/include/power_overwhelming/sensor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/power_overwhelming/include/power_overwhelming/sensor.h b/power_overwhelming/include/power_overwhelming/sensor.h index ce9ea1a7..95771d7c 100644 --- a/power_overwhelming/include/power_overwhelming/sensor.h +++ b/power_overwhelming/include/power_overwhelming/sensor.h @@ -47,7 +47,7 @@ namespace power_overwhelming { /// /// The implementation-defined, human-readable name of the /// sensor. - virtual const wchar_t *name(void) const noexcept = 0; + virtual _Ret_z_ const wchar_t *name(void) const noexcept = 0; /// /// Sample the sensor using a timestamp with the specified resolution. From e988f6ed6d701e0197694ff371dc5b530fbbbb1a Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 12:28:08 +0100 Subject: [PATCH 04/24] ADL sensor annotation. --- .../include/power_overwhelming/adl_sensor.h | 35 ++++++++++--------- .../include/power_overwhelming/sensor.h | 5 +-- power_overwhelming/src/adl_sensor.cpp | 29 ++++++++------- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/adl_sensor.h b/power_overwhelming/include/power_overwhelming/adl_sensor.h index 1879cb45..f4318f28 100644 --- a/power_overwhelming/include/power_overwhelming/adl_sensor.h +++ b/power_overwhelming/include/power_overwhelming/adl_sensor.h @@ -37,8 +37,9 @@ namespace power_overwhelming { /// of the size of the output array. If this number is larger than /// , not all sensors have been returned. /// - static std::size_t for_all(adl_sensor *outSensors, - const std::size_t cntSensors); + static std::size_t for_all( + _Out_writes_all_(cntSensors) adl_sensor *outSensors, + _In_ const std::size_t cntSensors); /// /// Create a new instance for the specified adapter index. @@ -50,8 +51,8 @@ namespace power_overwhelming { /// /// If the specified device was not /// found, or another error occurred in ADL. - static adl_sensor from_index(const int index, - const adl_sensor_source source); + static adl_sensor from_index(_In_ const int index, + _In_ const adl_sensor_source source); /// /// Create a new instance for the unique device ID. @@ -66,8 +67,8 @@ namespace power_overwhelming { /// /// If the specified device was not /// found, or another error occurred in ADL. - static adl_sensor from_udid(const char *udid, - const adl_sensor_source source); + static adl_sensor from_udid(_In_z_ const char *udid, + _In_ const adl_sensor_source source); /// /// Initialises a new instance. @@ -85,7 +86,7 @@ namespace power_overwhelming { /// /// /// - inline adl_sensor(adl_sensor&& rhs) noexcept : _impl(rhs._impl) { + inline adl_sensor(_In_ adl_sensor&& rhs) noexcept : _impl(rhs._impl) { rhs._impl = nullptr; } @@ -98,7 +99,8 @@ namespace power_overwhelming { /// The status block, which must have been allocated /// using new. The object takes ownership of the status block. /// - inline explicit adl_sensor(detail::adl_sensor_impl *&& impl) noexcept + inline explicit adl_sensor( + _In_ detail::adl_sensor_impl *&& impl) noexcept : _impl(impl) { impl = nullptr; } @@ -113,7 +115,7 @@ namespace power_overwhelming { /// /// The implementation-defined, human-readable name of the /// sensor. - virtual const wchar_t *name(void) const noexcept override; + virtual _Ret_opt_z_ const wchar_t *name(void) const noexcept override; /// /// Sample the sensor. @@ -127,7 +129,7 @@ namespace power_overwhelming { /// If the sensor could not be sampled. /// virtual measurement sample( - const timestamp_resolution resolution) const override; + _In_ const timestamp_resolution resolution) const override; /// /// Asynchronously sample the sensor every @@ -156,9 +158,10 @@ namespace power_overwhelming { /// /// If the sensor could not be /// sampled. - void sample(const measurement_callback on_measurement, - const microseconds_type sampling_period = default_sampling_period, - void *context = nullptr); + void sample(_In_ const measurement_callback on_measurement, + _In_ const microseconds_type sampling_period + = default_sampling_period, + _In_opt_ void *context = nullptr); using sensor::sample; @@ -181,7 +184,7 @@ namespace power_overwhelming { /// the sensor is already asynchronously collecting data. /// If the source could not be /// started. - void start(const microseconds_type sampling_period); + void start(_In_ const microseconds_type sampling_period); /// /// Stops the sensor from asynchronously collecting data. @@ -207,14 +210,14 @@ namespace power_overwhelming { /// /// /// - const char *udid(void) const noexcept; + _Ret_opt_z_ const char *udid(void) const noexcept; /// /// Move assignment. /// /// The right-hand side operand /// *this - adl_sensor& operator =(adl_sensor&& rhs) noexcept; + adl_sensor& operator =(_In_ adl_sensor&& rhs) noexcept; /// /// Determines whether the sensor is valid. diff --git a/power_overwhelming/include/power_overwhelming/sensor.h b/power_overwhelming/include/power_overwhelming/sensor.h index 95771d7c..1953547d 100644 --- a/power_overwhelming/include/power_overwhelming/sensor.h +++ b/power_overwhelming/include/power_overwhelming/sensor.h @@ -46,8 +46,9 @@ namespace power_overwhelming { /// are supported on a single machine. /// /// The implementation-defined, human-readable name of the - /// sensor. - virtual _Ret_z_ const wchar_t *name(void) const noexcept = 0; + /// sensor. This value may be nullptr if the sensor has been + /// disposed. + virtual _Ret_opt_z_ const wchar_t *name(void) const noexcept = 0; /// /// Sample the sensor using a timestamp with the specified resolution. diff --git a/power_overwhelming/src/adl_sensor.cpp b/power_overwhelming/src/adl_sensor.cpp index 1ab88069..7f2a4d69 100644 --- a/power_overwhelming/src/adl_sensor.cpp +++ b/power_overwhelming/src/adl_sensor.cpp @@ -170,7 +170,8 @@ namespace detail { * visus::power_overwhelming::adl_sensor::for_all */ std::size_t visus::power_overwhelming::adl_sensor::for_all( - adl_sensor *outSensors, const std::size_t cntSensors) { + _Out_writes_all_(cntSensors) adl_sensor *outSensors, + _In_ const std::size_t cntSensors) { try { int cnt = 0; std::vector retval; @@ -224,8 +225,8 @@ std::size_t visus::power_overwhelming::adl_sensor::for_all( * visus::power_overwhelming::adl_sensor::from_index */ visus::power_overwhelming::adl_sensor -visus::power_overwhelming::adl_sensor::from_index(const int index, - const adl_sensor_source source) { +visus::power_overwhelming::adl_sensor::from_index(_In_ const int index, + _In_ const adl_sensor_source source) { adl_sensor retval; auto status = detail::amd_display_library::instance() @@ -244,8 +245,8 @@ visus::power_overwhelming::adl_sensor::from_index(const int index, * visus::power_overwhelming::adl_sensor::from_udid */ visus::power_overwhelming::adl_sensor -visus::power_overwhelming::adl_sensor::from_udid(const char *udid, - const adl_sensor_source source) { +visus::power_overwhelming::adl_sensor::from_udid(_In_z_ const char *udid, + _In_ const adl_sensor_source source) { if (udid == nullptr) { throw std::invalid_argument("The unique device identifier cannot be " "null."); @@ -282,7 +283,7 @@ visus::power_overwhelming::adl_sensor::~adl_sensor(void) { /* * visus::power_overwhelming::adl_sensor::name */ -const wchar_t *visus::power_overwhelming::adl_sensor::name( +_Ret_opt_z_ const wchar_t *visus::power_overwhelming::adl_sensor::name( void) const noexcept { if (this->_impl == nullptr) { return nullptr; @@ -297,7 +298,7 @@ const wchar_t *visus::power_overwhelming::adl_sensor::name( */ visus::power_overwhelming::measurement visus::power_overwhelming::adl_sensor::sample( - const timestamp_resolution resolution) const { + _In_ const timestamp_resolution resolution) const { this->check_not_disposed(); const auto is_running = this->_impl->running(); @@ -322,9 +323,9 @@ visus::power_overwhelming::adl_sensor::sample( * visus::power_overwhelming::adl_sensor::sample */ void visus::power_overwhelming::adl_sensor::sample( - const measurement_callback on_measurement, - const microseconds_type sampling_period, - void *context) { + _In_ const measurement_callback on_measurement, + _In_ const microseconds_type sampling_period, + _In_opt_ void *context) { using std::chrono::duration_cast; typedef decltype(detail::adl_sensor_impl::sampler)::interval_type interval_type; @@ -361,7 +362,7 @@ void visus::power_overwhelming::adl_sensor::sample( * visus::power_overwhelming::adl_sensor::start */ void visus::power_overwhelming::adl_sensor::start( - const microseconds_type sampling_period) { + _In_ const microseconds_type sampling_period) { using std::chrono::duration_cast; typedef decltype(detail::adl_sensor_impl::sampler)::interval_type interval_type; @@ -397,7 +398,8 @@ visus::power_overwhelming::adl_sensor::source(void) const { /* * visus::power_overwhelming::adl_sensor::udid */ -const char *visus::power_overwhelming::adl_sensor::udid(void) const noexcept { +_Ret_opt_z_ const char *visus::power_overwhelming::adl_sensor::udid( + void) const noexcept { if (this->_impl == nullptr) { return nullptr; } else { @@ -410,7 +412,8 @@ const char *visus::power_overwhelming::adl_sensor::udid(void) const noexcept { * visus::power_overwhelming::adl_sensor::operator = */ visus::power_overwhelming::adl_sensor& -visus::power_overwhelming::adl_sensor::operator =(adl_sensor&& rhs) noexcept { +visus::power_overwhelming::adl_sensor::operator =( + _In_ adl_sensor&& rhs) noexcept { if (this != std::addressof(rhs)) { this->_impl = rhs._impl; rhs._impl = nullptr; From c0bc975c56edda0fcd98b913e6ee4b82174ebe60 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 14:05:53 +0100 Subject: [PATCH 05/24] Annotations for collector. --- .../include/power_overwhelming/collector.h | 36 ++++++++++--------- .../include/power_overwhelming/collector.inl | 8 +++-- .../power_overwhelming_api.h | 4 +++ power_overwhelming/src/collector.cpp | 25 +++++++------ 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/collector.h b/power_overwhelming/include/power_overwhelming/collector.h index 47588c8a..b1c18292 100644 --- a/power_overwhelming/include/power_overwhelming/collector.h +++ b/power_overwhelming/include/power_overwhelming/collector.h @@ -37,7 +37,7 @@ namespace power_overwhelming { /// The general settings for the collector, /// including the sampling interval. /// A collector for all available sensors. - static collector for_all(const collector_settings& settings); + static collector for_all(_In_ const collector_settings& settings); /// /// Creates a collector for all sensors that could be found and @@ -50,8 +50,8 @@ namespace power_overwhelming { /// A collector for all available sensors. /// If /// is nullptr. - inline static collector for_all(const wchar_t *output_path, - const sensor::microseconds_type sampling_interval + inline static collector for_all(_In_z_ const wchar_t *output_path, + _In_ const sensor::microseconds_type sampling_interval = collector_settings::default_sampling_interval) { return for_all(collector_settings().output_path(output_path) .sampling_interval(sampling_interval)); @@ -71,7 +71,7 @@ namespace power_overwhelming { /// The path to the JSON configuration file. /// A new collector configured with the sensors in the /// specified file. - static collector from_json(const wchar_t *path); + static collector from_json(_In_z_ const wchar_t *path); /// /// Initialise a new instance from the given lists of sensors. @@ -84,8 +84,9 @@ namespace power_overwhelming { /// The lists of sensors. /// template - static collector from_sensor_lists(const collector_settings& settings, - TSensorLists&&... sensors); + static collector from_sensor_lists( + _In_ const collector_settings& settings, + _In_ TSensorLists&&... sensors); /// /// Initialise a new instance from the given compile-time list of @@ -100,8 +101,8 @@ namespace power_overwhelming { /// disposed by moving them once the method returns. /// A new collector using the given sensors. template - static collector from_sensors(const collector_settings& settings, - TSensors&&... sensors); + static collector from_sensors(_In_ const collector_settings& settings, + _In_ TSensors&&... sensors); /// /// Creates a configuration file for all sensors currently attached to @@ -118,7 +119,7 @@ namespace power_overwhelming { /// /// The path where the configuration file should be /// stored. - static void make_configuration_template(const wchar_t *path); + static void make_configuration_template(_In_z_ const wchar_t *path); /// /// Initialise a new instance. @@ -135,7 +136,7 @@ namespace power_overwhelming { /// /// /// - inline collector(collector&& rhs) noexcept : _impl(rhs._impl) { + inline collector(_In_ collector&& rhs) noexcept : _impl(rhs._impl) { rhs._impl = nullptr; } @@ -149,7 +150,7 @@ namespace power_overwhelming { /// output. /// /// - void marker(const wchar_t *marker); + void marker(_In_opt_z_ const wchar_t *marker); /// /// Answer the number of sensors in the collector. @@ -177,7 +178,7 @@ namespace power_overwhelming { /// /// The right-hand side operand /// *this - collector& operator =(collector&& rhs) noexcept; + collector& operator =(_In_ collector&& rhs) noexcept; /// /// Determines whether the object is valid. @@ -200,7 +201,7 @@ namespace power_overwhelming { /// template static std::vector> move_to_heap( - TSensorList&& sensors); + _In_ TSensorList&& sensors); /// /// Creates a new collector that has no sensors, but reserved space for @@ -209,14 +210,15 @@ namespace power_overwhelming { /// /// /// A new collector without sensors. - static collector prepare(const collector_settings& settings, - const std::size_t capacity); + static collector prepare(_In_ const collector_settings& settings, + _In_ const std::size_t capacity); /// /// Initialise a new instance. /// /// - inline collector(detail::collector_impl *impl) : _impl(impl) { } + inline collector(_In_opt_ detail::collector_impl *impl) + : _impl(impl) { } /// /// Adds a new sensor to the collector. @@ -229,7 +231,7 @@ namespace power_overwhelming { /// The sensor to be added. The object takes /// ownership of the object designated by this pointer. The object /// must have been allocated using C++ new. - void add(sensor *sensor); + void add(_In_ sensor *sensor); detail::collector_impl *_impl; diff --git a/power_overwhelming/include/power_overwhelming/collector.inl b/power_overwhelming/include/power_overwhelming/collector.inl index 2d42c3a5..45320190 100644 --- a/power_overwhelming/include/power_overwhelming/collector.inl +++ b/power_overwhelming/include/power_overwhelming/collector.inl @@ -10,7 +10,8 @@ template visus::power_overwhelming::collector visus::power_overwhelming::collector::from_sensor_lists( - const collector_settings& settings, TSensorLists&&... sensors) { + _In_ const collector_settings& settings, + _In_ TSensorLists&&... sensors) { std::array>, sizeof...(sensors)> instances = { move_to_heap(sensors)... }; typedef typename decltype(instances)::value_type sensor_type; @@ -39,7 +40,8 @@ visus::power_overwhelming::collector::from_sensor_lists( template visus::power_overwhelming::collector visus::power_overwhelming::collector::from_sensors( - const collector_settings& settings, TSensors&&... sensors) { + _In_ const collector_settings& settings, + _In_ TSensors&&... sensors) { std::array, sizeof...(sensors)> instances = { std::unique_ptr(new typename std::decay::type( std::move(sensors)))... @@ -64,7 +66,7 @@ visus::power_overwhelming::collector::from_sensors( */ template std::vector> -visus::power_overwhelming::collector::move_to_heap(TSensorList&& sensors) { +visus::power_overwhelming::collector::move_to_heap(_In_ TSensorList&& sensors) { typedef typename std::decay::type sensor_type; decltype(move_to_heap(sensors)) retval; diff --git a/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h b/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h index 4dd33fc9..2289cd01 100644 --- a/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h +++ b/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h @@ -19,5 +19,9 @@ #endif /* defined(WIN32) */ +#if defined(_WIN32) +#include +#else /* defined(_WIN32) */ // Empty SAL annotations for rancid platforms. #include "salieri.h" +#endif /* defined(_WIN32) */ diff --git a/power_overwhelming/src/collector.cpp b/power_overwhelming/src/collector.cpp index 8b6a5540..4d630e19 100644 --- a/power_overwhelming/src/collector.cpp +++ b/power_overwhelming/src/collector.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2022 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2022 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/collector.h" @@ -42,7 +42,7 @@ namespace detail { retval[field_computer_name] = computer_name(); retval[field_output] = "output.csv"; - retval[field_sampling] = 5000; // 5000 µs == 5 ms + retval[field_sampling] = 5000; // 5000 µs == 5 ms retval[field_require_marker] = true; retval[field_sensors] = get_all_sensor_descs(); @@ -79,7 +79,7 @@ namespace detail { */ visus::power_overwhelming::collector visus::power_overwhelming::collector::for_all( - const collector_settings& settings) { + _In_ const collector_settings& settings) { auto retval = collector(new detail::collector_impl()); retval._impl->apply(settings); retval._impl->sensors = detail::get_all_sensors(); @@ -103,7 +103,7 @@ visus::power_overwhelming::collector::from_defaults(void) { * visus::power_overwhelming::collector::from_json */ visus::power_overwhelming::collector -visus::power_overwhelming::collector::from_json(const wchar_t *path) { +visus::power_overwhelming::collector::from_json(_In_z_ const wchar_t *path) { if (path == nullptr) { throw std::invalid_argument("The path to the configuration file must " "not be null."); @@ -120,7 +120,7 @@ visus::power_overwhelming::collector::from_json(const wchar_t *path) { * visus::power_overwhelming::collector::make_configuration_template */ void visus::power_overwhelming::collector::make_configuration_template( - const wchar_t *path) { + _In_z_ const wchar_t *path) { detail::write_json(path, detail::make_json_template()); } @@ -137,7 +137,8 @@ visus::power_overwhelming::collector::~collector(void) { /* * visus::power_overwhelming::collector::marker */ -void visus::power_overwhelming::collector::marker(const wchar_t *marker) { +void visus::power_overwhelming::collector::marker( + _In_opt_z_ const wchar_t *marker) { if (this->_impl == nullptr) { throw std::runtime_error("The collector has been moved to another " "instance wherefore no marker can be set."); @@ -182,7 +183,8 @@ void visus::power_overwhelming::collector::stop(void) { * visus::power_overwhelming::collector::operator = */ visus::power_overwhelming::collector& -visus::power_overwhelming::collector::operator =(collector&& rhs) noexcept { +visus::power_overwhelming::collector::operator =( + _In_ collector&& rhs) noexcept { if (this != std::addressof(rhs)) { this->_impl = rhs._impl; rhs._impl = nullptr; @@ -205,7 +207,8 @@ visus::power_overwhelming::collector::operator bool(void) const noexcept { */ visus::power_overwhelming::collector visus::power_overwhelming::collector::prepare( - const collector_settings& settings, const std::size_t capacity) { + _In_ const collector_settings& settings, + _In_ const std::size_t capacity) { auto retval = collector(new detail::collector_impl()); retval._impl->sensors.reserve(capacity); retval._impl->apply(settings); @@ -216,7 +219,7 @@ visus::power_overwhelming::collector::prepare( /* * visus::power_overwhelming::collector::add */ -void visus::power_overwhelming::collector::add(sensor *sensor) { +void visus::power_overwhelming::collector::add(_In_ sensor *sensor) { assert(*this); if (sensor == nullptr) { From c774317415708ba75a8fe952735d538a143fd8c1 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 14:22:23 +0100 Subject: [PATCH 06/24] Change return annotations. Annotated convert_string. --- .../include/power_overwhelming/adl_sensor.h | 21 +++++++++++++++++-- .../power_overwhelming/convert_string.h | 16 ++++++++------ .../power_overwhelming/convert_string.inl | 4 ++-- .../include/power_overwhelming/sensor.h | 2 +- power_overwhelming/src/adl_sensor.cpp | 16 ++++++++++++-- power_overwhelming/src/convert_string.cpp | 12 +++++++---- 6 files changed, 54 insertions(+), 17 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/adl_sensor.h b/power_overwhelming/include/power_overwhelming/adl_sensor.h index f4318f28..1498d28d 100644 --- a/power_overwhelming/include/power_overwhelming/adl_sensor.h +++ b/power_overwhelming/include/power_overwhelming/adl_sensor.h @@ -70,6 +70,22 @@ namespace power_overwhelming { static adl_sensor from_udid(_In_z_ const char *udid, _In_ const adl_sensor_source source); + /// + /// Create a new instance for the unique device ID. + /// + /// The unique device ID to create the sensor for. + /// + /// The sensor source to retrieve. If the source + /// is not supported, the method will fail. + /// + /// If + /// is nullptr or if it did not match exactly one device. + /// + /// If the specified device was not + /// found, or another error occurred in ADL. + static adl_sensor from_udid(_In_z_ const wchar_t *udid, + _In_ const adl_sensor_source source); + /// /// Initialises a new instance. /// @@ -115,7 +131,8 @@ namespace power_overwhelming { /// /// The implementation-defined, human-readable name of the /// sensor. - virtual _Ret_opt_z_ const wchar_t *name(void) const noexcept override; + virtual _Ret_maybenull_z_ const wchar_t *name( + void) const noexcept override; /// /// Sample the sensor. @@ -210,7 +227,7 @@ namespace power_overwhelming { /// /// /// - _Ret_opt_z_ const char *udid(void) const noexcept; + _Ret_maybenull_z_ const char *udid(void) const noexcept; /// /// Move assignment. diff --git a/power_overwhelming/include/power_overwhelming/convert_string.h b/power_overwhelming/include/power_overwhelming/convert_string.h index 81484e93..6deaf46b 100644 --- a/power_overwhelming/include/power_overwhelming/convert_string.h +++ b/power_overwhelming/include/power_overwhelming/convert_string.h @@ -17,12 +17,16 @@ namespace power_overwhelming { namespace detail { extern std::size_t POWER_OVERWHELMING_API convert_string( - char *output, const std::size_t cnt_output, - const wchar_t *input, const std::size_t cnt_input); + _Out_writes_z_(cnt_coutput) char *output, + _In_ const std::size_t cnt_output, + _In_z_ const wchar_t *input, + _In_ const std::size_t cnt_input); extern std::size_t POWER_OVERWHELMING_API convert_string( - wchar_t *output, const std::size_t cnt_output, - const char *input, const std::size_t cnt_input); + _Out_writes_z_(cnt_coutput) wchar_t *output, + _In_ const std::size_t cnt_output, + _In_z_ const char *input, + _In_ const std::size_t cnt_input); } /// @@ -39,7 +43,7 @@ namespace detail { template typename std::enable_if::value, std::basic_string>::type - convert_string(const TInput *str); + convert_string(_In_opt_z_ const TInput *str); /// /// Converts a string to the given character set. @@ -55,7 +59,7 @@ namespace detail { template typename std::enable_if::value, std::basic_string>::type - convert_string(const TInput *str); + convert_string(_In_opt_z_ const TInput *str); /// /// Converts a string to the given character set. diff --git a/power_overwhelming/include/power_overwhelming/convert_string.inl b/power_overwhelming/include/power_overwhelming/convert_string.inl index 9619a1c4..c30ae2e2 100644 --- a/power_overwhelming/include/power_overwhelming/convert_string.inl +++ b/power_overwhelming/include/power_overwhelming/convert_string.inl @@ -10,7 +10,7 @@ template typename std::enable_if::value, std::basic_string>::type -visus::power_overwhelming::convert_string(const TInput *str) { +visus::power_overwhelming::convert_string(_In_opt_z_ const TInput *str) { return (str != nullptr) ? str : std::basic_string(); } @@ -21,7 +21,7 @@ visus::power_overwhelming::convert_string(const TInput *str) { template typename std::enable_if::value, std::basic_string>::type -visus::power_overwhelming::convert_string(const TInput *str) { +visus::power_overwhelming::convert_string(_In_opt_z_ const TInput *str) { std::vector retval; if (str != nullptr) { diff --git a/power_overwhelming/include/power_overwhelming/sensor.h b/power_overwhelming/include/power_overwhelming/sensor.h index 1953547d..94bfc6d7 100644 --- a/power_overwhelming/include/power_overwhelming/sensor.h +++ b/power_overwhelming/include/power_overwhelming/sensor.h @@ -48,7 +48,7 @@ namespace power_overwhelming { /// The implementation-defined, human-readable name of the /// sensor. This value may be nullptr if the sensor has been /// disposed. - virtual _Ret_opt_z_ const wchar_t *name(void) const noexcept = 0; + virtual _Ret_maybenull_z_ const wchar_t *name(void) const noexcept = 0; /// /// Sample the sensor using a timestamp with the specified resolution. diff --git a/power_overwhelming/src/adl_sensor.cpp b/power_overwhelming/src/adl_sensor.cpp index 7f2a4d69..23116a99 100644 --- a/power_overwhelming/src/adl_sensor.cpp +++ b/power_overwhelming/src/adl_sensor.cpp @@ -10,6 +10,7 @@ #include #include "power_overwhelming/adl_sensor_source.h" +#include "power_overwhelming/convert_string.h" #include "adl_exception.h" #include "adl_scope.h" @@ -265,6 +266,17 @@ visus::power_overwhelming::adl_sensor::from_udid(_In_z_ const char *udid, } +/* + * visus::power_overwhelming::adl_sensor::from_udid + */ +visus::power_overwhelming::adl_sensor +visus::power_overwhelming::adl_sensor::from_udid(_In_z_ const wchar_t *udid, + _In_ const adl_sensor_source source) { + auto u = convert_string(udid); + return from_udid(u.c_str(), source); +} + + /* * visus::power_overwhelming::adl_sensor::adl_sensor */ @@ -283,7 +295,7 @@ visus::power_overwhelming::adl_sensor::~adl_sensor(void) { /* * visus::power_overwhelming::adl_sensor::name */ -_Ret_opt_z_ const wchar_t *visus::power_overwhelming::adl_sensor::name( +_Ret_maybenull_z_ const wchar_t *visus::power_overwhelming::adl_sensor::name( void) const noexcept { if (this->_impl == nullptr) { return nullptr; @@ -398,7 +410,7 @@ visus::power_overwhelming::adl_sensor::source(void) const { /* * visus::power_overwhelming::adl_sensor::udid */ -_Ret_opt_z_ const char *visus::power_overwhelming::adl_sensor::udid( +_Ret_maybenull_z_ const char *visus::power_overwhelming::adl_sensor::udid( void) const noexcept { if (this->_impl == nullptr) { return nullptr; diff --git a/power_overwhelming/src/convert_string.cpp b/power_overwhelming/src/convert_string.cpp index 2e2b6b4d..c77044d7 100644 --- a/power_overwhelming/src/convert_string.cpp +++ b/power_overwhelming/src/convert_string.cpp @@ -17,8 +17,10 @@ * visus::power_overwhelming::detail::convert_string */ std::size_t visus::power_overwhelming::detail::convert_string( - char *output, const std::size_t cnt_output, - const wchar_t *input, const std::size_t cnt_input) { + _Out_writes_z_(cnt_coutput) char *output, + _In_ const std::size_t cnt_output, + _In_z_ const wchar_t *input, + _In_ const std::size_t cnt_input) { auto state = std::mbstate_t(); #if defined(_WIN32) @@ -53,8 +55,10 @@ std::size_t visus::power_overwhelming::detail::convert_string( * visus::power_overwhelming::detail::convert_string */ std::size_t visus::power_overwhelming::detail::convert_string( - wchar_t *output, const std::size_t cnt_output, - const char *input, const std::size_t cnt_input) { + _Out_writes_z_(cnt_coutput) wchar_t *output, + _In_ const std::size_t cnt_output, + _In_z_ const char *input, + _In_ const std::size_t cnt_input) { auto state = std::mbstate_t(); #if defined(_WIN32) From da8955f9fe41f7ce45f90ec9f82e67abe3b6a531 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 14:35:06 +0100 Subject: [PATCH 07/24] Fix annotation in adl_sensor. --- power_overwhelming/include/power_overwhelming/adl_sensor.h | 2 +- power_overwhelming/src/adl_sensor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/adl_sensor.h b/power_overwhelming/include/power_overwhelming/adl_sensor.h index 1498d28d..71377d28 100644 --- a/power_overwhelming/include/power_overwhelming/adl_sensor.h +++ b/power_overwhelming/include/power_overwhelming/adl_sensor.h @@ -175,7 +175,7 @@ namespace power_overwhelming { /// /// If the sensor could not be /// sampled. - void sample(_In_ const measurement_callback on_measurement, + void sample(_In_opt_ const measurement_callback on_measurement, _In_ const microseconds_type sampling_period = default_sampling_period, _In_opt_ void *context = nullptr); diff --git a/power_overwhelming/src/adl_sensor.cpp b/power_overwhelming/src/adl_sensor.cpp index 23116a99..0864cf35 100644 --- a/power_overwhelming/src/adl_sensor.cpp +++ b/power_overwhelming/src/adl_sensor.cpp @@ -335,7 +335,7 @@ visus::power_overwhelming::adl_sensor::sample( * visus::power_overwhelming::adl_sensor::sample */ void visus::power_overwhelming::adl_sensor::sample( - _In_ const measurement_callback on_measurement, + _In_opt_ const measurement_callback on_measurement, _In_ const microseconds_type sampling_period, _In_opt_ void *context) { using std::chrono::duration_cast; From 9dde2a5c72b2c555c700ae683c128a87f789c082 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 14:47:45 +0100 Subject: [PATCH 08/24] Fix convert_string annotation. --- .../include/power_overwhelming/convert_string.h | 4 ++-- power_overwhelming/src/convert_string.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/convert_string.h b/power_overwhelming/include/power_overwhelming/convert_string.h index 6deaf46b..3ec6de29 100644 --- a/power_overwhelming/include/power_overwhelming/convert_string.h +++ b/power_overwhelming/include/power_overwhelming/convert_string.h @@ -17,13 +17,13 @@ namespace power_overwhelming { namespace detail { extern std::size_t POWER_OVERWHELMING_API convert_string( - _Out_writes_z_(cnt_coutput) char *output, + _Out_writes_opt_z_(cnt_coutput) char *output, _In_ const std::size_t cnt_output, _In_z_ const wchar_t *input, _In_ const std::size_t cnt_input); extern std::size_t POWER_OVERWHELMING_API convert_string( - _Out_writes_z_(cnt_coutput) wchar_t *output, + _Out_writes_opt_z_(cnt_coutput) wchar_t *output, _In_ const std::size_t cnt_output, _In_z_ const char *input, _In_ const std::size_t cnt_input); diff --git a/power_overwhelming/src/convert_string.cpp b/power_overwhelming/src/convert_string.cpp index c77044d7..e52a6f07 100644 --- a/power_overwhelming/src/convert_string.cpp +++ b/power_overwhelming/src/convert_string.cpp @@ -17,7 +17,7 @@ * visus::power_overwhelming::detail::convert_string */ std::size_t visus::power_overwhelming::detail::convert_string( - _Out_writes_z_(cnt_coutput) char *output, + _Out_writes_opt_z_(cnt_coutput) char *output, _In_ const std::size_t cnt_output, _In_z_ const wchar_t *input, _In_ const std::size_t cnt_input) { @@ -55,7 +55,7 @@ std::size_t visus::power_overwhelming::detail::convert_string( * visus::power_overwhelming::detail::convert_string */ std::size_t visus::power_overwhelming::detail::convert_string( - _Out_writes_z_(cnt_coutput) wchar_t *output, + _Out_writes_opt_z_(cnt_coutput) wchar_t *output, _In_ const std::size_t cnt_output, _In_z_ const char *input, _In_ const std::size_t cnt_input) { From f66e5015d88b56841840ffc9ace8f82c15c50c08 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 19:08:55 +0100 Subject: [PATCH 09/24] Fix convert_string annotations. Added annotations to collector_settings. --- .../power_overwhelming/Output-Build.txt | 8 +++++ .../power_overwhelming/collector_settings.h | 10 +++--- .../power_overwhelming/computer_name.h | 10 +++--- .../power_overwhelming/convert_string.h | 10 +++--- .../include/power_overwhelming/csv_iomanip.h | 33 ++++++++++--------- power_overwhelming/src/collector_settings.cpp | 14 ++++---- power_overwhelming/src/computer_name.cpp | 10 +++--- power_overwhelming/src/convert_string.cpp | 8 ++--- power_overwhelming/src/hmc8015_sensor.cpp | 1 + power_overwhelming/src/measurement.cpp | 2 +- 10 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 power_overwhelming/include/power_overwhelming/Output-Build.txt diff --git a/power_overwhelming/include/power_overwhelming/Output-Build.txt b/power_overwhelming/include/power_overwhelming/Output-Build.txt new file mode 100644 index 00000000..6e6fefe1 --- /dev/null +++ b/power_overwhelming/include/power_overwhelming/Output-Build.txt @@ -0,0 +1,8 @@ +Build started... +1>------ Build started: Project: power_overwhelming, Configuration: Debug x64 ------ +1>collector.cpp +1>computer_name.cpp +1>Generating Code... +1>power_overwhelming.vcxproj -> C:\Users\mueller\source\repos\power-overwhelming\_build64\power_overwhelming\Debug\power_overwhelming.dll +2>------ Build started: Project: test, Configuration: Debug x64 ------ +2>adl_test.cpp diff --git a/power_overwhelming/include/power_overwhelming/collector_settings.h b/power_overwhelming/include/power_overwhelming/collector_settings.h index 272dd701..cf962449 100644 --- a/power_overwhelming/include/power_overwhelming/collector_settings.h +++ b/power_overwhelming/include/power_overwhelming/collector_settings.h @@ -48,7 +48,7 @@ namespace power_overwhelming { /// Clone . /// /// The object to be cloned. - collector_settings(const collector_settings& rhs); + collector_settings(_In_ const collector_settings& rhs); /// /// Finalises the instance. @@ -60,7 +60,7 @@ namespace power_overwhelming { /// output to. /// /// The path to the output file. - inline const wchar_t *output_path(void) const noexcept { + inline _Ret_z_ const wchar_t *output_path(void) const noexcept { return this->_output_path; } @@ -72,7 +72,7 @@ namespace power_overwhelming { /// *this. /// If /// is nullptr. - collector_settings& output_path(const wchar_t *path); + collector_settings& output_path(_In_z_ const wchar_t *path); /// /// Gets the time interval in which the collector should sample the @@ -89,14 +89,14 @@ namespace power_overwhelming { /// The sampling interval. /// *this. collector_settings& sampling_interval( - const sampling_interval_type interval); + _In_ const sampling_interval_type interval); /// /// Assignment. /// /// The right hand side operand. /// *this. - collector_settings& operator =(const collector_settings& rhs); + collector_settings& operator =(_In_ const collector_settings& rhs); private: diff --git a/power_overwhelming/include/power_overwhelming/computer_name.h b/power_overwhelming/include/power_overwhelming/computer_name.h index 5632ba34..6aa18bf0 100644 --- a/power_overwhelming/include/power_overwhelming/computer_name.h +++ b/power_overwhelming/include/power_overwhelming/computer_name.h @@ -32,8 +32,9 @@ namespace power_overwhelming { /// store the computer name, including the terminating null. /// In case the operation failed. /// - std::size_t POWER_OVERWHELMING_API computer_name(char *dst, - const std::size_t cnt); + std::size_t POWER_OVERWHELMING_API computer_name( + _Out_writes_opt_z_(cnt) char *dst, + _In_ const std::size_t cnt); /// /// Answer the name of the computer the calling code is running on. @@ -52,8 +53,9 @@ namespace power_overwhelming { /// store the computer name, including the terminating null. /// In case the operation failed. /// - std::size_t POWER_OVERWHELMING_API computer_name(wchar_t *dst, - const std::size_t cnt); + std::size_t POWER_OVERWHELMING_API computer_name( + _Out_writes_opt_z_(cnt) wchar_t *dst, + _In_ const std::size_t cnt); /// /// Answer the name of the computer the calling code is running on. diff --git a/power_overwhelming/include/power_overwhelming/convert_string.h b/power_overwhelming/include/power_overwhelming/convert_string.h index 3ec6de29..b81bfa23 100644 --- a/power_overwhelming/include/power_overwhelming/convert_string.h +++ b/power_overwhelming/include/power_overwhelming/convert_string.h @@ -17,15 +17,15 @@ namespace power_overwhelming { namespace detail { extern std::size_t POWER_OVERWHELMING_API convert_string( - _Out_writes_opt_z_(cnt_coutput) char *output, + _Out_writes_opt_z_(cnt_output) char *output, _In_ const std::size_t cnt_output, - _In_z_ const wchar_t *input, + _In_reads_or_z_(cnt_input) const wchar_t *input, _In_ const std::size_t cnt_input); extern std::size_t POWER_OVERWHELMING_API convert_string( - _Out_writes_opt_z_(cnt_coutput) wchar_t *output, + _Out_writes_opt_z_(cnt_output) wchar_t *output, _In_ const std::size_t cnt_output, - _In_z_ const char *input, + _In_reads_or_z_(cnt_input) const char *input, _In_ const std::size_t cnt_input); } @@ -72,7 +72,7 @@ namespace detail { /// template inline std::basic_string convert_string( - const std::basic_string& str) { + _In_ const std::basic_string& str) { return convert_string(str.c_str()); } diff --git a/power_overwhelming/include/power_overwhelming/csv_iomanip.h b/power_overwhelming/include/power_overwhelming/csv_iomanip.h index 16974b94..1cbe3130 100644 --- a/power_overwhelming/include/power_overwhelming/csv_iomanip.h +++ b/power_overwhelming/include/power_overwhelming/csv_iomanip.h @@ -34,7 +34,7 @@ namespace detail { /// Initialises a new instance. /// /// The character to be embedded in the stream. - inline csv_char_value(const TChar value) : value(value) { } + inline csv_char_value(_In_ const TChar value) : value(value) { } }; /// @@ -47,7 +47,8 @@ namespace detail { /// Initialises a new instance. /// /// The character to be used as delimiter. - inline csv_delimiter(const TChar value) : csv_char_value(value) { } + inline csv_delimiter(_In_ const TChar value) + : csv_char_value(value) { } }; /// @@ -60,7 +61,8 @@ namespace detail { /// Initialises a new instance. /// /// The character to be used as quote. - inline csv_quote(const TChar value) : csv_char_value(value) { } + inline csv_quote(_In_ const TChar value) + : csv_char_value(value) { } }; /// @@ -92,7 +94,7 @@ namespace detail { /// /// The stream to manipulate. /// - inline std::ios_base& csvdata(std::ios_base& stream) { + inline std::ios_base& csvdata(_In_ std::ios_base& stream) { stream.iword(detail::io_index_header()) = static_cast(0); return stream; } @@ -103,7 +105,7 @@ namespace detail { /// /// The stream to manipulate. /// - inline std::ios_base& csvheader(std::ios_base &stream) { + inline std::ios_base& csvheader(_In_ std::ios_base& stream) { stream.iword(detail::io_index_header()) = static_cast(1); return stream; } @@ -118,7 +120,7 @@ namespace detail { /// /// The stream to manipulate. /// - inline std::ios_base& csvnoquote(std::ios_base& stream) { + inline std::ios_base& csvnoquote(_In_ std::ios_base& stream) { stream.iword(detail::io_index_quote()) = static_cast(0); return stream; } @@ -138,7 +140,7 @@ namespace detail { /// template inline std::basic_ostream& csvquote( - std::basic_ostream& stream) { + _In_ std::basic_ostream& stream) { return stream << setcsvquote(POWER_OVERWHELMING_TPL_LITERAL( TChar, '"')); } @@ -156,7 +158,7 @@ namespace detail { /// The stream to retrieve the delimiter for. /// The configured CSV delimiter for the given stream. template inline TChar getcsvdelimiter( - std::basic_ostream& stream) { + _In_ std::basic_ostream& stream) { auto retval = stream.iword(detail::io_index_delimiter()); return (retval > 0) ? static_cast(retval) @@ -174,7 +176,7 @@ namespace detail { /// The configured CSV quote character for the given stream. If /// this value is zero, no quotes will be added. template inline TChar getcsvquote( - std::basic_ostream& stream) { + _In_ std::basic_ostream& stream) { return static_cast(stream.iword(detail::io_index_quote())); } @@ -187,7 +189,8 @@ namespace detail { /// The delimiter to be set. /// A proxy that can be piped into a stream. template - inline detail::csv_delimiter setcsvdelimiter(const TChar delimiter) { + inline detail::csv_delimiter setcsvdelimiter( + _In_ const TChar delimiter) { return detail::csv_delimiter(delimiter); } @@ -200,7 +203,7 @@ namespace detail { /// The quote character to be set. /// A proxy that can be piped into a stream. template - inline detail::csv_quote setcsvquote(const TChar quote) { + inline detail::csv_quote setcsvquote(_In_ const TChar quote) { return detail::csv_quote(quote); } @@ -223,8 +226,8 @@ namespace std { /// template inline std::basic_ostream& operator <<( - std::basic_ostream& lhs, - const visus::power_overwhelming::detail::csv_delimiter rhs) { + _In_ std::basic_ostream& lhs, + _In_ const visus::power_overwhelming::detail::csv_delimiter rhs) { lhs.iword(visus::power_overwhelming::detail::io_index_delimiter()) = rhs.value; return lhs; @@ -244,8 +247,8 @@ namespace std { /// template inline std::basic_ostream& operator <<( - std::basic_ostream& lhs, - const visus::power_overwhelming::detail::csv_quote rhs) { + _In_ std::basic_ostream& lhs, + _In_ const visus::power_overwhelming::detail::csv_quote rhs) { lhs.iword(visus::power_overwhelming::detail::io_index_quote()) = rhs.value; return lhs; } diff --git a/power_overwhelming/src/collector_settings.cpp b/power_overwhelming/src/collector_settings.cpp index c5d1c082..f1010c32 100644 --- a/power_overwhelming/src/collector_settings.cpp +++ b/power_overwhelming/src/collector_settings.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/collector_settings.h" @@ -31,7 +31,7 @@ visus::power_overwhelming::collector_settings::collector_settings(void) * visus::power_overwhelming::collector_settings::collector_settings */ visus::power_overwhelming::collector_settings::collector_settings( - const collector_settings& rhs) : _output_path(nullptr) { + _In_ const collector_settings& rhs) : _output_path(nullptr) { *this = rhs; } @@ -51,7 +51,7 @@ visus::power_overwhelming::collector_settings::~collector_settings(void) { */ visus::power_overwhelming::collector_settings& visus::power_overwhelming::collector_settings::output_path( - const wchar_t *path) { + _In_z_ const wchar_t *path) { if (path == nullptr) { throw std::invalid_argument("The output path must be a valid string."); } @@ -75,7 +75,7 @@ visus::power_overwhelming::collector_settings::output_path( */ visus::power_overwhelming::collector_settings& visus::power_overwhelming::collector_settings::sampling_interval( - const sampling_interval_type interval) { + _In_ const sampling_interval_type interval) { this->_sampling_interval = interval; return *this; } @@ -86,7 +86,7 @@ visus::power_overwhelming::collector_settings::sampling_interval( */ visus::power_overwhelming::collector_settings& visus::power_overwhelming::collector_settings::operator =( - const collector_settings& rhs) { + _In_ const collector_settings& rhs) { if (this != std::addressof(rhs)) { this->output_path(rhs._output_path); this->sampling_interval(rhs._sampling_interval); diff --git a/power_overwhelming/src/computer_name.cpp b/power_overwhelming/src/computer_name.cpp index ba774e50..0903e6c3 100644 --- a/power_overwhelming/src/computer_name.cpp +++ b/power_overwhelming/src/computer_name.cpp @@ -83,8 +83,9 @@ namespace detail { /* * visus::power_overwhelming::computer_name */ -std::size_t visus::power_overwhelming::computer_name(char *dst, - const std::size_t cnt) { +std::size_t visus::power_overwhelming::computer_name( + _Out_writes_opt_z_(cnt) char *dst, + _In_ const std::size_t cnt) { #if defined(_WIN32) return detail::computer_name(dst, cnt); @@ -108,8 +109,9 @@ std::size_t visus::power_overwhelming::computer_name(char *dst, /* * visus::power_overwhelming::computer_name */ -std::size_t visus::power_overwhelming::computer_name(wchar_t *dst, - const std::size_t cnt) { +std::size_t visus::power_overwhelming::computer_name( + _Out_writes_opt_z_(cnt) wchar_t *dst, + _In_ const std::size_t cnt) { #if defined(_WIN32) return detail::computer_name(dst, cnt); diff --git a/power_overwhelming/src/convert_string.cpp b/power_overwhelming/src/convert_string.cpp index e52a6f07..7675d77c 100644 --- a/power_overwhelming/src/convert_string.cpp +++ b/power_overwhelming/src/convert_string.cpp @@ -17,9 +17,9 @@ * visus::power_overwhelming::detail::convert_string */ std::size_t visus::power_overwhelming::detail::convert_string( - _Out_writes_opt_z_(cnt_coutput) char *output, + _Out_writes_opt_z_(cnt_output) char *output, _In_ const std::size_t cnt_output, - _In_z_ const wchar_t *input, + _In_reads_or_z_(cnt_input) const wchar_t *input, _In_ const std::size_t cnt_input) { auto state = std::mbstate_t(); @@ -55,9 +55,9 @@ std::size_t visus::power_overwhelming::detail::convert_string( * visus::power_overwhelming::detail::convert_string */ std::size_t visus::power_overwhelming::detail::convert_string( - _Out_writes_opt_z_(cnt_coutput) wchar_t *output, + _Out_writes_opt_z_(cnt_output) wchar_t *output, _In_ const std::size_t cnt_output, - _In_z_ const char *input, + _In_reads_or_z_(cnt_input) const char *input, _In_ const std::size_t cnt_input) { auto state = std::mbstate_t(); diff --git a/power_overwhelming/src/hmc8015_sensor.cpp b/power_overwhelming/src/hmc8015_sensor.cpp index dd6022c3..b78daec9 100644 --- a/power_overwhelming/src/hmc8015_sensor.cpp +++ b/power_overwhelming/src/hmc8015_sensor.cpp @@ -321,6 +321,7 @@ visus::power_overwhelming::hmc8015_sensor::sample( auto c = static_cast(::atof(tokens[1].c_str())); auto p = static_cast(::atof(tokens[2].c_str())); + assert(this->name() != nullptr); return measurement(this->name(), timestamp, v, c, p); } diff --git a/power_overwhelming/src/measurement.cpp b/power_overwhelming/src/measurement.cpp index d33db869..be624d6a 100644 --- a/power_overwhelming/src/measurement.cpp +++ b/power_overwhelming/src/measurement.cpp @@ -74,7 +74,7 @@ visus::power_overwhelming::measurement::measurement( visus::power_overwhelming::measurement::measurement( _In_z_ const char_type *sensor, _In_ const timestamp_type timestamp, - _In_z_ const value_type power) + _In_ const value_type power) :_current(invalid_value), _power(power), _sensor(nullptr), _timestamp(timestamp), _voltage(invalid_value) { if (sensor == nullptr) { From 827932627c9149f8e5c1da7bd9bee1ad628f9910 Mon Sep 17 00:00:00 2001 From: mueller Date: Sun, 19 Mar 2023 19:09:23 +0100 Subject: [PATCH 10/24] Remove build log --- .../include/power_overwhelming/Output-Build.txt | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 power_overwhelming/include/power_overwhelming/Output-Build.txt diff --git a/power_overwhelming/include/power_overwhelming/Output-Build.txt b/power_overwhelming/include/power_overwhelming/Output-Build.txt deleted file mode 100644 index 6e6fefe1..00000000 --- a/power_overwhelming/include/power_overwhelming/Output-Build.txt +++ /dev/null @@ -1,8 +0,0 @@ -Build started... -1>------ Build started: Project: power_overwhelming, Configuration: Debug x64 ------ -1>collector.cpp -1>computer_name.cpp -1>Generating Code... -1>power_overwhelming.vcxproj -> C:\Users\mueller\source\repos\power-overwhelming\_build64\power_overwhelming\Debug\power_overwhelming.dll -2>------ Build started: Project: test, Configuration: Debug x64 ------ -2>adl_test.cpp From f6a7e54abd1ec554a809db649d7e7a96cdeeb652 Mon Sep 17 00:00:00 2001 From: mueller Date: Mon, 20 Mar 2023 09:49:55 +0100 Subject: [PATCH 11/24] Added SAL annotations in dump_sensors. Added test for convert_string. Fixed issue of convert_string not accepting nullptr as expected. --- .../power_overwhelming/convert_string.inl | 1 + .../include/power_overwhelming/dump_sensors.h | 6 +- power_overwhelming/src/dump_sensors.cpp | 11 +- test/pch.h | 1 + test/sensor_desc_test.cpp | 4 +- test/string_test.cpp | 118 ++++++++++++++++++ 6 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 test/string_test.cpp diff --git a/power_overwhelming/include/power_overwhelming/convert_string.inl b/power_overwhelming/include/power_overwhelming/convert_string.inl index c30ae2e2..05291ab7 100644 --- a/power_overwhelming/include/power_overwhelming/convert_string.inl +++ b/power_overwhelming/include/power_overwhelming/convert_string.inl @@ -32,5 +32,6 @@ visus::power_overwhelming::convert_string(_In_opt_z_ const TInput *str) { detail::convert_string(retval.data(), retval.size(), str, len); } + retval.emplace_back(0); // Make sure that result is always terminated. return retval.data(); } diff --git a/power_overwhelming/include/power_overwhelming/dump_sensors.h b/power_overwhelming/include/power_overwhelming/dump_sensors.h index 8bb84184..675f5134 100644 --- a/power_overwhelming/include/power_overwhelming/dump_sensors.h +++ b/power_overwhelming/include/power_overwhelming/dump_sensors.h @@ -22,7 +22,7 @@ namespace power_overwhelming { /// The number of sensors actually dumped. /// If saving the sensor data /// failed. - std::size_t POWER_OVERWHELMING_API dump_sensors(const char *path); + std::size_t POWER_OVERWHELMING_API dump_sensors(_In_z_ const char *path); /// /// Saves a JSON array of all sensors currently found on the the system. @@ -32,7 +32,7 @@ namespace power_overwhelming { /// The number of sensors actually dumped. /// If saving the sensor data /// failed. - std::size_t POWER_OVERWHELMING_API dump_sensors(const wchar_t *path); + std::size_t POWER_OVERWHELMING_API dump_sensors(_In_z_ const wchar_t *path); /// /// Saves a JSON array of all sensors currently found on the the system. @@ -43,7 +43,7 @@ namespace power_overwhelming { /// If saving the sensor data /// failed. template - inline std::size_t dump_sensors(const std::basic_string& path) { + inline std::size_t dump_sensors(_In_ const std::basic_string& path) { return dump_sensors(path.c_str()); } diff --git a/power_overwhelming/src/dump_sensors.cpp b/power_overwhelming/src/dump_sensors.cpp index e86f5d9a..0bf1e7b3 100644 --- a/power_overwhelming/src/dump_sensors.cpp +++ b/power_overwhelming/src/dump_sensors.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/dump_sensors.h" @@ -11,7 +11,7 @@ /* * visus::power_overwhelming::dump_sensors */ -std::size_t visus::power_overwhelming::dump_sensors(const char *path) { +std::size_t visus::power_overwhelming::dump_sensors(_In_z_ const char *path) { const auto descs = detail::get_all_sensor_descs(); detail::write_json(path, descs); return descs.size(); @@ -21,7 +21,8 @@ std::size_t visus::power_overwhelming::dump_sensors(const char *path) { /* * visus::power_overwhelming::dump_sensors */ -std::size_t visus::power_overwhelming::dump_sensors(const wchar_t *path) { +std::size_t visus::power_overwhelming::dump_sensors( + _In_z_ const wchar_t *path) { const auto descs = detail::get_all_sensor_descs(); detail::write_json(path, descs); return descs.size(); diff --git a/test/pch.h b/test/pch.h index 37a8f378..26db4781 100644 --- a/test/pch.h +++ b/test/pch.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include diff --git a/test/sensor_desc_test.cpp b/test/sensor_desc_test.cpp index 0b69dc21..13db395a 100644 --- a/test/sensor_desc_test.cpp +++ b/test/sensor_desc_test.cpp @@ -1,4 +1,4 @@ -// +// // Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -13,7 +13,7 @@ namespace visus { namespace power_overwhelming { namespace test { - TEST_CLASS(sensor_desc) { + TEST_CLASS(sensor_desc_test) { public: diff --git a/test/string_test.cpp b/test/string_test.cpp new file mode 100644 index 00000000..bb183585 --- /dev/null +++ b/test/string_test.cpp @@ -0,0 +1,118 @@ +// +// Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Christoph Müller + +#include "pch.h" +#include "CppUnitTest.h" + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + + +namespace visus { +namespace power_overwhelming { +namespace test { + + /// + /// Tests for string-related functions. + /// + TEST_CLASS(string_test) { + + public: + + TEST_METHOD(test_convert_char_char) { + typedef char src_type; + typedef char dst_type; + + { + const std::basic_string expected = "input"; + const src_type *input = "input"; + Assert::AreEqual(expected, convert_string(input), L"standard input", LINE_INFO()); + } + + { + const std::basic_string expected = ""; + const src_type *input = ""; + Assert::AreEqual(expected, convert_string(input), L"empty conversion", LINE_INFO()); + } + + { + const std::basic_string expected = ""; + const src_type *input = nullptr; + Assert::AreEqual(expected, convert_string(input), L"nullptr conversion", LINE_INFO()); + } + } + + TEST_METHOD(test_convert_char_wchar_t) { + typedef char src_type; + typedef wchar_t dst_type; + + { + const std::basic_string expected = L"input"; + const src_type *input = "input"; + Assert::AreEqual(expected, convert_string(input), L"standard input", LINE_INFO()); + } + + { + const std::basic_string expected = L""; + const src_type *input = ""; + Assert::AreEqual(expected, convert_string(input), L"empty conversion", LINE_INFO()); + } + + { + const std::basic_string expected = L""; + const src_type *input = nullptr; + Assert::AreEqual(expected, convert_string(input), L"nullptr conversion", LINE_INFO()); + } + } + + TEST_METHOD(test_convert_wchar_t_char) { + typedef wchar_t src_type; + typedef char dst_type; + + { + const std::basic_string expected = "input"; + const src_type *input = L"input"; + Assert::AreEqual(expected, convert_string(input), L"standard input", LINE_INFO()); + } + + { + const std::basic_string expected = ""; + const src_type *input = L""; + Assert::AreEqual(expected, convert_string(input), L"empty conversion", LINE_INFO()); + } + + { + const std::basic_string expected = ""; + const src_type *input = nullptr; + Assert::AreEqual(expected, convert_string(input), L"nullptr conversion", LINE_INFO()); + } + } + + TEST_METHOD(test_convert_wchar_t_wchar_t) { + typedef wchar_t src_type; + typedef wchar_t dst_type; + + { + const std::basic_string expected = L"input"; + const src_type *input = L"input"; + Assert::AreEqual(expected, convert_string(input), L"standard input", LINE_INFO()); + } + + { + const std::basic_string expected = L""; + const src_type *input = L""; + Assert::AreEqual(expected, convert_string(input), L"empty conversion", LINE_INFO()); + } + + { + const std::basic_string expected = L""; + const src_type *input = nullptr; + Assert::AreEqual(expected, convert_string(input), L"nullptr conversion", LINE_INFO()); + } + } + + }; +} /* namespace test */ +} /* namespace power_overwhelming */ +} /* namespace visus */ From abccd198ff21dcb754b8618444f6616ad2ae5bd1 Mon Sep 17 00:00:00 2001 From: mueller Date: Mon, 20 Mar 2023 10:15:47 +0100 Subject: [PATCH 12/24] Added annotations to EMI sensor. --- .../include/power_overwhelming/adl_sensor.h | 5 +- .../include/power_overwhelming/emi_sensor.h | 64 +++++++++++-------- power_overwhelming/src/emi_sensor.cpp | 54 +++++++++------- 3 files changed, 71 insertions(+), 52 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/adl_sensor.h b/power_overwhelming/include/power_overwhelming/adl_sensor.h index 71377d28..609dc7c0 100644 --- a/power_overwhelming/include/power_overwhelming/adl_sensor.h +++ b/power_overwhelming/include/power_overwhelming/adl_sensor.h @@ -163,7 +163,7 @@ namespace power_overwhelming { /// The callback to be invoked if new data /// arrived. If this is nullptr, the asynchronous sampling will /// be disabled. - /// The desired sampling period in + /// The desired sampling period in /// microseconds. This parameter defaults to 1 millisecond. /// A user-defined context pointer that is passed /// on to . This parameter defaults to @@ -176,8 +176,7 @@ namespace power_overwhelming { /// If the sensor could not be /// sampled. void sample(_In_opt_ const measurement_callback on_measurement, - _In_ const microseconds_type sampling_period - = default_sampling_period, + _In_ const microseconds_type period = default_sampling_period, _In_opt_ void *context = nullptr); using sensor::sample; diff --git a/power_overwhelming/include/power_overwhelming/emi_sensor.h b/power_overwhelming/include/power_overwhelming/emi_sensor.h index 09f60ba6..0102b4dd 100644 --- a/power_overwhelming/include/power_overwhelming/emi_sensor.h +++ b/power_overwhelming/include/power_overwhelming/emi_sensor.h @@ -70,8 +70,9 @@ namespace power_overwhelming { /// /// If enumerating or opening the /// devices failed. - static std::size_t for_all(emi_sensor *out_sensors, - const std::size_t cnt_sensors); + static std::size_t for_all( + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors); /// /// Create sensors for all channels of all devices whose name matches @@ -91,8 +92,10 @@ namespace power_overwhelming { /// is nullptr. /// If enumerating or opening the /// devices failed. - static std::size_t for_channel(emi_sensor *out_sensors, - const std::size_t cnt_sensors, const wchar_t *channel); + static std::size_t for_channel( + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_z_ const wchar_t *channel); /// /// Create sensors for all devices whose name matches the given regular @@ -112,8 +115,10 @@ namespace power_overwhelming { /// is nullptr. /// If enumerating or opening the /// devices failed. - static std::size_t for_device(emi_sensor *out_sensors, - const std::size_t cnt_sensors, const char_type *device); + static std::size_t for_device( + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_z_ const char_type *device); /// /// Create sensors for all devices and channels whose names matches the @@ -132,12 +137,15 @@ namespace power_overwhelming { /// , not all sensors have been returned. /// /// If - /// is nullptr. + /// is nullptr, of + /// is nullptr. /// If enumerating or opening the /// devices failed. - static std::size_t for_device_and_channel(emi_sensor *out_sensors, - const std::size_t cnt_sensors, const char_type *device, - const char_type *channel); + static std::size_t for_device_and_channel( + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_z_ const char_type *device, + _In_z_ const char_type *channel); /// /// Create sensors for all devices whose name matches the given regular @@ -158,9 +166,11 @@ namespace power_overwhelming { /// is nullptr. /// If enumerating or opening the /// devices failed. - static std::size_t for_device_and_channel(emi_sensor *out_sensors, - const std::size_t cnt_sensors, const char_type *device, - const channel_type channel); + static std::size_t for_device_and_channel( + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_z_ const char_type *device, + _In_ const channel_type channel); /// /// Initialises a new instance. @@ -171,7 +181,7 @@ namespace power_overwhelming { /// Move into a new instance. /// /// The object to be moved. - inline emi_sensor(emi_sensor&& rhs) noexcept : _impl(rhs._impl) { + inline emi_sensor(_In_ emi_sensor&& rhs) noexcept : _impl(rhs._impl) { rhs._impl = nullptr; } @@ -203,18 +213,19 @@ namespace power_overwhelming { channel_type channels(void) const; /// - virtual const wchar_t *name(void) const noexcept override; + virtual _Ret_maybenull_z_ const wchar_t *name( + void) const noexcept override; /// /// Answer the path to the underlying device. /// /// The path of the EMI device or nullptr if the sensor /// is invalid. - const char_type *path(void) const noexcept; + _Ret_maybenull_z_ const char_type *path(void) const noexcept; /// virtual measurement sample( - const timestamp_resolution resolution) const override; + _In_ const timestamp_resolution resolution) const override; /// /// Asynchronously sample the sensor every @@ -223,7 +234,7 @@ namespace power_overwhelming { /// The callback to be invoked if new data /// arrived. If this is nullptr, the asynchronous sampling will /// be disabled. - /// The desired sampling period in + /// The desired sampling period in /// microseconds. This parameter defaults to 1 millisecond. /// A user-defined context pointer that is passed /// on to . This parameter defaults to @@ -235,9 +246,9 @@ namespace power_overwhelming { /// /// If the sensor could not be /// sampled. - void sample(const measurement_callback on_measurement, - const microseconds_type sampling_period = default_sampling_period, - void *context = nullptr); + void sample(_In_opt_ const measurement_callback on_measurement, + _In_ const microseconds_type period = default_sampling_period, + _In_opt_ void *context = nullptr); #if defined(_WIN32) /// @@ -256,8 +267,8 @@ namespace power_overwhelming { /// If the method is called on a /// sensor that uses a different version than EMIv1. /// If the IOCTL failed. - EMI_MEASUREMENT_DATA_V1 *sample( - EMI_MEASUREMENT_DATA_V1& measurement) const; + _Ret_ EMI_MEASUREMENT_DATA_V1 *sample( + _In_ EMI_MEASUREMENT_DATA_V1& measurement) const; #endif /* defined(_WIN32) */ #if defined(_WIN32) @@ -280,8 +291,9 @@ namespace power_overwhelming { /// If the method is called on a /// sensor that uses a different version than EMIv2. /// If the IOCTL failed. - EMI_MEASUREMENT_DATA_V2 *sample(EMI_MEASUREMENT_DATA_V2 *measurement, - const std::size_t size) const; + _Ret_ EMI_MEASUREMENT_DATA_V2 *sample( + _Inout_updates_bytes_(size) EMI_MEASUREMENT_DATA_V2 *measurement, + _In_ const std::size_t size) const; #endif /* defined(_WIN32) */ using sensor::sample; @@ -305,7 +317,7 @@ namespace power_overwhelming { /// /// The right-hand side operand /// *this - emi_sensor& operator =(emi_sensor&& rhs) noexcept; + emi_sensor& operator =(_In_ emi_sensor&& rhs) noexcept; /// virtual operator bool(void) const noexcept override; diff --git a/power_overwhelming/src/emi_sensor.cpp b/power_overwhelming/src/emi_sensor.cpp index f77707f8..2586b224 100644 --- a/power_overwhelming/src/emi_sensor.cpp +++ b/power_overwhelming/src/emi_sensor.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/emi_sensor.h" @@ -24,7 +24,8 @@ * visus::power_overwhelming::emi_sensor::for_all */ std::size_t visus::power_overwhelming::emi_sensor::for_all( - emi_sensor *out_sensors, const std::size_t cnt_sensors) { + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors) { #if defined(_WIN32) typedef detail::emi_sensor_impl::string_type string_type; return detail::emi_sensor_impl::create(out_sensors, cnt_sensors, @@ -41,8 +42,9 @@ std::size_t visus::power_overwhelming::emi_sensor::for_all( * visus::power_overwhelming::emi_sensor::for_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_channel( - emi_sensor *out_sensors, const std::size_t cnt_sensors, - const wchar_t *channel) { + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_z_ const wchar_t *channel) { if (channel == nullptr) { throw std::invalid_argument("The regular expression selecting the " "channel must not be null."); @@ -66,8 +68,9 @@ std::size_t visus::power_overwhelming::emi_sensor::for_channel( * visus::power_overwhelming::emi_sensor::for_device */ std::size_t visus::power_overwhelming::emi_sensor::for_device( - emi_sensor *out_sensors, const std::size_t cnt_sensors, - const char_type *device) { + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_z_ const char_type *device) { if (device == nullptr) { throw std::invalid_argument("The regular expression selecting the " "device must not be null."); @@ -91,8 +94,10 @@ std::size_t visus::power_overwhelming::emi_sensor::for_device( * visus::power_overwhelming::emi_sensor::for_device_and_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( - emi_sensor *out_sensors, const std::size_t cnt_sensors, - const char_type *device, const char_type *channel) { + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_z_ const char_type *device, + _In_z_ const char_type *channel) { if (device == nullptr) { throw std::invalid_argument("The regular expression selecting the " "device must not be null."); @@ -122,8 +127,10 @@ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( * visus::power_overwhelming::emi_sensor::for_device_and_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( - emi_sensor *out_sensors, const std::size_t cnt_sensors, - const char_type *device, const channel_type channel) { + _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_z_ const char_type *device, + _In_ const channel_type channel) { if (device == nullptr) { throw std::invalid_argument("The regular expression selecting the " "device must not be null."); @@ -194,7 +201,7 @@ visus::power_overwhelming::emi_sensor::channels(void) const { /* * visus::power_overwhelming::emi_sensor::name */ -const wchar_t *visus::power_overwhelming::emi_sensor::name( +_Ret_maybenull_z_ const wchar_t *visus::power_overwhelming::emi_sensor::name( void) const noexcept { #if defined(_WIN32) return (this->_impl != nullptr) @@ -209,7 +216,7 @@ const wchar_t *visus::power_overwhelming::emi_sensor::name( /* * visus::power_overwhelming::emi_sensor::path */ -const visus::power_overwhelming::emi_sensor::char_type * +_Ret_maybenull_z_ const visus::power_overwhelming::emi_sensor::char_type * visus::power_overwhelming::emi_sensor::path(void) const noexcept { #if defined(_WIN32) return (this->_impl != nullptr) @@ -226,7 +233,7 @@ visus::power_overwhelming::emi_sensor::path(void) const noexcept { */ visus::power_overwhelming::measurement visus::power_overwhelming::emi_sensor::sample( - const timestamp_resolution resolution) const { + _In_ const timestamp_resolution resolution) const { #if defined(_WIN32) this->check_not_disposed(); @@ -257,9 +264,9 @@ visus::power_overwhelming::emi_sensor::sample( * visus::power_overwhelming::emi_sensor::sample */ void visus::power_overwhelming::emi_sensor::sample( - const measurement_callback on_measurement, - const microseconds_type sampling_period, - void *context) { + _In_opt_ const measurement_callback on_measurement, + _In_ const microseconds_type sampling_period, + _In_opt_ void *context) { #if defined(_WIN32) typedef decltype(detail::emi_sensor_impl::sampler)::interval_type interval_type; @@ -286,8 +293,8 @@ void visus::power_overwhelming::emi_sensor::sample( /* * visus::power_overwhelming::emi_sensor::sample */ -EMI_MEASUREMENT_DATA_V1 *visus::power_overwhelming::emi_sensor::sample( - EMI_MEASUREMENT_DATA_V1& measurement) const { +_Ret_ EMI_MEASUREMENT_DATA_V1 *visus::power_overwhelming::emi_sensor::sample( + _In_ EMI_MEASUREMENT_DATA_V1& measurement) const { this->check_not_disposed(); if (this->version() != EMI_VERSION_V1) { @@ -305,8 +312,9 @@ EMI_MEASUREMENT_DATA_V1 *visus::power_overwhelming::emi_sensor::sample( /* * visus::power_overwhelming::emi_sensor::sample */ -EMI_MEASUREMENT_DATA_V2 *visus::power_overwhelming::emi_sensor::sample( - EMI_MEASUREMENT_DATA_V2 *measurement, const std::size_t size) const { +_Ret_ EMI_MEASUREMENT_DATA_V2 *visus::power_overwhelming::emi_sensor::sample( + _Inout_updates_bytes_(size) EMI_MEASUREMENT_DATA_V2 *measurement, + _In_ const std::size_t size) const { this->check_not_disposed(); if (this->version() != EMI_VERSION_V2) { @@ -342,7 +350,7 @@ visus::power_overwhelming::emi_sensor::version(void) const noexcept { * visus::power_overwhelming::emi_sensor::operator = */ visus::power_overwhelming::emi_sensor& -visus::power_overwhelming::emi_sensor::operator =(emi_sensor&& rhs) noexcept { +visus::power_overwhelming::emi_sensor::operator =(_In_ emi_sensor&& rhs) noexcept { if (this != std::addressof(rhs)) { this->_impl = rhs._impl; rhs._impl = nullptr; From 550a781dc3bc49281967a2c5e9a601d112c8ad33 Mon Sep 17 00:00:00 2001 From: mueller Date: Mon, 20 Mar 2023 10:21:36 +0100 Subject: [PATCH 13/24] Added annotations to event. --- .../include/power_overwhelming/event.h | 22 ++++++++++-------- power_overwhelming/src/event.cpp | 23 ++++++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/event.h b/power_overwhelming/include/power_overwhelming/event.h index d3a3c7da..ac77a9fc 100644 --- a/power_overwhelming/include/power_overwhelming/event.h +++ b/power_overwhelming/include/power_overwhelming/event.h @@ -6,8 +6,11 @@ #pragma once #if defined(_WIN32) +#pragma push_macro("NOMINMAX") #define NOMINMAX #include +#pragma pop_macro("NOMINMAX") + #else /*defined(_WIN32) */ #define POWER_OVERWHELMING_EVENT_EMULATION #endif /* defined(_WIN32) */ @@ -44,15 +47,16 @@ namespace power_overwhelming { /// /// /// - extern event_type POWER_OVERWHELMING_API create_event( - const bool manual_reset = false, - const bool initially_signalled = false); + extern _Ret_ event_type POWER_OVERWHELMING_API create_event( + _In_ const bool manual_reset = false, + _In_ const bool initially_signalled = false); /// /// Destroys the given event. /// /// The event to be released. - extern void POWER_OVERWHELMING_API destroy_event(event_type& event); + extern void POWER_OVERWHELMING_API destroy_event( + _Inout_opt_ event_type& event); /// /// Resets a manual reset event. @@ -60,7 +64,7 @@ namespace power_overwhelming { /// The handle of the event to reset. /// In case the operation failed. /// - extern void POWER_OVERWHELMING_API reset_event(event_type event); + extern void POWER_OVERWHELMING_API reset_event(_In_ event_type event); /// /// Signals an event. @@ -68,7 +72,7 @@ namespace power_overwhelming { /// The handle of the event to set. /// In case the operation failed. /// - extern void POWER_OVERWHELMING_API set_event(event_type event); + extern void POWER_OVERWHELMING_API set_event(_In_ event_type event); /// /// Waits for an event to become signalled. @@ -76,7 +80,7 @@ namespace power_overwhelming { /// The handle of the event to wait for. /// In case the operation failed. /// - extern void POWER_OVERWHELMING_API wait_event(event_type event); + extern void POWER_OVERWHELMING_API wait_event(_In_ event_type event); /// /// Waits for an event to become signalled. @@ -87,8 +91,8 @@ namespace power_overwhelming { /// the operation timed out without another error. /// In case the operation failed. /// - extern bool POWER_OVERWHELMING_API wait_event(event_type event, - const unsigned int timeout); + extern bool POWER_OVERWHELMING_API wait_event(_In_ event_type event, + _In_ const unsigned int timeout); } /* namespace power_overwhelming */ } /* namespace visus */ diff --git a/power_overwhelming/src/event.cpp b/power_overwhelming/src/event.cpp index 2bf54c32..f55cae11 100644 --- a/power_overwhelming/src/event.cpp +++ b/power_overwhelming/src/event.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2018 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2018 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/event.h" @@ -31,8 +31,9 @@ namespace detail { /* * visus::power_overwhelming::create_event */ -visus::power_overwhelming::event_type visus::power_overwhelming::create_event( - const bool manual_reset, const bool initially_signalled) { +_Ret_ visus::power_overwhelming::event_type +visus::power_overwhelming::create_event(_In_ const bool manual_reset, + _In_ const bool initially_signalled) { #if defined(POWER_OVERWHELMING_EVENT_EMULATION) auto retval = new detail::event_impl; @@ -61,7 +62,7 @@ visus::power_overwhelming::event_type visus::power_overwhelming::create_event( /* * visus::power_overwhelming::destroy_event */ -void visus::power_overwhelming::destroy_event(event_type& event) { +void visus::power_overwhelming::destroy_event(_Inout_opt_ event_type& event) { #if defined(POWER_OVERWHELMING_EVENT_EMULATION) delete event; event = nullptr; @@ -76,7 +77,7 @@ void visus::power_overwhelming::destroy_event(event_type& event) { /* * visus::power_overwhelming::reset_event */ -void visus::power_overwhelming::reset_event(event_type event) { +void visus::power_overwhelming::reset_event(_In_ event_type event) { #if defined(POWER_OVERWHELMING_EVENT_EMULATION) if (event == nullptr) { throw std::system_error(EINVAL, std::system_category()); @@ -97,7 +98,7 @@ void visus::power_overwhelming::reset_event(event_type event) { /* * visus::power_overwhelming::set_event */ -void visus::power_overwhelming::set_event(event_type event) { +void visus::power_overwhelming::set_event(_In_ event_type event) { #if defined(POWER_OVERWHELMING_EVENT_EMULATION) if (event == nullptr) { throw std::system_error(EINVAL, std::system_category()); @@ -126,7 +127,7 @@ void visus::power_overwhelming::set_event(event_type event) { /* * visus::power_overwhelming::wait_event */ -void visus::power_overwhelming::wait_event(event_type event) { +void visus::power_overwhelming::wait_event(_In_ event_type event) { #if defined(POWER_OVERWHELMING_EVENT_EMULATION) if (event == nullptr) { throw std::system_error(EINVAL, std::system_category()); @@ -160,8 +161,8 @@ void visus::power_overwhelming::wait_event(event_type event) { /* * visus::power_overwhelming::wait_event */ -bool visus::power_overwhelming::wait_event(event_type event, - const unsigned int timeout) { +bool visus::power_overwhelming::wait_event(_In_ event_type event, + _In_ const unsigned int timeout) { #if defined(POWER_OVERWHELMING_EVENT_EMULATION) if (event == nullptr) { throw std::system_error(EINVAL, std::system_category()); From d64f5dadf2696e32cf83f973f5c093f5329bbc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 10:43:58 +0100 Subject: [PATCH 14/24] Annotated graphics_device. --- .../power_overwhelming/graphics_device.h | 22 ++++++++++--------- power_overwhelming/src/graphics_device.cpp | 19 ++++++++-------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/graphics_device.h b/power_overwhelming/include/power_overwhelming/graphics_device.h index 1ef54186..41b2f552 100644 --- a/power_overwhelming/include/power_overwhelming/graphics_device.h +++ b/power_overwhelming/include/power_overwhelming/graphics_device.h @@ -103,8 +103,10 @@ namespace power_overwhelming { /// is not zero. /// If the devices could not be /// enumerated due to an error in the underlying APIs. - static std::size_t all(graphics_device *outDevices, - const std::size_t cntDevices, const bool onlyHardware = true); + static std::size_t all( + _Out_writes_all_(cntDevices) graphics_device *outDevices, + _In_ const std::size_t cntDevices, + _In_ const bool onlyHardware = true); /// /// Initialises a new instance. @@ -120,13 +122,13 @@ namespace power_overwhelming { /// Clone . /// /// The object to be cloned. - graphics_device(const graphics_device& rhs); + graphics_device(_In_ const graphics_device& rhs); /// /// Move . /// /// The object to be moved. - graphics_device(graphics_device&& rhs) noexcept; + graphics_device(_In_ graphics_device&& rhs) noexcept; /// /// Finalises the instance. @@ -142,8 +144,8 @@ namespace power_overwhelming { /// If the there was not enough memory /// to store the device ID. /// If the device ID could not be - /// determines. - inline const wchar_t *id(void) const { + /// determined. + inline _Ret_ const wchar_t *id(void) const { this->assert_id_and_name(); return this->_id; } @@ -158,7 +160,7 @@ namespace power_overwhelming { /// to store the device name. /// If the device name could not be /// determines. - inline const wchar_t *name(void) const { + inline _Ret_ const wchar_t *name(void) const { this->assert_id_and_name(); return this->_name; } @@ -168,14 +170,14 @@ namespace power_overwhelming { /// /// The right hand side operand. /// *this. - graphics_device operator =(const graphics_device& rhs); + graphics_device operator =(_In_ const graphics_device& rhs); /// /// Move assignment. /// /// The right hand side operand. /// *this. - graphics_device operator =(graphics_device&& rhs) noexcept; + graphics_device operator =(_In_ graphics_device&& rhs) noexcept; /// /// Determines whether the device is valid. @@ -193,7 +195,7 @@ namespace power_overwhelming { /// reference count by itself. /// /// The underlying native device. - inline operator device_type *(void) noexcept { + inline _Ret_maybenull_ operator device_type *(void) noexcept { return this->_device; } diff --git a/power_overwhelming/src/graphics_device.cpp b/power_overwhelming/src/graphics_device.cpp index afc518df..92fcef30 100644 --- a/power_overwhelming/src/graphics_device.cpp +++ b/power_overwhelming/src/graphics_device.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/graphics_device.h" @@ -20,8 +20,9 @@ * visus::power_overwhelming::graphics_device::all */ std::size_t visus::power_overwhelming::graphics_device::all( - graphics_device *outDevices, const std::size_t cntDevices, - const bool onlyHardware) { + _Out_writes_all_(cntDevices) graphics_device *outDevices, + _In_ const std::size_t cntDevices, + _In_ const bool onlyHardware) { #if (POWER_OVERWHELMING_GPU_ABSTRACTION >= 11) Microsoft::WRL::ComPtr factory; auto hr = S_OK; @@ -104,7 +105,7 @@ visus::power_overwhelming::graphics_device::graphics_device(void) noexcept * visus::power_overwhelming::graphics_device::graphics_device */ visus::power_overwhelming::graphics_device::graphics_device( - const graphics_device& rhs) + _In_ const graphics_device& rhs) : _adapter(rhs._adapter), _device(rhs._device), _id(nullptr), _name(nullptr) { #if (POWER_OVERWHELMING_GPU_ABSTRACTION >= 11) @@ -118,7 +119,7 @@ visus::power_overwhelming::graphics_device::graphics_device( * visus::power_overwhelming::graphics_device::graphics_device */ visus::power_overwhelming::graphics_device::graphics_device( - graphics_device&& rhs) noexcept + _In_ graphics_device&& rhs) noexcept : _adapter(rhs._adapter), _device(rhs._device), _id(rhs._id), _name(rhs._name) { rhs._adapter = nullptr; @@ -147,7 +148,7 @@ visus::power_overwhelming::graphics_device::~graphics_device(void) { */ visus::power_overwhelming::graphics_device visus::power_overwhelming::graphics_device::operator =( - const graphics_device& rhs) { + _In_ const graphics_device& rhs) { if (this != std::addressof(rhs)) { #if (POWER_OVERWHELMING_GPU_ABSTRACTION >= 11) detail::safe_replace(this->_adapter, rhs._adapter); @@ -171,7 +172,7 @@ visus::power_overwhelming::graphics_device::operator =( */ visus::power_overwhelming::graphics_device visus::power_overwhelming::graphics_device::operator =( - graphics_device&& rhs) noexcept { + _In_ graphics_device&& rhs) noexcept { if (this != std::addressof(rhs)) { #if (POWER_OVERWHELMING_GPU_ABSTRACTION >= 11) detail::safe_move(this->_adapter, std::move(rhs._adapter)); From 75107c733783abaff0b76a02563625c8f0632d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 11:19:21 +0100 Subject: [PATCH 15/24] Annotated HMC and NVML sensors. --- .../include/power_overwhelming/adl_sensor.h | 2 +- .../include/power_overwhelming/emi_sensor.h | 10 +-- .../power_overwhelming/graphics_device.h | 2 +- .../power_overwhelming/hmc8015_sensor.h | 88 ++++++++++++++----- .../include/power_overwhelming/literal.h | 14 +-- .../include/power_overwhelming/measurement.h | 6 +- .../power_overwhelming/measurement.inl | 6 +- .../include/power_overwhelming/nvml_sensor.h | 62 +++++++++---- .../power_overwhelming_api.h | 4 + power_overwhelming/src/adl_sensor.cpp | 6 +- power_overwhelming/src/emi_sensor.cpp | 14 +-- power_overwhelming/src/graphics_device.cpp | 2 +- power_overwhelming/src/hmc8015_sensor.cpp | 78 ++++++++++++---- power_overwhelming/src/nvml_sensor.cpp | 70 +++++++++++---- 14 files changed, 258 insertions(+), 106 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/adl_sensor.h b/power_overwhelming/include/power_overwhelming/adl_sensor.h index 609dc7c0..95a27a4f 100644 --- a/power_overwhelming/include/power_overwhelming/adl_sensor.h +++ b/power_overwhelming/include/power_overwhelming/adl_sensor.h @@ -38,7 +38,7 @@ namespace power_overwhelming { /// , not all sensors have been returned. /// static std::size_t for_all( - _Out_writes_all_(cntSensors) adl_sensor *outSensors, + _Out_writes_(cntSensors) adl_sensor *outSensors, _In_ const std::size_t cntSensors); /// diff --git a/power_overwhelming/include/power_overwhelming/emi_sensor.h b/power_overwhelming/include/power_overwhelming/emi_sensor.h index 0102b4dd..dd2bfd39 100644 --- a/power_overwhelming/include/power_overwhelming/emi_sensor.h +++ b/power_overwhelming/include/power_overwhelming/emi_sensor.h @@ -71,7 +71,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_all( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors); /// @@ -93,7 +93,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_channel( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const wchar_t *channel); @@ -116,7 +116,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_device( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device); @@ -142,7 +142,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_device_and_channel( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device, _In_z_ const char_type *channel); @@ -167,7 +167,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_device_and_channel( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device, _In_ const channel_type channel); diff --git a/power_overwhelming/include/power_overwhelming/graphics_device.h b/power_overwhelming/include/power_overwhelming/graphics_device.h index 41b2f552..01ee8055 100644 --- a/power_overwhelming/include/power_overwhelming/graphics_device.h +++ b/power_overwhelming/include/power_overwhelming/graphics_device.h @@ -104,7 +104,7 @@ namespace power_overwhelming { /// If the devices could not be /// enumerated due to an error in the underlying APIs. static std::size_t all( - _Out_writes_all_(cntDevices) graphics_device *outDevices, + _Out_writes_(cntDevices) graphics_device *outDevices, _In_ const std::size_t cntDevices, _In_ const bool onlyHardware = true); diff --git a/power_overwhelming/include/power_overwhelming/hmc8015_sensor.h b/power_overwhelming/include/power_overwhelming/hmc8015_sensor.h index 46f58002..2a8f1807 100644 --- a/power_overwhelming/include/power_overwhelming/hmc8015_sensor.h +++ b/power_overwhelming/include/power_overwhelming/hmc8015_sensor.h @@ -1,5 +1,5 @@ // -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -42,9 +42,10 @@ namespace power_overwhelming { /// to 3000. /// The number of HMC8015 instruments found, regardless of how /// many have been returned to . - static std::size_t for_all(hmc8015_sensor *out_sensors, - const std::size_t cnt_sensors, - const std::int32_t timeout = 3000); + static std::size_t for_all( + _Out_writes_(cnt_sensors) hmc8015_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_ const std::int32_t timeout = 3000); /// /// The product ID of the HMC8015. @@ -74,13 +75,14 @@ namespace power_overwhelming { /// loaded. /// If the sensor could not be /// initialised. - hmc8015_sensor(const char *path, const std::int32_t timeout); + hmc8015_sensor(_In_z_ const char *path, + _In_ const std::int32_t timeout); /// /// Move into a new instance. /// /// The object to be moved. - inline hmc8015_sensor(hmc8015_sensor&& rhs) noexcept + inline hmc8015_sensor(_In_ hmc8015_sensor&& rhs) noexcept : detail::visa_sensor(std::move(rhs)) { } /// @@ -109,8 +111,8 @@ namespace power_overwhelming { /// object that has been disposed by moving it. /// If the VISA command was not /// processed successfully. - inline void current_range(const instrument_range range, - const float value = 0.0f) { + inline void current_range(_In_ const instrument_range range, + _In_ const float value = 0.0f) { // Note: HMC8015 supports only one channel, so this is hard coded. this->set_range(1, "CURR", range, value); } @@ -124,7 +126,18 @@ namespace power_overwhelming { /// object that has been disposed by moving it. /// If the VISA command was not /// processed successfully. - void display(const char *text); + void display(_In_opt_z_ const char *text); + + /// + /// Displays the given text or clears the display. + /// + /// The text to be displayed or nullptr to + /// clear the display. + /// If the method is called on an + /// object that has been disposed by moving it. + /// If the VISA command was not + /// processed successfully. + void display(_In_opt_z_ const wchar_t *text); /// /// Gets whether logging is enabled or not. @@ -146,7 +159,7 @@ namespace power_overwhelming { /// object that has been disposed by moving it. /// If the VISA command was not /// processed successfully. - void log(const bool enable); + void log(_In_ const bool enable); /// /// Configures how logging started by behaves. @@ -177,11 +190,15 @@ namespace power_overwhelming { /// object that has been disposed by moving it. /// If the VISA command was not /// processed successfully. - void log_behaviour(const float interval, const log_mode mode, - const int value = INT_MAX, - const std::int32_t year = 0, const std::int32_t month = 0, - const std::int32_t day = 0, const std::int32_t hour = 0, - const std::int32_t minute = 0, const std::int32_t second = 0); + void log_behaviour(_In_ const float interval, + _In_ const log_mode mode, + _In_ const int value = INT_MAX, + _In_ const std::int32_t year = 0, + _In_ const std::int32_t month = 0, + _In_ const std::int32_t day = 0, + _In_ const std::int32_t hour = 0, + _In_ const std::int32_t minute = 0, + _In_ const std::int32_t second = 0); /// /// Gets the path to the log file. @@ -199,7 +216,27 @@ namespace power_overwhelming { /// object that has been disposed by moving it. /// If the VISA command was not /// processed successfully. - std::size_t log_file(char *path, const std::size_t cnt); + std::size_t log_file(_Out_writes_opt_z_(cnt) char *path, + _In_ const std::size_t cnt); + + /// + /// Sets the path to the log file. + /// + /// The path to the log file, usually just the + /// file name. + /// If true, the file will be cleared + /// if it already exists. This parameter defaults to false. + /// + /// If true, the file will be written to + /// the attached USB stick instead of internal memory. This parameter + /// defaults to false. + /// If the method is called on an + /// object that has been disposed by moving it. + /// If the VISA command was not + /// processed successfully. + void log_file(_In_z_ const char *path, + _In_ const bool overwrite = false, + _In_ const bool use_usb = false); /// /// Sets the path to the log file. @@ -216,8 +253,9 @@ namespace power_overwhelming { /// object that has been disposed by moving it. /// If the VISA command was not /// processed successfully. - void log_file(const char *path, const bool overwrite = false, - const bool use_usb = false); + void log_file(_In_z_ const wchar_t *path, + _In_ const bool overwrite = false, + _In_ const bool use_usb = false); /// /// Resets the instrument to its default state. @@ -239,7 +277,7 @@ namespace power_overwhelming { /// If the VISA command was not /// processed successfully. virtual measurement sample( - const timestamp_resolution resolution) const override; + _In_ const timestamp_resolution resolution) const override; using sensor::sample; @@ -264,8 +302,8 @@ namespace power_overwhelming { /// object that has been disposed by moving it. /// If the VISA command was not /// processed successfully. - inline void voltage_range(const instrument_range range, - const std::int32_t value = 0) { + inline void voltage_range(_In_ const instrument_range range, + _In_ const std::int32_t value = 0) { // Note: HMC8015 supports only one channel, so this is hard coded. this->set_range(1, "VOLT", range, static_cast(value)); } @@ -275,7 +313,7 @@ namespace power_overwhelming { /// /// The right-hand side operand /// *this - inline hmc8015_sensor& operator =(hmc8015_sensor&& rhs) noexcept { + inline hmc8015_sensor& operator =(_In_ hmc8015_sensor&& rhs) noexcept { visa_sensor::operator =(std::move(rhs)); return *this; } @@ -284,8 +322,10 @@ namespace power_overwhelming { void configure(void); - void set_range(const std::int32_t channel, const char *quantity, - const instrument_range range, const float value); + void set_range(_In_ const std::int32_t channel, + _In_z_ const char *quantity, + _In_ const instrument_range range, + _In_ const float value); }; } /* namespace power_overwhelming */ diff --git a/power_overwhelming/include/power_overwhelming/literal.h b/power_overwhelming/include/power_overwhelming/literal.h index bcd7ce5b..a6d1ca87 100644 --- a/power_overwhelming/include/power_overwhelming/literal.h +++ b/power_overwhelming/include/power_overwhelming/literal.h @@ -1,10 +1,12 @@ // -// Copyright © 2017 - 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2017 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller #pragma once +#include "power_overwhelming/power_overwhelming_api.h" + namespace visus { namespace power_overwhelming { @@ -28,10 +30,11 @@ namespace detail { /// template<> struct literal_selector { typedef char char_type; - static const char_type select(const char n, const wchar_t w) { + static const char_type select(_In_ const char n, _In_ const wchar_t w) { return n; } - static const char_type *select(const char *n, const wchar_t *w) { + static _Ret_maybenull_z_ const char_type *select(_In_opt_z_ const char *n, + _In_opt_z_ const wchar_t *w) { return n; } }; @@ -41,10 +44,11 @@ namespace detail { /// template<> struct literal_selector { typedef wchar_t char_type; - static const char_type select(const char n, const wchar_t w) { + static const char_type select(_In_ const char n, _In_ const wchar_t w) { return w; } - static const char_type *select(const char *n, const wchar_t *w) { + static _Ret_maybenull_z_ const char_type *select(_In_opt_z_ const char *n, + _In_opt_z_ const wchar_t *w) { return w; } }; diff --git a/power_overwhelming/include/power_overwhelming/measurement.h b/power_overwhelming/include/power_overwhelming/measurement.h index 9584eef7..c4711c40 100644 --- a/power_overwhelming/include/power_overwhelming/measurement.h +++ b/power_overwhelming/include/power_overwhelming/measurement.h @@ -1,5 +1,5 @@ // -// Copyright © 2021 - 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -212,8 +212,8 @@ namespace std { /// template basic_ostream& operator <<( - basic_ostream& lhs, - const visus::power_overwhelming::measurement &rhs); + _In_ basic_ostream& lhs, + _In_ const visus::power_overwhelming::measurement &rhs); } diff --git a/power_overwhelming/include/power_overwhelming/measurement.inl b/power_overwhelming/include/power_overwhelming/measurement.inl index 9d566731..5dcb3ff4 100644 --- a/power_overwhelming/include/power_overwhelming/measurement.inl +++ b/power_overwhelming/include/power_overwhelming/measurement.inl @@ -1,5 +1,5 @@ // -// Copyright © 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2022 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -9,8 +9,8 @@ */ template std::basic_ostream& std::operator <<( - std::basic_ostream& lhs, - const visus::power_overwhelming::measurement& rhs) { + _In_ std::basic_ostream& lhs, + _In_ const visus::power_overwhelming::measurement& rhs) { using namespace visus::power_overwhelming; const auto delim = getcsvdelimiter(lhs); const auto quote_char = getcsvquote(lhs); diff --git a/power_overwhelming/include/power_overwhelming/nvml_sensor.h b/power_overwhelming/include/power_overwhelming/nvml_sensor.h index 5ff1c588..69bee41a 100644 --- a/power_overwhelming/include/power_overwhelming/nvml_sensor.h +++ b/power_overwhelming/include/power_overwhelming/nvml_sensor.h @@ -1,5 +1,5 @@ // -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -37,8 +37,9 @@ namespace power_overwhelming { /// of the size of the output array. If this number is larger than /// , not all sensors have been returned. /// - static std::size_t for_all(nvml_sensor *outSensors, - const std::size_t cntSensors); + static std::size_t for_all( + _Out_writes_(cntSensors) nvml_sensor *outSensors, + _In_ const std::size_t cntSensors); /// /// Create a new instance for the device with the specified PCI bus ID. @@ -47,7 +48,16 @@ namespace power_overwhelming { /// /// If the specified device was not /// found, is not unique or another error occurred in NVML. - static nvml_sensor from_bus_id(const char *pciBusId); + static nvml_sensor from_bus_id(_In_z_ const char *pciBusId); + + /// + /// Create a new instance for the device with the specified PCI bus ID. + /// + /// + /// + /// If the specified device was not + /// found, is not unique or another error occurred in NVML. + static nvml_sensor from_bus_id(_In_z_ const wchar_t *pciBusId); /// /// Create a new instance for the device with the specified unique ID. @@ -56,7 +66,16 @@ namespace power_overwhelming { /// /// If the specified device was not /// found, is not unique or another error occurred in NVML. - static nvml_sensor from_guid(const char *guid); + static nvml_sensor from_guid(_In_z_ const char *guid); + + /// + /// Create a new instance for the device with the specified unique ID. + /// + /// + /// + /// If the specified device was not + /// found, is not unique or another error occurred in NVML. + static nvml_sensor from_guid(_In_z_ const wchar_t *guid); /// /// Create a new instance from a device index. @@ -71,7 +90,17 @@ namespace power_overwhelming { /// /// If the specified device was not /// found, is not unique or another error occurred in NVML. - static nvml_sensor from_index(const unsigned int index); + static nvml_sensor from_index(_In_ const unsigned int index); + + /// + /// Create a new instance for a specific device serial number printed on + /// the board. + /// + /// + /// + /// If the specified device was not + /// found, is not unique or another error occurred in NVML. + static nvml_sensor from_serial(_In_z_ const char *serial); /// /// Create a new instance for a specific device serial number printed on @@ -81,7 +110,7 @@ namespace power_overwhelming { /// /// If the specified device was not /// found, is not unique or another error occurred in NVML. - static nvml_sensor from_serial(const char *serial); + static nvml_sensor from_serial(_In_z_ const wchar_t *serial); /// /// Initialises a new instance. @@ -98,7 +127,7 @@ namespace power_overwhelming { /// Move into a new instance. /// /// The object to be moved. - inline nvml_sensor(nvml_sensor&& rhs) noexcept : _impl(rhs._impl) { + inline nvml_sensor(_In_ nvml_sensor&& rhs) noexcept : _impl(rhs._impl) { rhs._impl = nullptr; } @@ -112,18 +141,19 @@ namespace power_overwhelming { /// is for. /// /// The GUID of the device. - const char *device_guid(void) const noexcept; + _Ret_maybenull_z_ const char *device_guid(void) const noexcept; /// /// Gets the name of the sensor. /// /// The implementation-defined, human-readable name of the /// sensor. - virtual const wchar_t *name(void) const noexcept override; + virtual _Ret_maybenull_z_ const wchar_t *name( + void) const noexcept override; /// virtual measurement sample( - const timestamp_resolution resolution) const override; + _In_ const timestamp_resolution resolution) const override; using sensor::sample; @@ -134,7 +164,7 @@ namespace power_overwhelming { /// The callback to be invoked if new data /// arrived. If this is nullptr, the asynchronous sampling will /// be disabled. - /// The desired sampling period in + /// The desired sampling period in /// microseconds. This parameter defaults to 1 millisecond. /// A user-defined context pointer that is passed /// on to . This parameter defaults to @@ -146,16 +176,16 @@ namespace power_overwhelming { /// /// If the sensor could not be /// sampled. - void sample(const measurement_callback on_measurement, - const microseconds_type sampling_period = default_sampling_period, - void *context = nullptr); + void sample(_In_opt_ const measurement_callback on_measurement, + _In_ const microseconds_type period = default_sampling_period, + _In_opt_ void *context = nullptr); /// /// Move assignment. /// /// The right-hand side operand /// *this - nvml_sensor& operator =(nvml_sensor&& rhs) noexcept; + nvml_sensor& operator =(_In_ nvml_sensor&& rhs) noexcept; /// virtual operator bool(void) const noexcept override; diff --git a/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h b/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h index 2289cd01..e256917b 100644 --- a/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h +++ b/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h @@ -21,7 +21,11 @@ #if defined(_WIN32) #include + #else /* defined(_WIN32) */ // Empty SAL annotations for rancid platforms. #include "salieri.h" + +// These are missing in the salieri header. +#define _Analysis_assume_(expr) #endif /* defined(_WIN32) */ diff --git a/power_overwhelming/src/adl_sensor.cpp b/power_overwhelming/src/adl_sensor.cpp index 0864cf35..e5be7821 100644 --- a/power_overwhelming/src/adl_sensor.cpp +++ b/power_overwhelming/src/adl_sensor.cpp @@ -171,7 +171,7 @@ namespace detail { * visus::power_overwhelming::adl_sensor::for_all */ std::size_t visus::power_overwhelming::adl_sensor::for_all( - _Out_writes_all_(cntSensors) adl_sensor *outSensors, + _Out_writes_(cntSensors) adl_sensor *outSensors, _In_ const std::size_t cntSensors) { try { int cnt = 0; @@ -336,7 +336,7 @@ visus::power_overwhelming::adl_sensor::sample( */ void visus::power_overwhelming::adl_sensor::sample( _In_opt_ const measurement_callback on_measurement, - _In_ const microseconds_type sampling_period, + _In_ const microseconds_type period, _In_opt_ void *context) { using std::chrono::duration_cast; typedef decltype(detail::adl_sensor_impl::sampler)::interval_type @@ -345,7 +345,7 @@ void visus::power_overwhelming::adl_sensor::sample( this->check_not_disposed(); if (on_measurement != nullptr) { - auto sampler_rate = interval_type(sampling_period); + auto sampler_rate = interval_type(period); auto adl_rate = duration_cast(sampler_rate); // Make sure that the sensor is running before queuing to the thread. diff --git a/power_overwhelming/src/emi_sensor.cpp b/power_overwhelming/src/emi_sensor.cpp index 2586b224..570e272b 100644 --- a/power_overwhelming/src/emi_sensor.cpp +++ b/power_overwhelming/src/emi_sensor.cpp @@ -24,7 +24,7 @@ * visus::power_overwhelming::emi_sensor::for_all */ std::size_t visus::power_overwhelming::emi_sensor::for_all( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors) { #if defined(_WIN32) typedef detail::emi_sensor_impl::string_type string_type; @@ -42,7 +42,7 @@ std::size_t visus::power_overwhelming::emi_sensor::for_all( * visus::power_overwhelming::emi_sensor::for_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_channel( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const wchar_t *channel) { if (channel == nullptr) { @@ -68,7 +68,7 @@ std::size_t visus::power_overwhelming::emi_sensor::for_channel( * visus::power_overwhelming::emi_sensor::for_device */ std::size_t visus::power_overwhelming::emi_sensor::for_device( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device) { if (device == nullptr) { @@ -94,7 +94,7 @@ std::size_t visus::power_overwhelming::emi_sensor::for_device( * visus::power_overwhelming::emi_sensor::for_device_and_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device, _In_z_ const char_type *channel) { @@ -127,7 +127,7 @@ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( * visus::power_overwhelming::emi_sensor::for_device_and_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( - _Out_writes_all_(cntSensors) emi_sensor *out_sensors, + _Out_writes_(cntSensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device, _In_ const channel_type channel) { @@ -265,7 +265,7 @@ visus::power_overwhelming::emi_sensor::sample( */ void visus::power_overwhelming::emi_sensor::sample( _In_opt_ const measurement_callback on_measurement, - _In_ const microseconds_type sampling_period, + _In_ const microseconds_type period, _In_opt_ void *context) { #if defined(_WIN32) typedef decltype(detail::emi_sensor_impl::sampler)::interval_type @@ -275,7 +275,7 @@ void visus::power_overwhelming::emi_sensor::sample( if (on_measurement != nullptr) { if (!detail::emi_sensor_impl::sampler.add(this->_impl, on_measurement, - context, interval_type(sampling_period))) { + context, interval_type(period))) { throw std::logic_error("Asynchronous sampling cannot be started " "while it is already running."); } diff --git a/power_overwhelming/src/graphics_device.cpp b/power_overwhelming/src/graphics_device.cpp index 92fcef30..e1794370 100644 --- a/power_overwhelming/src/graphics_device.cpp +++ b/power_overwhelming/src/graphics_device.cpp @@ -20,7 +20,7 @@ * visus::power_overwhelming::graphics_device::all */ std::size_t visus::power_overwhelming::graphics_device::all( - _Out_writes_all_(cntDevices) graphics_device *outDevices, + _Out_writes_(cntDevices) graphics_device *outDevices, _In_ const std::size_t cntDevices, _In_ const bool onlyHardware) { #if (POWER_OVERWHELMING_GPU_ABSTRACTION >= 11) diff --git a/power_overwhelming/src/hmc8015_sensor.cpp b/power_overwhelming/src/hmc8015_sensor.cpp index b78daec9..5c4a1306 100644 --- a/power_overwhelming/src/hmc8015_sensor.cpp +++ b/power_overwhelming/src/hmc8015_sensor.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/hmc8015_sensor.h" @@ -23,8 +23,9 @@ * visus::power_overwhelming::hmc8015_sensor::for_all */ std::size_t visus::power_overwhelming::hmc8015_sensor::for_all( - hmc8015_sensor *out_sensors, const std::size_t cnt_sensors, - const std::int32_t timeout) { + _Out_writes_(cnt_sensors) hmc8015_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_ const std::int32_t timeout) { // Build the query for all R&S HMC8015 instruments. std::string query("?*::"); // Any protocol query += rohde_und_schwarz; // Only R&S @@ -49,7 +50,7 @@ std::size_t visus::power_overwhelming::hmc8015_sensor::for_all( * visus::power_overwhelming::hmc8015_sensor::hmc8015_sensor */ visus::power_overwhelming::hmc8015_sensor::hmc8015_sensor( - const char *path, const std::int32_t timeout) + _In_z_ const char *path, _In_ const std::int32_t timeout) : detail::visa_sensor(path, timeout) { #if defined(POWER_OVERWHELMING_WITH_VISA) auto impl = static_cast(*this); @@ -95,7 +96,8 @@ visus::power_overwhelming::hmc8015_sensor::~hmc8015_sensor(void) { /* * visus::power_overwhelming::hmc8015_sensor::display */ -void visus::power_overwhelming::hmc8015_sensor::display(const char *text) { +void visus::power_overwhelming::hmc8015_sensor::display( + _In_opt_z_ const char *text) { auto impl = static_cast(*this); if (text != nullptr) { @@ -107,6 +109,21 @@ void visus::power_overwhelming::hmc8015_sensor::display(const char *text) { this->throw_on_system_error(); } + +/* + * visus::power_overwhelming::hmc8015_sensor::display + */ +void visus::power_overwhelming::hmc8015_sensor::display( + _In_opt_z_ const wchar_t *text) { + if (text == nullptr) { + this->display(static_cast(nullptr)); + } else { + auto t = convert_string(text); + this->display(t.c_str()); + } +} + + /* * visus::power_overwhelming::hmc8015_sensor::is_log */ @@ -120,7 +137,7 @@ bool visus::power_overwhelming::hmc8015_sensor::is_log(void) { /* * visus::power_overwhelming::hmc8015_sensor::log */ -void visus::power_overwhelming::hmc8015_sensor::log(const bool enable) { +void visus::power_overwhelming::hmc8015_sensor::log(_In_ const bool enable) { auto impl = static_cast(*this); //if (enable) { @@ -150,10 +167,15 @@ void visus::power_overwhelming::hmc8015_sensor::log(const bool enable) { * visus::power_overwhelming::hmc8015_sensor::log_behaviour */ void visus::power_overwhelming::hmc8015_sensor::log_behaviour( - const float interval, const log_mode mode, const int value, - const std::int32_t year, const std::int32_t month, - const std::int32_t day, const std::int32_t hour, - const std::int32_t minute, const std::int32_t second) { + _In_ const float interval, + _In_ const log_mode mode, + _In_ const int value, + _In_ const std::int32_t year, + _In_ const std::int32_t month, + _In_ const std::int32_t day, + _In_ const std::int32_t hour, + _In_ const std::int32_t minute, + _In_ const std::int32_t second) { auto impl = static_cast(*this); // Configure the logging mode. @@ -249,7 +271,7 @@ void visus::power_overwhelming::hmc8015_sensor::log_behaviour( * visus::power_overwhelming::hmc8015_sensor::log_file */ std::size_t visus::power_overwhelming::hmc8015_sensor::log_file( - char *path, const std::size_t cnt) { + _Out_writes_opt_z_(cnt) char *path, _In_ const std::size_t cnt) { auto impl = static_cast(*this); this->check_not_disposed(); @@ -276,8 +298,10 @@ std::size_t visus::power_overwhelming::hmc8015_sensor::log_file( /* * visus::power_overwhelming::hmc8015_sensor::log_file */ -void visus::power_overwhelming::hmc8015_sensor::log_file(const char *path, - const bool overwrite, const bool use_usb) { +void visus::power_overwhelming::hmc8015_sensor::log_file( + _In_z_ const char *path, + _In_ const bool overwrite, + _In_ const bool use_usb) { if (path == nullptr) { throw std::invalid_argument("The path to the log file cannot be null."); } @@ -293,6 +317,22 @@ void visus::power_overwhelming::hmc8015_sensor::log_file(const char *path, } +/* + * visus::power_overwhelming::hmc8015_sensor::log_file + */ +void visus::power_overwhelming::hmc8015_sensor::log_file( + _In_z_ const wchar_t *path, + _In_ const bool overwrite, + _In_ const bool use_usb) { + if (path == nullptr) { + throw std::invalid_argument("The path to the log file cannot be null."); + } + + auto p = convert_string(path); + this->log_file(p.c_str(), overwrite, use_usb); +} + + /* * visus::power_overwhelming::hmc8015_sensor::reset */ @@ -310,7 +350,7 @@ void visus::power_overwhelming::hmc8015_sensor::reset(void) { */ visus::power_overwhelming::measurement visus::power_overwhelming::hmc8015_sensor::sample( - const timestamp_resolution resolution) const { + _In_ const timestamp_resolution resolution) const { auto impl = static_cast(*this); auto response = impl.query("CHAN1:MEAS:DATA?\n"); auto timestamp = create_timestamp(resolution); @@ -321,7 +361,7 @@ visus::power_overwhelming::hmc8015_sensor::sample( auto c = static_cast(::atof(tokens[1].c_str())); auto p = static_cast(::atof(tokens[2].c_str())); - assert(this->name() != nullptr); + _Analysis_assume_(this->name() != nullptr); return measurement(this->name(), timestamp, v, c, p); } @@ -362,8 +402,8 @@ void visus::power_overwhelming::hmc8015_sensor::configure(void) { * visus::power_overwhelming::hmc8015_sensor::set_range */ void visus::power_overwhelming::hmc8015_sensor::set_range( - const std::int32_t channel, const char *quantity, - const instrument_range range, const float value) { + _In_ const std::int32_t channel, _In_z_ const char *quantity, + _In_ const instrument_range range, _In_ const float value) { assert(quantity != nullptr); auto impl = static_cast(*this); diff --git a/power_overwhelming/src/nvml_sensor.cpp b/power_overwhelming/src/nvml_sensor.cpp index d51d28ad..54e51c63 100644 --- a/power_overwhelming/src/nvml_sensor.cpp +++ b/power_overwhelming/src/nvml_sensor.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/nvml_sensor.h" @@ -16,7 +16,8 @@ * visus::power_overwhelming::nvml_sensor::for_all */ std::size_t visus::power_overwhelming::nvml_sensor::for_all( - nvml_sensor *outSensors, const std::size_t cntSensors) { + _Out_writes_(cntSensors) nvml_sensor *outSensors, + _In_ const std::size_t cntSensors) { try { unsigned int retval = 0; detail::nvml_scope scope; @@ -54,7 +55,7 @@ std::size_t visus::power_overwhelming::nvml_sensor::for_all( */ visus::power_overwhelming::nvml_sensor visus::power_overwhelming::nvml_sensor::from_bus_id( - const char *pciBusId) { + _In_z_ const char *pciBusId) { nvml_sensor retval; auto status = detail::nvidia_management_library::instance() @@ -69,12 +70,22 @@ visus::power_overwhelming::nvml_sensor::from_bus_id( } +/* + * visus::power_overwhelming::nvml_sensor::from_bus_id + */ +visus::power_overwhelming::nvml_sensor +visus::power_overwhelming::nvml_sensor::from_bus_id( + _In_z_ const wchar_t *pciBusId) { + auto b = convert_string(pciBusId); + return from_bus_id(b.c_str()); +} + + /* * visus::power_overwhelming::nvml_sensor::from_guid */ visus::power_overwhelming::nvml_sensor -visus::power_overwhelming::nvml_sensor::from_guid( - const char *guid) { +visus::power_overwhelming::nvml_sensor::from_guid(_In_z_ const char *guid) { nvml_sensor retval; auto status = detail::nvidia_management_library::instance() @@ -89,12 +100,22 @@ visus::power_overwhelming::nvml_sensor::from_guid( } +/* + * visus::power_overwhelming::nvml_sensor::from_guid + */ +visus::power_overwhelming::nvml_sensor +visus::power_overwhelming::nvml_sensor::from_guid(_In_z_ const wchar_t *guid) { + auto g = convert_string(guid); + return from_guid(g.c_str()); +} + + /* * visus::power_overwhelming::nvml_sensor::from_index */ visus::power_overwhelming::nvml_sensor visus::power_overwhelming::nvml_sensor::from_index( - const unsigned int index) { + _In_ const unsigned int index) { nvml_sensor retval; auto status = detail::nvidia_management_library::instance() @@ -114,7 +135,7 @@ visus::power_overwhelming::nvml_sensor::from_index( */ visus::power_overwhelming::nvml_sensor visus::power_overwhelming::nvml_sensor::from_serial( - const char *serial) { + _In_z_ const char *serial) { nvml_sensor retval; auto status = detail::nvidia_management_library::instance() @@ -128,6 +149,18 @@ visus::power_overwhelming::nvml_sensor::from_serial( return retval; } + +/* + * visus::power_overwhelming::nvml_sensor::from_serial + */ +visus::power_overwhelming::nvml_sensor +visus::power_overwhelming::nvml_sensor::from_serial( + const _In_z_ wchar_t *serial) { + auto s = convert_string(serial); + return from_serial(s.c_str()); +} + + /* * visus::power_overwhelming::nvml_sensor::nvml_sensor */ @@ -146,8 +179,8 @@ visus::power_overwhelming::nvml_sensor::~nvml_sensor(void) { /* * visus::power_overwhelming::nvml_sensor::device_guid */ -const char *visus::power_overwhelming::nvml_sensor::device_guid( - void) const noexcept { +_Ret_maybenull_z_ const char * +visus::power_overwhelming::nvml_sensor::device_guid(void) const noexcept { if (this->_impl == nullptr) { return nullptr; } else { @@ -159,7 +192,7 @@ const char *visus::power_overwhelming::nvml_sensor::device_guid( /* * visus::power_overwhelming::nvml_sensor::name */ -const wchar_t *visus::power_overwhelming::nvml_sensor::name( +_Ret_maybenull_z_ const wchar_t *visus::power_overwhelming::nvml_sensor::name( void) const noexcept { if (this->_impl == nullptr) { return nullptr; @@ -174,7 +207,7 @@ const wchar_t *visus::power_overwhelming::nvml_sensor::name( */ visus::power_overwhelming::measurement visus::power_overwhelming::nvml_sensor::sample( - const timestamp_resolution resolution) const { + _In_ const timestamp_resolution resolution) const { this->check_not_disposed(); return this->_impl->sample(resolution); } @@ -184,9 +217,9 @@ visus::power_overwhelming::nvml_sensor::sample( * visus::power_overwhelming::nvml_sensor::sample */ void visus::power_overwhelming::nvml_sensor::sample( - const measurement_callback on_measurement, - const microseconds_type sampling_period, - void *context) { + _In_opt_ const measurement_callback on_measurement, + _In_ const microseconds_type period, + _In_opt_ void *context) { typedef decltype(detail::nvml_sensor_impl::sampler)::interval_type interval_type; @@ -194,7 +227,7 @@ void visus::power_overwhelming::nvml_sensor::sample( if (on_measurement != nullptr) { if (!detail::nvml_sensor_impl::sampler.add(this->_impl, on_measurement, - context, interval_type(sampling_period))) { + context, interval_type(period))) { throw std::logic_error("Asynchronous sampling cannot be started " "while it is already running."); } @@ -209,7 +242,8 @@ void visus::power_overwhelming::nvml_sensor::sample( * visus::power_overwhelming::nvml_sensor::operator = */ visus::power_overwhelming::nvml_sensor& -visus::power_overwhelming::nvml_sensor::operator =(nvml_sensor&& rhs) noexcept { +visus::power_overwhelming::nvml_sensor::operator =( + _In_ nvml_sensor&& rhs) noexcept { if (this != std::addressof(rhs)) { this->_impl = rhs._impl; rhs._impl = nullptr; From 8e96c496682c4b3dbe5aa2c9633bfdfb754e5266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 11:39:09 +0100 Subject: [PATCH 16/24] Annotated RTB sensor --- .../oscilloscope_sensor_definition.h | 22 +++---- .../include/power_overwhelming/quote.h | 5 +- .../include/power_overwhelming/quote.inl | 4 +- .../include/power_overwhelming/regex_escape.h | 3 +- .../include/power_overwhelming/rtb_sensor.h | 41 +++++++++---- .../include/power_overwhelming/visa_sensor.h | 42 +++++++++++--- .../src/oscilloscope_sensor_definition.cpp | 24 ++++---- power_overwhelming/src/rtb_sensor.cpp | 43 +++++++++----- power_overwhelming/src/visa_sensor.cpp | 58 ++++++++++++------- power_overwhelming/src/visa_sensor_impl.cpp | 19 +++++- power_overwhelming/src/visa_sensor_impl.h | 12 ++-- 11 files changed, 184 insertions(+), 89 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/oscilloscope_sensor_definition.h b/power_overwhelming/include/power_overwhelming/oscilloscope_sensor_definition.h index 8b54738f..3b0172e3 100644 --- a/power_overwhelming/include/power_overwhelming/oscilloscope_sensor_definition.h +++ b/power_overwhelming/include/power_overwhelming/oscilloscope_sensor_definition.h @@ -37,9 +37,9 @@ namespace power_overwhelming { /// are the same. /// If the memory for storing the /// description could not be allocated. - oscilloscope_sensor_definition(const wchar_t *description, - const std::uint32_t channel_voltage, - const std::uint32_t channel_current); + oscilloscope_sensor_definition(_In_z_ const wchar_t *description, + _In_ const std::uint32_t channel_voltage, + _In_ const std::uint32_t channel_current); /// /// Initialises a new instance. @@ -63,18 +63,18 @@ namespace power_overwhelming { /// are the same. /// If the memory for storing the /// description could not be allocated. - oscilloscope_sensor_definition(const wchar_t *description, - const std::uint32_t channel_voltage, - const float attenuation_voltage, - const std::uint32_t channel_current, - const float attenuation_current); + oscilloscope_sensor_definition(_In_z_ const wchar_t *description, + _In_ const std::uint32_t channel_voltage, + _In_ const float attenuation_voltage, + _In_ const std::uint32_t channel_current, + _In_ const float attenuation_current); /// /// Clone . /// /// The object to be cloned. oscilloscope_sensor_definition( - const oscilloscope_sensor_definition& rhs); + _In_ const oscilloscope_sensor_definition& rhs); /// /// Finalises the instance. @@ -142,7 +142,7 @@ namespace power_overwhelming { /// /// The description of the sensor. The object remains owner of /// the string returned. - inline const wchar_t *description(void) const noexcept { + inline _Ret_z_ const wchar_t *description(void) const noexcept { return this->_description; } @@ -154,7 +154,7 @@ namespace power_overwhelming { /// If the necessary memory for the /// copy could not be acquired. oscilloscope_sensor_definition& operator =( - const oscilloscope_sensor_definition& rhs); + _In_ const oscilloscope_sensor_definition& rhs); private: diff --git a/power_overwhelming/include/power_overwhelming/quote.h b/power_overwhelming/include/power_overwhelming/quote.h index a955f282..51d868a3 100644 --- a/power_overwhelming/include/power_overwhelming/quote.h +++ b/power_overwhelming/include/power_overwhelming/quote.h @@ -8,7 +8,6 @@ #include #include "power_overwhelming/literal.h" -#include "power_overwhelming/power_overwhelming_api.h" namespace visus { @@ -26,8 +25,8 @@ namespace power_overwhelming { /// quotes. /// The quoted input string. template - std::basic_string quote(const TChar *str, - const TChar quote = POWER_OVERWHELMING_TPL_LITERAL(TChar, '"')); + std::basic_string quote(_In_opt_z_ const TChar *str, + _In_ const TChar quote = POWER_OVERWHELMING_TPL_LITERAL(TChar, '"')); } /* namespace power_overwhelming */ } /* namespace visus */ diff --git a/power_overwhelming/include/power_overwhelming/quote.inl b/power_overwhelming/include/power_overwhelming/quote.inl index 3b45c83d..941a2b32 100644 --- a/power_overwhelming/include/power_overwhelming/quote.inl +++ b/power_overwhelming/include/power_overwhelming/quote.inl @@ -8,8 +8,8 @@ * visus::power_overwhelming::quote */ template -std::basic_string visus::power_overwhelming::quote(const TChar *str, - const TChar quote) { +std::basic_string visus::power_overwhelming::quote( + _In_opt_z_ const TChar *str, _In_ const TChar quote) { std::basic_string retval; if (str != nullptr) { diff --git a/power_overwhelming/include/power_overwhelming/regex_escape.h b/power_overwhelming/include/power_overwhelming/regex_escape.h index 89a7aae7..b78f2ebb 100644 --- a/power_overwhelming/include/power_overwhelming/regex_escape.h +++ b/power_overwhelming/include/power_overwhelming/regex_escape.h @@ -23,7 +23,8 @@ namespace power_overwhelming { /// /// The escaped string. template - std::basic_string regex_escape(const std::basic_string& str) { + std::basic_string regex_escape( + _In_ const std::basic_string& str) { static const std::basic_string special = POWER_OVERWHELMING_TPL_LITERAL(TChar, "-[]{}()*+?.,\\^$|#"); std::basic_string retval; diff --git a/power_overwhelming/include/power_overwhelming/rtb_sensor.h b/power_overwhelming/include/power_overwhelming/rtb_sensor.h index f666077b..3f2fdfbd 100644 --- a/power_overwhelming/include/power_overwhelming/rtb_sensor.h +++ b/power_overwhelming/include/power_overwhelming/rtb_sensor.h @@ -40,9 +40,10 @@ namespace power_overwhelming { /// to 3000. /// The number of HMC8015 instruments found, regardless of how /// many have been returned to . - static std::size_t for_all(rtb_sensor *out_sensors, - const std::size_t cnt_sensors, - const std::int32_t timeout = 3000); + static std::size_t for_all( + _Out_writes_(cntSensors) rtb_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_ const std::int32_t timeout = 3000); /// /// The product ID of the RTB2004. @@ -72,13 +73,28 @@ namespace power_overwhelming { /// loaded. /// If the sensor could not be /// initialised. - rtb_sensor(const char *path, const std::int32_t timeout); + rtb_sensor(_In_z_ const char *path, _In_ const std::int32_t timeout); + + /// + /// Initialises a new instance. + /// + /// + /// + /// If + /// is nullptr. + /// If the memory for the sensor state + /// could not be allocated. + /// If the VISA library could not be + /// loaded. + /// If the sensor could not be + /// initialised. + rtb_sensor(_In_z_ const wchar_t *path, _In_ const std::int32_t timeout); /// /// Move into a new instance. /// /// The object to be moved. - inline rtb_sensor(rtb_sensor&& rhs) noexcept + inline rtb_sensor(_In_ rtb_sensor&& rhs) noexcept : detail::visa_sensor(std::move(rhs)) { } /// @@ -86,8 +102,9 @@ namespace power_overwhelming { /// ~rtb_sensor(void); - void configure(const oscilloscope_sensor_definition *sensors, - const std::size_t cnt_sensors); + void configure( + _In_reads_(cnt) const oscilloscope_sensor_definition *sensors, + _In_ const std::size_t cnt); /// /// Enable an configure one of the mathematical expressions. @@ -99,8 +116,9 @@ namespace power_overwhelming { /// The unit of the resulting values. If /// nullptr, the currently set unit will be unchanged. This /// parameter defaults to nullptr. - void expression(const std::uint32_t channel, const char *expression, - const char *unit = nullptr); + void expression(_In_ const std::uint32_t channel, + _In_opt_z_ const char *expression, + _In_opt_z_ const char *unit = nullptr); ///// ///// Sets the path to the log file. @@ -122,7 +140,7 @@ namespace power_overwhelming { /// virtual measurement sample( - const timestamp_resolution resolution) const override; + _In_ const timestamp_resolution resolution) const override; /// /// Sets the unit of the specified channel. @@ -133,7 +151,7 @@ namespace power_overwhelming { /// or "V"). /// If /// is nullptr. - void unit(const std::uint32_t channel, const char *unit); + void unit(_In_ const std::uint32_t channel, _In_z_ const char *unit); /// /// Move assignment. @@ -145,7 +163,6 @@ namespace power_overwhelming { return *this; } - }; } /* namespace power_overwhelming */ diff --git a/power_overwhelming/include/power_overwhelming/visa_sensor.h b/power_overwhelming/include/power_overwhelming/visa_sensor.h index 25edbfec..790cc38d 100644 --- a/power_overwhelming/include/power_overwhelming/visa_sensor.h +++ b/power_overwhelming/include/power_overwhelming/visa_sensor.h @@ -50,13 +50,33 @@ namespace detail { /// loaded. /// If the sensor could not be /// initialised. - visa_sensor(const char *path, const std::int32_t timeout); + visa_sensor(_In_z_ const char *path, _In_ const std::int32_t timeout); + + /// + /// Initialises a new instance. + /// + /// + /// This constructor will set the name of the sensor to the identity + /// string of the instrument, reset the instrument and clear any error + /// state in the instrument. + /// + /// + /// + /// If + /// is nullptr. + /// If the memory for the sensor state + /// could not be allocated. + /// If the VISA library could not be + /// loaded. + /// If the sensor could not be + /// initialised. + visa_sensor(_In_z_ const wchar_t *path, _In_ const std::int32_t timeout); /// /// Move into a new instance. /// /// The object to be moved. - inline visa_sensor(visa_sensor&& rhs) noexcept : _impl(rhs._impl) { + inline visa_sensor(_In_ visa_sensor&& rhs) noexcept : _impl(rhs._impl) { rhs._impl = nullptr; } @@ -74,13 +94,14 @@ namespace detail { /// /// The implementation-defined, human-readable name of the /// sensor. - virtual const wchar_t *name(void) const noexcept override; + _Ret_maybenull_z_ virtual const wchar_t *name( + void) const noexcept override; /// /// Gets the VISA path of the device. /// /// The VISA path used to open the device. - const char *path(void) const noexcept; + _Ret_maybenull_z_ const char *path(void) const noexcept; /// /// Resets the instrument to its default state. @@ -101,14 +122,14 @@ namespace detail { /// object that has been disposed by moving it. /// If the VISA command was not /// processed successfully. - void synchronise_clock(const bool utc = false); + void synchronise_clock(_In_ const bool utc = false); /// /// Move assignment. /// /// The right-hand side operand /// *this - visa_sensor& operator =(visa_sensor&& rhs) noexcept; + visa_sensor& operator =(_In_ visa_sensor&& rhs) noexcept; /// /// Determines whether the sensor is valid. @@ -128,6 +149,12 @@ namespace detail { /// void clear_status(void); + /// + /// Initialises the instance by retreving the name and resetting the + /// device. + /// + void initialise(void); + /// /// Checks and throws a /// if it does not return zero. @@ -150,7 +177,8 @@ namespace detail { /// /// /// - inline operator visa_sensor_impl *(void) const noexcept { + _Ret_maybenull_ inline operator visa_sensor_impl *( + void) const noexcept { return this->_impl; } diff --git a/power_overwhelming/src/oscilloscope_sensor_definition.cpp b/power_overwhelming/src/oscilloscope_sensor_definition.cpp index ec5f24e4..3b2d7bfa 100644 --- a/power_overwhelming/src/oscilloscope_sensor_definition.cpp +++ b/power_overwhelming/src/oscilloscope_sensor_definition.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/oscilloscope_sensor_definition.h" @@ -14,9 +14,9 @@ * ...::oscilloscope_sensor_definition */ visus::power_overwhelming::oscilloscope_sensor_definition::oscilloscope_sensor_definition( - const wchar_t *description, - const std::uint32_t channel_voltage, - const std::uint32_t channel_current) + _In_z_ const wchar_t *description, + _In_ const std::uint32_t channel_voltage, + _In_ const std::uint32_t channel_current) : _attenuation_current(0.0f), _attenuation_voltage(0.0f), _channel_current(channel_current), @@ -42,9 +42,11 @@ visus::power_overwhelming::oscilloscope_sensor_definition::oscilloscope_sensor_d * ...::oscilloscope_sensor_definition */ visus::power_overwhelming::oscilloscope_sensor_definition::oscilloscope_sensor_definition( - const wchar_t *description, const std::uint32_t channel_voltage, - const float attenuation_voltage, const std::uint32_t channel_current, - const float attenuation_current) + _In_z_ const wchar_t *description, + _In_ const std::uint32_t channel_voltage, + _In_ const float attenuation_voltage, + _In_ const std::uint32_t channel_current, + _In_ const float attenuation_current) : _attenuation_current(attenuation_current), _attenuation_voltage(attenuation_voltage), _channel_current(channel_current), @@ -70,7 +72,7 @@ visus::power_overwhelming::oscilloscope_sensor_definition::oscilloscope_sensor_d * ...::oscilloscope_sensor_definition */ visus::power_overwhelming::oscilloscope_sensor_definition::oscilloscope_sensor_definition( - const oscilloscope_sensor_definition& rhs) : _description(nullptr) { + _In_ const oscilloscope_sensor_definition& rhs) : _description(nullptr) { *this = rhs; } @@ -90,7 +92,7 @@ visus::power_overwhelming::oscilloscope_sensor_definition::~oscilloscope_sensor_ */ visus::power_overwhelming::oscilloscope_sensor_definition& visus::power_overwhelming::oscilloscope_sensor_definition::operator =( - const oscilloscope_sensor_definition& rhs) { + _In_ const oscilloscope_sensor_definition& rhs) { if (this != std::addressof(rhs)) { this->_attenuation_current = rhs._attenuation_current; this->_attenuation_voltage = rhs._attenuation_voltage; diff --git a/power_overwhelming/src/rtb_sensor.cpp b/power_overwhelming/src/rtb_sensor.cpp index f91c6bee..ca0a2591 100644 --- a/power_overwhelming/src/rtb_sensor.cpp +++ b/power_overwhelming/src/rtb_sensor.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/rtb_sensor.h" @@ -23,8 +23,9 @@ * visus::power_overwhelming::rtb_sensor::for_all */ std::size_t visus::power_overwhelming::rtb_sensor::for_all( - rtb_sensor *out_sensors, const std::size_t cnt_sensors, - const std::int32_t timeout) { + _Out_writes_(cntSensors) rtb_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_ const std::int32_t timeout) { // Build the query for all R&S RTB2004 instruments. std::string query("?*::"); // Any protocol query += rohde_und_schwarz; // Only R&S @@ -50,7 +51,18 @@ std::size_t visus::power_overwhelming::rtb_sensor::for_all( * visus::power_overwhelming::rtb_sensor::rtb_sensor */ visus::power_overwhelming::rtb_sensor::rtb_sensor( - const char *path, const std::int32_t timeout) + _In_z_ const char *path, _In_ const std::int32_t timeout) + : detail::visa_sensor(path, timeout) { +#if defined(POWER_OVERWHELMING_WITH_VISA) +#endif /*defined(POWER_OVERWHELMING_WITH_VISA) */ +} + + +/* + * visus::power_overwhelming::rtb_sensor::rtb_sensor + */ +visus::power_overwhelming::rtb_sensor::rtb_sensor( + _In_z_ const wchar_t *path, _In_ const std::int32_t timeout) : detail::visa_sensor(path, timeout) { #if defined(POWER_OVERWHELMING_WITH_VISA) #endif /*defined(POWER_OVERWHELMING_WITH_VISA) */ @@ -67,10 +79,10 @@ visus::power_overwhelming::rtb_sensor::~rtb_sensor(void) { } * visus::power_overwhelming::rtb_sensor::configure */ void visus::power_overwhelming::rtb_sensor::configure( - const oscilloscope_sensor_definition *sensors, - const std::size_t cnt_sensors) { + _In_reads_(cnt) const oscilloscope_sensor_definition *sensors, + _In_ const std::size_t cnt) { #if defined(POWER_OVERWHELMING_WITH_VISA) - if ((cnt_sensors > 0) && (sensors == nullptr)) { + if ((cnt > 0) && (sensors == nullptr)) { throw std::invalid_argument("The sensor definitions must be valid."); } @@ -80,7 +92,7 @@ void visus::power_overwhelming::rtb_sensor::configure( impl.printf("CHAN%u:STAT OFF\n", i); } - for (std::size_t i = 0; i < cnt_sensors; ++i) { + for (std::size_t i = 0; i < cnt; ++i) { { auto c = sensors[i].channel_current(); impl.printf("PROB%u:SET:ATT:UNIT %s\n", c, "A"); @@ -122,8 +134,9 @@ void visus::power_overwhelming::rtb_sensor::configure( * visus::power_overwhelming::rtb_sensor::expression */ void visus::power_overwhelming::rtb_sensor::expression( - const std::uint32_t channel, const char *expression, - const char *unit) { + _In_ const std::uint32_t channel, + _In_opt_z_ const char *expression, + _In_opt_z_ const char *unit) { auto impl = static_cast(*this); if (expression != nullptr) { @@ -149,7 +162,7 @@ void visus::power_overwhelming::rtb_sensor::expression( */ visus::power_overwhelming::measurement visus::power_overwhelming::rtb_sensor::sample( - const timestamp_resolution resolution) const { + _In_ const timestamp_resolution resolution) const { throw "TODO"; } @@ -157,8 +170,8 @@ visus::power_overwhelming::rtb_sensor::sample( /* * visus::power_overwhelming::rtb_sensor::unit */ -void visus::power_overwhelming::rtb_sensor::unit(const std::uint32_t channel, - const char *unit) { +void visus::power_overwhelming::rtb_sensor::unit( + _In_ const std::uint32_t channel, _In_z_ const char *unit) { if (unit == nullptr) { throw std::invalid_argument("The unit for a probe cannot be null."); } diff --git a/power_overwhelming/src/visa_sensor.cpp b/power_overwhelming/src/visa_sensor.cpp index 7df0eb9e..ad22ddf6 100644 --- a/power_overwhelming/src/visa_sensor.cpp +++ b/power_overwhelming/src/visa_sensor.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/visa_sensor.h" @@ -27,20 +27,19 @@ visus::power_overwhelming::detail::visa_sensor::visa_sensor(void) * visus::power_overwhelming::detail::visa_sensor::visa_sensor */ visus::power_overwhelming::detail::visa_sensor::visa_sensor( - const char *path, const std::int32_t timeout) + _In_z_ const char *path, _In_ const std::int32_t timeout) : _impl(new detail::visa_sensor_impl(path, timeout)) { -#if defined(POWER_OVERWHELMING_WITH_VISA) - // Query the instrument name for use a sensor name. - this->_impl->sensor_name = power_overwhelming::convert_string( - this->_impl->identify()); + this->initialise(); +} - // Reset the device to default state, but do not throw. - this->_impl->printf("*RST\n"); - // Clear any error that might have been caused by our setup. We do not want - // to abort just because the display does not look as expected. - this->_impl->clear_status(); -#endif /*defined(POWER_OVERWHELMING_WITH_VISA) */ +/* + * visus::power_overwhelming::detail::visa_sensor::visa_sensor + */ +visus::power_overwhelming::detail::visa_sensor::visa_sensor( + _In_z_ const wchar_t *path, _In_ const std::int32_t timeout) + : _impl(new detail::visa_sensor_impl(path, timeout)) { + this->initialise(); } @@ -55,8 +54,8 @@ visus::power_overwhelming::detail::visa_sensor::~visa_sensor(void) { /* * visus::power_overwhelming::detail::visa_sensor::name */ -const wchar_t *visus::power_overwhelming::detail::visa_sensor::name( - void) const noexcept { +_Ret_maybenull_z_ const wchar_t * +visus::power_overwhelming::detail::visa_sensor::name(void) const noexcept { return (this->_impl != nullptr) ? this->_impl->sensor_name.c_str() : nullptr; @@ -66,8 +65,8 @@ const wchar_t *visus::power_overwhelming::detail::visa_sensor::name( /* * visus::power_overwhelming::detail::visa_sensor::path */ -const char *visus::power_overwhelming::detail::visa_sensor::path( - void) const noexcept { +_Ret_maybenull_z_ const char * +visus::power_overwhelming::detail::visa_sensor::path(void) const noexcept { return (this->_impl != nullptr) ? this->_impl->path.c_str() : nullptr; @@ -88,7 +87,7 @@ void visus::power_overwhelming::detail::visa_sensor::reset(void) { * visus::power_overwhelming::detail::visa_sensor::synchronise_clock */ void visus::power_overwhelming::detail::visa_sensor::synchronise_clock( - const bool utc) { + _In_ const bool utc) { this->check_not_disposed(); #if defined(_WIN32) @@ -136,7 +135,7 @@ void visus::power_overwhelming::detail::visa_sensor::synchronise_clock( */ visus::power_overwhelming::detail::visa_sensor& visus::power_overwhelming::detail::visa_sensor::operator =( - visa_sensor&& rhs) noexcept { + _In_ visa_sensor&& rhs) noexcept { if (this != std::addressof(rhs)) { this->_impl = rhs._impl; rhs._impl = nullptr; @@ -165,6 +164,25 @@ void visus::power_overwhelming::detail::visa_sensor::clear_status(void) { } +/* + * visus::power_overwhelming::detail::visa_sensor::initialise + */ +void visus::power_overwhelming::detail::visa_sensor::initialise(void) { +#if defined(POWER_OVERWHELMING_WITH_VISA) + // Query the instrument name for use a sensor name. + this->_impl->sensor_name = power_overwhelming::convert_string( + this->_impl->identify()); + + // Reset the device to default state, but do not throw. + this->_impl->printf("*RST\n"); + + // Clear any error that might have been caused by our setup. We do not want + // to abort just because the display does not look as expected. + this->_impl->clear_status(); +#endif /*defined(POWER_OVERWHELMING_WITH_VISA) */ +} + + /* * visus::power_overwhelming::detail::visa_sensor::throw_on_system_error */ diff --git a/power_overwhelming/src/visa_sensor_impl.cpp b/power_overwhelming/src/visa_sensor_impl.cpp index d268c46c..b52f2fae 100644 --- a/power_overwhelming/src/visa_sensor_impl.cpp +++ b/power_overwhelming/src/visa_sensor_impl.cpp @@ -1,12 +1,14 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "visa_sensor_impl.h" #include +#include "power_overwhelming/convert_string.h" + /* * visus::power_overwhelming::detail::visa_sensor_impl::visa_sensor_impl @@ -18,6 +20,17 @@ visus::power_overwhelming::detail::visa_sensor_impl::visa_sensor_impl( } +/* + * visus::power_overwhelming::detail::visa_sensor_impl::visa_sensor_impl + */ +visus::power_overwhelming::detail::visa_sensor_impl::visa_sensor_impl( + const wchar_t *path, const std::int32_t timeout) + : scope(power_overwhelming::convert_string(path).c_str(), timeout), + path(power_overwhelming::convert_string(path)) { + this->clear(); +} + + /* * visus::power_overwhelming::detail::visa_sensor_impl::clear */ diff --git a/power_overwhelming/src/visa_sensor_impl.h b/power_overwhelming/src/visa_sensor_impl.h index 756aa1c3..d472669b 100644 --- a/power_overwhelming/src/visa_sensor_impl.h +++ b/power_overwhelming/src/visa_sensor_impl.h @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #pragma once @@ -45,9 +45,13 @@ namespace detail { /// /// Initialises a new instance. /// - /// visa_sensor_impl(const char *path, const std::int32_t timeout); + /// + /// Initialises a new instance. + /// + visa_sensor_impl(const wchar_t *path, const std::int32_t timeout); + /// /// Call on the instrument, which will flush all /// buffers. From 19877f1021c65b5ec33e082c4c6167e7eff7dd8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 11:39:57 +0100 Subject: [PATCH 17/24] Annotated sensor::sample. --- power_overwhelming/include/power_overwhelming/sensor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/power_overwhelming/include/power_overwhelming/sensor.h b/power_overwhelming/include/power_overwhelming/sensor.h index 94bfc6d7..960764b0 100644 --- a/power_overwhelming/include/power_overwhelming/sensor.h +++ b/power_overwhelming/include/power_overwhelming/sensor.h @@ -68,7 +68,7 @@ namespace power_overwhelming { /// If a sensor based on a VISA /// instrument could not be sampled. virtual measurement sample( - const timestamp_resolution resolution) const = 0; + _In_ const timestamp_resolution resolution) const = 0; /// /// Sample the sensor using a timestamp with millisecond resolution. From 7e4b3f5e36e847af35da81e914a3fce4bee25f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 11:46:26 +0100 Subject: [PATCH 18/24] Annotated and fixed stable_power_state_scope. --- .../stable_power_state_scope.h | 6 ++-- power_overwhelming/src/Output-Build.txt | 13 ++++++++ .../src/stable_power_state_scope.cpp | 30 ++++++++++++------- 3 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 power_overwhelming/src/Output-Build.txt diff --git a/power_overwhelming/include/power_overwhelming/stable_power_state_scope.h b/power_overwhelming/include/power_overwhelming/stable_power_state_scope.h index 144c0d9f..cbf233c5 100644 --- a/power_overwhelming/include/power_overwhelming/stable_power_state_scope.h +++ b/power_overwhelming/include/power_overwhelming/stable_power_state_scope.h @@ -32,7 +32,7 @@ namespace power_overwhelming { /// /// The device to be put into a stable power /// state. - stable_power_state_scope(graphics_device& device); + stable_power_state_scope(_In_ graphics_device& device); stable_power_state_scope(const stable_power_state_scope&) = delete; @@ -50,12 +50,12 @@ namespace power_overwhelming { return this->_cnt_devices; } - stable_power_state_scope &operator =( + stable_power_state_scope& operator =( const stable_power_state_scope&) = delete; private: - void enable(graphics_device::device_type *device); + void enable(_In_ graphics_device::device_type *device); std::size_t _cnt_devices; graphics_device *_devices; diff --git a/power_overwhelming/src/Output-Build.txt b/power_overwhelming/src/Output-Build.txt new file mode 100644 index 00000000..4bb82975 --- /dev/null +++ b/power_overwhelming/src/Output-Build.txt @@ -0,0 +1,13 @@ +Build started... +1>------ Build started: Project: power_overwhelming, Configuration: Debug x64 ------ +1>adl_sensor.cpp +1>collector.cpp +1>collector_impl.cpp +1>collector_settings.cpp +1>dump_sensors.cpp +1>emi_sampler_context.cpp +1>emi_sensor.cpp +1>emi_sensor_impl.cpp +1>hmc8015_sensor.cpp +1>nvml_sensor.cpp +1>rtb_sensor.cpp diff --git a/power_overwhelming/src/stable_power_state_scope.cpp b/power_overwhelming/src/stable_power_state_scope.cpp index 935388a2..42ece539 100644 --- a/power_overwhelming/src/stable_power_state_scope.cpp +++ b/power_overwhelming/src/stable_power_state_scope.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2022 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/stable_power_state_scope.h" @@ -23,8 +23,14 @@ visus::power_overwhelming::stable_power_state_scope::stable_power_state_scope( devices.resize(graphics_device::all(nullptr, 0, true)); graphics_device::all(devices.data(), devices.size(), true); - for (auto& d : devices) { - this->enable(d); + for (auto it = devices.begin(); it != devices.end(); ) { + auto d = static_cast(*it); + if (d != nullptr) { + this->enable(d); + ++it; + } else { + it = devices.erase(it); + } } this->_devices = new graphics_device[devices.size()]; @@ -37,12 +43,14 @@ visus::power_overwhelming::stable_power_state_scope::stable_power_state_scope( * visus::power_overwhelming::stable_power_state_scope::stable_power_state_scope */ visus::power_overwhelming::stable_power_state_scope::stable_power_state_scope( - graphics_device& device) : _cnt_devices(0), _devices(nullptr) { - this->enable(device); + _In_ graphics_device& device) : _cnt_devices(0), _devices(nullptr) { + if (device != nullptr) { + this->enable(device); - this->_devices = new graphics_device[1]; - this->_cnt_devices = 1; - this->_devices[0] = device; + this->_devices = new graphics_device[1]; + this->_cnt_devices = 1; + this->_devices[0] = device; + } } @@ -59,7 +67,7 @@ visus::power_overwhelming::stable_power_state_scope::~stable_power_state_scope( * visus::power_overwhelming::stable_power_state_scope::enable */ void visus::power_overwhelming::stable_power_state_scope::enable( - graphics_device::device_type *device) { + _In_ graphics_device::device_type *device) { #if (POWER_OVERWHELMING_GPU_ABSTRACTION == 12) if (device == nullptr) { throw std::invalid_argument("A valid Direct3D 12 device must be " From 12b01dbb7c44a6760e858c7e2fe367e8a4e70c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 11:48:34 +0100 Subject: [PATCH 19/24] Annotated time_synchroniser --- .../include/power_overwhelming/time_synchroniser.h | 10 +++++----- power_overwhelming/src/time_synchroniser.cpp | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/time_synchroniser.h b/power_overwhelming/include/power_overwhelming/time_synchroniser.h index ca5d3a02..56c500b2 100644 --- a/power_overwhelming/include/power_overwhelming/time_synchroniser.h +++ b/power_overwhelming/include/power_overwhelming/time_synchroniser.h @@ -1,5 +1,5 @@ // -// Copyright © 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2022 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -24,8 +24,8 @@ namespace power_overwhelming { public: - static time_synchroniser create(const int address_family, - const std::uint16_t port); + static time_synchroniser create(_In_ const int address_family, + _In_ const std::uint16_t port); /// /// Initialise a new instance. @@ -44,7 +44,7 @@ namespace power_overwhelming { /// /// /// - inline time_synchroniser(time_synchroniser&& rhs) noexcept + inline time_synchroniser(_In_ time_synchroniser&& rhs) noexcept : _impl(rhs._impl) { rhs._impl = nullptr; } @@ -61,7 +61,7 @@ namespace power_overwhelming { /// /// The right-hand side operand /// *this - time_synchroniser& operator =(time_synchroniser&& rhs) noexcept; + time_synchroniser& operator =(_In_ time_synchroniser&& rhs) noexcept; /// /// Determines whether the object is valid. diff --git a/power_overwhelming/src/time_synchroniser.cpp b/power_overwhelming/src/time_synchroniser.cpp index 1590e6da..05a8c332 100644 --- a/power_overwhelming/src/time_synchroniser.cpp +++ b/power_overwhelming/src/time_synchroniser.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2022 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/time_synchroniser.h" @@ -12,8 +12,9 @@ * visus::power_overwhelming::time_synchroniser::create */ visus::power_overwhelming::time_synchroniser -visus::power_overwhelming::time_synchroniser::create(const int address_family, - const std::uint16_t port) { +visus::power_overwhelming::time_synchroniser::create( + _In_ const int address_family, + _In_ const std::uint16_t port) { time_synchroniser retval; #if defined(POWER_OVERWHELMING_WITH_TIME_SYNCHRONISER) @@ -43,7 +44,7 @@ visus::power_overwhelming::time_synchroniser::~time_synchroniser(void) { */ visus::power_overwhelming::time_synchroniser& visus::power_overwhelming::time_synchroniser::operator =( - time_synchroniser&& rhs) noexcept { + _In_ time_synchroniser&& rhs) noexcept { if (this != std::addressof(rhs)) { this->_impl = rhs._impl; rhs._impl = nullptr; From b657de710883ece5b6828d14b8022777d7c69f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 11:53:20 +0100 Subject: [PATCH 20/24] Annotated tinkerforge_display. --- .../power_overwhelming/timestamp_resolution.h | 6 ++-- .../power_overwhelming/tinkerforge_display.h | 28 ++++++++++------- .../src/tinkerforge_display.cpp | 30 ++++++++++++------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/timestamp_resolution.h b/power_overwhelming/include/power_overwhelming/timestamp_resolution.h index b5dc37c8..69645e70 100644 --- a/power_overwhelming/include/power_overwhelming/timestamp_resolution.h +++ b/power_overwhelming/include/power_overwhelming/timestamp_resolution.h @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #pragma once diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_display.h b/power_overwhelming/include/power_overwhelming/tinkerforge_display.h index 512fdfb5..eb007955 100644 --- a/power_overwhelming/include/power_overwhelming/tinkerforge_display.h +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_display.h @@ -47,10 +47,12 @@ namespace power_overwhelming { /// /// /// - static std::size_t for_all(tinkerforge_display *out_displays, - const std::size_t cnt_displays, const char *host = default_host, - const std::uint16_t port = default_port, - const std::size_t timeout = 1000); + static std::size_t for_all( + _Out_writes_(cnt_displays) tinkerforge_display *out_displays, + _In_ const std::size_t cnt_displays, + _In_opt_z_ const char *host = default_host, + _In_ const std::uint16_t port = default_port, + _In_ const std::size_t timeout = 1000); /// /// Initialises a new instance. @@ -72,14 +74,15 @@ namespace power_overwhelming { /// be allocated. /// If the connection to the /// master brick could not be established. - tinkerforge_display(const char *uid, const char *host = default_host, - const std::uint16_t port = default_port); + tinkerforge_display(_In_z_ const char *uid, + _In_opt_z_ const char *host = default_host, + _In_ const std::uint16_t port = default_port); /// /// Move into a new instance. /// /// The object to be moved. - inline tinkerforge_display(tinkerforge_display&& rhs) noexcept + inline tinkerforge_display(_In_ tinkerforge_display&& rhs) noexcept : _impl(rhs._impl) { rhs._impl = nullptr; } @@ -99,16 +102,19 @@ namespace power_overwhelming { /// one of the constants like LCD_128X64_FONT_6X8. /// If true (the default), print the text /// in black. Otherwise, print in white. - void print(const char *text, const std::uint8_t x = 0, - const std::uint8_t y = 0, const std::uint8_t font = 0, - const bool colour = true); + void print(_In_z_ const char *text, + _In_ const std::uint8_t x = 0, + _In_ const std::uint8_t y = 0, + _In_ const std::uint8_t font = 0, + _In_ const bool colour = true); /// /// Move assignment. /// /// The right-hand side operand /// *this - tinkerforge_display& operator =(tinkerforge_display&& rhs) noexcept; + tinkerforge_display& operator =( + _In_ tinkerforge_display&& rhs) noexcept; /// /// Determines whether the LCD display is valid. diff --git a/power_overwhelming/src/tinkerforge_display.cpp b/power_overwhelming/src/tinkerforge_display.cpp index e9de3675..75366de9 100644 --- a/power_overwhelming/src/tinkerforge_display.cpp +++ b/power_overwhelming/src/tinkerforge_display.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/tinkerforge_display.h" @@ -17,8 +17,11 @@ * visus::power_overwhelming::tinkerforge_display::for_all */ std::size_t visus::power_overwhelming::tinkerforge_display::for_all( - tinkerforge_display *out_displays, const std::size_t cnt_displays, - const char *host, const std::uint16_t port, const std::size_t timeout) { + _Out_writes_(cnt_displays) tinkerforge_display *out_displays, + _In_ const std::size_t cnt_displays, + _In_opt_z_ const char *host, + _In_ const std::uint16_t port, + _In_ const std::size_t timeout) { std::vector bricklets; const std::string safe_host = (host != nullptr) ? host : default_host; detail::tinkerforge_scope scope(safe_host, port); @@ -43,7 +46,9 @@ std::size_t visus::power_overwhelming::tinkerforge_display::for_all( * visus::power_overwhelming::tinkerforge_display::tinkerforge_display */ visus::power_overwhelming::tinkerforge_display::tinkerforge_display( - const char *uid, const char *host, const std::uint16_t port) + _In_z_ const char *uid, + _In_opt_z_ const char *host, + _In_ const std::uint16_t port) : _impl(nullptr) { this->_impl = new detail::tinkerforge_display_impl( (host != nullptr) ? host : default_host, @@ -71,9 +76,12 @@ void visus::power_overwhelming::tinkerforge_display::clear(void) { /* * visus::power_overwhelming::tinkerforge_display::print */ -void visus::power_overwhelming::tinkerforge_display::print(const char *text, - const std::uint8_t x, const std::uint8_t y, const std::uint8_t font, - const bool colour) { +void visus::power_overwhelming::tinkerforge_display::print( + _In_z_ const char *text, + _In_ const std::uint8_t x, + _In_ const std::uint8_t y, + _In_ const std::uint8_t font, + _In_ const bool colour) { if (!*this) { throw std::runtime_error("A disposed instance of tinkerforge_display " "cannot be used to print text."); @@ -91,11 +99,11 @@ void visus::power_overwhelming::tinkerforge_display::print(const char *text, /* - * + * visus::power_overwhelming::tinkerforge_display::operator = */ visus::power_overwhelming::tinkerforge_display& visus::power_overwhelming::tinkerforge_display::operator =( - tinkerforge_display&& rhs) noexcept { + _In_ tinkerforge_display&& rhs) noexcept { if (this != std::addressof(rhs)) { this->_impl = rhs._impl; rhs._impl = nullptr; From 5526c0556d43e4b2664197ffe975f9030867ac21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 12:05:16 +0100 Subject: [PATCH 21/24] Fix typo in class name. --- README.md | 2 +- podump/tinkerforge.cpp | 4 +- .../power_overwhelming/tinkerforge_sensor.h | 8 +- .../tinkerforge_sensor_definition.h | 114 ++++++++++++++++++ .../tinkerforge_sensor_definiton.h | 103 +--------------- .../tinkerforge_sensor_source.h | 16 +-- power_overwhelming/src/sensor_desc.h | 2 +- power_overwhelming/src/tinkerforge_sensor.cpp | 14 +-- ....cpp => tinkerforge_sensor_definition.cpp} | 42 +++---- .../src/tinkerforge_sensor_source.cpp | 18 +-- test/pch.h | 2 +- test/tinkerforge_sensor_definition_test.cpp | 24 ++-- 12 files changed, 186 insertions(+), 163 deletions(-) create mode 100644 power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definition.h rename power_overwhelming/src/{tinkerforge_sensor_definiton.cpp => tinkerforge_sensor_definition.cpp} (55%) diff --git a/README.md b/README.md index 3bfd4256..94e32181 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Some sensors have a slightly different API. For instance, sensors using *Tinkerf ```c++ using namespace visus::power_overwhelming; -std::vector descs; +std::vector descs; // Call 'get_definitions' to find out how many definitions there are. descs.resize(tinkerforge_sensor::get_definitions(nullptr, 0)); // Call 'get_definitions' to get the actual descriptors. diff --git a/podump/tinkerforge.cpp b/podump/tinkerforge.cpp index 4b54d1ca..d3cc0fee 100644 --- a/podump/tinkerforge.cpp +++ b/podump/tinkerforge.cpp @@ -14,7 +14,7 @@ void sample_tinkerforge_sensor(void) { using namespace visus::power_overwhelming; try { - std::vector descs; + std::vector descs; descs.resize(tinkerforge_sensor::get_definitions(nullptr, 0)); auto cnt = tinkerforge_sensor::get_definitions(descs.data(), descs.size()); @@ -47,7 +47,7 @@ void sample_tinkerforge_sensor_async(const unsigned int dt) { using namespace visus::power_overwhelming; try { - std::vector descs; + std::vector descs; std::vector sensors; descs.resize(tinkerforge_sensor::get_definitions(nullptr, 0)); auto cnt = tinkerforge_sensor::get_definitions(descs.data(), diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor.h b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor.h index e6f4091f..d758e3fd 100644 --- a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor.h +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor.h @@ -1,5 +1,5 @@ // -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -8,7 +8,7 @@ #include "power_overwhelming/conversion_time.h" #include "power_overwhelming/sample_averaging.h" #include "power_overwhelming/sensor.h" -#include "power_overwhelming/tinkerforge_sensor_definiton.h" +#include "power_overwhelming/tinkerforge_sensor_definition.h" #include "power_overwhelming/tinkerforge_sensor_source.h" @@ -138,7 +138,7 @@ namespace power_overwhelming { /// The number of current/voltage bricklets available, /// regardless of how many have been copied. static std::size_t get_definitions( - tinkerforge_sensor_definiton *out_definitions, + tinkerforge_sensor_definition *out_definitions, const std::size_t cnt_definitions, const std::size_t timeout = 1000, const char *host = default_host, const std::uint16_t port = default_port); @@ -203,7 +203,7 @@ namespace power_overwhelming { /// be allocated. /// If the connection to the /// master brick could not be established. - tinkerforge_sensor(const tinkerforge_sensor_definiton& definition, + tinkerforge_sensor(const tinkerforge_sensor_definition& definition, const char *host = default_host, const std::uint16_t port = default_port); diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definition.h b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definition.h new file mode 100644 index 00000000..53484b1d --- /dev/null +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definition.h @@ -0,0 +1,114 @@ +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Christoph Müller + +#pragma once + +#include "power_overwhelming/power_overwhelming_api.h" + + +namespace visus { +namespace power_overwhelming { + + /// + /// Definition of a Tinkerforge sensor allowing the sensor UID and a + /// description to be specified at the same time. + /// + class POWER_OVERWHELMING_API tinkerforge_sensor_definition final { + + public: + + /// + /// Initialises a new instance. + /// + inline tinkerforge_sensor_definition(void) + : _description(nullptr), _uid(nullptr) { } + + /// + /// Initialises a new instance. + /// + /// The UID of the sensor. + /// If + /// is nullptr. + /// If the memory for the UID + /// could not be allocated. + tinkerforge_sensor_definition(const char *uid); + + /// + /// Clone . + /// + /// The object to be cloned. + /// If the memory for the copied data + /// could not be allocated. + tinkerforge_sensor_definition(const tinkerforge_sensor_definition& rhs); + + /// + /// Move into a new object. + /// + /// The object to be moved. + inline tinkerforge_sensor_definition( + tinkerforge_sensor_definition&& rhs) noexcept + : _description(rhs._description), _uid(rhs._uid) { + rhs._description = nullptr; + rhs._uid = nullptr; + } + + /// + /// Finalises the instance. + /// + ~tinkerforge_sensor_definition(void); + + /// + /// Gets the user-defined description of the sensor. + /// + /// The description of the sensor. The object remains owner of + /// the memory returned. + const wchar_t *description(void) const noexcept { + return this->_description; + } + + /// + /// Sets the user-defined description of the sensor. + /// + /// The new description of the sensor. It is + /// safe to pass nullptr. + /// If the memory for the description + /// could not be allocated. + void description(const wchar_t *description); + + /// + /// Gets the UID of the sensor. + /// + /// The UID of the sensor. The object remains owner of the + /// memory returned. + const char *uid(void) const noexcept { + return this->_uid; + } + + /// + /// Assignment operator. + /// + /// The right-hand side operand. + /// *this + /// If the memory for the copied data + /// could not be allocated. + tinkerforge_sensor_definition& operator =( + const tinkerforge_sensor_definition& rhs); + + /// + /// Move-assignment operator. + /// + /// The right-hand side operand. + /// *this + tinkerforge_sensor_definition& operator =( + tinkerforge_sensor_definition&& rhs) noexcept; + + private: + + wchar_t *_description; + char *_uid; + }; + +} /* namespace power_overwhelming */ +} /* namespace visus */ diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definiton.h b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definiton.h index cc0d95ff..aabac900 100644 --- a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definiton.h +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definiton.h @@ -1,114 +1,21 @@ // -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller #pragma once -#include "power_overwhelming/power_overwhelming_api.h" +#include "power_overwhelming/tinkerforge_sensor_definition.h" namespace visus { namespace power_overwhelming { /// - /// Definition of a Tinkerforge sensor allowing the sensor UID and a - /// description to be specified at the same time. + /// Provides backwards compatibility for a typo in a previous version of + /// the API. /// - class POWER_OVERWHELMING_API tinkerforge_sensor_definiton final { - - public: - - /// - /// Initialises a new instance. - /// - inline tinkerforge_sensor_definiton(void) - : _description(nullptr), _uid(nullptr) { } - - /// - /// Initialises a new instance. - /// - /// The UID of the sensor. - /// If - /// is nullptr. - /// If the memory for the UID - /// could not be allocated. - tinkerforge_sensor_definiton(const char *uid); - - /// - /// Clone . - /// - /// The object to be cloned. - /// If the memory for the copied data - /// could not be allocated. - tinkerforge_sensor_definiton(const tinkerforge_sensor_definiton& rhs); - - /// - /// Move into a new object. - /// - /// The object to be moved. - inline tinkerforge_sensor_definiton( - tinkerforge_sensor_definiton&& rhs) noexcept - : _description(rhs._description), _uid(rhs._uid) { - rhs._description = nullptr; - rhs._uid = nullptr; - } - - /// - /// Finalises the instance. - /// - ~tinkerforge_sensor_definiton(void); - - /// - /// Gets the user-defined description of the sensor. - /// - /// The description of the sensor. The object remains owner of - /// the memory returned. - const wchar_t *description(void) const noexcept { - return this->_description; - } - - /// - /// Sets the user-defined description of the sensor. - /// - /// The new description of the sensor. It is - /// safe to pass nullptr. - /// If the memory for the description - /// could not be allocated. - void description(const wchar_t *description); - - /// - /// Gets the UID of the sensor. - /// - /// The UID of the sensor. The object remains owner of the - /// memory returned. - const char *uid(void) const noexcept { - return this->_uid; - } - - /// - /// Assignment operator. - /// - /// The right-hand side operand. - /// *this - /// If the memory for the copied data - /// could not be allocated. - tinkerforge_sensor_definiton& operator =( - const tinkerforge_sensor_definiton& rhs); - - /// - /// Move-assignment operator. - /// - /// The right-hand side operand. - /// *this - tinkerforge_sensor_definiton& operator =( - tinkerforge_sensor_definiton&& rhs) noexcept; - - private: - - wchar_t *_description; - char *_uid; - }; + typedef tinkerforge_sensor_definition tinkerforge_sensor_definiton; } /* namespace power_overwhelming */ } /* namespace visus */ diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_source.h b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_source.h index 3da7b729..3ee3e077 100644 --- a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_source.h +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_source.h @@ -1,5 +1,5 @@ // -// Copyright © 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2022 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -46,8 +46,8 @@ namespace power_overwhelming { /// /// POWER_OVERWHELMING_API tinkerforge_sensor_source operator |( - const tinkerforge_sensor_source lhs, - const tinkerforge_sensor_source rhs); + _In_ const tinkerforge_sensor_source lhs, + _In_ const tinkerforge_sensor_source rhs); /// /// Test two s. @@ -56,8 +56,8 @@ namespace power_overwhelming { /// /// POWER_OVERWHELMING_API tinkerforge_sensor_source operator &( - const tinkerforge_sensor_source lhs, - const tinkerforge_sensor_source rhs); + _In_ const tinkerforge_sensor_source lhs, + _In_ const tinkerforge_sensor_source rhs); /// /// Convert the given sensor source to a human-readable string @@ -65,8 +65,10 @@ namespace power_overwhelming { /// /// The source to be converted. /// The name of the source. - extern POWER_OVERWHELMING_API const wchar_t *to_string( - const tinkerforge_sensor_source source); + /// If the source is not + /// valid and therefore could not be converted. + extern POWER_OVERWHELMING_API _Ret_ const wchar_t *to_string( + _In_ const tinkerforge_sensor_source source); } /* namespace power_overwhelming */ } /* namespace visus */ diff --git a/power_overwhelming/src/sensor_desc.h b/power_overwhelming/src/sensor_desc.h index b779916b..7fb5d5f8 100644 --- a/power_overwhelming/src/sensor_desc.h +++ b/power_overwhelming/src/sensor_desc.h @@ -345,7 +345,7 @@ namespace detail { // We do not need to create the sensor to write its properties, // the definition and the API for the sensor name suffice. - std::vector descs; + std::vector descs; descs.resize(tinkerforge_sensor::get_definitions(nullptr, 0)); const auto cnt = tinkerforge_sensor::get_definitions(descs.data(), descs.size()); diff --git a/power_overwhelming/src/tinkerforge_sensor.cpp b/power_overwhelming/src/tinkerforge_sensor.cpp index 4d9edf1f..b9474ad6 100644 --- a/power_overwhelming/src/tinkerforge_sensor.cpp +++ b/power_overwhelming/src/tinkerforge_sensor.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/tinkerforge_sensor.h" @@ -30,7 +30,7 @@ std::size_t visus::power_overwhelming::tinkerforge_sensor::for_all( port); } else { - std::vector descs(cnt_sensors); + std::vector descs(cnt_sensors); auto retval = tinkerforge_sensor::get_definitions(descs.data(), descs.size(), timeout, host, port); @@ -53,7 +53,7 @@ std::size_t visus::power_overwhelming::tinkerforge_sensor::for_all( * visus::power_overwhelming::tinkerforge_sensor::get_definitions */ std::size_t visus::power_overwhelming::tinkerforge_sensor::get_definitions( - tinkerforge_sensor_definiton *out_definitions, + tinkerforge_sensor_definition *out_definitions, const std::size_t cnt_definitions, const std::size_t timeout, const char *host, const std::uint16_t port) { std::vector bricklets; @@ -66,7 +66,7 @@ std::size_t visus::power_overwhelming::tinkerforge_sensor::get_definitions( if (out_definitions != nullptr) { for (std::size_t i = 0; (i < cnt_definitions) && (i < retval); ++i) { - out_definitions[i] = tinkerforge_sensor_definiton( + out_definitions[i] = tinkerforge_sensor_definition( bricklets[i].uid().c_str()); } } @@ -112,7 +112,7 @@ visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor( * visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor */ visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor( - const tinkerforge_sensor_definiton& definition, + const tinkerforge_sensor_definition& definition, const char *host, const std::uint16_t port) : _impl(nullptr) { this->_impl = new detail::tinkerforge_sensor_impl( (host != nullptr) ? host : default_host, diff --git a/power_overwhelming/src/tinkerforge_sensor_definiton.cpp b/power_overwhelming/src/tinkerforge_sensor_definition.cpp similarity index 55% rename from power_overwhelming/src/tinkerforge_sensor_definiton.cpp rename to power_overwhelming/src/tinkerforge_sensor_definition.cpp index 12ae726f..036e1e5a 100644 --- a/power_overwhelming/src/tinkerforge_sensor_definiton.cpp +++ b/power_overwhelming/src/tinkerforge_sensor_definition.cpp @@ -1,9 +1,9 @@ -// -// Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2021 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller -#include "power_overwhelming/tinkerforge_sensor_definiton.h" +#include "power_overwhelming/tinkerforge_sensor_definition.h" #include #include @@ -11,9 +11,9 @@ /* - * ...::tinkerforge_sensor_definiton::tinkerforge_sensor_definiton + * ...::tinkerforge_sensor_definition::tinkerforge_sensor_definition */ -visus::power_overwhelming::tinkerforge_sensor_definiton::tinkerforge_sensor_definiton( +visus::power_overwhelming::tinkerforge_sensor_definition::tinkerforge_sensor_definition( const char *uid) : _description(nullptr), _uid(nullptr) { if (uid == nullptr) { throw std::invalid_argument("The UID of a Tinkerforge sensor cannot " @@ -28,19 +28,19 @@ visus::power_overwhelming::tinkerforge_sensor_definiton::tinkerforge_sensor_defi /* - * ...::tinkerforge_sensor_definiton::tinkerforge_sensor_definiton + * ...::tinkerforge_sensor_definition::tinkerforge_sensor_definition */ -visus::power_overwhelming::tinkerforge_sensor_definiton::tinkerforge_sensor_definiton( - const tinkerforge_sensor_definiton& rhs) +visus::power_overwhelming::tinkerforge_sensor_definition::tinkerforge_sensor_definition( + const tinkerforge_sensor_definition& rhs) : _description(nullptr), _uid(nullptr) { *this = rhs; } /* - * ...::tinkerforge_sensor_definiton::~tinkerforge_sensor_definiton + * ...::tinkerforge_sensor_definition::~tinkerforge_sensor_definition */ -visus::power_overwhelming::tinkerforge_sensor_definiton::~tinkerforge_sensor_definiton( +visus::power_overwhelming::tinkerforge_sensor_definition::~tinkerforge_sensor_definition( void) { if (this->_description != nullptr) { ::free(this->_description); @@ -52,9 +52,9 @@ visus::power_overwhelming::tinkerforge_sensor_definiton::~tinkerforge_sensor_def /* - * visus::power_overwhelming::tinkerforge_sensor_definiton::description + * visus::power_overwhelming::tinkerforge_sensor_definition::description */ -void visus::power_overwhelming::tinkerforge_sensor_definiton::description( +void visus::power_overwhelming::tinkerforge_sensor_definition::description( const wchar_t *description) { if (this->_description != nullptr) { ::free(this->_description); @@ -73,11 +73,11 @@ void visus::power_overwhelming::tinkerforge_sensor_definiton::description( /* - * visus::power_overwhelming::tinkerforge_sensor_definiton::operator = + * visus::power_overwhelming::tinkerforge_sensor_definition::operator = */ -visus::power_overwhelming::tinkerforge_sensor_definiton& -visus::power_overwhelming::tinkerforge_sensor_definiton::operator =( - const tinkerforge_sensor_definiton& rhs) { +visus::power_overwhelming::tinkerforge_sensor_definition& +visus::power_overwhelming::tinkerforge_sensor_definition::operator =( + const tinkerforge_sensor_definition& rhs) { if (this != std::addressof(rhs)) { this->description(rhs._description); @@ -101,11 +101,11 @@ visus::power_overwhelming::tinkerforge_sensor_definiton::operator =( /* - * visus::power_overwhelming::tinkerforge_sensor_definiton::operator = + * visus::power_overwhelming::tinkerforge_sensor_definition::operator = */ -visus::power_overwhelming::tinkerforge_sensor_definiton& -visus::power_overwhelming::tinkerforge_sensor_definiton::operator =( - tinkerforge_sensor_definiton&& rhs) noexcept { +visus::power_overwhelming::tinkerforge_sensor_definition& +visus::power_overwhelming::tinkerforge_sensor_definition::operator =( + tinkerforge_sensor_definition&& rhs) noexcept { if (this != std::addressof(rhs)) { if (this->_description != nullptr) { ::free(this->_description); diff --git a/power_overwhelming/src/tinkerforge_sensor_source.cpp b/power_overwhelming/src/tinkerforge_sensor_source.cpp index 3442d870..32098ef4 100644 --- a/power_overwhelming/src/tinkerforge_sensor_source.cpp +++ b/power_overwhelming/src/tinkerforge_sensor_source.cpp @@ -1,7 +1,7 @@ -// -// Copyright © 2022 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// +// Copyright © 2022 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // -// Christoph Müller +// Christoph Müller #include "power_overwhelming/tinkerforge_sensor_source.h" @@ -13,8 +13,8 @@ * visus::power_overwhelming::operator | */ visus::power_overwhelming::tinkerforge_sensor_source -visus::power_overwhelming::operator |(const tinkerforge_sensor_source lhs, - const tinkerforge_sensor_source rhs) { +visus::power_overwhelming::operator |(_In_ const tinkerforge_sensor_source lhs, + _In_ const tinkerforge_sensor_source rhs) { typedef std::underlying_type::type mask_type; auto retval = static_cast(lhs) | static_cast(rhs); return static_cast(retval); @@ -25,8 +25,8 @@ visus::power_overwhelming::operator |(const tinkerforge_sensor_source lhs, * visus::power_overwhelming::operator & */ visus::power_overwhelming::tinkerforge_sensor_source -visus::power_overwhelming::operator &(const tinkerforge_sensor_source lhs, - const tinkerforge_sensor_source rhs) { +visus::power_overwhelming::operator &(_In_ const tinkerforge_sensor_source lhs, + _In_ const tinkerforge_sensor_source rhs) { typedef std::underlying_type::type mask_type; auto retval = static_cast(lhs) & static_cast(rhs); return static_cast(retval); @@ -36,8 +36,8 @@ visus::power_overwhelming::operator &(const tinkerforge_sensor_source lhs, /* * visus::power_overwhelming::to_string */ -const wchar_t *visus::power_overwhelming::to_string( - const tinkerforge_sensor_source source) { +_Ret_ const wchar_t *visus::power_overwhelming::to_string( + _In_ const tinkerforge_sensor_source source) { #define _GCC_IS_SHIT(v) L##v #define _TO_STRING_CASE(v) case tinkerforge_sensor_source::v:\ return _GCC_IS_SHIT(#v) diff --git a/test/pch.h b/test/pch.h index 26db4781..f2da928d 100644 --- a/test/pch.h +++ b/test/pch.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include diff --git a/test/tinkerforge_sensor_definition_test.cpp b/test/tinkerforge_sensor_definition_test.cpp index ebc3b7aa..5d0c7d57 100644 --- a/test/tinkerforge_sensor_definition_test.cpp +++ b/test/tinkerforge_sensor_definition_test.cpp @@ -1,4 +1,4 @@ -// +// // Copyright © 2021 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller @@ -13,41 +13,41 @@ namespace visus { namespace power_overwhelming { namespace test { - TEST_CLASS(tinkerforge_sensor_definiton_test) { + TEST_CLASS(tinkerforge_sensor_definition_test) { public: TEST_METHOD(test_ctor) { { - tinkerforge_sensor_definiton d; + tinkerforge_sensor_definition d; Assert::IsNull(d.description(), L"Description is nullptr", LINE_INFO()); Assert::IsNull(d.uid(), L"UID is nullptr", LINE_INFO()); } { - tinkerforge_sensor_definiton d("horst"); + tinkerforge_sensor_definition d("horst"); Assert::IsNull(d.description(), L"Description is nullptr", LINE_INFO()); Assert::AreEqual("horst", d.uid(), L"UID is \"horst\"", LINE_INFO()); } { - tinkerforge_sensor_definiton d("horst"); + tinkerforge_sensor_definition d("horst"); d.description(L"Hugo"); Assert::AreEqual(L"Hugo", d.description(), L"Description is \"Hugo\"", LINE_INFO()); Assert::AreEqual("horst", d.uid(), L"UID is \"horst\"", LINE_INFO()); - tinkerforge_sensor_definiton dd(d); + tinkerforge_sensor_definition dd(d); Assert::AreEqual(d.description(), dd.description(), L"Description copied", LINE_INFO()); Assert::AreEqual(d.uid(), dd.uid(), L"UID copied", LINE_INFO()); } { - tinkerforge_sensor_definiton d("horst"); + tinkerforge_sensor_definition d("horst"); d.description(L"Hugo"); Assert::AreEqual(L"Hugo", d.description(), L"Description is \"Hugo\"", LINE_INFO()); Assert::AreEqual("horst", d.uid(), L"UID is \"horst\"", LINE_INFO()); - tinkerforge_sensor_definiton dd(std::move(d)); + tinkerforge_sensor_definition dd(std::move(d)); Assert::AreEqual(L"Hugo", dd.description(), L"Description is \"Hugo\"", LINE_INFO()); Assert::AreEqual("horst", dd.uid(), L"UID is \"horst\"", LINE_INFO()); Assert::IsNull(d.description(), L"Description source erased.", LINE_INFO()); @@ -57,12 +57,12 @@ namespace test { TEST_METHOD(test_assignment) { { - tinkerforge_sensor_definiton d("horst"); + tinkerforge_sensor_definition d("horst"); d.description(L"Hugo"); Assert::AreEqual(L"Hugo", d.description(), L"Description is \"Hugo\"", LINE_INFO()); Assert::AreEqual("horst", d.uid(), L"UID is \"horst\"", LINE_INFO()); - tinkerforge_sensor_definiton dd; + tinkerforge_sensor_definition dd; Assert::IsNull(dd.description(), L"Description is nullptr", LINE_INFO()); Assert::IsNull(dd.uid(), L"UID is nullptr", LINE_INFO()); @@ -72,12 +72,12 @@ namespace test { } { - tinkerforge_sensor_definiton d("horst"); + tinkerforge_sensor_definition d("horst"); d.description(L"Hugo"); Assert::AreEqual(L"Hugo", d.description(), L"Description is \"Hugo\"", LINE_INFO()); Assert::AreEqual("horst", d.uid(), L"UID is \"horst\"", LINE_INFO()); - tinkerforge_sensor_definiton dd; + tinkerforge_sensor_definition dd; Assert::IsNull(dd.description(), L"Description is nullptr", LINE_INFO()); Assert::IsNull(dd.uid(), L"UID is nullptr", LINE_INFO()); From 7ee7c75358de90edbfe9ec5a132467c6ceba1318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 15:11:42 +0100 Subject: [PATCH 22/24] Annotate Tinkerforge sensor. --- .../include/power_overwhelming/adl_sensor.h | 2 +- .../include/power_overwhelming/collector.h | 6 +- .../include/power_overwhelming/collector.inl | 6 +- .../include/power_overwhelming/emi_sensor.h | 10 +- .../power_overwhelming/graphics_device.h | 2 +- .../power_overwhelming/hmc8015_sensor.h | 4 +- .../include/power_overwhelming/nvml_sensor.h | 2 +- .../include/power_overwhelming/rtb_sensor.h | 4 +- .../power_overwhelming/tinkerforge_display.h | 2 +- .../power_overwhelming/tinkerforge_sensor.h | 125 ++++++++++++------ .../tinkerforge_sensor_definition.h | 17 +-- power_overwhelming/src/adl_sensor.cpp | 2 +- power_overwhelming/src/emi_sensor.cpp | 10 +- power_overwhelming/src/graphics_device.cpp | 2 +- power_overwhelming/src/hmc8015_sensor.cpp | 9 +- power_overwhelming/src/nvml_sensor.cpp | 2 +- power_overwhelming/src/rtb_sensor.cpp | 9 +- .../src/tinkerforge_display.cpp | 2 +- power_overwhelming/src/tinkerforge_sensor.cpp | 98 +++++++++----- .../src/tinkerforge_sensor_definition.cpp | 10 +- 20 files changed, 207 insertions(+), 117 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/adl_sensor.h b/power_overwhelming/include/power_overwhelming/adl_sensor.h index 95a27a4f..f3f3cdd4 100644 --- a/power_overwhelming/include/power_overwhelming/adl_sensor.h +++ b/power_overwhelming/include/power_overwhelming/adl_sensor.h @@ -38,7 +38,7 @@ namespace power_overwhelming { /// , not all sensors have been returned. /// static std::size_t for_all( - _Out_writes_(cntSensors) adl_sensor *outSensors, + _Out_writes_opt_(cntSensors) adl_sensor *outSensors, _In_ const std::size_t cntSensors); /// diff --git a/power_overwhelming/include/power_overwhelming/collector.h b/power_overwhelming/include/power_overwhelming/collector.h index b1c18292..a70e61c0 100644 --- a/power_overwhelming/include/power_overwhelming/collector.h +++ b/power_overwhelming/include/power_overwhelming/collector.h @@ -86,7 +86,7 @@ namespace power_overwhelming { template static collector from_sensor_lists( _In_ const collector_settings& settings, - _In_ TSensorLists&&... sensors); + TSensorLists&&... sensors); /// /// Initialise a new instance from the given compile-time list of @@ -102,7 +102,7 @@ namespace power_overwhelming { /// A new collector using the given sensors. template static collector from_sensors(_In_ const collector_settings& settings, - _In_ TSensors&&... sensors); + TSensors&&... sensors); /// /// Creates a configuration file for all sensors currently attached to @@ -201,7 +201,7 @@ namespace power_overwhelming { /// template static std::vector> move_to_heap( - _In_ TSensorList&& sensors); + TSensorList&& sensors); /// /// Creates a new collector that has no sensors, but reserved space for diff --git a/power_overwhelming/include/power_overwhelming/collector.inl b/power_overwhelming/include/power_overwhelming/collector.inl index 45320190..7b43b5a7 100644 --- a/power_overwhelming/include/power_overwhelming/collector.inl +++ b/power_overwhelming/include/power_overwhelming/collector.inl @@ -11,7 +11,7 @@ template visus::power_overwhelming::collector visus::power_overwhelming::collector::from_sensor_lists( _In_ const collector_settings& settings, - _In_ TSensorLists&&... sensors) { + TSensorLists&&... sensors) { std::array>, sizeof...(sensors)> instances = { move_to_heap(sensors)... }; typedef typename decltype(instances)::value_type sensor_type; @@ -41,7 +41,7 @@ template visus::power_overwhelming::collector visus::power_overwhelming::collector::from_sensors( _In_ const collector_settings& settings, - _In_ TSensors&&... sensors) { + TSensors&&... sensors) { std::array, sizeof...(sensors)> instances = { std::unique_ptr(new typename std::decay::type( std::move(sensors)))... @@ -66,7 +66,7 @@ visus::power_overwhelming::collector::from_sensors( */ template std::vector> -visus::power_overwhelming::collector::move_to_heap(_In_ TSensorList&& sensors) { +visus::power_overwhelming::collector::move_to_heap(TSensorList&& sensors) { typedef typename std::decay::type sensor_type; decltype(move_to_heap(sensors)) retval; diff --git a/power_overwhelming/include/power_overwhelming/emi_sensor.h b/power_overwhelming/include/power_overwhelming/emi_sensor.h index dd2bfd39..100af903 100644 --- a/power_overwhelming/include/power_overwhelming/emi_sensor.h +++ b/power_overwhelming/include/power_overwhelming/emi_sensor.h @@ -71,7 +71,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_all( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors); /// @@ -93,7 +93,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_channel( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const wchar_t *channel); @@ -116,7 +116,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_device( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device); @@ -142,7 +142,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_device_and_channel( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device, _In_z_ const char_type *channel); @@ -167,7 +167,7 @@ namespace power_overwhelming { /// If enumerating or opening the /// devices failed. static std::size_t for_device_and_channel( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device, _In_ const channel_type channel); diff --git a/power_overwhelming/include/power_overwhelming/graphics_device.h b/power_overwhelming/include/power_overwhelming/graphics_device.h index 01ee8055..ffe0e080 100644 --- a/power_overwhelming/include/power_overwhelming/graphics_device.h +++ b/power_overwhelming/include/power_overwhelming/graphics_device.h @@ -104,7 +104,7 @@ namespace power_overwhelming { /// If the devices could not be /// enumerated due to an error in the underlying APIs. static std::size_t all( - _Out_writes_(cntDevices) graphics_device *outDevices, + _Out_writes_opt_(cntDevices) graphics_device *outDevices, _In_ const std::size_t cntDevices, _In_ const bool onlyHardware = true); diff --git a/power_overwhelming/include/power_overwhelming/hmc8015_sensor.h b/power_overwhelming/include/power_overwhelming/hmc8015_sensor.h index 2a8f1807..e46e855f 100644 --- a/power_overwhelming/include/power_overwhelming/hmc8015_sensor.h +++ b/power_overwhelming/include/power_overwhelming/hmc8015_sensor.h @@ -43,8 +43,8 @@ namespace power_overwhelming { /// The number of HMC8015 instruments found, regardless of how /// many have been returned to . static std::size_t for_all( - _Out_writes_(cnt_sensors) hmc8015_sensor *out_sensors, - _In_ const std::size_t cnt_sensors, + _Out_writes_opt_(cnt_sensors) hmc8015_sensor *out_sensors, + _In_ std::size_t cnt_sensors, _In_ const std::int32_t timeout = 3000); /// diff --git a/power_overwhelming/include/power_overwhelming/nvml_sensor.h b/power_overwhelming/include/power_overwhelming/nvml_sensor.h index 69bee41a..7aeefd7f 100644 --- a/power_overwhelming/include/power_overwhelming/nvml_sensor.h +++ b/power_overwhelming/include/power_overwhelming/nvml_sensor.h @@ -38,7 +38,7 @@ namespace power_overwhelming { /// , not all sensors have been returned. /// static std::size_t for_all( - _Out_writes_(cntSensors) nvml_sensor *outSensors, + _Out_writes_opt_(cntSensors) nvml_sensor *outSensors, _In_ const std::size_t cntSensors); /// diff --git a/power_overwhelming/include/power_overwhelming/rtb_sensor.h b/power_overwhelming/include/power_overwhelming/rtb_sensor.h index 3f2fdfbd..e3e9dc9c 100644 --- a/power_overwhelming/include/power_overwhelming/rtb_sensor.h +++ b/power_overwhelming/include/power_overwhelming/rtb_sensor.h @@ -41,8 +41,8 @@ namespace power_overwhelming { /// The number of HMC8015 instruments found, regardless of how /// many have been returned to . static std::size_t for_all( - _Out_writes_(cntSensors) rtb_sensor *out_sensors, - _In_ const std::size_t cnt_sensors, + _Out_writes_opt_(cnt_sensors) rtb_sensor *out_sensors, + _In_ std::size_t cnt_sensors, _In_ const std::int32_t timeout = 3000); /// diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_display.h b/power_overwhelming/include/power_overwhelming/tinkerforge_display.h index eb007955..a7600f41 100644 --- a/power_overwhelming/include/power_overwhelming/tinkerforge_display.h +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_display.h @@ -48,7 +48,7 @@ namespace power_overwhelming { /// /// static std::size_t for_all( - _Out_writes_(cnt_displays) tinkerforge_display *out_displays, + _Out_writes_opt_(cnt_displays) tinkerforge_display *out_displays, _In_ const std::size_t cnt_displays, _In_opt_z_ const char *host = default_host, _In_ const std::uint16_t port = default_port, diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor.h b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor.h index d758e3fd..26e05227 100644 --- a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor.h +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor.h @@ -75,10 +75,53 @@ namespace power_overwhelming { /// be allocated. /// If the connection to the /// master brick could not be established. - static std::size_t for_all(tinkerforge_sensor *out_sensors, - const std::size_t cnt_sensors, const std::size_t timeout = 1000, - const char *host = default_host, - const std::uint16_t port = default_port); + static std::size_t for_all( + _Out_writes_opt_(cnt_sensors) tinkerforge_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_ const std::size_t timeout = 1000, + _In_opt_z_ const char *host = default_host, + _In_ const std::uint16_t port = default_port); + + /// + /// Create sensors for all Tinkerforge bricklets attached to the + /// on . + /// + /// + /// This method is a utility method that retrieves all sensor + /// definition from + /// and creates a sensor for all of them. + /// The method handles the fact that sensors may be attached and + /// detached at runtime by truncating the number of sensors actually + /// created should this happen during the measuring call and the + /// instantiation call to the method. Therefore, the number of sensors + /// acually created may be smaller than the buffer provided even if the + /// buffer has been measured before using the same method. + /// + /// Receives the sensors, if not + /// nullptr. + /// The available space in + /// . + /// The host on which the Brick daemon is running. + /// This parameter defaults to "localhost". + /// The port on which the Brick daemon is listening. + /// This parameter defaults to 4223. + /// The number of milliseconds to wait for the + /// bricklets to connect if none are cached. This value defaults to + /// 1000. + /// The number of sensors available on the system, regardless + /// of the size of the output array. If this number is larger than + /// , not all sensors have been returned. + /// + /// If the required resources could not + /// be allocated. + /// If the connection to the + /// master brick could not be established. + static std::size_t for_all( + _Out_writes_opt_(cnt_sensors) tinkerforge_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_opt_z_ const wchar_t *host, + _In_ const std::uint16_t port = default_port, + _In_ const std::size_t timeout = 1000); /// /// Retrieve sensor definitions for all bricklets attacted to the @@ -123,7 +166,7 @@ namespace power_overwhelming { /// /// Receives the sensor definitions. If /// nullptr, the sensors will only be counted. - /// Size of + /// Size of /// in elements. It is safe to pass /// any number if is nullptr. /// In this case, the number is interpreted as the expected number of @@ -138,10 +181,11 @@ namespace power_overwhelming { /// The number of current/voltage bricklets available, /// regardless of how many have been copied. static std::size_t get_definitions( - tinkerforge_sensor_definition *out_definitions, - const std::size_t cnt_definitions, const std::size_t timeout = 1000, - const char *host = default_host, - const std::uint16_t port = default_port); + _Out_writes_opt_(cnt) tinkerforge_sensor_definition *out_definitions, + _In_ const std::size_t cnt, + _In_ const std::size_t timeout = 1000, + _In_opt_z_ const char *host = default_host, + _In_ const std::uint16_t port = default_port); /// /// Initialises a new instance. @@ -163,8 +207,9 @@ namespace power_overwhelming { /// be allocated. /// If the connection to the /// master brick could not be established. - tinkerforge_sensor(const char *uid, const char *host = default_host, - const std::uint16_t port = default_port); + tinkerforge_sensor(_In_z_ const char *uid, + _In_opt_z_ const char *host = default_host, + _In_ const std::uint16_t port = default_port); /// /// Initialises a new instance. @@ -184,9 +229,10 @@ namespace power_overwhelming { /// be allocated. /// If the connection to the /// master brick could not be established. - tinkerforge_sensor(const char *uid, const wchar_t *description, - const char *host = default_host, - const std::uint16_t port = default_port); + tinkerforge_sensor(_In_z_ const char *uid, + _In_opt_z_ const wchar_t *description, + _In_opt_z_ const char *host = default_host, + _In_ const std::uint16_t port = default_port); /// /// Initialises a new instance. @@ -203,15 +249,16 @@ namespace power_overwhelming { /// be allocated. /// If the connection to the /// master brick could not be established. - tinkerforge_sensor(const tinkerforge_sensor_definition& definition, - const char *host = default_host, - const std::uint16_t port = default_port); + tinkerforge_sensor( + _In_ const tinkerforge_sensor_definition& definition, + _In_opt_z_ const char *host = default_host, + _In_ const std::uint16_t port = default_port); /// /// Move into a new instance. /// /// The object to be moved. - inline tinkerforge_sensor(tinkerforge_sensor&& rhs) noexcept + inline tinkerforge_sensor(_In_ tinkerforge_sensor&& rhs) noexcept : _impl(rhs._impl) { rhs._impl = nullptr; } @@ -234,9 +281,9 @@ namespace power_overwhelming { /// by a move before. /// If the operation failed. /// - void configuration(sample_averaging& averaging, - conversion_time& voltage_conversion_time, - conversion_time& current_conversion_time); + void configuration(_Out_ sample_averaging& averaging, + _Out_ conversion_time& voltage_conversion_time, + _Out_ conversion_time& current_conversion_time); /// /// Configures the bricklet. @@ -250,15 +297,15 @@ namespace power_overwhelming { /// by a move before. /// If the operation failed. /// - void configure(const sample_averaging averaging, - const conversion_time voltage_conversion_time, - const conversion_time current_conversion_time); + void configure(_In_ const sample_averaging averaging, + _In_ const conversion_time voltage_conversion_time, + _In_ const conversion_time current_conversion_time); /// /// The user-defined description of what the sensor is measuring. /// /// The description of what the sensor is measuring. - const wchar_t *description(void) const noexcept; + _Ret_maybenull_z_ const wchar_t *description(void) const noexcept; /// /// Identify the bricklet used for the sensor. @@ -280,9 +327,12 @@ namespace power_overwhelming { /// by a move before. /// If the operation failed. /// - void identify(char uid[8], char connected_to_uid[8], char& position, - std::uint8_t hardware_version[3], std::uint8_t firmware_version[3], - std::uint16_t& device_id) const; + void identify(_Out_writes_(8) char uid[8], + _Out_writes_(8) char connected_to_uid[8], + _Out_ char& position, + _Out_writes_(3) std::uint8_t hardware_version[3], + _Out_writes_(3) std::uint8_t firmware_version[3], + _Out_ std::uint16_t& device_id) const; /// /// Answer the UID of the bricklet used for the sensor. @@ -292,14 +342,15 @@ namespace power_overwhelming { /// by a move before. /// If the operation failed. /// - void identify(char uid[8]) const; + void identify(_Out_writes_(8) char uid[8]) const; /// /// Gets the name of the sensor. /// /// The implementation-defined, human-readable name of the /// sensor. - virtual const wchar_t *name(void) const noexcept override; + virtual _Ret_maybenull_z_ const wchar_t *name( + void) const noexcept override; /// /// Reset the bricklet. @@ -321,7 +372,7 @@ namespace power_overwhelming { /// If the sensor could not be /// sampled. virtual measurement sample( - const timestamp_resolution resolution) const override; + _In_ const timestamp_resolution resolution) const override; using sensor::sample; @@ -337,7 +388,7 @@ namespace power_overwhelming { /// bricklet. If you are only interested in power, it is reasonable to /// not request current and voltage in order to free up bandwidth. /// - /// The desired sampling period in + /// The desired sampling period in /// microseconds. Note that Tinkerforge only supports millisecond /// resolution for this parameter, so this number must be divisble by /// 1000. The sampling frequence will be clamped to 1 ms at the bottom. @@ -353,17 +404,17 @@ namespace power_overwhelming { /// /// If the sensor could not be /// sampled. - void sample(const measurement_callback on_measurement, - const tinkerforge_sensor_source source = default_source, - const microseconds_type sampling_period = default_sampling_period, - void *context = nullptr); + void sample(_In_opt_ const measurement_callback on_measurement, + _In_ const tinkerforge_sensor_source source = default_source, + _In_ const microseconds_type period = default_sampling_period, + _In_opt_ void *context = nullptr); /// /// Move assignment. /// /// The right-hand side operand /// *this - tinkerforge_sensor& operator =(tinkerforge_sensor&& rhs) noexcept; + tinkerforge_sensor& operator =(_In_ tinkerforge_sensor&& rhs) noexcept; /// /// Determines whether the sensor is valid. diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definition.h b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definition.h index 53484b1d..0c0ec7cb 100644 --- a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definition.h +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_definition.h @@ -33,7 +33,7 @@ namespace power_overwhelming { /// is nullptr. /// If the memory for the UID /// could not be allocated. - tinkerforge_sensor_definition(const char *uid); + tinkerforge_sensor_definition(_In_z_ const char *uid); /// /// Clone . @@ -41,14 +41,15 @@ namespace power_overwhelming { /// The object to be cloned. /// If the memory for the copied data /// could not be allocated. - tinkerforge_sensor_definition(const tinkerforge_sensor_definition& rhs); + tinkerforge_sensor_definition( + _In_ const tinkerforge_sensor_definition& rhs); /// /// Move into a new object. /// /// The object to be moved. inline tinkerforge_sensor_definition( - tinkerforge_sensor_definition&& rhs) noexcept + _In_ tinkerforge_sensor_definition&& rhs) noexcept : _description(rhs._description), _uid(rhs._uid) { rhs._description = nullptr; rhs._uid = nullptr; @@ -64,7 +65,7 @@ namespace power_overwhelming { /// /// The description of the sensor. The object remains owner of /// the memory returned. - const wchar_t *description(void) const noexcept { + _Ret_maybenull_z_ const wchar_t *description(void) const noexcept { return this->_description; } @@ -75,14 +76,14 @@ namespace power_overwhelming { /// safe to pass nullptr. /// If the memory for the description /// could not be allocated. - void description(const wchar_t *description); + void description(_In_opt_z_ const wchar_t *description); /// /// Gets the UID of the sensor. /// /// The UID of the sensor. The object remains owner of the /// memory returned. - const char *uid(void) const noexcept { + _Ret_maybenull_z_ const char *uid(void) const noexcept { return this->_uid; } @@ -94,7 +95,7 @@ namespace power_overwhelming { /// If the memory for the copied data /// could not be allocated. tinkerforge_sensor_definition& operator =( - const tinkerforge_sensor_definition& rhs); + _In_ const tinkerforge_sensor_definition& rhs); /// /// Move-assignment operator. @@ -102,7 +103,7 @@ namespace power_overwhelming { /// The right-hand side operand. /// *this tinkerforge_sensor_definition& operator =( - tinkerforge_sensor_definition&& rhs) noexcept; + _In_ tinkerforge_sensor_definition&& rhs) noexcept; private: diff --git a/power_overwhelming/src/adl_sensor.cpp b/power_overwhelming/src/adl_sensor.cpp index e5be7821..97ffdd2d 100644 --- a/power_overwhelming/src/adl_sensor.cpp +++ b/power_overwhelming/src/adl_sensor.cpp @@ -171,7 +171,7 @@ namespace detail { * visus::power_overwhelming::adl_sensor::for_all */ std::size_t visus::power_overwhelming::adl_sensor::for_all( - _Out_writes_(cntSensors) adl_sensor *outSensors, + _Out_writes_opt_(cntSensors) adl_sensor *outSensors, _In_ const std::size_t cntSensors) { try { int cnt = 0; diff --git a/power_overwhelming/src/emi_sensor.cpp b/power_overwhelming/src/emi_sensor.cpp index 570e272b..9d6716f1 100644 --- a/power_overwhelming/src/emi_sensor.cpp +++ b/power_overwhelming/src/emi_sensor.cpp @@ -24,7 +24,7 @@ * visus::power_overwhelming::emi_sensor::for_all */ std::size_t visus::power_overwhelming::emi_sensor::for_all( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors) { #if defined(_WIN32) typedef detail::emi_sensor_impl::string_type string_type; @@ -42,7 +42,7 @@ std::size_t visus::power_overwhelming::emi_sensor::for_all( * visus::power_overwhelming::emi_sensor::for_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_channel( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const wchar_t *channel) { if (channel == nullptr) { @@ -68,7 +68,7 @@ std::size_t visus::power_overwhelming::emi_sensor::for_channel( * visus::power_overwhelming::emi_sensor::for_device */ std::size_t visus::power_overwhelming::emi_sensor::for_device( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device) { if (device == nullptr) { @@ -94,7 +94,7 @@ std::size_t visus::power_overwhelming::emi_sensor::for_device( * visus::power_overwhelming::emi_sensor::for_device_and_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device, _In_z_ const char_type *channel) { @@ -127,7 +127,7 @@ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( * visus::power_overwhelming::emi_sensor::for_device_and_channel */ std::size_t visus::power_overwhelming::emi_sensor::for_device_and_channel( - _Out_writes_(cntSensors) emi_sensor *out_sensors, + _Out_writes_opt_(cnt_sensors) emi_sensor *out_sensors, _In_ const std::size_t cnt_sensors, _In_z_ const char_type *device, _In_ const channel_type channel) { diff --git a/power_overwhelming/src/graphics_device.cpp b/power_overwhelming/src/graphics_device.cpp index e1794370..f02325f9 100644 --- a/power_overwhelming/src/graphics_device.cpp +++ b/power_overwhelming/src/graphics_device.cpp @@ -20,7 +20,7 @@ * visus::power_overwhelming::graphics_device::all */ std::size_t visus::power_overwhelming::graphics_device::all( - _Out_writes_(cntDevices) graphics_device *outDevices, + _Out_writes_opt_(cntDevices) graphics_device *outDevices, _In_ const std::size_t cntDevices, _In_ const bool onlyHardware) { #if (POWER_OVERWHELMING_GPU_ABSTRACTION >= 11) diff --git a/power_overwhelming/src/hmc8015_sensor.cpp b/power_overwhelming/src/hmc8015_sensor.cpp index 5c4a1306..d9f3ff1e 100644 --- a/power_overwhelming/src/hmc8015_sensor.cpp +++ b/power_overwhelming/src/hmc8015_sensor.cpp @@ -23,8 +23,8 @@ * visus::power_overwhelming::hmc8015_sensor::for_all */ std::size_t visus::power_overwhelming::hmc8015_sensor::for_all( - _Out_writes_(cnt_sensors) hmc8015_sensor *out_sensors, - _In_ const std::size_t cnt_sensors, + _Out_writes_opt_(cnt_sensors) hmc8015_sensor *out_sensors, + _In_ std::size_t cnt_sensors, _In_ const std::int32_t timeout) { // Build the query for all R&S HMC8015 instruments. std::string query("?*::"); // Any protocol @@ -37,6 +37,11 @@ std::size_t visus::power_overwhelming::hmc8015_sensor::for_all( auto devices = detail::visa_library::instance().find_resource( query.c_str()); + // Guard against misuse. + if (out_sensors == nullptr) { + cnt_sensors = 0; + } + // Create a sensor for each instrument we found. for (std::size_t i = 0; (i < cnt_sensors) && (i < devices.size()); ++i) { out_sensors[i] = hmc8015_sensor(devices[i].c_str(), timeout); diff --git a/power_overwhelming/src/nvml_sensor.cpp b/power_overwhelming/src/nvml_sensor.cpp index 54e51c63..cd29b6fb 100644 --- a/power_overwhelming/src/nvml_sensor.cpp +++ b/power_overwhelming/src/nvml_sensor.cpp @@ -16,7 +16,7 @@ * visus::power_overwhelming::nvml_sensor::for_all */ std::size_t visus::power_overwhelming::nvml_sensor::for_all( - _Out_writes_(cntSensors) nvml_sensor *outSensors, + _Out_writes_opt_(cntSensors) nvml_sensor *outSensors, _In_ const std::size_t cntSensors) { try { unsigned int retval = 0; diff --git a/power_overwhelming/src/rtb_sensor.cpp b/power_overwhelming/src/rtb_sensor.cpp index ca0a2591..1b02b7c0 100644 --- a/power_overwhelming/src/rtb_sensor.cpp +++ b/power_overwhelming/src/rtb_sensor.cpp @@ -23,8 +23,8 @@ * visus::power_overwhelming::rtb_sensor::for_all */ std::size_t visus::power_overwhelming::rtb_sensor::for_all( - _Out_writes_(cntSensors) rtb_sensor *out_sensors, - _In_ const std::size_t cnt_sensors, + _Out_writes_opt_(cnt_sensors) rtb_sensor *out_sensors, + _In_ std::size_t cnt_sensors, _In_ const std::int32_t timeout) { // Build the query for all R&S RTB2004 instruments. std::string query("?*::"); // Any protocol @@ -37,6 +37,11 @@ std::size_t visus::power_overwhelming::rtb_sensor::for_all( auto devices = detail::visa_library::instance().find_resource( query.c_str()); + // Guard against misuse. + if (out_sensors == nullptr) { + cnt_sensors = 0; + } + // Create a sensor for each instrument we found. for (std::size_t i = 0; (i < cnt_sensors) && (i < devices.size()); ++i) { out_sensors[i] = rtb_sensor(devices[i].c_str(), timeout); diff --git a/power_overwhelming/src/tinkerforge_display.cpp b/power_overwhelming/src/tinkerforge_display.cpp index 75366de9..3f277fc7 100644 --- a/power_overwhelming/src/tinkerforge_display.cpp +++ b/power_overwhelming/src/tinkerforge_display.cpp @@ -17,7 +17,7 @@ * visus::power_overwhelming::tinkerforge_display::for_all */ std::size_t visus::power_overwhelming::tinkerforge_display::for_all( - _Out_writes_(cnt_displays) tinkerforge_display *out_displays, + _Out_writes_opt_(cnt_displays) tinkerforge_display *out_displays, _In_ const std::size_t cnt_displays, _In_opt_z_ const char *host, _In_ const std::uint16_t port, diff --git a/power_overwhelming/src/tinkerforge_sensor.cpp b/power_overwhelming/src/tinkerforge_sensor.cpp index b9474ad6..d9295946 100644 --- a/power_overwhelming/src/tinkerforge_sensor.cpp +++ b/power_overwhelming/src/tinkerforge_sensor.cpp @@ -22,9 +22,11 @@ * visus::power_overwhelming::tinkerforge_sensor::for_all */ std::size_t visus::power_overwhelming::tinkerforge_sensor::for_all( - tinkerforge_sensor *out_sensors, const std::size_t timeout, - const std::size_t cnt_sensors, const char *host, - const std::uint16_t port) { + _Out_writes_opt_(cnt_sensors) tinkerforge_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_ const std::size_t timeout, + _In_opt_z_ const char *host, + _In_ const std::uint16_t port) { if ((out_sensors == nullptr) || (cnt_sensors == 0)) { return tinkerforge_sensor::get_definitions(nullptr, 0, timeout, host, port); @@ -49,23 +51,40 @@ std::size_t visus::power_overwhelming::tinkerforge_sensor::for_all( } +/* + * visus::power_overwhelming::tinkerforge_sensor::for_all + */ +std::size_t visus::power_overwhelming::tinkerforge_sensor::for_all( + _Out_writes_(cnt_sensors) tinkerforge_sensor *out_sensors, + _In_ const std::size_t cnt_sensors, + _In_opt_z_ const wchar_t *host, + _In_ const std::uint16_t port, + _In_ const std::size_t timeout) { + auto h = convert_string(host); + return for_all(out_sensors, cnt_sensors, timeout, h.c_str(), port); +} + + /* * visus::power_overwhelming::tinkerforge_sensor::get_definitions */ std::size_t visus::power_overwhelming::tinkerforge_sensor::get_definitions( - tinkerforge_sensor_definition *out_definitions, - const std::size_t cnt_definitions, const std::size_t timeout, - const char *host, const std::uint16_t port) { + _Out_writes_opt_(cnt) tinkerforge_sensor_definition *out_definitions, + _In_ const std::size_t cnt, + _In_ const std::size_t timeout, + _In_opt_z_ const char *host, + _In_ const std::uint16_t port) { std::vector bricklets; - detail::tinkerforge_scope scope(host, port); + const auto h = (host != nullptr) ? host : default_host; + detail::tinkerforge_scope scope(h, port); auto retval = scope.copy_bricklets(std::back_inserter(bricklets), [](const detail::tinkerforge_bricklet& b) { return (b.device_type() == VOLTAGE_CURRENT_V2_DEVICE_IDENTIFIER); - }, std::chrono::milliseconds(timeout), cnt_definitions); + }, std::chrono::milliseconds(timeout), cnt); if (out_definitions != nullptr) { - for (std::size_t i = 0; (i < cnt_definitions) && (i < retval); ++i) { + for (std::size_t i = 0; (i < cnt) && (i < retval); ++i) { out_definitions[i] = tinkerforge_sensor_definition( bricklets[i].uid().c_str()); } @@ -79,8 +98,9 @@ std::size_t visus::power_overwhelming::tinkerforge_sensor::get_definitions( * visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor */ visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor( - const char *uid, const char *host, const std::uint16_t port) - : _impl(nullptr) { + _In_z_ const char *uid, + _In_opt_z_ const char *host, + _In_ const std::uint16_t port) : _impl(nullptr) { // The implementation will (i) obtain and manage the scope with the // connection to the master brick, (ii) allocate the voltage/current // bricklet and manage its life time. @@ -95,8 +115,10 @@ visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor( * visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor */ visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor( - const char *uid, const wchar_t *description, const char *host, - const std::uint16_t port) : _impl(nullptr) { + _In_z_ const char *uid, + _In_opt_z_ const wchar_t *description, + _In_opt_z_ const char *host, + _In_ const std::uint16_t port) : _impl(nullptr) { this->_impl = new detail::tinkerforge_sensor_impl( (host != nullptr) ? host : default_host, port, @@ -112,8 +134,9 @@ visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor( * visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor */ visus::power_overwhelming::tinkerforge_sensor::tinkerforge_sensor( - const tinkerforge_sensor_definition& definition, - const char *host, const std::uint16_t port) : _impl(nullptr) { + _In_ const tinkerforge_sensor_definition& definition, + _In_opt_z_ const char *host, + _In_ const std::uint16_t port) : _impl(nullptr) { this->_impl = new detail::tinkerforge_sensor_impl( (host != nullptr) ? host : default_host, port, @@ -138,8 +161,9 @@ visus::power_overwhelming::tinkerforge_sensor::~tinkerforge_sensor( * visus::power_overwhelming::tinkerforge_sensor::configuration */ void visus::power_overwhelming::tinkerforge_sensor::configuration( - sample_averaging& averaging, conversion_time& voltage_conversion_time, - conversion_time& current_conversion_time) { + _Out_ sample_averaging& averaging, + _Out_ conversion_time& voltage_conversion_time, + _Out_ conversion_time& current_conversion_time) { typedef std::underlying_type::type native_adc_type; typedef std::underlying_type::type native_avg_type; @@ -163,9 +187,9 @@ void visus::power_overwhelming::tinkerforge_sensor::configuration( * visus::power_overwhelming::tinkerforge_sensor::configure */ void visus::power_overwhelming::tinkerforge_sensor::configure( - const sample_averaging averaging, - const conversion_time voltage_conversion_time, - const conversion_time current_conversion_time) { + _In_ const sample_averaging averaging, + _In_ const conversion_time voltage_conversion_time, + _In_ const conversion_time current_conversion_time) { typedef std::underlying_type::type native_adc_type; typedef std::underlying_type::type native_avg_type; @@ -188,7 +212,8 @@ void visus::power_overwhelming::tinkerforge_sensor::configure( /* * visus::power_overwhelming::tinkerforge_sensor::description */ -const wchar_t *visus::power_overwhelming::tinkerforge_sensor::description( +_Ret_maybenull_z_ const wchar_t * +visus::power_overwhelming::tinkerforge_sensor::description( void) const noexcept { if (this->_impl != nullptr) { return this->_impl->description.c_str(); @@ -201,10 +226,13 @@ const wchar_t *visus::power_overwhelming::tinkerforge_sensor::description( /* * visus::power_overwhelming::tinkerforge_sensor::identify */ -void visus::power_overwhelming::tinkerforge_sensor::identify(char uid[8], - char connected_to_uid[8], char& position, - std::uint8_t hardware_version[3], std::uint8_t firmware_version[3], - std::uint16_t& device_id) const { +void visus::power_overwhelming::tinkerforge_sensor::identify( + _Out_writes_(8) char uid[8], + _Out_writes_(8) char connected_to_uid[8], + _Out_ char& position, + _Out_writes_(3) std::uint8_t hardware_version[3], + _Out_writes_(3) std::uint8_t firmware_version[3], + _Out_ std::uint16_t& device_id) const { if (!*this) { throw std::runtime_error("A disposed instance of tinkerforge_sensor " "cannot be identified."); @@ -223,7 +251,7 @@ void visus::power_overwhelming::tinkerforge_sensor::identify(char uid[8], * visus::power_overwhelming::tinkerforge_sensor::identify */ void visus::power_overwhelming::tinkerforge_sensor::identify( - char uid[8]) const { + _Out_writes_(8) char uid[8]) const { char dummy0[8]; char dummy1; std::uint8_t dummy2[3]; @@ -236,8 +264,8 @@ void visus::power_overwhelming::tinkerforge_sensor::identify( /* * visus::power_overwhelming::tinkerforge_sensor::name */ -const wchar_t *visus::power_overwhelming::tinkerforge_sensor::name( - void) const noexcept { +_Ret_maybenull_z_ const wchar_t * +visus::power_overwhelming::tinkerforge_sensor::name(void) const noexcept { if (this->_impl != nullptr) { return this->_impl->sensor_name.c_str(); } else { @@ -267,7 +295,7 @@ void visus::power_overwhelming::tinkerforge_sensor::reset(void) { */ visus::power_overwhelming::measurement visus::power_overwhelming::tinkerforge_sensor::sample( - const timestamp_resolution resolution) const { + _In_ const timestamp_resolution resolution) const { if (!*this) { throw std::runtime_error("A disposed instance of tinkerforge_sensor " "cannot be sampled."); @@ -314,10 +342,10 @@ visus::power_overwhelming::tinkerforge_sensor::sample( * visus::power_overwhelming::tinkerforge_sensor::sample */ void visus::power_overwhelming::tinkerforge_sensor::sample( - const measurement_callback on_measurement, - const tinkerforge_sensor_source source, - const microseconds_type sampling_period, - void *context) { + _In_opt_ const measurement_callback on_measurement, + _In_ const tinkerforge_sensor_source source, + _In_ const microseconds_type period, + _In_opt_ void *context) { static constexpr auto one = static_cast(1); static constexpr auto thousand = static_cast(1000); @@ -338,7 +366,7 @@ void visus::power_overwhelming::tinkerforge_sensor::sample( try { auto millis = static_cast((std::max)(one, - sampling_period / thousand)); + period / thousand)); this->_impl->on_measurement_context = context; @@ -383,7 +411,7 @@ void visus::power_overwhelming::tinkerforge_sensor::sample( */ visus::power_overwhelming::tinkerforge_sensor& visus::power_overwhelming::tinkerforge_sensor::operator =( - tinkerforge_sensor&& rhs) noexcept { + _In_ tinkerforge_sensor&& rhs) noexcept { if (this != std::addressof(rhs)) { this->_impl = rhs._impl; rhs._impl = nullptr; diff --git a/power_overwhelming/src/tinkerforge_sensor_definition.cpp b/power_overwhelming/src/tinkerforge_sensor_definition.cpp index 036e1e5a..d8e21c48 100644 --- a/power_overwhelming/src/tinkerforge_sensor_definition.cpp +++ b/power_overwhelming/src/tinkerforge_sensor_definition.cpp @@ -14,7 +14,7 @@ * ...::tinkerforge_sensor_definition::tinkerforge_sensor_definition */ visus::power_overwhelming::tinkerforge_sensor_definition::tinkerforge_sensor_definition( - const char *uid) : _description(nullptr), _uid(nullptr) { + _In_z_ const char *uid) : _description(nullptr), _uid(nullptr) { if (uid == nullptr) { throw std::invalid_argument("The UID of a Tinkerforge sensor cannot " "be null."); @@ -31,7 +31,7 @@ visus::power_overwhelming::tinkerforge_sensor_definition::tinkerforge_sensor_def * ...::tinkerforge_sensor_definition::tinkerforge_sensor_definition */ visus::power_overwhelming::tinkerforge_sensor_definition::tinkerforge_sensor_definition( - const tinkerforge_sensor_definition& rhs) + _In_ const tinkerforge_sensor_definition& rhs) : _description(nullptr), _uid(nullptr) { *this = rhs; } @@ -55,7 +55,7 @@ visus::power_overwhelming::tinkerforge_sensor_definition::~tinkerforge_sensor_de * visus::power_overwhelming::tinkerforge_sensor_definition::description */ void visus::power_overwhelming::tinkerforge_sensor_definition::description( - const wchar_t *description) { + _In_opt_z_ const wchar_t *description) { if (this->_description != nullptr) { ::free(this->_description); } @@ -77,7 +77,7 @@ void visus::power_overwhelming::tinkerforge_sensor_definition::description( */ visus::power_overwhelming::tinkerforge_sensor_definition& visus::power_overwhelming::tinkerforge_sensor_definition::operator =( - const tinkerforge_sensor_definition& rhs) { + _In_ const tinkerforge_sensor_definition& rhs) { if (this != std::addressof(rhs)) { this->description(rhs._description); @@ -105,7 +105,7 @@ visus::power_overwhelming::tinkerforge_sensor_definition::operator =( */ visus::power_overwhelming::tinkerforge_sensor_definition& visus::power_overwhelming::tinkerforge_sensor_definition::operator =( - tinkerforge_sensor_definition&& rhs) noexcept { + _In_ tinkerforge_sensor_definition&& rhs) noexcept { if (this != std::addressof(rhs)) { if (this->_description != nullptr) { ::free(this->_description); From 4a6ddc7152d5c9b9c9b8bac1be86604fba976709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 15:23:15 +0100 Subject: [PATCH 23/24] Fix ret annotations. --- power_overwhelming/include/power_overwhelming/event.h | 2 +- .../include/power_overwhelming/graphics_device.h | 4 ++-- .../include/power_overwhelming/tinkerforge_sensor_source.h | 2 +- power_overwhelming/src/event.cpp | 2 +- power_overwhelming/src/tinkerforge_sensor_source.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/power_overwhelming/include/power_overwhelming/event.h b/power_overwhelming/include/power_overwhelming/event.h index ac77a9fc..eecf7875 100644 --- a/power_overwhelming/include/power_overwhelming/event.h +++ b/power_overwhelming/include/power_overwhelming/event.h @@ -47,7 +47,7 @@ namespace power_overwhelming { /// /// /// - extern _Ret_ event_type POWER_OVERWHELMING_API create_event( + extern _Ret_valid_ event_type POWER_OVERWHELMING_API create_event( _In_ const bool manual_reset = false, _In_ const bool initially_signalled = false); diff --git a/power_overwhelming/include/power_overwhelming/graphics_device.h b/power_overwhelming/include/power_overwhelming/graphics_device.h index ffe0e080..2df6840c 100644 --- a/power_overwhelming/include/power_overwhelming/graphics_device.h +++ b/power_overwhelming/include/power_overwhelming/graphics_device.h @@ -145,7 +145,7 @@ namespace power_overwhelming { /// to store the device ID. /// If the device ID could not be /// determined. - inline _Ret_ const wchar_t *id(void) const { + inline _Ret_valid_ const wchar_t *id(void) const { this->assert_id_and_name(); return this->_id; } @@ -160,7 +160,7 @@ namespace power_overwhelming { /// to store the device name. /// If the device name could not be /// determines. - inline _Ret_ const wchar_t *name(void) const { + inline _Ret_valid_ const wchar_t *name(void) const { this->assert_id_and_name(); return this->_name; } diff --git a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_source.h b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_source.h index 3ee3e077..2d365c8e 100644 --- a/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_source.h +++ b/power_overwhelming/include/power_overwhelming/tinkerforge_sensor_source.h @@ -67,7 +67,7 @@ namespace power_overwhelming { /// The name of the source. /// If the source is not /// valid and therefore could not be converted. - extern POWER_OVERWHELMING_API _Ret_ const wchar_t *to_string( + extern POWER_OVERWHELMING_API _Ret_valid_ const wchar_t *to_string( _In_ const tinkerforge_sensor_source source); } /* namespace power_overwhelming */ diff --git a/power_overwhelming/src/event.cpp b/power_overwhelming/src/event.cpp index f55cae11..fb2e478b 100644 --- a/power_overwhelming/src/event.cpp +++ b/power_overwhelming/src/event.cpp @@ -31,7 +31,7 @@ namespace detail { /* * visus::power_overwhelming::create_event */ -_Ret_ visus::power_overwhelming::event_type +_Ret_valid_ visus::power_overwhelming::event_type visus::power_overwhelming::create_event(_In_ const bool manual_reset, _In_ const bool initially_signalled) { #if defined(POWER_OVERWHELMING_EVENT_EMULATION) diff --git a/power_overwhelming/src/tinkerforge_sensor_source.cpp b/power_overwhelming/src/tinkerforge_sensor_source.cpp index 32098ef4..fb5f53e8 100644 --- a/power_overwhelming/src/tinkerforge_sensor_source.cpp +++ b/power_overwhelming/src/tinkerforge_sensor_source.cpp @@ -36,7 +36,7 @@ visus::power_overwhelming::operator &(_In_ const tinkerforge_sensor_source lhs, /* * visus::power_overwhelming::to_string */ -_Ret_ const wchar_t *visus::power_overwhelming::to_string( +_Ret_valid_ const wchar_t *visus::power_overwhelming::to_string( _In_ const tinkerforge_sensor_source source) { #define _GCC_IS_SHIT(v) L##v #define _TO_STRING_CASE(v) case tinkerforge_sensor_source::v:\ From 0f0ce455b43b2da8b021a1fa0ae38dcc5a8d5592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20M=C3=BCller?= Date: Mon, 20 Mar 2023 15:26:51 +0100 Subject: [PATCH 24/24] Added _Ret_valid_ --- .../include/power_overwhelming/power_overwhelming_api.h | 1 + 1 file changed, 1 insertion(+) diff --git a/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h b/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h index e256917b..0c537de0 100644 --- a/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h +++ b/power_overwhelming/include/power_overwhelming/power_overwhelming_api.h @@ -28,4 +28,5 @@ // These are missing in the salieri header. #define _Analysis_assume_(expr) +#define _Ret_valid_ #endif /* defined(_WIN32) */