From 99fd001292b4841564504d487137875e60495b8b Mon Sep 17 00:00:00 2001 From: blue Date: Sun, 5 Mar 2023 01:36:53 +0300 Subject: [PATCH] some more thinking about delay manager --- core/CMakeLists.txt | 1 + core/components/CMakeLists.txt | 2 - core/components/delaymanager.cpp | 136 -------------- core/components/delaymanager.h | 71 ------- core/delayManager/CMakeLists.txt | 22 +++ core/delayManager/cardinternal.cpp | 32 ++++ core/delayManager/cardinternal.h | 41 +++++ core/delayManager/delaymanager.cpp | 255 ++++++++++++++++++++++++++ core/delayManager/delaymanager.h | 116 ++++++++++++ core/delayManager/infoforuser.cpp | 26 +++ core/delayManager/infoforuser.h | 32 ++++ core/delayManager/job.cpp | 32 ++++ core/delayManager/job.h | 50 +++++ core/delayManager/owncardinternal.cpp | 30 +++ core/delayManager/owncardinternal.h | 35 ++++ core/delayManager/owninfoforuser.cpp | 25 +++ core/delayManager/owninfoforuser.h | 32 ++++ 17 files changed, 729 insertions(+), 209 deletions(-) delete mode 100644 core/components/delaymanager.cpp delete mode 100644 core/components/delaymanager.h create mode 100644 core/delayManager/CMakeLists.txt create mode 100644 core/delayManager/cardinternal.cpp create mode 100644 core/delayManager/cardinternal.h create mode 100644 core/delayManager/delaymanager.cpp create mode 100644 core/delayManager/delaymanager.h create mode 100644 core/delayManager/infoforuser.cpp create mode 100644 core/delayManager/infoforuser.h create mode 100644 core/delayManager/job.cpp create mode 100644 core/delayManager/job.h create mode 100644 core/delayManager/owncardinternal.cpp create mode 100644 core/delayManager/owncardinternal.h create mode 100644 core/delayManager/owninfoforuser.cpp create mode 100644 core/delayManager/owninfoforuser.h diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index b971a88..01c6d8f 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -34,3 +34,4 @@ add_subdirectory(handlers) add_subdirectory(storage) add_subdirectory(passwordStorageEngines) add_subdirectory(components) +add_subdirectory(delayManager) diff --git a/core/components/CMakeLists.txt b/core/components/CMakeLists.txt index 0e26037..b78794a 100644 --- a/core/components/CMakeLists.txt +++ b/core/components/CMakeLists.txt @@ -1,13 +1,11 @@ set(SOURCE_FILES networkaccess.cpp clientcache.cpp - delaymanager.cpp ) set(HEADER_FILES networkaccess.h clientcache.h - delaymanager.h ) target_sources(squawk PRIVATE diff --git a/core/components/delaymanager.cpp b/core/components/delaymanager.cpp deleted file mode 100644 index 627eab8..0000000 --- a/core/components/delaymanager.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// Squawk messenger. -// Copyright (C) 2019 Yury Gubich -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "delaymanager.h" - -Core::DelayManager::DelayManager(uint16_t mpj, QObject* parent) : - QObject(parent), - maxParallelJobs(mpj), - nextJobId(0), - scheduledJobs(), - runningJobs(), - pendingVCards(), - requestedVCards() -{ -} - -Core::DelayManager::~DelayManager() {} - -void Core::DelayManager::requestInfo(const QString& jid) { - bool needToRequest = false; - std::pair::const_iterator, bool> result = pendingVCards.insert(jid); - if (result.second) { //if there is a clear evidence that we have not alredy been asked to request a VCard - just request it - needToRequest = true; - } else { - std::map::const_iterator itr = requestedVCards.find(jid); - if (itr != requestedVCards.end()) { //first check if the card is already requested, and if it is make sure we reply to user after we receive it - runningJobs[itr->second].first = TaskType::infoForUser; - } else { - needToRequest = true; - for (Job& job : scheduledJobs) { //looks like we need to manually check all the scheduled job and find the one with that jid there - if (job.first == TaskType::cardInternal || job.first == TaskType::infoForUser) { //to make sure we reply to user after we receive it - QString* jobJid = static_cast(job.second); - if (*jobJid == jid) { - needToRequest = false; - job.first = TaskType::infoForUser; - break; - } - } - } - if (needToRequest) { - throw 8573; //something went terribly wrong here, the state is not correct; - } - } - } - - if (needToRequest) - scheduleJob(TaskType::infoForUser, new QString(jid)); -} - -void Core::DelayManager::requestVCard(const QString& jid) { - std::pair::const_iterator, bool> result = pendingVCards.insert(jid); - if (result.second) - scheduleJob(TaskType::cardInternal, new QString(jid)); -} - -void Core::DelayManager::scheduleJob(Core::DelayManager::TaskType type, void* data) { - if (runningJobs.size() < maxParallelJobs) { - uint16_t currentJobId = nextJobId++; - runningJobs.emplace(currentJobId, std::make_pair(type, data)); - switch (type) { - case TaskType::cardInternal: - case TaskType::infoForUser: { - QString* jid = static_cast(data); - requestedVCards.emplace(*jid, currentJobId); - emit requestVCard(*jid); - } - break; - } - } else { - scheduledJobs.emplace_back(type, data); - } -} - -void Core::DelayManager::executeJob(Core::DelayManager::Job job) { - uint16_t currentJobId = nextJobId++; - runningJobs.emplace(currentJobId, job); - switch (job.first) { - case TaskType::cardInternal: - case TaskType::infoForUser: { - QString* jid = static_cast(job.second); - requestedVCards.emplace(*jid, currentJobId); - emit requestVCard(*jid); - } - break; - } -} - - -void Core::DelayManager::jobIsDone(uint16_t jobId) { - std::map::const_iterator itr = runningJobs.find(jobId); - if (itr == runningJobs.end()) { - throw 8574; //not supposed to happen, never - } - runningJobs.erase(itr); - if (scheduledJobs.size() > 0) { - Job job = scheduledJobs.front(); - scheduledJobs.pop_front(); - executeJob(job); - } -} - - -void Core::DelayManager::receivedVCard(const QString& jid, const Shared::VCard& card) { - std::map::const_iterator cardItr = requestedVCards.find(jid); - if (cardItr == requestedVCards.end()) { - throw 8575; //never supposed to happen, the state is not correct; - } else { - uint16_t jobId = cardItr->second; - requestedVCards.erase(cardItr); - pendingVCards.erase(jid); - const Job& job = runningJobs[jobId]; - switch (job.first) { - case TaskType::cardInternal: - jobIsDone(jobId); - break; - case TaskType::infoForUser: - //all that stuff with further requesting - break; - default: - throw 8576; - } - } -} diff --git a/core/components/delaymanager.h b/core/components/delaymanager.h deleted file mode 100644 index f34b00e..0000000 --- a/core/components/delaymanager.h +++ /dev/null @@ -1,71 +0,0 @@ -// Squawk messenger. -// Copyright (C) 2019 Yury Gubich -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#ifndef CORE_DELAYMANAGER_H -#define CORE_DELAYMANAGER_H - -#include -#include - -#include -#include - -#include -#include - -namespace Core { - -class DelayManager : public QObject -{ - Q_OBJECT - - enum class TaskType { - cardInternal, - infoForUser - } -public: - DelayManager(uint16_t maxParallelJobs = 5, QObject* parent = nullptr); - ~DelayManager(); - - void requestVCard(const QString& jid); - void requestInfo(const QString& jid); - -signals: - void requestVCard(const QString& jid); - -public slots: - void receivedVCard(const QString& jid, const Shared::VCard& card); - -private: - typedef std::pair Job; - - void scheduleJob(TaskType type, void* data); - void executeJob(Job job); - void jobIsDone(uint16_t jobId); - -private: - uint16_t maxParallelJobs; - uint16_t nextJobId; - std::list scheduledJobs; - std::map runningJobs; - - std::set pendingVCards; - std::map requestedVCards; -}; - -} - -#endif // CORE_DELAYMANAGER_H diff --git a/core/delayManager/CMakeLists.txt b/core/delayManager/CMakeLists.txt new file mode 100644 index 0000000..f9ccb57 --- /dev/null +++ b/core/delayManager/CMakeLists.txt @@ -0,0 +1,22 @@ +set(SOURCE_FILES + delaymanager.cpp + job.cpp + cardinternal.cpp + infoforuser.cpp + owncardinternal.cpp + owninfoforuser.cpp +) + +set(HEADER_FILES + delaymanager.h + job.h + cardinternal.h + infoforuser.h + owncardinternal.h + owninfoforuser.h +) + +target_sources(squawk PRIVATE + ${SOURCE_FILES} + ${HEADER_FILES} +) diff --git a/core/delayManager/cardinternal.cpp b/core/delayManager/cardinternal.cpp new file mode 100644 index 0000000..c7a599a --- /dev/null +++ b/core/delayManager/cardinternal.cpp @@ -0,0 +1,32 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "cardinternal.h" + +Core::CardInternal::CardInternal(Job::Id p_id, const QString& p_jid) : + Job(p_id, Type::cardInternal), + jid(p_id) +{} + +Core::CardInternal::CardInternal(Job::Id p_id, const QString& p_jid, Job::Type p_type) : + Job(p_id, p_type), + jid(p_id) +{} + +Core::CardInternal::CardInternal(const Core::CardInternal& other) : + Job(other), + jid(other.jid) +{} diff --git a/core/delayManager/cardinternal.h b/core/delayManager/cardinternal.h new file mode 100644 index 0000000..a95f0ba --- /dev/null +++ b/core/delayManager/cardinternal.h @@ -0,0 +1,41 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef CORE_CARDINTERNAL_H +#define CORE_CARDINTERNAL_H + + +#include + +#include "job.h" + +namespace Core { + +class CardInternal : public Job { +protected: + CardInternal(Job::Id id, const QString& jid, Job::Type type); + +public: + CardInternal(Job::Id id, const QString& jid); + CardInternal(const CardInternal& other); + + const QString jid; + +}; + +} + +#endif // CORE_CARDINTERNAL_H diff --git a/core/delayManager/delaymanager.cpp b/core/delayManager/delaymanager.cpp new file mode 100644 index 0000000..6ebc85d --- /dev/null +++ b/core/delayManager/delaymanager.cpp @@ -0,0 +1,255 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "delaymanager.h" + +#include "cardinternal.h" +#include "infoforuser.h" +#include "owncardinternal.h" +#include "owninfoforuser.h" + +Core::DelayManager::DelayManager(Job::Id mpj, QObject* parent) : + QObject(parent), + maxParallelJobs(mpj), + nextJobId(1), + scheduledJobs(), + scheduledJobsById(scheduledJobs.get()), + jobSequence(scheduledJobs.get()), + runningJobs(), + ownVCardJobId(0), + ownInfoJobId(0), + scheduledVCards(), + requestedVCards(), + requestedBundles() +{ +} + +Core::DelayManager::~DelayManager() {} + +Core::Job::Id Core::DelayManager::getNextJobId() { + Job::Id id = nextJobId++; + if (id == 0) + id = nextJobId++; + + return id; +} + +void Core::DelayManager::getInfo(const QString& jid) { + Job* job = nullptr; +#ifdef WITH_OMEMO + std::map::const_iterator bitr = requestedBundles.find(jid); + if (bitr != requestedBundles.end()) + job = runningJobs.at(bitr->second); + else +#endif + job = getVCardJob(jid); + + if (job != nullptr) { + if (job->getType() == Job::Type::cardInternal) + replaceJob(new InfoForUser(job->id, jid)); + } else + scheduleJob(new InfoForUser(getNextJobId(), jid)); +} + +void Core::DelayManager::getOwnInfo() { + if (ownInfoJobId == 0) { + if (ownVCardJobId != 0) + replaceJob(new OwnInfoForUser(ownVCardJobId)); + else + scheduleJob(new OwnInfoForUser(getNextJobId())); + } +} + +void Core::DelayManager::getVCard(const QString& jid) { + Job* job = getVCardJob(jid); + if (job == nullptr) + scheduleJob(new CardInternal(getNextJobId(), jid)); +} + +void Core::DelayManager::getOwnVCard() { + if (ownInfoJobId == 0) + scheduleJob(new OwnCardInternal(getNextJobId())); +} + +Core::Job* Core::DelayManager::getVCardJob(const QString& jid) { + Job* job = nullptr; + std::map::const_iterator sitr = scheduledVCards.find(jid); + if (sitr == scheduledVCards.end()) { + std::map::const_iterator ritr = requestedVCards.find(jid); + if (ritr != requestedVCards.end()) + job = runningJobs.at(ritr->second); + } else { + job = *(scheduledJobsById.find(sitr->second)); + } + + return job; +} +void Core::DelayManager::preScheduleJob(Core::Job* job) { + switch (job->getType()) { + case Job::Type::cardInternal: + scheduledVCards.emplace(static_cast(job)->jid, job->id); + break; + case Job::Type::ownCardInternal: + ownVCardJobId = job->id; + break; + case Job::Type::infoForUser: + scheduledVCards.emplace(static_cast(job)->jid, job->id); + break; + case Job::Type::ownInfoForUser: + ownVCardJobId = job->id; + ownInfoJobId = job->id; + break; + } +} + +void Core::DelayManager::scheduleJob(Core::Job* job) { + preScheduleJob(job); + if (runningJobs.size() < maxParallelJobs) { + executeJob(job); + } else { + scheduledJobs.push_back(job); + } +} + +void Core::DelayManager::preExecuteJob(Core::Job* job) { + switch (job->getType()) { + case Job::Type::cardInternal: + case Job::Type::infoForUser: { + CardInternal* cij = static_cast(job); + requestedVCards.emplace(cij->jid, job->id); + scheduledVCards.erase(cij->jid); + } + break; + case Job::Type::ownInfoForUser: + case Job::Type::ownCardInternal: + break; + } +} + +void Core::DelayManager::executeJob(Core::Job* job) { + preExecuteJob(job); + runningJobs.emplace(job->id, job); + switch (job->getType()) { + case Job::Type::cardInternal: + case Job::Type::infoForUser: + emit requestVCard(static_cast(job)->jid); + break; + case Job::Type::ownInfoForUser: + case Job::Type::ownCardInternal: + emit requestOwnVCard(); + break; + } +} + +void Core::DelayManager::jobIsDone(Job::Id jobId) { + std::map::const_iterator itr = runningJobs.find(jobId); + if (itr == runningJobs.end()) { + throw 8573; //not supposed to happen, ever + } + Job* job = itr->second; + delete job; + runningJobs.erase(itr); + if (scheduledJobs.size() > 0) { + Job* job = scheduledJobs.front(); + scheduledJobs.pop_front(); + executeJob(job); + } +} + +void Core::DelayManager::replaceJob(Core::Job* job) { + preScheduleJob(job); + std::map::iterator itr = runningJobs.find(job->id); + if (itr != runningJobs.end()) { + preExecuteJob(job); + delete itr->second; + itr->second = job; + } else { + StorageById::iterator sitr = scheduledJobsById.find(job->id); + if (sitr != scheduledJobsById.end()) { + delete *(sitr); + scheduledJobsById.replace(sitr, job); + } else { + throw 8574; //not supposed to happen, ever + } + } +} + +void Core::DelayManager::receivedVCard(const QString& jid, const Shared::VCard& card) { + std::map::const_iterator cardItr = requestedVCards.find(jid); + if (cardItr == requestedVCards.end()) { + throw 8575; //never supposed to happen, the state is not correct; + } else { + Job::Id jobId = cardItr->second; + requestedVCards.erase(cardItr); + Job* job = runningJobs.at(jobId); + switch (job->getType()) { + case Job::Type::cardInternal: + jobIsDone(jobId); + emit receivedCard(jid, card); + break; + case Job::Type::infoForUser: +#ifdef WITH_OMEMO + requestedBundles.emplace(jid, jobId); + //TODO save card! + emit requestBundles(jid); +#else + { + Shared::Info info(jid); + info.turnIntoContact(card); + emit receivedInfo(info); + } + jobIsDone(jobId); +#endif + emit receivedCard(jid, card); + break; + default: + throw 8576; + } + } +} + +void Core::DelayManager::ownVCardReceived(const Shared::VCard& card) { + Job::Id jobId = ownVCardJobId; + ownVCardJobId = 0; + Job* job = runningJobs.at(jobId); + switch (job->getType()) { + case Job::Type::ownCardInternal: + jobIsDone(jobId); + emit receivedOwnCard(card); + break; + case Job::Type::ownInfoForUser: +#ifdef WITH_OMEMO + //requestedBundles.emplace(jid, jobId); + //TODO save card! + emit requestOwnBundle(); +#else + { + Shared::Info info(""); + info.turnIntoOwnAccount(card); + emit receivedOwnInfo(info); + } + jobIsDone(jobId); +#endif + emit receivedOwnCard(card); + break; + default: + throw 8576; + } +} + +void Core::DelayManager::receivedBundles(const QString& jid) { + +} diff --git a/core/delayManager/delaymanager.h b/core/delayManager/delaymanager.h new file mode 100644 index 0000000..e4f3e2a --- /dev/null +++ b/core/delayManager/delaymanager.h @@ -0,0 +1,116 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef CORE_DELAYMANAGER_H +#define CORE_DELAYMANAGER_H + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "job.h" + +namespace Core { + +class DelayManager : public QObject +{ + Q_OBJECT +public: + DelayManager(Job::Id maxParallelJobs = 5, QObject* parent = nullptr); + ~DelayManager(); + + void getOwnVCard(); + void getOwnInfo(); + void getVCard(const QString& jid); + void getInfo(const QString& jid); + +signals: + void requestVCard(const QString& jid); + void requestOwnVCard(); + void requestBundles(const QString& jid); + void requestOwnBundle(); + void receivedCard(const QString& jid, const Shared::VCard& info); + void receivedOwnCard(const Shared::VCard& info); + void receivedInfo(const Shared::Info& info); + void receivedOwnInfo(const Shared::Info& info); + +public slots: + void ownVCardReceived(const Shared::VCard& card); + void receivedVCard(const QString& jid, const Shared::VCard& card); + void receivedBundles(const QString& jid); + +private: + void preScheduleJob(Job* job); + void scheduleJob(Job* job); + void preExecuteJob(Job* job); + void executeJob(Job* job); + void jobIsDone(Job::Id jobId); + Job::Id getNextJobId(); + void replaceJob(Job* job); + Job* getVCardJob(const QString& jid); + +private: + struct id {}; + struct sequence {}; + + typedef boost::multi_index_container< + Job*, + boost::multi_index::indexed_by< + boost::multi_index::sequenced< + boost::multi_index::tag + >, + boost::multi_index::ordered_unique< + boost::multi_index::tag, + boost::multi_index::member< + Job, + const Job::Id, + &Job::id + > + > + > + > Storage; + + + typedef Storage::index::type StorageById; + typedef Storage::index::type StorageSequence; + Job::Id maxParallelJobs; + Job::Id nextJobId; + + Storage scheduledJobs; + StorageById& scheduledJobsById; + StorageSequence& jobSequence; + std::map runningJobs; + + Job::Id ownVCardJobId; + Job::Id ownInfoJobId; + std::map scheduledVCards; + std::map requestedVCards; + std::map requestedBundles; +}; + +} + +#endif // CORE_DELAYMANAGER_H diff --git a/core/delayManager/infoforuser.cpp b/core/delayManager/infoforuser.cpp new file mode 100644 index 0000000..31d0571 --- /dev/null +++ b/core/delayManager/infoforuser.cpp @@ -0,0 +1,26 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "infoforuser.h" + +Core::InfoForUser::InfoForUser(Job::Id p_id, const QString& p_jid) : + CardInternal(p_id, p_jid, Type::infoForUser) +{} + +Core::InfoForUser::InfoForUser(const Core::InfoForUser& other) : + CardInternal(other) +{} + diff --git a/core/delayManager/infoforuser.h b/core/delayManager/infoforuser.h new file mode 100644 index 0000000..2bc84e4 --- /dev/null +++ b/core/delayManager/infoforuser.h @@ -0,0 +1,32 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef CORE_INFOFORUSER_H +#define CORE_INFOFORUSER_H + +#include "cardinternal.h" + +namespace Core { + +class InfoForUser : public CardInternal { +public: + InfoForUser(Job::Id id, const QString& jid); + InfoForUser(const InfoForUser& other); +}; + +} + +#endif // CORE_INFOFORUSER_H diff --git a/core/delayManager/job.cpp b/core/delayManager/job.cpp new file mode 100644 index 0000000..0d4c868 --- /dev/null +++ b/core/delayManager/job.cpp @@ -0,0 +1,32 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "job.h" + +Core::Job::Job(Core::Job::Id p_id, Core::Job::Type p_type) : + id (p_id), + type (p_type) {} + + +Core::Job::Job(const Core::Job& other) : + id(other.id), + type(other.type) {} + +Core::Job::~Job() {} + +Core::Job::Type Core::Job::getType() const { + return type; +} diff --git a/core/delayManager/job.h b/core/delayManager/job.h new file mode 100644 index 0000000..6314f48 --- /dev/null +++ b/core/delayManager/job.h @@ -0,0 +1,50 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef CORE_DELAYMANAGER_JOB_H +#define CORE_DELAYMANAGER_JOB_H + +#include + +namespace Core { + +class Job { +public: + typedef uint16_t Id; + + enum class Type { + cardInternal, + ownCardInternal, + infoForUser, + ownInfoForUser + }; + + Job(Id id, Type type); + Job(const Job& other); + virtual ~Job(); + + const Id id; + +public: + Type getType() const; + +protected: + Type type; +}; + +} + +#endif // CORE_DELAYMANAGER_JOB_H diff --git a/core/delayManager/owncardinternal.cpp b/core/delayManager/owncardinternal.cpp new file mode 100644 index 0000000..0167516 --- /dev/null +++ b/core/delayManager/owncardinternal.cpp @@ -0,0 +1,30 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "owncardinternal.h" + +Core::OwnCardInternal::OwnCardInternal(Job::Id p_id) : + Job(p_id, Type::ownCardInternal) +{} + +Core::OwnCardInternal::OwnCardInternal(Job::Id p_id, Job::Type p_type) : + Job(p_id, p_type) +{} + +Core::OwnCardInternal::OwnCardInternal(const Core::OwnCardInternal& other) : + Job(other) +{} + diff --git a/core/delayManager/owncardinternal.h b/core/delayManager/owncardinternal.h new file mode 100644 index 0000000..296666f --- /dev/null +++ b/core/delayManager/owncardinternal.h @@ -0,0 +1,35 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef CORE_OWNCARDINTERNAL_H +#define CORE_OWNCARDINTERNAL_H + +#include "job.h" + +namespace Core { + +class OwnCardInternal : public Job { +protected: + OwnCardInternal(Job::Id id, Job::Type type); + +public: + OwnCardInternal(Job::Id id); + OwnCardInternal(const OwnCardInternal& other); +}; + +} + +#endif // CORE_OWNCARDINTERNAL_H diff --git a/core/delayManager/owninfoforuser.cpp b/core/delayManager/owninfoforuser.cpp new file mode 100644 index 0000000..12d1f72 --- /dev/null +++ b/core/delayManager/owninfoforuser.cpp @@ -0,0 +1,25 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "owninfoforuser.h" + +Core::OwnInfoForUser::OwnInfoForUser(Job::Id p_id) : + OwnCardInternal(p_id, Type::ownInfoForUser) +{} + +Core::OwnInfoForUser::OwnInfoForUser(const Core::OwnInfoForUser& other) : + OwnCardInternal(other) +{} diff --git a/core/delayManager/owninfoforuser.h b/core/delayManager/owninfoforuser.h new file mode 100644 index 0000000..a2534e5 --- /dev/null +++ b/core/delayManager/owninfoforuser.h @@ -0,0 +1,32 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef CORE_OWNINFOFORUSER_H +#define CORE_OWNINFOFORUSER_H + +#include "owncardinternal.h" + +namespace Core { + +class OwnInfoForUser : public OwnCardInternal { +public: + OwnInfoForUser(Job::Id id); + OwnInfoForUser(const OwnInfoForUser& other); +}; + +} + +#endif // CORE_OWNINFOFORUSER_H