Skip to content

Commit 1b5d38a

Browse files
authored
Merge pull request #12 from UniStuttgart-VISUS/sal
SAL annotations
2 parents 1c90916 + 0f0ce45 commit 1b5d38a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1340
-701
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Some sensors have a slightly different API. For instance, sensors using *Tinkerf
3737
```c++
3838
using namespace visus::power_overwhelming;
3939
40-
std::vector<tinkerforge_sensor_definiton> descs;
40+
std::vector<tinkerforge_sensor_definition> descs;
4141
// Call 'get_definitions' to find out how many definitions there are.
4242
descs.resize(tinkerforge_sensor::get_definitions(nullptr, 0));
4343
// Call 'get_definitions' to get the actual descriptors.

podump/tinkerforge.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void sample_tinkerforge_sensor(void) {
1414
using namespace visus::power_overwhelming;
1515

1616
try {
17-
std::vector<tinkerforge_sensor_definiton> descs;
17+
std::vector<tinkerforge_sensor_definition> descs;
1818
descs.resize(tinkerforge_sensor::get_definitions(nullptr, 0));
1919
auto cnt = tinkerforge_sensor::get_definitions(descs.data(),
2020
descs.size());
@@ -47,7 +47,7 @@ void sample_tinkerforge_sensor_async(const unsigned int dt) {
4747
using namespace visus::power_overwhelming;
4848

4949
try {
50-
std::vector<tinkerforge_sensor_definiton> descs;
50+
std::vector<tinkerforge_sensor_definition> descs;
5151
std::vector<tinkerforge_sensor> sensors;
5252
descs.resize(tinkerforge_sensor::get_definitions(nullptr, 0));
5353
auto cnt = tinkerforge_sensor::get_definitions(descs.data(),

power_overwhelming/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ target_include_directories(${PROJECT_NAME}
5656
PRIVATE
5757
$<BUILD_INTERFACE:${SourceDir}>)
5858

59-
target_link_libraries(${PROJECT_NAME} PRIVATE
60-
nlohmann_json
61-
adl
62-
nvml
63-
tinkerforge)
59+
target_link_libraries(${PROJECT_NAME}
60+
PUBLIC salieri
61+
PRIVATE adl nlohmann_json nvml tinkerforge)
6462

6563
if (WIN32)
6664
target_link_libraries(${PROJECT_NAME} PUBLIC Ws2_32)

power_overwhelming/include/power_overwhelming/adl_sensor.h

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ namespace power_overwhelming {
3737
/// of the size of the output array. If this number is larger than
3838
/// <paramref name="cntSensors" />, not all sensors have been returned.
3939
/// </returns>
40-
static std::size_t for_all(adl_sensor *outSensors,
41-
const std::size_t cntSensors);
40+
static std::size_t for_all(
41+
_Out_writes_opt_(cntSensors) adl_sensor *outSensors,
42+
_In_ const std::size_t cntSensors);
4243

4344
/// <summary>
4445
/// Create a new instance for the specified adapter index.
@@ -50,8 +51,8 @@ namespace power_overwhelming {
5051
/// <returns></returns>
5152
/// <exception cref="adl_exception">If the specified device was not
5253
/// found, or another error occurred in ADL.</exception>
53-
static adl_sensor from_index(const int index,
54-
const adl_sensor_source source);
54+
static adl_sensor from_index(_In_ const int index,
55+
_In_ const adl_sensor_source source);
5556

5657
/// <summary>
5758
/// Create a new instance for the unique device ID.
@@ -66,8 +67,24 @@ namespace power_overwhelming {
6667
/// </exception>
6768
/// <exception cref="adl_exception">If the specified device was not
6869
/// found, or another error occurred in ADL.</exception>
69-
static adl_sensor from_udid(const char *udid,
70-
const adl_sensor_source source);
70+
static adl_sensor from_udid(_In_z_ const char *udid,
71+
_In_ const adl_sensor_source source);
72+
73+
/// <summary>
74+
/// Create a new instance for the unique device ID.
75+
/// </summary>
76+
/// <param name="udid">The unique device ID to create the sensor for.
77+
/// </param>
78+
/// <param name="source">The sensor source to retrieve. If the source
79+
/// is not supported, the method will fail.</param>
80+
/// <returns></returns>
81+
/// <exception cref="std::invalid_argument">If <paramref name="udid" />
82+
/// is <c>nullptr</c> or if it did not match exactly one device.
83+
/// </exception>
84+
/// <exception cref="adl_exception">If the specified device was not
85+
/// found, or another error occurred in ADL.</exception>
86+
static adl_sensor from_udid(_In_z_ const wchar_t *udid,
87+
_In_ const adl_sensor_source source);
7188

7289
/// <summary>
7390
/// Initialises a new instance.
@@ -85,7 +102,7 @@ namespace power_overwhelming {
85102
/// </summary>
86103
/// <param name="rhs"></param>
87104
/// <returns></returns>
88-
inline adl_sensor(adl_sensor&& rhs) noexcept : _impl(rhs._impl) {
105+
inline adl_sensor(_In_ adl_sensor&& rhs) noexcept : _impl(rhs._impl) {
89106
rhs._impl = nullptr;
90107
}
91108

@@ -98,7 +115,8 @@ namespace power_overwhelming {
98115
/// <param name="impl">The status block, which must have been allocated
99116
/// using <c>new</c>. The object takes ownership of the status block.
100117
/// </param>
101-
inline explicit adl_sensor(detail::adl_sensor_impl *&& impl) noexcept
118+
inline explicit adl_sensor(
119+
_In_ detail::adl_sensor_impl *&& impl) noexcept
102120
: _impl(impl) {
103121
impl = nullptr;
104122
}
@@ -113,7 +131,8 @@ namespace power_overwhelming {
113131
/// </summary>
114132
/// <returns>The implementation-defined, human-readable name of the
115133
/// sensor.</returns>
116-
virtual const wchar_t *name(void) const noexcept override;
134+
virtual _Ret_maybenull_z_ const wchar_t *name(
135+
void) const noexcept override;
117136

118137
/// <summary>
119138
/// Sample the sensor.
@@ -127,7 +146,7 @@ namespace power_overwhelming {
127146
/// <exception cref="adl_exception">If the sensor could not be sampled.
128147
/// </exception>
129148
virtual measurement sample(
130-
const timestamp_resolution resolution) const override;
149+
_In_ const timestamp_resolution resolution) const override;
131150

132151
/// <summary>
133152
/// Asynchronously sample the sensor every
@@ -144,7 +163,7 @@ namespace power_overwhelming {
144163
/// <param name="on_measurement">The callback to be invoked if new data
145164
/// arrived. If this is <c>nullptr</c>, the asynchronous sampling will
146165
/// be disabled.</param>
147-
/// <param name="sampling_period">The desired sampling period in
166+
/// <param name="period">The desired sampling period in
148167
/// microseconds. This parameter defaults to 1 millisecond.</param>
149168
/// <param name="context">A user-defined context pointer that is passed
150169
/// on to <see cref="on_measurement" />. This parameter defaults to
@@ -156,9 +175,9 @@ namespace power_overwhelming {
156175
/// </exception>
157176
/// <exception cref="tinkerforge_exception">If the sensor could not be
158177
/// sampled. </exception>
159-
void sample(const measurement_callback on_measurement,
160-
const microseconds_type sampling_period = default_sampling_period,
161-
void *context = nullptr);
178+
void sample(_In_opt_ const measurement_callback on_measurement,
179+
_In_ const microseconds_type period = default_sampling_period,
180+
_In_opt_ void *context = nullptr);
162181

163182
using sensor::sample;
164183

@@ -181,7 +200,7 @@ namespace power_overwhelming {
181200
/// the sensor is already asynchronously collecting data.</exception>
182201
/// <exception cref="adl_exception">If the source could not be
183202
/// started.</exception>
184-
void start(const microseconds_type sampling_period);
203+
void start(_In_ const microseconds_type sampling_period);
185204

186205
/// <summary>
187206
/// Stops the sensor from asynchronously collecting data.
@@ -207,14 +226,14 @@ namespace power_overwhelming {
207226
/// </summary>
208227
/// <param name=""></param>
209228
/// <returns></returns>
210-
const char *udid(void) const noexcept;
229+
_Ret_maybenull_z_ const char *udid(void) const noexcept;
211230

212231
/// <summary>
213232
/// Move assignment.
214233
/// </summary>
215234
/// <param name="rhs">The right-hand side operand</param>
216235
/// <returns><c>*this</c></returns>
217-
adl_sensor& operator =(adl_sensor&& rhs) noexcept;
236+
adl_sensor& operator =(_In_ adl_sensor&& rhs) noexcept;
218237

219238
/// <summary>
220239
/// Determines whether the sensor is valid.

power_overwhelming/include/power_overwhelming/collector.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace power_overwhelming {
3737
/// <param name="settings">The general settings for the collector,
3838
/// including the sampling interval.</param>
3939
/// <returns>A collector for all available sensors.</returns>
40-
static collector for_all(const collector_settings& settings);
40+
static collector for_all(_In_ const collector_settings& settings);
4141

4242
/// <summary>
4343
/// Creates a collector for all sensors that could be found and
@@ -50,8 +50,8 @@ namespace power_overwhelming {
5050
/// <returns>A collector for all available sensors.</returns>
5151
/// <exception std::invalid_argument">If <paramref name="output_path" />
5252
/// is <c>nullptr</c>.</exception>
53-
inline static collector for_all(const wchar_t *output_path,
54-
const sensor::microseconds_type sampling_interval
53+
inline static collector for_all(_In_z_ const wchar_t *output_path,
54+
_In_ const sensor::microseconds_type sampling_interval
5555
= collector_settings::default_sampling_interval) {
5656
return for_all(collector_settings().output_path(output_path)
5757
.sampling_interval(sampling_interval));
@@ -71,7 +71,7 @@ namespace power_overwhelming {
7171
/// <param name="path">The path to the JSON configuration file.</param>
7272
/// <returns>A new collector configured with the sensors in the
7373
/// specified file.</returns>
74-
static collector from_json(const wchar_t *path);
74+
static collector from_json(_In_z_ const wchar_t *path);
7575

7676
/// <summary>
7777
/// Initialise a new instance from the given lists of sensors.
@@ -84,7 +84,8 @@ namespace power_overwhelming {
8484
/// <param name="sensors">The lists of sensors.</param>
8585
/// <returns></returns>
8686
template<class... TSensorLists>
87-
static collector from_sensor_lists(const collector_settings& settings,
87+
static collector from_sensor_lists(
88+
_In_ const collector_settings& settings,
8889
TSensorLists&&... sensors);
8990

9091
/// <summary>
@@ -100,7 +101,7 @@ namespace power_overwhelming {
100101
/// disposed by moving them once the method returns.</param>
101102
/// <returns>A new collector using the given sensors.</returns>
102103
template<class... TSensors>
103-
static collector from_sensors(const collector_settings& settings,
104+
static collector from_sensors(_In_ const collector_settings& settings,
104105
TSensors&&... sensors);
105106

106107
/// <summary>
@@ -118,7 +119,7 @@ namespace power_overwhelming {
118119
/// </remarks>
119120
/// <param name="path">The path where the configuration file should be
120121
/// stored.</param>
121-
static void make_configuration_template(const wchar_t *path);
122+
static void make_configuration_template(_In_z_ const wchar_t *path);
122123

123124
/// <summary>
124125
/// Initialise a new instance.
@@ -135,7 +136,7 @@ namespace power_overwhelming {
135136
/// </summary>
136137
/// <param name="rhs"></param>
137138
/// <returns></returns>
138-
inline collector(collector&& rhs) noexcept : _impl(rhs._impl) {
139+
inline collector(_In_ collector&& rhs) noexcept : _impl(rhs._impl) {
139140
rhs._impl = nullptr;
140141
}
141142

@@ -149,7 +150,7 @@ namespace power_overwhelming {
149150
/// output.
150151
/// </summary>
151152
/// <param name="marker"></param>
152-
void marker(const wchar_t *marker);
153+
void marker(_In_opt_z_ const wchar_t *marker);
153154

154155
/// <summary>
155156
/// Answer the number of sensors in the collector.
@@ -177,7 +178,7 @@ namespace power_overwhelming {
177178
/// </summary>
178179
/// <param name="rhs">The right-hand side operand</param>
179180
/// <returns><c>*this</c></returns>
180-
collector& operator =(collector&& rhs) noexcept;
181+
collector& operator =(_In_ collector&& rhs) noexcept;
181182

182183
/// <summary>
183184
/// Determines whether the object is valid.
@@ -209,14 +210,15 @@ namespace power_overwhelming {
209210
/// <param name="settings"></param>
210211
/// <param name="capacity"></param>
211212
/// <returns>A new collector without sensors.</returns>
212-
static collector prepare(const collector_settings& settings,
213-
const std::size_t capacity);
213+
static collector prepare(_In_ const collector_settings& settings,
214+
_In_ const std::size_t capacity);
214215

215216
/// <summary>
216217
/// Initialise a new instance.
217218
/// </summary>
218219
/// <param name="impl"></param>
219-
inline collector(detail::collector_impl *impl) : _impl(impl) { }
220+
inline collector(_In_opt_ detail::collector_impl *impl)
221+
: _impl(impl) { }
220222

221223
/// <summary>
222224
/// Adds a new sensor to the collector.
@@ -229,7 +231,7 @@ namespace power_overwhelming {
229231
/// <param name="sensor">The sensor to be added. The object takes
230232
/// ownership of the object designated by this pointer. The object
231233
/// must have been allocated using C++ <c>new</c>.</param>
232-
void add(sensor *sensor);
234+
void add(_In_ sensor *sensor);
233235

234236
detail::collector_impl *_impl;
235237

power_overwhelming/include/power_overwhelming/collector.inl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
template<class... TSensorLists>
1111
visus::power_overwhelming::collector
1212
visus::power_overwhelming::collector::from_sensor_lists(
13-
const collector_settings& settings, TSensorLists&&... sensors) {
13+
_In_ const collector_settings& settings,
14+
TSensorLists&&... sensors) {
1415
std::array<std::vector<std::unique_ptr<sensor>>,
1516
sizeof...(sensors)> instances = { move_to_heap(sensors)... };
1617
typedef typename decltype(instances)::value_type sensor_type;
@@ -39,7 +40,8 @@ visus::power_overwhelming::collector::from_sensor_lists(
3940
template<class... TSensors>
4041
visus::power_overwhelming::collector
4142
visus::power_overwhelming::collector::from_sensors(
42-
const collector_settings& settings, TSensors&&... sensors) {
43+
_In_ const collector_settings& settings,
44+
TSensors&&... sensors) {
4345
std::array<std::unique_ptr<sensor>, sizeof...(sensors)> instances = {
4446
std::unique_ptr<sensor>(new typename std::decay<TSensors>::type(
4547
std::move(sensors)))...

power_overwhelming/include/power_overwhelming/collector_settings.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace power_overwhelming {
4848
/// Clone <paramref name="rhs" />.
4949
/// </summary>
5050
/// <param name="rhs">The object to be cloned.</param>
51-
collector_settings(const collector_settings& rhs);
51+
collector_settings(_In_ const collector_settings& rhs);
5252

5353
/// <summary>
5454
/// Finalises the instance.
@@ -60,7 +60,7 @@ namespace power_overwhelming {
6060
/// output to.
6161
/// </summary>
6262
/// <returns>The path to the output file.</returns>
63-
inline const wchar_t *output_path(void) const noexcept {
63+
inline _Ret_z_ const wchar_t *output_path(void) const noexcept {
6464
return this->_output_path;
6565
}
6666

@@ -72,7 +72,7 @@ namespace power_overwhelming {
7272
/// <returns><c>*this</c>.</returns>
7373
/// <exception cref="std::invalid_argument">If
7474
/// <paramref name="output_path" /> is <c>nullptr</c>.</exception>
75-
collector_settings& output_path(const wchar_t *path);
75+
collector_settings& output_path(_In_z_ const wchar_t *path);
7676

7777
/// <summary>
7878
/// Gets the time interval in which the collector should sample the
@@ -89,14 +89,14 @@ namespace power_overwhelming {
8989
/// <param name="interval">The sampling interval.</param>
9090
/// <returns><c>*this</c>.</returns>
9191
collector_settings& sampling_interval(
92-
const sampling_interval_type interval);
92+
_In_ const sampling_interval_type interval);
9393

9494
/// <summary>
9595
/// Assignment.
9696
/// </summary>
9797
/// <param name="rhs">The right hand side operand.</param>
9898
/// <returns><c>*this</c>.</returns>
99-
collector_settings& operator =(const collector_settings& rhs);
99+
collector_settings& operator =(_In_ const collector_settings& rhs);
100100

101101
private:
102102

power_overwhelming/include/power_overwhelming/computer_name.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ namespace power_overwhelming {
3232
/// store the computer name, including the terminating null.</returns>
3333
/// <exception cref="std::system_error">In case the operation failed.
3434
/// </exception>
35-
std::size_t POWER_OVERWHELMING_API computer_name(char *dst,
36-
const std::size_t cnt);
35+
std::size_t POWER_OVERWHELMING_API computer_name(
36+
_Out_writes_opt_z_(cnt) char *dst,
37+
_In_ const std::size_t cnt);
3738

3839
/// <summary>
3940
/// Answer the name of the computer the calling code is running on.
@@ -52,8 +53,9 @@ namespace power_overwhelming {
5253
/// store the computer name, including the terminating null.</returns>
5354
/// <exception cref="std::system_error">In case the operation failed.
5455
/// </exception>
55-
std::size_t POWER_OVERWHELMING_API computer_name(wchar_t *dst,
56-
const std::size_t cnt);
56+
std::size_t POWER_OVERWHELMING_API computer_name(
57+
_Out_writes_opt_z_(cnt) wchar_t *dst,
58+
_In_ const std::size_t cnt);
5759

5860
/// <summary>
5961
/// Answer the name of the computer the calling code is running on.

0 commit comments

Comments
 (0)