Merge pull request #1748 from csoler/v0.6-ImprovedGUI_2

V0.6 improved gui 2
This commit is contained in:
csoler 2020-01-17 22:14:49 +01:00 committed by GitHub
commit 26df59971f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 155 additions and 95 deletions

View File

@ -111,6 +111,7 @@ p3discovery2::p3discovery2(
if(rsEvents) if(rsEvents)
rsEvents->registerEventsHandler( rsEvents->registerEventsHandler(
RsEventType::GOSSIP_DISCOVERY,
[this](std::shared_ptr<const RsEvent> event) [this](std::shared_ptr<const RsEvent> event)
{ {
rsEventsHandler(*event); rsEventsHandler(*event);
@ -1345,8 +1346,3 @@ void p3discovery2::rsEventsHandler(const RsEvent& event)
// //
// /* ignore other operations */ // /* ignore other operations */
// } // }
// (cyril) do we still need this??
RsGossipDiscoveryFriendInviteReceivedEvent::RsGossipDiscoveryFriendInviteReceivedEvent(const std::string& invite) :
RsEvent(RsEventType::GOSSIP_DISCOVERY_INVITE_RECEIVED),
mInvite(invite) {}

View File

@ -331,6 +331,15 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"),
rsEvents, "rsEvents", cAns, session ) ) rsEvents, "rsEvents", cAns, session ) )
return; return;
RsEventType eventType = RsEventType::NONE;
// deserialize input parameters from JSON
{
RsGenericSerializer::SerializeContext& ctx(cReq);
RsGenericSerializer::SerializeJob j(RsGenericSerializer::FROM_JSON);
RS_SERIAL_PROCESS(eventType);
}
const std::weak_ptr<rb::Session> weakSession(session); const std::weak_ptr<rb::Session> weakSession(session);
RsEventsHandlerId_t hId = rsEvents->generateUniqueHandlerId(); RsEventsHandlerId_t hId = rsEvents->generateUniqueHandlerId();
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback = std::function<void(std::shared_ptr<const RsEvent>)> multiCallback =
@ -365,7 +374,7 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"),
} ); } );
}; };
bool retval = rsEvents->registerEventsHandler(multiCallback, hId); bool retval = rsEvents->registerEventsHandler(eventType,multiCallback, hId);
{ {
RsGenericSerializer::SerializeContext& ctx(cAns); RsGenericSerializer::SerializeContext& ctx(cAns);

View File

@ -71,23 +71,32 @@ struct RsBroadcastDiscoveryResult : RsSerializable
* @brief Event emitted when a non friend new peer is found in the local network * @brief Event emitted when a non friend new peer is found in the local network
* @see RsEvents * @see RsEvents
*/ */
struct RsBroadcastDiscoveryPeerFoundEvent : RsEvent enum class RsBroadcastDiscoveryEventType: uint32_t {
{ UNKNOWN = 0x00,
RsBroadcastDiscoveryPeerFoundEvent( PEER_FOUND = 0x01
const RsBroadcastDiscoveryResult& eventData ) : };
RsEvent(RsEventType::BROADCAST_DISCOVERY_PEER_FOUND), mData(eventData) {}
RsBroadcastDiscoveryResult mData; struct RsBroadcastDiscoveryEvent : RsEvent
{
RsBroadcastDiscoveryEvent()
: RsEvent(RsEventType::BROADCAST_DISCOVERY),
mDiscoveryEventType(RsBroadcastDiscoveryEventType::UNKNOWN)
{}
virtual ~RsBroadcastDiscoveryEvent() override = default;
RsBroadcastDiscoveryEventType mDiscoveryEventType;
RsBroadcastDiscoveryResult mData;
/// @see RsSerializable /// @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j, void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx) override RsGenericSerializer::SerializeContext& ctx) override
{ {
RsEvent::serial_process(j, ctx); RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mDiscoveryEventType);
RS_SERIAL_PROCESS(mData); RS_SERIAL_PROCESS(mData);
} }
~RsBroadcastDiscoveryPeerFoundEvent() override;
}; };

View File

@ -53,10 +53,10 @@ enum class RsEventType : uint32_t
NONE = 0, /// Used to detect uninitialized event NONE = 0, /// Used to detect uninitialized event
/// @see RsBroadcastDiscovery /// @see RsBroadcastDiscovery
BROADCAST_DISCOVERY_PEER_FOUND = 1, BROADCAST_DISCOVERY = 1,
/// @see RsDiscPendingPgpReceivedEvent /// @see RsDiscPendingPgpReceivedEvent
GOSSIP_DISCOVERY_INVITE_RECEIVED = 2, GOSSIP_DISCOVERY = 2,
/// @see AuthSSL /// @see AuthSSL
AUTHSSL_CONNECTION_AUTENTICATION = 3, AUTHSSL_CONNECTION_AUTENTICATION = 3,
@ -64,14 +64,14 @@ enum class RsEventType : uint32_t
/// @see pqissl /// @see pqissl
PEER_CONNECTION = 4, PEER_CONNECTION = 4,
/// @see RsGxsChanges /// @see RsGxsChanges // this one is used in RsGxsBroadcast
GXS_CHANGES = 5, GXS_CHANGES = 5,
/// Emitted when a peer state changes, @see RsPeers /// Emitted when a peer state changes, @see RsPeers
PEER_STATE_CHANGED = 6, PEER_STATE_CHANGED = 6,
/// @see RsMailStatusEvent /// @see RsMailStatusEvent
MAIL_STATUS_CHANGE = 7, MAIL_STATUS = 7,
/// @see RsGxsCircleEvent /// @see RsGxsCircleEvent
GXS_CIRCLES = 8, GXS_CIRCLES = 8,
@ -163,6 +163,7 @@ public:
* Every time an event is dispatced the registered events handlers will get * Every time an event is dispatced the registered events handlers will get
* their method handleEvent called with the event passed as paramether. * their method handleEvent called with the event passed as paramether.
* @jsonapi{development,manualwrapper} * @jsonapi{development,manualwrapper}
* @param eventType Type of event for which the callback is called
* @param multiCallback Function that will be called each time an event * @param multiCallback Function that will be called each time an event
* is dispatched. * is dispatched.
* @param[inout] hId Optional storage for handler id, useful to * @param[inout] hId Optional storage for handler id, useful to
@ -173,6 +174,7 @@ public:
* @return False on error, true otherwise. * @return False on error, true otherwise.
*/ */
virtual bool registerEventsHandler( virtual bool registerEventsHandler(
RsEventType eventType,
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback, std::function<void(std::shared_ptr<const RsEvent>)> multiCallback,
RsEventsHandlerId_t& hId = RS_DEFAULT_STORAGE_PARAM(RsEventsHandlerId_t, 0) RsEventsHandlerId_t& hId = RS_DEFAULT_STORAGE_PARAM(RsEventsHandlerId_t, 0)
) = 0; ) = 0;

View File

@ -45,11 +45,18 @@ extern std::shared_ptr<RsGossipDiscovery> rsGossipDiscovery;
/** /**
* @brief Emitted when a pending PGP certificate is received * @brief Emitted when a pending PGP certificate is received
*/ */
struct RsGossipDiscoveryFriendInviteReceivedEvent : RsEvent
{
RsGossipDiscoveryFriendInviteReceivedEvent(
const std::string& invite );
enum class RsGossipDiscoveryEventType: uint32_t {
UNKNOWN = 0x00,
PEER_INVITE_RECEIVED = 0x01
};
struct RsGossipDiscoveryEvent : RsEvent
{
RsGossipDiscoveryEvent(): RsEvent(RsEventType::GOSSIP_DISCOVERY) {}
virtual ~RsGossipDiscoveryEvent() override {}
RsGossipDiscoveryEventType mGossipDiscoveryEventType;
std::string mInvite; std::string mInvite;
/// @see RsSerializable /// @see RsSerializable
@ -57,6 +64,7 @@ struct RsGossipDiscoveryFriendInviteReceivedEvent : RsEvent
RsGenericSerializer::SerializeContext& ctx ) RsGenericSerializer::SerializeContext& ctx )
{ {
RsEvent::serial_process(j,ctx); RsEvent::serial_process(j,ctx);
RS_SERIAL_PROCESS(mGossipDiscoveryEventType);
RS_SERIAL_PROCESS(mInvite); RS_SERIAL_PROCESS(mInvite);
} }
}; };

View File

@ -296,7 +296,6 @@ struct MsgTagType : RsSerializable
} //namespace Rs } //namespace Rs
} //namespace Msgs } //namespace Msgs
enum class RsMailStatusEventCode: uint8_t enum class RsMailStatusEventCode: uint8_t
{ {
NEW_MESSAGE = 0x00, NEW_MESSAGE = 0x00,
@ -312,9 +311,9 @@ enum class RsMailStatusEventCode: uint8_t
struct RsMailStatusEvent : RsEvent struct RsMailStatusEvent : RsEvent
{ {
RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS_CHANGE) {} RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS) {}
RsMailStatusEventCode mMailStatusEventCode; RsMailStatusEventCode mMailStatusEventCode;
std::set<RsMailMessageId> mChangedMsgIds; std::set<RsMailMessageId> mChangedMsgIds;
/// @see RsEvent /// @see RsEvent
@ -326,7 +325,7 @@ struct RsMailStatusEvent : RsEvent
RS_SERIAL_PROCESS(mMailStatusEventCode); RS_SERIAL_PROCESS(mMailStatusEventCode);
} }
~RsMailStatusEvent() override; ~RsMailStatusEvent() override = default;
}; };
#define RS_CHAT_PUBLIC 0x0001 #define RS_CHAT_PUBLIC 0x0001
@ -335,7 +334,7 @@ struct RsMailStatusEvent : RsEvent
#define RS_DISTANT_CHAT_STATUS_UNKNOWN 0x0000 #define RS_DISTANT_CHAT_STATUS_UNKNOWN 0x0000
#define RS_DISTANT_CHAT_STATUS_TUNNEL_DN 0x0001 #define RS_DISTANT_CHAT_STATUS_TUNNEL_DN 0x0001
#define RS_DISTANT_CHAT_STATUS_CAN_TALK 0x0002 #define RS_DISTANT_CHAT_STATUS_CAN_TALK 0x0002
#define RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED 0x0003 #define RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED 0x0003
#define RS_DISTANT_CHAT_ERROR_NO_ERROR 0x0000 #define RS_DISTANT_CHAT_ERROR_NO_ERROR 0x0000

View File

@ -33,8 +33,8 @@ void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsG
// and do not expect to deserialize mImage member if the data block has been consummed entirely (keeps compatibility // and do not expect to deserialize mImage member if the data block has been consummed entirely (keeps compatibility
// of new RS with older posts. // of new RS with older posts.
if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize) if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize)
return ; return ;
if((j == RsGenericSerializer::SIZE_ESTIMATE || j == RsGenericSerializer::SERIALIZE) && mImage.empty()) if((j == RsGenericSerializer::SIZE_ESTIMATE || j == RsGenericSerializer::SERIALIZE) && mImage.empty())
return ; return ;

View File

@ -538,8 +538,7 @@ bool p3Msgs::initiateDistantChatConnexion(
const RsGxsId& to_gxs_id, const RsGxsId& from_gxs_id, const RsGxsId& to_gxs_id, const RsGxsId& from_gxs_id,
DistantChatPeerId& pid, uint32_t& error_code, bool notify ) DistantChatPeerId& pid, uint32_t& error_code, bool notify )
{ {
return mChatSrv->initiateDistantChatConnexion( to_gxs_id, from_gxs_id, return mChatSrv->initiateDistantChatConnexion( to_gxs_id, from_gxs_id, pid, error_code, notify );
pid, error_code, notify );
} }
bool p3Msgs::getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info) bool p3Msgs::getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)
{ {
@ -559,7 +558,6 @@ uint32_t p3Msgs::getDistantChatPermissionFlags()
} }
RsMsgs::~RsMsgs() = default; RsMsgs::~RsMsgs() = default;
RsMailStatusEvent::~RsMailStatusEvent() = default;
Rs::Msgs::MessageInfo::~MessageInfo() = default; Rs::Msgs::MessageInfo::~MessageInfo() = default;
MsgInfoSummary::~MsgInfoSummary() = default; MsgInfoSummary::~MsgInfoSummary() = default;
VisibleChatLobbyRecord::~VisibleChatLobbyRecord() = default; VisibleChatLobbyRecord::~VisibleChatLobbyRecord() = default;

View File

@ -182,10 +182,15 @@ void BroadcastDiscoveryService::threadTick()
} }
else if(!isFriend) else if(!isFriend)
{ {
typedef RsBroadcastDiscoveryPeerFoundEvent Evt_t;
if(rsEvents) if(rsEvents)
rsEvents->postEvent( {
std::shared_ptr<Evt_t>(new Evt_t(rbdr)) ); auto ev = std::make_shared<RsBroadcastDiscoveryEvent>();
ev->mDiscoveryEventType = RsBroadcastDiscoveryEventType::PEER_FOUND;
ev->mData = rbdr;
rsEvents->postEvent(ev);
}
} }
} }
} }
@ -307,5 +312,4 @@ bool BroadcastDiscoveryService::assertMulticastLockIsvalid()
RsBroadcastDiscovery::~RsBroadcastDiscovery() = default; RsBroadcastDiscovery::~RsBroadcastDiscovery() = default;
RsBroadcastDiscoveryResult::~RsBroadcastDiscoveryResult() = default; RsBroadcastDiscoveryResult::~RsBroadcastDiscoveryResult() = default;
RsBroadcastDiscoveryPeerFoundEvent::~RsBroadcastDiscoveryPeerFoundEvent() = default;
BroadcastDiscoveryPack::~BroadcastDiscoveryPack() = default; BroadcastDiscoveryPack::~BroadcastDiscoveryPack() = default;

View File

@ -100,22 +100,42 @@ RsEventsHandlerId_t RsEventsService::generateUniqueHandlerId_unlocked()
} }
bool RsEventsService::registerEventsHandler( bool RsEventsService::registerEventsHandler(
RsEventType eventType,
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback, std::function<void(std::shared_ptr<const RsEvent>)> multiCallback,
RsEventsHandlerId_t& hId ) RsEventsHandlerId_t& hId )
{ {
RS_STACK_MUTEX(mHandlerMapMtx); RS_STACK_MUTEX(mHandlerMapMtx);
if(!hId) hId = generateUniqueHandlerId_unlocked();
mHandlerMap[hId] = multiCallback; if( (int)eventType > mHandlerMaps.size() + 10)
{
RsErr() << "Cannot register an event handler for an event type larger than 10 plus the max pre-defined event (value passed was " << (int)eventType << " whereas max is " << (int)RsEventType::MAX << ")" << std::endl;
return false;
}
if( (int)eventType >= mHandlerMaps.size())
mHandlerMaps.resize( (int)eventType +1 );
if(!hId)
hId = generateUniqueHandlerId_unlocked();
mHandlerMaps[(int)eventType][hId] = multiCallback;
return true; return true;
} }
bool RsEventsService::unregisterEventsHandler(RsEventsHandlerId_t hId) bool RsEventsService::unregisterEventsHandler(RsEventsHandlerId_t hId)
{ {
RS_STACK_MUTEX(mHandlerMapMtx); RS_STACK_MUTEX(mHandlerMapMtx);
auto it = mHandlerMap.find(hId);
if(it == mHandlerMap.end()) return false; for(uint32_t i=0;i<mHandlerMaps.size();++i)
mHandlerMap.erase(it); {
return true; auto it = mHandlerMaps[i].find(hId);
if(it != mHandlerMaps[i].end())
{
mHandlerMaps[i].erase(it);
return true;
}
}
return false;
} }
void RsEventsService::threadTick() void RsEventsService::threadTick()
@ -156,23 +176,25 @@ void RsEventsService::handleEvent(std::shared_ptr<const RsEvent> event)
{ {
std::function<void(std::shared_ptr<const RsEvent>)> mCallback; std::function<void(std::shared_ptr<const RsEvent>)> mCallback;
mHandlerMapMtx.lock(); uint32_t event_type_index = static_cast<uint32_t>(event->mType);
auto cbpt = mHandlerMap.begin();
mHandlerMapMtx.unlock();
getHandlerFromMapLock:
mHandlerMapMtx.lock();
if(cbpt != mHandlerMap.end())
{ {
mCallback = cbpt->second; RS_STACK_MUTEX(mHandlerMapMtx); /* LOCKED AREA */
++cbpt;
}
mHandlerMapMtx.unlock();
if(mCallback) if(event_type_index >= mHandlerMaps.size() || event_type_index < 1)
{ {
mCallback(event); // It is relevant that this happens outside mutex RsErr() << "Cannot handle an event of type " << event_type_index << ": out of scope!" << std::endl;
mCallback = std::function<void(std::shared_ptr<const RsEvent>)>(nullptr); return;
goto getHandlerFromMapLock; }
// Call all clients that registered a callback for this event type
for(auto cbit: mHandlerMaps[event_type_index])
cbit.second(event);
// Also call all clients that registered with NONE, meaning that they expect all events
for(auto cbit: mHandlerMaps[static_cast<uint32_t>(RsEventType::NONE)])
cbit.second(event);
} }
} }

View File

@ -35,6 +35,7 @@ class RsEventsService :
public: public:
RsEventsService(): RsEventsService():
mHandlerMapMtx("RsEventsService::mHandlerMapMtx"), mLastHandlerId(1), mHandlerMapMtx("RsEventsService::mHandlerMapMtx"), mLastHandlerId(1),
mHandlerMaps(static_cast<int>(RsEventType::MAX)),
mEventQueueMtx("RsEventsService::mEventQueueMtx") {} mEventQueueMtx("RsEventsService::mEventQueueMtx") {}
/// @see RsEvents /// @see RsEvents
@ -54,6 +55,7 @@ public:
/// @see RsEvents /// @see RsEvents
bool registerEventsHandler( bool registerEventsHandler(
RsEventType eventType,
std::function<void(std::shared_ptr<const RsEvent>)> multiCallback, std::function<void(std::shared_ptr<const RsEvent>)> multiCallback,
RsEventsHandlerId_t& hId = RS_DEFAULT_STORAGE_PARAM(RsEventsHandlerId_t, 0) RsEventsHandlerId_t& hId = RS_DEFAULT_STORAGE_PARAM(RsEventsHandlerId_t, 0)
) override; ) override;
@ -64,9 +66,11 @@ public:
protected: protected:
RsMutex mHandlerMapMtx; RsMutex mHandlerMapMtx;
RsEventsHandlerId_t mLastHandlerId; RsEventsHandlerId_t mLastHandlerId;
std::map<
RsEventsHandlerId_t, std::vector<
std::function<void(std::shared_ptr<const RsEvent>)> > mHandlerMap; std::map<
RsEventsHandlerId_t,
std::function<void(std::shared_ptr<const RsEvent>)> > > mHandlerMaps;
RsMutex mEventQueueMtx; RsMutex mEventQueueMtx;
std::deque< std::shared_ptr<const RsEvent> > mEventQueue; std::deque< std::shared_ptr<const RsEvent> > mEventQueue;

View File

@ -1886,11 +1886,15 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
// because there is not too much file hashes to be active at a time, // because there is not too much file hashes to be active at a time,
// and this mostly prevents from sending the hash back in the tunnel. // and this mostly prevents from sending the hash back in the tunnel.
bool found = false ; #ifdef P3TURTLE_DEBUG
bool ext_found = false ;
#endif
for(std::map<TurtleFileHash,TurtleHashInfo>::iterator it(_incoming_file_hashes.begin());it!=_incoming_file_hashes.end();++it) for(std::map<TurtleFileHash,TurtleHashInfo>::iterator it(_incoming_file_hashes.begin());it!=_incoming_file_hashes.end();++it)
if(it->second.last_request == item->request_id) if(it->second.last_request == item->request_id)
{ {
found = true ; #ifdef P3TURTLE_DEBUG
ext_found = true ;
#endif
{ {
// add the tunnel uniquely // add the tunnel uniquely
@ -1917,7 +1921,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
} }
} }
#ifdef P3TURTLE_DEBUG #ifdef P3TURTLE_DEBUG
if(!found) if(!ext_found)
std::cerr << "p3turtle: error. Could not find hash that emmitted tunnel request " << reinterpret_cast<void*>(item->tunnel_id) << std::endl ; std::cerr << "p3turtle: error. Could not find hash that emmitted tunnel request " << reinterpret_cast<void*>(item->tunnel_id) << std::endl ;
#endif #endif
} }

View File

@ -72,8 +72,21 @@ static NewsFeed *instance = NULL;
/** Constructor */ /** Constructor */
NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed) NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed)
{ {
mEventHandlerId =0; // needed to force intialization by registerEventsHandler() mEventTypes = {
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId ); RsEventType::AUTHSSL_CONNECTION_AUTENTICATION,
RsEventType::PEER_CONNECTION ,
RsEventType::GXS_CIRCLES ,
RsEventType::GXS_CHANNELS ,
RsEventType::GXS_FORUMS ,
RsEventType::GXS_POSTED ,
RsEventType::MAIL_STATUS
};
for(uint32_t i=0;i<mEventTypes.size();++i)
{
mEventHandlerIds.push_back(0); // needed to force intialization by registerEventsHandler()
rsEvents->registerEventsHandler(mEventTypes[i], [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerIds.back() );
}
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui->setupUi(this); ui->setupUi(this);
@ -117,7 +130,8 @@ QString hlp_str = tr(
NewsFeed::~NewsFeed() NewsFeed::~NewsFeed()
{ {
rsEvents->unregisterEventsHandler(mEventHandlerId); for(uint32_t i=0;i<mEventHandlerIds.size();++i)
rsEvents->unregisterEventsHandler(mEventHandlerIds[i]);
// save settings // save settings
processSettings(false); processSettings(false);
@ -190,7 +204,7 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED)) if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED))
handleMailEvent(event); handleMailEvent(event);
if(event->mType == RsEventType::MAIL_STATUS_CHANGE && (flags & RS_FEED_TYPE_MSG)) if(event->mType == RsEventType::MAIL_STATUS && (flags & RS_FEED_TYPE_MSG))
handlePostedEvent(event); handlePostedEvent(event);
} }
@ -200,6 +214,7 @@ void NewsFeed::handleMailEvent(std::shared_ptr<const RsEvent> event)
dynamic_cast<const RsMailStatusEvent*>(event.get()); dynamic_cast<const RsMailStatusEvent*>(event.get());
if(!pe) return; if(!pe) return;
switch(pe->mMailStatusEventCode) switch(pe->mMailStatusEventCode)
{ {
case RsMailStatusEventCode::NEW_MESSAGE: case RsMailStatusEventCode::NEW_MESSAGE:

View File

@ -118,7 +118,8 @@ private:
/* UI - from Designer */ /* UI - from Designer */
Ui::NewsFeed *ui; Ui::NewsFeed *ui;
RsEventsHandlerId_t mEventHandlerId; std::vector<RsEventsHandlerId_t> mEventHandlerIds;
std::vector<RsEventType> mEventTypes;
}; };
#endif #endif

View File

@ -178,7 +178,7 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent)
ui->filterLineEdit->showFilterIcon(); ui->filterLineEdit->showFilterIcon();
mEventHandlerId=0; // forces initialization mEventHandlerId=0; // forces initialization
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId ); rsEvents->registerEventsHandler( RsEventType::PEER_CONNECTION, [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId );
mModel = new RsFriendListModel(); mModel = new RsFriendListModel();
mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this); mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this);
@ -258,13 +258,10 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent)
void NewFriendList::handleEvent(std::shared_ptr<const RsEvent> e) void NewFriendList::handleEvent(std::shared_ptr<const RsEvent> e)
{ {
if(e->mType == RsEventType::PEER_CONNECTION) // /!\ The function we're in is called from a different thread. It's very important
{ // to use this trick in order to avoid data races.
// /!\ The function we're in is called from a different thread. It's very important
// to use this trick in order to avoid data races.
RsQThreadUtils::postToObject( [=]() { forceUpdateDisplay() ; }, this ) ; RsQThreadUtils::postToObject( [=]() { forceUpdateDisplay() ; }, this ) ;
}
} }
NewFriendList::~NewFriendList() NewFriendList::~NewFriendList()

View File

@ -52,17 +52,15 @@ GxsChannelDialog::GxsChannelDialog(QWidget *parent)
{ {
mEventHandlerId = 0; mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread! // Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); rsEvents->registerEventsHandler(RsEventType::GXS_CHANNELS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
} }
void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{ {
if(event->mType == RsEventType::GXS_CHANNELS) const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
{
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
if(!e) if(!e)
return; return;
switch(e->mChannelEventCode) switch(e->mChannelEventCode)
{ {
@ -71,7 +69,6 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
default: default:
break; break;
} }
}
} }
GxsChannelDialog::~GxsChannelDialog() GxsChannelDialog::~GxsChannelDialog()

View File

@ -132,17 +132,15 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid
mEventHandlerId = 0; mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread! // Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); rsEvents->registerEventsHandler(RsEventType::GXS_CHANNELS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
} }
void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{ {
if(event->mType == RsEventType::GXS_CHANNELS) const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
{
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
if(!e) if(!e)
return; return;
switch(e->mChannelEventCode) switch(e->mChannelEventCode)
{ {
@ -156,7 +154,6 @@ void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEven
default: default:
break; break;
} }
}
} }
GxsChannelPostsWidget::~GxsChannelPostsWidget() GxsChannelPostsWidget::~GxsChannelPostsWidget()

View File

@ -436,7 +436,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
mEventHandlerId = 0; mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread! // Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); rsEvents->registerEventsHandler(RsEventType::GXS_FORUMS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
} }
void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View File

@ -45,7 +45,7 @@ GxsForumsDialog::GxsForumsDialog(QWidget *parent)
mEventHandlerId = 0; mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread! // Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); rsEvents->registerEventsHandler(RsEventType::GXS_FORUMS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
} }
void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View File

@ -39,11 +39,9 @@ RsGxsUpdateBroadcast::RsGxsUpdateBroadcast(RsGxsIfaceHelper *ifaceImpl) :
{ {
mEventHandlerId = 0; // forces initialization in registerEventsHandler() mEventHandlerId = 0; // forces initialization in registerEventsHandler()
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) rsEvents->registerEventsHandler(RsEventType::GXS_CHANGES, [this](std::shared_ptr<const RsEvent> event)
{ {
if(event->mType == RsEventType::GXS_CHANGES) onChangesReceived(*dynamic_cast<const RsGxsChanges*>(event.get()));
onChangesReceived(*dynamic_cast<const RsGxsChanges*>(event.get()));
}, mEventHandlerId ); }, mEventHandlerId );
} }