File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -227,3 +227,12 @@ extern LIBLSL_C_API double lsl_local_clock();
227227 * no free() method is available (e.g., in some scripting languages).
228228 */
229229extern LIBLSL_C_API void lsl_destroy_string (char *s);
230+
231+ /* *
232+ * Set the name of the configuration file to be used.
233+ *
234+ * This is a global setting that will be used by all LSL
235+ * after this function is called. If, and only if, this function
236+ * is called before the first call to any other LSL function.
237+ */
238+ extern LIBLSL_C_API void lsl_set_config_filename (const char *filename);
Original file line number Diff line number Diff line change @@ -55,6 +55,16 @@ api_config::api_config() {
5555 // for each config file location under consideration...
5656 std::vector<std::string> filenames;
5757
58+ // NOLINTNEXTLINE(concurrency-mt-unsafe)
59+ if (api_config_filename_ != " " ) {
60+ // if a config file name was set, use it if it is readable
61+ if (file_is_readable (api_config_filename_)) {
62+ filenames.insert (filenames.begin (), api_config_filename_);
63+ } else {
64+ LOG_F (ERROR, " Config file %s not found" , api_config_filename_.c_str ());
65+ }
66+ }
67+
5868 // NOLINTNEXTLINE(concurrency-mt-unsafe)
5969 if (auto *cfgpath = getenv (" LSLAPICFG" )) {
6070 std::string envcfg (cfgpath);
Original file line number Diff line number Diff line change @@ -76,6 +76,21 @@ class api_config {
7676 bool allow_ipv6 () const { return allow_ipv6_; }
7777 bool allow_ipv4 () const { return allow_ipv4_; }
7878
79+ /* *
80+ * @brief An additional settings path to load configuration from.
81+ */
82+ const std::string &api_config_filename () const { return api_config_filename_; }
83+
84+ /* *
85+ * @brief Set the config file name used to load the settings.
86+ *
87+ * This MUST be called before the first call to get_instance() to have any effect.
88+ */
89+ static void set_api_config_filename (const std::string &filename) {
90+ api_config_filename_ = filename;
91+ }
92+
93+
7994 /* *
8095 * @brief The range or scope of stream lookup when using multicast-based discovery
8196 *
@@ -221,6 +236,8 @@ class api_config {
221236 */
222237 void load_from_file (const std::string &filename = std::string());
223238
239+ static std::string api_config_filename_ = " " ;
240+
224241 // core parameters
225242 bool allow_ipv6_, allow_ipv4_;
226243 uint16_t base_port_;
Original file line number Diff line number Diff line change @@ -26,6 +26,12 @@ LIBLSL_C_API int32_t lsl_protocol_version() {
2626 return lsl::api_config::get_instance ()->use_protocol_version ();
2727}
2828
29+ LIBLSL_C_API void lsl_set_config_filename (const char *filename) {
30+ if (filename) {
31+ lsl::api_config::set_api_config_filename (filename);
32+ }
33+ }
34+
2935LIBLSL_C_API int32_t lsl_library_version () { return LSL_LIBRARY_VERSION; }
3036
3137LIBLSL_C_API double lsl_local_clock () {
You can’t perform that action at this time.
0 commit comments