Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/iptux/UiCoreThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "config.h"
#include "UiCoreThread.h"

#include <cinttypes>
#include <sys/socket.h>
#include <sys/stat.h>

Expand Down Expand Up @@ -111,6 +110,20 @@
}
}

struct UiCoreThreadCtx {
UiCoreThread* self;
PalKey key;
};

static gboolean iptux_uithread_update_pal_to_list(gpointer data) {
auto* ctx = (UiCoreThreadCtx*)data;
ctx->self->Lock();
ctx->self->UpdatePalToListInUI(ctx->key);
ctx->self->Unlock();
delete ctx;
return G_SOURCE_REMOVE;
}
Comment thread
Copilot marked this conversation as resolved.

/**
* 通告指定的好友信息数据已经被更新(非UI线程安全).
* @param ipv4 ipv4
Expand All @@ -121,84 +134,88 @@
*/
void UiCoreThread::UpdatePalToList(PalKey palKey) {
CoreThread::UpdatePalToList(palKey);
UiCoreThreadCtx* ctx = new UiCoreThreadCtx{this, palKey};
g_main_context_invoke(NULL, iptux_uithread_update_pal_to_list, ctx);
}

void UiCoreThread::UpdatePalToListInUI(PalKey palKey) {
PPalInfo ppal;
GroupInfo* grpinf;
SessionAbstract* session;

/* 如果好友链表中不存在此好友,则视为程序设计出错 */
if (!(ppal = GetPal(palKey))) {
return;
}

auto pal = ppal.get();

/* 更新好友所在的群组,以及它在UI上的信息 */
/*/* 更新常规模式下的群组 */
if ((grpinf = GetPalRegularItem(pal))) {
if (!grpinf->hasPal(pal)) {
AttachPalToGroupInfoItem(grpinf, ppal);
} else if (grpinf->getDialog()) {
session = (SessionAbstract*)g_object_get_data(
G_OBJECT(grpinf->getDialog()), "session-class");
session->UpdatePalData(pal);
}
} else {
if (!(grpinf = GetPalRegularItem(pal)))
grpinf = AttachPalRegularItem(ppal);
AttachPalToGroupInfoItem(grpinf, ppal);
}
/*/* 更新网段模式下的群组 */
if ((grpinf = GetPalSegmentItem(pal))) {
if (!grpinf->hasPal(pal)) {
AttachPalToGroupInfoItem(grpinf, ppal);
} else if (grpinf->getDialog()) {
session = (SessionAbstract*)g_object_get_data(
G_OBJECT(grpinf->getDialog()), "session-class");
session->UpdatePalData(pal);
}
} else {
if (!(grpinf = GetPalSegmentItem(pal)))
grpinf = AttachPalSegmentItem(ppal);
AttachPalToGroupInfoItem(grpinf, ppal);
}
/*/* 更新分组模式下的群组 */
if ((grpinf = GetPalPrevGroupItem(pal))) {
if (strcmp(grpinf->name().c_str(), pal->getGroup().c_str()) != 0) {
DelPalFromGroupInfoItem(grpinf, pal);
if (!(grpinf = GetPalGroupItem(pal)))
grpinf = AttachPalGroupItem(ppal);
AttachPalToGroupInfoItem(grpinf, ppal);
} else if (grpinf->getDialog()) {
session = (SessionAbstract*)g_object_get_data(
G_OBJECT(grpinf->getDialog()), "session-class");
session->UpdatePalData(pal);
}
} else {
if (!(grpinf = GetPalGroupItem(pal)))
grpinf = AttachPalGroupItem(ppal);
AttachPalToGroupInfoItem(grpinf, ppal);
}
/*/* 更新广播模式下的群组 */
if ((grpinf = GetPalBroadcastItem(pal))) {
if (!grpinf->hasPal(pal)) {
AttachPalToGroupInfoItem(grpinf, ppal);
} else if (grpinf->getDialog()) {
session = (SessionAbstract*)g_object_get_data(
G_OBJECT(grpinf->getDialog()), "session-class");
session->UpdatePalData(pal);
}
} else {
if (!(grpinf = GetPalBroadcastItem(pal)))
grpinf = AttachPalBroadcastItem(ppal);
AttachPalToGroupInfoItem(grpinf, ppal);
}
}

/**
* 将好友信息数据加入到好友链表(非UI线程安全).
* @param pal class PalInfo
* @note 鉴于在线的好友必须被分配到它所属的群组,所以加入好友到好友链表的同时

Check notice on line 218 in src/iptux/UiCoreThread.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/iptux/UiCoreThread.cpp#L139-L218

Complex Method
* 也应该分配好友到相应的群组
*/
void UiCoreThread::AttachPalToList(shared_ptr<PalInfo> pal2) {
Expand Down
1 change: 1 addition & 0 deletions src/iptux/UiCoreThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class UiCoreThread : public CoreThread {

void ClearAllPalFromList() override;
void UpdatePalToList(PalKey palKey) override;
void UpdatePalToListInUI(PalKey palKey);
void UpdatePalToList(in_addr ipv4) override {
UpdatePalToList(PalKey(ipv4, port()));
}
Comment on lines 46 to 51
Expand Down
2 changes: 2 additions & 0 deletions src/iptux/UiCoreThreadTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Application.h"
#include "gtest/gtest.h"

#include "iptux-utils/utils.h"
#include "iptux/TestHelper.h"
#include "iptux/UiCoreThread.h"

Expand All @@ -17,6 +18,7 @@ TEST(UiCoreThread, Constructor) {
UiCoreThread* thread = new UiCoreThread(app, core);
thread->setIgnoreTcpBindFailed(true);
thread->start();
thread->UpdatePalToList(PalKey(inAddrFromString("127.0.0.1"), 2425));
thread->stop();
delete thread;
DestroyApplication(app);
Expand Down
Loading