pulseview/main.cpp

121 lines
2.8 KiB
C++
Raw Normal View History

2012-09-03 20:20:51 +08:00
/*
* This file is part of the PulseView project.
2012-09-03 20:20:51 +08:00
*
* Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
2012-05-11 16:48:50 +08:00
extern "C" {
#include <sigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
#include <stdint.h>
#include <libsigrok/libsigrok.h>
}
2012-10-13 07:59:37 +08:00
#include <getopt.h>
2012-09-03 20:20:51 +08:00
#include <QtGui/QApplication>
2012-05-11 16:48:50 +08:00
#include <QDebug>
#include "pv/mainwindow.h"
2012-09-03 20:20:51 +08:00
#include "config.h"
2012-10-13 08:15:47 +08:00
void usage()
{
fprintf(stderr,
"Usage:\n"
" %s — %s\n"
"\n"
"Help Options:\n"
" -V, --version Show release version\n"
" -h, -?, --help Show help option\n"
"\n", PV_BIN_NAME, PV_DESCRIPTION);
}
2012-09-03 20:20:51 +08:00
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
2012-10-13 07:13:44 +08:00
// Set some application metadata
QApplication::setApplicationVersion(PV_VERSION_STRING);
QApplication::setApplicationName("PulseView");
2012-05-11 16:40:27 +08:00
QApplication::setOrganizationDomain("http://www.sigrok.org");
2012-10-13 07:59:37 +08:00
// Parse arguments
while (1) {
static const struct option long_options[] = {
{"version", no_argument, 0, 'V'},
2012-10-13 08:15:47 +08:00
{"help", no_argument, 0, 'h'},
2012-10-13 07:59:37 +08:00
{0, 0, 0, 0}
};
2012-10-13 08:15:47 +08:00
const char c = getopt_long(argc, argv,
"Vh?", long_options, NULL);
2012-10-13 07:59:37 +08:00
if (c == -1)
break;
switch (c) {
case 'V':
// Print version info
fprintf(stderr, "%s %s\n", PV_TITLE, PV_VERSION_STRING);
return 0;
2012-10-13 08:15:47 +08:00
case 'h':
case '?':
usage();
return 0;
2012-10-13 07:59:37 +08:00
}
}
2012-10-13 07:13:44 +08:00
// Initialise libsigrok
2012-05-11 16:48:50 +08:00
if (sr_init() != SR_OK) {
qDebug() << "ERROR: libsigrok init failed.";
return 1;
}
2012-10-13 07:13:44 +08:00
// Initialise libsigrokdecode
2012-05-11 16:48:50 +08:00
if (srd_init(NULL) != SRD_OK) {
qDebug() << "ERROR: libsigrokdecode init failed.";
return 1;
}
2012-10-13 07:13:44 +08:00
// Load the protocol decoders
2012-05-11 16:48:50 +08:00
srd_decoder_load_all();
2012-10-13 07:13:44 +08:00
// Initialize all libsigrok drivers
2012-06-28 05:36:23 +08:00
sr_dev_driver **const drivers = sr_driver_list();
for (sr_dev_driver **driver = drivers; *driver; driver++) {
if (sr_driver_init(*driver) != SR_OK) {
qDebug("Failed to initialize driver %s",
(*driver)->name);
return 1;
}
}
2012-10-13 07:13:44 +08:00
// Initialise the main window
pv::MainWindow w;
2012-05-11 16:48:50 +08:00
w.show();
2012-10-13 07:13:44 +08:00
// Run the application
2012-05-11 16:48:50 +08:00
const int ret = a.exec();
2012-10-13 07:13:44 +08:00
// Destroy libsigrokdecode and libsigrok
2012-05-11 16:48:50 +08:00
srd_exit();
sr_exit();
return ret;
2012-09-03 20:20:51 +08:00
}