X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=main.cpp;h=74d13fdc4af1b0eeb9e9b3d3e1d64169597b8dd9;hp=715dc526c2f07fce90eb9d111cf253acf57dc09a;hb=c13447b3916ffed6257fa806536a52bcb58f0315;hpb=140181a46034cf65739ba4bf0bf1260ab94ac736 diff --git a/main.cpp b/main.cpp index 715dc526..74d13fdc 100644 --- a/main.cpp +++ b/main.cpp @@ -18,26 +18,37 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef ENABLE_SIGROKDECODE -#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 #ifdef ENABLE_SIGNALS -#include "signalhandler.h" +#include "signalhandler.hpp" #endif -#include "pv/mainwindow.h" +#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, @@ -54,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) { @@ -82,9 +93,9 @@ 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_SIGROKDECODE +#ifdef ENABLE_DECODE srd_log_loglevel_set(loglevel); #endif @@ -110,14 +121,11 @@ 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(); do { -#ifdef ENABLE_SIGROKDECODE +#ifdef ENABLE_DECODE // Initialise libsigrokdecode if (srd_init(NULL) != SRD_OK) { qDebug() << "ERROR: libsigrokdecode init failed."; @@ -128,20 +136,12 @@ int main(int argc, char *argv[]) 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 @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) QObject::connect(handler, SIGNAL(term_received()), &w, SLOT(close())); - } else { + } else { qWarning() << "Could not prepare signal handler."; } @@ -162,18 +162,17 @@ int main(int argc, char *argv[]) // Run the application ret = a.exec(); + + } catch(std::exception e) { + qDebug() << e.what(); } -#ifdef ENABLE_SIGROKDECODE +#ifdef ENABLE_DECODE // Destroy libsigrokdecode srd_exit(); #endif } while (0); - // Destroy libsigrok - if (sr_ctx) - sr_exit(sr_ctx); - return ret; }