From a496f11ec1a7e11a48b5a41bb4c44659cc5ed7a1 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Tue, 12 Jul 2022 11:27:32 +0800 Subject: [PATCH] update: 'DSView' project used new log lib --- CMakeLists.txt | 6 +- DSView/main.cpp | 245 +++++++++--------- DSView/pv/ZipMaker.cpp | 1 - DSView/pv/appcontrol.cpp | 4 +- DSView/pv/config/appconfig.cpp | 11 +- DSView/pv/data/decode/annotation.cpp | 1 - DSView/pv/data/decode/annotationrestable.cpp | 9 +- DSView/pv/data/decoderstack.cpp | 28 +-- DSView/pv/data/logicsnapshot.cpp | 8 +- DSView/pv/data/snapshot.cpp | 3 - DSView/pv/device/devinst.cpp | 17 +- DSView/pv/devicemanager.cpp | 1 - DSView/pv/dialogs/decoderoptionsdlg.cpp | 2 - DSView/pv/dialogs/deviceoptions.cpp | 1 - DSView/pv/dialogs/fftoptions.cpp | 12 +- DSView/pv/dialogs/storeprogress.cpp | 2 - DSView/pv/dock/protocoldock.cpp | 20 +- DSView/pv/dock/searchcombobox.cpp | 1 - DSView/pv/dock/searchdock.cpp | 2 - DSView/pv/log.cpp | 34 +++ DSView/pv/log.h | 12 +- DSView/pv/mainframe.cpp | 1 - DSView/pv/mainwindow.cpp | 26 +- DSView/pv/prop/binding/deviceoptions.cpp | 13 +- DSView/pv/prop/binding/probeoptions.cpp | 14 +- DSView/pv/sigsession.cpp | 85 ++++--- DSView/pv/storesession.cpp | 1 - DSView/pv/toolbars/samplingbar.cpp | 23 +- DSView/pv/ui/dscombobox.cpp | 1 - DSView/pv/view/analogsignal.cpp | 23 +- DSView/pv/view/decodetrace.cpp | 1 - DSView/pv/view/devmode.cpp | 1 - DSView/pv/view/dsosignal.cpp | 86 +++---- DSView/pv/view/lissajoustrace.cpp | 7 +- DSView/pv/view/logicsignal.cpp | 2 - DSView/pv/view/mathtrace.cpp | 5 +- DSView/pv/view/viewport.cpp | 1 - common/log/xlog.c | 247 +++++++++++++++---- common/log/xlog.h | 51 ++-- 39 files changed, 589 insertions(+), 419 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6982c65..7ed776dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,6 +210,7 @@ find_package(Threads) set(DSView_SOURCES DSView/main.cpp DSView/dsapplication.cpp + DSView/pv/log.cpp DSView/pv/sigsession.cpp DSView/pv/mainwindow.cpp DSView/pv/devicemanager.cpp @@ -331,6 +332,7 @@ set(DSView_SOURCES set(DSView_HEADERS DSView/mystyle.h + DSView/pv/log.h DSView/pv/sigsession.h DSView/pv/mainwindow.h DSView/pv/dialogs/deviceoptions.h @@ -494,13 +496,15 @@ set(libsigrokdecode4DSL_HEADERS set(common_SOURCES common/minizip/zip.c common/minizip/unzip.c - common/minizip/ioapi.c + common/minizip/ioapi.c + common/log/xlog.c ) set(common_HEADERS common/minizip/zip.h common/minizip/unzip.h common/minizip/ioapi.h + common/log/xlog.h ) #=============================================================================== diff --git a/DSView/main.cpp b/DSView/main.cpp index 56223f03..57ff8e2b 100644 --- a/DSView/main.cpp +++ b/DSView/main.cpp @@ -22,14 +22,11 @@ #include #include - #include -#include #include #include #include #include - #include "dsapplication.h" #include "mystyle.h" #include "pv/mainframe.h" @@ -50,9 +47,9 @@ void usage() " %s [OPTION…] [FILE] — %s\n" "\n" "Help Options:\n" - " -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n" - " -V, --version Show release version\n" - " -lf, --savelog save log to locale file\n" + " -l, --loglevel Set log level, value between 0 to 5\n" + " -v, -V, --version Show release version\n" + " -s, --storelog save log to locale file\n" " -h, -?, --help Show help option\n" "\n", DS_BIN_NAME, DS_DESCRIPTION); } @@ -62,9 +59,106 @@ int main(int argc, char *argv[]) { int ret = 0; const char *open_file = NULL; + int logLevel = -1; + bool bStoreLog = false; + + //----------------------rebuild command param +#ifdef _WIN32 + // Under Windows, we need to manually retrieve the command-line arguments and convert them from UTF-16 to UTF-8. + // This prevents data loss if there are any characters that wouldn't fit in the local ANSI code page. + int argcUTF16 = 0; + LPWSTR* argvUTF16 = CommandLineToArgvW(GetCommandLineW(), &argcUTF16); + + std::vector argvUTF8Q; + std::for_each(argvUTF16, argvUTF16 + argcUTF16, [&argvUTF8Q](const LPWSTR& arg) { + argvUTF8Q.emplace_back(QString::fromUtf16(reinterpret_cast(arg), -1).toUtf8()); + }); + + LocalFree(argvUTF16); + + // Ms::runApplication() wants an argv-style array of raw pointers to the arguments, so let's create a vector of them. + std::vector argvUTF8; + for (auto& arg : argvUTF8Q){ + argvUTF8.push_back(arg.data()); + } + + // Don't use the arguments passed to main(), because they're in the local ANSI code page. + (void*)(argc); + (void*)(argv); + + int argcFinal = argcUTF16; + char** argvFinal = argvUTF8.data(); + #else + int argcFinal = argc; + char** argvFinal = argv; + #endif + //----------------------command param parse + while (1) { + static const struct option long_options[] = { + {"loglevel", required_argument, 0, 'l'}, + {"version", no_argument, 0, 'v'}, + {"storelog", no_argument, 0, 's'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + const char *shortopts = "l:Vvhs?"; + const int c = getopt_long(argcFinal, argvFinal, shortopts, long_options, NULL); + if (c == -1) + break; + + switch (c) + { + case 'l': // log level + logLevel = atoi(optarg); + break; + + case 's': // the store log flag + bStoreLog = true; + break; + + case 'V': // version + case 'v': + printf("%s %s\n", DS_TITLE, DS_VERSION_STRING); + return 0; + + case 'h': // get help + case '?': + usage(); + return 0; + } + } + + if (argcFinal - optind > 1) { + printf("Only one file can be openened.\n"); + return 1; + } + else if (argcFinal - optind == 1){ + open_file = argvFinal[argcFinal - 1]; + } + + //----------------------init log + dsv_log_init(); + + if (logLevel != -1){ + dsv_log_level(logLevel); + } + + #ifdef DEBUG_INFO + if (XLOG_LEVEL_DBG > logLevel){ + dsv_log_level(XLOG_LEVEL_DBG); // on develop mode, set the default log ldevel + } + #endif + + if (bStoreLog){ + dsv_log_enalbe_logfile(); + } + + //----------------------HightDpiScaling #if QT_VERSION >= QT_VERSION_CHECK(5,6,0) bool bHighScale = true; + #ifdef _WIN32 int argc1 = 0; QApplication *a1 = new QApplication(argc1, NULL); @@ -83,39 +177,9 @@ bool bHighScale = true; QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); } -#endif - -#ifdef _WIN32 - // Under Windows, we need to manually retrieve the command-line arguments and convert them from UTF-16 to UTF-8. - // This prevents data loss if there are any characters that wouldn't fit in the local ANSI code page. - int argcUTF16 = 0; - LPWSTR* argvUTF16 = CommandLineToArgvW(GetCommandLineW(), &argcUTF16); - - std::vector argvUTF8Q; - - std::for_each(argvUTF16, argvUTF16 + argcUTF16, [&argvUTF8Q](const LPWSTR& arg) { - argvUTF8Q.emplace_back(QString::fromUtf16(reinterpret_cast(arg), -1).toUtf8()); - }); - - LocalFree(argvUTF16); - - // Ms::runApplication() wants an argv-style array of raw pointers to the arguments, so let's create a vector of them. - std::vector argvUTF8; - - for (auto& arg : argvUTF8Q) - argvUTF8.push_back(arg.data()); - - // Don't use the arguments passed to main(), because they're in the local ANSI code page. - Q_UNUSED(argc); - Q_UNUSED(argv); - - int argcFinal = argcUTF16; - char** argvFinal = argvUTF8.data(); - #else - int argcFinal = argc; - char** argvFinal = argv; - #endif +#endif + //----------------------init app QApplication a(argcFinal, argvFinal); a.setStyle(new MyStyle); @@ -125,111 +189,44 @@ bool bHighScale = true; QApplication::setOrganizationName("DreamSourceLab"); QApplication::setOrganizationDomain("www.DreamSourceLab.com"); - dsv_log_init(); + //----------------------run + dsv_info("----------------- version: %s-----------------", DS_VERSION_STRING); + dsv_info("Qt:%s", QT_VERSION_STR); - xlog_print(dsv_log, 3, NULL, "----------------- version:%s-----------------", DS_VERSION_STRING); - xlog_print(dsv_log, 3, NULL, "Qt:%s", QT_VERSION_STR); - - //qDebug()<<"\n----------------- version:"<SetLogLevel(loglevel); - break; - } - - case 'V': - // Print version info - printf("%s %s\n", DS_TITLE, DS_VERSION_STRING); - return 0; - - case 'h': - case '?': - usage(); - return 0; - } - } - - if (argcFinal - optind > 1) { - printf("Only one file can be openened.\n"); - return 1; - } else if (argcFinal - optind == 1){ - open_file = argvFinal[argcFinal - 1]; - control->_open_file_name = open_file; - } - - -//#ifdef Q_OS_DARWIN -//#endif - - //load app config - AppConfig::Instance().LoadAll(); + AppControl *control = AppControl::Instance(); + AppConfig::Instance().LoadAll(); //load app config //init core - if (!control->Init()){ - printf("init error!"); - qDebug() << control->GetLastError(); + if (!control->Init()){ + dsv_err("%s", "init error!"); + dsv_err("%s", control->GetLastError()); return 1; } + + if (open_file != NULL){ + control->_open_file_name = open_file; + } try { control->Start(); - - // Initialise the main frame - pv::MainFrame w; + pv::MainFrame w; //Initialise the main frame w.show(); - w.readSettings(); - - //to show the dailog for open help document - w.show_doc(); - - //Run the application - ret = a.exec(); - + w.show_doc(); //to show the dailog for open help document + ret = a.exec(); //Run the application control->Stop(); } catch (const std::exception &e) { - printf("main() catch a except!"); + dsv_err("%s", "main() catch a except!"); const char *exstr = e.what(); - qDebug() << exstr; + dsv_err("%s", exstr); } - //uninit - control->UnInit(); + control->UnInit(); //uninit control->Destroy(); + dsv_log_uninit(); return ret; diff --git a/DSView/pv/ZipMaker.cpp b/DSView/pv/ZipMaker.cpp index 1c521258..e81e3df7 100644 --- a/DSView/pv/ZipMaker.cpp +++ b/DSView/pv/ZipMaker.cpp @@ -25,7 +25,6 @@ #include #include #include -#include ZipMaker::ZipMaker() : m_zDoc(NULL) diff --git a/DSView/pv/appcontrol.cpp b/DSView/pv/appcontrol.cpp index a86b8d67..b2b3d391 100644 --- a/DSView/pv/appcontrol.cpp +++ b/DSView/pv/appcontrol.cpp @@ -25,13 +25,13 @@ #include "libsigrokdecode.h" #include #include -#include #include #include "devicemanager.h" #include "sigsession.h" #include "dsvdef.h" #include "config/appconfig.h" +#include "log.h" AppControl::AppControl() { @@ -97,7 +97,7 @@ bool AppControl::Init() QString dir = GetDecodeScriptDir(); strcpy(path, dir.toUtf8().data()); - qDebug()<<"decode script path is:"< #include #include -#include -#include +#include #include #include +#include "../log.h" #define MAX_PROTOCOL_FORMAT_LIST 15 @@ -321,7 +321,8 @@ QString GetAppDataDir() if (dir1.exists()){ return dir1.absolutePath(); } - qDebug() << "Data directory is not exists:" <<"../share/DSView"; + + dsv_err("%s", "Data directory is not exists: ../share/DSView"); assert(false); #else // The bin location @@ -342,8 +343,8 @@ QString GetResourceDir(){ { return dir.absolutePath(); } - - qDebug() << "Resource directory is not exists:" << dir1.absolutePath(); + + dsv_err("%s%s", "Resource directory is not exists:", dir1.absolutePath().toUtf8().data()); assert(false); } diff --git a/DSView/pv/data/decode/annotation.cpp b/DSView/pv/data/decode/annotation.cpp index 6e70dfa8..5fc0c606 100644 --- a/DSView/pv/data/decode/annotation.cpp +++ b/DSView/pv/data/decode/annotation.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include "../../config/appconfig.h" #include "decoderstatus.h" diff --git a/DSView/pv/data/decode/annotationrestable.cpp b/DSView/pv/data/decode/annotationrestable.cpp index 3f33f263..6a863f63 100644 --- a/DSView/pv/data/decode/annotationrestable.cpp +++ b/DSView/pv/data/decode/annotationrestable.cpp @@ -21,9 +21,8 @@ #include "annotationrestable.h" #include -#include -#include - +#include +#include "../../log.h" #include "../../dsvdef.h" const char g_bin_cvt_table[] = "0000000100100011010001010110011110001001101010111100110111101111"; @@ -168,8 +167,8 @@ const char* AnnotationResTable::format_to_string(const char *hex_str, int fmt) else if (c >= 'a' && c <= 'f'){ dex = (int)(c - 'a') + 10; } - else{ - qDebug()<<"is not a hex string!"; + else{ + dsv_err("%s", "is not a hex string"); assert(false); } diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 8809bfa8..0ae0c7d9 100644 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -23,11 +23,9 @@ #include #include - -#include +#include #include "decoderstack.h" - #include "logic.h" #include "logicsnapshot.h" #include "decode/decoder.h" @@ -36,7 +34,7 @@ #include "../sigsession.h" #include "../view/logicsignal.h" #include "../dsvdef.h" -#include +#include "../log.h" using namespace pv::data::decode; using namespace std; @@ -482,9 +480,7 @@ uint64_t DecoderStack::get_max_sample_count() void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decode_end, srd_session *const session) { - decode_task_status *status = _stask_stauts; - - // qDebug()<<"decode start:"<= decode_end){ - qDebug()<<"decode data index have been end:"<_bStop) @@ -583,8 +579,8 @@ void DecoderStack::decode_data(const uint64_t decode_start, const uint64_t decod if (error) _error_message = QString::fromLocal8Bit(error); } - - qDebug()<<"send to decoder times:"<get_sample_count(); - qDebug()<<"decoder sample count:"<<_sample_count; + dsv_dbg("%s%llu", "decoder sample count:", _sample_count); // Create the decoders for(auto &dec : _stack) @@ -683,12 +679,11 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *self) DecoderStack *const d = st->_decoder; assert(d); - if (st->_bStop){ - // qDebug()<<"decode task was stoped."; + if (st->_bStop){ return; } - if (d->_decoder_status == NULL){ - qDebug()<<"decode task was deleted."; + if (d->_decoder_status == NULL){ + dsv_err("%s", "decode task was deleted."); assert(false); } @@ -723,8 +718,7 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *self) assert(row_iter != d->_rows.end()); if (row_iter == d->_rows.end()) { - qDebug() << "Unexpected annotation: decoder = " << decc << - ", format = " << a->format(); + dsv_err("Unexpected annotation: decoder = 0x%x, format = %d", (void*)decc, a->format()); assert(0); return; } diff --git a/DSView/pv/data/logicsnapshot.cpp b/DSView/pv/data/logicsnapshot.cpp index 03d645c3..4fa71759 100644 --- a/DSView/pv/data/logicsnapshot.cpp +++ b/DSView/pv/data/logicsnapshot.cpp @@ -19,8 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -#include + #include #include #include @@ -28,6 +27,7 @@ #include "logicsnapshot.h" #include "../dsvdef.h" +#include "../log.h" using namespace std; @@ -103,9 +103,7 @@ void LogicSnapshot::clear() void LogicSnapshot::capture_ended() { - Snapshot::capture_ended(); - - // qDebug()<<"total:"<<_total_sample_count<<","<<_times; + Snapshot::capture_ended(); uint64_t block_index = _ring_sample_count / LeafBlockSamples; uint64_t block_offset = (_ring_sample_count % LeafBlockSamples) / Scale; diff --git a/DSView/pv/data/snapshot.cpp b/DSView/pv/data/snapshot.cpp index c359addb..d58eabd7 100644 --- a/DSView/pv/data/snapshot.cpp +++ b/DSView/pv/data/snapshot.cpp @@ -22,9 +22,6 @@ #include "snapshot.h" - -#include - #include #include #include diff --git a/DSView/pv/device/devinst.cpp b/DSView/pv/device/devinst.cpp index 28414b8c..19f5371c 100644 --- a/DSView/pv/device/devinst.cpp +++ b/DSView/pv/device/devinst.cpp @@ -19,13 +19,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - -#include - +#include #include "devinst.h" - #include "../sigsession.h" +#include "../log.h" namespace pv { namespace device { @@ -201,13 +198,13 @@ void DevInst::start() } void DevInst::run() -{ - qDebug()<<"session run loop start"; +{ + dsv_dbg("%s", "session run loop start"); int ret = sr_session_run(); if (ret != SR_OK){ - qDebug()<<"start session error!"; - } - qDebug()<<"session run loop end"; + dsv_err("%s", "start session error!"); + } + dsv_dbg("%s", "session run loop end"); } void DevInst::stop() diff --git a/DSView/pv/devicemanager.cpp b/DSView/pv/devicemanager.cpp index 5e0c48c0..7c4107ad 100644 --- a/DSView/pv/devicemanager.cpp +++ b/DSView/pv/devicemanager.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include "config/appconfig.h" diff --git a/DSView/pv/dialogs/decoderoptionsdlg.cpp b/DSView/pv/dialogs/decoderoptionsdlg.cpp index 0c6a03a3..32987362 100644 --- a/DSView/pv/dialogs/decoderoptionsdlg.cpp +++ b/DSView/pv/dialogs/decoderoptionsdlg.cpp @@ -46,8 +46,6 @@ #include "../view/decodetrace.h" #include "../ui/msgbox.h" -#include - namespace pv { namespace dialogs { diff --git a/DSView/pv/dialogs/deviceoptions.cpp b/DSView/pv/dialogs/deviceoptions.cpp index 769484e9..d65ba4c8 100644 --- a/DSView/pv/dialogs/deviceoptions.cpp +++ b/DSView/pv/dialogs/deviceoptions.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/DSView/pv/dialogs/fftoptions.cpp b/DSView/pv/dialogs/fftoptions.cpp index 10855971..35a2f9d9 100644 --- a/DSView/pv/dialogs/fftoptions.cpp +++ b/DSView/pv/dialogs/fftoptions.cpp @@ -20,18 +20,15 @@ */ #include "fftoptions.h" - - #include #include -#include - #include "../sigsession.h" #include "../data/spectrumstack.h" #include "../view/trace.h" #include "../view/dsosignal.h" #include "../view/spectrumtrace.h" #include "../dsvdef.h" +#include "../log.h" using namespace boost; @@ -79,12 +76,15 @@ FftOptions::FftOptions(QWidget *parent, SigSession *session) : // setup _window_combobox _len_combobox _sample_limit = 0; GVariant* gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLELIMITS); + if (gvar != NULL) { _sample_limit = g_variant_get_uint64(gvar) * 0.5; g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_MAX_DSO_SAMPLELIMITS failed."; } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_MAX_DSO_SAMPLELIMITS failed."); + } + std::vector windows; std::vector length; std::vector view_modes; diff --git a/DSView/pv/dialogs/storeprogress.cpp b/DSView/pv/dialogs/storeprogress.cpp index 698d2f1b..f05ad861 100644 --- a/DSView/pv/dialogs/storeprogress.cpp +++ b/DSView/pv/dialogs/storeprogress.cpp @@ -28,8 +28,6 @@ #include #include #include -#include - #include "../ui/msgbox.h" #include "../config/appconfig.h" diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index 94d385db..a6e37c6d 100644 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -46,18 +46,16 @@ #include #include #include - #include #include "../ui/msgbox.h" #include "../dsvdef.h" #include "../config/appconfig.h" #include "../data/decode/decoderstatus.h" #include "../data/decode/decoder.h" - +#include "../log.h" using namespace std; - namespace pv { namespace dock { @@ -364,18 +362,18 @@ void ProtocolDock::on_add_protocol() bool ProtocolDock::add_protocol_by_id(QString id, bool silent, std::list &sub_decoders) { if (_session->is_device_re_attach() == true){ - qDebug()<<"Keep current decoders, cancel add new."; + dsv_dbg("%s", "Keep current decoders, cancel add new."); return true; } - if (_session->get_device()->dev_inst()->mode != LOGIC) { - qDebug()<<"Protocol Analyzer\nProtocol Analyzer is only valid in Digital Mode!"; + if (_session->get_device()->dev_inst()->mode != LOGIC) { + dsv_dbg("%s", "Protocol Analyzer\nProtocol Analyzer is only valid in Digital Mode!"); return false; } int dex = this->get_protocol_index_by_id(id); if (dex == -1){ - qDebug()<<"Protocol not exists! id:"<< id; + dsv_err("%s%s", "Protocol not exists! id:", id.toUtf8().data()); return false; } @@ -555,8 +553,6 @@ void ProtocolDock::item_clicked(const QModelIndex &index) decoder_stack->set_mark_index((ann.start_sample()+ann.end_sample())/2); _session->show_region(ann.start_sample(), ann.end_sample(), false); - - // qDebug()<resizeRowToContents(index.row()); @@ -734,8 +730,8 @@ void ProtocolDock::search_nxt() pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); auto decoder_stack = decoder_model->getDecoderStack(); - if (decoder_stack == NULL){ - qDebug()<<"decoder_stack is null"; + if (decoder_stack == NULL){ + dsv_err("%s", "decoder_stack is null"); return; } @@ -749,8 +745,6 @@ void ProtocolDock::search_nxt() if (!matchingIndex.isValid()) break; - // qDebug()<<"row:"< #include #include -#include //----------------------ComboButtonItem diff --git a/DSView/pv/dock/searchdock.cpp b/DSView/pv/dock/searchdock.cpp index 69ef2345..1bc914eb 100644 --- a/DSView/pv/dock/searchdock.cpp +++ b/DSView/pv/dock/searchdock.cpp @@ -38,8 +38,6 @@ #include #include #include -#include - #include #include "../config/appconfig.h" diff --git a/DSView/pv/log.cpp b/DSView/pv/log.cpp index ec8cceb8..9a147aca 100644 --- a/DSView/pv/log.cpp +++ b/DSView/pv/log.cpp @@ -20,9 +20,13 @@ */ #include "log.h" +#include +#include +#include "config/appconfig.h" xlog_writer *dsv_log = nullptr; xlog_context *log_ctx = nullptr; +bool b_logfile = false; void dsv_log_init() { @@ -38,4 +42,34 @@ void dsv_log_uninit() xlog_free_writer(dsv_log); log_ctx = nullptr; dsv_log = nullptr; +} + +xlog_context* dsv_log_context() +{ + return log_ctx; +} + +void dsv_log_level(int l) +{ + xlog_set_level(log_ctx, l); + dsv_dbg("%s%d", "set log level: ", l); +} + +void dsv_log_enalbe_logfile() +{ + if (!b_logfile && log_ctx){ + b_logfile = true; + + QString lf; + + #ifdef Q_OS_LINUX + lf = QDir::homePath() + "/DSView.log"; + #else + lf = GetAppDataDir() + "/DSView.log"; + #endif + + xlog_add_receiver_from_file(log_ctx, lf.toUtf8().data(), 0); + + dsv_dbg("%s\"%s\"", "store log to file: ", lf.toUtf8().data()); + } } \ No newline at end of file diff --git a/DSView/pv/log.h b/DSView/pv/log.h index 189821ef..b193beee 100644 --- a/DSView/pv/log.h +++ b/DSView/pv/log.h @@ -27,7 +27,17 @@ extern xlog_writer *dsv_log; void dsv_log_init(); - void dsv_log_uninit(); +xlog_context* dsv_log_context(); +void dsv_log_level(int l); + +void dsv_log_enalbe_logfile(); + +#define dsv_err(fmt, args...) xlog_err(dsv_log, fmt, ## args) +#define dsv_warn(fmt, args...) xlog_warn(dsv_log, fmt, ## args) +#define dsv_info(fmt, args...) xlog_info(dsv_log, fmt, ## args) +#define dsv_dbg(fmt, args...) xlog_dbg(dsv_log, fmt, ## args) +#define dsv_detail(fmt, args...) xlog_detail(dsv_log, fmt, ## args) + #endif \ No newline at end of file diff --git a/DSView/pv/mainframe.cpp b/DSView/pv/mainframe.cpp index 7d2e03b1..19b2651e 100644 --- a/DSView/pv/mainframe.cpp +++ b/DSView/pv/mainframe.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 91063650..8361883e 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -42,6 +41,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -95,6 +95,7 @@ #include "appcontrol.h" #include "utility/encoding.h" #include "utility/path.h" +#include "log.h" #define BASE_SESSION_VERSION 2 @@ -175,8 +176,7 @@ void MainWindow::setup_ui() _protocol_dock->setAllowedAreas(Qt::RightDockWidgetArea); _protocol_dock->setVisible(false); _protocol_widget = new dock::ProtocolDock(_protocol_dock, *_view, _session); - _protocol_dock->setWidget(_protocol_widget); - //qDebug() << "Protocol decoder enabled!\n"; + _protocol_dock->setWidget(_protocol_widget); // measure dock @@ -444,12 +444,12 @@ void MainWindow::update_device_list() QString ldFileName(AppControl::Instance()->_open_file_name.c_str()); if (ldFileName != ""){ - if (QFile::exists(ldFileName)){ - qDebug()<<"auto load file:"< -#include #include #include - #include "../bool.h" #include "../double.h" #include "../enum.h" #include "../int.h" #include "../../config/appconfig.h" - +#include "../../log.h" using namespace std; @@ -149,8 +147,8 @@ GVariant* DeviceOptions::config_getter( const struct sr_dev_inst *sdi, int key) { GVariant *data = NULL; - if (sr_config_get(sdi->driver, sdi, NULL, NULL, key, &data) != SR_OK) { - qDebug() << "WARNING: Failed to get value of config id" << key; + if (sr_config_get(sdi->driver, sdi, NULL, NULL, key, &data) != SR_OK) { + dsv_warn("%s%d", "WARNING: Failed to get value of config id:", key); return NULL; } return data; @@ -159,8 +157,9 @@ GVariant* DeviceOptions::config_getter( void DeviceOptions::config_setter( struct sr_dev_inst *sdi, int key, GVariant* value) { - if (sr_config_set(sdi, NULL, NULL, key, value) != SR_OK) - qDebug() << "WARNING: Failed to set value of config id" << key; + if (sr_config_set(sdi, NULL, NULL, key, value) != SR_OK){ + dsv_warn("%s%d", "WARNING: Failed to set value of config id:", key); + } } void DeviceOptions::bind_bool(const QString &name, const QString label, int key) diff --git a/DSView/pv/prop/binding/probeoptions.cpp b/DSView/pv/prop/binding/probeoptions.cpp index 76fdb81a..2aa6309c 100644 --- a/DSView/pv/prop/binding/probeoptions.cpp +++ b/DSView/pv/prop/binding/probeoptions.cpp @@ -20,20 +20,16 @@ */ #include "probeoptions.h" - #include - -#include #include #include #include "../bool.h" #include "../double.h" #include "../enum.h" #include "../int.h" - #include "../../config/appconfig.h" +#include "../../log.h" - using namespace std; namespace pv { @@ -121,8 +117,7 @@ GVariant* ProbeOptions::config_getter( { GVariant *data = NULL; if (sr_config_get(sdi->driver, sdi, probe, NULL, key, &data) != SR_OK) { - qDebug() << - "WARNING: Failed to get value of config id" << key; + dsv_warn(NULL, "%s%d", "WARNING: Failed to get value of config id:", key); return NULL; } return data; @@ -132,8 +127,9 @@ void ProbeOptions::config_setter( struct sr_dev_inst *sdi, struct sr_channel *probe, int key, GVariant* value) { - if (sr_config_set(sdi, probe, NULL, key, value) != SR_OK) - qDebug() << "WARNING: Failed to set value of sample rate"; + if (sr_config_set(sdi, probe, NULL, key, value) != SR_OK){ + dsv_warn("%s", "WARNING: Failed to set value of sample rate"); + } } void ProbeOptions::bind_bool(const QString &name, const QString label, int key) diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 2349f50e..0cdf9435 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -54,12 +54,12 @@ #include #include -#include -#include +#include #include #include "data/decode/decoderstatus.h" #include "dsvdef.h" +#include "log.h" namespace pv { @@ -142,7 +142,7 @@ void SigSession::set_device(DevInst *dev_inst) clear_all_decoder(false); } else{ - qDebug()<<"Keep current decoders"; + dsv_dbg("%s", "Keep current decoders"); } RELEASE_ARRAY(_group_traces); @@ -167,8 +167,11 @@ void SigSession::set_device(DevInst *dev_inst) else if (is_device_re_attach() == false){ clear_all_decoder(false); } - - qDebug()<<"Switch to device:"<is_file()) + dsv_dbg("%s\"%s\"", "Switch to file: ", dev_name.toUtf8().data()); + else + dsv_dbg("%s\"%s\"", "Switch to device: ", dev_name.toUtf8().data()); try { _dev_inst->use(this); @@ -437,7 +440,7 @@ void SigSession::start_capture(bool instant) { // Check that a device instance has been selected. if (!_dev_inst) { - qDebug() << "No device selected"; + dsv_dbg("%s", "No device selected"); capture_state_changed(SigSession::Stopped); return; } @@ -707,7 +710,7 @@ void SigSession::init_signals() clear_all_decoder(); } else{ - qDebug()<<"Device loose contact"; + dsv_dbg("%s", "Device loose contact"); } // Detect what data types we will receive @@ -975,7 +978,7 @@ void SigSession::feed_in_trigger(const ds_trigger_pos &trigger_pos) void SigSession::feed_in_logic(const sr_datafeed_logic &logic) { if (!_logic_data || _logic_data->snapshot()->memory_failed()) { - qDebug() << "Unexpected logic packet"; + dsv_err("%s", "Unexpected logic packet"); return; } @@ -1013,8 +1016,8 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) void SigSession::feed_in_dso(const sr_datafeed_dso &dso) { if(!_dso_data || _dso_data->snapshot()->memory_failed()) - { - qDebug() << "Unexpected dso packet"; + { + dsv_err("%s", "Unexpected dso packet"); return; // This dso packet was not expected. } @@ -1085,8 +1088,8 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) { if(!_analog_data || _analog_data->snapshot()->memory_failed()) - { - qDebug() << "Unexpected analog packet"; + { + dsv_err("%s", "Unexpected analog packet"); return; // This analog packet was not expected. } @@ -1239,7 +1242,7 @@ void SigSession::on_hotplug_event(void *ctx, void *dev, int event, void *user_da (void)user_data; if (USB_EV_HOTPLUG_ATTACH != event && USB_EV_HOTPLUG_DETTACH != event){ - qDebug("Unhandled event %d\n", event); + dsv_err("%s%d", "Unhandled event", event); return; } @@ -1251,8 +1254,9 @@ void SigSession::on_hotplug_event(void *ctx, void *dev, int event, void *user_da } else if (USB_EV_HOTPLUG_DETTACH == event) { + dsv_dbg("%s", "Device detached, will wait it reattach."); _wait_reattch_times = 0; - _is_wait_reattch = true; + _is_wait_reattch = true; //wait the device reattach. _is_device_reattach = false; } } @@ -1261,21 +1265,21 @@ void SigSession::hotplug_proc() { if (!_dev_inst) return; - - qDebug("Hotplug thread start!"); + + dsv_dbg("%s", "Hotplug thread start!"); try { while(_session && !_bHotplugStop) { sr_hotplug_wait_timout(_sr_ctx); - if (_hot_attach) { - qDebug("process event: DreamSourceLab hardware attached!"); + if (_hot_attach) { + dsv_dbg("%s", "process event: DreamSourceLab hardware attached!"); _callback->device_attach(); _hot_attach = false; } - if (_hot_detach) { - qDebug("process event: DreamSourceLab hardware detached!"); + if (_hot_detach) { + dsv_dbg("%s", "process event: DreamSourceLab hardware detached!"); _callback->device_detach(); _hot_detach = false; } @@ -1287,21 +1291,23 @@ void SigSession::hotplug_proc() // 500ms if (_wait_reattch_times == 5) { + dsv_dbg("%s", "Wait the device reattach time out for 500ms"); _hot_detach = true; _is_wait_reattch = false; } } } - } catch(...) { - qDebug("Interrupt exception for hotplug thread was thrown."); + } catch(...) { + dsv_err("%s", "Interrupt exception for hotplug thread was thrown."); } - qDebug("Hotplug thread exit!"); + + dsv_dbg("%s", "Hotplug thread exit!"); } void SigSession::register_hotplug_callback() { if (sr_listen_hotplug(_sr_ctx, hotplug_callback, NULL) != 0){ - qDebug() << "Error creating a hotplug callback,code:"; + dsv_err("%s", "Error creating a hotplug callback!"); } } @@ -1312,8 +1318,7 @@ void SigSession::deregister_hotplug_callback() void SigSession::start_hotplug_work() { - // Begin the session - // qDebug() << "Starting a hotplug thread...\n"; + // Begin the session _hot_attach = false; _hot_detach = false; @@ -1858,9 +1863,7 @@ void SigSession::set_stop_scale(float scale) //append a decode task, and try create a thread void SigSession::add_decode_task(view::DecodeTrace *trace) - { - //qDebug()<<"add a decode task"; - + { std::lock_guard lock(_decode_task_mutex); _decode_tasks.push_back(trace); @@ -1880,15 +1883,14 @@ void SigSession::set_stop_scale(float scale) for (auto it = _decode_tasks.begin(); it != _decode_tasks.end(); it++){ if ((*it) == trace){ - (*it)->decoder()->stop_decode_work(); + (*it)->decoder()->stop_decode_work(); _decode_tasks.erase(it); - qDebug()<<"remove a wait decode task"; + dsv_dbg("%s", "remove a waiting decode task"); return; } } //the task maybe is running - // qDebug()<<"remove a running decode task"; trace->decoder()->stop_decode_work(); } @@ -1915,8 +1917,7 @@ void SigSession::set_stop_scale(float scale) //wait thread end if (_decode_thread.joinable()) { - // qDebug() << "wait the decode thread end"; - _decode_thread.join(); + _decode_thread.join(); } if (!is_closed() && bUpdateView){ @@ -1971,21 +1972,19 @@ void SigSession::set_stop_scale(float scale) } //the decode task thread proc - void SigSession::decode_task_proc(){ - - qDebug()<<"------->decode thread start"; + void SigSession::decode_task_proc() + { + dsv_dbg("%s", "------->decode thread start"); auto task = get_top_decode_task(); while (task != NULL) { - // qDebug()<<"one decode task be actived"; - if (!task->_delete_flag){ task->decoder()->begin_decode_work(); } - if (task->_delete_flag){ - qDebug()<<"destroy a decoder in task thread"; + if (task->_delete_flag){ + dsv_dbg("%s", "destroy a decoder in task thread"); DESTROY_QT_LATER(task); std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -1996,8 +1995,8 @@ void SigSession::set_stop_scale(float scale) task = get_top_decode_task(); } - - qDebug()<<"------->decode thread end"; + + dsv_dbg("%s", "------->decode thread end"); _bDecodeRunning = false; } diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 5ba97707..1bfff9f2 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #ifdef _WIN32 diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 5a466263..e01b9a1f 100644 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -20,16 +20,12 @@ */ #include "samplingbar.h" -#include "../dsvdef.h" - #include #include -#include #include #include #include #include - #include "../devicemanager.h" #include "../device/devinst.h" #include "../dialogs/deviceoptions.h" @@ -38,7 +34,8 @@ #include "../view/dsosignal.h" #include "../dialogs/interval.h" #include "../config/appconfig.h" - +#include "../dsvdef.h" +#include "../log.h" using std::map; using std::max; @@ -671,8 +668,9 @@ void SamplingBar::update_sample_count_selector_value() if (gvar != NULL) { duration = g_variant_get_uint64(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_TIMEBASE failed."); return; } } else { @@ -680,8 +678,9 @@ void SamplingBar::update_sample_count_selector_value() if (gvar != NULL) { duration = g_variant_get_uint64(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_TIMEBASE failed."); return; } const uint64_t samplerate = dev_inst->get_sample_rate(); @@ -752,11 +751,13 @@ double SamplingBar::commit_hori_res() GVariant* gvar; uint64_t max_sample_rate; gvar = dev_inst->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLERATE); + if (gvar != NULL) { max_sample_rate = g_variant_get_uint64(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_MAX_DSO_SAMPLERATE failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_MAX_DSO_SAMPLERATE failed."); return -1; } diff --git a/DSView/pv/ui/dscombobox.cpp b/DSView/pv/ui/dscombobox.cpp index b57c66d8..c24c7876 100644 --- a/DSView/pv/ui/dscombobox.cpp +++ b/DSView/pv/ui/dscombobox.cpp @@ -23,7 +23,6 @@ #include "dscombobox.h" #include #include -#include #ifdef Q_OS_DARWIN #include diff --git a/DSView/pv/view/analogsignal.cpp b/DSView/pv/view/analogsignal.cpp index 4098735b..524536ae 100644 --- a/DSView/pv/view/analogsignal.cpp +++ b/DSView/pv/view/analogsignal.cpp @@ -20,17 +20,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -#include #include - #include "../view/analogsignal.h" #include "../data/analog.h" #include "../data/analogsnapshot.h" #include "../view/view.h" #include "../device/devinst.h" #include "../dsvdef.h" - +#include "../log.h" using namespace std; @@ -67,10 +64,12 @@ AnalogSignal::AnalogSignal(DevInst *dev_inst,data::Analog *data, if (gvar != NULL) { _bits = g_variant_get_byte(gvar); g_variant_unref(gvar); - } else { - _bits = DefaultBits; - qDebug("Warning: config_get SR_CONF_UNIT_BITS failed, set to %d(default).", DefaultBits); } + else { + _bits = DefaultBits; + dsv_warn("%s%d", "Warning: config_get SR_CONF_UNIT_BITS failed, set to %d(default).", DefaultBits); + } + gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_REF_MIN); if (gvar != NULL) { _ref_min = g_variant_get_uint32(gvar); @@ -91,8 +90,9 @@ AnalogSignal::AnalogSignal(DevInst *dev_inst,data::Analog *data, if (gvar != NULL) { _zero_offset = g_variant_get_uint16(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_OFFSET failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_OFFSET failed."); } } @@ -357,8 +357,9 @@ uint64_t AnalogSignal::get_factor() factor = g_variant_get_uint64(gvar); g_variant_unref(gvar); return factor; - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_FACTOR failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_FACTOR failed."); return 1; } } diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index 48485781..5fe3170b 100644 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -55,7 +55,6 @@ #include "../ui/msgbox.h" #include "../appcontrol.h" #include "../dialogs/decoderoptionsdlg.h" -#include using namespace boost; using namespace std; diff --git a/DSView/pv/view/devmode.cpp b/DSView/pv/view/devmode.cpp index 6acfe774..b897b8ed 100644 --- a/DSView/pv/view/devmode.cpp +++ b/DSView/pv/view/devmode.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include "../config/appconfig.h" diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index 6af99eff..5b37e8db 100644 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -19,18 +19,19 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsvdef.h" #include "dsosignal.h" -#include "../data/dso.h" -#include "../data/dsosnapshot.h" -#include "view.h" -#include "../sigsession.h" -#include "../device/devinst.h" -#include #include #include #include #include + +#include "view.h" +#include "../dsvdef.h" +#include "../data/dso.h" +#include "../data/dsosnapshot.h" +#include "../sigsession.h" +#include "../device/devinst.h" +#include "../log.h" using namespace std; @@ -157,8 +158,9 @@ void DsoSignal::set_enable(bool enable) if (gvar != NULL) { cur_enable = g_variant_get_boolean(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_EN failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_EN failed."); _en_lock = false; return; } @@ -264,25 +266,16 @@ bool DsoSignal::load_settings() { GVariant* gvar; - // -- enable -// bool enable; -// gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_EN); -// if (gvar != NULL) { -// enable = g_variant_get_boolean(gvar); -// g_variant_unref(gvar); -// } else { -// qDebug() << "ERROR: config_get SR_CONF_PROBE_EN failed."; -// return false; -// } - // dso channel bits gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_UNIT_BITS); if (gvar != NULL) { _bits = g_variant_get_byte(gvar); g_variant_unref(gvar); - } else { - _bits = DefaultBits; - qDebug("Warning: config_get SR_CONF_UNIT_BITS failed, set to %d(default).", DefaultBits); + } + else { + _bits = DefaultBits; + dsv_warn("%s%d", "Warning: config_get SR_CONF_UNIT_BITS failed, set to %d(default).", DefaultBits); + if (strncmp(_dev_inst->name().toUtf8().data(), "virtual", 7)) return false; } @@ -308,44 +301,43 @@ bool DsoSignal::load_settings() if (gvar != NULL) { vdiv = g_variant_get_uint64(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_VDIV failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_VDIV failed."); return false; } gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); if (gvar != NULL) { vfactor = g_variant_get_uint64(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_FACTOR failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_FACTOR failed."); return false; } _vDial->set_value(vdiv); _vDial->set_factor(vfactor); -// _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, -// g_variant_new_uint64(_vDial->get_value())); // -- coupling gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_COUPLING); if (gvar != NULL) { _acCoupling = g_variant_get_byte(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_COUPLING failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_COUPLING failed."); return false; } - -// _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_COUPLING, -// g_variant_new_byte(_acCoupling)); - + // -- vpos gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_OFFSET); if (gvar != NULL) { _zero_offset = g_variant_get_uint16(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_OFFSET failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_OFFSET failed."); return false; } @@ -355,8 +347,9 @@ bool DsoSignal::load_settings() _trig_value = g_variant_get_byte(gvar); _trig_delta = get_trig_vrate() - get_zero_ratio(); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_TRIGGER_VALUE failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_TRIGGER_VALUE failed."); if (strncmp(_dev_inst->name().toUtf8().data(), "virtual", 7)) return false; } @@ -526,8 +519,9 @@ void DsoSignal::set_factor(uint64_t factor) if (gvar != NULL) { prefactor = g_variant_get_uint64(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_FACTOR failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_FACTOR failed."); return; } if (prefactor != factor) { @@ -549,8 +543,9 @@ uint64_t DsoSignal::get_factor() factor = g_variant_get_uint64(gvar); g_variant_unref(gvar); return factor; - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_FACTOR failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_FACTOR failed."); return 1; } } @@ -1178,8 +1173,9 @@ void DsoSignal::paint_type_options(QPainter &p, int right, const QPoint pt, QCol if (gvar != NULL) { factor = g_variant_get_uint64(gvar); g_variant_unref(gvar); - } else { - qDebug() << "ERROR: config_get SR_CONF_PROBE_FACTOR failed."; + } + else { + dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_FACTOR failed."); return; } diff --git a/DSView/pv/view/lissajoustrace.cpp b/DSView/pv/view/lissajoustrace.cpp index 4dc17ed3..e5286388 100644 --- a/DSView/pv/view/lissajoustrace.cpp +++ b/DSView/pv/view/lissajoustrace.cpp @@ -21,6 +21,7 @@ #include +#include #include "view.h" #include "../dsvdef.h" @@ -29,12 +30,6 @@ #include "../data/dsosnapshot.h" #include "../sigsession.h" #include "../device/devinst.h" - - - -#include -#include - using namespace std; diff --git a/DSView/pv/view/logicsignal.cpp b/DSView/pv/view/logicsignal.cpp index 5d37cd44..1d90f23b 100644 --- a/DSView/pv/view/logicsignal.cpp +++ b/DSView/pv/view/logicsignal.cpp @@ -21,8 +21,6 @@ */ #include "libsigrokdecode.h" - -#include #include #include "logicsignal.h" #include "view.h" diff --git a/DSView/pv/view/mathtrace.cpp b/DSView/pv/view/mathtrace.cpp index e96a025b..8b2075c1 100644 --- a/DSView/pv/view/mathtrace.cpp +++ b/DSView/pv/view/mathtrace.cpp @@ -21,7 +21,7 @@ #include - +#include #include "mathtrace.h" #include "../data/dso.h" #include "../data/dsosnapshot.h" @@ -32,9 +32,6 @@ #include "../view/dsosignal.h" #include "../dsvdef.h" -#include -#include - using namespace std; namespace pv { diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 3caa6b22..5250a3b3 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include "../config/appconfig.h" #include "../dsvdef.h" diff --git a/common/log/xlog.c b/common/log/xlog.c index 27390092..c8f86b27 100644 --- a/common/log/xlog.c +++ b/common/log/xlog.c @@ -25,6 +25,7 @@ #include #include #include +#include #define RECEIVER_MAX_COUNT 10 #define LOG_MAX_LENGTH 1000 @@ -37,7 +38,7 @@ enum xlog_receiver_type{ struct xlog_receiver_info; -typedef void (*xlog_print_func)(struct xlog_receiver_info *info, const char *domain, const char *prefix, const char *format, va_list args); +typedef void (*xlog_print_func)(struct xlog_receiver_info *info, const char *domain, const char *format, va_list args); struct xlog_receiver_info { @@ -53,6 +54,7 @@ struct xlog_context int _log_level; char _error[50]; int _count; + pthread_mutex_t _mutext; }; struct xlog_writer{ @@ -63,7 +65,7 @@ struct xlog_writer{ /** * the default mode process */ -static void print_to_console(struct xlog_receiver_info *info, const char *domain, const char *prefix, const char *format, va_list args) +static void print_to_console(struct xlog_receiver_info *info, const char *domain, const char *format, va_list args) { (void)info; @@ -71,10 +73,6 @@ static void print_to_console(struct xlog_receiver_info *info, const char *domain fprintf(stderr, "%s", domain); fprintf(stderr, ": "); } - if (prefix){ - fprintf(stderr, "%s", prefix); - fprintf(stderr, ": "); - } vfprintf(stderr, format, args); fprintf(stderr, "\n"); @@ -83,7 +81,7 @@ static void print_to_console(struct xlog_receiver_info *info, const char *domain /** * the file mode process */ -static void print_to_file(struct xlog_receiver_info *info, const char *domain, const char *prefix, const char *format, va_list args) +static void print_to_file(struct xlog_receiver_info *info, const char *domain, const char *format, va_list args) { char buf[LOG_MAX_LENGTH + 1]; int fmtl; @@ -101,13 +99,6 @@ static void print_to_file(struct xlog_receiver_info *info, const char *domain, c strcpy(buf + wr, ": "); wr += 2; } - if (prefix && *prefix){ - strl = strlen(prefix); - strcpy(buf + wr, prefix); - wr += strl; - strcpy(buf + wr, ": "); - wr += 2; - } fmtl = vsnprintf(buf + wr, LOG_MAX_LENGTH - wr - 1, format, args); wr += fmtl; @@ -121,7 +112,7 @@ static void print_to_file(struct xlog_receiver_info *info, const char *domain, c /** * the callback mode process */ -static void print_to_user_callback(struct xlog_receiver_info *info, const char *domain, const char *prefix, const char *format, va_list args) +static void print_to_user_callback(struct xlog_receiver_info *info, const char *domain, const char *format, va_list args) { char buf[LOG_MAX_LENGTH + 1]; int fmtl; @@ -139,19 +130,12 @@ static void print_to_user_callback(struct xlog_receiver_info *info, const char * strcpy(buf + wr, ": "); wr += 2; } - if (prefix && *prefix){ - strl = strlen(prefix); - strcpy(buf + wr, prefix); - wr += strl; - strcpy(buf + wr, ": "); - wr += 2; - } fmtl = vsnprintf(buf + wr, LOG_MAX_LENGTH - wr - 1, format, args); wr += fmtl; *(buf + wr) = '\n'; wr += 1; - + info->_rev(buf, wr); } @@ -162,6 +146,7 @@ XLOG_API xlog_context* xlog_new() { int i=0; xlog_context *ctx = (xlog_context*)malloc(sizeof(xlog_context)); + if (ctx != NULL){ for(i=0; i< RECEIVER_MAX_COUNT; i++){ ctx->_receivers[i]._fn = NULL; @@ -169,9 +154,12 @@ XLOG_API xlog_context* xlog_new() } ctx->_receivers[0]._fn = print_to_console; ctx->_receivers[0]._type = RECEIVER_TYPE_CONSOLE; - ctx->_log_level = XLOG_INFO; + ctx->_log_level = XLOG_LEVEL_INFO; ctx->_count = 1; + + pthread_mutex_init(&ctx->_mutext, NULL); } + return ctx; } @@ -193,6 +181,8 @@ XLOG_API void xlog_free(xlog_context* ctx) } } + pthread_mutex_destroy(&ctx->_mutext); + free(ctx); } } @@ -212,6 +202,8 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receiver rev, int *out_in return -1; } + pthread_mutex_lock(&ctx->_mutext); + for (i = 0; i < RECEIVER_MAX_COUNT; i++){ if (ctx->_receivers[i]._fn == NULL) break; @@ -219,6 +211,7 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receiver rev, int *out_in if (i == RECEIVER_MAX_COUNT){ strcpy(ctx->_error, "receiver count is full"); + pthread_mutex_unlock(&ctx->_mutext); return -1; } @@ -230,6 +223,8 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receiver rev, int *out_in if (out_index) *out_index = i; + pthread_mutex_unlock(&ctx->_mutext); + return 0; } @@ -250,6 +245,8 @@ XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_pat return -1; } + pthread_mutex_lock(&ctx->_mutext); + for (i = 0; i < RECEIVER_MAX_COUNT; i++){ if (ctx->_receivers[i]._fn == NULL) break; @@ -257,12 +254,14 @@ XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_pat if (i == RECEIVER_MAX_COUNT){ strcpy(ctx->_error, "receiver list is full"); + pthread_mutex_unlock(&ctx->_mutext); return -1; } fh = fopen(file_path, "a+"); if (fh == NULL){ strcpy(ctx->_error, "open file error"); + pthread_mutex_unlock(&ctx->_mutext); return -1; } @@ -273,6 +272,8 @@ XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_pat if (out_index) *out_index = i; + + pthread_mutex_unlock(&ctx->_mutext); return 0; } @@ -285,8 +286,12 @@ XLOG_API int xlog_remove_receiver_by_index(xlog_context* ctx, int index) if (ctx == NULL){ return -1; } + + pthread_mutex_lock(&ctx->_mutext); + if (index < 0 || index >= ctx->_count){ strcpy(ctx->_error, "index out of range"); + pthread_mutex_unlock(&ctx->_mutext); return -1; } @@ -299,8 +304,11 @@ XLOG_API int xlog_remove_receiver_by_index(xlog_context* ctx, int index) ctx->_receivers[index-1]._type = ctx->_receivers[index]._type; ctx->_receivers[index-1]._rev = ctx->_receivers[index]._rev; ctx->_receivers[index-1]._file = ctx->_receivers[index]._file; + index++; } ctx->_count--; + + pthread_mutex_unlock(&ctx->_mutext); return 0; } @@ -315,11 +323,15 @@ XLOG_API int xlog_clear_all_receiver(xlog_context* ctx) return -1; } + pthread_mutex_lock(&ctx->_mutext); + for (i = 0; i < RECEIVER_MAX_COUNT; i++){ ctx->_receivers[i]._fn = NULL; } ctx->_count = 0; + pthread_mutex_unlock(&ctx->_mutext); + return 0; } @@ -343,16 +355,15 @@ XLOG_API int xlog_set_level(xlog_context* ctx, int level) if (ctx == NULL){ return -1; } - if (level < XLOG_NONE || level > XLOG_SPEW){ - strcpy(ctx->_error, "@level value must between 0 and 5"); - return -1; - } + if (level < XLOG_LEVEL_NONE) + level = XLOG_LEVEL_NONE; + if (level > XLOG_LEVEL_DETAIL) + level = XLOG_LEVEL_DETAIL; + ctx->_log_level = level; return 0; -} - -//-------------------------------------------------print api +} /** * create a new writer @@ -396,38 +407,184 @@ XLOG_API int xlog_set_domain(xlog_writer* wr, const char *domain) return 0; } +//-------------------------------------------------print api + /** - * print a log data, return 0 if success. + * print a error message, return 0 if success. */ -XLOG_API int xlog_print(xlog_writer *wr, int level, const char *prefix, const char *format, ...) +XLOG_API int xlog_err(xlog_writer *wr, const char *format, ...) { int i; struct xlog_receiver_info *inf; va_list args; + xlog_context *ctx; if (wr == NULL){ return -1; } - xlog_context *ctx = wr->_ctx; - if (ctx == NULL || ctx->_log_level < level){ - return -1; - } - if (ctx->_count == 0){ + ctx = wr->_ctx; + if (ctx == NULL || ctx->_log_level < XLOG_LEVEL_ERR || ctx->_count < 1){ return -1; } - for (i = 0; i < RECEIVER_MAX_COUNT; i++){ + pthread_mutex_lock(&ctx->_mutext); + + for (i = 0; i < ctx->_count; i++){ inf = &ctx->_receivers[i]; + if (inf->_fn != NULL){ va_start(args, format); - inf->_fn(inf, wr->_domain, prefix, format, args); + inf->_fn(inf, wr->_domain, format, args); va_end(args); - } - else{ - break; - } - } + } + } + + pthread_mutex_unlock(&ctx->_mutext); return 0; +} + +/** + * print a warning message, return 0 if success. + */ +XLOG_API int xlog_warn(xlog_writer *wr, const char *format, ...) +{ + int i; + struct xlog_receiver_info *inf; + va_list args; + xlog_context *ctx; + + if (wr == NULL){ + return -1; + } + + ctx = wr->_ctx; + if (ctx == NULL || ctx->_log_level < XLOG_LEVEL_WARN || ctx->_count < 1){ + return -1; + } + + pthread_mutex_lock(&ctx->_mutext); + + for (i = 0; i < ctx->_count; i++){ + inf = &ctx->_receivers[i]; + + if (inf->_fn != NULL){ + va_start(args, format); + inf->_fn(inf, wr->_domain, format, args); + va_end(args); + } + } + + pthread_mutex_unlock(&ctx->_mutext); + + return 0; +} + +/** + * print a informational message, return 0 if success. + */ +XLOG_API int xlog_info(xlog_writer *wr, const char *format, ...) +{ + int i; + struct xlog_receiver_info *inf; + va_list args; + xlog_context *ctx; + + if (wr == NULL){ + return -1; + } + + ctx = wr->_ctx; + if (ctx == NULL || ctx->_log_level < XLOG_LEVEL_INFO || ctx->_count < 1){ + return -1; + } + + pthread_mutex_lock(&ctx->_mutext); + + for (i = 0; i < ctx->_count; i++){ + inf = &ctx->_receivers[i]; + + if (inf->_fn != NULL){ + va_start(args, format); + inf->_fn(inf, wr->_domain, format, args); + va_end(args); + } + } + + pthread_mutex_unlock(&ctx->_mutext); + + return 0; +} + +/** + * print a debug message, return 0 if success. + */ +XLOG_API int xlog_dbg(xlog_writer *wr, const char *format, ...) +{ + int i; + struct xlog_receiver_info *inf; + va_list args; + xlog_context *ctx; + + if (wr == NULL){ + return -1; + } + + ctx = wr->_ctx; + if (ctx == NULL || ctx->_log_level < XLOG_LEVEL_DBG || ctx->_count < 1){ + return -1; + } + + pthread_mutex_lock(&ctx->_mutext); + + for (i = 0; i < ctx->_count; i++){ + inf = &ctx->_receivers[i]; + + if (inf->_fn != NULL){ + va_start(args, format); + inf->_fn(inf, wr->_domain, format, args); + va_end(args); + } + } + + pthread_mutex_unlock(&ctx->_mutext); + + return 0; +} + +/** + * print a detailed message, return 0 if success. + */ +XLOG_API int xlog_detail(xlog_writer *wr, const char *format, ...) +{ + int i; + struct xlog_receiver_info *inf; + va_list args; + xlog_context *ctx; + + if (wr == NULL){ + return -1; + } + + ctx = wr->_ctx; + if (ctx == NULL || ctx->_log_level < XLOG_LEVEL_DETAIL || ctx->_count < 1){ + return -1; + } + + pthread_mutex_lock(&ctx->_mutext); + + for (i = 0; i < ctx->_count; i++){ + inf = &ctx->_receivers[i]; + + if (inf->_fn != NULL){ + va_start(args, format); + inf->_fn(inf, wr->_domain, format, args); + va_end(args); + } + } + + pthread_mutex_unlock(&ctx->_mutext); + + return 0; } \ No newline at end of file diff --git a/common/log/xlog.h b/common/log/xlog.h index 0a0851dd..947113c0 100644 --- a/common/log/xlog.h +++ b/common/log/xlog.h @@ -23,9 +23,8 @@ * example: * xlog_context *ctx = xlog_new(); * xlog_writer *wr = xlog_create_writer(ctx, "module name"); -* xlog_print(wr, 2, "prefix", "count:%d", 100); //print: "module name: prefix: count:100\n" +* xlog_err(wr, "count:%d", 100); * xlog_free(ctx); //free the context, all writer will can't to use -* */ #ifndef _X_LOG_H_ @@ -42,15 +41,19 @@ extern "C" { #endif /** loglevels. */ -enum xlog_level_code{ - XLOG_NONE = 0, /**< Output no messages at all. */ - XLOG_ERR = 1, /**< Output error messages. */ - XLOG_WARN = 2, /**< Output warnings. */ - XLOG_INFO = 3, /**< Output informational messages. */ - XLOG_DBG = 4, /**< Output debug messages. */ - XLOG_SPEW = 5, /**< Output very noisy debug messages. */ +enum xlog_level_code +{ + XLOG_LEVEL_NONE = 0, /**< Output no messages at all. */ + XLOG_LEVEL_ERR = 1, /**< Output error messages. */ + XLOG_LEVEL_WARN = 2, /**< Output warnings. */ + XLOG_LEVEL_INFO = 3, /**< Output informational messages. */ + XLOG_LEVEL_DBG = 4, /**< Output debug messages. */ + XLOG_LEVEL_DETAIL = 5, /**< Output detailed messages. */ }; +/* + a log module instance. +*/ struct xlog_context; typedef struct xlog_context xlog_context; @@ -104,8 +107,6 @@ XLOG_API const char* xlog_get_error(xlog_context* ctx); */ XLOG_API int xlog_set_level(xlog_context* ctx, int level); -//-------------------------------------------------print api - /** * create a new writer * use free to delete the returns object. @@ -122,11 +123,33 @@ XLOG_API void xlog_free_writer(xlog_writer *wr); */ XLOG_API int xlog_set_domain(xlog_writer* wr, const char *domain); + +//-------------------------------------------------print api + /** - * print a log data, return 0 if success. - * @level see enum xlog_level_code + * print a error message, return 0 if success. */ -XLOG_API int xlog_print(xlog_writer *wr, int level, const char *prefix, const char *format, ...); +XLOG_API int xlog_err(xlog_writer *wr, const char *format, ...); + +/** + * print a warning message, return 0 if success. + */ +XLOG_API int xlog_warn(xlog_writer *wr, const char *format, ...); + +/** + * print a informational message, return 0 if success. + */ +XLOG_API int xlog_info(xlog_writer *wr, const char *format, ...); + +/** + * print a debug message, return 0 if success. + */ +XLOG_API int xlog_dbg(xlog_writer *wr, const char *format, ...); + +/** + * print a detailed message, return 0 if success. + */ +XLOG_API int xlog_detail(xlog_writer *wr, const char *format, ...); #ifdef __cplusplus }