forked from blue/squawk
72 lines
1.8 KiB
C
72 lines
1.8 KiB
C
|
// 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_H
|
||
|
#define CORE_DELAYMANAGER_H
|
||
|
|
||
|
#include <list>
|
||
|
#include <set>
|
||
|
|
||
|
#include <QObject>
|
||
|
#include <QString>
|
||
|
|
||
|
#include <shared/vcard.h>
|
||
|
#include <shared/info.h>
|
||
|
|
||
|
namespace Core {
|
||
|
|
||
|
class DelayManager : public QObject
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
|
||
|
enum class TaskType {
|
||
|
cardInternal,
|
||
|
infoForUser
|
||
|
}
|
||
|
public:
|
||
|
DelayManager(uint16_t maxParallelJobs = 5, QObject* parent = nullptr);
|
||
|
~DelayManager();
|
||
|
|
||
|
void requestVCard(const QString& jid);
|
||
|
void requestInfo(const QString& jid);
|
||
|
|
||
|
signals:
|
||
|
void requestVCard(const QString& jid);
|
||
|
|
||
|
public slots:
|
||
|
void receivedVCard(const QString& jid, const Shared::VCard& card);
|
||
|
|
||
|
private:
|
||
|
typedef std::pair<TaskType, void*> Job;
|
||
|
|
||
|
void scheduleJob(TaskType type, void* data);
|
||
|
void executeJob(Job job);
|
||
|
void jobIsDone(uint16_t jobId);
|
||
|
|
||
|
private:
|
||
|
uint16_t maxParallelJobs;
|
||
|
uint16_t nextJobId;
|
||
|
std::list<Job> scheduledJobs;
|
||
|
std::map<uint16_t, Job> runningJobs;
|
||
|
|
||
|
std::set<QString> pendingVCards;
|
||
|
std::map<QString, uint16_t> requestedVCards;
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif // CORE_DELAYMANAGER_H
|