]>
Commit | Line | Data |
---|---|---|
d7bed479 | 1 | /* |
b3f22de0 | 2 | * This file is part of the PulseView project. |
d7bed479 JH |
3 | * |
4 | * Copyright (C) 2012 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, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
aaabd61b | 21 | #include <libsigrokdecode/libsigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */ |
d52d8455 | 22 | |
664fca5c JH |
23 | #include <stdint.h> |
24 | #include <libsigrok/libsigrok.h> | |
664fca5c | 25 | |
f7951df4 JH |
26 | #include <getopt.h> |
27 | ||
d7bed479 | 28 | #include <QtGui/QApplication> |
664fca5c | 29 | #include <QDebug> |
075fb499 | 30 | |
140181a4 | 31 | #ifdef ENABLE_SIGNALS |
7a255aa9 | 32 | #include "signalhandler.h" |
140181a4 JH |
33 | #endif |
34 | ||
107ca6d3 | 35 | #include "pv/devicemanager.h" |
51e77110 | 36 | #include "pv/mainwindow.h" |
d7bed479 | 37 | |
075fb499 AG |
38 | #include "config.h" |
39 | ||
d4384c6d JH |
40 | void usage() |
41 | { | |
9fd5bb6e | 42 | fprintf(stdout, |
d4384c6d | 43 | "Usage:\n" |
1d478458 | 44 | " %s [OPTION…] [FILE] — %s\n" |
d4384c6d JH |
45 | "\n" |
46 | "Help Options:\n" | |
9b5099b6 | 47 | " -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n" |
d4384c6d JH |
48 | " -V, --version Show release version\n" |
49 | " -h, -?, --help Show help option\n" | |
50 | "\n", PV_BIN_NAME, PV_DESCRIPTION); | |
51 | } | |
52 | ||
d7bed479 JH |
53 | int main(int argc, char *argv[]) |
54 | { | |
be03620e | 55 | int ret = 0; |
f2242929 | 56 | struct sr_context *sr_ctx = NULL; |
1d478458 | 57 | const char *open_file = NULL; |
f2242929 | 58 | |
d7bed479 | 59 | QApplication a(argc, argv); |
d7bed479 | 60 | |
6a6772b7 | 61 | // Set some application metadata |
075fb499 | 62 | QApplication::setApplicationVersion(PV_VERSION_STRING); |
3623c8d3 | 63 | QApplication::setApplicationName("PulseView"); |
640e5565 JH |
64 | QApplication::setOrganizationDomain("http://www.sigrok.org"); |
65 | ||
f7951df4 JH |
66 | // Parse arguments |
67 | while (1) { | |
68 | static const struct option long_options[] = { | |
9b5099b6 | 69 | {"loglevel", required_argument, 0, 'l'}, |
333d5bbc UH |
70 | {"version", no_argument, 0, 'V'}, |
71 | {"help", no_argument, 0, 'h'}, | |
f7951df4 JH |
72 | {0, 0, 0, 0} |
73 | }; | |
74 | ||
815b3f26 | 75 | const int c = getopt_long(argc, argv, |
9b5099b6 | 76 | "l:Vh?", long_options, NULL); |
f7951df4 JH |
77 | if (c == -1) |
78 | break; | |
79 | ||
80 | switch (c) { | |
9b5099b6 JH |
81 | case 'l': |
82 | { | |
83 | const int loglevel = atoi(optarg); | |
84 | sr_log_loglevel_set(loglevel); | |
85 | srd_log_loglevel_set(loglevel); | |
d52d8455 | 86 | |
9b5099b6 JH |
87 | break; |
88 | } | |
89 | ||
f7951df4 JH |
90 | case 'V': |
91 | // Print version info | |
9fd5bb6e | 92 | fprintf(stdout, "%s %s\n", PV_TITLE, PV_VERSION_STRING); |
f7951df4 | 93 | return 0; |
d4384c6d JH |
94 | |
95 | case 'h': | |
96 | case '?': | |
97 | usage(); | |
98 | return 0; | |
f7951df4 JH |
99 | } |
100 | } | |
101 | ||
1d478458 JH |
102 | if (argc - optind > 1) { |
103 | fprintf(stderr, "Only one file can be openened.\n"); | |
104 | return 1; | |
105 | } else if (argc - optind == 1) | |
106 | open_file = argv[argc - 1]; | |
107 | ||
6a6772b7 | 108 | // Initialise libsigrok |
f2242929 | 109 | if (sr_init(&sr_ctx) != SR_OK) { |
664fca5c JH |
110 | qDebug() << "ERROR: libsigrok init failed."; |
111 | return 1; | |
112 | } | |
113 | ||
d52d8455 JH |
114 | do { |
115 | ||
d52d8455 JH |
116 | // Initialise libsigrokdecode |
117 | if (srd_init(NULL) != SRD_OK) { | |
118 | qDebug() << "ERROR: libsigrokdecode init failed."; | |
119 | break; | |
120 | } | |
be03620e JH |
121 | |
122 | // Load the protocol decoders | |
123 | srd_decoder_load_all(); | |
124 | ||
107ca6d3 JH |
125 | try { |
126 | // Create the device manager, initialise the drivers | |
127 | pv::DeviceManager device_manager(sr_ctx); | |
664fca5c | 128 | |
be03620e | 129 | // Initialise the main window |
107ca6d3 | 130 | pv::MainWindow w(device_manager, open_file); |
be03620e | 131 | w.show(); |
664fca5c | 132 | |
140181a4 | 133 | #ifdef ENABLE_SIGNALS |
708605aa JH |
134 | if(SignalHandler::prepare_signals()) { |
135 | SignalHandler *const handler = | |
7a255aa9 | 136 | new SignalHandler(&w); |
708605aa JH |
137 | QObject::connect(handler, |
138 | SIGNAL(int_received()), | |
7a255aa9 | 139 | &w, SLOT(close())); |
708605aa JH |
140 | QObject::connect(handler, |
141 | SIGNAL(term_received()), | |
7a255aa9 JH |
142 | &w, SLOT(close())); |
143 | } else { | |
144 | qWarning() << | |
145 | "Could not prepare signal handler."; | |
146 | } | |
140181a4 | 147 | #endif |
7a255aa9 | 148 | |
be03620e JH |
149 | // Run the application |
150 | ret = a.exec(); | |
107ca6d3 JH |
151 | |
152 | } catch(std::exception e) { | |
153 | qDebug() << e.what(); | |
6fb67b27 | 154 | } |
6fb67b27 | 155 | |
d52d8455 | 156 | // Destroy libsigrokdecode |
be03620e | 157 | srd_exit(); |
664fca5c | 158 | |
d52d8455 | 159 | } while (0); |
664fca5c | 160 | |
d52d8455 | 161 | // Destroy libsigrok |
f2242929 PS |
162 | if (sr_ctx) |
163 | sr_exit(sr_ctx); | |
664fca5c JH |
164 | |
165 | return ret; | |
d7bed479 | 166 | } |