2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
26 #include <libsigrokcxx/libsigrokcxx.hpp>
33 #include "signalhandler.hpp"
36 #include "pv/application.hpp"
37 #include "pv/devicemanager.hpp"
38 #include "pv/mainwindow.hpp"
40 #include <libsigrokandroidutils/libsigrokandroidutils.h>
41 #include "android/assetreader.hpp"
42 #include "android/loghandler.hpp"
48 // The static qsvg lib is required for SVG graphics/icons (on Windows).
57 " %s [OPTION…] — %s\n"
60 " -h, -?, --help Show help option\n"
62 "Application Options:\n"
63 " -V, --version Show release version\n"
64 " -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n"
65 " -i, --input-file Load input from file\n"
66 " -I, --input-format Input format\n"
67 "\n", PV_BIN_NAME, PV_DESCRIPTION);
70 int main(int argc, char *argv[])
73 std::shared_ptr<sigrok::Context> context;
74 std::string open_file, open_file_format;
76 Application a(argc, argv);
79 srau_init_environment();
80 pv::AndroidLogHandler::install_callbacks();
81 pv::AndroidAssetReader asset_reader;
86 static const struct option long_options[] = {
87 {"help", no_argument, nullptr, 'h'},
88 {"version", no_argument, nullptr, 'V'},
89 {"loglevel", required_argument, nullptr, 'l'},
90 {"input-file", required_argument, nullptr, 'i'},
91 {"input-format", required_argument, nullptr, 'I'},
92 {nullptr, 0, nullptr, 0}
95 const int c = getopt_long(argc, argv,
96 "l:Vh?i:I:", long_options, nullptr);
107 // Print version info
108 fprintf(stdout, "%s %s\n", PV_TITLE, PV_VERSION_STRING);
113 const int loglevel = atoi(optarg);
114 context->set_log_level(sigrok::LogLevel::get(loglevel));
117 srd_log_loglevel_set(loglevel);
128 open_file_format = optarg;
133 if (argc - optind > 1) {
134 fprintf(stderr, "Only one file can be opened.\n");
136 } else if (argc - optind == 1) {
137 open_file = argv[argc - 1];
140 // Initialise libsigrok
141 context = sigrok::Context::create();
143 context->set_resource_reader(&asset_reader);
148 // Initialise libsigrokdecode
149 if (srd_init(nullptr) != SRD_OK) {
150 qDebug() << "ERROR: libsigrokdecode init failed.";
154 // Load the protocol decoders
155 srd_decoder_load_all();
159 // Create the device manager, initialise the drivers
160 pv::DeviceManager device_manager(context);
162 // Initialise the main window
163 pv::MainWindow w(device_manager,
164 open_file, open_file_format);
167 #ifdef ENABLE_SIGNALS
168 if (SignalHandler::prepare_signals()) {
169 SignalHandler *const handler =
170 new SignalHandler(&w);
171 QObject::connect(handler,
172 SIGNAL(int_received()),
174 QObject::connect(handler,
175 SIGNAL(term_received()),
179 "Could not prepare signal handler.";
183 // Run the application
186 } catch (std::exception e) {
187 qDebug() << e.what();
191 // Destroy libsigrokdecode