]> sigrok.org Git - pulseview.git/blame - main.cpp
Fix compiler warnings/errors due to -Wall.
[pulseview.git] / main.cpp
CommitLineData
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
664fca5c
JH
21extern "C" {
22#include <sigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
31e6731d 23#include <signal.h>
664fca5c
JH
24#include <stdint.h>
25#include <libsigrok/libsigrok.h>
26}
27
f7951df4
JH
28#include <getopt.h>
29
d7bed479 30#include <QtGui/QApplication>
664fca5c 31#include <QDebug>
075fb499 32
51e77110 33#include "pv/mainwindow.h"
d7bed479 34
075fb499
AG
35#include "config.h"
36
9d544917
AG
37// Global pointer to our QApplication
38QApplication *g_app = NULL;
eec29dcd 39
d4384c6d
JH
40void usage()
41{
42 fprintf(stderr,
43 "Usage:\n"
44 " %s — %s\n"
45 "\n"
46 "Help Options:\n"
47 " -V, --version Show release version\n"
48 " -h, -?, --help Show help option\n"
49 "\n", PV_BIN_NAME, PV_DESCRIPTION);
50}
51
31e6731d 52/*
eec29dcd 53 * SIGINT handler (likely received Ctrl-C from terminal)
31e6731d 54 */
eec29dcd 55void sigint_handler(int param)
31e6731d 56{
eec29dcd 57 (void)param;
9d544917 58
eec29dcd 59 qDebug("Received SIGINT.");
9d544917
AG
60
61 if (g_app)
62 g_app->quit();
31e6731d
AG
63}
64
d7bed479
JH
65int main(int argc, char *argv[])
66{
be03620e 67 int ret = 0;
f2242929
PS
68 struct sr_context *sr_ctx = NULL;
69
31e6731d 70 // Register a SIGINT handler
eec29dcd 71 signal(SIGINT, sigint_handler);
31e6731d 72
d7bed479 73 QApplication a(argc, argv);
9d544917
AG
74 // Now we have an application to populate our global pointer
75 g_app = &a;
d7bed479 76
6a6772b7 77 // Set some application metadata
075fb499 78 QApplication::setApplicationVersion(PV_VERSION_STRING);
3623c8d3 79 QApplication::setApplicationName("PulseView");
640e5565
JH
80 QApplication::setOrganizationDomain("http://www.sigrok.org");
81
f7951df4
JH
82 // Parse arguments
83 while (1) {
84 static const struct option long_options[] = {
333d5bbc
UH
85 {"version", no_argument, 0, 'V'},
86 {"help", no_argument, 0, 'h'},
f7951df4
JH
87 {0, 0, 0, 0}
88 };
89
d4384c6d
JH
90 const char c = getopt_long(argc, argv,
91 "Vh?", long_options, NULL);
f7951df4
JH
92 if (c == -1)
93 break;
94
95 switch (c) {
96 case 'V':
97 // Print version info
98 fprintf(stderr, "%s %s\n", PV_TITLE, PV_VERSION_STRING);
99 return 0;
d4384c6d
JH
100
101 case 'h':
102 case '?':
103 usage();
104 return 0;
f7951df4
JH
105 }
106 }
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
6a6772b7 114 // Initialise libsigrokdecode
be03620e
JH
115 if (srd_init(NULL) == SRD_OK) {
116
117 // Load the protocol decoders
118 srd_decoder_load_all();
119
120 // Initialize all libsigrok drivers
121 sr_dev_driver **const drivers = sr_driver_list();
122 for (sr_dev_driver **driver = drivers; *driver; driver++) {
24ea28e7 123 if (sr_driver_init(sr_ctx, *driver) != SR_OK) {
be03620e
JH
124 qDebug("Failed to initialize driver %s",
125 (*driver)->name);
126 ret = 1;
127 break;
128 }
129 }
664fca5c 130
333d5bbc 131 if (ret == 0) {
be03620e
JH
132 // Initialise the main window
133 pv::MainWindow w;
134 w.show();
664fca5c 135
be03620e
JH
136 // Run the application
137 ret = a.exec();
6fb67b27 138 }
6fb67b27 139
be03620e
JH
140 // Destroy libsigrokdecode and libsigrok
141 srd_exit();
664fca5c 142
be03620e
JH
143 } else {
144 qDebug() << "ERROR: libsigrokdecode init failed.";
145 }
664fca5c 146
f2242929
PS
147 if (sr_ctx)
148 sr_exit(sr_ctx);
664fca5c
JH
149
150 return ret;
d7bed479 151}