OCT 1. 修正状态栏更新模式

This commit is contained in:
黄昕 2023-05-05 18:33:09 +08:00
parent efb39449a9
commit 64a72d81f7
1 changed files with 18 additions and 14 deletions

View File

@ -21,6 +21,7 @@ static GtkWidget *g_statusBar = NULL;
static GtkTextBuffer *g_pTxtBuf[4]; static GtkTextBuffer *g_pTxtBuf[4];
static GtkWidget *g_ptvDHcp[4]; static GtkWidget *g_ptvDHcp[4];
static guint g_timer_id = 0; static guint g_timer_id = 0;
static PDHCP_INFO g_preInfo = NULL;
static const char *g_mess_info[] = {"NONE", "DISCOVER", "OFFER", "REQUEST", "DECLINE", static const char *g_mess_info[] = {"NONE", "DISCOVER", "OFFER", "REQUEST", "DECLINE",
"ACK", "NAK", "RELEASE", "INFORM"}; "ACK", "NAK", "RELEASE", "INFORM"};
@ -29,7 +30,6 @@ static gboolean delete_event(GtkWidget *widget, GdkEventAny *event) {
* TRUE * TRUE
* 退?*/ * 退?*/
//gtk_widget_hide_all(window_test); //gtk_widget_hide_all(window_test);
if (g_timer_id) { if (g_timer_id) {
g_source_remove(g_timer_id); g_source_remove(g_timer_id);
} }
@ -276,26 +276,25 @@ static void create_dhcp_tree_mode(PDHCP_PACKAGE p, U32 nBytes, GtkWidget *treeVi
} }
} }
static PDHCP_INFO g_preInfo = NULL; static gboolean upgrade_statusbar_proc(gpointer user_data) {
PDHCP_INFO pInfo = (PDHCP_INFO)user_data;
static gboolean timer_proc(gpointer user_data) {
int ret; int ret;
DHCP_OPT opt; DHCP_OPT opt;
char buf[1024] = {0}; char buf[1024] = {0};
S32 tmOffer = 0, tmAck = 0; S32 tmOffer = 0, tmAck = 0;
const char *pIp = NULL, *pNetmask = NULL, *pGw = NULL, *pDns1 = NULL, *pDns2 = NULL; const char *pIp = NULL, *pNetmask = NULL, *pGw = NULL, *pDns1 = NULL, *pDns2 = NULL;
if (g_preInfo) { if (pInfo) {
tmOffer = MAX(0, tmOffer = MAX(0,
(g_preInfo->pOfferBuf.tm.tv_sec * 1000000 + g_preInfo->pOfferBuf.tm.tv_usec) - (pInfo->pOfferBuf.tm.tv_sec * 1000000 + pInfo->pOfferBuf.tm.tv_usec) -
(g_preInfo->pDiscBuf.tm.tv_sec * 1000000 + g_preInfo->pDiscBuf.tm.tv_usec)); (pInfo->pDiscBuf.tm.tv_sec * 1000000 + pInfo->pDiscBuf.tm.tv_usec));
tmAck = MAX(0, tmAck = MAX(0,
(g_preInfo->pAckBuf.tm.tv_sec * 1000000 + g_preInfo->pAckBuf.tm.tv_usec) - (pInfo->pAckBuf.tm.tv_sec * 1000000 + pInfo->pAckBuf.tm.tv_usec) -
(g_preInfo->pReqBuf.tm.tv_sec * 1000000 + g_preInfo->pReqBuf.tm.tv_usec)); (pInfo->pReqBuf.tm.tv_sec * 1000000 + pInfo->pReqBuf.tm.tv_usec));
if (g_preInfo->pAckBuf.p) { if (pInfo->pAckBuf.p) {
PDHCP_PACKAGE pkg = (PDHCP_PACKAGE)g_preInfo->pAckBuf.p; PDHCP_PACKAGE pkg = (PDHCP_PACKAGE)pInfo->pAckBuf.p;
U32 optSize = g_preInfo->pAckBuf.buf_size - sizeof(DHCP_PACKAGE); U32 optSize = pInfo->pAckBuf.buf_size - sizeof(DHCP_PACKAGE);
pIp = u32_to_str_ip_safe(pkg->dhcp.yiaddr); pIp = u32_to_str_ip_safe(pkg->dhcp.yiaddr);
ret = dhcp_get_option(OPT_NETMASK, pkg->dhcp.options, optSize, &opt); ret = dhcp_get_option(OPT_NETMASK, pkg->dhcp.options, optSize, &opt);
@ -318,6 +317,8 @@ static gboolean timer_proc(gpointer user_data) {
pDns2 = u32_to_str_ip_safe(*pVal); pDns2 = u32_to_str_ip_safe(*pVal);
} }
} }
g_source_remove(g_timer_id);
} }
} }
@ -428,9 +429,11 @@ void details_wnd_show(PDHCP_INFO pInfo) {
add_dhcp_tree_colums(g_ptvDHcp[i]); add_dhcp_tree_colums(g_ptvDHcp[i]);
create_dhcp_tree_mode((PDHCP_PACKAGE)hexBuf[i]->p, hexBuf[i]->buf_size, g_ptvDHcp[i]); create_dhcp_tree_mode((PDHCP_PACKAGE)hexBuf[i]->p, hexBuf[i]->buf_size, g_ptvDHcp[i]);
} }
upgrade_statusbar_proc(pInfo);
} }
g_timer_id = g_timeout_add(1000, (GSourceFunc)timer_proc, NULL); g_timer_id = g_timeout_add(1000, (GSourceFunc)upgrade_statusbar_proc, NULL);
gtk_widget_show_all(g_detailWnd); gtk_widget_show_all(g_detailWnd);
} }
@ -460,6 +463,7 @@ void switch_page(GtkNotebook *UNUSED(self),
gpointer UNUSED(user_data)) { gpointer UNUSED(user_data)) {
if (g_preInfo) { if (g_preInfo) {
details_wnd_show(g_preInfo); details_wnd_show(g_preInfo);
upgrade_statusbar_proc(g_preInfo);
} }
} }
@ -558,7 +562,7 @@ void details_wnd_create(GtkBuilder *builder) {
} }
g_statusBar = gtk_statusbar_new(); g_statusBar = gtk_statusbar_new();
gtk_box_pack_start(GTK_BOX(vBox), g_statusBar, FALSE, FALSE, 1); gtk_box_pack_start(GTK_BOX(vBox), g_statusBar, FALSE, FALSE, 0);
//gtk_widget_set_size_request(vBox, -1, 16); //gtk_widget_set_size_request(vBox, -1, 16);
g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), builder); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), builder);