]> sigrok.org Git - pulseview.git/blame - pv/application.cpp
Fix #1213 by improving the version information handling
[pulseview.git] / pv / application.cpp
CommitLineData
dac1bb97
ML
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
dac1bb97
ML
18 */
19
2acdb232 20#include "application.hpp"
dac1bb97
ML
21#include "config.h"
22
49719858 23#include <iostream>
c1a688de
SA
24#include <typeinfo>
25
26#include <QDebug>
27
49719858
SA
28#include <boost/version.hpp>
29
c1a688de
SA
30#ifdef ENABLE_STACKTRACE
31#include <boost/stacktrace.hpp>
32#endif
dac1bb97 33
49719858
SA
34#ifdef ENABLE_DECODE
35#include <libsigrokdecode/libsigrokdecode.h>
36#endif
37
38using std::cout;
39using std::endl;
6f925ba9 40using std::exception;
49719858
SA
41using std::shared_ptr;
42
43#ifdef ENABLE_DECODE
44static gint sort_pds(gconstpointer a, gconstpointer b)
45{
46 const struct srd_decoder *sda, *sdb;
47
48 sda = (const struct srd_decoder *)a;
49 sdb = (const struct srd_decoder *)b;
50 return strcmp(sda->id, sdb->id);
51}
52#endif
6f925ba9 53
dac1bb97
ML
54Application::Application(int &argc, char* argv[]) :
55 QApplication(argc, argv)
56{
57 setApplicationVersion(PV_VERSION_STRING);
58 setApplicationName("PulseView");
39eb0d45 59 setOrganizationName("sigrok");
dac1bb97
ML
60 setOrganizationDomain("sigrok.org");
61}
62
49719858
SA
63void Application::collect_version_info(shared_ptr<sigrok::Context> context)
64{
65 // Library versions and features
66 version_info_.emplace_back(applicationName(), applicationVersion());
67 version_info_.emplace_back("Qt", qVersion());
68 version_info_.emplace_back("glibmm", PV_GLIBMM_VERSION);
69 version_info_.emplace_back("Boost", BOOST_LIB_VERSION);
70
71 version_info_.emplace_back("libsigrok", QString("%1/%2 (rt: %3/%4)")
72 .arg(SR_PACKAGE_VERSION_STRING, SR_LIB_VERSION_STRING,
73 sr_package_version_string_get(), sr_lib_version_string_get()));
74
75 GSList *l_orig = sr_buildinfo_libs_get();
76 for (GSList *l = l_orig; l; l = l->next) {
77 GSList *m = (GSList *)l->data;
78 const char *lib = (const char *)m->data;
79 const char *version = (const char *)m->next->data;
80 version_info_.emplace_back(QString(" - %1").arg(QString(lib)), QString(version));
81 g_slist_free_full(m, g_free);
82 }
83 g_slist_free(l_orig);
84
85 char *host = sr_buildinfo_host_get();
86 version_info_.emplace_back(" - Host", QString(host));
87 g_free(host);
88
89 char *scpi_backends = sr_buildinfo_scpi_backends_get();
90 version_info_.emplace_back(" - SCPI backends", QString(scpi_backends));
91 g_free(scpi_backends);
92
93#ifdef ENABLE_DECODE
94 struct srd_decoder *dec;
95
96 version_info_.emplace_back("libsigrokdecode", QString("%1/%2 (rt: %3/%4)")
97 .arg(SRD_PACKAGE_VERSION_STRING, SRD_LIB_VERSION_STRING,
98 srd_package_version_string_get(), srd_lib_version_string_get()));
99
100 l_orig = srd_buildinfo_libs_get();
101 for (GSList *l = l_orig; l; l = l->next) {
102 GSList *m = (GSList *)l->data;
103 const char *lib = (const char *)m->data;
104 const char *version = (const char *)m->next->data;
105 version_info_.emplace_back(QString(" - %1").arg(QString(lib)), QString(version));
106 g_slist_free_full(m, g_free);
107 }
108 g_slist_free(l_orig);
109
110 host = srd_buildinfo_host_get();
111 version_info_.emplace_back(" - Host", QString(host));
112 g_free(host);
113#endif
114
115 // Firmware paths
116 l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE);
117 for (GSList *l = l_orig; l; l = l->next)
118 fw_path_list_.push_back(QString((char*)l->data));
119 g_slist_free_full(l_orig, g_free);
120
121 // PD paths
122#ifdef ENABLE_DECODE
123 l_orig = srd_searchpaths_get();
124 for (GSList *l = l_orig; l; l = l->next)
125 pd_path_list_.push_back(QString((char*)l->data));
126 g_slist_free_full(l_orig, g_free);
127#endif
128
129 // Device drivers
130 for (auto entry : context->drivers())
131 driver_list_.emplace_back(QString::fromUtf8(entry.first.c_str()),
132 QString::fromUtf8(entry.second->long_name().c_str()));
133
134 // Input formats
135 for (auto entry : context->input_formats())
136 input_format_list_.emplace_back(QString::fromUtf8(entry.first.c_str()),
137 QString::fromUtf8(entry.second->description().c_str()));
138
139 // Output formats
140 for (auto entry : context->output_formats())
141 output_format_list_.emplace_back(QString::fromUtf8(entry.first.c_str()),
142 QString::fromUtf8(entry.second->description().c_str()));
143
144 // Protocol decoders
145#ifdef ENABLE_DECODE
146 GSList *sl = g_slist_copy((GSList *)srd_decoder_list());
147 sl = g_slist_sort(sl, sort_pds);
148 for (const GSList *l = sl; l; l = l->next) {
149 dec = (struct srd_decoder *)l->data;
150 pd_list_.emplace_back(QString::fromUtf8(dec->id),
151 QString::fromUtf8(dec->longname));
152 }
153 g_slist_free(sl);
154#endif
155}
156
157void Application::print_version_info()
158{
159 cout << PV_TITLE << PV_VERSION_STRING << endl;
160
161 cout << endl << "Libraries and features:" << endl;
162 for (pair<QString, QString> &entry : version_info_)
163 cout << " " << entry.first.toStdString() << " " << entry.second.toStdString() << endl;
164
165 cout << endl << "Firmware search paths:" << endl;
166 for (QString &entry : fw_path_list_)
167 cout << " " << entry.toStdString() << endl;
168
169 cout << endl << "Protocol decoder search paths:" << endl;
170 for (QString &entry : pd_path_list_)
171 cout << " " << entry.toStdString() << endl;
172
173 cout << endl << "Supported hardware drivers:" << endl;
174 for (pair<QString, QString> &entry : driver_list_)
175 cout << " " << entry.first.leftJustified(21, ' ').toStdString() <<
176 entry.second.toStdString() << endl;
177
178 cout << endl << "Supported input formats:" << endl;
179 for (pair<QString, QString> &entry : input_format_list_)
180 cout << " " << entry.first.leftJustified(21, ' ').toStdString() <<
181 entry.second.toStdString() << endl;
182
183 cout << endl << "Supported output formats:" << endl;
184 for (pair<QString, QString> &entry : output_format_list_)
185 cout << " " << entry.first.leftJustified(21, ' ').toStdString() <<
186 entry.second.toStdString() << endl;
187
188#ifdef ENABLE_DECODE
189 cout << endl << "Supported protocol decoders:" << endl;
190 for (pair<QString, QString> &entry : pd_list_)
191 cout << " " << entry.first.leftJustified(21, ' ').toStdString() <<
192 entry.second.toStdString() << endl;
193#endif
194
195 cout << endl;
196}
197
198vector< pair<QString, QString> > Application::get_version_info() const
199{
200 return version_info_;
201}
202
203vector<QString> Application::get_fw_path_list() const
204{
205 return fw_path_list_;
206}
207
208vector<QString> Application::get_pd_path_list() const
209{
210 return pd_path_list_;
211}
212
213vector< pair<QString, QString> > Application::get_driver_list() const
214{
215 return driver_list_;
216}
217
218vector< pair<QString, QString> > Application::get_input_format_list() const
219{
220 return input_format_list_;
221}
222
223vector< pair<QString, QString> > Application::get_output_format_list() const
224{
225 return output_format_list_;
226}
227
228vector< pair<QString, QString> > Application::get_pd_list() const
229{
230 return pd_list_;
231}
232
dac1bb97
ML
233bool Application::notify(QObject *receiver, QEvent *event)
234{
235 try {
236 return QApplication::notify(receiver, event);
6f925ba9 237 } catch (exception& e) {
c1a688de
SA
238 qDebug().nospace() << "Caught exception of type " << \
239 typeid(e).name() << " (" << e.what() << ")";
240#ifdef ENABLE_STACKTRACE
241 throw e;
242#else
dac1bb97 243 exit(1);
c1a688de 244#endif
dac1bb97
ML
245 return false;
246 }
247}