]> sigrok.org Git - pulseview.git/blame_incremental - sigsession.cpp
Push data into data model
[pulseview.git] / sigsession.cpp
... / ...
CommitLineData
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
23#include "logicdata.h"
24#include "logicdatasnapshot.h"
25
26#include <QDebug>
27
28#include <assert.h>
29
30using namespace boost;
31
32// TODO: This should not be necessary
33SigSession* SigSession::session = NULL;
34
35SigSession::SigSession()
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) {
65 case SR_DF_HEADER:
66 break;
67
68 case SR_DF_META_LOGIC:
69 {
70 assert(packet->payload);
71
72 _logic_data.reset(new LogicData(
73 *(sr_datafeed_meta_logic*)packet->payload));
74
75 assert(_logic_data);
76 if(!_logic_data)
77 break;
78
79 break;
80 }
81
82 case SR_DF_LOGIC:
83
84 assert(packet->payload);
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
96 _cur_logic_snapshot->append_payload(
97 *(sr_datafeed_logic*)packet->payload);
98 }
99
100 break;
101
102 case SR_DF_END:
103 _cur_logic_snapshot.reset();
104 dataUpdated();
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}