@@ -33,7 +33,8 @@ std::mutex mutex;
3333
3434std::pair<int , struct BrainFlowInputParams > get_key (
3535 int board_id, struct BrainFlowInputParams params);
36- static int check_board_session (std::pair<int , struct BrainFlowInputParams > key);
36+ static int check_board_session (int board_id, char *json_brainflow_input_params,
37+ std::pair<int , struct BrainFlowInputParams > &key, bool log_error = true );
3738static int string_to_brainflow_input_params (
3839 const char *json_brainflow_input_params, struct BrainFlowInputParams *params);
3940
@@ -96,24 +97,38 @@ int prepare_session (int board_id, char *json_brainflow_input_params)
9697 {
9798 board = NULL ;
9899 }
99- boards[key] = board;
100+ else
101+ {
102+ boards[key] = board;
103+ }
100104 return res;
101105}
102106
103- int start_stream (
104- int buffer_size, char *streamer_params, int board_id, char *json_brainflow_input_params)
107+ int is_prepared (int *prepared, int board_id, char *json_brainflow_input_params)
105108{
106109 std::lock_guard<std::mutex> lock (mutex);
107110
108- struct BrainFlowInputParams params ;
109- int res = string_to_brainflow_input_params ( json_brainflow_input_params, ¶ms );
110- if (res ! = STATUS_OK)
111+ std::pair< int , struct BrainFlowInputParams > key ;
112+ int res = check_board_session (board_id, json_brainflow_input_params, key, false );
113+ if (res = = STATUS_OK)
111114 {
112- return res ;
115+ *prepared = 1 ;
113116 }
117+ if (res == BOARD_NOT_CREATED_ERROR)
118+ {
119+ *prepared = 0 ;
120+ res = STATUS_OK;
121+ }
122+ return res;
123+ }
114124
115- std::pair<int , struct BrainFlowInputParams > key = get_key (board_id, params);
116- res = check_board_session (key);
125+ int start_stream (
126+ int buffer_size, char *streamer_params, int board_id, char *json_brainflow_input_params)
127+ {
128+ std::lock_guard<std::mutex> lock (mutex);
129+
130+ std::pair<int , struct BrainFlowInputParams > key;
131+ int res = check_board_session (board_id, json_brainflow_input_params, key, false );
117132 if (res != STATUS_OK)
118133 {
119134 return res;
@@ -126,15 +141,8 @@ int stop_stream (int board_id, char *json_brainflow_input_params)
126141{
127142 std::lock_guard<std::mutex> lock (mutex);
128143
129- struct BrainFlowInputParams params;
130- int res = string_to_brainflow_input_params (json_brainflow_input_params, ¶ms);
131- if (res != STATUS_OK)
132- {
133- return res;
134- }
135-
136- std::pair<int , struct BrainFlowInputParams > key = get_key (board_id, params);
137- res = check_board_session (key);
144+ std::pair<int , struct BrainFlowInputParams > key;
145+ int res = check_board_session (board_id, json_brainflow_input_params, key, false );
138146 if (res != STATUS_OK)
139147 {
140148 return res;
@@ -147,15 +155,8 @@ int release_session (int board_id, char *json_brainflow_input_params)
147155{
148156 std::lock_guard<std::mutex> lock (mutex);
149157
150- struct BrainFlowInputParams params;
151- int res = string_to_brainflow_input_params (json_brainflow_input_params, ¶ms);
152- if (res != STATUS_OK)
153- {
154- return res;
155- }
156-
157- std::pair<int , struct BrainFlowInputParams > key = get_key (board_id, params);
158- res = check_board_session (key);
158+ std::pair<int , struct BrainFlowInputParams > key;
159+ int res = check_board_session (board_id, json_brainflow_input_params, key, false );
159160 if (res != STATUS_OK)
160161 {
161162 return res;
@@ -171,15 +172,8 @@ int get_current_board_data (int num_samples, double *data_buf, int *returned_sam
171172{
172173 std::lock_guard<std::mutex> lock (mutex);
173174
174- struct BrainFlowInputParams params;
175- int res = string_to_brainflow_input_params (json_brainflow_input_params, ¶ms);
176- if (res != STATUS_OK)
177- {
178- return res;
179- }
180-
181- std::pair<int , struct BrainFlowInputParams > key = get_key (board_id, params);
182- res = check_board_session (key);
175+ std::pair<int , struct BrainFlowInputParams > key;
176+ int res = check_board_session (board_id, json_brainflow_input_params, key, false );
183177 if (res != STATUS_OK)
184178 {
185179 return res;
@@ -192,15 +186,8 @@ int get_board_data_count (int *result, int board_id, char *json_brainflow_input_
192186{
193187 std::lock_guard<std::mutex> lock (mutex);
194188
195- struct BrainFlowInputParams params;
196- int res = string_to_brainflow_input_params (json_brainflow_input_params, ¶ms);
197- if (res != STATUS_OK)
198- {
199- return res;
200- }
201-
202- std::pair<int , struct BrainFlowInputParams > key = get_key (board_id, params);
203- res = check_board_session (key);
189+ std::pair<int , struct BrainFlowInputParams > key;
190+ int res = check_board_session (board_id, json_brainflow_input_params, key, false );
204191 if (res != STATUS_OK)
205192 {
206193 return res;
@@ -214,15 +201,8 @@ int get_board_data (
214201{
215202 std::lock_guard<std::mutex> lock (mutex);
216203
217- struct BrainFlowInputParams params;
218- int res = string_to_brainflow_input_params (json_brainflow_input_params, ¶ms);
219- if (res != STATUS_OK)
220- {
221- return res;
222- }
223-
224- std::pair<int , struct BrainFlowInputParams > key = get_key (board_id, params);
225- res = check_board_session (key);
204+ std::pair<int , struct BrainFlowInputParams > key;
205+ int res = check_board_session (board_id, json_brainflow_input_params, key, false );
226206 if (res != STATUS_OK)
227207 {
228208 return res;
@@ -273,15 +253,8 @@ int config_board (char *config, int board_id, char *json_brainflow_input_params)
273253{
274254 std::lock_guard<std::mutex> lock (mutex);
275255
276- struct BrainFlowInputParams params;
277- int res = string_to_brainflow_input_params (json_brainflow_input_params, ¶ms);
278- if (res != STATUS_OK)
279- {
280- return res;
281- }
282-
283- std::pair<int , struct BrainFlowInputParams > key = get_key (board_id, params);
284- res = check_board_session (key);
256+ std::pair<int , struct BrainFlowInputParams > key;
257+ int res = check_board_session (board_id, json_brainflow_input_params, key, false );
285258 if (res != STATUS_OK)
286259 {
287260 return res;
@@ -301,12 +274,25 @@ std::pair<int, struct BrainFlowInputParams> get_key (
301274 return key;
302275}
303276
304- int check_board_session (std::pair<int , struct BrainFlowInputParams > key)
277+ int check_board_session (int board_id, char *json_brainflow_input_params,
278+ std::pair<int , struct BrainFlowInputParams > &key, bool log_error)
305279{
280+ struct BrainFlowInputParams params;
281+ int res = string_to_brainflow_input_params (json_brainflow_input_params, ¶ms);
282+ if (res != STATUS_OK)
283+ {
284+ return res;
285+ }
286+
287+ key = get_key (board_id, params);
288+
306289 if (boards.find (key) == boards.end ())
307290 {
308- Board::board_logger->error (
309- " Board with id {} and port provided config is not created" , key.first );
291+ if (log_error)
292+ {
293+ Board::board_logger->error (
294+ " Board with id {} and port provided config is not created" , key.first );
295+ }
310296 return BOARD_NOT_CREATED_ERROR;
311297 }
312298 return STATUS_OK;
0 commit comments