Skip to content

Commit

Permalink
refactor: Optimize project global module[564802]
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Jan 29, 2022
1 parent fe087aa commit 8e03779
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
20 changes: 13 additions & 7 deletions TTKCommon/ttkglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,21 @@ Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) { return t; }
# endif
#endif

//
#define TTK_DECLARE_MODULE(Class) \
public: \
inline static QString className() \
{ \
return #Class; \
// disable copy
#define TTK_DISABLE_COPY(Class) \
private: \
Class(const Class &) TTK_DELETE; \
Class &operator=(const Class &) TTK_DELETE;

// make class name
#define TTK_DECLARE_MODULE(Class) \
public: \
inline static QString className() \
{ \
return #Class; \
}

//
// marco str cat
#ifndef _MSC_VER
// gcc version less than 3.4.0
# if __GNUC__ <= 3 && __GNUC_MINOR__ <= 4
Expand Down
2 changes: 1 addition & 1 deletion TTKCommon/ttkprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class TTK_MODULE_EXPORT TTKPrivateInterface

private:
TTKPrivate<PUB>* m_dptr;
Q_DISABLE_COPY(TTKPrivateInterface)
TTK_DISABLE_COPY(TTKPrivateInterface)

};

Expand Down
2 changes: 1 addition & 1 deletion TTKCommon/ttksingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TTK_MODULE_EXPORT TTKSingleton

static QMutex m_mutex;
static QScopedPointer<T> m_instance;
Q_DISABLE_COPY(TTKSingleton)
TTK_DISABLE_COPY(TTKSingleton)

};

Expand Down
33 changes: 24 additions & 9 deletions TTKThirdParty/TTKDumper/minidumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@

LPCWSTR MiniDumper::m_appName;
LPWSTR MiniDumper::m_appVersion;
LPWSTR MiniDumper::m_appBuildNumber;
LPWSTR MiniDumper::m_dumpFilePath;

#define MAX_DUMP_FILE_NUMBER 9999

MiniDumper::MiniDumper(LPCWSTR name, LPCWSTR version, LPCWSTR number)
MiniDumper::MiniDumper(LPCWSTR name, LPCWSTR version)
{
m_appName = name ? wcsdup(name) : wcsdup(L"TTK");
m_appVersion = version ? wcsdup(version) : wcsdup(L"1.0.0.0");
m_appBuildNumber = number ? wcsdup(number) : wcsdup(L"0000");
m_dumpFilePath = nullptr;

::SetUnhandledExceptionFilter(TopLevelFilter);
}

Expand Down Expand Up @@ -92,8 +90,6 @@ LONG MiniDumper::TopLevelFilter(EXCEPTION_POINTERS *info)
wcscat(dumpPath, m_appName);
wcscat(dumpPath, L"_");
wcscat(dumpPath, m_appVersion);
wcscat(dumpPath, L"_");
wcscat(dumpPath, m_appBuildNumber);
wcscat(dumpPath, fileNumber);
wcscat(dumpPath, L".dmp");

Expand Down Expand Up @@ -142,15 +138,34 @@ LONG MiniDumper::TopLevelFilter(EXCEPTION_POINTERS *info)

#elif defined Q_OS_UNIX
#include <signal.h>
#include <execinfo.h>
#include <unistd.h>
#include <fcntl.h>

void errorHandler(int type)
static QString GlobalAppName;

static void errorHandler(int id)
{
TTK_LOGGER_INFO("Error Type " << type);
TTK_LOGGER_INFO("App error occurred, error code " << id);

char stamp[50];
sprintf(stamp, "%ld", time(nullptr));
const std::string& file_name = GlobalAppName.toStdString() + "." + stamp + ".dmp";

const int size = 512;
void* array[size];
const int fd = open(file_name.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
backtrace_symbols_fd(array, backtrace(array, size), fd);
close(fd);

raise(id);
exit(0);
}

MiniDumper::MiniDumper()
MiniDumper::MiniDumper(const QString &name, const QString &version)
{
GlobalAppName = name + '_' + version;

signal(SIGPIPE, errorHandler);
signal(SIGSEGV, errorHandler);
signal(SIGFPE, errorHandler);
Expand Down
6 changes: 3 additions & 3 deletions TTKThirdParty/TTKDumper/minidumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hF
class TTK_MODULE_EXPORT MiniDumper
{
public:
MiniDumper(LPCWSTR name, LPCWSTR version, LPCWSTR number = nullptr);
MiniDumper(LPCWSTR name, LPCWSTR version);

private:
static LPCWSTR m_appName;
static LPWSTR m_appVersion;
static LPWSTR m_appBuildNumber;
static LPWSTR m_dumpFilePath;

static LONG WINAPI TopLevelFilter(EXCEPTION_POINTERS *info);

};
Expand All @@ -38,7 +38,7 @@ class TTK_MODULE_EXPORT MiniDumper
class TTK_MODULE_EXPORT MiniDumper
{
public:
MiniDumper();
MiniDumper(const QString &name, const QString &version);

};

Expand Down
2 changes: 1 addition & 1 deletion TTKThirdParty/TTKDumper/ttkdumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TTKDumper::TTKDumper()
#ifdef Q_OS_WIN
m_dump = new MiniDumper(L"TTK", DOWNLOAD_VERSION_WSTR);
#elif defined Q_OS_UNIX
m_dump = new MiniDumper();
m_dump = new MiniDumper("TTK", DOWNLOAD_VERSION_STR);
#endif
}

Expand Down

0 comments on commit 8e03779

Please sign in to comment.