]> sigrok.org Git - pulseview.git/blame - sigsession.cpp
Added session file open support
[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
23#include <assert.h>
24
25// TODO: This should not be necessary
26SigSession* SigSession::session = NULL;
27
28SigSession::SigSession()
29{
30 // TODO: This should not be necessary
31 session = this;
32}
33
34SigSession::~SigSession()
35{
36 // TODO: This should not be necessary
37 session = NULL;
38}
39
40void SigSession::loadFile(const std::string &name)
41{
42 if (sr_session_load(name.c_str()) == SR_OK) {
43 /* sigrok session file */
44 sr_session_datafeed_callback_add(dataFeedInProc);
45 sr_session_start();
46 sr_session_run();
47 sr_session_stop();
48 }
49}
50
51void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
52 struct sr_datafeed_packet *packet)
53{
54 assert(sdi);
55 assert(packet);
56
57 switch (packet->type) {
58 case SR_DF_META_LOGIC:
59 {
60 const sr_datafeed_meta_logic *meta_logic =
61 (sr_datafeed_meta_logic*)packet->payload;
62 int num_enabled_probes = 0;
63
64 for (int i = 0; i < meta_logic->num_probes; i++) {
65 const sr_probe *probe =
66 (sr_probe *)g_slist_nth_data(sdi->probes, i);
67 if (probe->enabled) {
68 probeList[num_enabled_probes++] = probe->index;
69 }
70 }
71 }
72 break;
73
74 case SR_DF_END:
75 break;
76 }
77}
78
79void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
80 struct sr_datafeed_packet *packet)
81{
82 assert(session);
83 session->dataFeedIn(sdi, packet);
84}