Skip to content

Commit b65724a

Browse files
committed
Use constants from public API in implementation to reduce clashes and reuse documentation strings
1 parent 61da047 commit b65724a

17 files changed

+202
-217
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ endif()
9797

9898
set(headers
9999
include/lsl_c.h
100+
include/lsl_constants.h
100101
include/lsl_cpp.h
101102
)
102103

include/lsl_c.h

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -64,86 +64,8 @@ typedef unsigned int uint32_t;
6464
extern "C" {
6565
#endif
6666

67-
68-
69-
/* =========================== */
70-
/* ==== Defined constants ==== */
71-
/* =========================== */
72-
73-
/**
74-
* Constant to indicate that a stream has variable sampling rate.
75-
*/
76-
#define LSL_IRREGULAR_RATE 0.0
77-
78-
/**
79-
* Constant to indicate that a sample has the next successive time stamp.
80-
* This is an optional optimization to transmit less data per sample.
81-
* The stamp is then deduced from the preceding one according to the stream's sampling rate
82-
* (in the case of an irregular rate, the same time stamp as before will is assumed).
83-
*/
84-
#define LSL_DEDUCED_TIMESTAMP -1.0
85-
86-
/**
87-
* A very large time value (ca. 1 year); can be used in timeouts.
88-
*/
89-
#define LSL_FOREVER 32000000.0
90-
91-
/**
92-
* Constant to indicate that there is no preference about how a data stream shall be chunked for transmission.
93-
* (can be used for the chunking parameters in the inlet or the outlet).
94-
*/
95-
#define LSL_NO_PREFERENCE 0
96-
97-
/**
98-
* Data format of a channel (each transmitted sample holds an array of channels).
99-
*/
100-
typedef enum {
101-
cft_float32 = 1, /* For up to 24-bit precision measurements in the appropriate physical unit */
102-
/* (e.g., microvolts). Integers from -16777216 to 16777216 are represented accurately. */
103-
cft_double64 = 2, /* For universal numeric data as long as permitted by network & disk budget. */
104-
/* The largest representable integer is 53-bit. */
105-
cft_string = 3, /* For variable-length ASCII strings or data blobs, such as video frames, */
106-
/* complex event descriptions, etc. */
107-
cft_int32 = 4, /* For high-rate digitized formats that require 32-bit precision. Depends critically on */
108-
/* meta-data to represent meaningful units. Useful for application event codes or other coded data. */
109-
cft_int16 = 5, /* For very high rate signals (40Khz+) or consumer-grade audio */
110-
/* (for professional audio float is recommended). */
111-
cft_int8 = 6, /* For binary signals or other coded data. */
112-
/* Not recommended for encoding string data. */
113-
cft_int64 = 7, /* For now only for future compatibility. Support for this type is not yet exposed in all languages. */
114-
/* Also, some builds of liblsl will not be able to send or receive data of this type. */
115-
cft_undefined = 0 /* Can not be transmitted. */
116-
} lsl_channel_format_t;
117-
118-
/**
119-
* Post-processing options for stream inlets.
120-
*/
121-
typedef enum {
122-
proc_none = 0, /* No automatic post-processing; return the ground-truth time stamps for manual post-processing */
123-
/* (this is the default behavior of the inlet). */
124-
proc_clocksync = 1, /* Perform automatic clock synchronization; equivalent to manually adding the time_correction() value */
125-
/* to the received time stamps. */
126-
proc_dejitter = 2, /* Remove jitter from time stamps. This will apply a smoothing algorithm to the received time stamps; */
127-
/* the smoothing needs to see a minimum number of samples (30-120 seconds worst-case) until the remaining */
128-
/* jitter is consistently below 1ms. */
129-
proc_monotonize = 4, /* Force the time-stamps to be monotonically ascending (only makes sense if timestamps are dejittered). */
130-
proc_threadsafe = 8, /* Post-processing is thread-safe (same inlet can be read from by multiple threads); uses somewhat more CPU. */
131-
proc_ALL = 1|2|4|8 /* The combination of all possible post-processing options. */
132-
} lsl_processing_options_t;
133-
134-
/**
135-
* Possible error codes.
136-
*/
137-
typedef enum {
138-
lsl_no_error = 0, /* No error occurred */
139-
lsl_timeout_error = -1, /* The operation failed due to a timeout. */
140-
lsl_lost_error = -2, /* The stream has been lost. */
141-
lsl_argument_error = -3, /* An argument was incorrectly specified (e.g., wrong format or wrong length). */
142-
lsl_internal_error = -4 /* Some other internal error has happened. */
143-
} lsl_error_code_t;
144-
145-
146-
67+
// Defined constants
68+
#include "lsl_constants.h"
14769

14870
/* ===================================================== */
14971
/* ==== Objects provided by the lab streaming layer ==== */

include/lsl_constants.h

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#pragma once
2+
3+
/* =========================== */
4+
/* ==== Defined constants ==== */
5+
/* =========================== */
6+
7+
//! Constant to indicate that a stream has variable sampling rate.
8+
#define LSL_IRREGULAR_RATE 0.0
9+
10+
/**
11+
* Constant to indicate that a sample has the next successive time stamp.
12+
* This is an optional optimization to transmit less data per sample.
13+
* The stamp is then deduced from the preceding one according to the stream's sampling rate
14+
* (in the case of an irregular rate, the same time stamp as before will is assumed).
15+
*/
16+
#define LSL_DEDUCED_TIMESTAMP -1.0
17+
18+
//! A very large time value (ca. 1 year); can be used in timeouts.
19+
#define LSL_FOREVER 32000000.0
20+
21+
/**
22+
* Constant to indicate that there is no preference about how a data stream shall be chunked for
23+
* transmission. (can be used for the chunking parameters in the inlet or the outlet).
24+
*/
25+
#define LSL_NO_PREFERENCE 0
26+
27+
//! Data format of a channel (each transmitted sample holds an array of channels).
28+
typedef enum {
29+
/*! For up to 24-bit precision measurements in the appropriate physical unit (e.g., microvolts).
30+
* Integers from -16777216 to 16777216 are represented accurately. */
31+
cft_float32 = 1,
32+
33+
/*! For universal numeric data as long as permitted by network & disk budget.
34+
* The largest representable integer is 53-bit. */
35+
cft_double64 = 2,
36+
37+
/*! For variable-length ASCII strings or data blobs, such as video frames, complex event
38+
descriptions, etc. */
39+
cft_string = 3,
40+
41+
/*! For high-rate digitized formats that require 32-bit precision.
42+
* Depends critically on meta-data to represent meaningful units.
43+
* Useful for application event codes or other coded data. */
44+
cft_int32 = 4,
45+
46+
/*! For very high rate signals (40Khz+) or consumer-grade audio.
47+
* For professional audio float is recommended. */
48+
cft_int16 = 5,
49+
50+
/*! For binary signals or other coded data. Not recommended for encoding string data. */
51+
cft_int8 = 6,
52+
53+
/*! For now only for future compatibility. Support for this type is not yet
54+
exposed in all languages. Also, some builds of liblsl will not be able
55+
to send or receive data of this type.*/
56+
cft_int64 = 7,
57+
58+
//! Can not be transmitted.
59+
cft_undefined = 0
60+
} lsl_channel_format_t;
61+
62+
//! Post-processing options for stream inlets.
63+
typedef enum {
64+
/*! No automatic post-processing; return the ground-truth time stamps for manual
65+
* post-processing. This is the default behavior of the inlet. */
66+
proc_none = 0,
67+
68+
/*! Perform automatic clock synchronization;
69+
* equivalent to manually adding the time_correction() value to the received time stamps. */
70+
proc_clocksync = 1,
71+
72+
/*! Remove jitter from time stamps.<br>
73+
* This will apply a smoothing algorithm to the received time stamps;
74+
* the smoothing needs to see a minimum number of samples (30-120 seconds worst-case)
75+
* until the remaining jitter is consistently below 1ms. */
76+
proc_dejitter = 2,
77+
78+
/*! Force the time-stamps to be monotonically ascending.<br>
79+
* Only makes sense if timestamps are dejittered. */
80+
proc_monotonize = 4,
81+
82+
/*! Post-processing is thread-safe (same inlet can be read from by multiple threads);
83+
* uses somewhat more CPU. */
84+
proc_threadsafe = 8,
85+
86+
//! The combination of all possible post-processing options.
87+
proc_ALL = 1 | 2 | 4 | 8
88+
} lsl_processing_options_t;
89+
90+
/**
91+
* Possible error codes.
92+
*/
93+
typedef enum {
94+
//! No error occurred
95+
lsl_no_error = 0,
96+
97+
//! The operation failed due to a timeout.
98+
lsl_timeout_error = -1,
99+
100+
//! The stream has been lost.
101+
lsl_lost_error = -2,
102+
103+
//! An argument was incorrectly specified (e.g., wrong format or wrong length).
104+
lsl_argument_error = -3,
105+
106+
//! Some other internal error has happened.
107+
lsl_internal_error = -4
108+
} lsl_error_code_t;

src/common.h

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef COMMON_H
22
#define COMMON_H
33

4+
#include "../include/lsl_constants.h"
45
#include <stdexcept>
56
#include <boost/version.hpp>
67
#include <string>
@@ -55,53 +56,6 @@ namespace lsl {
5556
/// Ensure that LSL is initialized.
5657
void ensure_lsl_initialized();
5758

58-
/// Data format of a channel (each transmitted sample holds an array of channels).
59-
enum channel_format_t {
60-
cf_float32 = 1, // For up to 24-bit precision measurements in the appropriate physical unit
61-
// (e.g., microvolts). Integers from -16777216 to 16777216 are represented accurately.
62-
cf_double64 = 2, // For universal numeric data as long as permitted by network & disk budget.
63-
// The largest representable integer is 53-bit.
64-
cf_string = 3, // For variable-length ASCII strings or data blobs, such as video frames,
65-
// complex event descriptions, etc.
66-
cf_int32 = 4, // For high-rate digitized formats that require 32-bit precision. Depends critically on
67-
// meta-data to represent meaningful units. Useful for application event codes or other coded data.
68-
cf_int16 = 5, // For very high rate signals (40Khz+) or consumer-grade audio
69-
// (for professional audio float is recommended).
70-
cf_int8 = 6, // For binary signals or other coded data.
71-
// Not recommended for encoding string data.
72-
cf_int64 = 7, // For now only for future compatibility. Support for this type is not yet exposed in all languages.
73-
// Also, some builds of liblsl will not be able to send or receive data of this type.
74-
cf_undefined = 0 // Can not be transmitted.
75-
};
76-
77-
78-
/// Processing options for the time_postprocessor.
79-
enum processing_options_t {
80-
post_none = 0, // No automatic post-processing; return the ground-truth time stamps for manual post-processing
81-
// (this is the default behavior of the inlet).
82-
post_clocksync = 1, // Perform automatic clock synchronization; equivalent to manually adding the time_correction() value
83-
// to the received time stamps.
84-
post_dejitter = 2, // Remove jitter from time stamps. This will apply a smoothing algorithm to the received time stamps;
85-
// the smoothing needs to see a minimum number of samples (30-120 seconds worst-case) until the remaining
86-
// jitter is consistently below 1ms.
87-
post_monotonize = 4, // Force the time-stamps to be monotonically ascending (only makes sense if timestamps are dejittered).
88-
post_threadsafe = 8, // Post-processing is thread-safe (same inlet can be read from by multiple threads); uses somewhat more CPU.
89-
post_ALL = 1|2|4|8 // The combination of all possible post-processing options.
90-
};
91-
92-
#ifndef LSL_C_H
93-
/**
94-
* Possible error codes.
95-
*/
96-
typedef enum {
97-
lsl_no_error = 0, /* No error occurred */
98-
lsl_timeout_error = -1, /* The operation failed due to a timeout. */
99-
lsl_lost_error = -2, /* The stream has been lost. */
100-
lsl_argument_error = -3, /* An argument was incorrectly specified (e.g., wrong format or wrong length). */
101-
lsl_internal_error = -4 /* Some other internal error has happened. */
102-
} lsl_error_code_t;
103-
#endif
104-
10559
/// Exception class that indicates that a stream inlet's source has been irrecoverably lost.
10660
class LIBLSL_CPP_API lost_error: public std::runtime_error {
10761
public:

src/data_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void data_receiver::data_thread() {
166166
// transmit request parameters
167167
server_stream << "Native-Byte-Order: " << BOOST_BYTE_ORDER << "\r\n";
168168
server_stream << "Endian-Performance: " << std::floor(measure_endian_performance()) << "\r\n";
169-
server_stream << "Has-IEEE754-Floats: " << (format_ieee754[cf_float32] && format_ieee754[cf_double64]) << "\r\n";
169+
server_stream << "Has-IEEE754-Floats: " << (format_ieee754[cft_float32] && format_ieee754[cft_double64]) << "\r\n";
170170
server_stream << "Supports-Subnormals: " << format_subnormal[conn_.type_info().channel_format()] << "\r\n";
171171
server_stream << "Value-Size: " << conn_.type_info().channel_bytes() << "\r\n"; // 0 for strings
172172
server_stream << "Data-Protocol-Version: " << proposed_protocol_version << "\r\n";

src/inlet_connection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ inlet_connection::inlet_connection(const stream_info_impl &info, bool recover):
6161
throw std::invalid_argument("When creating an inlet with a constructed (instead of resolved) stream_info, you must assign at least the name, type or source_id of the desired stream.");
6262
if (type_info_.channel_count() == 0)
6363
throw std::invalid_argument("When creating an inlet with a constructed (instead of resolved) stream_info, you must assign a nonzero channel count.");
64-
if (type_info_.channel_format() == cf_undefined)
64+
if (type_info_.channel_format() == cft_undefined)
6565
throw std::invalid_argument("When creating an inlet with a constructed (instead of resolved) stream_info, you must assign a channel format.");
6666

6767
// use the protocol that is specified in the config

src/legacy/legacy_abi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ using namespace pugi;
1717
// boilerplate code calling the private implementation
1818
stream_info::stream_info(): impl_(new stream_info_impl()) { }
1919
stream_info::stream_info(const stream_info &rhs): impl_(new stream_info_impl(*rhs.impl_)) { }
20-
stream_info::stream_info(const std::string &name, const std::string &type, int channel_count, double nominal_srate, channel_format_t channel_format, const std::string &source_id): impl_(new stream_info_impl(name,type,channel_count,nominal_srate,channel_format,source_id)) { }
20+
stream_info::stream_info(const std::string &name, const std::string &type, int channel_count, double nominal_srate, lsl_channel_format_t channel_format, const std::string &source_id): impl_(new stream_info_impl(name,type,channel_count,nominal_srate,channel_format,source_id)) { }
2121
stream_info::stream_info(const stream_info_impl *impl): impl_(new stream_info_impl(*impl)) { }
2222
stream_info::stream_info(const stream_info_impl &impl): impl_(new stream_info_impl(impl)) { }
2323
stream_info::~stream_info() { delete impl_; }
2424
const std::string &stream_info::name() const { return impl_->name(); }
2525
const std::string &stream_info::type() const { return impl_->type(); }
2626
int stream_info::channel_count() const { return impl_->channel_count(); }
2727
double stream_info::nominal_srate() const { return impl_->nominal_srate(); }
28-
channel_format_t stream_info::channel_format() const { return impl_->channel_format(); }
28+
lsl_channel_format_t stream_info::channel_format() const { return impl_->channel_format(); }
2929
const std::string &stream_info::source_id() const { return impl_->source_id(); }
3030
int stream_info::version() const { return impl_->version(); }
3131
const std::string &stream_info::uid() const { return impl_->uid(); }

src/legacy/legacy_abi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ namespace lsl {
7676
* @param channel_count Number of channels per sample. This stays constant for the lifetime of the stream.
7777
* @param nominal_srate The sampling rate (in Hz) as advertised by the data source, if regular (otherwise set to IRREGULAR_RATE).
7878
* @param channel_format Format/type of each channel. If your channels have different formats, consider supplying
79-
* multiple streams or use the largest type that can hold them all (such as cf_double64).
79+
* multiple streams or use the largest type that can hold them all (such as cft_double64).
8080
* @param source_id Unique identifier of the device or source of the data, if available (such as the serial number).
8181
* This is critical for system robustness since it allows recipients to recover from failure even after the
8282
* serving app, device or computer crashes (just by finding a stream with the same source id on the network again).
8383
* Therefore, it is highly recommended to always try to provide whatever information can uniquely identify the data source itself.
8484
*/
85-
stream_info(const std::string &name, const std::string &type, int channel_count=1, double nominal_srate=IRREGULAR_RATE, channel_format_t channel_format=cf_float32, const std::string &source_id=std::string());
85+
stream_info(const std::string &name, const std::string &type, int channel_count=1, double nominal_srate=IRREGULAR_RATE, lsl_channel_format_t channel_format=cft_float32, const std::string &source_id=std::string());
8686

8787
// ========================
8888
// === Core Information ===
@@ -128,7 +128,7 @@ namespace lsl {
128128
* All channels in a stream have the same format. However, a device might offer multiple time-synched streams
129129
* each with its own format.
130130
*/
131-
channel_format_t channel_format() const;
131+
lsl_channel_format_t channel_format() const;
132132

133133
/**
134134
* Unique identifier of the stream's source, if available.

src/lsl_streaminfo_c.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LIBLSL_C_API lsl_streaminfo lsl_create_streaminfo(const char *name, const char *
1414
try {
1515
if (!source_id)
1616
source_id = "";
17-
return (lsl_streaminfo)new stream_info_impl(name,type,channel_count,nominal_srate,(channel_format_t)channel_format,source_id);
17+
return (lsl_streaminfo)new stream_info_impl(name,type,channel_count,nominal_srate,(lsl_channel_format_t)channel_format,source_id);
1818
} catch(std::exception &e) {
1919
std::cerr << "Unexpected error during streaminfo construction: " << e.what() << std::endl;
2020
return NULL;
@@ -42,7 +42,7 @@ LIBLSL_C_API const char *lsl_get_type(lsl_streaminfo info) { return ((stream_inf
4242
LIBLSL_C_API const char *lsl_get_name(lsl_streaminfo info) { return ((stream_info_impl*)info)->name().c_str(); }
4343
LIBLSL_C_API int32_t lsl_get_channel_count(lsl_streaminfo info) { return ((stream_info_impl*)info)->channel_count(); }
4444
LIBLSL_C_API double lsl_get_nominal_srate(lsl_streaminfo info) { return ((stream_info_impl*)info)->nominal_srate(); }
45-
LIBLSL_C_API lsl_channel_format_t lsl_get_channel_format(lsl_streaminfo info) { return (lsl_channel_format_t)((stream_info_impl*)info)->channel_format(); }
45+
LIBLSL_C_API lsl_channel_format_t lsl_get_channel_format(lsl_streaminfo info) { return ((stream_info_impl*)info)->channel_format(); }
4646
LIBLSL_C_API const char *lsl_get_source_id(lsl_streaminfo info) { return ((stream_info_impl*)info)->source_id().c_str(); }
4747
LIBLSL_C_API int32_t lsl_get_version(lsl_streaminfo info) { return ((stream_info_impl*)info)->version(); }
4848
LIBLSL_C_API double lsl_get_created_at(lsl_streaminfo info) { return ((stream_info_impl*)info)->created_at(); }

0 commit comments

Comments
 (0)