Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update documentation #60

Merged
merged 4 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HeartTests/units/abstractnodetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class TestingClient: public QH::AbstractNode {
return _ping;
}

NodeType nodeType() const override {
return NodeType::Node;
};

protected slots:
void receivePing(const QSharedPointer<QH::PKG::Ping>& ping) override {
_ping = *ping;
Expand Down
4 changes: 4 additions & 0 deletions HeartTests/units/bigdatatest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class TestingClientBigData: public QH::AbstractNode {
_parser = addApiParser<BigDataTestParser>();
}

NodeType nodeType() const override {
return NodeType::Node;
};

const QSharedPointer<QH::iParser>& parser() const {
return _parser;
}
Expand Down
6 changes: 6 additions & 0 deletions HeartTests/units/shedullertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class ShedullerestNode: public QH::AbstractNode {
public:
quint64 executedTime = 0;


// AbstractNode interface
public:
NodeType nodeType() const override {
return NodeType::Node;
};
};

class TestTask: public QH::AbstractTask {
Expand Down
159 changes: 75 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,7 @@ This library consists of two levels (AbstractNode level and DataBaseNode level).
- [X] Support ssl sockets
- [X] Support initialize database
- [X] Support work in database
- [ ] Support decentralized network mode

### AbstractNode level (0)
#### Description
The AbstractNode level implement only base functions of create a new work threads and parsing packages.
For more information see QuasarApp Heart documentation, QH namespace.

### DataBaseNode level (1)
#### Description
The DataBaseNode level implement methods and packages for work with databases. This level using Qt classes for wrking with database, so for more information about suport databases see [Qt Documentation](https://doc.qt.io/qt-5/sql-driver.html).

### NetworkNode level (2)
#### Description
This level is still in develop.

## Build and Include
### For cmake projects
Expand All @@ -32,13 +19,11 @@ This level is still in develop.
* git submodule add /~https://github.com/QuasarApp/Heart.git # add the repository of Heart into your repo like submodule
* git submodule update --init --recursive
* Include in your CMakeLists.txt file the main CMakeLists.txt file of Heart library
``` cmake

```cmake
add_subdirectory(Heart)
```
* select requiriment build level for you project
```
set(HEART_BUILD_LVL 2)
```

where 1 - is code of build level

1 - AbstractNode
Expand All @@ -57,6 +42,7 @@ This level is still in develop.
## Usage

Create a own package class and override some basic methods.

```cpp

class MyPackage: public QH::AbstractData
Expand All @@ -67,105 +53,110 @@ public:
// override this method for validation your package class
bool isValid() const {
return AbstractData::isValid();
}; /
};

// your data for for server of client
std::string _data = "";

protected:
// StreamBase interface override this methods for serialization your package
QDataStream &fromStream(QDataStream &stream) {
AbstractData::fromStream(stream);
stream >> _data;
return stream;
}
QDataStream &toStream(QDataStream &stream) const {
AbstractData::toStream(stream);
stream << _data;
return stream;
}

};
```

Create a server class and override parsePackage method for work with packages.
Create your parser api class.

```cpp
*
* class MyParser: public QH::iParser {
public:
MyParser(QH::AbstractNode* parentNode): QH::iParser(parentNode) {
registerPackageType<MyPackage>();
data = new BigPackage();
}

// iParser interface
public:

// override this method for processed received data.
ParserResult parsePackage(const Package &pkg,
const AbstractNodeInfo *sender) {

auto parentResult = AbstractNode::parsePackage(pkg, sender);
if (parentResult != ParserResult::NotProcessed) {
return parentResult;
}

auto result = commandHandler<MyPackage>(this, &MyClass::processMyPackage, pkg, sender, pkgHeader);
if (result != QH::ParserResult::NotProcessed) {
return result;
}

return ParserResult::NotProcessed;
}

bool processMyPackage(const QSharedPointer<MyPackage> &cardrequest,
const QH::AbstractNodeInfo *sender, const QH::Header &hdr) {

BaseId requesterId = getSender(sender, &cardrequest);

if (!cardrequest.isValid()) {
badRequest(sender->networkAddress(), hdr);
return ParserResult::Error;
}

cardrequest._data = "responce for client "

// responce only for servers.
if (nodeType() == QH::AbstractNode::NodeType::Server)
sendData(cardrequest, sender->networkAddress(), &pkg.hdr);

return ParserResult::Processed;
}

// This vesion of the parser (any digital value.) .
int version() const override {return 0;};
QString parserId() const override {return "MyParser";};

};
```

Create a server class and add supported parsers to work with packages.
```cpp
class TestingServer: public QH::AbstractNode {
Q_OBJECT
Q_OBJECT
public:
TestingServer() {
registerPackageType<MyPackage>();
}

protected:
// override this method for processed received data.
ParserResult parsePackage(const Package &pkg,
const AbstractNodeInfo *sender) {

auto parentResult = AbstractNode::parsePackage(pkg, sender);
if (parentResult != ParserResult::NotProcessed) {
return parentResult;
}

auto result = commandHandler<MyPackage>(this, &MyClass::processMyPackage, pkg, sender, pkgHeader);
if (result != QH::ParserResult::NotProcessed) {
return result;
}

return ParserResult::NotProcessed;
addApiParser<MyParser>();
}

bool processMyPackage(const QSharedPointer<MyPackage> &cardrequest,
const QH::AbstractNodeInfo *sender, const QH::Header &hdr) {

BaseId requesterId = getSender(sender, &cardrequest);

if (!cardrequest.isValid()) {
badRequest(sender->networkAddress(), hdr);
return ParserResult::Error;
}

cardrequest._data = "responce for client "

SendData(cardrequest, sender->networkAddress(), &pkg.hdr);
return ParserResult::Processed;

QH::AbstractNode::NodeType nodeType() const override {
return QH::AbstractNode::NodeType::Server;
}
};
```

Create a client class and override parsePackage method for work with packages.
Create a client class and add supported parsers to work with packages.

```cpp

class TestingClient: public QH::AbstractNode {


protected:
// parsing incoming packages
ParserResult parsePackage(const Package &pkg,
const AbstractNodeInfo *sender) {

auto parentResult = AbstractNode::parsePackage(pkg, sender);
if (parentResult != ParserResult::NotProcessed) {
return parentResult;
}

if (MyPackage::command() == pkg.hdr.command) {
MyPackage obj(pkg);

// print responce of server
std::cout << obj._data;
...
return ParserResult::Processed;
}
// Do not forget return status of parsing packages
return ParserResult::NotProcessed;

public:
TestingClient() {
addApiParser<MyParser>();
}
// sending request to server
bool sendMyPackage() {
Ping cmd;
return sendData(&cmd, address);

QH::AbstractNode::NodeType nodeType() const override {
return QH::AbstractNode::NodeType::Client;
}
};
```
Expand Down
Loading