]>
Commit | Line | Data |
---|---|---|
2953961c | 1 | /* |
b3f22de0 | 2 | * This file is part of the PulseView project. |
2953961c JH |
3 | * |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include "sigsession.h" | |
22 | ||
dc0867ff | 23 | #include "devicemanager.h" |
119aff65 | 24 | |
1b1ec774 JH |
25 | #include "data/analog.h" |
26 | #include "data/analogsnapshot.h" | |
119aff65 | 27 | #include "data/decoder.h" |
1b1ec774 JH |
28 | #include "data/logic.h" |
29 | #include "data/logicsnapshot.h" | |
82c7f640 | 30 | |
aba1dd16 | 31 | #include "view/analogsignal.h" |
82c7f640 | 32 | #include "view/decodesignal.h" |
8d634081 | 33 | #include "view/logicsignal.h" |
28a4c9c5 | 34 | |
2953961c JH |
35 | #include <assert.h> |
36 | ||
728e5ef7 JH |
37 | #include <sys/stat.h> |
38 | ||
79efbc53 JH |
39 | #include <QDebug> |
40 | ||
28a4c9c5 | 41 | using namespace boost; |
e3f65ace | 42 | using namespace std; |
28a4c9c5 | 43 | |
51e77110 JH |
44 | namespace pv { |
45 | ||
2953961c | 46 | // TODO: This should not be necessary |
04abfae9 | 47 | SigSession* SigSession::_session = NULL; |
2953961c | 48 | |
dc0867ff JH |
49 | SigSession::SigSession(DeviceManager &device_manager) : |
50 | _device_manager(device_manager), | |
d64d1596 | 51 | _sdi(NULL), |
5b7cf66c | 52 | _capture_state(Stopped) |
2953961c JH |
53 | { |
54 | // TODO: This should not be necessary | |
04abfae9 | 55 | _session = this; |
2953961c JH |
56 | } |
57 | ||
58 | SigSession::~SigSession() | |
59 | { | |
5b7cf66c JH |
60 | stop_capture(); |
61 | ||
e042ad64 | 62 | _sampling_thread.join(); |
2e2946fe | 63 | |
0f784939 JH |
64 | if (_sdi) |
65 | _device_manager.release_device(_sdi); | |
66 | _sdi = NULL; | |
67 | ||
2953961c | 68 | // TODO: This should not be necessary |
04abfae9 | 69 | _session = NULL; |
2953961c JH |
70 | } |
71 | ||
dc0867ff JH |
72 | struct sr_dev_inst* SigSession::get_device() const |
73 | { | |
74 | return _sdi; | |
75 | } | |
76 | ||
d64d1596 JH |
77 | void SigSession::set_device(struct sr_dev_inst *sdi) |
78 | { | |
88497156 | 79 | if (_sdi) |
dc0867ff | 80 | _device_manager.release_device(_sdi); |
88497156 | 81 | if (sdi) |
dc0867ff | 82 | _device_manager.use_device(sdi, this); |
d64d1596 | 83 | _sdi = sdi; |
b698553c | 84 | update_signals(sdi); |
d64d1596 JH |
85 | } |
86 | ||
dc0867ff JH |
87 | void SigSession::release_device(struct sr_dev_inst *sdi) |
88 | { | |
89 | (void)sdi; | |
90 | ||
91 | assert(_capture_state == Stopped); | |
92 | _sdi = NULL; | |
b698553c | 93 | update_signals(NULL); |
dc0867ff JH |
94 | } |
95 | ||
f2edb557 JH |
96 | void SigSession::load_file(const string &name, |
97 | function<void (const QString)> error_handler) | |
2953961c | 98 | { |
8a67bd9e | 99 | stop_capture(); |
e8c9f8a5 JH |
100 | |
101 | if (sr_session_load(name.c_str()) == SR_OK) { | |
102 | GSList *devlist = NULL; | |
103 | sr_session_dev_list(&devlist); | |
104 | ||
105 | if (!devlist || !devlist->data || | |
106 | sr_session_start() != SR_OK) { | |
107 | error_handler(tr("Failed to start session.")); | |
108 | return; | |
109 | } | |
110 | ||
deef291c | 111 | sr_dev_inst *const sdi = (sr_dev_inst*)devlist->data; |
e8c9f8a5 JH |
112 | g_slist_free(devlist); |
113 | ||
deef291c JH |
114 | update_signals(sdi); |
115 | read_sample_rate(sdi); | |
116 | ||
e042ad64 | 117 | _sampling_thread = boost::thread( |
e8c9f8a5 | 118 | &SigSession::load_session_thread_proc, this, |
e042ad64 | 119 | error_handler); |
e8c9f8a5 JH |
120 | |
121 | } else { | |
122 | sr_input *in = NULL; | |
123 | ||
124 | if (!(in = load_input_file_format(name.c_str(), | |
125 | error_handler))) | |
126 | return; | |
127 | ||
128 | update_signals(in->sdi); | |
deef291c | 129 | read_sample_rate(in->sdi); |
e8c9f8a5 | 130 | |
e042ad64 | 131 | _sampling_thread = boost::thread( |
e8c9f8a5 | 132 | &SigSession::load_input_thread_proc, this, |
e042ad64 | 133 | name, in, error_handler); |
e8c9f8a5 | 134 | } |
2953961c JH |
135 | } |
136 | ||
5b7cf66c JH |
137 | SigSession::capture_state SigSession::get_capture_state() const |
138 | { | |
949f8050 | 139 | lock_guard<mutex> lock(_sampling_mutex); |
5b7cf66c JH |
140 | return _capture_state; |
141 | } | |
142 | ||
d64d1596 | 143 | void SigSession::start_capture(uint64_t record_length, |
f2edb557 | 144 | function<void (const QString)> error_handler) |
2e2946fe | 145 | { |
5b7cf66c JH |
146 | stop_capture(); |
147 | ||
d64d1596 JH |
148 | // Check that a device instance has been selected. |
149 | if (!_sdi) { | |
150 | qDebug() << "No device selected"; | |
151 | return; | |
152 | } | |
153 | ||
9c48fa57 JH |
154 | // Check that at least one probe is enabled |
155 | const GSList *l; | |
d64d1596 | 156 | for (l = _sdi->probes; l; l = l->next) { |
9c48fa57 JH |
157 | sr_probe *const probe = (sr_probe*)l->data; |
158 | assert(probe); | |
159 | if (probe->enabled) | |
160 | break; | |
161 | } | |
162 | ||
163 | if (!l) { | |
164 | error_handler(tr("No probes enabled.")); | |
165 | return; | |
166 | } | |
167 | ||
168 | // Begin the session | |
e042ad64 | 169 | _sampling_thread = boost::thread( |
d64d1596 | 170 | &SigSession::sample_thread_proc, this, _sdi, |
e042ad64 | 171 | record_length, error_handler); |
2e2946fe JH |
172 | } |
173 | ||
5b7cf66c JH |
174 | void SigSession::stop_capture() |
175 | { | |
333d5bbc | 176 | if (get_capture_state() == Stopped) |
5b7cf66c JH |
177 | return; |
178 | ||
179 | sr_session_stop(); | |
180 | ||
181 | // Check that sampling stopped | |
e042ad64 | 182 | _sampling_thread.join(); |
5b7cf66c JH |
183 | } |
184 | ||
38eeddea | 185 | vector< shared_ptr<view::Signal> > SigSession::get_signals() const |
2e2946fe | 186 | { |
3868e5fa | 187 | lock_guard<mutex> lock(_signals_mutex); |
2e2946fe JH |
188 | return _signals; |
189 | } | |
190 | ||
1b1ec774 | 191 | boost::shared_ptr<data::Logic> SigSession::get_data() |
2e2946fe JH |
192 | { |
193 | return _logic_data; | |
194 | } | |
195 | ||
708c5523 JH |
196 | void SigSession::add_decoder(srd_decoder *const dec, |
197 | std::map<const srd_probe*, | |
198 | boost::shared_ptr<view::Signal> > probes) | |
82c7f640 JH |
199 | { |
200 | { | |
119aff65 | 201 | lock_guard<mutex> lock(_signals_mutex); |
e0fc5810 JH |
202 | |
203 | if (!_decode_traces.empty()) { | |
204 | qDebug("Currently only one decode trace can be added " | |
205 | "at once"); | |
206 | _decode_traces.clear(); | |
207 | } | |
208 | ||
119aff65 | 209 | shared_ptr<data::Decoder> decoder( |
708c5523 | 210 | new data::Decoder(dec, probes)); |
119aff65 | 211 | shared_ptr<view::DecodeSignal> d( |
06bb4e6a JH |
212 | new view::DecodeSignal(*this, decoder, |
213 | _decode_traces.size())); | |
82c7f640 JH |
214 | _decode_traces.push_back(d); |
215 | } | |
216 | signals_changed(); | |
217 | } | |
218 | ||
38eeddea JH |
219 | vector< shared_ptr<view::DecodeSignal> > SigSession::get_decode_signals() const |
220 | { | |
221 | lock_guard<mutex> lock(_signals_mutex); | |
222 | return _decode_traces; | |
223 | } | |
224 | ||
6ac96c2e JH |
225 | void SigSession::set_capture_state(capture_state state) |
226 | { | |
949f8050 | 227 | lock_guard<mutex> lock(_sampling_mutex); |
2b49eeb0 | 228 | const bool changed = _capture_state != state; |
6ac96c2e | 229 | _capture_state = state; |
2b49eeb0 JH |
230 | if(changed) |
231 | capture_state_changed(state); | |
6ac96c2e JH |
232 | } |
233 | ||
728e5ef7 JH |
234 | /** |
235 | * Attempts to autodetect the format. Failing that | |
236 | * @param filename The filename of the input file. | |
237 | * @return A pointer to the 'struct sr_input_format' that should be used, | |
238 | * or NULL if no input format was selected or auto-detected. | |
239 | */ | |
240 | sr_input_format* SigSession::determine_input_file_format( | |
241 | const string &filename) | |
242 | { | |
243 | int i; | |
244 | ||
245 | /* If there are no input formats, return NULL right away. */ | |
246 | sr_input_format *const *const inputs = sr_input_list(); | |
247 | if (!inputs) { | |
248 | g_critical("No supported input formats available."); | |
249 | return NULL; | |
250 | } | |
251 | ||
252 | /* Otherwise, try to find an input module that can handle this file. */ | |
253 | for (i = 0; inputs[i]; i++) { | |
254 | if (inputs[i]->format_match(filename.c_str())) | |
255 | break; | |
256 | } | |
257 | ||
258 | /* Return NULL if no input module wanted to touch this. */ | |
259 | if (!inputs[i]) { | |
260 | g_critical("Error: no matching input module found."); | |
261 | return NULL; | |
262 | } | |
263 | ||
264 | return inputs[i]; | |
265 | } | |
266 | ||
267 | sr_input* SigSession::load_input_file_format(const string &filename, | |
268 | function<void (const QString)> error_handler, | |
269 | sr_input_format *format) | |
270 | { | |
271 | struct stat st; | |
272 | sr_input *in; | |
273 | ||
274 | if (!format && !(format = | |
275 | determine_input_file_format(filename.c_str()))) { | |
276 | /* The exact cause was already logged. */ | |
277 | return NULL; | |
278 | } | |
279 | ||
280 | if (stat(filename.c_str(), &st) == -1) { | |
281 | error_handler(tr("Failed to load file")); | |
282 | return NULL; | |
283 | } | |
284 | ||
285 | /* Initialize the input module. */ | |
286 | if (!(in = new sr_input)) { | |
287 | qDebug("Failed to allocate input module.\n"); | |
288 | return NULL; | |
289 | } | |
290 | ||
291 | in->format = format; | |
292 | in->param = NULL; | |
293 | if (in->format->init && | |
294 | in->format->init(in, filename.c_str()) != SR_OK) { | |
295 | qDebug("Input format init failed.\n"); | |
296 | return NULL; | |
297 | } | |
298 | ||
299 | sr_session_new(); | |
300 | ||
301 | if (sr_session_dev_add(in->sdi) != SR_OK) { | |
302 | qDebug("Failed to use device.\n"); | |
303 | sr_session_destroy(); | |
304 | return NULL; | |
305 | } | |
306 | ||
307 | return in; | |
308 | } | |
309 | ||
b698553c | 310 | void SigSession::update_signals(const sr_dev_inst *const sdi) |
b087ba7f JH |
311 | { |
312 | assert(_capture_state == Stopped); | |
313 | ||
314 | shared_ptr<view::Signal> signal; | |
315 | unsigned int logic_probe_count = 0; | |
316 | unsigned int analog_probe_count = 0; | |
317 | ||
82c7f640 JH |
318 | // Clear the decode traces |
319 | _decode_traces.clear(); | |
320 | ||
b087ba7f | 321 | // Detect what data types we will receive |
b698553c JH |
322 | if(sdi) { |
323 | for (const GSList *l = sdi->probes; l; l = l->next) { | |
b087ba7f JH |
324 | const sr_probe *const probe = (const sr_probe *)l->data; |
325 | if (!probe->enabled) | |
326 | continue; | |
327 | ||
328 | switch(probe->type) { | |
329 | case SR_PROBE_LOGIC: | |
330 | logic_probe_count++; | |
331 | break; | |
332 | ||
333 | case SR_PROBE_ANALOG: | |
334 | analog_probe_count++; | |
335 | break; | |
336 | } | |
337 | } | |
338 | } | |
339 | ||
340 | // Create data containers for the data snapshots | |
341 | { | |
342 | lock_guard<mutex> data_lock(_data_mutex); | |
343 | ||
344 | _logic_data.reset(); | |
345 | if (logic_probe_count != 0) { | |
346 | _logic_data.reset(new data::Logic( | |
347 | logic_probe_count)); | |
348 | assert(_logic_data); | |
349 | } | |
350 | ||
351 | _analog_data.reset(); | |
352 | if (analog_probe_count != 0) { | |
353 | _analog_data.reset(new data::Analog()); | |
354 | assert(_analog_data); | |
355 | } | |
356 | } | |
357 | ||
358 | // Make the Signals list | |
359 | { | |
360 | lock_guard<mutex> lock(_signals_mutex); | |
361 | ||
362 | _signals.clear(); | |
363 | ||
b698553c JH |
364 | if(sdi) { |
365 | for (const GSList *l = sdi->probes; l; l = l->next) { | |
b087ba7f JH |
366 | const sr_probe *const probe = |
367 | (const sr_probe *)l->data; | |
368 | assert(probe); | |
b087ba7f JH |
369 | |
370 | switch(probe->type) { | |
371 | case SR_PROBE_LOGIC: | |
372 | signal = shared_ptr<view::Signal>( | |
c0f86852 | 373 | new view::LogicSignal(*this, probe, |
cec48d16 | 374 | _logic_data)); |
b087ba7f JH |
375 | break; |
376 | ||
377 | case SR_PROBE_ANALOG: | |
378 | signal = shared_ptr<view::Signal>( | |
c0f86852 | 379 | new view::AnalogSignal(*this, probe, |
cec48d16 | 380 | _analog_data)); |
b087ba7f JH |
381 | break; |
382 | } | |
383 | ||
384 | _signals.push_back(signal); | |
385 | } | |
386 | } | |
387 | } | |
388 | ||
389 | signals_changed(); | |
390 | } | |
391 | ||
2b49eeb0 JH |
392 | bool SigSession::is_trigger_enabled() const |
393 | { | |
394 | assert(_sdi); | |
395 | for (const GSList *l = _sdi->probes; l; l = l->next) { | |
396 | const sr_probe *const p = (const sr_probe *)l->data; | |
397 | assert(p); | |
398 | if (p->trigger && p->trigger[0] != '\0') | |
399 | return true; | |
400 | } | |
401 | ||
402 | return false; | |
403 | } | |
404 | ||
deef291c JH |
405 | void SigSession::read_sample_rate(const sr_dev_inst *const sdi) |
406 | { | |
407 | GVariant *gvar; | |
408 | uint64_t sample_rate = 0; | |
409 | ||
410 | // Read out the sample rate | |
411 | if(sdi->driver) | |
412 | { | |
413 | const int ret = sr_config_get(sdi->driver, | |
414 | SR_CONF_SAMPLERATE, &gvar, sdi); | |
415 | if (ret != SR_OK) { | |
416 | qDebug("Failed to get samplerate\n"); | |
417 | return; | |
418 | } | |
419 | ||
420 | sample_rate = g_variant_get_uint64(gvar); | |
421 | g_variant_unref(gvar); | |
422 | } | |
423 | ||
424 | if(_analog_data) | |
425 | _analog_data->set_samplerate(sample_rate); | |
426 | if(_logic_data) | |
427 | _logic_data->set_samplerate(sample_rate); | |
428 | } | |
429 | ||
e8c9f8a5 | 430 | void SigSession::load_session_thread_proc( |
f2edb557 | 431 | function<void (const QString)> error_handler) |
8a67bd9e | 432 | { |
e8c9f8a5 | 433 | (void)error_handler; |
728e5ef7 | 434 | |
e8c9f8a5 JH |
435 | sr_session_datafeed_callback_add(data_feed_in_proc, NULL); |
436 | ||
437 | set_capture_state(Running); | |
438 | ||
439 | sr_session_run(); | |
440 | ||
441 | sr_session_destroy(); | |
442 | set_capture_state(Stopped); | |
443 | ||
444 | // Confirm that SR_DF_END was received | |
445 | assert(!_cur_logic_snapshot); | |
446 | assert(!_cur_analog_snapshot); | |
447 | } | |
448 | ||
449 | void SigSession::load_input_thread_proc(const string name, | |
450 | sr_input *in, function<void (const QString)> error_handler) | |
451 | { | |
452 | (void)error_handler; | |
453 | ||
454 | assert(in); | |
455 | assert(in->format); | |
8a67bd9e | 456 | |
5045f16d | 457 | sr_session_datafeed_callback_add(data_feed_in_proc, NULL); |
8a67bd9e | 458 | |
8a67bd9e JH |
459 | set_capture_state(Running); |
460 | ||
e8c9f8a5 | 461 | in->format->loadfile(in, name.c_str()); |
8a67bd9e | 462 | |
728e5ef7 | 463 | sr_session_destroy(); |
8a67bd9e | 464 | set_capture_state(Stopped); |
1a2fe44c JH |
465 | |
466 | // Confirm that SR_DF_END was received | |
467 | assert(!_cur_logic_snapshot); | |
468 | assert(!_cur_analog_snapshot); | |
728e5ef7 JH |
469 | |
470 | delete in; | |
8a67bd9e JH |
471 | } |
472 | ||
2e2946fe | 473 | void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, |
f2edb557 JH |
474 | uint64_t record_length, |
475 | function<void (const QString)> error_handler) | |
274d4f13 | 476 | { |
be73bdfa | 477 | assert(sdi); |
f2edb557 | 478 | assert(error_handler); |
be73bdfa | 479 | |
274d4f13 | 480 | sr_session_new(); |
5045f16d | 481 | sr_session_datafeed_callback_add(data_feed_in_proc, NULL); |
274d4f13 JH |
482 | |
483 | if (sr_session_dev_add(sdi) != SR_OK) { | |
f2edb557 | 484 | error_handler(tr("Failed to use device.")); |
274d4f13 JH |
485 | sr_session_destroy(); |
486 | return; | |
487 | } | |
488 | ||
be73bdfa JH |
489 | // Set the sample limit |
490 | if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, | |
8eb9d311 | 491 | g_variant_new_uint64(record_length)) != SR_OK) { |
f2edb557 JH |
492 | error_handler(tr("Failed to configure " |
493 | "time-based sample limit.")); | |
274d4f13 JH |
494 | sr_session_destroy(); |
495 | return; | |
496 | } | |
497 | ||
eec446e1 | 498 | if (sr_session_start() != SR_OK) { |
f2edb557 | 499 | error_handler(tr("Failed to start session.")); |
eec446e1 JH |
500 | return; |
501 | } | |
502 | ||
2b49eeb0 | 503 | set_capture_state(is_trigger_enabled() ? AwaitingTrigger : Running); |
eec446e1 JH |
504 | |
505 | sr_session_run(); | |
506 | sr_session_destroy(); | |
507 | ||
508 | set_capture_state(Stopped); | |
1a2fe44c JH |
509 | |
510 | // Confirm that SR_DF_END was received | |
511 | assert(!_cur_logic_snapshot); | |
512 | assert(!_cur_analog_snapshot); | |
eec446e1 JH |
513 | } |
514 | ||
515 | void SigSession::feed_in_header(const sr_dev_inst *sdi) | |
516 | { | |
deef291c | 517 | read_sample_rate(sdi); |
be73bdfa JH |
518 | } |
519 | ||
520 | void SigSession::feed_in_meta(const sr_dev_inst *sdi, | |
521 | const sr_datafeed_meta &meta) | |
522 | { | |
94fe58ef UH |
523 | (void)sdi; |
524 | ||
be73bdfa JH |
525 | for (const GSList *l = meta.config; l; l = l->next) { |
526 | const sr_config *const src = (const sr_config*)l->data; | |
527 | switch (src->key) { | |
528 | case SR_CONF_SAMPLERATE: | |
529 | /// @todo handle samplerate changes | |
530 | /// samplerate = (uint64_t *)src->value; | |
531 | break; | |
532 | default: | |
533 | // Unknown metadata is not an error. | |
534 | break; | |
535 | } | |
aba1dd16 | 536 | } |
74043039 JH |
537 | |
538 | signals_changed(); | |
aba1dd16 JH |
539 | } |
540 | ||
9c112671 JH |
541 | void SigSession::feed_in_logic(const sr_datafeed_logic &logic) |
542 | { | |
543 | lock_guard<mutex> lock(_data_mutex); | |
79efbc53 JH |
544 | |
545 | if (!_logic_data) | |
9c112671 | 546 | { |
79efbc53 JH |
547 | qDebug() << "Unexpected logic packet"; |
548 | return; | |
549 | } | |
be73bdfa | 550 | |
79efbc53 JH |
551 | if (!_cur_logic_snapshot) |
552 | { | |
2b49eeb0 JH |
553 | set_capture_state(Running); |
554 | ||
9c112671 | 555 | // Create a new data snapshot |
1b1ec774 JH |
556 | _cur_logic_snapshot = shared_ptr<data::LogicSnapshot>( |
557 | new data::LogicSnapshot(logic)); | |
9c112671 JH |
558 | _logic_data->push_snapshot(_cur_logic_snapshot); |
559 | } | |
560 | else | |
561 | { | |
562 | // Append to the existing data snapshot | |
563 | _cur_logic_snapshot->append_payload(logic); | |
564 | } | |
565 | ||
566 | data_updated(); | |
567 | } | |
568 | ||
aba1dd16 JH |
569 | void SigSession::feed_in_analog(const sr_datafeed_analog &analog) |
570 | { | |
571 | lock_guard<mutex> lock(_data_mutex); | |
79efbc53 JH |
572 | |
573 | if(!_analog_data) | |
aba1dd16 | 574 | { |
79efbc53 JH |
575 | qDebug() << "Unexpected analog packet"; |
576 | return; // This analog packet was not expected. | |
577 | } | |
be73bdfa | 578 | |
79efbc53 JH |
579 | if (!_cur_analog_snapshot) |
580 | { | |
2b49eeb0 JH |
581 | set_capture_state(Running); |
582 | ||
aba1dd16 | 583 | // Create a new data snapshot |
1b1ec774 JH |
584 | _cur_analog_snapshot = shared_ptr<data::AnalogSnapshot>( |
585 | new data::AnalogSnapshot(analog)); | |
aba1dd16 JH |
586 | _analog_data->push_snapshot(_cur_analog_snapshot); |
587 | } | |
588 | else | |
589 | { | |
590 | // Append to the existing data snapshot | |
591 | _cur_analog_snapshot->append_payload(analog); | |
592 | } | |
593 | ||
594 | data_updated(); | |
595 | } | |
9c112671 | 596 | |
b0e1d01d JH |
597 | void SigSession::data_feed_in(const struct sr_dev_inst *sdi, |
598 | const struct sr_datafeed_packet *packet) | |
599 | { | |
600 | assert(sdi); | |
601 | assert(packet); | |
602 | ||
603 | switch (packet->type) { | |
604 | case SR_DF_HEADER: | |
eec446e1 | 605 | feed_in_header(sdi); |
b0e1d01d JH |
606 | break; |
607 | ||
be73bdfa | 608 | case SR_DF_META: |
aba1dd16 | 609 | assert(packet->payload); |
be73bdfa JH |
610 | feed_in_meta(sdi, |
611 | *(const sr_datafeed_meta*)packet->payload); | |
aba1dd16 JH |
612 | break; |
613 | ||
2e2946fe | 614 | case SR_DF_LOGIC: |
28a4c9c5 | 615 | assert(packet->payload); |
9c112671 | 616 | feed_in_logic(*(const sr_datafeed_logic*)packet->payload); |
2953961c JH |
617 | break; |
618 | ||
aba1dd16 JH |
619 | case SR_DF_ANALOG: |
620 | assert(packet->payload); | |
621 | feed_in_analog(*(const sr_datafeed_analog*)packet->payload); | |
622 | break; | |
623 | ||
2953961c | 624 | case SR_DF_END: |
2e2946fe JH |
625 | { |
626 | { | |
627 | lock_guard<mutex> lock(_data_mutex); | |
628 | _cur_logic_snapshot.reset(); | |
aba1dd16 | 629 | _cur_analog_snapshot.reset(); |
2e2946fe | 630 | } |
04abfae9 | 631 | data_updated(); |
2953961c JH |
632 | break; |
633 | } | |
2e2946fe | 634 | } |
2953961c JH |
635 | } |
636 | ||
04abfae9 | 637 | void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi, |
5045f16d | 638 | const struct sr_datafeed_packet *packet, void *cb_data) |
2953961c | 639 | { |
5045f16d | 640 | (void) cb_data; |
04abfae9 JH |
641 | assert(_session); |
642 | _session->data_feed_in(sdi, packet); | |
2953961c | 643 | } |
51e77110 JH |
644 | |
645 | } // namespace pv |