]> sigrok.org Git - pulseview.git/blame - sigsession.cpp
Push data into 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 79 break;
2953961c 80 }
28a4c9c5
JH
81
82 case SR_DF_LOGIC:
f556bc6a 83
28a4c9c5 84 assert(packet->payload);
f556bc6a
JH
85 if(!_cur_logic_snapshot)
86 {
87 // Create a new data snapshot
88 _cur_logic_snapshot = shared_ptr<LogicDataSnapshot>(
89 new LogicDataSnapshot(
90 *(sr_datafeed_logic*)packet->payload));
91 _logic_data->push_snapshot(_cur_logic_snapshot);
92 }
93 else
94 {
95 // Append to the existing data snapshot
28a4c9c5
JH
96 _cur_logic_snapshot->append_payload(
97 *(sr_datafeed_logic*)packet->payload);
f556bc6a
JH
98 }
99
2953961c
JH
100 break;
101
102 case SR_DF_END:
28a4c9c5 103 _cur_logic_snapshot.reset();
009e1503 104 dataUpdated();
2953961c
JH
105 break;
106 }
107}
108
109void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
110 struct sr_datafeed_packet *packet)
111{
112 assert(session);
113 session->dataFeedIn(sdi, packet);
114}