forked from blue/squawk
some more thinking about delay manager
This commit is contained in:
parent
99fd001292
commit
9fff409630
@ -5,6 +5,8 @@ set(SOURCE_FILES
|
|||||||
infoforuser.cpp
|
infoforuser.cpp
|
||||||
owncardinternal.cpp
|
owncardinternal.cpp
|
||||||
owninfoforuser.cpp
|
owninfoforuser.cpp
|
||||||
|
contact.cpp
|
||||||
|
info.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(HEADER_FILES
|
set(HEADER_FILES
|
||||||
@ -14,6 +16,8 @@ set(HEADER_FILES
|
|||||||
infoforuser.h
|
infoforuser.h
|
||||||
owncardinternal.h
|
owncardinternal.h
|
||||||
owninfoforuser.h
|
owninfoforuser.h
|
||||||
|
contact.h
|
||||||
|
info.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_sources(squawk PRIVATE
|
target_sources(squawk PRIVATE
|
||||||
|
@ -16,17 +16,13 @@
|
|||||||
|
|
||||||
#include "cardinternal.h"
|
#include "cardinternal.h"
|
||||||
|
|
||||||
Core::CardInternal::CardInternal(Job::Id p_id, const QString& p_jid) :
|
Core::DelayManager::CardInternal::CardInternal(Id p_id, const QString& p_jid) :
|
||||||
Job(p_id, Type::cardInternal),
|
Job(p_id, Type::cardInternal),
|
||||||
jid(p_id)
|
Contact(p_id, p_jid, Type::cardInternal)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
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) :
|
Core::DelayManager::CardInternal::CardInternal(const CardInternal& other) :
|
||||||
Job(other),
|
Job(other),
|
||||||
jid(other.jid)
|
Contact(other)
|
||||||
{}
|
{}
|
||||||
|
@ -14,28 +14,24 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#ifndef CORE_CARDINTERNAL_H
|
#ifndef CORE_DELAYMANAGER_CARDINTERNAL_H
|
||||||
#define CORE_CARDINTERNAL_H
|
#define CORE_DELAYMANAGER_CARDINTERNAL_H
|
||||||
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "job.h"
|
#include "contact.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
namespace DelayManager {
|
||||||
|
|
||||||
class CardInternal : public Job {
|
class CardInternal : public Contact {
|
||||||
protected:
|
|
||||||
CardInternal(Job::Id id, const QString& jid, Job::Type type);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CardInternal(Job::Id id, const QString& jid);
|
CardInternal(Id id, const QString& jid);
|
||||||
CardInternal(const CardInternal& other);
|
CardInternal(const CardInternal& other);
|
||||||
|
|
||||||
const QString jid;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CORE_CARDINTERNAL_H
|
#endif // CORE_DELAYMANAGER_CARDINTERNAL_H
|
||||||
|
26
core/delayManager/contact.cpp
Normal file
26
core/delayManager/contact.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Squawk messenger.
|
||||||
|
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "contact.h"
|
||||||
|
|
||||||
|
Core::DelayManager::Contact::Contact(const Contact& other):
|
||||||
|
Job(other),
|
||||||
|
jid(other.jid) {}
|
||||||
|
|
||||||
|
|
||||||
|
Core::DelayManager::Contact::Contact(Id p_id, const QString& p_jid, Type p_type):
|
||||||
|
Job(p_id, p_type),
|
||||||
|
jid(p_jid) {}
|
39
core/delayManager/contact.h
Normal file
39
core/delayManager/contact.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Squawk messenger.
|
||||||
|
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef CORE_DELAYMANAGER_CONTACT_H
|
||||||
|
#define CORE_DELAYMANAGER_CONTACT_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "job.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
namespace DelayManager {
|
||||||
|
|
||||||
|
class Contact : public virtual Job {
|
||||||
|
protected:
|
||||||
|
Contact(Id id, const QString& jid, Type type);
|
||||||
|
Contact(const Contact& other);
|
||||||
|
|
||||||
|
public:
|
||||||
|
const QString jid;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CORE_DELAYMANAGER_CONTACT_H
|
@ -21,7 +21,7 @@
|
|||||||
#include "owncardinternal.h"
|
#include "owncardinternal.h"
|
||||||
#include "owninfoforuser.h"
|
#include "owninfoforuser.h"
|
||||||
|
|
||||||
Core::DelayManager::DelayManager(Job::Id mpj, QObject* parent) :
|
Core::DelayManager::Manager::Manager(Job::Id mpj, QObject* parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
maxParallelJobs(mpj),
|
maxParallelJobs(mpj),
|
||||||
nextJobId(1),
|
nextJobId(1),
|
||||||
@ -33,13 +33,23 @@ Core::DelayManager::DelayManager(Job::Id mpj, QObject* parent) :
|
|||||||
ownInfoJobId(0),
|
ownInfoJobId(0),
|
||||||
scheduledVCards(),
|
scheduledVCards(),
|
||||||
requestedVCards(),
|
requestedVCards(),
|
||||||
|
#ifdef WITH_OMEMO
|
||||||
requestedBundles()
|
requestedBundles()
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::DelayManager::~DelayManager() {}
|
Core::DelayManager::Manager::~Manager() {
|
||||||
|
for (const std::pair<const Job::Id, Job*>& pair : runningJobs) {
|
||||||
|
delete pair.second;
|
||||||
|
}
|
||||||
|
|
||||||
Core::Job::Id Core::DelayManager::getNextJobId() {
|
for (Job* job : jobSequence) {
|
||||||
|
delete job;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::Job::Id Core::DelayManager::Manager::getNextJobId() {
|
||||||
Job::Id id = nextJobId++;
|
Job::Id id = nextJobId++;
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
id = nextJobId++;
|
id = nextJobId++;
|
||||||
@ -47,7 +57,7 @@ Core::Job::Id Core::DelayManager::getNextJobId() {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::getInfo(const QString& jid) {
|
void Core::DelayManager::Manager::getInfo(const QString& jid) {
|
||||||
Job* job = nullptr;
|
Job* job = nullptr;
|
||||||
#ifdef WITH_OMEMO
|
#ifdef WITH_OMEMO
|
||||||
std::map<QString, Job::Id>::const_iterator bitr = requestedBundles.find(jid);
|
std::map<QString, Job::Id>::const_iterator bitr = requestedBundles.find(jid);
|
||||||
@ -58,13 +68,13 @@ void Core::DelayManager::getInfo(const QString& jid) {
|
|||||||
job = getVCardJob(jid);
|
job = getVCardJob(jid);
|
||||||
|
|
||||||
if (job != nullptr) {
|
if (job != nullptr) {
|
||||||
if (job->getType() == Job::Type::cardInternal)
|
if (job->type == Job::Type::cardInternal)
|
||||||
replaceJob(new InfoForUser(job->id, jid));
|
replaceJob(new InfoForUser(job->id, jid));
|
||||||
} else
|
} else
|
||||||
scheduleJob(new InfoForUser(getNextJobId(), jid));
|
scheduleJob(new InfoForUser(getNextJobId(), jid));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::getOwnInfo() {
|
void Core::DelayManager::Manager::getOwnInfo() {
|
||||||
if (ownInfoJobId == 0) {
|
if (ownInfoJobId == 0) {
|
||||||
if (ownVCardJobId != 0)
|
if (ownVCardJobId != 0)
|
||||||
replaceJob(new OwnInfoForUser(ownVCardJobId));
|
replaceJob(new OwnInfoForUser(ownVCardJobId));
|
||||||
@ -73,18 +83,18 @@ void Core::DelayManager::getOwnInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::getVCard(const QString& jid) {
|
void Core::DelayManager::Manager::getVCard(const QString& jid) {
|
||||||
Job* job = getVCardJob(jid);
|
Job* job = getVCardJob(jid);
|
||||||
if (job == nullptr)
|
if (job == nullptr)
|
||||||
scheduleJob(new CardInternal(getNextJobId(), jid));
|
scheduleJob(new CardInternal(getNextJobId(), jid));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::getOwnVCard() {
|
void Core::DelayManager::Manager::getOwnVCard() {
|
||||||
if (ownInfoJobId == 0)
|
if (ownInfoJobId == 0)
|
||||||
scheduleJob(new OwnCardInternal(getNextJobId()));
|
scheduleJob(new OwnCardInternal(getNextJobId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Job* Core::DelayManager::getVCardJob(const QString& jid) {
|
Core::Job* Core::DelayManager::Manager::getVCardJob(const QString& jid) {
|
||||||
Job* job = nullptr;
|
Job* job = nullptr;
|
||||||
std::map<QString, Job::Id>::const_iterator sitr = scheduledVCards.find(jid);
|
std::map<QString, Job::Id>::const_iterator sitr = scheduledVCards.find(jid);
|
||||||
if (sitr == scheduledVCards.end()) {
|
if (sitr == scheduledVCards.end()) {
|
||||||
@ -97,16 +107,16 @@ Core::Job* Core::DelayManager::getVCardJob(const QString& jid) {
|
|||||||
|
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
void Core::DelayManager::preScheduleJob(Core::Job* job) {
|
void Core::DelayManager::Manager::preScheduleJob(Core::Job* job) {
|
||||||
switch (job->getType()) {
|
switch (job->type) {
|
||||||
case Job::Type::cardInternal:
|
case Job::Type::cardInternal:
|
||||||
scheduledVCards.emplace(static_cast<CardInternal*>(job)->jid, job->id);
|
scheduledVCards.emplace(dynamic_cast<CardInternal*>(job)->jid, job->id);
|
||||||
break;
|
break;
|
||||||
case Job::Type::ownCardInternal:
|
case Job::Type::ownCardInternal:
|
||||||
ownVCardJobId = job->id;
|
ownVCardJobId = job->id;
|
||||||
break;
|
break;
|
||||||
case Job::Type::infoForUser:
|
case Job::Type::infoForUser:
|
||||||
scheduledVCards.emplace(static_cast<InfoForUser*>(job)->jid, job->id);
|
scheduledVCards.emplace(dynamic_cast<InfoForUser*>(job)->jid, job->id);
|
||||||
break;
|
break;
|
||||||
case Job::Type::ownInfoForUser:
|
case Job::Type::ownInfoForUser:
|
||||||
ownVCardJobId = job->id;
|
ownVCardJobId = job->id;
|
||||||
@ -115,7 +125,7 @@ void Core::DelayManager::preScheduleJob(Core::Job* job) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::scheduleJob(Core::Job* job) {
|
void Core::DelayManager::Manager::scheduleJob(Core::Job* job) {
|
||||||
preScheduleJob(job);
|
preScheduleJob(job);
|
||||||
if (runningJobs.size() < maxParallelJobs) {
|
if (runningJobs.size() < maxParallelJobs) {
|
||||||
executeJob(job);
|
executeJob(job);
|
||||||
@ -124,11 +134,11 @@ void Core::DelayManager::scheduleJob(Core::Job* job) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::preExecuteJob(Core::Job* job) {
|
void Core::DelayManager::Manager::preExecuteJob(Core::Job* job) {
|
||||||
switch (job->getType()) {
|
switch (job->type) {
|
||||||
case Job::Type::cardInternal:
|
case Job::Type::cardInternal:
|
||||||
case Job::Type::infoForUser: {
|
case Job::Type::infoForUser: {
|
||||||
CardInternal* cij = static_cast<CardInternal*>(job);
|
Contact* cij = dynamic_cast<Contact*>(job);
|
||||||
requestedVCards.emplace(cij->jid, job->id);
|
requestedVCards.emplace(cij->jid, job->id);
|
||||||
scheduledVCards.erase(cij->jid);
|
scheduledVCards.erase(cij->jid);
|
||||||
}
|
}
|
||||||
@ -139,13 +149,13 @@ void Core::DelayManager::preExecuteJob(Core::Job* job) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::executeJob(Core::Job* job) {
|
void Core::DelayManager::Manager::executeJob(Core::Job* job) {
|
||||||
preExecuteJob(job);
|
preExecuteJob(job);
|
||||||
runningJobs.emplace(job->id, job);
|
runningJobs.emplace(job->id, job);
|
||||||
switch (job->getType()) {
|
switch (job->type) {
|
||||||
case Job::Type::cardInternal:
|
case Job::Type::cardInternal:
|
||||||
case Job::Type::infoForUser:
|
case Job::Type::infoForUser:
|
||||||
emit requestVCard(static_cast<CardInternal*>(job)->jid);
|
emit requestVCard(dynamic_cast<Contact*>(job)->jid);
|
||||||
break;
|
break;
|
||||||
case Job::Type::ownInfoForUser:
|
case Job::Type::ownInfoForUser:
|
||||||
case Job::Type::ownCardInternal:
|
case Job::Type::ownCardInternal:
|
||||||
@ -154,7 +164,7 @@ void Core::DelayManager::executeJob(Core::Job* job) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::jobIsDone(Job::Id jobId) {
|
void Core::DelayManager::Manager::jobIsDone(Job::Id jobId) {
|
||||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
|
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
|
||||||
if (itr == runningJobs.end()) {
|
if (itr == runningJobs.end()) {
|
||||||
throw 8573; //not supposed to happen, ever
|
throw 8573; //not supposed to happen, ever
|
||||||
@ -169,7 +179,7 @@ void Core::DelayManager::jobIsDone(Job::Id jobId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::replaceJob(Core::Job* job) {
|
void Core::DelayManager::Manager::replaceJob(Core::Job* job) {
|
||||||
preScheduleJob(job);
|
preScheduleJob(job);
|
||||||
std::map<Job::Id, Job*>::iterator itr = runningJobs.find(job->id);
|
std::map<Job::Id, Job*>::iterator itr = runningJobs.find(job->id);
|
||||||
if (itr != runningJobs.end()) {
|
if (itr != runningJobs.end()) {
|
||||||
@ -187,7 +197,63 @@ void Core::DelayManager::replaceJob(Core::Job* job) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::receivedVCard(const QString& jid, const Shared::VCard& card) {
|
void Core::DelayManager::Manager::jobIsCanceled(Core::Job* job, bool wasRunning) {
|
||||||
|
switch (job->type) {
|
||||||
|
case Job::Type::cardInternal: {
|
||||||
|
CardInternal* jb = dynamic_cast<CardInternal*>(job);
|
||||||
|
if (wasRunning)
|
||||||
|
requestedVCards.erase(jb->jid);
|
||||||
|
else
|
||||||
|
scheduledVCards.erase(jb->jid);
|
||||||
|
|
||||||
|
emit receivedVCard(jb->jid, Shared::VCard());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Job::Type::infoForUser: {
|
||||||
|
InfoForUser* jb = dynamic_cast<InfoForUser*>(job);
|
||||||
|
if (jb->getStage() == InfoForUser::Stage::waitingForVCard) {
|
||||||
|
if (wasRunning)
|
||||||
|
requestedVCards.erase(jb->jid);
|
||||||
|
else
|
||||||
|
scheduledVCards.erase(jb->jid);
|
||||||
|
|
||||||
|
emit receivedVCard(jb->jid, Shared::VCard());
|
||||||
|
}
|
||||||
|
emit receivedInfo(Shared::Info(jb->jid));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Job::Type::ownInfoForUser: {
|
||||||
|
OwnInfoForUser* jb = dynamic_cast<OwnInfoForUser*>(job);
|
||||||
|
if (jb->getStage() == OwnInfoForUser::Stage::waitingForVCard) {
|
||||||
|
ownVCardJobId = 0;
|
||||||
|
emit receivedOwnCard(Shared::VCard());
|
||||||
|
}
|
||||||
|
ownInfoJobId = 0;
|
||||||
|
emit receivedOwnInfo(Shared::Info (""));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Job::Type::ownCardInternal:
|
||||||
|
ownVCardJobId = 0;
|
||||||
|
emit receivedOwnCard(Shared::VCard());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete job;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::DelayManager::Manager::disconnected() {
|
||||||
|
for (const std::pair<const Job::Id, Job*> pair : runningJobs)
|
||||||
|
jobIsCanceled(pair.second, true);
|
||||||
|
|
||||||
|
for (Job* job : scheduledJobs)
|
||||||
|
jobIsCanceled(job, false);
|
||||||
|
|
||||||
|
runningJobs.clear();
|
||||||
|
scheduledJobs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::DelayManager::Manager::receivedVCard(const QString& jid, const Shared::VCard& card) {
|
||||||
std::map<QString, Job::Id>::const_iterator cardItr = requestedVCards.find(jid);
|
std::map<QString, Job::Id>::const_iterator cardItr = requestedVCards.find(jid);
|
||||||
if (cardItr == requestedVCards.end()) {
|
if (cardItr == requestedVCards.end()) {
|
||||||
throw 8575; //never supposed to happen, the state is not correct;
|
throw 8575; //never supposed to happen, the state is not correct;
|
||||||
@ -195,7 +261,7 @@ void Core::DelayManager::receivedVCard(const QString& jid, const Shared::VCard&
|
|||||||
Job::Id jobId = cardItr->second;
|
Job::Id jobId = cardItr->second;
|
||||||
requestedVCards.erase(cardItr);
|
requestedVCards.erase(cardItr);
|
||||||
Job* job = runningJobs.at(jobId);
|
Job* job = runningJobs.at(jobId);
|
||||||
switch (job->getType()) {
|
switch (job->type) {
|
||||||
case Job::Type::cardInternal:
|
case Job::Type::cardInternal:
|
||||||
jobIsDone(jobId);
|
jobIsDone(jobId);
|
||||||
emit receivedCard(jid, card);
|
emit receivedCard(jid, card);
|
||||||
@ -221,11 +287,11 @@ void Core::DelayManager::receivedVCard(const QString& jid, const Shared::VCard&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::ownVCardReceived(const Shared::VCard& card) {
|
void Core::DelayManager::Manager::ownVCardReceived(const Shared::VCard& card) {
|
||||||
Job::Id jobId = ownVCardJobId;
|
Job::Id jobId = ownVCardJobId;
|
||||||
ownVCardJobId = 0;
|
ownVCardJobId = 0;
|
||||||
Job* job = runningJobs.at(jobId);
|
Job* job = runningJobs.at(jobId);
|
||||||
switch (job->getType()) {
|
switch (job->type) {
|
||||||
case Job::Type::ownCardInternal:
|
case Job::Type::ownCardInternal:
|
||||||
jobIsDone(jobId);
|
jobIsDone(jobId);
|
||||||
emit receivedOwnCard(card);
|
emit receivedOwnCard(card);
|
||||||
@ -250,6 +316,6 @@ void Core::DelayManager::ownVCardReceived(const Shared::VCard& card) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::DelayManager::receivedBundles(const QString& jid) {
|
void Core::DelayManager::Manager::receivedBundles(const QString& jid) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#ifndef CORE_DELAYMANAGER_H
|
#ifndef CORE_DELAYMANAGER_MANAGER_H
|
||||||
#define CORE_DELAYMANAGER_H
|
#define CORE_DELAYMANAGER_MANAGER_H
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -34,13 +34,14 @@
|
|||||||
#include "job.h"
|
#include "job.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
namespace DelayManager {
|
||||||
|
|
||||||
class DelayManager : public QObject
|
class Manager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DelayManager(Job::Id maxParallelJobs = 5, QObject* parent = nullptr);
|
Manager(Job::Id maxParallelJobs = 5, QObject* parent = nullptr);
|
||||||
~DelayManager();
|
~Manager();
|
||||||
|
|
||||||
void getOwnVCard();
|
void getOwnVCard();
|
||||||
void getOwnInfo();
|
void getOwnInfo();
|
||||||
@ -58,6 +59,7 @@ signals:
|
|||||||
void receivedOwnInfo(const Shared::Info& info);
|
void receivedOwnInfo(const Shared::Info& info);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void disconnected();
|
||||||
void ownVCardReceived(const Shared::VCard& card);
|
void ownVCardReceived(const Shared::VCard& card);
|
||||||
void receivedVCard(const QString& jid, const Shared::VCard& card);
|
void receivedVCard(const QString& jid, const Shared::VCard& card);
|
||||||
void receivedBundles(const QString& jid);
|
void receivedBundles(const QString& jid);
|
||||||
@ -67,6 +69,7 @@ private:
|
|||||||
void scheduleJob(Job* job);
|
void scheduleJob(Job* job);
|
||||||
void preExecuteJob(Job* job);
|
void preExecuteJob(Job* job);
|
||||||
void executeJob(Job* job);
|
void executeJob(Job* job);
|
||||||
|
void jobIsCanceled(Job* job, bool wasRunning);
|
||||||
void jobIsDone(Job::Id jobId);
|
void jobIsDone(Job::Id jobId);
|
||||||
Job::Id getNextJobId();
|
Job::Id getNextJobId();
|
||||||
void replaceJob(Job* job);
|
void replaceJob(Job* job);
|
||||||
@ -108,9 +111,12 @@ private:
|
|||||||
Job::Id ownInfoJobId;
|
Job::Id ownInfoJobId;
|
||||||
std::map<QString, Job::Id> scheduledVCards;
|
std::map<QString, Job::Id> scheduledVCards;
|
||||||
std::map<QString, Job::Id> requestedVCards;
|
std::map<QString, Job::Id> requestedVCards;
|
||||||
|
#ifdef WITH_OMEMO
|
||||||
std::map<QString, Job::Id> requestedBundles;
|
std::map<QString, Job::Id> requestedBundles;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CORE_DELAYMANAGER_H
|
#endif // CORE_DELAYMANAGER_MANAGER_H
|
||||||
|
34
core/delayManager/info.cpp
Normal file
34
core/delayManager/info.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Squawk messenger.
|
||||||
|
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "info.h"
|
||||||
|
|
||||||
|
Core::DelayManager::Info::Info(Id p_id, Type p_type) :
|
||||||
|
Job(p_id, p_type),
|
||||||
|
stage(Stage::waitingForVCard)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Core::DelayManager::Info::Info(const Info& other) :
|
||||||
|
Job(other),
|
||||||
|
stage(other.stage)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Core::DelayManager::Info::~Info() {
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::DelayManager::Info::Stage Core::DelayManager::Info::getStage() const {
|
||||||
|
return stage;
|
||||||
|
}
|
48
core/delayManager/info.h
Normal file
48
core/delayManager/info.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// Squawk messenger.
|
||||||
|
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef CORE_DELAYMANAGER_INFO_H
|
||||||
|
#define CORE_DELAYMANAGER_INFO_H
|
||||||
|
|
||||||
|
#include "job.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
namespace DelayManager {
|
||||||
|
|
||||||
|
class Info : public virtual Job {
|
||||||
|
public:
|
||||||
|
enum class Stage {
|
||||||
|
waitingForVCard,
|
||||||
|
waitingForBundles
|
||||||
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Info(Id id, Type type);
|
||||||
|
Info(const Info& other);
|
||||||
|
|
||||||
|
public:
|
||||||
|
~Info();
|
||||||
|
|
||||||
|
Stage getStage() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Stage stage;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CORE_DELAYMANAGER_INFO_H
|
@ -16,11 +16,15 @@
|
|||||||
|
|
||||||
#include "infoforuser.h"
|
#include "infoforuser.h"
|
||||||
|
|
||||||
Core::InfoForUser::InfoForUser(Job::Id p_id, const QString& p_jid) :
|
Core::DelayManager::InfoForUser::InfoForUser(Id p_id, const QString& p_jid) :
|
||||||
CardInternal(p_id, p_jid, Type::infoForUser)
|
Job(p_id, Type::infoForUser),
|
||||||
|
Contact(p_id, p_jid, Type::infoForUser),
|
||||||
|
Info(p_id, Type::infoForUser)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Core::InfoForUser::InfoForUser(const Core::InfoForUser& other) :
|
Core::DelayManager::InfoForUser::InfoForUser(const InfoForUser& other) :
|
||||||
CardInternal(other)
|
Job(other),
|
||||||
|
Contact(other),
|
||||||
|
Info(other)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -14,19 +14,22 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#ifndef CORE_INFOFORUSER_H
|
#ifndef CORE_DELAYMANAGER_INFOFORUSER_H
|
||||||
#define CORE_INFOFORUSER_H
|
#define CORE_DELAYMANAGER_INFOFORUSER_H
|
||||||
|
|
||||||
#include "cardinternal.h"
|
#include "contact.h"
|
||||||
|
#include "info.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
namespace DelayManager {
|
||||||
|
|
||||||
class InfoForUser : public CardInternal {
|
class InfoForUser : public Contact, public Info {
|
||||||
public:
|
public:
|
||||||
InfoForUser(Job::Id id, const QString& jid);
|
InfoForUser(Id id, const QString& jid);
|
||||||
InfoForUser(const InfoForUser& other);
|
InfoForUser(const InfoForUser& other);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CORE_INFOFORUSER_H
|
#endif // CORE_DELAYMANAGER_INFOFORUSER_H
|
||||||
|
@ -16,17 +16,13 @@
|
|||||||
|
|
||||||
#include "job.h"
|
#include "job.h"
|
||||||
|
|
||||||
Core::Job::Job(Core::Job::Id p_id, Core::Job::Type p_type) :
|
Core::DelayManager::Job::Job(Id p_id, Type p_type) :
|
||||||
id (p_id),
|
id (p_id),
|
||||||
type (p_type) {}
|
type (p_type) {}
|
||||||
|
|
||||||
|
|
||||||
Core::Job::Job(const Core::Job& other) :
|
Core::DelayManager::Job::Job(const Job& other) :
|
||||||
id(other.id),
|
id(other.id),
|
||||||
type(other.type) {}
|
type(other.type) {}
|
||||||
|
|
||||||
Core::Job::~Job() {}
|
Core::DelayManager::Job::~Job() {}
|
||||||
|
|
||||||
Core::Job::Type Core::Job::getType() const {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
namespace DelayManager {
|
||||||
|
|
||||||
class Job {
|
class Job {
|
||||||
public:
|
public:
|
||||||
@ -31,20 +32,18 @@ public:
|
|||||||
infoForUser,
|
infoForUser,
|
||||||
ownInfoForUser
|
ownInfoForUser
|
||||||
};
|
};
|
||||||
|
protected:
|
||||||
Job(Id id, Type type);
|
Job(Id id, Type type);
|
||||||
Job(const Job& other);
|
Job(const Job& other);
|
||||||
|
|
||||||
|
public:
|
||||||
virtual ~Job();
|
virtual ~Job();
|
||||||
|
|
||||||
const Id id;
|
const Id id;
|
||||||
|
const Type type;
|
||||||
public:
|
|
||||||
Type getType() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Type type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CORE_DELAYMANAGER_JOB_H
|
#endif // CORE_DELAYMANAGER_JOB_H
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
#include "owncardinternal.h"
|
#include "owncardinternal.h"
|
||||||
|
|
||||||
Core::OwnCardInternal::OwnCardInternal(Job::Id p_id) :
|
Core::DelayManager::OwnCardInternal::OwnCardInternal(Id p_id) :
|
||||||
Job(p_id, Type::ownCardInternal)
|
Job(p_id, Type::ownCardInternal)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Core::OwnCardInternal::OwnCardInternal(Job::Id p_id, Job::Type p_type) :
|
Core::DelayManager::OwnCardInternal::OwnCardInternal(Id p_id, Type p_type) :
|
||||||
Job(p_id, p_type)
|
Job(p_id, p_type)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Core::OwnCardInternal::OwnCardInternal(const Core::OwnCardInternal& other) :
|
Core::DelayManager::OwnCardInternal::OwnCardInternal(const OwnCardInternal& other) :
|
||||||
Job(other)
|
Job(other)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -14,22 +14,24 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#ifndef CORE_OWNCARDINTERNAL_H
|
#ifndef CORE_DELAYMANAGER_OWNCARDINTERNAL_H
|
||||||
#define CORE_OWNCARDINTERNAL_H
|
#define CORE_DELAYMANAGER_OWNCARDINTERNAL_H
|
||||||
|
|
||||||
#include "job.h"
|
#include "job.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
namespace DelayManager {
|
||||||
|
|
||||||
class OwnCardInternal : public Job {
|
class OwnCardInternal : public Job {
|
||||||
protected:
|
protected:
|
||||||
OwnCardInternal(Job::Id id, Job::Type type);
|
OwnCardInternal(Id id, Type type);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OwnCardInternal(Job::Id id);
|
OwnCardInternal(Id id);
|
||||||
OwnCardInternal(const OwnCardInternal& other);
|
OwnCardInternal(const OwnCardInternal& other);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CORE_OWNCARDINTERNAL_H
|
#endif // CORE_DELAYMANAGER_OWNCARDINTERNAL_H
|
||||||
|
@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
#include "owninfoforuser.h"
|
#include "owninfoforuser.h"
|
||||||
|
|
||||||
Core::OwnInfoForUser::OwnInfoForUser(Job::Id p_id) :
|
Core::DelayManager::OwnInfoForUser::OwnInfoForUser(Id p_id) :
|
||||||
OwnCardInternal(p_id, Type::ownInfoForUser)
|
Job(p_id, Type::ownInfoForUser),
|
||||||
|
Info(p_id, Type::ownInfoForUser)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Core::OwnInfoForUser::OwnInfoForUser(const Core::OwnInfoForUser& other) :
|
Core::DelayManager::OwnInfoForUser::OwnInfoForUser(const OwnInfoForUser& other) :
|
||||||
OwnCardInternal(other)
|
Job(other),
|
||||||
|
Info(other)
|
||||||
{}
|
{}
|
||||||
|
@ -14,19 +14,22 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#ifndef CORE_OWNINFOFORUSER_H
|
#ifndef CORE_DELAYMANAGER_OWNINFOFORUSER_H
|
||||||
#define CORE_OWNINFOFORUSER_H
|
#define CORE_DELAYMANAGER_OWNINFOFORUSER_H
|
||||||
|
|
||||||
#include "owncardinternal.h"
|
#include "contact.h"
|
||||||
|
#include "info.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
namespace DelayManager {
|
||||||
|
|
||||||
class OwnInfoForUser : public OwnCardInternal {
|
class OwnInfoForUser : public Info {
|
||||||
public:
|
public:
|
||||||
OwnInfoForUser(Job::Id id);
|
OwnInfoForUser(Id id);
|
||||||
OwnInfoForUser(const OwnInfoForUser& other);
|
OwnInfoForUser(const OwnInfoForUser& other);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CORE_OWNINFOFORUSER_H
|
#endif // CORE_DELAYMANAGER_OWNINFOFORUSER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user