/* * 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 . */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include "job.h" namespace Core { namespace DelayManager { class Manager : public QObject { Q_OBJECT public: Manager(const QString& ownJid, Job::Id maxParallelJobs = 5, QObject* parent = nullptr); ~Manager(); void setOwnJid(const QString& jid); bool isOwnVCardPending() const; public slots: void getOwnVCard(); void getOwnInfo(); void getVCard(const QString& jid); void getInfo(const QString& jid); signals: void requestVCard(const QString& jid); void requestOwnVCard(); #ifdef WITH_OMEMO void requestBundles(const QString& jid); void requestOwnBundles(); #endif 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); public slots: void disconnected(); void receivedOwnVCard(const Shared::VCard& card); void receivedVCard(const QString& jid, const Shared::VCard& card); #ifdef WITH_OMEMO void receivedBundles(const QString& jid, const std::list& keys); void receivedOwnBundles(const std::list& keys); #endif private: void preScheduleJob(Job* job); void scheduleJob(Job* job); void preExecuteJob(Job* job); void executeJob(Job* job); void jobIsCanceled(Job* job, bool wasRunning); 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; #ifdef WITH_OMEMO std::map 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; }; }; } }