debugged a crash, keys are now fetching, refactored main, added some exceptions instead of ints, debugged termination process
This commit is contained in:
parent
927bdf0dab
commit
4b68da458f
9 changed files with 321 additions and 130 deletions
|
@ -32,6 +32,12 @@ public:
|
|||
infoForUser,
|
||||
ownInfoForUser
|
||||
};
|
||||
inline static constexpr const char * const TypeString[] = {
|
||||
"cardInternal",
|
||||
"ownCardInternal",
|
||||
"infoForUser",
|
||||
"ownInfoForUser"
|
||||
};
|
||||
protected:
|
||||
Job(Id id, Type type);
|
||||
Job(const Job& other);
|
||||
|
|
|
@ -67,8 +67,13 @@ void Core::DelayManager::Manager::getInfo(const QString& jid) {
|
|||
Job* job = nullptr;
|
||||
#ifdef WITH_OMEMO
|
||||
std::map<QString, Job::Id>::const_iterator bitr = requestedBundles.find(jid);
|
||||
if (bitr != requestedBundles.end())
|
||||
job = runningJobs.at(bitr->second);
|
||||
if (bitr != requestedBundles.end()) {
|
||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(bitr->second);
|
||||
if (itr == runningJobs.end())
|
||||
throw JobNotFound(bitr->second);
|
||||
|
||||
job = itr->second;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
job = getVCardJob(jid);
|
||||
|
@ -109,10 +114,19 @@ Core::DelayManager::Job* Core::DelayManager::Manager::getVCardJob(const QString&
|
|||
std::map<QString, Job::Id>::const_iterator sitr = scheduledVCards.find(jid);
|
||||
if (sitr == scheduledVCards.end()) {
|
||||
std::map<QString, Job::Id>::const_iterator ritr = requestedVCards.find(jid);
|
||||
if (ritr != requestedVCards.end())
|
||||
job = runningJobs.at(ritr->second);
|
||||
if (ritr != requestedVCards.end()) {
|
||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(ritr->second);
|
||||
if (itr == runningJobs.end())
|
||||
throw JobNotFound(ritr->second, "getVCardJob:1");
|
||||
|
||||
job = itr->second;
|
||||
}
|
||||
} else {
|
||||
job = *(scheduledJobsById.find(sitr->second));
|
||||
StorageById::const_iterator itr = scheduledJobsById.find(sitr->second);
|
||||
if (itr == scheduledJobsById.end())
|
||||
throw JobNotFound(sitr->second, "getVCardJob:2");
|
||||
|
||||
job = *itr;
|
||||
}
|
||||
|
||||
return job;
|
||||
|
@ -177,7 +191,7 @@ void Core::DelayManager::Manager::executeJob(Job* job) {
|
|||
void Core::DelayManager::Manager::jobIsDone(Job::Id jobId) {
|
||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
|
||||
if (itr == runningJobs.end()) {
|
||||
throw 8573; //not supposed to happen, ever
|
||||
throw JobNotFound(jobId, "jobIsDone");
|
||||
}
|
||||
Job* job = itr->second;
|
||||
delete job;
|
||||
|
@ -201,9 +215,8 @@ void Core::DelayManager::Manager::replaceJob(Job* job) {
|
|||
if (sitr != scheduledJobsById.end()) {
|
||||
delete *(sitr);
|
||||
scheduledJobsById.replace(sitr, job);
|
||||
} else {
|
||||
throw 8574; //not supposed to happen, ever
|
||||
}
|
||||
} else
|
||||
throw JobNotFound(job->id, "replaceJob");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,7 +291,12 @@ void Core::DelayManager::Manager::receivedVCard(const QString& jid, const Shared
|
|||
}
|
||||
Job::Id jobId = cardItr->second;
|
||||
requestedVCards.erase(cardItr);
|
||||
Job* job = runningJobs.at(jobId);
|
||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
|
||||
if (itr == runningJobs.end()) {
|
||||
throw JobNotFound(jobId, "receivedVCard");
|
||||
}
|
||||
Job* job = itr->second;
|
||||
|
||||
switch (job->type) {
|
||||
case Job::Type::cardInternal:
|
||||
jobIsDone(jobId);
|
||||
|
@ -300,14 +318,22 @@ void Core::DelayManager::Manager::receivedVCard(const QString& jid, const Shared
|
|||
}
|
||||
break;
|
||||
default:
|
||||
throw 8576;
|
||||
throw UnexpectedJobType(job->type, "receivedVCard");
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DelayManager::Manager::receivedOwnVCard(const Shared::VCard& card) {
|
||||
if (ownVCardJobId == 0) {
|
||||
qDebug() << "received own VCard for" << ownJid << "but it was never requested through manager, ignoring";
|
||||
return;
|
||||
}
|
||||
Job::Id jobId = ownVCardJobId;
|
||||
ownVCardJobId = 0;
|
||||
Job* job = runningJobs.at(jobId);
|
||||
std::map<Job::Id, Job*>::const_iterator itr = runningJobs.find(jobId);
|
||||
if (itr == runningJobs.end()) {
|
||||
throw JobNotFound(jobId, "receivedOwnVCard");
|
||||
}
|
||||
Job* job = itr->second;
|
||||
switch (job->type) {
|
||||
case Job::Type::ownCardInternal:
|
||||
jobIsDone(jobId);
|
||||
|
@ -328,19 +354,24 @@ void Core::DelayManager::Manager::receivedOwnVCard(const Shared::VCard& card) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
throw 8576;
|
||||
throw UnexpectedJobType(job->type, "receivedVCard");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
qDebug() << "received bundles for" << jid << "but they were never requested through manager, ignoring";
|
||||
return;
|
||||
}
|
||||
|
||||
Job::Id jobId = itr->second;
|
||||
requestedBundles.erase(itr);
|
||||
Job* jb = runningJobs.at(jobId);
|
||||
std::map<Job::Id, Job*>::const_iterator jitr = runningJobs.find(jobId);
|
||||
if (jitr == runningJobs.end()) {
|
||||
throw JobNotFound(jobId, "receivedBundles");
|
||||
}
|
||||
Job* jb = jitr->second;
|
||||
InfoForUser* job = dynamic_cast<InfoForUser*>(jb);
|
||||
|
||||
Shared::Info info(jid);
|
||||
|
@ -350,9 +381,17 @@ void Core::DelayManager::Manager::receivedBundles(const QString& jid, const std:
|
|||
}
|
||||
|
||||
void Core::DelayManager::Manager::receivedOwnBundles(const std::list<Shared::KeyInfo>& keys) {
|
||||
if (ownInfoJobId == 0) {
|
||||
qDebug() << "received own bundles for" << ownJid << "but they were never requested through manager, ignoring";
|
||||
return;
|
||||
}
|
||||
Job::Id jobId = ownInfoJobId;
|
||||
ownInfoJobId = 0;
|
||||
Job* jb = runningJobs.at(jobId);
|
||||
std::map<Job::Id, Job*>::const_iterator jitr = runningJobs.find(jobId);
|
||||
if (jitr == runningJobs.end()) {
|
||||
throw JobNotFound(jobId, "receivedOwnBundles");
|
||||
}
|
||||
Job* jb = jitr->second;
|
||||
OwnInfoForUser* job = dynamic_cast<OwnInfoForUser*>(jb);
|
||||
|
||||
Shared::Info info(ownJid);
|
||||
|
@ -364,3 +403,35 @@ void Core::DelayManager::Manager::receivedOwnBundles(const std::list<Shared::Key
|
|||
void Core::DelayManager::Manager::setOwnJid(const QString& jid) {
|
||||
ownJid = jid;
|
||||
}
|
||||
|
||||
|
||||
Core::DelayManager::Manager::UnexpectedJobType::UnexpectedJobType(Job::Type p_type, const std::string& p_method):
|
||||
Exception(),
|
||||
type(p_type),
|
||||
method(p_method)
|
||||
{}
|
||||
|
||||
std::string Core::DelayManager::Manager::UnexpectedJobType::getMessage() const{
|
||||
std::string msg("Unexpected job type: ");
|
||||
msg += Job::TypeString[static_cast<int>(type)];
|
||||
if (method.size() > 0) {
|
||||
msg += " in method " + method;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
Core::DelayManager::Manager::JobNotFound::JobNotFound(Job::Id p_id, const std::string& p_method) :
|
||||
Exception(),
|
||||
id(p_id),
|
||||
method(p_method)
|
||||
{}
|
||||
|
||||
std::string Core::DelayManager::Manager::JobNotFound::getMessage() const {
|
||||
std::string msg("Job with id ");
|
||||
msg += std::to_string(id);
|
||||
msg += " was not found";
|
||||
if (method.size() > 0) {
|
||||
msg += " in method " + method;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include <boost/multi_index_container.hpp>
|
||||
#include <boost/multi_index/ordered_index.hpp>
|
||||
|
@ -30,6 +31,7 @@
|
|||
|
||||
#include <shared/vcard.h>
|
||||
#include <shared/info.h>
|
||||
#include <shared/exception.h>
|
||||
|
||||
#include "job.h"
|
||||
|
||||
|
@ -121,6 +123,25 @@ private:
|
|||
std::map<QString, Job::Id> requestedBundles;
|
||||
#endif
|
||||
QString ownJid;
|
||||
|
||||
public:
|
||||
class UnexpectedJobType: public Utils::Exception {
|
||||
public:
|
||||
UnexpectedJobType(Job::Type p_type, const std::string& p_method = "");
|
||||
std::string getMessage() const override;
|
||||
private:
|
||||
Job::Type type;
|
||||
std::string method;
|
||||
};
|
||||
|
||||
class JobNotFound: public Utils::Exception {
|
||||
public:
|
||||
JobNotFound(Job::Id p_id, const std::string& p_method = "");
|
||||
std::string getMessage() const override;
|
||||
private:
|
||||
Job::Id id;
|
||||
std::string method;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue