PulseView
0.3.0
A Qt-based sigrok GUI
Main Page
Namespaces
Classes
Files
File List
File Members
main.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of the PulseView project.
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
21
#ifdef ENABLE_DECODE
22
#include <libsigrokdecode/libsigrokdecode.h>
/* First, so we avoid a _POSIX_C_SOURCE warning. */
23
#endif
24
25
#include <stdint.h>
26
#include <libsigrokcxx/libsigrokcxx.hpp>
27
28
#include <getopt.h>
29
30
#include <QDebug>
31
32
#ifdef ENABLE_SIGNALS
33
#include "
signalhandler.hpp
"
34
#endif
35
36
#include "
pv/application.hpp
"
37
#include "
pv/devicemanager.hpp
"
38
#include "
pv/mainwindow.hpp
"
39
#ifdef ANDROID
40
#include <libsigrokandroidutils/libsigrokandroidutils.h>
41
#include "
android/assetreader.hpp
"
42
#include "
android/loghandler.hpp
"
43
#endif
44
45
#include "
config.h
"
46
47
#ifdef _WIN32
48
// The static qsvg lib is required for SVG graphics/icons (on Windows).
49
#include <QtPlugin>
50
Q_IMPORT_PLUGIN(qsvg)
51
#endif
52
53
void
usage
()
54
{
55
fprintf(stdout,
56
"Usage:\n"
57
" %s [OPTION…] — %s\n"
58
"\n"
59
"Help Options:\n"
60
" -h, -?, --help Show help option\n"
61
"\n"
62
"Application Options:\n"
63
" -V, --version Show release version\n"
64
" -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n"
65
" -i, --input-file Load input from file\n"
66
" -I, --input-format Input format\n"
67
"\n"
,
PV_BIN_NAME
,
PV_DESCRIPTION
);
68
}
69
70
int
main
(
int
argc,
char
*argv[])
71
{
72
int
ret = 0;
73
std::shared_ptr<sigrok::Context> context;
74
std::string open_file, open_file_format;
75
76
Application
a(argc, argv);
77
78
#ifdef ANDROID
79
srau_init_environment();
80
pv::AndroidLogHandler::install_callbacks
();
81
pv::AndroidAssetReader
asset_reader;
82
#endif
83
84
// Parse arguments
85
while
(1) {
86
static
const
struct
option long_options[] = {
87
{
"help"
, no_argument, 0,
'h'
},
88
{
"version"
, no_argument, 0,
'V'
},
89
{
"loglevel"
, required_argument, 0,
'l'
},
90
{
"input-file"
, required_argument, 0,
'i'
},
91
{
"input-format"
, required_argument, 0,
'I'
},
92
{0, 0, 0, 0}
93
};
94
95
const
int
c = getopt_long(argc, argv,
96
"l:Vh?i:I:"
, long_options,
nullptr
);
97
if
(c == -1)
98
break
;
99
100
switch
(c) {
101
case
'h'
:
102
case
'?'
:
103
usage
();
104
return
0;
105
106
case
'V'
:
107
// Print version info
108
fprintf(stdout,
"%s %s\n"
,
PV_TITLE
,
PV_VERSION_STRING
);
109
return
0;
110
111
case
'l'
:
112
{
113
const
int
loglevel = atoi(optarg);
114
context->set_log_level(sigrok::LogLevel::get(loglevel));
115
116
#ifdef ENABLE_DECODE
117
srd_log_loglevel_set(loglevel);
118
#endif
119
120
break
;
121
}
122
123
case
'i'
:
124
open_file = optarg;
125
break
;
126
127
case
'I'
:
128
open_file_format = optarg;
129
break
;
130
}
131
}
132
133
if
(argc - optind > 1) {
134
fprintf(stderr,
"Only one file can be opened.\n"
);
135
return
1;
136
}
else
if
(argc - optind == 1) {
137
open_file = argv[argc - 1];
138
}
139
140
// Initialise libsigrok
141
context = sigrok::Context::create();
142
#ifdef ANDROID
143
context->set_resource_reader(&asset_reader);
144
#endif
145
do
{
146
147
#ifdef ENABLE_DECODE
148
// Initialise libsigrokdecode
149
if
(srd_init(
nullptr
) != SRD_OK) {
150
qDebug() <<
"ERROR: libsigrokdecode init failed."
;
151
break
;
152
}
153
154
// Load the protocol decoders
155
srd_decoder_load_all();
156
#endif
157
158
try
{
159
// Create the device manager, initialise the drivers
160
pv::DeviceManager
device_manager(context);
161
162
// Initialise the main window
163
pv::MainWindow
w(device_manager,
164
open_file, open_file_format);
165
w.show();
166
167
#ifdef ENABLE_SIGNALS
168
if
(
SignalHandler::prepare_signals
()) {
169
SignalHandler
*
const
handler =
170
new
SignalHandler
(&w);
171
QObject::connect(handler,
172
SIGNAL(int_received()),
173
&w, SLOT(close()));
174
QObject::connect(handler,
175
SIGNAL(term_received()),
176
&w, SLOT(close()));
177
}
else
{
178
qWarning() <<
179
"Could not prepare signal handler."
;
180
}
181
#endif
182
183
// Run the application
184
ret = a.exec();
185
186
}
catch
(std::exception e) {
187
qDebug() << e.what();
188
}
189
190
#ifdef ENABLE_DECODE
191
// Destroy libsigrokdecode
192
srd_exit();
193
#endif
194
195
}
while
(0);
196
197
return
ret;
198
}
pv::DeviceManager
Definition:
devicemanager.hpp:48
devicemanager.hpp
pv::AndroidLogHandler::install_callbacks
static void install_callbacks()
Definition:
loghandler.cpp:95
config.h
usage
void usage()
Definition:
main.cpp:53
PV_BIN_NAME
#define PV_BIN_NAME
Definition:
config.h:26
SignalHandler
Definition:
signalhandler.hpp:28
loghandler.hpp
pv::AndroidAssetReader
Definition:
assetreader.hpp:27
signalhandler.hpp
pv::MainWindow
Definition:
mainwindow.hpp:62
Application
Definition:
application.hpp:26
SignalHandler::prepare_signals
static bool prepare_signals()
Definition:
signalhandler.cpp:34
assetreader.hpp
PV_TITLE
#define PV_TITLE
Definition:
config.h:24
PV_DESCRIPTION
#define PV_DESCRIPTION
Definition:
config.h:25
PV_VERSION_STRING
#define PV_VERSION_STRING
Definition:
config.h:33
main
int main(int argc, char *argv[])
Definition:
main.cpp:70
mainwindow.hpp
application.hpp
main.cpp
Generated on Sat Jan 30 2016 00:46:41 for PulseView by
1.8.9.1