|
| 1 | +#include "api_config.h" |
1 | 2 | #include "common.h" |
2 | 3 | #include <algorithm> |
3 | 4 | #include <boost/chrono/duration.hpp> |
4 | 5 | #include <boost/chrono/system_clocks.hpp> |
5 | 6 | #include <cctype> |
6 | 7 |
|
7 | 8 | #ifdef _WIN32 |
8 | | -#include "api_config.h" |
9 | 9 | #include <windows.h> |
10 | 10 | #include <mmsystem.h> |
11 | 11 | #pragma comment (lib,"winmm.lib") |
12 | 12 | #endif |
13 | 13 |
|
14 | | -// === implementation of misc functions === |
| 14 | +// === Implementation of the free-standing functions in lsl_c.h === |
| 15 | + |
| 16 | +extern "C" { |
| 17 | +#include "../include/lsl_c.h" |
| 18 | + |
| 19 | +/// Get the protocol version. |
| 20 | +LIBLSL_C_API int32_t lsl_protocol_version() { |
| 21 | + return lsl::api_config::get_instance()->use_protocol_version(); |
| 22 | +} |
| 23 | + |
| 24 | +/// Get the library version. |
| 25 | +LIBLSL_C_API int32_t lsl_library_version() { return LSL_LIBRARY_VERSION; } |
15 | 26 |
|
| 27 | +/// Get a string containing library information |
| 28 | +LIBLSL_C_API const char *lsl_library_info() { |
| 29 | +#ifdef LSL_LIBRARY_INFO_STR |
| 30 | + return LSL_LIBRARY_INFO_STR; |
| 31 | +#else |
| 32 | + return "Unknown (not set by build system)"; |
| 33 | +#endif |
| 34 | +} |
| 35 | + |
| 36 | +/** Obtain a local system time stamp in seconds. |
| 37 | + * |
| 38 | + * The resolution is better than a millisecond. |
| 39 | + * This reading can be used to assign time stamps to samples as they are being |
| 40 | + * acquired. |
| 41 | + * |
| 42 | + * If the "age" of a sample is known at a particular time (e.g., from USB |
| 43 | + * transmission delays), it can be used as an offset to local_clock() to obtain |
| 44 | + * a better estimate of when a sample was actually captured. */ |
| 45 | +LIBLSL_C_API double lsl_local_clock() { |
| 46 | + return lslboost::chrono::nanoseconds( |
| 47 | + lslboost::chrono::high_resolution_clock::now().time_since_epoch()) |
| 48 | + .count() / |
| 49 | + 1000000000.0; |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +/** Deallocate a string that has been transferred to the application. |
| 54 | + * |
| 55 | + * The only use case is to deallocate the contents of string-valued samples |
| 56 | + * received from LSL in an application where no free() method is available |
| 57 | + * (e.g., in some scripting languages). */ |
| 58 | +LIBLSL_C_API void lsl_destroy_string(char *s) { |
| 59 | + if (s) free(s); |
| 60 | +} |
| 61 | +} |
| 62 | + |
| 63 | +// === implementation of misc functions === |
16 | 64 | /// Implementation of the clock facility. |
17 | 65 | double lsl::lsl_clock() { |
18 | | - return lslboost::chrono::nanoseconds(lslboost::chrono::high_resolution_clock::now().time_since_epoch()).count()/1000000000.0; |
| 66 | + return lsl_local_clock(); |
19 | 67 | } |
20 | 68 |
|
21 | 69 | /// Ensure that LSL is initialized. Performs initialization tasks |
@@ -78,4 +126,3 @@ std::string lsl::trim(const std::string& input) |
78 | 126 | if(first == std::string::npos || last == std::string::npos) return ""; |
79 | 127 | return input.substr(first, last-first+1); |
80 | 128 | } |
81 | | - |
|
0 commit comments