added base copy operator for the QDataSteamObjects

This commit is contained in:
Andrei Yankovich 2021-01-15 19:08:30 +03:00
parent 313fd29c05
commit a3afbb8167
4 changed files with 38 additions and 8 deletions

View File

@ -31,6 +31,9 @@ AbstractNode::AbstractNode( QObject *ptr):
QTcpServer(ptr) {
_dataSender = new DataSender();
_threadPool = new QThreadPool(this);
_threadPool->setMaxThreadCount(QThread::idealThreadCount());
_threadPool->setObjectName("PackageWorker");
}
bool AbstractNode::run(const QString &addres, unsigned short port) {
@ -134,17 +137,19 @@ bool AbstractNode::connectToHost(const QString &domain, unsigned short port, Ssl
return;
}
if (info.addresses().size() > 1) {
auto addresses = info.addresses();
if (addresses.size() > 1) {
QuasarAppUtils::Params::log("The domain name :" + domain + " has more 1 ip addresses.",
QuasarAppUtils::Warning);
}
if (!connectToHost(HostAddress{info.addresses().first(), port}, mode)) {
if (!connectToHost(HostAddress{addresses.first(), port}, mode)) {
return;
}
auto hostObject = getInfoPtr(HostAddress{info.addresses().first(), port});
auto hostObject = getInfoPtr(HostAddress{addresses.first(), port});
if (!hostObject) {
QuasarAppUtils::Params::log("The domain name :" + domain + " has connected bud not have network object!",
@ -191,8 +196,6 @@ HostAddress AbstractNode::address() const {
}
AbstractNode::~AbstractNode() {
// delete _nodeKeys;
stop();
}
QSslConfiguration AbstractNode::getSslConfig() const {
@ -892,7 +895,7 @@ void AbstractNode::newWork(const Package &pkg, const AbstractNodeInfo *sender,
};
auto worker = new QFutureWatcher <bool>();
worker->setFuture(QtConcurrent::run(executeObject));
worker->setFuture(QtConcurrent::run(_threadPool, executeObject));
_workers.insert(worker);
connect(worker, &QFutureWatcher<bool>::finished,
@ -977,6 +980,10 @@ AbstractNode::takeFromQueue(const HostAddress &node,
return list;
}
void AbstractNode::prepareForDelete() {
stop();
}
void AbstractNode::nodeStatusChanged(const HostAddress &node, NodeCoonectionStatus status) {
auto list = takeFromQueue(node, status);

View File

@ -16,7 +16,9 @@
#include <QMutex>
#include <QSslConfiguration>
#include <QTcpServer>
#include <QThreadPool>
#include <QTimer>
#include <softdelete.h>
#include "abstractdata.h"
#include "workstate.h"
#include "package.h"
@ -91,7 +93,7 @@ class Abstract;
* and work with crypto method for crease a security connections betwin nodes.
* AbstractNode - is thread save class
*/
class HEARTSHARED_EXPORT AbstractNode : public QTcpServer
class HEARTSHARED_EXPORT AbstractNode : public QTcpServer, public SoftDelete
{
Q_OBJECT
@ -505,6 +507,10 @@ protected:
*/
QList<std::function<void ()>> takeFromQueue(const HostAddress& node,
NodeCoonectionStatus triggerStatus);
void prepareForDelete() override;
private slots:
void avelableBytes();
@ -571,8 +577,9 @@ private:
mutable QMutex _actionCacheMutex;
mutable QMutex _confirmNodeMutex;
friend class WebSocketController;
QThreadPool *_threadPool = nullptr;
friend class WebSocketController;
};

View File

@ -34,6 +34,15 @@ QByteArray StreamBase::toBytes() const {
return res;
}
StreamBase &StreamBase::operator=(const StreamBase &righ) {
QByteArray res;
QDataStream stream(&res, QIODevice::WriteOnly);
righ.toStream(stream);
toStream(stream);
return *this;
}
QDataStream &operator<<(QDataStream &stream, const StreamBase &obj) {
return (&obj)->toStream(stream);
}

View File

@ -57,6 +57,13 @@ public:
*/
friend QDataStream& operator>> (QDataStream& stream, StreamBase& obj);
/**
* @brief operator = This is base copy operator for all StreamBase structures.
* Default implementation it is copy from byteArray.
* @param righ input data object.
* @return return lvalue link to object.
*/
StreamBase& operator=(const StreamBase &righ);
protected: