2 * This file is part of the PulseView project.
4 * Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
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, see <http://www.gnu.org/licenses/>.
20 #include "application.hpp"
28 #include <boost/version.hpp>
30 #ifdef ENABLE_STACKTRACE
31 #include <boost/stacktrace.hpp>
35 #include <libsigrokdecode/libsigrokdecode.h>
41 using std::shared_ptr;
44 static gint sort_pds(gconstpointer a, gconstpointer b)
46 const struct srd_decoder *sda, *sdb;
48 sda = (const struct srd_decoder *)a;
49 sdb = (const struct srd_decoder *)b;
50 return strcmp(sda->id, sdb->id);
54 Application::Application(int &argc, char* argv[]) :
55 QApplication(argc, argv)
57 setApplicationVersion(PV_VERSION_STRING);
58 setApplicationName("PulseView");
59 setOrganizationName("sigrok");
60 setOrganizationDomain("sigrok.org");
63 void Application::collect_version_info(shared_ptr<sigrok::Context> context)
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);
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()));
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);
85 char *host = sr_buildinfo_host_get();
86 version_info_.emplace_back(" - Host", QString(host));
89 char *scpi_backends = sr_buildinfo_scpi_backends_get();
90 version_info_.emplace_back(" - SCPI backends", QString(scpi_backends));
91 g_free(scpi_backends);
94 struct srd_decoder *dec;
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()));
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);
108 g_slist_free(l_orig);
110 host = srd_buildinfo_host_get();
111 version_info_.emplace_back(" - Host", QString(host));
116 l_orig = sr_resourcepaths_get(SR_RESOURCE_FIRMWARE);
117 for (GSList *l = l_orig; l; l = l->next)
118 fw_path_list_.emplace_back((char*)l->data);
119 g_slist_free_full(l_orig, g_free);
123 l_orig = srd_searchpaths_get();
124 for (GSList *l = l_orig; l; l = l->next)
125 pd_path_list_.emplace_back((char*)l->data);
126 g_slist_free_full(l_orig, g_free);
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()));
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()));
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()));
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));
157 void Application::print_version_info()
159 cout << PV_TITLE << " " << PV_VERSION_STRING << endl;
161 cout << endl << "Libraries and features:" << endl;
162 for (pair<QString, QString>& entry : version_info_)
163 cout << " " << entry.first.toStdString() << " " << entry.second.toStdString() << endl;
165 cout << endl << "Firmware search paths:" << endl;
166 for (QString& entry : fw_path_list_)
167 cout << " " << entry.toStdString() << endl;
169 cout << endl << "Protocol decoder search paths:" << endl;
170 for (QString& entry : pd_path_list_)
171 cout << " " << entry.toStdString() << endl;
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;
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;
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;
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;
196 vector< pair<QString, QString> > Application::get_version_info() const
198 return version_info_;
201 vector<QString> Application::get_fw_path_list() const
203 return fw_path_list_;
206 vector<QString> Application::get_pd_path_list() const
208 return pd_path_list_;
211 vector< pair<QString, QString> > Application::get_driver_list() const
216 vector< pair<QString, QString> > Application::get_input_format_list() const
218 return input_format_list_;
221 vector< pair<QString, QString> > Application::get_output_format_list() const
223 return output_format_list_;
226 vector< pair<QString, QString> > Application::get_pd_list() const
231 bool Application::notify(QObject *receiver, QEvent *event)
234 return QApplication::notify(receiver, event);
235 } catch (exception& e) {
236 qDebug().nospace() << "Caught exception of type " << \
237 typeid(e).name() << " (" << e.what() << ")";
238 #ifdef ENABLE_STACKTRACE