]> sigrok.org Git - pulseview.git/blame - sigsession.cpp
Fleshed out data model
[pulseview.git] / sigsession.cpp
CommitLineData
2953961c
JH
1/*
2 * This file is part of the sigrok project.
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
28a4c9c5
JH
23#include "logicdata.h"
24#include "logicdatasnapshot.h"
25
009e1503
JH
26#include <QDebug>
27
2953961c
JH
28#include <assert.h>
29
28a4c9c5
JH
30using namespace boost;
31
2953961c
JH
32// TODO: This should not be necessary
33SigSession* SigSession::session = NULL;
34
28a4c9c5 35SigSession::SigSession()
2953961c
JH
36{
37 // TODO: This should not be necessary
38 session = this;
39}
40
41SigSession::~SigSession()
42{
43 // TODO: This should not be necessary
44 session = NULL;
45}
46
47void SigSession::loadFile(const std::string &name)
48{
49 if (sr_session_load(name.c_str()) == SR_OK) {
50 /* sigrok session file */
51 sr_session_datafeed_callback_add(dataFeedInProc);
52 sr_session_start();
53 sr_session_run();
54 sr_session_stop();
55 }
56}
57
58void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
59 struct sr_datafeed_packet *packet)
60{
61 assert(sdi);
62 assert(packet);
63
64 switch (packet->type) {
28a4c9c5 65 case SR_DF_HEADER:
009e1503
JH
66 break;
67
28a4c9c5 68 case SR_DF_META_LOGIC:
009e1503 69 {
28a4c9c5 70 assert(packet->payload);
009e1503 71
28a4c9c5
JH
72 _logic_data.reset(new LogicData(
73 *(sr_datafeed_meta_logic*)packet->payload));
009e1503 74
28a4c9c5
JH
75 assert(_logic_data);
76 if(!_logic_data)
77 break;
009e1503 78
28a4c9c5
JH
79 // Add an empty data snapshot
80 shared_ptr<LogicDataSnapshot> snapshot(
81 new LogicDataSnapshot());
82 _logic_data->push_snapshot(snapshot);
83 _cur_logic_snapshot = snapshot;
009e1503 84
28a4c9c5 85 break;
2953961c 86 }
28a4c9c5
JH
87
88 case SR_DF_LOGIC:
89 assert(packet->payload);
90 assert(_cur_logic_snapshot);
91 if(_cur_logic_snapshot)
92 _cur_logic_snapshot->append_payload(
93 *(sr_datafeed_logic*)packet->payload);
2953961c
JH
94 break;
95
96 case SR_DF_END:
28a4c9c5 97 _cur_logic_snapshot.reset();
009e1503 98 dataUpdated();
2953961c
JH
99 break;
100 }
101}
102
103void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
104 struct sr_datafeed_packet *packet)
105{
106 assert(session);
107 session->dataFeedIn(sdi, packet);
108}