From 41b52470df22d3b2a2bf9190c13820b0cac66b09 Mon Sep 17 00:00:00 2001 From: shi_jq Date: Wed, 12 Mar 2025 17:44:25 +0800 Subject: [PATCH] =?UTF-8?q?[ref]=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/src/net/net.pro | 2 +- .../net_keepalived/CCheckDatabaseThread.cpp | 8 +- .../src/net/net_keepalived/RegistForLinux.h | 2 +- .../src/net/net_keepalived/RegistForWindows.h | 2 +- platform/src/net/net_msg_bus/CLocalMng.cpp | 1 + platform/src/net/net_msg_bus/CMbServer.cpp | 12 ++ platform/src/net/net_msg_bus/CRemoteHost.cpp | 14 ++- platform/src/net/net_msg_bus/CRemoteMng.cpp | 1 + .../src/net/net_msg_bus_api/CInProcBroker.cpp | 8 +- .../net_msg_bus_api/CMbCommunicatorImp.cpp | 10 +- .../src/net/net_msg_bus_api/MsgBusApi.cpp | 11 ++ .../src/net/net_msg_bus_base_api/CommonDef.h | 2 +- .../src/net/net_msg_bus_base_api/kmbmp.bnf | 2 +- platform/src/net/net_msg_bus_base_api/kmbmp.c | 4 +- platform/src/net/net_msg_bus_base_api/kmbmp.h | 2 +- .../src/net/net_msg_bus_base_api/kmbmp.xml | 2 +- .../src/net/net_msg_bus_base_api/kmbp.bnf | 2 +- platform/src/net/net_msg_bus_base_api/kmbp.c | 4 +- platform/src/net/net_msg_bus_base_api/kmbp.h | 2 +- .../src/net/net_msg_bus_base_api/kmbp.xml | 2 +- .../addnodedialog.cpp | 6 +- .../net_msg_bus_mng_ping_gui/addnodedialog.h | 4 +- .../net_msg_bus_mng_ping_gui/addnodedialog.ui | 96 ++++++++-------- .../src/net/net_msg_bus_mng_ping_gui/main.cpp | 34 +++++- .../net_msg_bus_mng_ping_gui/mainwindow.cpp | 29 +++-- .../net/net_msg_bus_mng_ping_gui/mainwindow.h | 3 +- .../net_msg_bus_mng_ping_gui/mainwindow.ui | 9 +- .../net_msg_bus_mng_ping_gui.pro | 3 +- .../src/net/net_msg_bus_relay/CDomainMng.cpp | 11 ++ .../net/net_msg_bus_relay/CDomainThread.cpp | 10 +- .../src/net/net_msg_bus_relay/CMainThread.cpp | 11 +- .../src/net/net_msg_bus_relay/CRemoteConn.cpp | 5 +- .../client_dealer/client_dealer.pro | 32 ++++++ .../net_msg_bus_test/client_dealer/main.cpp | 83 ++++++++++++++ .../net/net_msg_bus_test/net_msg_bus_test.pro | 2 + .../src/net/net_msg_bus_test/sender/main.cpp | 2 +- .../net_msg_bus_test/server_router/main.cpp | 106 ++++++++++++++++++ .../server_router/server_router.pro | 32 ++++++ .../src/net/net_snmp_agent/AgentCommon.cpp | 13 ++- .../src/net/net_snmp_agent/CAgentServer.cpp | 28 +++-- platform/src/net/net_snmp_agent/MainLinux.cpp | 22 ++-- .../src/net/net_snmp_agent/MainWindows.cpp | 14 +-- .../src/net/net_snmp_agent/ProcessGroup.cpp | 3 + .../src/net/net_snmp_agent/test/snmp_test.sh | 4 +- 44 files changed, 514 insertions(+), 141 deletions(-) create mode 100644 platform/src/net/net_msg_bus_test/client_dealer/client_dealer.pro create mode 100644 platform/src/net/net_msg_bus_test/client_dealer/main.cpp create mode 100644 platform/src/net/net_msg_bus_test/server_router/main.cpp create mode 100644 platform/src/net/net_msg_bus_test/server_router/server_router.pro diff --git a/platform/src/net/net.pro b/platform/src/net/net.pro index ce086624..5d6955f9 100644 --- a/platform/src/net/net.pro +++ b/platform/src/net/net.pro @@ -8,7 +8,7 @@ SUBDIRS += \ net_msg_bus_relay \ net_msg_bus_ping \ net_msg_bus_mng \ - net_msg_bus_test \ +# net_msg_bus_test \ net_msg_bus_mng_ping_gui \ net_snmp_agent \ net_keepalived diff --git a/platform/src/net/net_keepalived/CCheckDatabaseThread.cpp b/platform/src/net/net_keepalived/CCheckDatabaseThread.cpp index 1d165f92..f5ef3fec 100644 --- a/platform/src/net/net_keepalived/CCheckDatabaseThread.cpp +++ b/platform/src/net/net_keepalived/CCheckDatabaseThread.cpp @@ -129,7 +129,13 @@ int CCheckDatabaseThread::getMaxSyncId() if ( m_pDb->open() ) { if ( m_eDBType == EDBType_KINGBASE ) - m_pDb->exec( "SET search_path TO iscs6000;" ); + { + /* 为以后搜索方便,保留此注释 + * QString sSql = QString("SET search_path TO %1;").arg(EMS_DEFAULT_DATABASE) ; + */ + QString sSql = QString("SET search_path TO %1;").arg(m_pDb->databaseName()) ; + m_pDb->exec( sSql); + } QSqlQuery objQuery = m_pDb->exec( "select max(id) from dbop_list" ); if ( objQuery.isActive() ) { diff --git a/platform/src/net/net_keepalived/RegistForLinux.h b/platform/src/net/net_keepalived/RegistForLinux.h index bc97627b..9df2c6fc 100644 --- a/platform/src/net/net_keepalived/RegistForLinux.h +++ b/platform/src/net/net_keepalived/RegistForLinux.h @@ -9,7 +9,7 @@ #include #include -static const char *pszSystemdCfgFile = "/lib/systemd/system/net_keepalived.service"; +static const char *pszSystemdCfgFile = "/usr/lib/systemd/system/net_keepalived.service"; //< 注册系统服务,并设置自启动 bool regSysService(QString &strErr) diff --git a/platform/src/net/net_keepalived/RegistForWindows.h b/platform/src/net/net_keepalived/RegistForWindows.h index d1dde7e8..e16d0da9 100644 --- a/platform/src/net/net_keepalived/RegistForWindows.h +++ b/platform/src/net/net_keepalived/RegistForWindows.h @@ -51,7 +51,7 @@ static bool regSysService( QString &strErr ) else { SERVICE_DESCRIPTIONA stSrvDesc; - char szDesc[] = "Virtual IP service of KBD."; + char szDesc[] = "Virtual IP service"; stSrvDesc.lpDescription = szDesc; if (::ChangeServiceConfig2A(hService, SERVICE_CONFIG_DESCRIPTION, &stSrvDesc)) { diff --git a/platform/src/net/net_msg_bus/CLocalMng.cpp b/platform/src/net/net_msg_bus/CLocalMng.cpp index b91cad08..58978988 100644 --- a/platform/src/net/net_msg_bus/CLocalMng.cpp +++ b/platform/src/net/net_msg_bus/CLocalMng.cpp @@ -121,6 +121,7 @@ CLocalMng::SLocalMng* CLocalMng::SLocalMng::newLocalMng(zsock_t *pActorPipe) int nTimerID = zloop_timer(self->m_pLoop, 1000, 0, handleProcTimeOutTimer, self); assert(nTimerID >= 0); //< zloop的TimerID从0开始 + boost::ignore_unused_variable_warning(nTimerID); bRc = setSocketHandle(self, self->m_pSockMng, handleSockMng); assert(bRc); diff --git a/platform/src/net/net_msg_bus/CMbServer.cpp b/platform/src/net/net_msg_bus/CMbServer.cpp index 8a0ceaa8..2969e846 100644 --- a/platform/src/net/net_msg_bus/CMbServer.cpp +++ b/platform/src/net/net_msg_bus/CMbServer.cpp @@ -11,8 +11,20 @@ #include "boost/typeof/typeof.hpp" #include "boost/program_options.hpp" + +//< 屏蔽xml_parser编译告警 +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-copy" +#endif + #include "boost/property_tree/xml_parser.hpp" +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + + #include "czmq.h" #include "pub_logger_api/logger.h" diff --git a/platform/src/net/net_msg_bus/CRemoteHost.cpp b/platform/src/net/net_msg_bus/CRemoteHost.cpp index 5cb1326b..38212e44 100644 --- a/platform/src/net/net_msg_bus/CRemoteHost.cpp +++ b/platform/src/net/net_msg_bus/CRemoteHost.cpp @@ -8,14 +8,11 @@ **********************************************************************************/ #include "boost/format.hpp" - #include "pub_logger_api/logger.h" - #include "../net_msg_bus_base_api/CommonDef.h" - #include "CMbServer.h" - #include "CRemoteHost.h" +#include "boost/concept_check.hpp" namespace iot_net { @@ -285,6 +282,7 @@ CRemoteHost::SRemoteHost* CRemoteHost::SRemoteHost::newRemoteHost(zsock_t *pActo int nPendingMsgTimerID = zloop_timer(self->m_pLoop, 1000, 0, handlePendingMsgTimer, self); assert(nPendingMsgTimerID >= 0); + boost::ignore_unused_variable_warning(nPendingMsgTimerID); //< 系统信号打断不退出 zloop_set_nonstop(self->m_pLoop, true); @@ -454,6 +452,7 @@ int CRemoteHost::SRemoteHost::delaySockDataIn(zloop_t *, int timer_id, void *arg //< 恢复接收m_pSockDataIn的消息 bool bRc = setSocketHandle(self, self->m_pSockDataIn, handleSockDataIn); assert(bRc); + boost::ignore_unused_variable_warning(bRc); } //< 取消本定时器 @@ -465,6 +464,7 @@ int CRemoteHost::SRemoteHost::delaySockDataIn(zloop_t *, int timer_id, void *arg //< 取消接收m_pSockDataIn的消息 bool bRc = setSocketHandle(self, self->m_pSockDataIn, NULL); assert(bRc); + boost::ignore_unused_variable_warning(bRc); //< 设置定时器,到时恢复,单位ms self->m_nDelaySockDataInTimerID = zloop_timer(self->m_pLoop, 100, 1, delaySockDataIn, self); @@ -701,6 +701,8 @@ int CRemoteHost::SRemoteHost::handleActorPipe(zloop_t *, zsock_t *reader, void * int CRemoteHost::SRemoteHost::handleSockDataIn(zloop_t *, zsock_t *reader, void *arg) { + boost::ignore_unused_variable_warning(reader); + SRemoteHost *self = (SRemoteHost *)arg; assert(reader == self->m_pSockDataIn); @@ -1021,11 +1023,15 @@ int CRemoteHost::SRemoteHost::handleSockNetAllMon(zloop_t *, zsock_t *reader, vo int CRemoteHost::SRemoteHost::handleSockNetAll(zloop_t *, zsock_t *reader, void *arg) { + boost::ignore_unused_variable_warning(reader); + SRemoteHost *self = (SRemoteHost *)arg; assert(reader == self->m_pSockNetA || reader == self->m_pSockNetB); + boost::ignore_unused_variable_warning(self); + //< 当前,不应该收到任何消息 //< 将收到的消息释放,避免占用内存 diff --git a/platform/src/net/net_msg_bus/CRemoteMng.cpp b/platform/src/net/net_msg_bus/CRemoteMng.cpp index 79a0da04..89493951 100644 --- a/platform/src/net/net_msg_bus/CRemoteMng.cpp +++ b/platform/src/net/net_msg_bus/CRemoteMng.cpp @@ -159,6 +159,7 @@ CRemoteMng::SRemoteMng* CRemoteMng::SRemoteMng::newRemoteMng(zsock_t *pActorPipe //< 10s发一次 int nSubChgCntTimerID = zloop_timer(self->m_pLoop, 10000, 0, handleSubChgCntTimer, self); assert(nSubChgCntTimerID >= 0); + boost::ignore_unused_variable_warning(nSubChgCntTimerID); bRc = setSocketHandle(self, self->m_pSockMng, handleSockMng); assert(bRc); diff --git a/platform/src/net/net_msg_bus_api/CInProcBroker.cpp b/platform/src/net/net_msg_bus_api/CInProcBroker.cpp index 8ac8ba11..1b4ba395 100644 --- a/platform/src/net/net_msg_bus_api/CInProcBroker.cpp +++ b/platform/src/net/net_msg_bus_api/CInProcBroker.cpp @@ -10,16 +10,12 @@ #include "boost/typeof/typeof.hpp" #include "boost/asio/ip/host_name.hpp" #include "boost/interprocess/detail/os_thread_functions.hpp" - +#include "boost/concept_check.hpp" #include "lz4.h" - #include "pub_logger_api/logger.h" - #include "../net_msg_bus_base_api/kmbp_cnt.h" - #include "../net_msg_bus_base_api/CMbSubEngine.h" #include "../net_msg_bus_base_api/CommonDef.h" - #include "CInProcBroker.h" namespace iot_net @@ -100,6 +96,7 @@ CInProcBroker::SActWorker* CInProcBroker::SActWorker::newActWorker(zsock_t *pAct int nRc = zsock_bind(self->m_pSockInData, MB_P2C_DATA_ENDPOINT); assert(0 == nRc); + boost::ignore_unused_variable_warning(nRc); } //< 初始化m_pSockOut @@ -186,6 +183,7 @@ CInProcBroker::SActWorker* CInProcBroker::SActWorker::newActWorker(zsock_t *pAct bRc = setSocketHandle(self, self->m_pSockOut, handleSockOut); assert(bRc); + boost::ignore_unused_variable_warning(nRc); //< 系统信号打断不退出 zloop_set_nonstop(self->m_pLoop, true); } diff --git a/platform/src/net/net_msg_bus_api/CMbCommunicatorImp.cpp b/platform/src/net/net_msg_bus_api/CMbCommunicatorImp.cpp index 359e7f8c..a2d67d1f 100644 --- a/platform/src/net/net_msg_bus_api/CMbCommunicatorImp.cpp +++ b/platform/src/net/net_msg_bus_api/CMbCommunicatorImp.cpp @@ -64,7 +64,8 @@ CMbCommunicatorImp::CMbCommunicatorImp(const char *pchName, const int *pAutoZipS zsock_set_identity(m_pSockCmd, pchName); if (0 != zsock_connect(m_pSockCmd, MB_P2C_CMD_ENDPOINT)) { - LOGERROR("CMbCommunicatorImp(): 0 != zsock_connect() !"); + const char *errMsg=zmq_strerror(zmq_errno()); + LOGERROR("CMbCommunicatorImp(): 0 != zsock_connect() errno(%d)_error(%s) !",zmq_errno(),errMsg); } //< 初始化m_pSockData @@ -79,7 +80,8 @@ CMbCommunicatorImp::CMbCommunicatorImp(const char *pchName, const int *pAutoZipS zsock_set_identity(m_pSockData, pchName); if (0 != zsock_connect(m_pSockData, MB_P2C_DATA_ENDPOINT)) { - LOGERROR("CMbCommunicatorImp(): 0 != zsock_connect() !"); + const char *errMsg=zmq_strerror(zmq_errno()); + LOGERROR("CMbCommunicatorImp(): 0 != zsock_connect() errno(%d)_error(%s) !",zmq_errno(),errMsg); } //< 初始化m_pPollerData @@ -444,8 +446,8 @@ bool CMbCommunicatorImp::sendMsgToDomain(kmbp_t **ppKmbpSend, const int nDomainI //< 释放本端引用 kmbp_cnt_dec(&pKmbpCnt); - - LOGWARN("sendMsgToDomain(): 0 != zsock_send() , return false !"); + const char *errMsg=zmq_strerror(zmq_errno()); + LOGWARN("sendMsgToDomain(): 0 != zsock_send() , return false ! errno(%d)_error(%s)",zmq_errno(),errMsg); return false; } diff --git a/platform/src/net/net_msg_bus_api/MsgBusApi.cpp b/platform/src/net/net_msg_bus_api/MsgBusApi.cpp index 0706619e..65562d31 100644 --- a/platform/src/net/net_msg_bus_api/MsgBusApi.cpp +++ b/platform/src/net/net_msg_bus_api/MsgBusApi.cpp @@ -8,8 +8,19 @@ **********************************************************************************/ #include "boost/typeof/typeof.hpp" + +//< 屏蔽xml_parser编译告警 +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-copy" +#endif + #include "boost/property_tree/xml_parser.hpp" +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #include "pub_logger_api/logger.h" #include "pub_utility_api/FileUtil.h" diff --git a/platform/src/net/net_msg_bus_base_api/CommonDef.h b/platform/src/net/net_msg_bus_base_api/CommonDef.h index 3c78c512..d5f2b90d 100644 --- a/platform/src/net/net_msg_bus_base_api/CommonDef.h +++ b/platform/src/net/net_msg_bus_base_api/CommonDef.h @@ -29,7 +29,7 @@ namespace iot_net //#define MB_H2P_PORT_INT ((int)6020) //#define MB_H2P_PORT_STR "6020" #if defined (__UTYPE_LINUX) -#define MB_H2P_ENDPOINT "ipc://@/kbd_msg_bus_h2p_ipc" +#define MB_H2P_ENDPOINT "ipc://@/iot_msg_bus_h2p_ipc" #else #define MB_H2P_ENDPOINT "tcp://127.0.0.1:6020" #endif diff --git a/platform/src/net/net_msg_bus_base_api/kmbmp.bnf b/platform/src/net/net_msg_bus_base_api/kmbmp.bnf index 99fad30e..c7809780 100644 --- a/platform/src/net/net_msg_bus_base_api/kmbmp.bnf +++ b/platform/src/net/net_msg_bus_base_api/kmbmp.bnf @@ -1,4 +1,4 @@ -The following ABNF grammar defines the 宏茂技术消息总线管理协议(KBD Message Bus Management Protocol): +The following ABNF grammar defines the 远信储能消息总线管理协议(KBD Message Bus Management Protocol): kmbmp = *( MEMORY-ALIGNMENT | COMMON-RETURN-TRUE | COMMON-RETURN-FALSE | M2H-LOCAL-INFO-REQ | H2M-LOCAL-INFO | M2H-REMOTE-INFO-REQ | H2M-REMOTE-INFO ) diff --git a/platform/src/net/net_msg_bus_base_api/kmbmp.c b/platform/src/net/net_msg_bus_base_api/kmbmp.c index 59f0c97b..52e34f03 100644 --- a/platform/src/net/net_msg_bus_base_api/kmbmp.c +++ b/platform/src/net/net_msg_bus_base_api/kmbmp.c @@ -1,5 +1,5 @@ /* ========================================================================= - kmbmp - 宏茂技术消息总线管理协议(KBD Message Bus Management Protocol) + kmbmp - 远信储能消息总线管理协议(KBD Message Bus Management Protocol) Codec class for kmbmp. @@ -17,7 +17,7 @@ /** @header - kmbmp - 宏茂技术消息总线管理协议(KBD Message Bus Management Protocol) + kmbmp - 远信储能消息总线管理协议(KBD Message Bus Management Protocol) @discuss @end */ diff --git a/platform/src/net/net_msg_bus_base_api/kmbmp.h b/platform/src/net/net_msg_bus_base_api/kmbmp.h index dc178db6..fbc3a1bd 100644 --- a/platform/src/net/net_msg_bus_base_api/kmbmp.h +++ b/platform/src/net/net_msg_bus_base_api/kmbmp.h @@ -1,5 +1,5 @@ /* ========================================================================= - kmbmp - 宏茂技术消息总线管理协议(KBD Message Bus Management Protocol) + kmbmp - 远信储能消息总线管理协议(KBD Message Bus Management Protocol) Codec header for kmbmp. diff --git a/platform/src/net/net_msg_bus_base_api/kmbmp.xml b/platform/src/net/net_msg_bus_base_api/kmbmp.xml index c3f7daec..5ab64b69 100644 --- a/platform/src/net/net_msg_bus_base_api/kmbmp.xml +++ b/platform/src/net/net_msg_bus_base_api/kmbmp.xml @@ -7,7 +7,7 @@ ******************************************************************************** --> - diff --git a/platform/src/net/net_msg_bus_base_api/kmbp.bnf b/platform/src/net/net_msg_bus_base_api/kmbp.bnf index 631da516..af4b29d8 100644 --- a/platform/src/net/net_msg_bus_base_api/kmbp.bnf +++ b/platform/src/net/net_msg_bus_base_api/kmbp.bnf @@ -1,4 +1,4 @@ -The following ABNF grammar defines the 宏茂技术消息总线协议(KBD Message Bus Protocol): +The following ABNF grammar defines the 远信储能消息总线协议(KBD Message Bus Protocol): kmbp = *( MEMORY-ALIGNMENT | COMMON-RETURN-TRUE | COMMON-RETURN-FALSE | C2H-DATA-PEER | C2H-DATA-HOST | C2H-DATA-DOMAIN | H2P-DATA | P2C-DATA | H2H-SUB-ALL | H2H-SUB-ALL-REQ | H2H-SUB-CHGCNT | H2H-SUB-CHGCNT-REQ | H2H-SUB-ADD | H2H-SUB-DEL | P2H-HEARTBEAT | P2H-SUB-ALL | H2P-SUB-ALL-REQ | P2H-SUB-ADD | P2H-SUB-DEL | C2P-REG | C2P-UNREG | C2P-SUB-ADD | C2P-SUB-DEL | C2P-SUB-ALL-REQ | P2C-SUB-ALL ) diff --git a/platform/src/net/net_msg_bus_base_api/kmbp.c b/platform/src/net/net_msg_bus_base_api/kmbp.c index a884dfad..5b53b45b 100644 --- a/platform/src/net/net_msg_bus_base_api/kmbp.c +++ b/platform/src/net/net_msg_bus_base_api/kmbp.c @@ -1,5 +1,5 @@ /* ========================================================================= - kmbp - 宏茂技术消息总线协议(KBD Message Bus Protocol) + kmbp - 远信储能消息总线协议(KBD Message Bus Protocol) Codec class for kmbp. @@ -17,7 +17,7 @@ /** @header - kmbp - 宏茂技术消息总线协议(KBD Message Bus Protocol) + kmbp - 远信储能消息总线协议(KBD Message Bus Protocol) @discuss @end */ diff --git a/platform/src/net/net_msg_bus_base_api/kmbp.h b/platform/src/net/net_msg_bus_base_api/kmbp.h index cf07c609..1faecadb 100644 --- a/platform/src/net/net_msg_bus_base_api/kmbp.h +++ b/platform/src/net/net_msg_bus_base_api/kmbp.h @@ -1,5 +1,5 @@ /* ========================================================================= - kmbp - 宏茂技术消息总线协议(KBD Message Bus Protocol) + kmbp - 远信储能消息总线协议(KBD Message Bus Protocol) Codec header for kmbp. diff --git a/platform/src/net/net_msg_bus_base_api/kmbp.xml b/platform/src/net/net_msg_bus_base_api/kmbp.xml index 95d4ebdd..b63dd481 100644 --- a/platform/src/net/net_msg_bus_base_api/kmbp.xml +++ b/platform/src/net/net_msg_bus_base_api/kmbp.xml @@ -7,7 +7,7 @@ ******************************************************************************** --> - diff --git a/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.cpp b/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.cpp index f675dbfe..8da8556b 100644 --- a/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.cpp +++ b/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.cpp @@ -21,10 +21,14 @@ static bool isIpFormatRight(const char *ipAddress) } addNodeDialog::addNodeDialog(QWidget *parent) : - QDialog(parent), + CustomUiDialog(parent), ui(new Ui::addNodeDialog) { + setWindowTitle(tr("添加节点")); + ui->setupUi(this); + + setAutoLayout(true); } addNodeDialog::~addNodeDialog() diff --git a/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.h b/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.h index 97705f5e..30287222 100644 --- a/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.h +++ b/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.h @@ -1,13 +1,13 @@ #ifndef ADDNODEDIALOG_H #define ADDNODEDIALOG_H -#include +#include"pub_widget/CustomDialog.h" namespace Ui { class addNodeDialog; } -class addNodeDialog : public QDialog +class addNodeDialog : public CustomUiDialog { Q_OBJECT diff --git a/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.ui b/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.ui index 92e0eb59..89865441 100644 --- a/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.ui +++ b/platform/src/net/net_msg_bus_mng_ping_gui/addnodedialog.ui @@ -13,54 +13,54 @@ Dialog - - - - 120 - 90 - 221 - 41 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 20 - 10 - 321 - 81 - - - - - - - 结点名称 - - - - - - - - - - 结点ip地址 - - - - - - - - + + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + 结点名称 + + + + + + + + + + 结点ip地址 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + diff --git a/platform/src/net/net_msg_bus_mng_ping_gui/main.cpp b/platform/src/net/net_msg_bus_mng_ping_gui/main.cpp index 7ed6b1c1..ac14fed2 100644 --- a/platform/src/net/net_msg_bus_mng_ping_gui/main.cpp +++ b/platform/src/net/net_msg_bus_mng_ping_gui/main.cpp @@ -1,12 +1,40 @@ #include "mainwindow.h" #include - #include - #include "czmq.h" #include "pub_logger_api/logger.h" #include "Common.h" #include "net_msg_bus_api/MsgBusApi.h" +#include "pub_utility_api/FileStyle.h" +#include + +void loadStyle() +{ + QString qss = QString(); + std::string strFullPath = iot_public::CFileStyle::getPathOfStyleFile("public.qss","zh","light"); + + QFile qssfile1(QString::fromStdString(strFullPath)); + qssfile1.open(QFile::ReadOnly); + if (qssfile1.isOpen()) + { + qss += QLatin1String(qssfile1.readAll()); + qssfile1.close(); + } + + strFullPath = iot_public::CFileStyle::getPathOfStyleFile("net_msg_bus_mng_ping_gui.qss","zh","light"); + QFile qssfile2(QString::fromStdString(strFullPath)); + qssfile2.open(QFile::ReadOnly); + if (qssfile2.isOpen()) + { + qss += QLatin1String(qssfile2.readAll()); + qssfile2.close(); + } + + if (!qss.isEmpty()) + { + qApp->setStyleSheet(qss); + } +} int main(int argc, char *argv[]) @@ -22,6 +50,8 @@ int main(int argc, char *argv[]) iot_public::StartLogSystem("default", "net_msg_bus_mng_ping_gui"); QApplication a(argc, argv); + loadStyle(); + MainWindow w; w.show(); diff --git a/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.cpp b/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.cpp index 26bcbd63..9bb77a98 100644 --- a/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.cpp +++ b/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.cpp @@ -34,10 +34,8 @@ #define treeWidgetIpType 3 - - MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), + CustomUiMainWindow(parent), ui(new Ui::MainWindow), m_browser(new QtTreePropertyBrowser(this)), m_strPropMngLocalHost(new QtStringPropertyManager(this)), @@ -46,16 +44,19 @@ MainWindow::MainWindow(QWidget *parent) : m_propMngremoteHostInfosGroup(new QtGroupPropertyManager(this)), m_timerAutoPing(new QTimer(this)) { + setAutoLayout(true); + setWindowTitle(tr("消息总线管理工具")); + ui->setupUi(this); // tabWidet填充整个mainwindow this->setCentralWidget(ui->tabWidget); // 分为两个tab,每个tab的宽度为主窗口的一半 - auto tabWidth = this->width()/2; - ui->tabWidget->setStyleSheet( ui->tabWidget->styleSheet() + - "QTabBar::tab {" - "width: " + QString::number(tabWidth) + "px; }" ); +// auto tabWidth = this->width()/2; +// ui->tabWidget->setStyleSheet( ui->tabWidget->styleSheet() + +// "QTabBar::tab {" +// "width: " + QString::number(tabWidth) + "px; }" ); loadTreeHosts(); loadCustomHosts(); @@ -118,6 +119,8 @@ MainWindow::MainWindow(QWidget *parent) : // ping查询结果返回到textbrowser上 connect(this,&MainWindow::signalPingQuery,this,&MainWindow::slotSendPingQuery); + + setContentsMargins(5,5,5,5); } MainWindow::~MainWindow() @@ -144,12 +147,14 @@ void MainWindow::resizeEvent(QResizeEvent *event) { // 重新绘制tab的宽度 // 分为两个tab,每个tab的宽度为主窗口的一半 - auto tabWidth = this->width()/2; - ui->tabWidget->setStyleSheet( ui->tabWidget->styleSheet() + - "QTabBar::tab {" - "width: " + QString::number(tabWidth) + "px; }" ); +// auto tabWidth = (this->width()-100)/2; +// ui->tabWidget->setStyleSheet( ui->tabWidget->styleSheet() + +// "QTabBar::tab {" +// "width: " + QString::number(tabWidth) + "px; }" ); - Q_UNUSED(event); +// Q_UNUSED(event); + + CustomUiMainWindow::resizeEvent(event); } void MainWindow::loadTreeHosts() diff --git a/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.h b/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.h index 12551915..3248e736 100644 --- a/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.h +++ b/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.h @@ -15,12 +15,13 @@ #include "qteditorfactory.h" #include "qttreepropertybrowser.h" #include "cmbping.h" +#include "pub_widget/CustomMainWindow.h" namespace Ui { class MainWindow; } -class MainWindow : public QMainWindow +class MainWindow : public CustomUiMainWindow { Q_OBJECT public: diff --git a/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.ui b/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.ui index e5087f23..2520de6e 100644 --- a/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.ui +++ b/platform/src/net/net_msg_bus_mng_ping_gui/mainwindow.ui @@ -15,6 +15,9 @@ + + 9 + @@ -28,7 +31,7 @@ - mng + 节点管理 @@ -107,7 +110,7 @@ - ping + PING @@ -514,7 +517,7 @@ 请选择功能,然后输入参数,然后点击go按钮 输入参数参考 -主机名:kbd-rd-gyh (通过hostname命令得到) +主机名:db01 (通过hostname命令得到) 进程名:rdb_server 实例:rdb_server -a COMAPP 进程号(pid):55558 diff --git a/platform/src/net/net_msg_bus_mng_ping_gui/net_msg_bus_mng_ping_gui.pro b/platform/src/net/net_msg_bus_mng_ping_gui/net_msg_bus_mng_ping_gui.pro index 1a6e51bc..41825970 100644 --- a/platform/src/net/net_msg_bus_mng_ping_gui/net_msg_bus_mng_ping_gui.pro +++ b/platform/src/net/net_msg_bus_mng_ping_gui/net_msg_bus_mng_ping_gui.pro @@ -12,7 +12,8 @@ TARGET = net_msg_bus_mng_ping_gui TEMPLATE = app LIBS += -lboost_system -lboost_program_options -lzmq -lczmq -llog4cplus \ - -lpub_logger_api -lnet_msg_bus_base_api -lnet_msg_bus_api -lpub_sysinfo_api + -lpub_logger_api -lnet_msg_bus_base_api -lnet_msg_bus_api -lpub_sysinfo_api \ + -lpub_widget -lpub_utility_api diff --git a/platform/src/net/net_msg_bus_relay/CDomainMng.cpp b/platform/src/net/net_msg_bus_relay/CDomainMng.cpp index 966a39c7..6bb5da1d 100644 --- a/platform/src/net/net_msg_bus_relay/CDomainMng.cpp +++ b/platform/src/net/net_msg_bus_relay/CDomainMng.cpp @@ -9,8 +9,19 @@ #include "boost/typeof/typeof.hpp" #include "boost/lexical_cast.hpp" + +//< 屏蔽xml_parser编译告警 +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-copy" +#endif + #include "boost/property_tree/xml_parser.hpp" +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #include "pub_logger_api/logger.h" #include "pub_utility_api/FileUtil.h" diff --git a/platform/src/net/net_msg_bus_relay/CDomainThread.cpp b/platform/src/net/net_msg_bus_relay/CDomainThread.cpp index 780c8d0b..5806073b 100644 --- a/platform/src/net/net_msg_bus_relay/CDomainThread.cpp +++ b/platform/src/net/net_msg_bus_relay/CDomainThread.cpp @@ -8,12 +8,10 @@ **********************************************************************************/ #include "pub_logger_api/logger.h" - #include "../net_msg_bus_base_api/CommonDef.h" - #include "CDomainMng.h" - #include "CDomainThread.h" +#include "boost/concept_check.hpp" namespace iot_net { @@ -76,6 +74,7 @@ CDomainThread::CActWorker* CDomainThread::CActWorker::newCActWorker(zsock_t *pAc //< 设置m_pLoop事件驱动,优先级与书写顺序有关 bool bRc = self->setSocketHandle(self->m_pActorPipe, handleActorPipe); assert(bRc); + boost::ignore_unused_variable_warning(bRc); //< 此处不添加m_pSockDataIn的接收处理 //bRc = setSocketHandle(self, self->m_pSockDataIn, handleSockDataIn); @@ -83,6 +82,7 @@ CDomainThread::CActWorker* CDomainThread::CActWorker::newCActWorker(zsock_t *pAc int nPendingMsgTimerID = zloop_timer(self->m_pLoop, 1000, 0, handlePendingMsgTimer, self); assert(nPendingMsgTimerID >= 0); + boost::ignore_unused_variable_warning(nPendingMsgTimerID); } //< m_vecRemoteConn @@ -386,6 +386,8 @@ int CDomainThread::CActWorker::handleActorPipe(zloop_t *, zsock_t *reader, void int CDomainThread::CActWorker::handleSockDataIn(zloop_t *, zsock_t *reader, void *arg) { + boost::ignore_unused_variable_warning(reader); + CActWorker *self = (CActWorker *)arg; assert(reader == self->m_pSockDataIn); @@ -427,6 +429,7 @@ int CDomainThread::CActWorker::delaySockDataIn(zloop_t *, int timer_id, void *ar //< 恢复接收 m_pSockDataIn 的消息 bool bRc = self->setSocketHandle(self->m_pSockDataIn, handleSockDataIn); assert(bRc); + boost::ignore_unused_variable_warning(bRc); } //< 取消本定时器 @@ -438,6 +441,7 @@ int CDomainThread::CActWorker::delaySockDataIn(zloop_t *, int timer_id, void *ar //< 取消接收 m_pSockDataIn 的消息 bool bRc = self->setSocketHandle(self->m_pSockDataIn, NULL); assert(bRc); + boost::ignore_unused_variable_warning(bRc); //< 设置定时器,到时恢复,单位ms self->m_nDelaySockDataInTimerID = zloop_timer(self->m_pLoop, 100, 1, delaySockDataIn, self); diff --git a/platform/src/net/net_msg_bus_relay/CMainThread.cpp b/platform/src/net/net_msg_bus_relay/CMainThread.cpp index d1b47b69..f30bdb46 100644 --- a/platform/src/net/net_msg_bus_relay/CMainThread.cpp +++ b/platform/src/net/net_msg_bus_relay/CMainThread.cpp @@ -9,13 +9,10 @@ #include "boost/typeof/typeof.hpp" #include "boost/format.hpp" - +#include "boost/concept_check.hpp" #include "pub_logger_api/logger.h" - #include "../net_msg_bus_base_api/CommonDef.h" - #include "CDomainMng.h" - #include "CMainThread.h" namespace iot_net @@ -284,6 +281,7 @@ int CMainThread::CActWorker::handleActorPipe(zloop_t *, zsock_t *reader, void *a CActWorker *self = (CActWorker *)arg; assert(reader == self->m_pActorPipe); + boost::ignore_unused_variable_warning(self); bool bTerm = false; @@ -348,6 +346,7 @@ int CMainThread::CActWorker::delaySockRemote(zloop_t *, int timer_id, void *arg) //< 恢复接收m_pSockRemote的消息 bool bRc = self->setSocketHandle(self->m_pSockRemote, handleSockRemote); assert(bRc); + boost::ignore_unused_variable_warning(bRc); } //< 取消本定时器 @@ -359,6 +358,7 @@ int CMainThread::CActWorker::delaySockRemote(zloop_t *, int timer_id, void *arg) //< 取消接收m_pSockRemote的消息 bool bRc = self->setSocketHandle(self->m_pSockRemote, NULL); assert(bRc); + boost::ignore_unused_variable_warning(bRc); //< 设置定时器,到时恢复,单位ms self->m_nDelaySockRemoteTimerID = zloop_timer(self->m_pLoop, 100, 1, delaySockRemote, self); @@ -624,6 +624,7 @@ int CMainThread::CActWorker::handleSockLocalMon(zloop_t *, zsock_t *reader, void //< 取消接收 m_pSockRemote 的消息 bool bRc = self->setSocketHandle(self->m_pSockRemote, NULL); assert(bRc); + boost::ignore_unused_variable_warning(bRc); } break; case ZMQ_EVENT_CONNECTED: @@ -639,6 +640,8 @@ int CMainThread::CActWorker::handleSockLocalMon(zloop_t *, zsock_t *reader, void //< 设置接收 m_pSockRemote 的消息 bool bRc = self->setSocketHandle(self->m_pSockRemote, handleSockRemote); assert(bRc); + boost::ignore_unused_variable_warning(bRc); + if (self->m_nDelaySockRemoteTimerID >= 0) { //< 如果有延迟接收定时器,取消它,避免重复添加reader,zloop的说明如下: diff --git a/platform/src/net/net_msg_bus_relay/CRemoteConn.cpp b/platform/src/net/net_msg_bus_relay/CRemoteConn.cpp index 02b3a2a2..0be98dac 100644 --- a/platform/src/net/net_msg_bus_relay/CRemoteConn.cpp +++ b/platform/src/net/net_msg_bus_relay/CRemoteConn.cpp @@ -8,12 +8,10 @@ **********************************************************************************/ #include "pub_logger_api/logger.h" - #include "../net_msg_bus_base_api/CommonDef.h" - #include "CDomainMng.h" - #include "CRemoteConn.h" +#include "boost/concept_check.hpp" namespace iot_net { @@ -258,6 +256,7 @@ int CRemoteConn::handleSockConn(zloop_t *, zsock_t *reader, void *arg) CRemoteConn *self = (CRemoteConn *)arg; assert(reader == self->m_pSockConn); + boost::ignore_unused_variable_warning(self); //< 当前,不应该收到任何消息 //< 将收到的消息释放,避免占用内存 diff --git a/platform/src/net/net_msg_bus_test/client_dealer/client_dealer.pro b/platform/src/net/net_msg_bus_test/client_dealer/client_dealer.pro new file mode 100644 index 00000000..71940920 --- /dev/null +++ b/platform/src/net/net_msg_bus_test/client_dealer/client_dealer.pro @@ -0,0 +1,32 @@ + +QT -= gui core +CONFIG -= qt + +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app +TARGET = net_msg_bus_test_client_dealer + +LIBS += -lboost_system -lboost_thread -llog4cplus -lpub_logger_api -lzmq -lczmq + +win32{ + LIBS += -lboost_date_time +} +else{ + LIBS += -lpthread +} + + +#HEADERS += + +SOURCES += main.cpp + +#------------------------------------------------------------------- +COMMON_PRI=$$PWD/../../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} + diff --git a/platform/src/net/net_msg_bus_test/client_dealer/main.cpp b/platform/src/net/net_msg_bus_test/client_dealer/main.cpp new file mode 100644 index 00000000..271861d2 --- /dev/null +++ b/platform/src/net/net_msg_bus_test/client_dealer/main.cpp @@ -0,0 +1,83 @@ + +/******************************************************************************//** +* @file +* @brief +* @author yikenan +* @version 1.0 +* @date +**********************************************************************************/ + +#include +#include +#include + +#include "boost/thread.hpp" + +#include "pub_logger_api/logger.h" +#include "czmq.h" + +static volatile bool g_bNeedExit = false; +#define WORKER_READY "hello caodingfa" // Signals worker is ready + +static void signalCallback(int /*sig*/) +{ + std::cout << "signalCallback()" << std::endl; + + g_bNeedExit = true; +} + +int main(int /*argc*/, char ** /*argv[]*/) +{ + signal(SIGTERM, signalCallback); + signal(SIGINT, signalCallback); +#ifdef WIN32 + signal(SIGBREAK, signalCallback); +#else + signal(SIGQUIT, signalCallback); +#endif + + //< 启动日志 + iot_public::StartLogSystem("default", "net_msg_bus_test_client_dealer"); + + LOGINFO("Log system OK !"); + + zsock_t *client = zsock_new(ZMQ_DEALER); + zsock_set_sndhwm(client,2); + zsock_set_sndtimeo(client,10); + zsock_set_identity(client,"fes"); +// zframe_t *frame = zframe_new(WORKER_READY, strlen(WORKER_READY)); +// zsock_set_hello_msg(client,frame); +// zsock_set_heartbeat_ivl(client,10*1000); + + printf("begin connect\n"); + zsock_connect(client,"tcp://localhost:8888"); + printf("end connect\n"); + + zpoller_t *poller = zpoller_new (client, NULL); + zpoller_set_nonstop (poller, true); + + int request_nbr = 0; + + while (!g_bNeedExit) + { + int ret = zstr_sendf (client, "request #%d", ++request_nbr); + printf("ret=%d request #%d\n", ret,request_nbr); + + zsock_t *pReader = (zsock_t *)zpoller_wait(poller,2000); + if(pReader == NULL) + { + continue; + } + +// zmq_sleep(1); + zmsg_t *msg = zmsg_recv (client); + zframe_print (zmsg_last (msg), "recv:"); + zmsg_destroy(&msg); + } + + //< 停止日志系统 + iot_public::StopLogSystem(); + + return 0; +} + diff --git a/platform/src/net/net_msg_bus_test/net_msg_bus_test.pro b/platform/src/net/net_msg_bus_test/net_msg_bus_test.pro index 3af2cdfc..adf6ed2b 100644 --- a/platform/src/net/net_msg_bus_test/net_msg_bus_test.pro +++ b/platform/src/net/net_msg_bus_test/net_msg_bus_test.pro @@ -6,4 +6,6 @@ SUBDIRS += receiver \ sender \ client \ server \ + client_dealer \ + server_router diff --git a/platform/src/net/net_msg_bus_test/sender/main.cpp b/platform/src/net/net_msg_bus_test/sender/main.cpp index 2f99567c..1380fe20 100644 --- a/platform/src/net/net_msg_bus_test/sender/main.cpp +++ b/platform/src/net/net_msg_bus_test/sender/main.cpp @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) objMsgToSend.setPara1(nLoop); bSendRc = pMbComm->sendMsgToDomain(objMsgToSend); //bSendRc = g_pComm->sendMsgToHost(objMsgToSend); - //bSendRc = g_pComm->sendMsgToPeer(objMsgToSend, "Comm1", "Proc2", "Inst1", -1, "kbd-rd-ykn"); + //bSendRc = g_pComm->sendMsgToPeer(objMsgToSend, "Comm1", "Proc2", "Inst1", -1, "host1"); if (!bSendRc) { diff --git a/platform/src/net/net_msg_bus_test/server_router/main.cpp b/platform/src/net/net_msg_bus_test/server_router/main.cpp new file mode 100644 index 00000000..b5985662 --- /dev/null +++ b/platform/src/net/net_msg_bus_test/server_router/main.cpp @@ -0,0 +1,106 @@ + +/******************************************************************************//** +* @file +* @brief +* @author yikenan +* @version 1.0 +* @date +**********************************************************************************/ + +#include +#include + +#include "boost/thread.hpp" + +#include "pub_logger_api/logger.h" + +#include "net_msg_bus_api/MsgBusApi.h" +#include "czmq.h" +#include + + +static volatile bool g_bNeedExit = false; +#define WORKER_READY "hello caodingfa" // Signals worker is ready + + +static void signalCallback(int /*sig*/) +{ + std::cout << "signalCallback()" << std::endl; + + g_bNeedExit = true; +} + +int main(int /*argc*/, char ** /*argv[]*/) +{ + typedef boost::icl::interval_set set_t; + typedef set_t::interval_type ival; + set_t outages; + + outages.insert(ival::closed(1,9)); + outages.insert(ival::open(7,10)); + outages.insert(ival::open(8,11)); + outages.insert(ival::open(90,120)); + + for(set_t::iterator it = outages.begin(); it != outages.end(); it++){ + std::cout << it->lower() << ", " << it->upper() << "\n"; + } + + return 0; + + + signal(SIGTERM, signalCallback); + signal(SIGINT, signalCallback); +#ifdef WIN32 + signal(SIGBREAK, signalCallback); +#else + signal(SIGQUIT, signalCallback); +#endif + + //< 启动日志 + iot_public::StartLogSystem("default", "net_msg_bus_test_server"); + + LOGINFO("Log system OK !"); + + zsock_t *server = zsock_new(ZMQ_ROUTER); + zframe_t *frame = zframe_new(WORKER_READY, strlen(WORKER_READY)); + zsock_set_hello_msg(server,frame); + + zsock_bind(server,"tcp://*:5570"); + zpoller_t *poller = zpoller_new (server, NULL); + zpoller_set_nonstop (poller, true); + + int request_nbr = 0; + + while (!g_bNeedExit) + { + zsock_t *pReader = (zsock_t *)zpoller_wait(poller,2000); + if(pReader == NULL) + { + continue; + } + + zmsg_t *msg = zmsg_recv (server); + printf("recv msg size=%d\n",(int)zmsg_size(msg)); + zframe_print (zmsg_last (msg), "recv:"); + zframe_print (zmsg_first(msg), "recv2:"); + printf("\n"); + zmsg_destroy(&msg); + + zmsg_t *sendMsg = zmsg_new (); + zmsg_addstr(sendMsg,"fes"); + zmsg_addstrf(sendMsg,"request #%d",--request_nbr); + int ret = zmsg_send(&sendMsg,server); + zmsg_destroy(&sendMsg); + + //int ret = zstr_sendf (pReader, "request #%d", --request_nbr); + printf("ret=%d request #%d\n", ret,request_nbr); +// zmq_sleep(1); + } + + + //< 停止日志系统 + iot_public::StopLogSystem(); + + return 0; +} + diff --git a/platform/src/net/net_msg_bus_test/server_router/server_router.pro b/platform/src/net/net_msg_bus_test/server_router/server_router.pro new file mode 100644 index 00000000..bdf915c5 --- /dev/null +++ b/platform/src/net/net_msg_bus_test/server_router/server_router.pro @@ -0,0 +1,32 @@ + +QT -= gui core +CONFIG -= qt + +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app +TARGET = net_msg_bus_test_server_router + +LIBS += -lboost_system -lboost_thread -llog4cplus -lpub_logger_api -lzmq -lczmq + +win32{ + LIBS += -lboost_date_time +} +else{ + LIBS += -lpthread +} + + +#HEADERS += + +SOURCES += main.cpp + +#------------------------------------------------------------------- +COMMON_PRI=$$PWD/../../../common.pri +exists($$COMMON_PRI) { + include($$COMMON_PRI) +}else { + error("FATAL error: can not find common.pri") +} + diff --git a/platform/src/net/net_snmp_agent/AgentCommon.cpp b/platform/src/net/net_snmp_agent/AgentCommon.cpp index 011feac6..757f9304 100644 --- a/platform/src/net/net_snmp_agent/AgentCommon.cpp +++ b/platform/src/net/net_snmp_agent/AgentCommon.cpp @@ -35,8 +35,19 @@ //< 纯头文件,不会引入动态库依赖,不影响单程序发布 #include "boost/typeof/typeof.hpp" #include "boost/program_options.hpp" + +//< 屏蔽xml_parser编译告警 +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-copy" +#endif + #include "boost/property_tree/xml_parser.hpp" +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #include "AgentCommon.h" namespace iot_net @@ -50,7 +61,7 @@ bool g_bNeedExit = false; sigar_t *g_pSigar = nullptr; //< 模块名,调用日志时使用 -const char *cn_szModuleName = "kbd"; +const char *cn_szModuleName = "agent"; //< 进程名最大长度 //< 比如Linux系统限制进程名最大长度为15个字符(即加上最后的\0是16Byte),超过则截断 diff --git a/platform/src/net/net_snmp_agent/CAgentServer.cpp b/platform/src/net/net_snmp_agent/CAgentServer.cpp index b540c5ac..f45dcc88 100644 --- a/platform/src/net/net_snmp_agent/CAgentServer.cpp +++ b/platform/src/net/net_snmp_agent/CAgentServer.cpp @@ -179,8 +179,8 @@ bool CAgentServer::initialize() std::string strLogFile("/net_snmp_agent.log"); int nLogErrFlt = 15, nLogWarFlt = 4, nLogEvtFlt = 0, nLogInfFlt = 0, nLogDbgFlt = 0, nLogUsrFlt = ULL_EVENT; std::string strCommunity("public"); - std::string strAdminAuth("kbdct"); - std::string strAdminPriv("kbdct@0755"); + std::string strAdminAuth("admin"); + std::string strAdminPriv(EMS_DEFAULT_PASSWD); std::set setProcWhiteList; const std::string &&strCurModuleDir = iot_net::getCurModuleDir(); @@ -298,7 +298,7 @@ bool CAgentServer::initialize() //< 业务相关 { //< add() 后由MIB接管,无需我们来释放内存 - pMib->add(new sysGroup("Agent of KBDCT", CN_OID_KBD_ROOT, 10)); + pMib->add(new sysGroup("Snmp Agent", CN_OID_KBD_ROOT, 10)); pMib->add(new snmpGroup()); //mib->add(new snmp_target_mib()); //mib->add(new snmp_notification_mib()); @@ -326,14 +326,17 @@ bool CAgentServer::initialize() void CAgentServer::release() { - //< 如果有尚未处理完的请求,析构Mib时会“死等”,分析其源码,是Agent++的Bug - while (!pMib->get_thread_pool()->is_idle()) + if( pMib ) { - Thread::sleep(100); - } + //< 如果有尚未处理完的请求,析构Mib时会“死等”,分析其源码,是Agent++的Bug + while (!pMib->get_thread_pool()->is_idle()) + { + Thread::sleep(100); + } - delete pMib; - pMib = nullptr; + delete pMib; + pMib = nullptr; + } delete pReqList; pReqList = nullptr; @@ -354,8 +357,11 @@ void CAgentServer::release() pCpuGroup = nullptr; pProcessGroup = nullptr; - sigar_close(g_pSigar); - g_pSigar = nullptr; + if( g_pSigar ) + { + sigar_close(g_pSigar); + g_pSigar = nullptr; + } Snmp::socket_cleanup(); diff --git a/platform/src/net/net_snmp_agent/MainLinux.cpp b/platform/src/net/net_snmp_agent/MainLinux.cpp index b8b0217f..e2e80e61 100644 --- a/platform/src/net/net_snmp_agent/MainLinux.cpp +++ b/platform/src/net/net_snmp_agent/MainLinux.cpp @@ -29,15 +29,15 @@ static void handleSigno(int nSigno) iot_net::g_bNeedExit = true; } -static const char *szSystemdCfgFile = "/lib/systemd/system/kbd_snmp_agent.service"; +static const char *szSystemdCfgFile = "/usr/lib/systemd/system/byd_snmp_agent.service"; //< 注册系统服务,并设置自启动 static bool regSysService() { //< 判断服务是否已注册,普通用户权限可执行 - if (0 == std::system("systemctl is-enabled kbd_snmp_agent.service")) + if (0 == std::system("systemctl is-enabled byd_snmp_agent.service")) { - printf("\nSystem service kbd_snmp_agent already enabled, exit.\n"); + printf("\nSystem service byd_snmp_agent already enabled, exit.\n"); return false; } @@ -52,7 +52,7 @@ static bool regSysService() // fclose(pFile); // } - const std::string strExec = iot_net::getCurModuleDir() + "/net_snmp_agent -s"; + const std::string strExec = iot_net::getCurModuleDir() + "net_snmp_agent -s"; //< 生成或修改systemd服务配置文件 try @@ -60,7 +60,7 @@ static bool regSysService() using namespace boost::property_tree; ptree objPtree; - objPtree.put("Unit.Description", "kbd_snmp_agent"); + objPtree.put("Unit.Description", "byd_snmp_agent"); objPtree.put("Unit.After", "network.target"); objPtree.put("Service.Type", "simple"); @@ -87,13 +87,13 @@ static bool regSysService() } //< 设置服务开机自启动 - if (0 != std::system("systemctl enable kbd_snmp_agent.service")) + if (0 != std::system("systemctl enable byd_snmp_agent.service")) { printf("\nEnable service failed, exit.\n"); return false; } - printf("\nSuccessfully registered system service kbd_snmp_agent.\n"); + printf("\nSuccessfully registered system service byd_snmp_agent.\n"); return true; } @@ -112,7 +112,7 @@ static bool unregSysService() //< 重新加载一次,确保systemd配置与文件一致,需需管理员权限 nRc = std::system("systemctl daemon-reload"); - printf("\nSystem service kbd_snmp_agent has not been registered.\n"); + printf("\nSystem service byd_snmp_agent has not been registered.\n"); return false; } else @@ -120,10 +120,10 @@ static bool unregSysService() } //< 停止服务 - nRc = std::system("systemctl stop kbd_snmp_agent.service"); + nRc = std::system("systemctl stop byd_snmp_agent.service"); //< 取消服务开机自启动 - nRc = std::system("systemctl disable kbd_snmp_agent.service"); + nRc = std::system("systemctl disable byd_snmp_agent.service"); //< 删除服务配置文件 remove(szSystemdCfgFile); @@ -131,7 +131,7 @@ static bool unregSysService() //< systemd重新加载配置文件 nRc = std::system("systemctl daemon-reload"); - printf("\nSuccessfully unregistered system service kbd_snmp_agent.\n"); + printf("\nSuccessfully unregistered system service byd_snmp_agent.\n"); return true; } diff --git a/platform/src/net/net_snmp_agent/MainWindows.cpp b/platform/src/net/net_snmp_agent/MainWindows.cpp index a0b7b33a..edbca609 100644 --- a/platform/src/net/net_snmp_agent/MainWindows.cpp +++ b/platform/src/net/net_snmp_agent/MainWindows.cpp @@ -29,7 +29,7 @@ static void handleSigno(int nSigno) iot_net::g_bNeedExit = true; } -#define CN_SERVICE_NAME "kbd_snmp_agent" +#define CN_SERVICE_NAME "byd_snmp_agent" static const char *szServiceName = CN_SERVICE_NAME; static SERVICE_STATUS_HANDLE g_hServiceStatus = NULL; static LPSERVICE_STATUS g_pStatus = NULL; @@ -52,7 +52,7 @@ static bool regSysService() SC_HANDLE hService = ::OpenServiceA(hSCM, szServiceName, SERVICE_QUERY_CONFIG); if (NULL == hService) { - const std::string strExec = iot_net::getCurModuleDir() + "/net_snmp_agent.exe -s"; + const std::string strExec = iot_net::getCurModuleDir() + "net_snmp_agent.exe -s"; //< 创建服务 @@ -72,7 +72,7 @@ static bool regSysService() else { SERVICE_DESCRIPTIONA stSrvDesc; - char szDesc[] = "The SNMP agent of KBD."; + char szDesc[] = "The SNMP agent"; stSrvDesc.lpDescription = szDesc; if (::ChangeServiceConfig2A(hService, SERVICE_CONFIG_DESCRIPTION, &stSrvDesc)) { @@ -84,7 +84,7 @@ static bool regSysService() } else { - printf("System service kbd_snmp_agent already exists.\n"); + printf("System service byd_snmp_agent already exists.\n"); ::CloseServiceHandle(hService); } @@ -92,7 +92,7 @@ static bool regSysService() } if(bRet) - printf("\nSuccessfully registered system service kbd_snmp_agent.\n"); + printf("\nSuccessfully registered system service byd_snmp_agent.\n"); return bRet; } @@ -115,7 +115,7 @@ static bool unregSysService() if (NULL == hService) { //< 服务不存在 - printf("System service kbd_snmp_agent not exists.\n"); + printf("System service byd_snmp_agent not exists.\n"); } else { @@ -171,7 +171,7 @@ static bool unregSysService() } if(bRet) - printf("\nSuccessfully unregistered system service kbd_snmp_agent.\n"); + printf("\nSuccessfully unregistered system service byd_snmp_agent.\n"); return bRet; } diff --git a/platform/src/net/net_snmp_agent/ProcessGroup.cpp b/platform/src/net/net_snmp_agent/ProcessGroup.cpp index f87e9e37..179cb96e 100644 --- a/platform/src/net/net_snmp_agent/ProcessGroup.cpp +++ b/platform/src/net/net_snmp_agent/ProcessGroup.cpp @@ -201,9 +201,12 @@ void CProcessGroup::CTabByCrc32::updateOfMine(unsigned long &nTotal, unsigned lo ++nRunning; break; case SIGAR_PROC_STATE_SLEEP: + case SIGAR_PROC_STATE_DISK_SLEEP: // added by yikenan ++nSleeping; break; case SIGAR_PROC_STATE_STOP: + case SIGAR_PROC_STATE_TRACE: // added by yikenan + case SIGAR_PROC_STATE_DEAD: // added by yikenan,是否合理待商榷 ++nStopped; break; case SIGAR_PROC_STATE_ZOMBIE: diff --git a/platform/src/net/net_snmp_agent/test/snmp_test.sh b/platform/src/net/net_snmp_agent/test/snmp_test.sh index 320120cd..963c9950 100644 --- a/platform/src/net/net_snmp_agent/test/snmp_test.sh +++ b/platform/src/net/net_snmp_agent/test/snmp_test.sh @@ -1,6 +1,6 @@ #!/bin/sh while true do -#snmpbulkwalk -v 3 -u admin -l authPriv -a sha -A kbdct@0755 -x des -X kbdct@0755 192.168.77.79:4700 ".1.3" -snmpbulkwalk -v 3 -u admin -l authPriv -a sha -A kbdct@0755 -x des -X kbdct@0755 127.0.0.1:4700 ".1.3" +#snmpbulkwalk -v 3 -u admin -l authPriv -a sha -A ems@byd23 -x des -X ems@byd23 192.168.77.79:4700 ".1.3" +snmpbulkwalk -v 3 -u admin -l authPriv -a sha -A ems@byd23 -x des -X ems@byd23 127.0.0.1:4700 ".1.3" done