This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/example/doric/utils/DoricGlobalBroadcast.h
2021-07-21 19:03:29 +08:00

34 lines
800 B
C++

#ifndef DORICGLOBALBROADCAST_H
#define DORICGLOBALBROADCAST_H
#include <QDebug>
#include "DoricExport.h"
class DORIC_EXPORT DoricGlobalBroadcast {
private:
static DoricGlobalBroadcast *local_instance;
DoricGlobalBroadcast() { qDebug() << "DoricGlobalBroadcast constructor"; }
~DoricGlobalBroadcast() { qDebug() << "DoricGlobalBroadcast destructor"; }
public:
static DoricGlobalBroadcast *getInstance() {
static DoricGlobalBroadcast instance;
return &instance;
}
QString subscribe(QString name, std::function<void(QString)> callback);
void unsubscribe(QString subscribeId);
void publish(QString name, QString data);
private:
QAtomicInt idGenerator;
QMap<QString, QList<QPair<QString, std::function<void(QString)>>>> subjects;
};
#endif // DORICGLOBALBROADCAST_H