X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=main.cpp;h=8fac92340c1326b3aafd38a5d678b69a06b9046a;hp=42e4a7c17062f863e987a4d68d81c313663d062f;hb=bccef54223c86f65fb0b7ead3124d945f1548beb;hpb=708605aa2c4ac7bbdaa3b2b539911f0d5ede1baf diff --git a/main.cpp b/main.cpp index 42e4a7c1..8fac9234 100644 --- a/main.cpp +++ b/main.cpp @@ -18,20 +18,37 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include /* First, so we avoid a _POSIX_C_SOURCE warning. */ +#ifdef ENABLE_DECODE +#include /* First, so we avoid a _POSIX_C_SOURCE warning. */ +#endif + #include -#include +#include #include -#include #include -#include "signalhandler.h" -#include "pv/mainwindow.h" +#ifdef ENABLE_SIGNALS +#include "signalhandler.hpp" +#endif + +#include "pv/application.hpp" +#include "pv/devicemanager.hpp" +#include "pv/mainwindow.hpp" +#ifdef ANDROID +#include +#include "android/loghandler.hpp" +#endif #include "config.h" +#ifdef _WIN32 +// The static qsvg lib is required for SVG graphics/icons (on Windows). +#include +Q_IMPORT_PLUGIN(qsvg) +#endif + void usage() { fprintf(stdout, @@ -48,15 +65,15 @@ void usage() int main(int argc, char *argv[]) { int ret = 0; - struct sr_context *sr_ctx = NULL; + std::shared_ptr context; const char *open_file = NULL; - QApplication a(argc, argv); + Application a(argc, argv); - // Set some application metadata - QApplication::setApplicationVersion(PV_VERSION_STRING); - QApplication::setApplicationName("PulseView"); - QApplication::setOrganizationDomain("http://www.sigrok.org"); +#ifdef ANDROID + srau_init_environment(); + pv::AndroidLogHandler::install_callbacks(); +#endif // Parse arguments while (1) { @@ -76,8 +93,12 @@ int main(int argc, char *argv[]) case 'l': { const int loglevel = atoi(optarg); - sr_log_loglevel_set(loglevel); + context->set_log_level(sigrok::LogLevel::get(loglevel)); + +#ifdef ENABLE_DECODE srd_log_loglevel_set(loglevel); +#endif + break; } @@ -100,33 +121,30 @@ int main(int argc, char *argv[]) open_file = argv[argc - 1]; // Initialise libsigrok - if (sr_init(&sr_ctx) != SR_OK) { - qDebug() << "ERROR: libsigrok init failed."; - return 1; - } + context = sigrok::Context::create(); - // Initialise libsigrokdecode - if (srd_init(NULL) == SRD_OK) { + do { + +#ifdef ENABLE_DECODE + // Initialise libsigrokdecode + if (srd_init(NULL) != SRD_OK) { + qDebug() << "ERROR: libsigrokdecode init failed."; + break; + } // Load the protocol decoders srd_decoder_load_all(); +#endif - // Initialize all libsigrok drivers - sr_dev_driver **const drivers = sr_driver_list(); - for (sr_dev_driver **driver = drivers; *driver; driver++) { - if (sr_driver_init(sr_ctx, *driver) != SR_OK) { - qDebug("Failed to initialize driver %s", - (*driver)->name); - ret = 1; - break; - } - } + try { + // Create the device manager, initialise the drivers + pv::DeviceManager device_manager(context); - if (ret == 0) { // Initialise the main window - pv::MainWindow w(open_file); + pv::MainWindow w(device_manager, open_file); w.show(); +#ifdef ENABLE_SIGNALS if(SignalHandler::prepare_signals()) { SignalHandler *const handler = new SignalHandler(&w); @@ -140,20 +158,21 @@ int main(int argc, char *argv[]) qWarning() << "Could not prepare signal handler."; } +#endif // Run the application ret = a.exec(); + + } catch(std::exception e) { + qDebug() << e.what(); } - // Destroy libsigrokdecode and libsigrok +#ifdef ENABLE_DECODE + // Destroy libsigrokdecode srd_exit(); +#endif - } else { - qDebug() << "ERROR: libsigrokdecode init failed."; - } - - if (sr_ctx) - sr_exit(sr_ctx); + } while (0); return ret; }