mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-23 06:31:20 -04:00
use notify for gxs events. Removed the previous polling based system. Now multiple clients can receive gxs changes. This also fixes the always growing changes queue in rs-nogui.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8057 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b912ac656c
commit
6dff335515
11 changed files with 117 additions and 280 deletions
|
@ -18,6 +18,7 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*************************************************************************/
|
||||
#include <retroshare/rsgxsifacehelper.h>
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
|
@ -140,6 +141,7 @@ NotifyQt::NotifyQt() : cDialog(NULL)
|
|||
// register to allow sending over Qt::QueuedConnection
|
||||
qRegisterMetaType<ChatId>("ChatId");
|
||||
qRegisterMetaType<ChatMessage>("ChatMessage");
|
||||
qRegisterMetaType<RsGxsChanges>("RsGxsChanges");
|
||||
}
|
||||
|
||||
void NotifyQt::notifyErrorMsg(int list, int type, std::string msg)
|
||||
|
@ -417,6 +419,22 @@ void NotifyQt::notifyPeerStatusChangedSummary()
|
|||
|
||||
emit peerStatusChangedSummary();
|
||||
}
|
||||
|
||||
void NotifyQt::notifyGxsChange(const RsGxsChanges& changes)
|
||||
{
|
||||
{
|
||||
QMutexLocker m(&_mutex) ;
|
||||
if(!_enabled)
|
||||
return ;
|
||||
}
|
||||
|
||||
#ifdef NOTIFY_DEBUG
|
||||
std::cerr << "Notifyqt:: notified that gxs has changes" << std::endl;
|
||||
#endif
|
||||
|
||||
emit gxsChange(changes);
|
||||
}
|
||||
|
||||
#ifdef REMOVE
|
||||
void NotifyQt::notifyForumMsgReadSatusChanged(const std::string& forumId, const std::string& msgId, uint32_t status)
|
||||
{
|
||||
|
|
|
@ -57,6 +57,9 @@ class NotifyQt: public QObject, public NotifyClient
|
|||
virtual void notifyPeerStatusChanged(const std::string& peer_id, uint32_t state);
|
||||
/* one or more peers has changed the states */
|
||||
virtual void notifyPeerStatusChangedSummary();
|
||||
|
||||
virtual void notifyGxsChange(const RsGxsChanges& change);
|
||||
|
||||
#ifdef REMOVE
|
||||
virtual void notifyForumMsgReadSatusChanged(const std::string& forumId, const std::string& msgId, uint32_t status);
|
||||
virtual void notifyChannelMsgReadSatusChanged(const std::string& channelId, const std::string& msgId, uint32_t status);
|
||||
|
@ -121,6 +124,7 @@ class NotifyQt: public QObject, public NotifyClient
|
|||
void diskFull(int,int) const ;
|
||||
void peerStatusChanged(const QString& /* peer_id */, int /* status */);
|
||||
void peerStatusChangedSummary() const;
|
||||
void gxsChange(const RsGxsChanges& /* changes */);
|
||||
#ifdef REMOVE
|
||||
void publicChatChanged(int type) const ;
|
||||
void privateChatChanged(int list, int type) const ;
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
//#include <QTimer>
|
||||
#include <QMap>
|
||||
|
||||
#include "RsGxsUpdateBroadcast.h"
|
||||
#include "RsProtectedTimer.h"
|
||||
#include "gui/notifyqt.h"
|
||||
|
||||
#include <retroshare/rsgxsifacehelper.h>
|
||||
|
||||
// previously gxs allowed only one event consumer to poll for changes
|
||||
// this required a single broadcast instance per service
|
||||
// now the update notify works through rsnotify and notifyqt
|
||||
// so the single instance per service is not really needed anymore
|
||||
|
||||
QMap<RsGxsIfaceHelper*, RsGxsUpdateBroadcast*> 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()));
|
||||
connect(NotifyQt::getInstance(), SIGNAL(gxsChange(RsGxsChanges)), this, SLOT(onChangesReceived(RsGxsChanges)));
|
||||
}
|
||||
|
||||
void RsGxsUpdateBroadcast::cleanup()
|
||||
|
@ -36,34 +37,24 @@ RsGxsUpdateBroadcast *RsGxsUpdateBroadcast::get(RsGxsIfaceHelper *ifaceImpl)
|
|||
|
||||
RsGxsUpdateBroadcast *updateBroadcast = new RsGxsUpdateBroadcast(ifaceImpl);
|
||||
updateBroadcastMap.insert(ifaceImpl, updateBroadcast);
|
||||
updateBroadcast->poll();
|
||||
|
||||
return updateBroadcast;
|
||||
}
|
||||
|
||||
void RsGxsUpdateBroadcast::poll()
|
||||
void RsGxsUpdateBroadcast::onChangesReceived(const RsGxsChanges& changes)
|
||||
{
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgsMeta;
|
||||
std::list<RsGxsGroupId> grps;
|
||||
std::list<RsGxsGroupId> grpsMeta;
|
||||
if(changes.mService != mIfaceImpl->getTokenService())
|
||||
return;
|
||||
|
||||
if (mIfaceImpl->updated(true, true))
|
||||
{
|
||||
mIfaceImpl->msgsChanged(msgs, msgsMeta);
|
||||
if (!msgs.empty() || !msgsMeta.empty())
|
||||
{
|
||||
emit msgsChanged(msgs, msgsMeta);
|
||||
}
|
||||
if (!changes.mMsgs.empty() || !changes.mMsgsMeta.empty())
|
||||
{
|
||||
emit msgsChanged(changes.mMsgs, changes.mMsgsMeta);
|
||||
}
|
||||
|
||||
mIfaceImpl->groupsChanged(grps, grpsMeta);
|
||||
if (!grps.empty() || !grpsMeta.empty())
|
||||
{
|
||||
emit grpsChanged(grps, grpsMeta);
|
||||
}
|
||||
if (!changes.mGrps.empty() || !changes.mGrpsMeta.empty())
|
||||
{
|
||||
emit grpsChanged(changes.mGrps, changes.mGrpsMeta);
|
||||
}
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
mTimer->start();
|
||||
emit changed();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <retroshare/rsgxsifacetypes.h>
|
||||
|
||||
class RsGxsIfaceHelper;
|
||||
class QTimer;
|
||||
class RsGxsChanges;
|
||||
|
||||
class RsGxsUpdateBroadcast : public QObject
|
||||
{
|
||||
|
@ -23,14 +23,13 @@ signals:
|
|||
void grpsChanged(const std::list<RsGxsGroupId>& grpIds, const std::list<RsGxsGroupId>& grpIdsMeta);
|
||||
|
||||
private slots:
|
||||
void poll();
|
||||
void onChangesReceived(const RsGxsChanges& changes);
|
||||
|
||||
private:
|
||||
explicit RsGxsUpdateBroadcast(RsGxsIfaceHelper* ifaceImpl);
|
||||
|
||||
private:
|
||||
RsGxsIfaceHelper* mIfaceImpl;
|
||||
QTimer *mTimer;
|
||||
};
|
||||
|
||||
#endif // RSGXSUPDATEBROADCAST_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue