]>
Commit | Line | Data |
---|---|---|
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, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #ifndef PULSEVIEW_PV_STORESESSION_HPP | |
21 | #define PULSEVIEW_PV_STORESESSION_HPP | |
22 | ||
23 | #include <stdint.h> | |
24 | ||
25 | #include <atomic> | |
26 | #include <fstream> | |
27 | #include <map> | |
28 | #include <memory> | |
29 | #include <mutex> | |
30 | #include <string> | |
31 | #include <thread> | |
32 | ||
33 | #include <glibmm/variant.h> | |
34 | ||
35 | #include <QObject> | |
36 | ||
37 | using std::atomic; | |
38 | using std::string; | |
39 | using std::shared_ptr; | |
40 | using std::pair; | |
41 | using std::map; | |
42 | using std::vector; | |
43 | using std::thread; | |
44 | using std::mutex; | |
45 | using std::ofstream; | |
46 | ||
47 | namespace sigrok { | |
48 | class Output; | |
49 | class OutputFormat; | |
50 | } | |
51 | ||
52 | namespace pv { | |
53 | ||
54 | class Session; | |
55 | ||
56 | namespace data { | |
57 | class SignalBase; | |
58 | class AnalogSegment; | |
59 | class LogicSegment; | |
60 | } | |
61 | ||
62 | class StoreSession : public QObject | |
63 | { | |
64 | Q_OBJECT | |
65 | ||
66 | private: | |
67 | static const size_t BlockSize; | |
68 | ||
69 | public: | |
70 | StoreSession(const string &file_name, | |
71 | const shared_ptr<sigrok::OutputFormat> &output_format, | |
72 | const map<string, Glib::VariantBase> &options, | |
73 | const pair<uint64_t, uint64_t> sample_range, | |
74 | const Session &session); | |
75 | ||
76 | ~StoreSession(); | |
77 | ||
78 | pair<int, int> progress() const; | |
79 | ||
80 | const QString& error() const; | |
81 | ||
82 | bool start(); | |
83 | ||
84 | void wait(); | |
85 | ||
86 | void cancel(); | |
87 | ||
88 | private: | |
89 | void store_proc(vector< shared_ptr<data::SignalBase> > achannel_list, | |
90 | vector< shared_ptr<pv::data::AnalogSegment> > asegment_list, | |
91 | shared_ptr<pv::data::LogicSegment> lsegment); | |
92 | ||
93 | Q_SIGNALS: | |
94 | void progress_updated(); | |
95 | ||
96 | void store_successful(); | |
97 | ||
98 | private: | |
99 | const string file_name_; | |
100 | const shared_ptr<sigrok::OutputFormat> output_format_; | |
101 | const map<string, Glib::VariantBase> options_; | |
102 | const pair<uint64_t, uint64_t> sample_range_; | |
103 | const Session &session_; | |
104 | ||
105 | shared_ptr<sigrok::Output> output_; | |
106 | ofstream output_stream_; | |
107 | ||
108 | std::thread thread_; | |
109 | ||
110 | atomic<bool> interrupt_; | |
111 | ||
112 | atomic<int> units_stored_, unit_count_; | |
113 | ||
114 | mutable mutex mutex_; | |
115 | QString error_; | |
116 | ||
117 | uint64_t start_sample_, sample_count_; | |
118 | }; | |
119 | ||
120 | } // pv | |
121 | ||
122 | #endif // PULSEVIEW_PV_STORESESSION_HPP |