mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-05-12 09:29:41 +00:00
begin write documentation
This commit is contained in:
parent
ac0985b66b
commit
107a9510b9
148
Heart/heart.h
148
Heart/heart.h
@ -9,15 +9,155 @@
|
||||
#define NETWORKPROTOCOL_H
|
||||
|
||||
#include "package.h"
|
||||
#if HEART_BUILD_LVL >= 0
|
||||
#include "abstractnode.h"
|
||||
#endif
|
||||
|
||||
#if HEART_BUILD_LVL >= 1
|
||||
#include "databasenode.h"
|
||||
#endif
|
||||
|
||||
#if HEART_BUILD_LVL >= 2
|
||||
#include "networknode.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* QH - Network protocol
|
||||
* defirent values:
|
||||
* SP - shared pointer
|
||||
* WP - weak pointer
|
||||
* @brief The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart library.
|
||||
* Usage:
|
||||
* 1. First one you need to create a package for transporting data betwin server and client. For this you need to do Inheritance with the
|
||||
* QF::PKG::AbstrcatData class. So You need to override 2 serialization methods of AbstrcatData and method copyFrom.
|
||||
* Example package for transporting text data.
|
||||
* \code{cpp}
|
||||
class MyPackage: public QH::AbstractData
|
||||
{
|
||||
public:
|
||||
MyPackage();
|
||||
|
||||
// constructor for create object from package
|
||||
MyPackage(const Package& from): QH::AbstractData(from) {
|
||||
|
||||
};
|
||||
|
||||
// override this method for validation your package class
|
||||
bool isValid() const {
|
||||
return AbstractData::isValid();
|
||||
}; /
|
||||
// override this method for copy object data from other to this object
|
||||
bool copyFrom(const AbstractData *other) {
|
||||
if (!AbstractData::copyFrom(other))
|
||||
return false;
|
||||
|
||||
auto otherObject = dynamic_cast<const MyPackage*>(other);
|
||||
if (!otherObject)
|
||||
return false;
|
||||
|
||||
this->_data = otherObject->_data;
|
||||
return true;
|
||||
};
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
};
|
||||
* \endcode
|
||||
* @note The method copyFrom is not nicessery method so yo can be skip it.
|
||||
* 2. You need to create a Server class. For this you need to do Inheritance with the QF::AbstrcatData class
|
||||
* Example:
|
||||
* \code{cpp}
|
||||
class TestingServer: public QH::AbstractNode {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (H_16<MyPackage>() == pkg.hdr.command) {
|
||||
MyPackage obj(pkg);
|
||||
|
||||
BaseId requesterId = getSender(sender, &obj);
|
||||
|
||||
if (!obj.isValid()) {
|
||||
badRequest(sender->networkAddress(), pkg.hdr);
|
||||
return ParserResult::Error;
|
||||
}
|
||||
|
||||
obj._data = "responce for client "
|
||||
|
||||
SendData(&obj, sender->networkAddress(), &pkg.hdr);
|
||||
return ParserResult::Processed;
|
||||
}
|
||||
return ParserResult::NotProcessed;
|
||||
|
||||
}
|
||||
};
|
||||
* \endcode
|
||||
* This is simple echo server for our client - server application.
|
||||
* For Run this serve use method QF::AbstrcatData::run
|
||||
*
|
||||
* \code{cpp}
|
||||
int main () {
|
||||
TestingServer testServer();
|
||||
testServer.run("127.0.0.1", 7777)
|
||||
}
|
||||
\endcode
|
||||
* 3. Create a client application class.
|
||||
* Client and server must be inheritance from QF::AbstrcatData class for support parsing packages.
|
||||
* \code{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 (H_16<MyPackage>() == 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;
|
||||
|
||||
}
|
||||
// sending request to server
|
||||
bool sendMyPackage() {
|
||||
Ping cmd;
|
||||
return sendData(&cmd, address);
|
||||
}
|
||||
};
|
||||
* \endcode
|
||||
*/
|
||||
namespace QH {
|
||||
namespace PKG {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // NETWORKPROTOCOL_H
|
||||
|
14
doxygen.conf
14
doxygen.conf
@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
|
||||
# title of most generated pages and in a few other places.
|
||||
# The default value is: My Project.
|
||||
|
||||
PROJECT_NAME = NetworkProtocol
|
||||
PROJECT_NAME = Heart
|
||||
|
||||
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
@ -703,7 +703,7 @@ FILE_VERSION_FILTER =
|
||||
# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
|
||||
# tag is left empty.
|
||||
|
||||
LAYOUT_FILE = NetworkProtocol/Qt-Secret/res/DoxyStyle/DoxygenLayout.xml
|
||||
LAYOUT_FILE = Heart/Qt-Secret/res/DoxyStyle/DoxygenLayout.xml
|
||||
|
||||
# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
|
||||
# the reference definitions. This must be a list of .bib files. The .bib
|
||||
@ -790,7 +790,7 @@ WARN_LOGFILE =
|
||||
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
INPUT = ./NetworkProtocol \
|
||||
INPUT = ./Heart \
|
||||
./Doc
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
@ -874,8 +874,8 @@ RECURSIVE = YES
|
||||
# Note that relative paths are relative to the directory from which doxygen is
|
||||
# run.
|
||||
|
||||
EXCLUDE = ./NetworkProtocol/Qt-Secret \
|
||||
./NetworkProtocol/CMakeFiles
|
||||
EXCLUDE = ./Heart/Qt-Secret \
|
||||
./Heart/CMakeFiles
|
||||
|
||||
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
|
||||
# directories that are symbolic links (a Unix file system feature) are excluded
|
||||
@ -1194,7 +1194,7 @@ HTML_STYLESHEET =
|
||||
# list). For an example see the documentation.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
HTML_EXTRA_STYLESHEET = NetworkProtocol/Qt-Secret/res/DoxyStyle/doxygenStyles.css
|
||||
HTML_EXTRA_STYLESHEET = Heart/Qt-Secret/res/DoxyStyle/doxygenStyles.css
|
||||
|
||||
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
|
||||
# other source files which should be copied to the HTML output directory. Note
|
||||
@ -1452,7 +1452,7 @@ GENERATE_ECLIPSEHELP = NO
|
||||
# The default value is: org.doxygen.Project.
|
||||
# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
|
||||
|
||||
ECLIPSE_DOC_ID = QuasarApp.NetworkProtocol
|
||||
ECLIPSE_DOC_ID = QuasarApp.Heart
|
||||
|
||||
# If you want full control over the layout of the generated HTML pages it might
|
||||
# be necessary to disable the index and replace it with your own. The
|
||||
|
Loading…
x
Reference in New Issue
Block a user