//#include #include #include "RsGxsUpdateBroadcast.h" #include "RsProtectedTimer.h" #include QMap updateBroadcastMap; RsGxsUpdateBroadcast::RsGxsUpdateBroadcast(RsGxsIfaceHelper *ifaceImpl) : QObject(NULL), mIfaceImpl(ifaceImpl) { mTimer = new RsProtectedTimer(this); mTimer->setInterval(1000); mTimer->setSingleShot(true); connect(mTimer, SIGNAL(timeout()), this, SLOT(poll())); } void RsGxsUpdateBroadcast::cleanup() { QMap::iterator it; for (it = updateBroadcastMap.begin(); it != updateBroadcastMap.end(); ++it) { delete(it.value()); } updateBroadcastMap.clear(); } RsGxsUpdateBroadcast *RsGxsUpdateBroadcast::get(RsGxsIfaceHelper *ifaceImpl) { QMap::iterator it = updateBroadcastMap.find(ifaceImpl); if (it != updateBroadcastMap.end()) { return it.value(); } RsGxsUpdateBroadcast *updateBroadcast = new RsGxsUpdateBroadcast(ifaceImpl); updateBroadcastMap.insert(ifaceImpl, updateBroadcast); updateBroadcast->poll(); return updateBroadcast; } void RsGxsUpdateBroadcast::poll() { std::map > msgs; std::map > msgsMeta; std::list grps; std::list grpsMeta; if (mIfaceImpl->updated(true, true)) { mIfaceImpl->msgsChanged(msgs, msgsMeta); if (!msgs.empty() || !msgsMeta.empty()) { emit msgsChanged(msgs, msgsMeta); } mIfaceImpl->groupsChanged(grps, grpsMeta); if (!grps.empty() || !grpsMeta.empty()) { emit grpsChanged(grps, grpsMeta); } emit changed(); } mTimer->start(); }