forked from Ivasoft/DSView
Code refactoring 13
This commit is contained in:
@@ -185,20 +185,30 @@ bool bHighScale = true;
|
||||
#ifdef DEBUG_INFO
|
||||
if (XLOG_LEVEL_INFO > logLevel){
|
||||
dsv_log_level(XLOG_LEVEL_INFO); // on develop mode, set the default log ldevel
|
||||
logLevel = XLOG_LEVEL_INFO;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bStoreLog){
|
||||
dsv_log_enalbe_logfile();
|
||||
dsv_log_enalbe_logfile(true);
|
||||
}
|
||||
|
||||
AppControl *control = AppControl::Instance();
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
app.LoadAll(); //load app config
|
||||
|
||||
if (app._appOptions.ableSaveLog){
|
||||
dsv_log_enalbe_logfile(false);
|
||||
|
||||
if (app._appOptions.logLevel >= logLevel){
|
||||
dsv_log_level(app._appOptions.logLevel);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------run
|
||||
dsv_info("----------------- version: %s-----------------", DS_VERSION_STRING);
|
||||
dsv_info("Qt:%s", QT_VERSION_STR);
|
||||
|
||||
AppControl *control = AppControl::Instance();
|
||||
AppConfig::Instance().LoadAll(); //load app config
|
||||
|
||||
//init core
|
||||
if (!control->Init()){
|
||||
dsv_err("%s", "init error!");
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
#include <libsigrokdecode.h>
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
#include <QWidget>
|
||||
#include <QWidget>
|
||||
#include <string>
|
||||
#include "sigsession.h"
|
||||
#include "dsvdef.h"
|
||||
#include "config/appconfig.h"
|
||||
#include "log.h"
|
||||
#include <QTextCodec>
|
||||
#include <string.h>
|
||||
#include "utility/path.h"
|
||||
|
||||
AppControl::AppControl()
|
||||
{
|
||||
@@ -66,7 +66,7 @@ bool AppControl::Init()
|
||||
{
|
||||
_session->init();
|
||||
|
||||
srd_log_set_context(dsv_log_context());
|
||||
srd_log_set_context(dsv_log_context());
|
||||
|
||||
#if defined(_WIN32) && defined(DEBUG_INFO)
|
||||
//able run debug with qtcreator
|
||||
|
||||
@@ -94,6 +94,8 @@ void _loadApp(AppOptions &o, QSettings &st){
|
||||
getFiled("quickScroll", st, o.quickScroll, true);
|
||||
getFiled("warnofMultiTrig", st, o.warnofMultiTrig, true);
|
||||
getFiled("originalData", st, o.originalData, false);
|
||||
getFiled("ableSaveLog", st, o.ableSaveLog, false);
|
||||
getFiled("logLevel", st, o.logLevel, 3);
|
||||
|
||||
QString fmt;
|
||||
getFiled("protocalFormats", st, fmt, "");
|
||||
@@ -109,6 +111,8 @@ void _saveApp(AppOptions &o, QSettings &st){
|
||||
setFiled("quickScroll", st, o.quickScroll);
|
||||
setFiled("warnofMultiTrig", st, o.warnofMultiTrig);
|
||||
setFiled("originalData", st, o.originalData);
|
||||
setFiled("ableSaveLog", st, o.ableSaveLog);
|
||||
setFiled("logLevel", st, o.logLevel);
|
||||
|
||||
QString fmt = FormatArrayToString(o.m_protocolFormats);
|
||||
setFiled("protocalFormats", st, fmt);
|
||||
@@ -238,6 +242,8 @@ void AppConfig::LoadAll()
|
||||
_loadApp(_appOptions, st);
|
||||
_loadHistory(_userHistory, st);
|
||||
_loadFrame(_frameOptions, st);
|
||||
|
||||
//dsv_dbg("Config file path:\"%s\"", st.fileName().toUtf8().data());
|
||||
}
|
||||
|
||||
void AppConfig::SaveApp()
|
||||
|
||||
@@ -57,6 +57,8 @@ struct AppOptions
|
||||
bool quickScroll;
|
||||
bool warnofMultiTrig;
|
||||
bool originalData;
|
||||
bool ableSaveLog;
|
||||
int logLevel;
|
||||
|
||||
std::vector<StringPair> m_protocolFormats;
|
||||
};
|
||||
|
||||
@@ -23,10 +23,13 @@
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include "config/appconfig.h"
|
||||
#include "utility/path.h"
|
||||
#include <string>
|
||||
|
||||
xlog_writer *dsv_log = nullptr;
|
||||
static xlog_context *log_ctx = nullptr;
|
||||
bool b_logfile = false;
|
||||
static bool b_logfile = false;
|
||||
static int log_file_index = -1;
|
||||
|
||||
void dsv_log_init()
|
||||
{
|
||||
@@ -52,10 +55,10 @@ xlog_context* dsv_log_context()
|
||||
void dsv_log_level(int l)
|
||||
{
|
||||
xlog_set_level(log_ctx, l);
|
||||
dsv_info("%s%d", "set log level: ", l);
|
||||
dsv_info("%s%d", "Set log level: ", l);
|
||||
}
|
||||
|
||||
void dsv_log_enalbe_logfile()
|
||||
void dsv_log_enalbe_logfile(bool append)
|
||||
{
|
||||
if (!b_logfile && log_ctx){
|
||||
b_logfile = true;
|
||||
@@ -68,11 +71,22 @@ void dsv_log_enalbe_logfile()
|
||||
lf = GetAppDataDir() + "/DSView.log";
|
||||
#endif
|
||||
|
||||
dsv_info("%s\"%s\"", "store log to file: ", lf.toUtf8().data());
|
||||
dsv_info("%s\"%s\"", "Store log to file: ", lf.toUtf8().data());
|
||||
|
||||
int ret = xlog_add_receiver_from_file(log_ctx, lf.toUtf8().data(), 0);
|
||||
std::string log_file = pv::path::ToUnicodePath(lf);
|
||||
|
||||
int ret = xlog_add_receiver_from_file(log_ctx, log_file.c_str(), &log_file_index, append);
|
||||
if (ret != 0){
|
||||
dsv_err("%s", "create log file error!");
|
||||
}
|
||||
dsv_err("%s", "Create log file error!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dsv_remove_log_file()
|
||||
{
|
||||
if (b_logfile && log_ctx)
|
||||
{
|
||||
b_logfile = false;
|
||||
xlog_remove_receiver_by_index(log_ctx, log_file_index);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,8 @@ void dsv_log_uninit();
|
||||
xlog_context* dsv_log_context();
|
||||
void dsv_log_level(int l);
|
||||
|
||||
void dsv_log_enalbe_logfile();
|
||||
void dsv_log_enalbe_logfile(bool append);
|
||||
void dsv_remove_log_file();
|
||||
|
||||
#define LOG_PREFIX ""
|
||||
#define dsv_err(fmt, args...) xlog_err(dsv_log, LOG_PREFIX fmt, ## args)
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
#include "dsvdef.h"
|
||||
#include "log.h"
|
||||
#include "config/appconfig.h"
|
||||
#include "utility/path.h"
|
||||
|
||||
namespace pv {
|
||||
|
||||
@@ -110,8 +111,6 @@ SigSession::SigSession()
|
||||
_group_data = new data::Group();
|
||||
_group_cnt = 0;
|
||||
|
||||
_sr_ctx = NULL;
|
||||
|
||||
_feed_timer.Stop();
|
||||
_feed_timer.SetCallback(std::bind(&SigSession::feed_timeout, this));
|
||||
}
|
||||
@@ -145,8 +144,7 @@ void SigSession::set_device(DevInst *dev_inst)
|
||||
|
||||
RELEASE_ARRAY(_group_traces);
|
||||
|
||||
if (_dev_inst) {
|
||||
sr_session_datafeed_callback_remove_all();
|
||||
if (_dev_inst) {
|
||||
_dev_inst->release();
|
||||
_dev_inst = NULL;
|
||||
}
|
||||
@@ -1887,6 +1885,17 @@ void SigSession::set_stop_scale(float scale)
|
||||
_bDecodeRunning = false;
|
||||
}
|
||||
|
||||
void SigSession::get_device_list(std::vector<struct ds_device_info> &devices)
|
||||
{
|
||||
struct ds_device_info *array = NULL;
|
||||
int num = 0;
|
||||
|
||||
if (ds_get_device_list(&array, &num) != SR_OK){
|
||||
dsv_err("%s", "Failed to get device list!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void SigSession::device_lib_event_callback(int event)
|
||||
{
|
||||
struct ds_device_info *array = NULL;
|
||||
@@ -1917,16 +1926,10 @@ void SigSession::set_stop_scale(float scale)
|
||||
|
||||
ds_set_datafeed_callback(data_feed_callback);
|
||||
|
||||
// firmware resource directory
|
||||
QString resdir = GetResourceDir();
|
||||
char res_path[256] = {0};
|
||||
#ifdef _WIN32
|
||||
QTextCodec *codec = QTextCodec::codecForName("System");
|
||||
QByteArray str_tmp = codec->fromUnicode(resdir);
|
||||
strncpy(res_path, str_tmp.data(), sizeof(res_path) - 1);
|
||||
#else
|
||||
strncpy(res_path, resdir.toUtf8().data(), sizeof(res_path) - 1);
|
||||
#endif
|
||||
ds_set_firmware_resource_dir(res_path);
|
||||
std::string res_path = pv::path::ToUnicodePath(resdir);
|
||||
ds_set_firmware_resource_dir(res_path.c_str());
|
||||
|
||||
if (ds_lib_init() != SR_OK)
|
||||
{
|
||||
@@ -1946,7 +1949,7 @@ void SigSession::set_stop_scale(float scale)
|
||||
|
||||
int SigSession::get_device_work_mode()
|
||||
{
|
||||
return ds_get_selected_device_index()
|
||||
return ds_get_actived_device_mode();
|
||||
}
|
||||
|
||||
} // namespace pv
|
||||
|
||||
@@ -310,6 +310,7 @@ private:
|
||||
void feed_timeout();
|
||||
void repeat_update();
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* Attempts to autodetect the format. Failing that
|
||||
@@ -332,6 +333,8 @@ private:
|
||||
void data_feed_in(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet);
|
||||
|
||||
void get_device_list(std::vector<struct ds_device_info> &devices);
|
||||
|
||||
static void data_feed_callback(const struct sr_dev_inst *sdi,
|
||||
const struct sr_datafeed_packet *packet);
|
||||
|
||||
|
||||
@@ -28,11 +28,18 @@
|
||||
#include <QUrl>
|
||||
#include <QApplication>
|
||||
#include <assert.h>
|
||||
#include <QComboBox>
|
||||
#include <QFormLayout>
|
||||
#include <QWidget>
|
||||
#include <QCheckBox>
|
||||
|
||||
#include "logobar.h"
|
||||
#include "../dialogs/about.h"
|
||||
#include "../dialogs/dsmessagebox.h"
|
||||
#include "../config/appconfig.h"
|
||||
#include "../dialogs/dsdialog.h"
|
||||
#include "../appcontrol.h"
|
||||
#include "../log.h"
|
||||
|
||||
namespace pv {
|
||||
namespace toolbars {
|
||||
@@ -76,6 +83,7 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
|
||||
_logo_button.addAction(_issue);
|
||||
|
||||
_update = new QAction(this);
|
||||
_log = new QAction(this);
|
||||
|
||||
_menu = new QMenu(this);
|
||||
_menu->addMenu(_language);
|
||||
@@ -83,6 +91,7 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
|
||||
_menu->addAction(_manual);
|
||||
_menu->addAction(_issue);
|
||||
_menu->addAction(_update);
|
||||
_menu->addAction(_log);
|
||||
_logo_button.setMenu(_menu);
|
||||
|
||||
_logo_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
@@ -104,6 +113,7 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
|
||||
connect(_manual, SIGNAL(triggered()), this, SIGNAL(sig_open_doc()));
|
||||
connect(_issue, SIGNAL(triggered()), this, SLOT(on_actionIssue_triggered()));
|
||||
connect(_update, SIGNAL(triggered()), this, SLOT(on_action_update()));
|
||||
connect(_log, SIGNAL(triggered()), this, SLOT(on_action_setting_log()));
|
||||
}
|
||||
|
||||
void LogoBar::changeEvent(QEvent *event)
|
||||
@@ -125,6 +135,7 @@ void LogoBar::retranslateUi()
|
||||
_manual->setText(tr("&Manual"));
|
||||
_issue->setText(tr("&Bug Report"));
|
||||
_update->setText(tr("&Update"));
|
||||
_log->setText(tr("L&og Options"));
|
||||
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
if (app._frameOptions.language == LAN_CN)
|
||||
@@ -141,6 +152,7 @@ void LogoBar::reStyle()
|
||||
_manual->setIcon(QIcon(iconPath+"/manual.svg"));
|
||||
_issue->setIcon(QIcon(iconPath+"/bug.svg"));
|
||||
_update->setIcon(QIcon(iconPath+"/update.svg"));
|
||||
_log->setIcon(QIcon(iconPath+"/file.svg"));
|
||||
|
||||
if (_connected)
|
||||
_logo_button.setIcon(QIcon(iconPath+"/logo_color.svg"));
|
||||
@@ -226,5 +238,53 @@ void LogoBar::enable_toggle(bool enable)
|
||||
_logo_button.setDisabled(!enable);
|
||||
}
|
||||
|
||||
void LogoBar::on_action_setting_log()
|
||||
{
|
||||
AppConfig &app = AppConfig::Instance();
|
||||
auto *topWind = AppControl::Instance()->GetTopWindow();
|
||||
dialogs::DSDialog dlg(topWind, false, true);
|
||||
dlg.setTitle(tr("Log Options"));
|
||||
dlg.setMinimumSize(260, 120);
|
||||
QWidget *panel = new QWidget(&dlg);
|
||||
dlg.layout()->addWidget(panel);
|
||||
panel->setMinimumSize(250, 110);
|
||||
QFormLayout *lay = new QFormLayout();
|
||||
panel->setLayout(lay);
|
||||
lay->setVerticalSpacing(15);
|
||||
|
||||
QComboBox *cbBox = new QComboBox();
|
||||
cbBox->setMinimumWidth(40);
|
||||
lay->addRow(tr("Log Level"), cbBox);
|
||||
|
||||
for (int i=0; i<=5; i++){
|
||||
cbBox->addItem(QString::number(i));
|
||||
}
|
||||
cbBox->setCurrentIndex(app._appOptions.logLevel);
|
||||
|
||||
QCheckBox *ckBox = new QCheckBox();
|
||||
ckBox->setChecked(app._appOptions.ableSaveLog);
|
||||
lay->addRow(tr("Save To File"), ckBox);
|
||||
|
||||
dlg.exec();
|
||||
|
||||
if (dlg.IsClickYes()){
|
||||
bool ableSave = ckBox->isChecked();
|
||||
int level = cbBox->currentIndex();
|
||||
|
||||
if (ableSave != app._appOptions.ableSaveLog || level != app._appOptions.logLevel){
|
||||
app._appOptions.ableSaveLog = ableSave;
|
||||
app._appOptions.logLevel = level;
|
||||
app.SaveApp();
|
||||
|
||||
dsv_log_level(level);
|
||||
|
||||
if (ableSave)
|
||||
dsv_log_enalbe_logfile(false);
|
||||
else
|
||||
dsv_remove_log_file();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace toolbars
|
||||
} // namespace pv
|
||||
|
||||
@@ -75,6 +75,7 @@ private slots:
|
||||
void on_actionManual_triggered();
|
||||
void on_actionIssue_triggered();
|
||||
void on_action_update();
|
||||
void on_action_setting_log();
|
||||
|
||||
private:
|
||||
bool _enable;
|
||||
@@ -93,6 +94,7 @@ private:
|
||||
QAction *_manual;
|
||||
QAction *_issue;
|
||||
QAction *_update;
|
||||
QAction *_log;
|
||||
|
||||
IMainForm *_mainForm;
|
||||
};
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
*/
|
||||
|
||||
#include "path.h"
|
||||
#ifdef _WIN32
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
|
||||
namespace pv{
|
||||
namespace path{
|
||||
@@ -38,5 +41,20 @@ namespace path{
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string ToUnicodePath(QString path)
|
||||
{
|
||||
std::string str;
|
||||
|
||||
#ifdef _WIN32
|
||||
QTextCodec *codec = QTextCodec::codecForName("System");
|
||||
QByteArray str_tmp = codec->fromUnicode(path);
|
||||
str = str_tmp.data();
|
||||
#else
|
||||
str = path.toUtf8().data();
|
||||
#endif
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ namespace path{
|
||||
std::string ConvertPath(QString fileName);
|
||||
|
||||
QString GetDirectoryName(QString path);
|
||||
|
||||
std::string ToUnicodePath(QString path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receive_callback rev, int
|
||||
* append a log data receiver, return 0 if success.
|
||||
* the log data will be writed to file.
|
||||
*/
|
||||
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index)
|
||||
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index, int bAppend)
|
||||
{
|
||||
int i;
|
||||
FILE *fh = NULL;
|
||||
@@ -275,7 +275,11 @@ XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_pat
|
||||
return -1;
|
||||
}
|
||||
|
||||
fh = fopen(file_path, "a+");
|
||||
if (bAppend)
|
||||
fh = fopen(file_path, "a+");
|
||||
else
|
||||
fh = fopen(file_path, "w+");
|
||||
|
||||
if (fh == NULL){
|
||||
strcpy(ctx->_error, "open file error");
|
||||
pthread_mutex_unlock(&ctx->_mutext);
|
||||
|
||||
@@ -90,7 +90,7 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receive_callback rev, int
|
||||
* append a log data receiver, return 0 if success.
|
||||
* the log data will be writed to file.
|
||||
*/
|
||||
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index);
|
||||
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index, int bAppend);
|
||||
|
||||
/**
|
||||
* remove a log data receiver,return 0 if success.
|
||||
|
||||
Reference in New Issue
Block a user