OCT 1. 暂存开发过程代码

2. DHCP 请求界面更改为树状视图
This commit is contained in:
黄昕 2023-04-25 18:46:20 +08:00
parent 47c3f0b4f6
commit 34b91e6efc
3 changed files with 124 additions and 74 deletions

View File

@ -10,6 +10,7 @@
typedef enum {
COL_INDEX = 0,
COL_VNI,
COL_MAC,
COL_HOSTNAME,
COL_DISCOVER,
@ -20,6 +21,7 @@ typedef enum {
COL_STATUS,
COL_ATTR_EDITABLE,
COL_ATTR_VISIABLE,
NUM_COLS
} COL_NAME;
@ -44,19 +46,19 @@ typedef struct {
} BUF_INFO, *PBUF_INFO;
typedef struct {
U32 index;
U32 vni;
U8 mac[6];
S8 hostname[64];
DHCP_STEP step;
DHCP_STATUS status;
BUF_INFO pDiscBuf;
BUF_INFO pOfferBuf;
BUF_INFO pReqBuf;
BUF_INFO pAckBuf;
DHCP_RSP offerRsp;
DHCP_RSP ackRsp;
UT_hash_handle hh;
U32 index;
U32 vni;
U8 mac[6];
S8 hostname[64];
DHCP_STEP step;
DHCP_STATUS status;
BUF_INFO pDiscBuf;
BUF_INFO pOfferBuf;
BUF_INFO pReqBuf;
BUF_INFO pAckBuf;
DHCP_RSP offerRsp;
DHCP_RSP ackRsp;
UT_hash_handle hh;
} DHCP_INFO, *PDHCP_INFO;
U32 rand_number();

View File

@ -3,7 +3,6 @@
//
#include <gtk/gtk.h>
#include <zlog.h>
#include "common.h"
#include "main.h"
#include "misc.h"
#include "task_manager.h"
@ -44,8 +43,7 @@ static void load_css(void) {
display = gdk_display_get_default();
screen = gdk_display_get_default_screen(display);
gtk_style_context_add_provider_for_screen(screen,
GTK_STYLE_PROVIDER(provider),
gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_css_provider_load_from_file(provider, css_fp, &error);
@ -74,40 +72,66 @@ static void tree_view_data_store_create() {
int i, j;
PDHCP_INFO pInfo, pTemp;
GtkTreeIter iter, iter_child, iter_sub;
GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "treeResult"));
GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo"));
GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "treeResult"));
GtkTreeStore *store = GTK_TREE_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo"));
GtkWidget *vniStart = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbVni"));
GtkWidget *numRequest = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbReqNum"));
int nRequest = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(numRequest));
int nVni = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(vniStart));
gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL);
gtk_list_store_clear(store);
gtk_tree_store_clear(store);
HASH_ITER(hh, g_pDhcpInfo, pInfo, pTemp) {
char mac[24] = {0};
sprintf(mac,
"%02X:%02X:%02X:%02X:%02X:%02X",
pInfo->mac[0],
pInfo->mac[1],
pInfo->mac[2],
pInfo->mac[3],
pInfo->mac[4],
pInfo->mac[5]);
for (i = 0; i < nRequest; i++) {
int isCreateRoot = FALSE;
gtk_list_store_append(store, &iter);
HASH_ITER(hh, g_pDhcpInfo, pInfo, pTemp) {
if (pInfo->vni == (nVni + i)) {
char idx[64] = {0};
char mac[24] = {0};
sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", pInfo->mac[0], pInfo->mac[1], pInfo->mac[2],
pInfo->mac[3], pInfo->mac[4], pInfo->mac[5]);
// clang-format off
gtk_list_store_set(store,
if (!isCreateRoot) {
sprintf(idx, "VNI %d", nVni + i);
// 创建根节点
gtk_tree_store_append(store, &iter, NULL);
// clang-format off
gtk_tree_store_set(store,
&iter,
COL_INDEX, pInfo->index,
COL_MAC, mac,
COL_HOSTNAME, pInfo->hostname,
COL_DISCOVER, calc_step_progress(pInfo, STEP_DISCOVER),
COL_OFFER, calc_step_progress(pInfo, STEP_OFFER),
COL_REQUEST, calc_step_progress(pInfo, STEP_REQUEST),
COL_ACK, calc_step_progress(pInfo, STEP_ACK),
COL_INDEX, idx,
COL_RESULT, "",
COL_STATUS, calc_total_progress(pInfo),
COL_ATTR_EDITABLE, FALSE,
COL_ATTR_VISIABLE, FALSE,
-1);
// clang-format on
// clang-format on
isCreateRoot = TRUE;
}
gtk_tree_store_append(store, &iter_child, &iter);
// clang-format off
// 创建子节点
memset(idx, 0, 64);
sprintf(idx, "%u", pInfo->index);
gtk_tree_store_set(store,
&iter_child,
COL_INDEX, idx,
COL_MAC, mac,
COL_HOSTNAME, pInfo->hostname,
COL_DISCOVER, calc_step_progress(pInfo, STEP_DISCOVER),
COL_OFFER, calc_step_progress(pInfo, STEP_OFFER),
COL_REQUEST, calc_step_progress(pInfo, STEP_REQUEST),
COL_ACK, calc_step_progress(pInfo, STEP_ACK),
COL_RESULT, "",
COL_STATUS, calc_total_progress(pInfo),
COL_ATTR_EDITABLE, FALSE,
COL_ATTR_VISIABLE, TRUE,
-1);
// clang-format on
}
}
}
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
@ -165,9 +189,10 @@ static void tree_view_data_store_create() {
}
static gboolean tree_view_data_store_upgade(gpointer pInfo) {
#if 0
char buf[32] = {0};
GtkTreeIter iter;
GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo"));
GtkTreeStore *store = GTK_TREE_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo"));
if (!pInfo) {
return FALSE;
@ -177,7 +202,7 @@ static gboolean tree_view_data_store_upgade(gpointer pInfo) {
if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, buf)) {
// clang-format off
gtk_list_store_set(store,
gtk_tree_store_set(store,
&iter,
COL_DISCOVER, calc_step_progress(pInfo, STEP_DISCOVER),
COL_OFFER, calc_step_progress(pInfo, STEP_OFFER),
@ -186,10 +211,11 @@ static gboolean tree_view_data_store_upgade(gpointer pInfo) {
COL_RESULT, "",
COL_STATUS, calc_total_progress(pInfo),
COL_ATTR_EDITABLE, FALSE,
COL_ATTR_VISIABLE, TRUE,
-1);
// clang-format on
}
#endif
return TRUE;
}
@ -210,7 +236,7 @@ int cacheDhcpOfferBuffer(PDHCP_INFO pInfo, U8 *pBuf, int size) {
return -ERR_MALLOC_MEMORY;
}
static void *dhcpThreadCb(void *pData) {
_Noreturn static void *dhcpThreadCb(void *pData) {
U8 *pkg;
int size = 0;
PDHCP_INFO pInfo, pTemp;
@ -286,7 +312,6 @@ static void *dhcpThreadCb(void *pData) {
LOG_MSG(debug, "DHCP status mathine exit......\n");
g_thread_exit(NULL);
return NULL;
}
static void cleanupDHCPInfo() {
@ -341,28 +366,28 @@ G_MODULE_EXPORT void __mainWnd_on_tb_start(GObject *object, gpointer user_data)
for (i = 0; i < nRequest; i++) {
for (j = 0; j < nVniCnt; j++) {
U32 macAddr = macVal + index;
pInfo = (PDHCP_INFO)malloc(sizeof(DHCP_INFO));
pInfo = (PDHCP_INFO)malloc(sizeof(DHCP_INFO));
if (pInfo == NULL) {
fprintf(stderr, "Malloc %lu bytes memory error of %d\n", sizeof(DHCP_INFO), i);
continue;
}
if (pInfo == NULL) {
fprintf(stderr, "Malloc %lu bytes memory error of %d\n", sizeof(DHCP_INFO), i);
continue;
}
memset(pInfo, 0, sizeof(DHCP_INFO));
memset(pInfo, 0, sizeof(DHCP_INFO));
pInfo->index = index;
pInfo->vni = nVni + i;
pInfo->mac[0] = mac[0];
pInfo->mac[1] = mac[1];
pInfo->mac[2] = (macAddr & 0xFF000000) >> 24;
pInfo->mac[3] = (macAddr & 0xFF0000) >> 16;
pInfo->mac[4] = (macAddr & 0xFF00) >> 8;
pInfo->mac[5] = (macAddr & 0xFF);
pInfo->vni = nVni + i;
pInfo->mac[0] = mac[0];
pInfo->mac[1] = mac[1];
pInfo->mac[2] = (macAddr & 0xFF000000) >> 24;
pInfo->mac[3] = (macAddr & 0xFF0000) >> 16;
pInfo->mac[4] = (macAddr & 0xFF00) >> 8;
pInfo->mac[5] = (macAddr & 0xFF);
sprintf(pInfo->hostname, "%s_%u", strPreHostname, pInfo->vni + index);
pInfo->step = STEP_BEGIN;
pInfo->status = STA_WAIT_START;
pInfo->step = STEP_BEGIN;
pInfo->status = STA_WAIT_START;
HASH_ADD_INT(g_pDhcpInfo, index, pInfo);
HASH_ADD_INT(g_pDhcpInfo, index, pInfo);
index++;
}
}

View File

@ -8,9 +8,11 @@
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="tsDhcpInfo">
<object class="GtkTreeStore" id="tsDhcpInfo">
<columns>
<!-- column-name cIndex -->
<column type="gchararray"/>
<!-- column-name cVni -->
<column type="guint"/>
<!-- column-name cMac -->
<column type="gchararray"/>
@ -30,6 +32,8 @@
<column type="gfloat"/>
<!-- column-name cAttrPrgTest -->
<column type="gboolean"/>
<!-- column-name cAttrVisialbe -->
<column type="gboolean"/>
</columns>
</object>
<object class="GtkWindow" id="wndMain">
@ -421,6 +425,19 @@
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcVni">
<property name="visible">False</property>
<property name="title">VNI</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcMac">
<property name="title">MAC</property>
@ -428,7 +445,8 @@
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">1</attribute>
<attribute name="visible">11</attribute>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
@ -440,7 +458,8 @@
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
<attribute name="text">2</attribute>
<attribute name="visible">11</attribute>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
@ -454,8 +473,9 @@
<child>
<object class="GtkCellRendererToggle" id="crDiscover"/>
<attributes>
<attribute name="sensitive">9</attribute>
<attribute name="active">3</attribute>
<attribute name="sensitive">10</attribute>
<attribute name="visible">11</attribute>
<attribute name="active">4</attribute>
</attributes>
</child>
</object>
@ -469,8 +489,9 @@
<child>
<object class="GtkCellRendererToggle" id="crOffer"/>
<attributes>
<attribute name="sensitive">9</attribute>
<attribute name="active">4</attribute>
<attribute name="sensitive">10</attribute>
<attribute name="visible">11</attribute>
<attribute name="active">5</attribute>
</attributes>
</child>
</object>
@ -484,8 +505,9 @@
<child>
<object class="GtkCellRendererToggle" id="crRequest"/>
<attributes>
<attribute name="sensitive">9</attribute>
<attribute name="active">5</attribute>
<attribute name="sensitive">10</attribute>
<attribute name="visible">11</attribute>
<attribute name="active">6</attribute>
</attributes>
</child>
</object>
@ -499,8 +521,9 @@
<child>
<object class="GtkCellRendererToggle" id="crAck"/>
<attributes>
<attribute name="sensitive">9</attribute>
<attribute name="active">6</attribute>
<attribute name="sensitive">10</attribute>
<attribute name="visible">11</attribute>
<attribute name="active">7</attribute>
</attributes>
</child>
</object>
@ -514,7 +537,7 @@
<child>
<object class="GtkCellRendererText" id="crResult"/>
<attributes>
<attribute name="text">7</attribute>
<attribute name="text">8</attribute>
</attributes>
</child>
</object>
@ -528,7 +551,7 @@
<child>
<object class="GtkCellRendererProgress" id="cellrendererprogress1"/>
<attributes>
<attribute name="value">8</attribute>
<attribute name="value">9</attribute>
</attributes>
</child>
</object>