Skip to content

Commit a1c06a2

Browse files
committed
Reorganize functions from lsl_freefuncs_c.cpp and lsl_continuous_resolver_c.cpp into common.cpp and lsl_resolver_c.cpp
1 parent 306b56a commit a1c06a2

File tree

4 files changed

+156
-164
lines changed

4 files changed

+156
-164
lines changed

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ set(lslobj_sources
4848
src/inlet_connection.h
4949
src/loguru/loguru.hpp
5050
src/loguru/loguru.cpp
51-
src/lsl_continuous_resolver_c.cpp
52-
src/lsl_freefuncs_c.cpp
51+
src/lsl_resolver_c.cpp
5352
src/lsl_inlet_c.cpp
5453
src/lsl_outlet_c.cpp
5554
src/lsl_streaminfo_c.cpp
@@ -115,7 +114,7 @@ else()
115114
set(lslgitbranch "unknown")
116115
endif()
117116
set(LSL_VERSION_INFO "\"git:${lslgitrevision}/branch:${lslgitbranch}/build:${CMAKE_BUILD_TYPE}/compiler:${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}/boost:\" BOOST_LIB_VERSION")
118-
set_source_files_properties("src/lsl_freefuncs_c.cpp" PROPERTIES COMPILE_DEFINITIONS LSL_LIBRARY_INFO_STR=${LSL_VERSION_INFO})
117+
set_source_files_properties("src/common.cpp" PROPERTIES COMPILE_DEFINITIONS LSL_LIBRARY_INFO_STR=${LSL_VERSION_INFO})
119118

120119

121120
## create the lslboost target

src/common.cpp

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,69 @@
1+
#include "api_config.h"
12
#include "common.h"
23
#include <algorithm>
34
#include <boost/chrono/duration.hpp>
45
#include <boost/chrono/system_clocks.hpp>
56
#include <cctype>
67

78
#ifdef _WIN32
8-
#include "api_config.h"
99
#include <windows.h>
1010
#include <mmsystem.h>
1111
#pragma comment (lib,"winmm.lib")
1212
#endif
1313

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; }
1526

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 ===
1664
/// Implementation of the clock facility.
1765
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();
1967
}
2068

2169
/// Ensure that LSL is initialized. Performs initialization tasks
@@ -78,4 +126,3 @@ std::string lsl::trim(const std::string& input)
78126
if(first == std::string::npos || last == std::string::npos) return "";
79127
return input.substr(first, last-first+1);
80128
}
81-

src/lsl_continuous_resolver_c.cpp

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)