2023-04-18 01:03:16 +00:00
|
|
|
//
|
|
|
|
// Created by xajhuang on 2023/4/12.
|
|
|
|
//
|
|
|
|
#include <gtk/gtk.h>
|
2023-04-20 09:20:30 +00:00
|
|
|
#include <zlog.h>
|
|
|
|
#include "common.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "task_manager.h"
|
|
|
|
#include "user_errno.h"
|
|
|
|
#include "zlog_module.h"
|
|
|
|
#include "dhcp_network.h"
|
2023-04-18 01:03:16 +00:00
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
#define ZLOG_CFG_PATH "./config/zlog.conf"
|
2023-04-18 01:03:16 +00:00
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
static GtkBuilder *g_mainBuilder = NULL;
|
|
|
|
static PDHCP_INFO g_pDhcpInfo = NULL;
|
|
|
|
static GThread *g_pEvLoopThread = NULL;
|
|
|
|
static GThread *g_pDHCPSTMThread = NULL;
|
|
|
|
static int g_runTask = FALSE;
|
|
|
|
|
|
|
|
U32 rand_number() {
|
|
|
|
GRand *pRand = g_rand_new_with_seed(time(NULL));
|
|
|
|
|
|
|
|
return g_rand_int(pRand);
|
|
|
|
}
|
2023-04-18 01:03:16 +00:00
|
|
|
|
2023-04-21 07:01:36 +00:00
|
|
|
PDHCP_INFO get_dhcp_info_by_id(U32 xid) {
|
|
|
|
PDHCP_INFO pInfo;
|
|
|
|
U32 index = xid & 0x00FFFFFF;
|
|
|
|
|
|
|
|
HASH_FIND_INT(g_pDhcpInfo, &index, pInfo);
|
|
|
|
return pInfo;
|
|
|
|
}
|
|
|
|
|
2023-04-18 01:03:16 +00:00
|
|
|
static void load_css(void) {
|
|
|
|
GtkCssProvider *provider;
|
|
|
|
GdkDisplay *display;
|
|
|
|
GdkScreen *screen;
|
|
|
|
GFile *css_fp = g_file_new_for_path("./res/style.css");
|
|
|
|
GError *error = 0;
|
|
|
|
|
|
|
|
provider = gtk_css_provider_new();
|
|
|
|
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_PROVIDER_PRIORITY_APPLICATION);
|
|
|
|
|
|
|
|
gtk_css_provider_load_from_file(provider, css_fp, &error);
|
|
|
|
}
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
static double calc_total_progress(PDHCP_INFO pInfo) {
|
|
|
|
double pre_cnt = 0.0;
|
|
|
|
|
|
|
|
if (pInfo) {
|
|
|
|
pre_cnt += pInfo->step * 20;
|
|
|
|
pre_cnt += pInfo->status * 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pre_cnt;
|
|
|
|
}
|
|
|
|
|
2023-04-20 09:48:19 +00:00
|
|
|
static gboolean calc_step_progress(PDHCP_INFO pInfo, DHCP_STEP step) {
|
2023-04-21 07:01:36 +00:00
|
|
|
if (pInfo && pInfo->step >= step) {
|
2023-04-20 09:48:19 +00:00
|
|
|
return TRUE;
|
2023-04-20 09:20:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 09:48:19 +00:00
|
|
|
return FALSE;
|
2023-04-18 01:03:16 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
static void tree_view_data_store_create() {
|
2023-04-18 01:03:16 +00:00
|
|
|
int i, j;
|
2023-04-20 09:20:30 +00:00
|
|
|
PDHCP_INFO pInfo, pTemp;
|
2023-04-18 01:03:16 +00:00
|
|
|
GtkTreeIter iter, iter_child, iter_sub;
|
2023-04-20 09:20:30 +00:00
|
|
|
GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "treeResult"));
|
|
|
|
GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo"));
|
|
|
|
|
|
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL);
|
|
|
|
gtk_list_store_clear(store);
|
2023-04-18 01:03:16 +00:00
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
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]);
|
|
|
|
|
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
gtk_list_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_RESULT, "",
|
|
|
|
COL_STATUS, calc_total_progress(pInfo),
|
2023-04-20 09:48:19 +00:00
|
|
|
COL_ATTR_EDITABLE, FALSE,
|
2023-04-20 09:20:30 +00:00
|
|
|
-1);
|
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
|
|
|
|
#if 0
|
2023-04-18 01:03:16 +00:00
|
|
|
for (i = 0; i < 1000; i++) {
|
|
|
|
char buf[24] = {0};
|
|
|
|
char bufHost[32] = {0};
|
|
|
|
char bufVni[16] = {0};
|
|
|
|
|
|
|
|
sprintf(bufVni, "%d", i);
|
|
|
|
sprintf(bufHost, "hostname%d", i);
|
|
|
|
sprintf(buf, "06:01:02:%02X:%02X:%02X", (i & 0xFF0000) >> 16, (i & 0xFF00) >> 8, (i & 0xFF));
|
|
|
|
|
|
|
|
gtk_tree_store_append(store, &iter, NULL);
|
|
|
|
// clang-format off
|
2023-04-20 09:20:30 +00:00
|
|
|
gtk_tree_store_set(store, &iter,
|
|
|
|
COL_INDEX, bufVni,
|
|
|
|
COL_MAC, buf,
|
|
|
|
COL_HOSTNAME, bufHost,
|
|
|
|
COL_STATUS, 20.0,
|
|
|
|
-1);
|
2023-04-18 01:03:16 +00:00
|
|
|
gtk_tree_store_append(store, &iter_child, &iter);
|
|
|
|
gtk_tree_store_set(store, &iter_child,
|
2023-04-20 09:20:30 +00:00
|
|
|
COL_INDEX, "",
|
|
|
|
COL_STEP, "Discover",
|
|
|
|
COL_RESULT, "",
|
|
|
|
COL_STATUS, 10.0,
|
|
|
|
-1);
|
2023-04-18 01:03:16 +00:00
|
|
|
gtk_tree_store_append(store, &iter_child, &iter);
|
|
|
|
gtk_tree_store_set(store, &iter_child,
|
2023-04-20 09:20:30 +00:00
|
|
|
COL_INDEX, "",
|
|
|
|
COL_STEP, "Offer",
|
|
|
|
COL_RESULT, "",
|
|
|
|
COL_STATUS, 10.0,
|
|
|
|
-1);
|
2023-04-18 01:03:16 +00:00
|
|
|
|
|
|
|
gtk_tree_store_append(store, &iter_child, &iter);
|
|
|
|
gtk_tree_store_set(store, &iter_child,
|
2023-04-20 09:20:30 +00:00
|
|
|
COL_INDEX, "",
|
|
|
|
COL_STEP, "Request",
|
|
|
|
COL_RESULT, "",
|
|
|
|
COL_STATUS, 10.0,
|
|
|
|
-1);
|
2023-04-18 01:03:16 +00:00
|
|
|
gtk_tree_store_append(store, &iter_child, &iter);
|
|
|
|
gtk_tree_store_set(store, &iter_child,
|
2023-04-20 09:20:30 +00:00
|
|
|
COL_INDEX, "",
|
|
|
|
COL_STEP, "ACK",
|
|
|
|
COL_RESULT, "",
|
|
|
|
COL_STATUS, 10.0,
|
|
|
|
-1);
|
2023-04-18 01:03:16 +00:00
|
|
|
// clang-format on
|
|
|
|
}
|
2023-04-20 09:20:30 +00:00
|
|
|
#endif
|
|
|
|
//g_object_unref(store);
|
2023-04-18 01:03:16 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
static gboolean tree_view_data_store_upgade(gpointer pInfo) {
|
|
|
|
char buf[32] = {0};
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "tsDhcpInfo"));
|
|
|
|
|
|
|
|
if (!pInfo) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(buf, "%d", ((PDHCP_INFO)pInfo)->index);
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(store), &iter, buf)) {
|
|
|
|
// clang-format off
|
|
|
|
gtk_list_store_set(store,
|
|
|
|
&iter,
|
|
|
|
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),
|
2023-04-20 09:48:19 +00:00
|
|
|
COL_ATTR_EDITABLE, FALSE,
|
2023-04-20 09:20:30 +00:00
|
|
|
-1);
|
|
|
|
// clang-format on
|
|
|
|
}
|
2023-04-21 07:01:36 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2023-04-20 09:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
G_MODULE_EXPORT void __mainWnd_on_destroy(GObject *object, gpointer user_data) {
|
|
|
|
task_manager_exit();
|
|
|
|
g_thread_unref(g_pEvLoopThread);
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|
|
|
|
|
2023-04-21 07:01:36 +00:00
|
|
|
int cacheDhcpOfferBuffer(PDHCP_INFO pInfo, U8 *pBuf, int size) {
|
|
|
|
pInfo->pOfferBuf.p = (U8 *)malloc(size);
|
|
|
|
if (pInfo->pOfferBuf.p) {
|
|
|
|
memcpy(pInfo->pOfferBuf.p, pBuf, size);
|
|
|
|
pInfo->pOfferBuf.buf_size = size;
|
|
|
|
return ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ERR_MALLOC_MEMORY;
|
|
|
|
}
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
static void *dhcpThreadCb(void *pData) {
|
|
|
|
U8 *pkg;
|
|
|
|
int size = 0;
|
|
|
|
PDHCP_INFO pInfo, pTemp;
|
|
|
|
|
|
|
|
while (TRUE) {
|
|
|
|
|
|
|
|
if (!g_runTask) {
|
|
|
|
g_usleep(1000);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
HASH_ITER(hh, g_pDhcpInfo, pInfo, pTemp) {
|
|
|
|
switch (pInfo->step) {
|
|
|
|
case STEP_BEGIN:
|
|
|
|
pInfo->pDiscBuf.p = dhcp_create_discover_req(pInfo, &size);
|
|
|
|
|
|
|
|
if (pInfo->pDiscBuf.p) {
|
|
|
|
pInfo->pDiscBuf.buf_size = size;
|
|
|
|
pInfo->step = STEP_DISCOVER;
|
|
|
|
pInfo->status = STA_WAIT_START;
|
|
|
|
g_idle_add(tree_view_data_store_upgade, pInfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_DISCOVER:
|
2023-04-21 07:01:36 +00:00
|
|
|
if (pInfo->status == STA_WAIT_START) {
|
|
|
|
pkg = get_pkg_free_buf();
|
2023-04-20 09:20:30 +00:00
|
|
|
|
2023-04-21 07:01:36 +00:00
|
|
|
if (pkg) {
|
|
|
|
memcpy(pkg, pInfo->pDiscBuf.p, pInfo->pDiscBuf.buf_size);
|
2023-04-20 09:20:30 +00:00
|
|
|
|
2023-04-21 07:01:36 +00:00
|
|
|
if (pkg_mmap_tx((U8 *)pkg, pInfo->pDiscBuf.buf_size) == pInfo->pDiscBuf.buf_size) {
|
|
|
|
pInfo->status = STA_SEND_REQ;
|
|
|
|
g_idle_add(tree_view_data_store_upgade, pInfo);
|
2023-04-20 09:20:30 +00:00
|
|
|
}
|
2023-04-21 07:01:36 +00:00
|
|
|
}
|
2023-04-20 09:20:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STEP_OFFER:
|
2023-04-21 07:01:36 +00:00
|
|
|
if (pInfo->status == STA_RECV_RSP) {
|
|
|
|
pInfo->pReqBuf.p = dhcp_create_request_req(pInfo, &size);
|
|
|
|
|
|
|
|
if (pInfo->pReqBuf.p) {
|
|
|
|
pInfo->pReqBuf.buf_size = size;
|
|
|
|
pInfo->step = STEP_REQUEST;
|
|
|
|
pInfo->status = STA_WAIT_START;
|
|
|
|
g_idle_add(tree_view_data_store_upgade, pInfo);
|
|
|
|
}
|
|
|
|
}
|
2023-04-20 09:20:30 +00:00
|
|
|
break;
|
|
|
|
case STEP_REQUEST:
|
2023-04-21 07:01:36 +00:00
|
|
|
if (pInfo->status == STA_WAIT_START) {
|
|
|
|
pkg = get_pkg_free_buf();
|
|
|
|
|
|
|
|
if (pkg) {
|
|
|
|
memcpy(pkg, pInfo->pReqBuf.p, pInfo->pReqBuf.buf_size);
|
|
|
|
|
|
|
|
if (pkg_mmap_tx((U8 *)pkg, pInfo->pReqBuf.buf_size) == pInfo->pReqBuf.buf_size) {
|
|
|
|
pInfo->status = STA_SEND_REQ;
|
|
|
|
g_idle_add(tree_view_data_store_upgade, pInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-20 09:20:30 +00:00
|
|
|
break;
|
|
|
|
case STEP_ACK:
|
|
|
|
break;
|
|
|
|
case STEP_END:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_usleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_MSG(debug, "DHCP status mathine exit......\n");
|
|
|
|
g_thread_exit(NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-04-21 07:01:36 +00:00
|
|
|
static void cleanupDHCPInfo() {
|
|
|
|
PDHCP_INFO pInfo, pTemp;
|
|
|
|
HASH_ITER(hh, g_pDhcpInfo, pInfo, pTemp) {
|
|
|
|
HASH_DEL(g_pDhcpInfo, pInfo);
|
|
|
|
if (pInfo->pOfferBuf.p) {
|
|
|
|
free(pInfo->pOfferBuf.p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pInfo->pDiscBuf.p) {
|
|
|
|
free(pInfo->pDiscBuf.p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pInfo->pReqBuf.p) {
|
|
|
|
free(pInfo->pReqBuf.p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pInfo->pAckBuf.p) {
|
|
|
|
free(pInfo->pAckBuf.p);
|
|
|
|
}
|
|
|
|
free(pInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
G_MODULE_EXPORT void __mainWnd_on_tb_start(GObject *object, gpointer user_data) {
|
2023-04-25 01:17:08 +00:00
|
|
|
int i, j, index = 0;
|
2023-04-21 07:01:36 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
PDHCP_INFO pInfo;
|
|
|
|
GtkTreeModel *cobModel;
|
|
|
|
gchar *pCobText;
|
2023-04-20 09:20:30 +00:00
|
|
|
unsigned char mac[6];
|
|
|
|
U32 macVal;
|
|
|
|
GtkWidget *stopButton = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStop"));
|
|
|
|
GtkWidget *nicSelect = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "cbNicName"));
|
|
|
|
GtkWidget *macBegin = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "txtMacStart"));
|
|
|
|
GtkWidget *preHostname = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "txtHostname"));
|
|
|
|
GtkWidget *vniStart = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbVni"));
|
2023-04-25 01:17:08 +00:00
|
|
|
GtkWidget *numVniCli = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbVniClient"));
|
2023-04-20 09:20:30 +00:00
|
|
|
GtkWidget *numRequest = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbReqNum"));
|
|
|
|
const char *strMacBegin = gtk_entry_get_text(GTK_ENTRY(macBegin));
|
|
|
|
const char *strPreHostname = gtk_entry_get_text(GTK_ENTRY(preHostname));
|
|
|
|
U32 nRequest = (U32)gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(numRequest));
|
|
|
|
U32 nVni = (U32)gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(vniStart));
|
2023-04-25 01:17:08 +00:00
|
|
|
U32 nVniCnt = (U32)gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(numVniCli));
|
2023-04-20 09:20:30 +00:00
|
|
|
|
|
|
|
string_mac_to_bytes(strMacBegin, mac);
|
|
|
|
macVal = mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5];
|
|
|
|
|
2023-04-21 07:01:36 +00:00
|
|
|
cleanupDHCPInfo();
|
2023-04-20 09:20:30 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nRequest; i++) {
|
2023-04-25 01:17:08 +00:00
|
|
|
for (j = 0; j < nVniCnt; j++) {
|
|
|
|
U32 macAddr = macVal + index;
|
2023-04-20 09:20:30 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(pInfo, 0, sizeof(DHCP_INFO));
|
2023-04-25 01:17:08 +00:00
|
|
|
pInfo->index = index;
|
2023-04-20 09:20:30 +00:00
|
|
|
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);
|
|
|
|
|
2023-04-25 01:17:08 +00:00
|
|
|
sprintf(pInfo->hostname, "%s_%u", strPreHostname, pInfo->vni + index);
|
2023-04-20 09:20:30 +00:00
|
|
|
pInfo->step = STEP_BEGIN;
|
|
|
|
pInfo->status = STA_WAIT_START;
|
|
|
|
|
|
|
|
HASH_ADD_INT(g_pDhcpInfo, index, pInfo);
|
2023-04-25 01:17:08 +00:00
|
|
|
index++;
|
|
|
|
}
|
2023-04-20 09:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(object), FALSE);
|
|
|
|
gtk_widget_set_sensitive(nicSelect, FALSE);
|
|
|
|
tree_view_data_store_create();
|
|
|
|
gtk_widget_set_sensitive(stopButton, TRUE);
|
|
|
|
|
2023-04-21 07:01:36 +00:00
|
|
|
cobModel = gtk_combo_box_get_model(GTK_COMBO_BOX(nicSelect));
|
|
|
|
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(nicSelect), &iter);
|
|
|
|
gtk_tree_model_get(cobModel, &iter, 0, &pCobText, -1);
|
2023-04-20 09:20:30 +00:00
|
|
|
|
2023-04-21 07:01:36 +00:00
|
|
|
dhcp_tools_init_network(pCobText);
|
2023-04-20 09:20:30 +00:00
|
|
|
g_runTask = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_MODULE_EXPORT void __mainWnd_on_tb_stop(GObject *object, gpointer user_data) {
|
|
|
|
GtkWidget *startButton = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStart"));
|
|
|
|
GtkWidget *nicSelect = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "cbNicName"));
|
|
|
|
|
2023-04-21 08:04:43 +00:00
|
|
|
g_runTask = FALSE;
|
2023-04-20 09:20:30 +00:00
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(object), FALSE);
|
|
|
|
gtk_widget_set_sensitive(startButton, TRUE);
|
|
|
|
gtk_widget_set_sensitive(nicSelect, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *uv_loop_thread(void *pData) {
|
|
|
|
static uv_timer_t uvTm;
|
|
|
|
task_manager_run();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int args, char **argv) {
|
|
|
|
int i, ret;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GList *pNicList = NULL;
|
|
|
|
SYS_NIC_INFO info = {0};
|
|
|
|
|
|
|
|
if ((ret = zlog_init(ZLOG_CFG_PATH)) != ERR_SUCCESS) {
|
|
|
|
printf("Zlog configure file [%s] init result: %d+++++\n", ZLOG_CFG_PATH, ret);
|
|
|
|
zlog_profile();
|
|
|
|
return -ERR_ZLOG_INIT;
|
|
|
|
} else {
|
|
|
|
LOG_MOD(debug, ZLOG_MOD_INIT, "Zlog used configure file [%s]\n", ZLOG_CFG_PATH);
|
|
|
|
dzlog_init(ZLOG_CFG_PATH, get_cur_process_name());
|
|
|
|
}
|
|
|
|
|
|
|
|
get_all_network_info(&info);
|
|
|
|
|
|
|
|
gtk_init(&args, &argv);
|
2023-04-18 01:03:16 +00:00
|
|
|
load_css();
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
g_mainBuilder = gtk_builder_new();
|
|
|
|
gtk_builder_add_from_file(g_mainBuilder, "./res/main.glade", NULL);
|
|
|
|
|
|
|
|
GtkWidget *mainWnd = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "wndMain"));
|
|
|
|
g_signal_connect(mainWnd, "destroy", G_CALLBACK(__mainWnd_on_destroy), g_mainBuilder);
|
|
|
|
|
|
|
|
GtkWidget *tbStart = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStart"));
|
|
|
|
g_signal_connect(tbStart, "clicked", G_CALLBACK(__mainWnd_on_tb_start), g_mainBuilder);
|
2023-04-18 01:03:16 +00:00
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
GtkWidget *tbStop = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "tbStop"));
|
|
|
|
g_signal_connect(tbStop, "clicked", G_CALLBACK(__mainWnd_on_tb_stop), g_mainBuilder);
|
2023-04-18 01:03:16 +00:00
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
GtkWidget *cbNic = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "cbNicName"));
|
|
|
|
for (i = 0; i < info.nicCnt; i++) {
|
|
|
|
GtkListStore *store = GTK_LIST_STORE(gtk_builder_get_object(g_mainBuilder, "lsNicName"));
|
|
|
|
gtk_combo_box_set_model(GTK_COMBO_BOX(cbNic), GTK_TREE_MODEL(store));
|
2023-04-18 01:03:16 +00:00
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
gtk_list_store_set(store, &iter, 0, info.pNicCtx[i].ethName, -1);
|
|
|
|
|
|
|
|
if (i == info.nicCnt - 1) {
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(cbNic), i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.pNicCtx) {
|
|
|
|
free(info.pNicCtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *macTxt = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "txtMacStart"));
|
|
|
|
|
|
|
|
GtkWidget *numInc = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbReqNum"));
|
2023-04-20 09:48:19 +00:00
|
|
|
GtkAdjustment *adj = gtk_adjustment_new(1, 1, 100000, 1, 0, 0);
|
2023-04-18 01:03:16 +00:00
|
|
|
gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(numInc), adj);
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
GtkWidget *numVni = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbVni"));
|
2023-04-18 01:03:16 +00:00
|
|
|
GtkAdjustment *adjVni = gtk_adjustment_new(1, 1, 10000000, 1, 0, 0);
|
|
|
|
gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(numVni), adjVni);
|
2023-04-20 09:20:30 +00:00
|
|
|
|
2023-04-25 01:17:08 +00:00
|
|
|
GtkWidget *numVniCli = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "sbVniClient"));
|
|
|
|
GtkAdjustment *adjVniCli = gtk_adjustment_new(1, 1, 1000, 1, 0, 0);
|
|
|
|
gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(numVniCli), adjVniCli);
|
2023-04-20 09:20:30 +00:00
|
|
|
GtkWidget *view = GTK_WIDGET(gtk_builder_get_object(g_mainBuilder, "treeResult"));
|
|
|
|
|
2023-04-18 01:03:16 +00:00
|
|
|
#if 0
|
|
|
|
gtk_list_store_new(NUM_COLS,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_FLOAT);
|
|
|
|
#endif
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
gtk_builder_connect_signals(g_mainBuilder, NULL);
|
2023-04-18 01:03:16 +00:00
|
|
|
gtk_widget_show(mainWnd);
|
|
|
|
|
2023-04-20 09:20:30 +00:00
|
|
|
g_pEvLoopThread = g_thread_new("uv_loop", uv_loop_thread, NULL);
|
|
|
|
g_pDHCPSTMThread = g_thread_new("dhcp", dhcpThreadCb, NULL);
|
2023-04-18 01:03:16 +00:00
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|