some hopefully final preparations for delay manager
This commit is contained in:
parent
9fff409630
commit
5ba97ecc25
@ -107,7 +107,6 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
||||
client.addExtension(tm);
|
||||
client.addExtension(om);
|
||||
om->setSecurityPolicy(QXmpp::Toakafa);
|
||||
om->setNewDeviceAutoSessionBuildingEnabled(true);
|
||||
|
||||
if (oh->hasOwnDevice()) {
|
||||
QXmppTask<bool> future = om->load();
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "owncardinternal.h"
|
||||
#include "owninfoforuser.h"
|
||||
|
||||
Core::DelayManager::Manager::Manager(Job::Id mpj, QObject* parent) :
|
||||
Core::DelayManager::Manager::Manager(const QString& poj, Job::Id mpj, QObject* parent) :
|
||||
QObject(parent),
|
||||
maxParallelJobs(mpj),
|
||||
nextJobId(1),
|
||||
@ -34,8 +34,9 @@ Core::DelayManager::Manager::Manager(Job::Id mpj, QObject* parent) :
|
||||
scheduledVCards(),
|
||||
requestedVCards(),
|
||||
#ifdef WITH_OMEMO
|
||||
requestedBundles()
|
||||
requestedBundles(),
|
||||
#endif
|
||||
ownJid(poj)
|
||||
{
|
||||
}
|
||||
|
||||
@ -49,7 +50,7 @@ Core::DelayManager::Manager::~Manager() {
|
||||
}
|
||||
}
|
||||
|
||||
Core::Job::Id Core::DelayManager::Manager::getNextJobId() {
|
||||
Core::DelayManager::Job::Id Core::DelayManager::Manager::getNextJobId() {
|
||||
Job::Id id = nextJobId++;
|
||||
if (id == 0)
|
||||
id = nextJobId++;
|
||||
@ -94,7 +95,7 @@ void Core::DelayManager::Manager::getOwnVCard() {
|
||||
scheduleJob(new OwnCardInternal(getNextJobId()));
|
||||
}
|
||||
|
||||
Core::Job* Core::DelayManager::Manager::getVCardJob(const QString& jid) {
|
||||
Core::DelayManager::Job* Core::DelayManager::Manager::getVCardJob(const QString& jid) {
|
||||
Job* job = nullptr;
|
||||
std::map<QString, Job::Id>::const_iterator sitr = scheduledVCards.find(jid);
|
||||
if (sitr == scheduledVCards.end()) {
|
||||
@ -107,7 +108,7 @@ Core::Job* Core::DelayManager::Manager::getVCardJob(const QString& jid) {
|
||||
|
||||
return job;
|
||||
}
|
||||
void Core::DelayManager::Manager::preScheduleJob(Core::Job* job) {
|
||||
void Core::DelayManager::Manager::preScheduleJob(Job* job) {
|
||||
switch (job->type) {
|
||||
case Job::Type::cardInternal:
|
||||
scheduledVCards.emplace(dynamic_cast<CardInternal*>(job)->jid, job->id);
|
||||
@ -125,7 +126,7 @@ void Core::DelayManager::Manager::preScheduleJob(Core::Job* job) {
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::scheduleJob(Core::Job* job) {
|
||||
void Core::DelayManager::Manager::scheduleJob(Job* job) {
|
||||
preScheduleJob(job);
|
||||
if (runningJobs.size() < maxParallelJobs) {
|
||||
executeJob(job);
|
||||
@ -134,7 +135,7 @@ void Core::DelayManager::Manager::scheduleJob(Core::Job* job) {
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::preExecuteJob(Core::Job* job) {
|
||||
void Core::DelayManager::Manager::preExecuteJob(Job* job) {
|
||||
switch (job->type) {
|
||||
case Job::Type::cardInternal:
|
||||
case Job::Type::infoForUser: {
|
||||
@ -149,7 +150,7 @@ void Core::DelayManager::Manager::preExecuteJob(Core::Job* job) {
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::executeJob(Core::Job* job) {
|
||||
void Core::DelayManager::Manager::executeJob(Job* job) {
|
||||
preExecuteJob(job);
|
||||
runningJobs.emplace(job->id, job);
|
||||
switch (job->type) {
|
||||
@ -179,7 +180,7 @@ void Core::DelayManager::Manager::jobIsDone(Job::Id jobId) {
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::replaceJob(Core::Job* job) {
|
||||
void Core::DelayManager::Manager::replaceJob(Job* job) {
|
||||
preScheduleJob(job);
|
||||
std::map<Job::Id, Job*>::iterator itr = runningJobs.find(job->id);
|
||||
if (itr != runningJobs.end()) {
|
||||
@ -197,7 +198,7 @@ void Core::DelayManager::Manager::replaceJob(Core::Job* job) {
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::jobIsCanceled(Core::Job* job, bool wasRunning) {
|
||||
void Core::DelayManager::Manager::jobIsCanceled(Job* job, bool wasRunning) {
|
||||
switch (job->type) {
|
||||
case Job::Type::cardInternal: {
|
||||
CardInternal* jb = dynamic_cast<CardInternal*>(job);
|
||||
@ -211,13 +212,20 @@ void Core::DelayManager::Manager::jobIsCanceled(Core::Job* job, bool wasRunning)
|
||||
break;
|
||||
case Job::Type::infoForUser: {
|
||||
InfoForUser* jb = dynamic_cast<InfoForUser*>(job);
|
||||
if (jb->getStage() == InfoForUser::Stage::waitingForVCard) {
|
||||
switch (jb->getStage()) {
|
||||
case InfoForUser::Stage::waitingForVCard:
|
||||
if (wasRunning)
|
||||
requestedVCards.erase(jb->jid);
|
||||
else
|
||||
scheduledVCards.erase(jb->jid);
|
||||
|
||||
emit receivedVCard(jb->jid, Shared::VCard());
|
||||
break;
|
||||
case InfoForUser::Stage::waitingForBundles:
|
||||
requestedBundles.erase(jb->jid);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
emit receivedInfo(Shared::Info(jb->jid));
|
||||
}
|
||||
@ -229,7 +237,7 @@ void Core::DelayManager::Manager::jobIsCanceled(Core::Job* job, bool wasRunning)
|
||||
emit receivedOwnCard(Shared::VCard());
|
||||
}
|
||||
ownInfoJobId = 0;
|
||||
emit receivedOwnInfo(Shared::Info (""));
|
||||
emit receivedOwnInfo(Shared::Info (ownJid));
|
||||
}
|
||||
|
||||
break;
|
||||
@ -257,7 +265,7 @@ void Core::DelayManager::Manager::receivedVCard(const QString& jid, const Shared
|
||||
std::map<QString, Job::Id>::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);
|
||||
@ -266,26 +274,25 @@ void Core::DelayManager::Manager::receivedVCard(const QString& jid, const Shared
|
||||
jobIsDone(jobId);
|
||||
emit receivedCard(jid, card);
|
||||
break;
|
||||
case Job::Type::infoForUser:
|
||||
case Job::Type::infoForUser: {
|
||||
#ifdef WITH_OMEMO
|
||||
requestedBundles.emplace(jid, jobId);
|
||||
//TODO save card!
|
||||
InfoForUser* jb = dynamic_cast<InfoForUser*>(job);
|
||||
jb->receivedVCard(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::Manager::ownVCardReceived(const Shared::VCard& card) {
|
||||
Job::Id jobId = ownVCardJobId;
|
||||
@ -296,26 +303,54 @@ void Core::DelayManager::Manager::ownVCardReceived(const Shared::VCard& card) {
|
||||
jobIsDone(jobId);
|
||||
emit receivedOwnCard(card);
|
||||
break;
|
||||
case Job::Type::ownInfoForUser:
|
||||
case Job::Type::ownInfoForUser: {
|
||||
#ifdef WITH_OMEMO
|
||||
//requestedBundles.emplace(jid, jobId);
|
||||
//TODO save card!
|
||||
OwnInfoForUser* jb = dynamic_cast<OwnInfoForUser*>(job);
|
||||
jb->receivedVCard(card);
|
||||
emit requestOwnBundle();
|
||||
#else
|
||||
{
|
||||
Shared::Info info("");
|
||||
Shared::Info info(ownJid);
|
||||
info.turnIntoOwnAccount(card);
|
||||
emit receivedOwnInfo(info);
|
||||
}
|
||||
jobIsDone(jobId);
|
||||
#endif
|
||||
emit receivedOwnCard(card);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw 8576;
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::receivedBundles(const QString& jid) {
|
||||
|
||||
void Core::DelayManager::Manager::receivedBundles(const QString& jid, const std::list<Shared::KeyInfo>& keys) {
|
||||
std::map<QString, Job::Id>::const_iterator itr = requestedBundles.find(jid);
|
||||
if (itr == requestedBundles.end()) {
|
||||
throw 8577; //never supposed to happen, the state is not correct;
|
||||
}
|
||||
|
||||
Job::Id jobId = itr->second;
|
||||
requestedBundles.erase(itr);
|
||||
Job* jb = runningJobs.at(jobId);
|
||||
InfoForUser* job = dynamic_cast<InfoForUser*>(jb);
|
||||
|
||||
Shared::Info info(jid);
|
||||
info.turnIntoContact(job->claim(), new std::list<Shared::KeyInfo>(keys));
|
||||
emit receivedInfo(info);
|
||||
jobIsDone(jobId);
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::receivedOwnBundles(const std::list<Shared::KeyInfo>& keys) {
|
||||
Job::Id jobId = ownInfoJobId;
|
||||
ownInfoJobId = 0;
|
||||
Job* jb = runningJobs.at(jobId);
|
||||
OwnInfoForUser* job = dynamic_cast<OwnInfoForUser*>(jb);
|
||||
|
||||
Shared::Info info(ownJid);
|
||||
info.turnIntoOwnAccount(job->claim(), new std::list<Shared::KeyInfo>(keys));
|
||||
emit receivedOwnInfo(info);
|
||||
jobIsDone(jobId);
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::setOwnJid(const QString& jid) {
|
||||
ownJid = jid;
|
||||
}
|
||||
|
@ -40,19 +40,21 @@ class Manager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Manager(Job::Id maxParallelJobs = 5, QObject* parent = nullptr);
|
||||
Manager(const QString& ownJid, Job::Id maxParallelJobs = 5, QObject* parent = nullptr);
|
||||
~Manager();
|
||||
|
||||
void getOwnVCard();
|
||||
void getOwnInfo();
|
||||
void getVCard(const QString& jid);
|
||||
void getInfo(const QString& jid);
|
||||
void setOwnJid(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);
|
||||
@ -62,7 +64,8 @@ public slots:
|
||||
void disconnected();
|
||||
void ownVCardReceived(const Shared::VCard& card);
|
||||
void receivedVCard(const QString& jid, const Shared::VCard& card);
|
||||
void receivedBundles(const QString& jid);
|
||||
void receivedBundles(const QString& jid, const std::list<Shared::KeyInfo>& keys);
|
||||
void receivedOwnBundles(const std::list<Shared::KeyInfo>& keys);
|
||||
|
||||
private:
|
||||
void preScheduleJob(Job* job);
|
||||
@ -114,6 +117,7 @@ private:
|
||||
#ifdef WITH_OMEMO
|
||||
std::map<QString, Job::Id> requestedBundles;
|
||||
#endif
|
||||
QString ownJid;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -18,17 +18,39 @@
|
||||
|
||||
Core::DelayManager::Info::Info(Id p_id, Type p_type) :
|
||||
Job(p_id, p_type),
|
||||
stage(Stage::waitingForVCard)
|
||||
stage(Stage::waitingForVCard),
|
||||
info(nullptr)
|
||||
{}
|
||||
|
||||
Core::DelayManager::Info::Info(const Info& other) :
|
||||
Job(other),
|
||||
stage(other.stage)
|
||||
stage(other.stage),
|
||||
info(nullptr)
|
||||
{}
|
||||
|
||||
Core::DelayManager::Info::~Info() {
|
||||
if (stage == Stage::waitingForBundles) {
|
||||
delete info;
|
||||
}
|
||||
}
|
||||
|
||||
Core::DelayManager::Info::Stage Core::DelayManager::Info::getStage() const {
|
||||
return stage;
|
||||
}
|
||||
|
||||
void Core::DelayManager::Info::receivedVCard(const Shared::VCard& card) {
|
||||
if (stage != Stage::waitingForVCard)
|
||||
throw 245;
|
||||
|
||||
info = new Shared::VCard(card);
|
||||
stage = Stage::waitingForBundles;
|
||||
}
|
||||
|
||||
Shared::VCard * Core::DelayManager::Info::claim() {
|
||||
if (stage != Stage::waitingForBundles)
|
||||
throw 246;
|
||||
|
||||
Shared::VCard* res = info;
|
||||
info = nullptr;
|
||||
return res;
|
||||
}
|
||||
|
@ -19,6 +19,9 @@
|
||||
|
||||
#include "job.h"
|
||||
|
||||
#include <shared/vcard.h>
|
||||
#include <shared/info.h>
|
||||
|
||||
namespace Core {
|
||||
namespace DelayManager {
|
||||
|
||||
@ -26,7 +29,8 @@ class Info : public virtual Job {
|
||||
public:
|
||||
enum class Stage {
|
||||
waitingForVCard,
|
||||
waitingForBundles
|
||||
waitingForBundles,
|
||||
finished
|
||||
};
|
||||
|
||||
protected:
|
||||
@ -36,10 +40,14 @@ protected:
|
||||
public:
|
||||
~Info();
|
||||
|
||||
void receivedVCard(const Shared::VCard& card);
|
||||
Shared::VCard* claim();
|
||||
Stage getStage() const;
|
||||
|
||||
|
||||
private:
|
||||
Stage stage;
|
||||
Shared::VCard* info;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -27,4 +27,3 @@ Core::DelayManager::InfoForUser::InfoForUser(const InfoForUser& other) :
|
||||
Contact(other),
|
||||
Info(other)
|
||||
{}
|
||||
|
||||
|
@ -328,3 +328,26 @@ Shared::VCard * Shared::Info::getVCard() {
|
||||
throw 365;
|
||||
}
|
||||
}
|
||||
|
||||
void Shared::Info::setActiveKeys(std::list<KeyInfo>* keys) {
|
||||
switch (type) {
|
||||
case EntryType::contact:
|
||||
case EntryType::ownAccount:
|
||||
activeKeys = keys;
|
||||
break;
|
||||
default:
|
||||
throw 366;
|
||||
}
|
||||
}
|
||||
|
||||
void Shared::Info::setVCard(Shared::VCard* card) {
|
||||
switch (type) {
|
||||
case EntryType::contact:
|
||||
case EntryType::ownAccount:
|
||||
vcard = card;
|
||||
break;
|
||||
default:
|
||||
throw 367;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,11 +69,13 @@ public:
|
||||
VCard& getVCardRef();
|
||||
const VCard* getVCard() const;
|
||||
VCard* getVCard();
|
||||
void setVCard(Shared::VCard* card);
|
||||
|
||||
const std::list<KeyInfo>& getActiveKeysRef() const;
|
||||
std::list<KeyInfo>& getActiveKeysRef();
|
||||
const std::list<KeyInfo>* getActiveKeys() const;
|
||||
std::list<KeyInfo>* getActiveKeys();
|
||||
void setActiveKeys(std::list<KeyInfo>* keys);
|
||||
|
||||
const std::list<KeyInfo>& getInactiveKeysRef() const;
|
||||
std::list<KeyInfo>& getInactiveKeysRef();
|
||||
|
Loading…
Reference in New Issue
Block a user