2 * This file is part of the sigrok project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
21 #include "sigsession.h"
23 #include "logicdata.h"
24 #include "logicdatasnapshot.h"
30 using namespace boost;
32 // TODO: This should not be necessary
33 SigSession* SigSession::session = NULL;
35 SigSession::SigSession()
37 // TODO: This should not be necessary
41 SigSession::~SigSession()
43 // TODO: This should not be necessary
47 void SigSession::loadFile(const std::string &name)
49 if (sr_session_load(name.c_str()) == SR_OK) {
50 /* sigrok session file */
51 sr_session_datafeed_callback_add(dataFeedInProc);
58 void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
59 struct sr_datafeed_packet *packet)
64 switch (packet->type) {
68 case SR_DF_META_LOGIC:
70 assert(packet->payload);
72 _logic_data.reset(new LogicData(
73 *(sr_datafeed_meta_logic*)packet->payload));
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;
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);
97 _cur_logic_snapshot.reset();
103 void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
104 struct sr_datafeed_packet *packet)
107 session->dataFeedIn(sdi, packet);