1
+ #include " lsl_c_api_helpers.hpp"
1
2
#include " stream_inlet_impl.h"
2
3
3
4
extern " C" {
@@ -9,20 +10,9 @@ using namespace lsl;
9
10
10
11
LIBLSL_C_API lsl_inlet lsl_create_inlet (
11
12
lsl_streaminfo info, int32_t max_buflen, int32_t max_chunklen, int32_t recover) {
12
- try {
13
- stream_info_impl *infoimpl = info;
14
- lsl_inlet result = new stream_inlet_impl (*infoimpl,
15
- infoimpl->nominal_srate () ? (int )(infoimpl->nominal_srate () * max_buflen)
16
- : max_buflen * 100 ,
17
- max_chunklen, recover != 0 );
18
- return result;
19
- } catch (std::invalid_argument &e) {
20
- LOG_F (WARNING, " Error during construction of a stream_inlet: %s" , e.what ());
21
- return nullptr ;
22
- } catch (std::exception &e) {
23
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
24
- return nullptr ;
25
- }
13
+ return create_object_noexcept<stream_inlet_impl>(*info,
14
+ info->nominal_srate () ? (int )(info->nominal_srate () * max_buflen) : max_buflen * 100 ,
15
+ max_chunklen, recover != 0 );
26
16
}
27
17
28
18
LIBLSL_C_API void lsl_destroy_inlet (lsl_inlet in) {
@@ -32,32 +22,14 @@ LIBLSL_C_API void lsl_destroy_inlet(lsl_inlet in) {
32
22
}
33
23
34
24
LIBLSL_C_API lsl_streaminfo lsl_get_fullinfo (lsl_inlet in, double timeout, int32_t *ec) {
35
- if (ec) *ec = lsl_no_error;
36
- try {
37
- return new stream_info_impl (in->info (timeout));
38
- } catch (timeout_error &) {
39
- if (ec) *ec = lsl_timeout_error;
40
- } catch (lost_error &) {
41
- if (ec) *ec = lsl_lost_error;
42
- } catch (std::exception &e) {
43
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
44
- if (ec) *ec = lsl_internal_error;
45
- }
46
- return nullptr ;
25
+ return create_object_noexcept<stream_info_impl>(in->info (timeout));
47
26
}
48
27
49
28
LIBLSL_C_API void lsl_open_stream (lsl_inlet in, double timeout, int32_t *ec) {
50
29
if (ec) *ec = lsl_no_error;
51
30
try {
52
31
in->open_stream (timeout);
53
- } catch (timeout_error &) {
54
- if (ec) *ec = lsl_timeout_error;
55
- } catch (lost_error &) {
56
- if (ec) *ec = lsl_lost_error;
57
- } catch (std::exception &e) {
58
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
59
- if (ec) *ec = lsl_internal_error;
60
- }
32
+ } LSL_STORE_EXCEPTION_IN (ec)
61
33
}
62
34
63
35
LIBLSL_C_API void lsl_close_stream (lsl_inlet in) {
@@ -70,14 +42,7 @@ LIBLSL_C_API double lsl_time_correction(lsl_inlet in, double timeout, int32_t *e
70
42
if (ec) *ec = lsl_no_error;
71
43
try {
72
44
return in->time_correction (timeout);
73
- } catch (timeout_error &) {
74
- if (ec) *ec = lsl_timeout_error;
75
- } catch (lost_error &) {
76
- if (ec) *ec = lsl_lost_error;
77
- } catch (std::exception &e) {
78
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
79
- if (ec) *ec = lsl_internal_error;
80
- }
45
+ } LSL_STORE_EXCEPTION_IN (ec)
81
46
return 0.0 ;
82
47
}
83
48
@@ -87,13 +52,7 @@ LIBLSL_C_API double lsl_time_correction_ex(
87
52
try {
88
53
double correction = in->time_correction (remote_time, uncertainty, timeout);
89
54
return correction;
90
- } catch (timeout_error &) {
91
- if (ec) *ec = lsl_timeout_error;
92
- } catch (lost_error &) {
93
- if (ec) *ec = lsl_lost_error;
94
- } catch (std::exception &) {
95
- if (ec) *ec = lsl_internal_error;
96
- }
55
+ } LSL_STORE_EXCEPTION_IN (ec)
97
56
return 0.0 ;
98
57
}
99
58
@@ -160,18 +119,7 @@ LIBLSL_C_API double lsl_pull_sample_str(
160
119
strcpy (buffer[k], tmp[k].c_str ());
161
120
}
162
121
return result;
163
- } catch (timeout_error &) {
164
- if (ec) *ec = lsl_timeout_error;
165
- } catch (lost_error &) {
166
- if (ec) *ec = lsl_lost_error;
167
- } catch (std::invalid_argument &) {
168
- if (ec) *ec = lsl_argument_error;
169
- } catch (std::range_error &) {
170
- if (ec) *ec = lsl_argument_error;
171
- } catch (std::exception &e) {
172
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
173
- if (ec) *ec = lsl_internal_error;
174
- }
122
+ } LSL_STORE_EXCEPTION_IN (ec)
175
123
return 0.0 ;
176
124
}
177
125
@@ -197,18 +145,7 @@ LIBLSL_C_API double lsl_pull_sample_buf(lsl_inlet in, char **buffer, uint32_t *b
197
145
memcpy (buffer[k], &tmp[k][0 ], tmp[k].size ());
198
146
}
199
147
return result;
200
- } catch (timeout_error &) {
201
- if (ec) *ec = lsl_timeout_error;
202
- } catch (lost_error &) {
203
- if (ec) *ec = lsl_lost_error;
204
- } catch (std::invalid_argument &) {
205
- if (ec) *ec = lsl_argument_error;
206
- } catch (std::range_error &) {
207
- if (ec) *ec = lsl_argument_error;
208
- } catch (std::exception &e) {
209
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
210
- if (ec) *ec = lsl_internal_error;
211
- }
148
+ } LSL_STORE_EXCEPTION_IN (ec)
212
149
return 0.0 ;
213
150
}
214
151
@@ -217,18 +154,7 @@ LIBLSL_C_API double lsl_pull_sample_v(
217
154
if (ec) *ec = lsl_no_error;
218
155
try {
219
156
return in->pull_numeric_raw (buffer, buffer_bytes, timeout);
220
- } catch (timeout_error &) {
221
- if (ec) *ec = lsl_timeout_error;
222
- } catch (lost_error &) {
223
- if (ec) *ec = lsl_lost_error;
224
- } catch (std::invalid_argument &) {
225
- if (ec) *ec = lsl_argument_error;
226
- } catch (std::range_error &) {
227
- if (ec) *ec = lsl_argument_error;
228
- } catch (std::exception &e) {
229
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
230
- if (ec) *ec = lsl_internal_error;
231
- }
157
+ } LSL_STORE_EXCEPTION_IN (ec)
232
158
return 0.0 ;
233
159
}
234
160
@@ -297,18 +223,7 @@ LIBLSL_C_API unsigned long lsl_pull_chunk_str(lsl_inlet in, char **data_buffer,
297
223
return result;
298
224
} else
299
225
return 0 ;
300
- } catch (timeout_error &) {
301
- if (ec) *ec = lsl_timeout_error;
302
- } catch (lost_error &) {
303
- if (ec) *ec = lsl_lost_error;
304
- } catch (std::invalid_argument &) {
305
- if (ec) *ec = lsl_argument_error;
306
- } catch (std::range_error &) {
307
- if (ec) *ec = lsl_argument_error;
308
- } catch (std::exception &e) {
309
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
310
- if (ec) *ec = lsl_internal_error;
311
- }
226
+ } LSL_STORE_EXCEPTION_IN (ec)
312
227
return 0 ;
313
228
}
314
229
@@ -336,18 +251,7 @@ LIBLSL_C_API unsigned long lsl_pull_chunk_buf(lsl_inlet in, char **data_buffer,
336
251
return result;
337
252
} else
338
253
return 0 ;
339
- } catch (timeout_error &) {
340
- if (ec) *ec = lsl_timeout_error;
341
- } catch (lost_error &) {
342
- if (ec) *ec = lsl_lost_error;
343
- } catch (std::invalid_argument &) {
344
- if (ec) *ec = lsl_argument_error;
345
- } catch (std::range_error &) {
346
- if (ec) *ec = lsl_argument_error;
347
- } catch (std::exception &e) {
348
- LOG_F (ERROR, " Unexpected error in %s: %s" , __func__, e.what ());
349
- if (ec) *ec = lsl_internal_error;
350
- }
254
+ } LSL_STORE_EXCEPTION_IN (ec)
351
255
return 0 ;
352
256
}
353
257
0 commit comments