changed RsEvents so that it takes event types when registering handlers, which limits the number of handlers called for each event

This commit is contained in:
csoler 2019-12-29 13:50:54 +01:00
parent dc2f2f5eb4
commit c544b1da7c
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
19 changed files with 186 additions and 140 deletions

View file

@ -52,26 +52,23 @@ GxsChannelDialog::GxsChannelDialog(QWidget *parent)
{
mEventHandlerId = 0;
// 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)
{
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)
return;
if(!e)
return;
switch(e->mChannelEventCode)
{
case RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true);
break;
default:
break;
}
}
switch(e->mChannelEventCode)
{
case RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true);
break;
default:
break;
}
}
GxsChannelDialog::~GxsChannelDialog()

View file

@ -132,31 +132,28 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid
mEventHandlerId = 0;
// 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)
{
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)
return;
if(!e)
return;
switch(e->mChannelEventCode)
{
case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL:
case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL:
case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE:
case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE:
if(e->mChannelGroupId == mChannelGroupId)
updateDisplay(true);
break;
default:
break;
}
}
switch(e->mChannelEventCode)
{
case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL:
case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL:
case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE:
case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE:
if(e->mChannelGroupId == mChannelGroupId)
updateDisplay(true);
break;
default:
break;
}
}
GxsChannelPostsWidget::~GxsChannelPostsWidget()