Heart/NetworkProtocol/basenode.h

135 lines
3.3 KiB
C
Raw Normal View History

2019-10-21 18:09:25 +03:00
#ifndef BASENODE_H
#define BASENODE_H
#include "abstractnode.h"
2019-11-07 16:13:56 +03:00
#include <dbobject.h>
2019-11-09 13:49:14 +03:00
namespace NetworkProtocol {
2019-10-21 18:09:25 +03:00
2019-10-29 18:31:01 +03:00
class SqlDBCache;
class SqlDBWriter;
2019-11-07 20:49:06 +03:00
class UserData;
2019-11-02 20:38:13 +03:00
class UserDataRequest;
2019-10-29 18:31:01 +03:00
2019-10-21 18:09:25 +03:00
/**
* @brief The BaseNode class - base inplementation of nodes
*/
class BaseNode : public AbstractNode
{
Q_OBJECT
public:
/**
* @brief BaseNode
* @param mode
* @param ptr
*/
BaseNode(SslMode mode = SslMode::NoSSL, QObject * ptr = nullptr);
2019-10-29 18:31:01 +03:00
/**
2019-10-31 18:15:20 +03:00
* @brief intSqlDb - this function init database of node
* @param DBparamsFile - path to json file with all patarams
* @param cache - new SqlDBCache object
* @param writer - new SqlDBWriter
* @return true if all good
2019-10-29 18:31:01 +03:00
*/
2019-10-31 18:15:20 +03:00
virtual bool intSqlDb( QString DBparamsFile,
SqlDBCache * cache = nullptr,
SqlDBWriter* writer = nullptr);
/**
* params it is map of data base params if it option is empty then params get from defaultDbParams function
*/
virtual bool intSqlDb( QVariantMap params = {},
2019-10-29 18:31:01 +03:00
SqlDBCache * cache = nullptr,
SqlDBWriter* writer = nullptr);
/**
* @brief isSqlInited
* @return return true if intSqlDb invocked correctly;
*/
bool isSqlInited() const;
/**
* @brief run server on address an port
* @param addres
* @param port
* @return recomendet befor invoke this method call the intSqlDb.
* If you skeap a call of intSqlDb method then data base inited with default parameters.
*/
bool run(const QString &addres, unsigned short port) override;
~BaseNode() override;
2019-10-31 18:15:20 +03:00
/**
* @brief defaultDbParams
* @return
*/
virtual QVariantMap defaultDbParams() const;
2019-11-02 20:38:13 +03:00
signals:
2019-11-08 20:12:31 +03:00
void incomingData(QSharedPointer<AbstractData> pkg,
const QHostAddress& sender);
2019-11-07 20:49:06 +03:00
void requestError(QString msg);
2019-11-02 20:38:13 +03:00
2019-10-30 17:58:38 +03:00
protected:
2019-10-31 18:15:20 +03:00
/**
* @brief initDefaultDbObjects create default cache and db writer if pointer is null
* @param cache
* @param writer
*/
void initDefaultDbObjects(SqlDBCache *cache, SqlDBWriter *writer);
2019-10-30 17:58:38 +03:00
2019-11-02 20:38:13 +03:00
/**
* @brief parsePackage
* @param pkg
* @param sender
* @return
*/
bool parsePackage(const Package &pkg, QWeakPointer<AbstractNodeInfo> sender) override;
/**
* @brief workWithUserRequest
* @return
*/
2019-11-07 20:49:06 +03:00
virtual bool workWithUserRequest(QWeakPointer<UserDataRequest>,
const QHostAddress &addere,
2019-11-02 20:38:13 +03:00
const Header *rHeader = nullptr);
2019-11-04 17:51:35 +03:00
/**
* @brief registerNewUser
* @param user
2019-11-07 16:13:56 +03:00
* @param address
2019-11-04 17:51:35 +03:00
* @return
*/
2019-11-07 16:13:56 +03:00
bool registerNewUser(QWeakPointer<UserDataRequest> user, const QHostAddress& address);
2019-11-04 17:51:35 +03:00
/**
* @brief loginUser
* @param user
2019-11-07 16:13:56 +03:00
* @param address
2019-11-04 17:51:35 +03:00
* @return
*/
2019-11-07 16:13:56 +03:00
bool loginUser(const QWeakPointer<UserDataRequest> &user,
const QWeakPointer<DBObject>& userdb,
const QHostAddress& address);
2019-11-04 17:51:35 +03:00
2019-11-03 16:03:00 +03:00
/**
* @brief hashgenerator
* @param pass
*/
virtual QString hashgenerator(const QByteArray &pass);
2019-11-02 20:38:13 +03:00
QSharedPointer<AbstractNodeInfo> createNodeInfo(QAbstractSocket *socket) const override;
2019-10-29 18:31:01 +03:00
private:
2019-10-31 18:15:20 +03:00
QSharedPointer<SqlDBCache> _db;
2019-10-21 18:09:25 +03:00
};
}
#endif // BASENODE_H