添加项目文件。
This commit is contained in:
58
BreakPad/QBreakpadHandler.h
Normal file
58
BreakPad/QBreakpadHandler.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Aleksey Palazhchenko
|
||||
* Copyright (C) 2014 Sergey Shambir
|
||||
* Copyright (C) 2016 Alexander Makarov
|
||||
*
|
||||
* This file is a part of Breakpad-qt library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QBREAKPAD_HANDLER_H
|
||||
#define QBREAKPAD_HANDLER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include "singletone/singleton.h"
|
||||
|
||||
namespace google_breakpad {
|
||||
class ExceptionHandler;
|
||||
class MinidumpDescriptor;
|
||||
}
|
||||
|
||||
class QBreakpadHandlerPrivate;
|
||||
|
||||
class QBreakpadHandler: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static QString version();
|
||||
|
||||
QBreakpadHandler();
|
||||
~QBreakpadHandler();
|
||||
|
||||
QString uploadUrl() const;
|
||||
QString dumpPath() const;
|
||||
QStringList dumpFileList() const;
|
||||
|
||||
void setDumpPath(const QString& path);
|
||||
void setUploadUrl(const QUrl& url);
|
||||
|
||||
public slots:
|
||||
void sendDumps();
|
||||
|
||||
private:
|
||||
QBreakpadHandlerPrivate* d;
|
||||
};
|
||||
#define QBreakpadInstance Singleton<QBreakpadHandler>::instance()
|
||||
|
||||
#endif // QBREAKPAD_HANDLER_H
|
63
BreakPad/QBreakpadHttpUploader.h
Normal file
63
BreakPad/QBreakpadHttpUploader.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Aleksey Palazhchenko
|
||||
* Copyright (C) 2014 Sergey Shambir
|
||||
* Copyright (C) 2016 Alexander Makarov
|
||||
*
|
||||
* This file is a part of Breakpad-qt library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QBREAKPAD_HTTP_SENDER_H
|
||||
#define QBREAKPAD_HTTP_SENDER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
class QString;
|
||||
class QUrl;
|
||||
class QFile;
|
||||
|
||||
class QBreakpadHttpUploader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QBreakpadHttpUploader(QObject *parent=0);
|
||||
QBreakpadHttpUploader(const QUrl& url, QObject *parent=0);
|
||||
~QBreakpadHttpUploader();
|
||||
|
||||
//TODO: proxy, ssl
|
||||
QString remoteUrl() const;
|
||||
void setUrl(const QUrl& url);
|
||||
|
||||
signals:
|
||||
void finished(QString answer);
|
||||
|
||||
public slots:
|
||||
void uploadDump(const QString& abs_file_path);
|
||||
|
||||
private slots:
|
||||
void onUploadProgress(qint64 sent, qint64 total);
|
||||
void onError(QNetworkReply::NetworkError err);
|
||||
void onUploadFinished();
|
||||
|
||||
private:
|
||||
QNetworkAccessManager m_manager;
|
||||
QNetworkRequest m_request;
|
||||
QPointer<QNetworkReply> m_reply;
|
||||
QFile* m_file;
|
||||
};
|
||||
|
||||
#endif // QBREAKPAD_HTTP_SENDER_H
|
81
BreakPad/singletone/call_once.h
Normal file
81
BreakPad/singletone/call_once.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Alexander Makarov
|
||||
*
|
||||
* Source:
|
||||
* https://wiki.qt.io/Qt_thread-safe_singleton
|
||||
*
|
||||
* This file is a part of Breakpad-qt library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CALL_ONCE
|
||||
#define CALL_ONCE
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QAtomicInt>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#include <QThreadStorage>
|
||||
#include <QThread>
|
||||
|
||||
namespace CallOnce {
|
||||
enum ECallOnce {
|
||||
CO_Request,
|
||||
CO_InProgress,
|
||||
CO_Finished
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(QThreadStorage<QAtomicInt*>, once_flag)
|
||||
}
|
||||
|
||||
template <class Function>
|
||||
inline static void qCallOnce(Function func, QBasicAtomicInt& flag)
|
||||
{
|
||||
using namespace CallOnce;
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
int protectFlag = flag.fetchAndStoreAcquire(flag);
|
||||
#elif QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
int protectFlag = flag.fetchAndStoreAcquire(flag.loadRelaxed());
|
||||
#else
|
||||
int protectFlag = flag.fetchAndStoreAcquire(flag.load());
|
||||
#endif
|
||||
|
||||
if (protectFlag == CO_Finished)
|
||||
return;
|
||||
if (protectFlag == CO_Request && flag.testAndSetRelaxed(protectFlag,
|
||||
CO_InProgress)) {
|
||||
func();
|
||||
flag.fetchAndStoreRelease(CO_Finished);
|
||||
}
|
||||
else {
|
||||
do {
|
||||
QThread::yieldCurrentThread();
|
||||
}
|
||||
while (!flag.testAndSetAcquire(CO_Finished, CO_Finished));
|
||||
}
|
||||
}
|
||||
|
||||
template <class Function>
|
||||
inline static void qCallOncePerThread(Function func)
|
||||
{
|
||||
using namespace CallOnce;
|
||||
if (!once_flag()->hasLocalData()) {
|
||||
once_flag()->setLocalData(new QAtomicInt(CO_Request));
|
||||
qCallOnce(func, *once_flag()->localData());
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CALL_ONCE
|
||||
|
56
BreakPad/singletone/singleton.h
Normal file
56
BreakPad/singletone/singleton.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Alexander Makarov
|
||||
*
|
||||
* Source:
|
||||
* https://wiki.qt.io/Qt_thread-safe_singleton
|
||||
*
|
||||
* This file is a part of Breakpad-qt library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SINGLETON
|
||||
#define SINGLETON
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QScopedPointer>
|
||||
#include "call_once.h"
|
||||
|
||||
template <class T>
|
||||
class Singleton
|
||||
{
|
||||
public:
|
||||
static T& instance()
|
||||
{
|
||||
qCallOnce(init, flag);
|
||||
return *tptr;
|
||||
}
|
||||
|
||||
static void init()
|
||||
{
|
||||
tptr.reset(new T);
|
||||
}
|
||||
|
||||
private:
|
||||
Singleton() {}
|
||||
~Singleton() {}
|
||||
Q_DISABLE_COPY(Singleton)
|
||||
|
||||
static QScopedPointer<T> tptr;
|
||||
static QBasicAtomicInt flag;
|
||||
};
|
||||
|
||||
template<class T> QScopedPointer<T> Singleton<T>::tptr(0);
|
||||
template<class T> QBasicAtomicInt Singleton<T>::flag = Q_BASIC_ATOMIC_INITIALIZER(CallOnce::CO_Request);
|
||||
|
||||
#endif // SINGLETON
|
||||
|
Reference in New Issue
Block a user