[ref]同步

This commit is contained in:
shi_jq 2025-03-12 17:44:25 +08:00
parent 9bf9491684
commit 41b52470df
44 changed files with 514 additions and 141 deletions

View File

@ -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

View File

@ -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() )
{

View File

@ -9,7 +9,7 @@
#include <QSettings>
#include <QTextCodec>
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)

View File

@ -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))
{

View File

@ -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);

View File

@ -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"

View File

@ -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);
//< 当前,不应该收到任何消息
//< 将收到的消息释放,避免占用内存

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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"

View File

@ -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

View File

@ -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 )

View File

@ -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
*/

View File

@ -1,5 +1,5 @@
/* =========================================================================
kmbmp - 线KBD Message Bus Management Protocol
kmbmp - 线KBD Message Bus Management Protocol
Codec header for kmbmp.

View File

@ -7,7 +7,7 @@
******************************************************************************** -->
<!-- signature用于协议版本校验本协议起始值6000当修改本协议与之前版本不兼容时需将signature加1 -->
<class name="kmbmp" signature="6000" title="宏茂技术消息总线管理协议KBD Message Bus Management Protocol"
<class name="kmbmp" signature="6000" title="远信储能消息总线管理协议KBD Message Bus Management Protocol"
script="./my_zproto_codec_c.gsl" package_dir="." source_dir="."
export_header="mb_base_api_exp.h" export_macro="MSGBUS_BASE_API">

View File

@ -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 )

View File

@ -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
*/

View File

@ -1,5 +1,5 @@
/* =========================================================================
kmbp - 线KBD Message Bus Protocol
kmbp - 线KBD Message Bus Protocol
Codec header for kmbp.

View File

@ -7,7 +7,7 @@
******************************************************************************** -->
<!-- signature用于协议版本校验本协议起始值0755当修改本协议与之前版本不兼容时需将signature加1 -->
<class name="kmbp" signature="0756" title="宏茂技术消息总线协议KBD Message Bus Protocol"
<class name="kmbp" signature="0756" title="远信储能消息总线协议KBD Message Bus Protocol"
script="./my_zproto_codec_c.gsl" package_dir="." source_dir="."
export_header="mb_base_api_exp.h" export_macro="MSGBUS_BASE_API">

View File

@ -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()

View File

@ -1,13 +1,13 @@
#ifndef ADDNODEDIALOG_H
#define ADDNODEDIALOG_H
#include <QDialog>
#include"pub_widget/CustomDialog.h"
namespace Ui {
class addNodeDialog;
}
class addNodeDialog : public QDialog
class addNodeDialog : public CustomUiDialog
{
Q_OBJECT

View File

@ -13,54 +13,54 @@
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>120</x>
<y>90</y>
<width>221</width>
<height>41</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>321</width>
<height>81</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>结点名称</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>结点ip地址</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_address"/>
</item>
</layout>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>结点名称</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>结点ip地址</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_address"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>

View File

@ -1,12 +1,40 @@
#include "mainwindow.h"
#include <QApplication>
#include <iostream>
#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 <QFile>
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();

View File

@ -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()

View File

@ -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:

View File

@ -15,6 +15,9 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>9</number>
</property>
<item row="0" column="1">
<widget class="QTabWidget" name="tabWidget">
<property name="minimumSize">
@ -28,7 +31,7 @@
</property>
<widget class="QWidget" name="tab_mng">
<attribute name="title">
<string>mng</string>
<string>节点管理</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
@ -107,7 +110,7 @@
</widget>
<widget class="QWidget" name="tab_ping">
<attribute name="title">
<string>ping</string>
<string>PING</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_10">
<item row="0" column="0">
@ -514,7 +517,7 @@
请选择功能,然后输入参数,然后点击go按钮
输入参数参考
主机名:kbd-rd-gyh (通过hostname命令得到)
主机名:db01 (通过hostname命令得到)
进程名:rdb_server
实例:rdb_server -a COMAPP
进程号(pid):55558

View File

@ -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

View File

@ -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"

View File

@ -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);

View File

@ -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)
{
//< 如果有延迟接收定时器取消它避免重复添加readerzloop的说明如下

View File

@ -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);
//< 当前,不应该收到任何消息
//< 将收到的消息释放,避免占用内存

View File

@ -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")
}

View File

@ -0,0 +1,83 @@

/******************************************************************************//**
* @file
* @brief
* @author yikenan
* @version 1.0
* @date
**********************************************************************************/
#include <signal.h>
#include <stdlib.h>
#include <iostream>
#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;
}

View File

@ -6,4 +6,6 @@ SUBDIRS += receiver \
sender \
client \
server \
client_dealer \
server_router

View File

@ -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)
{

View File

@ -0,0 +1,106 @@

/******************************************************************************//**
* @file
* @brief
* @author yikenan
* @version 1.0
* @date
**********************************************************************************/
#include <signal.h>
#include <iostream>
#include "boost/thread.hpp"
#include "pub_logger_api/logger.h"
#include "net_msg_bus_api/MsgBusApi.h"
#include "czmq.h"
#include <boost/icl/interval_set.hpp>
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<unsigned int> 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;
}

View File

@ -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")
}

View File

@ -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超过则截断

View File

@ -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<std::string> 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();

View File

@ -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<const char *>("Unit.Description", "kbd_snmp_agent");
objPtree.put<const char *>("Unit.Description", "byd_snmp_agent");
objPtree.put<const char *>("Unit.After", "network.target");
objPtree.put<const char *>("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;
}

View File

@ -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;
}

View File

@ -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:

View File

@ -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