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
21 #include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
24 #include <libsigrok/libsigrok.h>
28 #include <QtGui/QApplication>
32 #include "signalhandler.h"
35 #include "pv/devicemanager.h"
36 #include "pv/mainwindow.h"
44 " %s [OPTION…] [FILE] — %s\n"
47 " -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n"
48 " -V, --version Show release version\n"
49 " -h, -?, --help Show help option\n"
50 "\n", PV_BIN_NAME
, PV_DESCRIPTION
);
53 int main(int argc
, char *argv
[])
56 struct sr_context
*sr_ctx
= NULL
;
57 const char *open_file
= NULL
;
59 QApplication
a(argc
, argv
);
61 // Set some application metadata
62 QApplication::setApplicationVersion(PV_VERSION_STRING
);
63 QApplication::setApplicationName("PulseView");
64 QApplication::setOrganizationDomain("http://www.sigrok.org");
68 static const struct option long_options
[] = {
69 {"loglevel", required_argument
, 0, 'l'},
70 {"version", no_argument
, 0, 'V'},
71 {"help", no_argument
, 0, 'h'},
75 const int c
= getopt_long(argc
, argv
,
76 "l:Vh?", long_options
, NULL
);
83 const int loglevel
= atoi(optarg
);
84 sr_log_loglevel_set(loglevel
);
85 srd_log_loglevel_set(loglevel
);
92 fprintf(stdout
, "%s %s\n", PV_TITLE
, PV_VERSION_STRING
);
102 if (argc
- optind
> 1) {
103 fprintf(stderr
, "Only one file can be openened.\n");
105 } else if (argc
- optind
== 1)
106 open_file
= argv
[argc
- 1];
108 // Initialise libsigrok
109 if (sr_init(&sr_ctx
) != SR_OK
) {
110 qDebug() << "ERROR: libsigrok init failed.";
116 // Initialise libsigrokdecode
117 if (srd_init(NULL
) != SRD_OK
) {
118 qDebug() << "ERROR: libsigrokdecode init failed.";
122 // Load the protocol decoders
123 srd_decoder_load_all();
126 // Create the device manager, initialise the drivers
127 pv::DeviceManager
device_manager(sr_ctx
);
129 // Initialise the main window
130 pv::MainWindow
w(device_manager
, open_file
);
133 #ifdef ENABLE_SIGNALS
134 if(SignalHandler::prepare_signals()) {
135 SignalHandler
*const handler
=
136 new SignalHandler(&w
);
137 QObject::connect(handler
,
138 SIGNAL(int_received()),
140 QObject::connect(handler
,
141 SIGNAL(term_received()),
145 "Could not prepare signal handler.";
149 // Run the application
152 } catch(std::exception e
) {
153 qDebug() << e
.what();
156 // Destroy libsigrokdecode