*/
#include <sigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
-#include <signal.h>
#include <stdint.h>
#include <libsigrok/libsigrok.h>
#include <QtGui/QApplication>
#include <QDebug>
+#include "signalhandler.h"
#include "pv/mainwindow.h"
#include "config.h"
-// Global pointer to our QApplication
-QApplication *g_app = NULL;
-
void usage()
{
fprintf(stdout,
" %s [OPTION…] [FILE] — %s\n"
"\n"
"Help Options:\n"
+ " -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n"
" -V, --version Show release version\n"
" -h, -?, --help Show help option\n"
"\n", PV_BIN_NAME, PV_DESCRIPTION);
}
-/*
- * SIGINT handler (likely received Ctrl-C from terminal)
- */
-void sigint_handler(int param)
-{
- (void)param;
-
- qDebug("Received SIGINT.");
-
- if (g_app)
- g_app->quit();
-}
-
int main(int argc, char *argv[])
{
int ret = 0;
struct sr_context *sr_ctx = NULL;
const char *open_file = NULL;
- // Register a SIGINT handler
- signal(SIGINT, sigint_handler);
-
QApplication a(argc, argv);
- // Now we have an application to populate our global pointer
- g_app = &a;
// Set some application metadata
QApplication::setApplicationVersion(PV_VERSION_STRING);
// Parse arguments
while (1) {
static const struct option long_options[] = {
+ {"loglevel", required_argument, 0, 'l'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
- const char c = getopt_long(argc, argv,
- "Vh?", long_options, NULL);
+ const int c = getopt_long(argc, argv,
+ "l:Vh?", long_options, NULL);
if (c == -1)
break;
switch (c) {
+ case 'l':
+ {
+ const int loglevel = atoi(optarg);
+ sr_log_loglevel_set(loglevel);
+ srd_log_loglevel_set(loglevel);
+ break;
+ }
+
case 'V':
// Print version info
fprintf(stdout, "%s %s\n", PV_TITLE, PV_VERSION_STRING);
pv::MainWindow w(open_file);
w.show();
+ if(SignalHandler::prepare_signals()) {
+ SignalHandler *const handler =
+ new SignalHandler(&w);
+ QObject::connect(handler,
+ SIGNAL(int_received()),
+ &w, SLOT(close()));
+ QObject::connect(handler,
+ SIGNAL(term_received()),
+ &w, SLOT(close()));
+ } else {
+ qWarning() <<
+ "Could not prepare signal handler.";
+ }
+
// Run the application
ret = a.exec();
}