2023-03-04 22:36:53 +00:00
|
|
|
// 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/>.
|
|
|
|
|
2023-03-07 18:45:01 +00:00
|
|
|
#ifndef CORE_DELAYMANAGER_MANAGER_H
|
|
|
|
#define CORE_DELAYMANAGER_MANAGER_H
|
2023-03-04 22:36:53 +00:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <boost/multi_index_container.hpp>
|
|
|
|
#include <boost/multi_index/ordered_index.hpp>
|
|
|
|
#include <boost/multi_index/sequenced_index.hpp>
|
|
|
|
#include <boost/multi_index/member.hpp>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <shared/vcard.h>
|
|
|
|
#include <shared/info.h>
|
|
|
|
|
|
|
|
#include "job.h"
|
|
|
|
|
|
|
|
namespace Core {
|
2023-03-07 18:45:01 +00:00
|
|
|
namespace DelayManager {
|
2023-03-04 22:36:53 +00:00
|
|
|
|
2023-03-07 18:45:01 +00:00
|
|
|
class Manager : public QObject
|
2023-03-04 22:36:53 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-03-08 20:28:48 +00:00
|
|
|
Manager(const QString& ownJid, Job::Id maxParallelJobs = 5, QObject* parent = nullptr);
|
2023-03-07 18:45:01 +00:00
|
|
|
~Manager();
|
2023-03-04 22:36:53 +00:00
|
|
|
|
2023-03-10 18:43:31 +00:00
|
|
|
void setOwnJid(const QString& jid);
|
|
|
|
bool isOwnVCardPending() const;
|
|
|
|
|
|
|
|
public slots:
|
2023-03-04 22:36:53 +00:00
|
|
|
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);
|
2023-03-10 18:43:31 +00:00
|
|
|
void requestOwnBundles();
|
2023-03-08 20:28:48 +00:00
|
|
|
|
2023-03-10 18:43:31 +00:00
|
|
|
void gotVCard(const QString& jid, const Shared::VCard& info);
|
|
|
|
void gotOwnVCard(const Shared::VCard& info);
|
|
|
|
void gotInfo(const Shared::Info& info);
|
|
|
|
void gotOwnInfo(const Shared::Info& info);
|
2023-03-04 22:36:53 +00:00
|
|
|
|
|
|
|
public slots:
|
2023-03-07 18:45:01 +00:00
|
|
|
void disconnected();
|
2023-03-10 18:43:31 +00:00
|
|
|
void receivedOwnVCard(const Shared::VCard& card);
|
2023-03-04 22:36:53 +00:00
|
|
|
void receivedVCard(const QString& jid, const Shared::VCard& card);
|
2023-03-08 20:28:48 +00:00
|
|
|
void receivedBundles(const QString& jid, const std::list<Shared::KeyInfo>& keys);
|
|
|
|
void receivedOwnBundles(const std::list<Shared::KeyInfo>& keys);
|
2023-03-04 22:36:53 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void preScheduleJob(Job* job);
|
|
|
|
void scheduleJob(Job* job);
|
|
|
|
void preExecuteJob(Job* job);
|
|
|
|
void executeJob(Job* job);
|
2023-03-07 18:45:01 +00:00
|
|
|
void jobIsCanceled(Job* job, bool wasRunning);
|
2023-03-04 22:36:53 +00:00
|
|
|
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<sequence>
|
|
|
|
>,
|
|
|
|
boost::multi_index::ordered_unique<
|
|
|
|
boost::multi_index::tag<id>,
|
|
|
|
boost::multi_index::member<
|
|
|
|
Job,
|
|
|
|
const Job::Id,
|
|
|
|
&Job::id
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
> Storage;
|
|
|
|
|
|
|
|
|
|
|
|
typedef Storage::index<id>::type StorageById;
|
|
|
|
typedef Storage::index<sequence>::type StorageSequence;
|
|
|
|
Job::Id maxParallelJobs;
|
|
|
|
Job::Id nextJobId;
|
|
|
|
|
|
|
|
Storage scheduledJobs;
|
|
|
|
StorageById& scheduledJobsById;
|
|
|
|
StorageSequence& jobSequence;
|
|
|
|
std::map<Job::Id, Job*> runningJobs;
|
|
|
|
|
|
|
|
Job::Id ownVCardJobId;
|
|
|
|
Job::Id ownInfoJobId;
|
|
|
|
std::map<QString, Job::Id> scheduledVCards;
|
|
|
|
std::map<QString, Job::Id> requestedVCards;
|
2023-03-07 18:45:01 +00:00
|
|
|
#ifdef WITH_OMEMO
|
2023-03-04 22:36:53 +00:00
|
|
|
std::map<QString, Job::Id> requestedBundles;
|
2023-03-07 18:45:01 +00:00
|
|
|
#endif
|
2023-03-08 20:28:48 +00:00
|
|
|
QString ownJid;
|
2023-03-04 22:36:53 +00:00
|
|
|
};
|
|
|
|
|
2023-03-07 18:45:01 +00:00
|
|
|
}
|
2023-03-04 22:36:53 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 18:45:01 +00:00
|
|
|
#endif // CORE_DELAYMANAGER_MANAGER_H
|