diff --git a/MeoAssistance/include/AsstDef.h b/MeoAssistance/include/AsstDef.h index fc8b7013b4..67dd37915e 100644 --- a/MeoAssistance/include/AsstDef.h +++ b/MeoAssistance/include/AsstDef.h @@ -5,10 +5,14 @@ #include #include #include +#include #include #include namespace asst { + + /************ Type ************/ + enum class HandleType { Window = 1, @@ -23,7 +27,7 @@ namespace asst { int x = 0; int y = 0; }; - const static std::string Version = "release.alpha.12"; + const static std::string Version = "release.alpha.13"; struct Rect { @@ -46,6 +50,8 @@ namespace asst { int height = 0; }; + /************ Static Function ************/ + static std::string GetCurrentDir() { static std::string cur_dir; @@ -63,6 +69,20 @@ namespace asst { return res_dir; } + static std::string replace_all_distinct(const std::string& src, const std::string& old_value, const std::string& new_value) + { + std::string str = src; + for (std::string::size_type pos(0); pos != std::string::npos; pos += new_value.length()) { + if ((pos = str.find(old_value, pos)) != std::string::npos) + str.replace(pos, old_value.length(), new_value); + else + break; + } + return str; + } + + /************ Print and Log Trace ************/ + inline void StreamArgs(std::ostream& os) { os << std::endl; @@ -79,7 +99,7 @@ namespace asst { static std::mutex trace_mutex; std::unique_lock trace_lock(trace_mutex); #ifdef _DEBUG - auto & out_stream = std::cout; + auto& out_stream = std::cout; #else std::ofstream out_stream(GetCurrentDir() + "asst.log", std::ios::out | std::ios::app); #endif @@ -113,15 +133,25 @@ namespace asst { DebugPrint("ERR", std::forward(args)...); } - static std::string replace_all_distinct(const std::string& src, const std::string& old_value, const std::string& new_value) - { - std::string str = src; - for (std::string::size_type pos(0); pos != std::string::npos; pos += new_value.length()) { - if ((pos = str.find(old_value, pos)) != std::string::npos) - str.replace(pos, old_value.length(), new_value); - else - break; + class DebugTraceFuncAux { + public: + DebugTraceFuncAux(const std::string& func_name) + : m_func_name(func_name), + m_start_time(std::chrono::system_clock::now()) + { + DebugTrace(m_func_name, " | enter"); } - return str; - } + ~DebugTraceFuncAux() + { + auto duration = std::chrono::system_clock::now() - m_start_time; + DebugTrace(m_func_name, " | leave,", + std::chrono::duration_cast(duration).count(), "ms"); + } + private: + std::string m_func_name; + std::chrono::time_point m_start_time; + }; + +#define DebugTraceFunction DebugTraceFuncAux _func_aux(__FUNCTION__) + } \ No newline at end of file diff --git a/MeoAssistance/src/Assistance.cpp b/MeoAssistance/src/Assistance.cpp index 452c25b6ed..59d2878bf4 100644 --- a/MeoAssistance/src/Assistance.cpp +++ b/MeoAssistance/src/Assistance.cpp @@ -8,6 +8,8 @@ using namespace asst; Assistance::Assistance() { + DebugTraceFunction; + Configer::reload(); m_pIder = std::make_shared(); @@ -23,6 +25,8 @@ Assistance::Assistance() Assistance::~Assistance() { + DebugTraceFunction; + if (m_pWindow != nullptr) { m_pWindow->showWindow(); } @@ -38,6 +42,8 @@ Assistance::~Assistance() std::optional Assistance::setSimulator(const std::string& simulator_name) { + DebugTraceFunction; + stop(); auto create_handles = [&](const std::string& name) -> bool { @@ -77,6 +83,8 @@ std::optional Assistance::setSimulator(const std::string& simulator void Assistance::start(const std::string& task) { + DebugTraceFunction; + if (m_thread_running || !m_inited) { return; } @@ -93,6 +101,8 @@ void Assistance::start(const std::string& task) void Assistance::stop(bool block) { + DebugTraceFunction; + std::unique_lock lock; if (block) { // Íⲿµ÷Óà lock = std::unique_lock(m_mutex); @@ -105,16 +115,22 @@ void Assistance::stop(bool block) bool Assistance::setParam(const std::string& type, const std::string& param, const std::string& value) { + DebugTraceFunction; + return Configer::setParam(type, param, value); } std::optional Assistance::getParam(const std::string& type, const std::string& param) { + DebugTraceFunction; + return Configer::getParam(type, param); } void Assistance::workingProc(Assistance* pThis) { + DebugTraceFunction; + while (!pThis->m_thread_exit) { std::unique_lock lock(pThis->m_mutex); if (pThis->m_thread_running) {