]> sigrok.org Git - pulseview.git/blob - sigsession.cpp
37c758f776e098d86023bb07c123874ad53b2972
[pulseview.git] / sigsession.cpp
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
30 using namespace boost;
31
32 // TODO: This should not be necessary
33 SigSession* SigSession::session = NULL;
34
35 SigSession::SigSession()
36 {
37         // TODO: This should not be necessary
38         session = this;
39 }
40
41 SigSession::~SigSession()
42 {
43         // TODO: This should not be necessary
44         session = NULL;
45 }
46
47 void 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
58 void 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                         // Add an empty data snapshot
80                         shared_ptr<LogicDataSnapshot> snapshot(
81                                 new LogicDataSnapshot());
82                         _logic_data->push_snapshot(snapshot);
83                         _cur_logic_snapshot = snapshot;
84
85                         break;
86                 }
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);
94                 break;
95
96         case SR_DF_END:
97                 _cur_logic_snapshot.reset();
98                 dataUpdated();
99                 break;
100         }
101 }
102
103 void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
104         struct sr_datafeed_packet *packet)
105 {
106         assert(session);
107         session->dataFeedIn(sdi, packet);
108 }