]> sigrok.org Git - pulseview.git/blame - pv/device/sessionfile.cpp
CMakeLists.txt: Put quotes back for CXX_FLAGS only
[pulseview.git] / pv / device / sessionfile.cpp
CommitLineData
ae2d1bc5
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 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
f9abf97e
JH
21#include <cassert>
22
ae2d1bc5
JH
23#include "sessionfile.h"
24
25#include <libsigrok/libsigrok.h>
26
27namespace pv {
28namespace device {
29
30SessionFile::SessionFile(const std::string &path) :
31 File(path),
32 _sdi(NULL)
33{
34}
35
36sr_dev_inst* SessionFile::dev_inst() const
37{
38 return _sdi;
39}
40
41void SessionFile::use(SigSession *owner) throw(QString)
42{
43 assert(!_sdi);
44
45 if (sr_session_load(_path.c_str()) != SR_OK)
46 throw tr("Failed to open file.\n");
47
48 GSList *devlist = NULL;
49 sr_session_dev_list(&devlist);
50
51 if (!devlist || !devlist->data) {
52 if (devlist)
53 g_slist_free(devlist);
54 throw tr("Failed to start session.");
55 }
56
57 _sdi = (sr_dev_inst*)devlist->data;
58 g_slist_free(devlist);
59
60 File::use(owner);
61}
62
63void SessionFile::release()
64{
65 if (!_owner)
66 return;
67
68 assert(_sdi);
69 File::release();
70 sr_dev_close(_sdi);
71 sr_dev_clear(_sdi->driver);
72 sr_session_destroy();
73 _sdi = NULL;
74}
75
76} // device
77} // pv