Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
packagemanager.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8
9#include "packagemanager.h"
10
11#include <package.h>
12#include <ctime>
13#include <config.h>
14#include <packadata.h>
15
16namespace QH {
17
22
24 for (const auto& data : std::as_const(_parseResults)) {
25 delete data;
26 }
27
28 _parseResults.clear();
29}
30
31const Package *PackageManager::getPkgFromArhive(const unsigned int &id) const {
32 if (!contains(id))
33 return nullptr;
34
35 QMutexLocker lock(&_processMutex);
36 return _parseResults.value(id)->_data;
37}
38
39bool PackageManager::contains(const unsigned int &id) const {
40 QMutexLocker lock(&_processMutex);
41 return _parseResults.contains(id);
42}
43
44void PackageManager::processed(const Package &pkg, char processResult) {
45
46 if (!pkg.hdr.hash || !PACKAGE_CACHE_SIZE) {
47 return;
48 }
49
50 QMutexLocker lock(&_processMutex);
51
52 if (_parseResults.size() > PACKAGE_CACHE_SIZE) {
53#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
54 _processTime.erase(_processTime.begin());
55#else
56 _processTime.erase(_processTime.cbegin());
57#endif
58 }
59
60 _parseResults.insert(pkg.hdr.hash, new PackaData {
61 processResult,
62 new Package(pkg)
63 });
64
65 _processTime.insert(static_cast<int>(time(nullptr)), pkg.hdr.hash);
66}
67
68}
const Package * getPkgFromArhive(const unsigned int &id) const
getPkgFromArhive This method return pointer to package from archive.
void processed(const Package &pkg, char processResult)
processed This method add a package to the archive.
bool contains(const unsigned int &id) const
contains This method checks if the package contains in this container by id.
The Package struct. This is base structure for transporting data by network between QH nodes....
Definition package.h:23
Header hdr
hdr This is header of package. For more information see the Header struct.
Definition package.h:29
#define PACKAGE_CACHE_SIZE
Definition config.h:46
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13
unsigned int hash
hash This is unique id of a package. id calc with CRC32 function for Qt implementation.
Definition header.h:38
The PackaData struct - private data of packages.
Definition packadata.h:17