[add]添加进程监控信号输出服务
This commit is contained in:
parent
aca9d6f29a
commit
a87fcc01a4
@ -114,5 +114,8 @@ queueSize : 异步模式下日志队列大小,程序默认值100,单位条
|
||||
<subConfigure level="debug" file="net_msg_tool.log" maxFileSize="10485760" maxBackupIndex="10" createDirs="true" appender="RollingFileAppender" async="true" queueSize="1000" encoding="UTF-8" conversionPattern="%D{%y-%m-%d %H:%M:%S.%q} %p %T %l - %m %n"/>
|
||||
<subConfigure level="error" file="net_msg_tool.log" maxFileSize="10485760" maxBackupIndex="10" createDirs="true" appender="RollingFileAppender" async="true" queueSize="1000" encoding="UTF-8" conversionPattern="%D{%y-%m-%d %H:%M:%S.%q} %p %T %l - %m %n"/>
|
||||
</process>
|
||||
|
||||
<process name="signal_srv">
|
||||
<subConfigure level="info" file="signal_srv.log" maxFileSize="10485760" maxBackupIndex="10" createDirs="true" appender="RollingFileAppender" async="true" queueSize="1000" encoding="UTF-8" conversionPattern="%D{%y-%m-%d %H:%M:%S.%q} %p %T %l - %m %n"/>
|
||||
<subConfigure level="error" file="signal_srv_error.log" maxFileSize="10485760" maxBackupIndex="10" createDirs="true" appender="RollingFileAppender" async="true" queueSize="1000" encoding="UTF-8" conversionPattern="%D{%y-%m-%d %H:%M:%S.%q} %p %T %l - %m %n"/>
|
||||
</process>
|
||||
</log4cplus>
|
||||
|
||||
19
product/common/sysconfig/signal_srv.xml
Normal file
19
product/common/sysconfig/signal_srv.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<!-- echo 85 > /sys/class/gpio/export -->
|
||||
<!-- echo out > /sys/class/gpio/gpio85/direction -->
|
||||
<!--
|
||||
<alarm_signal>
|
||||
<alm_io file="/sys/class/gpio/gpio85/value" desc="告警io"/>
|
||||
<alm_act value="0" desc="存在告警的值"/>
|
||||
<alm_clr value="1" desc="告警消失的值"/>
|
||||
</alarm_signal>
|
||||
-->
|
||||
|
||||
<proc_check_signal>
|
||||
<proc_check name="fes" domain_id="1" app_id="1" />
|
||||
<alm_io file="/sys/class/gpio/gpio85/value"/>
|
||||
<alm_act value="0" />
|
||||
<alm_clr value="1" />
|
||||
</proc_check_signal>
|
||||
</root>
|
||||
@ -24,7 +24,8 @@ SUBDIRS += \
|
||||
his_amend \
|
||||
wave_record_server \
|
||||
sysparams_server \
|
||||
strategy_server
|
||||
strategy_server \
|
||||
signal_srv
|
||||
|
||||
idong_task_link.depends = idong_srv_api
|
||||
linkage_server.depends = linkage_server_api trigger_api
|
||||
|
||||
280
product/src/application/signal_srv/SignalSrvApp.cpp
Normal file
280
product/src/application/signal_srv/SignalSrvApp.cpp
Normal file
@ -0,0 +1,280 @@
|
||||
#include "SignalSrvApp.h"
|
||||
#include "pub_logger_api/logger.h"
|
||||
#include "pub_utility_api/SingleProcInstance.h"
|
||||
#include "net_msg_bus_api/MsgBusApi.h"
|
||||
#include "SignalSrvCommon.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace iot_public;
|
||||
using namespace iot_sys;
|
||||
using namespace iot_service;
|
||||
using namespace iot_net;
|
||||
|
||||
#define OPT_DESC_APP "app"
|
||||
#define OPT_DESC_HELP "help"
|
||||
|
||||
|
||||
iot_service::SignalSrvApp::SignalSrvApp()
|
||||
:m_ptrSysInfo(NULL),
|
||||
m_ptrProcMng(NULL),
|
||||
m_ptrRedundancyMng(NULL),
|
||||
m_ptrSignalSrvMng(NULL)
|
||||
{
|
||||
}
|
||||
iot_service::SignalSrvApp::~SignalSrvApp()
|
||||
{
|
||||
SignalSrvApp::stop();
|
||||
}
|
||||
|
||||
|
||||
bool iot_service::SignalSrvApp::start(int argc, char *argv[], int &/*nStatus*/)
|
||||
{
|
||||
//1.解析启动参数
|
||||
if(!parseCmdLine(argc, argv))
|
||||
{
|
||||
cerr<<"解析启动参数失败" <<endl;
|
||||
return false;
|
||||
}
|
||||
//2.注册日志
|
||||
if(!initLog())
|
||||
{
|
||||
cerr<<"初始化日志失败"<<endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
//3.避免进程重复启动
|
||||
if(isAlreadyRunning())
|
||||
{
|
||||
LOGERROR("进程已存在,不允许再次启动");
|
||||
return false;
|
||||
}
|
||||
//4.获取系统信息 m_stRunAppInfo
|
||||
if(!getSystemInfo())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//5.向注册进程管理
|
||||
if(!registToProcMng())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//6.创建冗余管理
|
||||
m_ptrRedundancyMng =getRedundantMngInstance(m_stRunAppInfo.nDomainId,m_stRunAppInfo.nAppId,m_stRunAppInfo.strLocalNodeName);
|
||||
if(m_ptrRedundancyMng ==NULL)
|
||||
{
|
||||
LOGERROR("创建冗余管理失败");
|
||||
return false;
|
||||
}
|
||||
//7.初始化业务资源
|
||||
if(!initialize())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//8.设置冗余通知回调
|
||||
if(iotSuccess !=m_ptrRedundancyMng->setCallback(m_ptrSignalSrvMng))
|
||||
{
|
||||
LOGERROR("设置冗余回调接口失败");
|
||||
return false;
|
||||
}
|
||||
//9.更新当前进程冗余状态
|
||||
if(iotSuccess !=m_ptrProcMng->updateProcessInfo(true,false,false))
|
||||
{
|
||||
LOGERROR("更新本进程的进程信息失败");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool iot_service::SignalSrvApp::stop()
|
||||
{
|
||||
//9.更新当前进程冗余状态
|
||||
if(m_ptrProcMng !=NULL)
|
||||
{
|
||||
m_ptrProcMng->updateProcessInfo(false,false,false);
|
||||
}
|
||||
//8.取消冗余通知回调
|
||||
if(m_ptrRedundancyMng !=NULL)
|
||||
{
|
||||
m_ptrRedundancyMng->unsetCallback();
|
||||
}
|
||||
//7.回收业务资源
|
||||
clean();
|
||||
//6.销毁冗余管理
|
||||
m_ptrRedundancyMng.reset();
|
||||
//5.销毁进程管理
|
||||
if(m_ptrProcMng !=NULL)
|
||||
{
|
||||
m_ptrProcMng->unsetCallback();
|
||||
m_ptrProcMng.reset();
|
||||
}
|
||||
//2.销毁日志系统
|
||||
StopLogSystem();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
int iot_service::SignalSrvApp::toQuit()
|
||||
{
|
||||
if(m_ptrProcMng != NULL)
|
||||
{
|
||||
m_ptrProcMng->unsetCallback();
|
||||
}
|
||||
shutdown();
|
||||
return iotSuccess;
|
||||
}
|
||||
|
||||
bool iot_service::SignalSrvApp::parseCmdLine(int argc, char *argv[])
|
||||
{
|
||||
//拼接启动参数,用于向进程管理注册
|
||||
for(int i=1;i<argc;++i)
|
||||
{
|
||||
if(i!=1)
|
||||
{
|
||||
m_strStartArgs +=" ";
|
||||
}
|
||||
m_strStartArgs += argv[i];
|
||||
}
|
||||
|
||||
namespace opt = boost::program_options;
|
||||
opt::options_description desc("usage");
|
||||
opt::variables_map vm;
|
||||
try
|
||||
{
|
||||
desc.add_options()
|
||||
(OPT_DESC_APP",a", opt::value<std::string>()->required(),"app label")
|
||||
(OPT_DESC_HELP",h", "\tusage");
|
||||
opt::store(opt::parse_command_line(argc, argv, desc), vm);
|
||||
opt::notify(vm);
|
||||
//输入的是help,则程序仅显示用法
|
||||
if(vm.count(OPT_DESC_HELP))
|
||||
{
|
||||
showHelp(desc);
|
||||
return false;
|
||||
}
|
||||
//输入错误,则显示用法
|
||||
if(vm.count(OPT_DESC_APP)== 0)
|
||||
{
|
||||
showHelp(desc);
|
||||
return false;
|
||||
}
|
||||
//获取应用名
|
||||
if(vm.count(OPT_DESC_APP))
|
||||
{
|
||||
m_strAppName=vm[OPT_DESC_APP].as<string>();
|
||||
}
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
{
|
||||
std::cerr<<ex.what()<<std::endl;
|
||||
showHelp(desc);
|
||||
return false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cerr<<"未知错误"<<std::endl;
|
||||
showHelp(desc);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void iot_service::SignalSrvApp::showHelp(const boost::program_options::options_description &objDesc)
|
||||
{
|
||||
std::cout<<CN_ProcName_SignalSrv<<"[-h] | [-a app]"<<std::endl;
|
||||
std::cout<<objDesc<<std::endl;
|
||||
}
|
||||
|
||||
bool iot_service::SignalSrvApp::isAlreadyRunning()
|
||||
{
|
||||
strUniqueName.clear();
|
||||
strUniqueName = CN_ProcName_SignalSrv;
|
||||
strUniqueName +=m_strStartArgs;
|
||||
return CSingleProcInstance::hasInstanceRunning(strUniqueName);
|
||||
}
|
||||
|
||||
bool iot_service::SignalSrvApp::initLog()
|
||||
{
|
||||
StartLogSystem(m_strAppName.c_str(),CN_ProcName_SignalSrv.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool iot_service::SignalSrvApp::getSystemInfo()
|
||||
{
|
||||
if(!createSysInfoInstance(m_ptrSysInfo))
|
||||
{
|
||||
LOGERROR("创建系统信息访问库失败");
|
||||
return false;
|
||||
}
|
||||
if(iotSuccess != m_ptrSysInfo->getLocalRunAppInfoByName(m_strAppName,m_stRunAppInfo))
|
||||
{
|
||||
LOGERROR("获取系统信息失败");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//向进程管理注册
|
||||
bool iot_service::SignalSrvApp::registToProcMng()
|
||||
{
|
||||
SProcessInfoKey stProcKey;
|
||||
stProcKey.nDomainId = m_stRunAppInfo.nDomainId;
|
||||
stProcKey.nAppId = m_stRunAppInfo.nAppId;
|
||||
stProcKey.strNodeName = m_stRunAppInfo.strLocalNodeName;
|
||||
stProcKey.strProcName = CN_ProcName_SignalSrv;
|
||||
stProcKey.strProcParam = m_strStartArgs;
|
||||
|
||||
m_ptrProcMng =getProcMngInstance(stProcKey);
|
||||
if(m_ptrProcMng == NULL)
|
||||
{
|
||||
LOGERROR("创建进程管理访问库失败");
|
||||
return false;
|
||||
}
|
||||
if(iotSuccess != m_ptrProcMng->setCallback(this))
|
||||
{
|
||||
LOGERROR("向进程管理设置回调函数失败");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool iot_service::SignalSrvApp::initialize()
|
||||
{
|
||||
//初始化消息总线
|
||||
if(!initMsgBus(CN_ProcName_SignalSrv.c_str(),strUniqueName.c_str()))
|
||||
{
|
||||
LOGERROR("初始化消息总线失败");
|
||||
return iotFailed;
|
||||
}
|
||||
//创建信号服务管理类
|
||||
m_ptrSignalSrvMng =boost::make_shared<SignalSrvMng>(m_stRunAppInfo,m_ptrProcMng);
|
||||
if(m_ptrSignalSrvMng ==NULL)
|
||||
{
|
||||
LOGERROR("创建信号服务管理类失败");
|
||||
return false;
|
||||
}
|
||||
if(iotSuccess !=m_ptrSignalSrvMng->initialize())
|
||||
{
|
||||
LOGERROR("初始化信号服务管理类失败");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//清理业务资源
|
||||
bool iot_service::SignalSrvApp::clean()
|
||||
{
|
||||
if(m_ptrSignalSrvMng!=NULL)
|
||||
{
|
||||
m_ptrSignalSrvMng.reset();
|
||||
}
|
||||
//销毁消息总线接口
|
||||
if(!releaseMsgBus())
|
||||
{
|
||||
LOGERROR("销毁消息总线资源失败");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
91
product/src/application/signal_srv/SignalSrvApp.h
Normal file
91
product/src/application/signal_srv/SignalSrvApp.h
Normal file
@ -0,0 +1,91 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
#include "pub_utility_api/BaseService.h"
|
||||
#include "pub_sysinfo_api/SysInfoApi.h"
|
||||
#include "sys_proc_mng_api/ProcMngInterface.h"
|
||||
#include "SignalSrvMng.h"
|
||||
|
||||
|
||||
namespace iot_service {
|
||||
class SignalSrvApp : public iot_public::CBaseService,public iot_sys::CProcessQuitInterface
|
||||
{
|
||||
public:
|
||||
SignalSrvApp();
|
||||
virtual ~SignalSrvApp();
|
||||
/**
|
||||
* @brief start 启动函数,允许子类执行它的启动活动,一般必须继承,并在其中实现自己的应用逻辑
|
||||
* @param argc 传入参数的个数
|
||||
* @param argv 传入的参数
|
||||
* @param nStatus 错误码
|
||||
* @return 启动成功,子类必须返回true,否则返回false
|
||||
*/
|
||||
virtual bool start(int argc, char *argv[], int &nStatus);
|
||||
/**
|
||||
* @brief stop 服务停止清理函数,决定了main()的返回值,缺省返回true,一般需要继承,进行一些必要的资源清理
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
virtual bool stop();
|
||||
/**
|
||||
* @brief toQuit 用来通知进程退出,一般应用继承后调用service::shutdown()
|
||||
* @return
|
||||
*/
|
||||
virtual int toQuit();
|
||||
private:
|
||||
/**
|
||||
* @brief parseCmdLine 解析启动参数
|
||||
* @param argc 参数个数
|
||||
* @param argv 参数列表
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
bool parseCmdLine(int argc, char *argv[]);
|
||||
/**
|
||||
* @brief showHelp 显示帮助信息
|
||||
* @param objDesc 帮助信息描述
|
||||
*/
|
||||
void showHelp(const boost::program_options::options_description &objDesc);
|
||||
/**
|
||||
* @brief isAlreadyRunning 判断同名参数进程是否已经有实例在运行
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
bool isAlreadyRunning();
|
||||
/**
|
||||
* @brief initLog 初始化日志
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
bool initLog();
|
||||
/**
|
||||
* @brief getSystemInf 读取系统配置相关信息
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
bool getSystemInfo();
|
||||
/**
|
||||
* @brief registToProcMng 向进程管理注册
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
bool registToProcMng();
|
||||
/**
|
||||
* @brief initialize 初始化业务资源
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
bool initialize();
|
||||
/**
|
||||
* @brief clean 清理业务资源
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
bool clean();
|
||||
private:
|
||||
std::string strUniqueName; //标识名
|
||||
std::string m_strAppName; //应用名
|
||||
iot_public::SRunAppInfo m_stRunAppInfo; //本应用相关运行参数
|
||||
std::string m_strStartArgs; //保存进程启动参数
|
||||
iot_public::SNodeInfo m_stLocalNodeInfo; //本机节点信息
|
||||
iot_public::CSysInfoInterfacePtr m_ptrSysInfo; //创建系统信息访问智能库指针
|
||||
iot_sys::CProcMngInterfacePtr m_ptrProcMng; //创建进程管理访问智能库指针
|
||||
iot_sys::CRedundantMngInterfacePtr m_ptrRedundancyMng; //冗余管理类
|
||||
SignalSrvMngPtr m_ptrSignalSrvMng; //计算量服务管理类
|
||||
};
|
||||
|
||||
} //namespace iot_service
|
||||
|
||||
7
product/src/application/signal_srv/SignalSrvCommon.h
Normal file
7
product/src/application/signal_srv/SignalSrvCommon.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace iot_service {
|
||||
const std::string CN_ProcName_SignalSrv="signal_srv";//当前进程名
|
||||
const std::string CN_CFG_NAME = "signal_srv.xml";
|
||||
|
||||
}
|
||||
60
product/src/application/signal_srv/SignalSrvMng.cpp
Normal file
60
product/src/application/signal_srv/SignalSrvMng.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
|
||||
|
||||
#include "SignalSrvMng.h"
|
||||
#include "pub_logger_api/logger.h"
|
||||
|
||||
iot_service::SignalSrvMng::SignalSrvMng(const iot_public::SRunAppInfo &stRunAppInfo,
|
||||
const iot_sys::CProcMngInterfacePtr &ptrProcMng)
|
||||
:m_stRunAppInfo(stRunAppInfo),
|
||||
m_ptrProcMng(ptrProcMng),
|
||||
m_ptrSignalSrvThread(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
iot_service::SignalSrvMng::~SignalSrvMng()
|
||||
{
|
||||
if(m_ptrSignalSrvThread != NULL)
|
||||
{
|
||||
m_ptrSignalSrvThread->quit();
|
||||
m_ptrSignalSrvThread.reset();
|
||||
}
|
||||
m_ptrProcMng.reset();
|
||||
}
|
||||
|
||||
//冗余切换
|
||||
int iot_service::SignalSrvMng::redundantSwitch(bool bMaster, bool bSlave)
|
||||
{
|
||||
LOGINFO("接收到冗余切换指令.Master=[%d],Slave=[%d]",bMaster,bSlave);
|
||||
if(bMaster && !bSlave) //为主
|
||||
{
|
||||
m_ptrSignalSrvThread->setMaster();
|
||||
m_ptrSignalSrvThread->resume();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ptrSignalSrvThread->suspend();
|
||||
m_ptrSignalSrvThread->setSlave();
|
||||
}
|
||||
|
||||
m_ptrProcMng->updateProcessInfo(true, bMaster, bSlave);
|
||||
|
||||
return iotSuccess;
|
||||
}
|
||||
|
||||
//初始化
|
||||
int iot_service::SignalSrvMng::initialize()
|
||||
{
|
||||
m_ptrSignalSrvThread =boost::make_shared<SignalSrvThread>(m_stRunAppInfo);
|
||||
if(m_ptrSignalSrvThread == NULL)
|
||||
{
|
||||
LOGERROR("创建signal线程失败");
|
||||
return iotFailed;
|
||||
}
|
||||
if(iotSuccess !=m_ptrSignalSrvThread->initialize())
|
||||
{
|
||||
LOGERROR("初始化signal线程失败");
|
||||
return iotFailed;
|
||||
}
|
||||
return iotSuccess;
|
||||
}
|
||||
41
product/src/application/signal_srv/SignalSrvMng.h
Normal file
41
product/src/application/signal_srv/SignalSrvMng.h
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pub_sysinfo_api/SysInfoApi.h"
|
||||
#include "sys_node_mng_api/NodeMngInterface.h"
|
||||
#include "sys_proc_mng_api/ProcMngInterface.h"
|
||||
#include "SignalSrvThread.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace iot_service {
|
||||
class SignalSrvMng : public iot_sys::CRedundantSwitchInterface
|
||||
{
|
||||
public:
|
||||
SignalSrvMng(const iot_public::SRunAppInfo &stRunAppInfo,
|
||||
const iot_sys::CProcMngInterfacePtr &ptrProcMng);
|
||||
virtual ~SignalSrvMng();
|
||||
/**
|
||||
* @brief redundantSwitch 冗余切换,应用需要继承并重写,实现自身的冗余切换逻辑
|
||||
* 在进程切换过程中,可能会被调用多次切换,业务进程需要保证幂等,无副作用
|
||||
* @param bMaster 是否为主
|
||||
* @param bSlave 是否为备
|
||||
* @return 成功返回iotSuccess,失败返回错误码
|
||||
*/
|
||||
virtual int redundantSwitch(bool bMaster, bool bSlave);
|
||||
/**
|
||||
* @brief initialize 初始化
|
||||
* @return 成功返回iotSuccess,失败返回错误码
|
||||
*/
|
||||
int initialize();
|
||||
private:
|
||||
iot_public::SRunAppInfo m_stRunAppInfo; //本应用相关运行参数
|
||||
iot_sys::CProcMngInterfacePtr m_ptrProcMng; //进程管理访问库智能指针
|
||||
SignalSrvThreadPtr m_ptrSignalSrvThread; //计算量主线程
|
||||
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<SignalSrvMng> SignalSrvMngPtr;
|
||||
} //namespace iot_service
|
||||
85
product/src/application/signal_srv/SignalSrvThread.cpp
Normal file
85
product/src/application/signal_srv/SignalSrvThread.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include "SignalSrvThread.h"
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <algorithm>
|
||||
#include "net_msg_bus_api/CMbCommunicator.h"
|
||||
#include "SignalSrvCommon.h"
|
||||
#include "common/MessageChannel.h"
|
||||
#include "alarm/CAlarmSignalManage.h"
|
||||
#include "alarm/CAlarmDataCollect.h"
|
||||
#include "processCheck/CProcessCheckSignalManage.h"
|
||||
#include "processCheck/CProcessQueryThread.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace iot_public;
|
||||
using namespace iot_service;
|
||||
using namespace iot_dbms;
|
||||
using namespace iot_service;
|
||||
using namespace iot_idl;
|
||||
|
||||
|
||||
const int CN_Scan_Period = 500; //扫描周期,单位ms
|
||||
|
||||
iot_service::SignalSrvThread::SignalSrvThread(const iot_public::SRunAppInfo &stRunAppInfo)
|
||||
:iot_public::CTimerThreadBase("SignalSrvThread",CN_Scan_Period),
|
||||
m_stRunAppInfo(stRunAppInfo),
|
||||
m_bMaster(false)
|
||||
{
|
||||
|
||||
}
|
||||
iot_service::SignalSrvThread::~SignalSrvThread()
|
||||
{
|
||||
|
||||
//CAlarmDataCollect::instance()->release();
|
||||
//CAlarmSignalManage::instance()->release();
|
||||
}
|
||||
|
||||
|
||||
int iot_service::SignalSrvThread::initialize()
|
||||
{
|
||||
|
||||
return iotSuccess;
|
||||
}
|
||||
|
||||
int iot_service::SignalSrvThread::setMaster()
|
||||
{
|
||||
m_bMaster=true;
|
||||
//CAlarmSignalManage::instance()->initialize();
|
||||
|
||||
//CAlarmDataCollect::instance()->initialize();
|
||||
|
||||
CProcessCheckSignalManage::instance()->initialize();
|
||||
CProcessQueryThread::instance()->initialize();
|
||||
|
||||
return iotSuccess;
|
||||
}
|
||||
|
||||
|
||||
int iot_service::SignalSrvThread::setSlave()
|
||||
{
|
||||
|
||||
m_bMaster=false;
|
||||
//CAlarmDataCollect::instance()->release();
|
||||
//CAlarmSignalManage::instance()->release();
|
||||
|
||||
CProcessQueryThread::instance()->release();
|
||||
return iotSuccess;
|
||||
|
||||
}
|
||||
|
||||
void iot_service::SignalSrvThread::execute()
|
||||
{
|
||||
|
||||
if(!m_bMaster)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CProcessCheckSignalManage::instance()->handleSignal();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
59
product/src/application/signal_srv/SignalSrvThread.h
Normal file
59
product/src/application/signal_srv/SignalSrvThread.h
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include "pub_utility_api/TimerThreadBase.h"
|
||||
#include "pub_sysinfo_api/SysInfoApi.h"
|
||||
#include "rdb_api/CRdbAccessEx.h"
|
||||
#include "../../include/service/dp_chg_data_api/CDpcdaForApp.h"
|
||||
#include "DataProcMessage.pb.h"
|
||||
#include "OptDataMessage.pb.h"
|
||||
#include "data_process_api/DataProcessApi.h"
|
||||
#include "rdb_api/RdbTableMng.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace iot_service {
|
||||
class SignalSrvThread : public iot_public::CTimerThreadBase
|
||||
{
|
||||
public:
|
||||
SignalSrvThread(const iot_public::SRunAppInfo &stRunAppInfo);
|
||||
virtual ~SignalSrvThread();
|
||||
/**
|
||||
* @brief execute 业务处理函数,必须继承实现自己的业务逻辑
|
||||
*/
|
||||
virtual void execute();
|
||||
/**
|
||||
* @brief initialize 初始化
|
||||
* @return 成功返回iotSuccess,失败返回失败码
|
||||
*/
|
||||
int initialize();
|
||||
/**
|
||||
* @brief setMaster 设置为主
|
||||
* @return 成功返回iotSuccess,失败返回失败码
|
||||
*/
|
||||
int setMaster();
|
||||
/**
|
||||
* @brief setSlave 设置为备
|
||||
* @return 成功返回iotSuccess,失败返回失败码
|
||||
*/
|
||||
int setSlave();
|
||||
|
||||
|
||||
private:
|
||||
iot_public::SRunAppInfo m_stRunAppInfo; //本应用运行参数
|
||||
bool m_bMaster;
|
||||
|
||||
};
|
||||
typedef boost::shared_ptr<SignalSrvThread> SignalSrvThreadPtr;
|
||||
}
|
||||
|
||||
|
||||
186
product/src/application/signal_srv/alarm/CAlarmDataCollect.cpp
Normal file
186
product/src/application/signal_srv/alarm/CAlarmDataCollect.cpp
Normal file
@ -0,0 +1,186 @@
|
||||
|
||||
#include "CAlarmDataCollect.h"
|
||||
#include "pub_logger_api/logger.h"
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include "CAlarmSignalManage.h"
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include "alarm_server_api/AlarmCommonDef.h"
|
||||
using namespace iot_service;
|
||||
|
||||
CAlarmDataCollect * CAlarmDataCollect::m_pInstance = NULL;
|
||||
|
||||
|
||||
CAlarmDataCollect::CAlarmDataCollect()
|
||||
: CAlmApiForAlmClt()
|
||||
{
|
||||
|
||||
}
|
||||
CAlarmDataCollect::~CAlarmDataCollect()
|
||||
{
|
||||
LOGINFO("CAlarmDataCollect::~CAlarmDataCollect()");
|
||||
|
||||
}
|
||||
|
||||
CAlarmDataCollect *CAlarmDataCollect::instance()
|
||||
{
|
||||
if(NULL == m_pInstance)
|
||||
{
|
||||
m_pInstance = new CAlarmDataCollect();
|
||||
}
|
||||
return m_pInstance;
|
||||
}
|
||||
|
||||
|
||||
void CAlarmDataCollect::initialize()
|
||||
{
|
||||
resumeThread();
|
||||
LOGINFO("CAlarmDataCollect::initialize()");
|
||||
}
|
||||
|
||||
|
||||
void CAlarmDataCollect::release()
|
||||
{
|
||||
suspendThread(true);
|
||||
LOGINFO("CAlarmDataCollect::release()");
|
||||
}
|
||||
|
||||
bool CAlarmDataCollect::needSendAlarmSignal(const iot_idl::SAlmInfoToAlmClt &msg)
|
||||
{
|
||||
if(msg.alm_type()==enAlarmType::ALM_TYPE_SOE)
|
||||
{
|
||||
return false;
|
||||
}else if(msg.region_id()==-1)
|
||||
{
|
||||
return false;
|
||||
}else if(msg.priority()==0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAlarmDataCollect::requestCfmAlm(iot_idl::SAlmCltCfmAlm &objCfmAlm)
|
||||
{
|
||||
Q_UNUSED(objCfmAlm)
|
||||
LOGERROR("signal srv do nothing for requestCfmAlm");
|
||||
return true;
|
||||
}
|
||||
bool CAlarmDataCollect::requestDelAlm(iot_idl::SAlmCltDelAlm &objDelAlm)
|
||||
{
|
||||
Q_UNUSED(objDelAlm)
|
||||
LOGERROR("signal srv do nothing for requestDelAlm");
|
||||
return true;
|
||||
}
|
||||
|
||||
void CAlarmDataCollect::handleAllAlmMsg(int domainId, iot_idl::SAlmCltAddAlm &objAllAlm)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
LOGDEBUG("========== AlarmDataCollect handleAllAlmMsg ==========");
|
||||
CAlarmSignalManage::instance()->removeAlarmMsgByDomainID(domainId);
|
||||
int nAlarmCount = objAllAlm.alm_info_size();
|
||||
|
||||
QMap<int,QSet<QString>> mapDomainUuid;
|
||||
for(int nAddMsgIndex(0); nAddMsgIndex < nAlarmCount; nAddMsgIndex++)
|
||||
{
|
||||
iot_idl::SAlmInfoToAlmClt msg = objAllAlm.alm_info(nAddMsgIndex);
|
||||
if(needSendAlarmSignal(msg))
|
||||
{
|
||||
QString uuid = QString::fromStdString(msg.uuid_base64());
|
||||
if(mapDomainUuid.contains(msg.domain_id()))
|
||||
{
|
||||
mapDomainUuid[msg.domain_id()].insert(uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSet<QString> uuidList;
|
||||
uuidList.insert(uuid);
|
||||
mapDomainUuid[msg.domain_id()]=uuidList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
CAlarmSignalManage::instance()->addAlarmMsg(mapDomainUuid);
|
||||
LOGDEBUG("handleAllAlmMsg END[%d] ",nAlarmCount);
|
||||
return;
|
||||
}
|
||||
void CAlarmDataCollect::handleAddAlmMsg(iot_idl::SAlmCltAddAlm &objAddAlm)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
LOGDEBUG("========== AlarmDataCollect handleAddAlmMsg ==========");
|
||||
int nAlarmCount = objAddAlm.alm_info_size();
|
||||
QMap<int,QSet<QString>> mapDomainUuid;
|
||||
for(int nAddMsgIndex(0); nAddMsgIndex < nAlarmCount; nAddMsgIndex++)
|
||||
{
|
||||
iot_idl::SAlmInfoToAlmClt msg = objAddAlm.alm_info(nAddMsgIndex);
|
||||
if(needSendAlarmSignal(msg))
|
||||
{
|
||||
QString uuid = QString::fromStdString(msg.uuid_base64());
|
||||
if(mapDomainUuid.contains(msg.domain_id()))
|
||||
{
|
||||
mapDomainUuid[msg.domain_id()].insert(uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSet<QString> uuidList;
|
||||
uuidList.insert(uuid);
|
||||
mapDomainUuid[msg.domain_id()]=uuidList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CAlarmSignalManage::instance()->addAlarmMsg(mapDomainUuid);
|
||||
LOGDEBUG("handleAddAlmMsg END[%d] ",nAlarmCount);
|
||||
return;
|
||||
}
|
||||
|
||||
void CAlarmDataCollect::handleCfmAlmMsg(iot_idl::SAlmCltCfmAlm &objCfmAlm)
|
||||
{
|
||||
Q_UNUSED(objCfmAlm)
|
||||
LOGDEBUG("signal srv do nothing for handleCfmAlmMsg");
|
||||
return ;
|
||||
}
|
||||
|
||||
void CAlarmDataCollect::handleDelAlmMsg(iot_idl::SAlmCltDelAlm &objDelAlm)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
LOGDEBUG("========== AlarmDataCollect handleDelAlmMsg ==========");
|
||||
QMap<int,QSet<QString>> mapDomainUuid;
|
||||
int nAlarmCount = objDelAlm.uuid_base64_size();
|
||||
for(int nDelMsgIndex(0); nDelMsgIndex < nAlarmCount; nDelMsgIndex++)
|
||||
{
|
||||
QString uuid = QString::fromStdString(objDelAlm.uuid_base64(nDelMsgIndex));
|
||||
if(mapDomainUuid.contains(objDelAlm.domain_id()))
|
||||
{
|
||||
mapDomainUuid[objDelAlm.domain_id()].insert(uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSet<QString> uuidList;
|
||||
uuidList.insert(uuid);
|
||||
mapDomainUuid[objDelAlm.domain_id()]=uuidList;
|
||||
}
|
||||
}
|
||||
CAlarmSignalManage::instance()->removeAlarmMsg(mapDomainUuid);
|
||||
LOGDEBUG("handleDelAlmMsg END[%d] ",nAlarmCount);
|
||||
return ;
|
||||
}
|
||||
|
||||
void CAlarmDataCollect::handleReleaseAlmMsg(iot_idl::SAlmCltReleaseAlm &objRelAlm)
|
||||
{
|
||||
Q_UNUSED(objRelAlm)
|
||||
LOGDEBUG("signal srv do nothing for handleReleaseAlmMsg");
|
||||
return ;
|
||||
}
|
||||
|
||||
void CAlarmDataCollect::handleLinkWave2AlmMsg(iot_idl::SAlmCltLinkWave2Alm &objWave2Alm)
|
||||
{
|
||||
Q_UNUSED(objWave2Alm)
|
||||
LOGDEBUG("signal srv do nothing for handleLinkWave2AlmMsg");
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
44
product/src/application/signal_srv/alarm/CAlarmDataCollect.h
Normal file
44
product/src/application/signal_srv/alarm/CAlarmDataCollect.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "AlarmMessage.pb.h"
|
||||
#include "alarm_server_api/CAlmApiForAlmClt.h"
|
||||
#include <QMutex>
|
||||
|
||||
class CAlarmDataCollect : public iot_service::CAlmApiForAlmClt
|
||||
{
|
||||
|
||||
public:
|
||||
static CAlarmDataCollect *instance();
|
||||
|
||||
virtual ~CAlarmDataCollect();
|
||||
|
||||
virtual bool requestCfmAlm(iot_idl::SAlmCltCfmAlm &objCfmAlm);
|
||||
|
||||
virtual bool requestDelAlm(iot_idl::SAlmCltDelAlm &objDelAlm);
|
||||
|
||||
virtual void handleAllAlmMsg(int domainId, iot_idl::SAlmCltAddAlm &objAllAlm);
|
||||
|
||||
virtual void handleAddAlmMsg(iot_idl::SAlmCltAddAlm &objAddAlm);
|
||||
|
||||
virtual void handleCfmAlmMsg(iot_idl::SAlmCltCfmAlm &objCfmAlm);
|
||||
|
||||
virtual void handleDelAlmMsg(iot_idl::SAlmCltDelAlm &objDelAlm);
|
||||
|
||||
virtual void handleReleaseAlmMsg(iot_idl::SAlmCltReleaseAlm &objDelAlm);
|
||||
|
||||
virtual void handleLinkWave2AlmMsg(iot_idl::SAlmCltLinkWave2Alm &objWave2Alm);
|
||||
|
||||
public:
|
||||
void initialize();
|
||||
|
||||
void release();
|
||||
|
||||
bool needSendAlarmSignal(const iot_idl::SAlmInfoToAlmClt& msg);
|
||||
|
||||
private:
|
||||
CAlarmDataCollect();
|
||||
|
||||
private:
|
||||
static CAlarmDataCollect * m_pInstance;
|
||||
QMutex m_mutex;
|
||||
};
|
||||
206
product/src/application/signal_srv/alarm/CAlarmSignalManage.cpp
Normal file
206
product/src/application/signal_srv/alarm/CAlarmSignalManage.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
#include "pub_logger_api/logger.h"
|
||||
#include "CAlarmSignalManage.h"
|
||||
#include "QSet"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/error/en.h"
|
||||
#include <QDomComment>
|
||||
#include <QFile>
|
||||
#include "pub_utility_api/FileUtil.h"
|
||||
#include <QProcess>
|
||||
#include "SignalSrvCommon.h"
|
||||
|
||||
static QMutex g_mutex;
|
||||
CAlarmSignalManage *CAlarmSignalManage::pInstance = NULL;
|
||||
CAlarmSignalManage *CAlarmSignalManage::instance()
|
||||
{
|
||||
QMutexLocker locker(&g_mutex);
|
||||
if(pInstance == NULL)
|
||||
{
|
||||
pInstance = new CAlarmSignalManage();
|
||||
}
|
||||
return pInstance;
|
||||
}
|
||||
CAlarmSignalManage::CAlarmSignalManage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CAlarmSignalManage::initialize()
|
||||
{
|
||||
release();
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
void CAlarmSignalManage::release()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
m_mapDomainUuid.clear();
|
||||
}
|
||||
|
||||
void CAlarmSignalManage::addAlarmMsg(const QMap<int,QSet<QString>> & mapDomainUuid)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
for (auto it = mapDomainUuid.cbegin(); it != mapDomainUuid.cend(); ++it) {
|
||||
if (m_mapDomainUuid.contains(it.key()))
|
||||
{
|
||||
m_mapDomainUuid[it.key()].unite(it.value());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mapDomainUuid.insert(it.key(), it.value());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CAlarmSignalManage::removeAlarmMsg(const QMap<int,QSet<QString>> & mapDomainUuid)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
for (auto it = mapDomainUuid.cbegin(); it != mapDomainUuid.cend(); ++it)
|
||||
{
|
||||
if (m_mapDomainUuid.contains(it.key())) {
|
||||
m_mapDomainUuid[it.key()].subtract(it.value());
|
||||
if (m_mapDomainUuid[it.key()].isEmpty()) {
|
||||
m_mapDomainUuid.remove(it.key());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CAlarmSignalManage::removeAlarmMsgByDomainID(const int &domainId)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if(domainId==-1)
|
||||
{
|
||||
m_mapDomainUuid.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mapDomainUuid.remove(domainId);
|
||||
}
|
||||
}
|
||||
|
||||
void CAlarmSignalManage::handleSignal()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if(!m_bActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(hasAlarm())
|
||||
{
|
||||
setGpio(m_strAlmActValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
setGpio(m_strAlmClrValue);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CAlarmSignalManage::loadConfig()
|
||||
{
|
||||
QDomDocument doc;
|
||||
QString strCfg = iot_public::CFileUtil::getPathOfCfgFile(iot_service::CN_CFG_NAME,CN_DIR_PRODUCT).c_str();
|
||||
|
||||
QFile file(strCfg);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
LOGERROR("signal_srv can not found file(%s)",strCfg.toStdString().c_str());
|
||||
return;
|
||||
}
|
||||
if (!doc.setContent(&file)){
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
file.close();
|
||||
QDomElement root = doc.documentElement();
|
||||
QDomElement alarmSignalNode= root.firstChildElement("alarm_signal");
|
||||
|
||||
if (alarmSignalNode.isNull()) {
|
||||
LOGINFO("signal_srv can not found alarm_signal node,and not outputsignal");
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
QDomElement almIoElem = alarmSignalNode.firstChildElement("alm_io");
|
||||
if (!almIoElem.isNull())
|
||||
{
|
||||
m_strAlmIO=almIoElem.attribute("file");
|
||||
LOGINFO("alm_io file: %s",almIoElem.attribute("file").toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("alm_io can not find!");
|
||||
return ;
|
||||
}
|
||||
|
||||
QDomElement almActElem = alarmSignalNode.firstChildElement("alm_act");
|
||||
QDomElement almClrElem = alarmSignalNode.firstChildElement("alm_clr");
|
||||
|
||||
if (!almActElem.isNull())
|
||||
{
|
||||
m_strAlmActValue=almActElem.attribute("value");
|
||||
LOGINFO("alm_act value: %s",almActElem.attribute("value").toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("alm_act value can not find!");
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
if (!almClrElem.isNull())
|
||||
{
|
||||
m_strAlmClrValue=almClrElem.attribute("value");
|
||||
LOGINFO("alm_clr value: %s",almClrElem.attribute("value").toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("alm_clr value can not find!");
|
||||
return ;
|
||||
}
|
||||
|
||||
m_bActive=true;
|
||||
LOGINFO("alarm_signal load config ok and will use");
|
||||
}
|
||||
|
||||
bool CAlarmSignalManage::hasAlarm()
|
||||
{
|
||||
for (auto it = m_mapDomainUuid.cbegin(); it != m_mapDomainUuid.cend(); ++it)
|
||||
{
|
||||
const QSet<QString> &set = it.value();
|
||||
|
||||
if (!set.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CAlarmSignalManage::setGpio(QString value)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
#else
|
||||
QFile file(m_strAlmIO);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
LOGERROR("open %s faild %s when want to write %s",m_strAlmIO.toStdString().c_str(),file.errorString().toStdString().c_str(),value.toStdString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
file.write(value.toUtf8());
|
||||
file.close();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QString>
|
||||
|
||||
class CAlarmSignalManage
|
||||
{
|
||||
public:
|
||||
static CAlarmSignalManage * instance();
|
||||
|
||||
~CAlarmSignalManage();
|
||||
|
||||
|
||||
void initialize();
|
||||
|
||||
void release();
|
||||
|
||||
void addAlarmMsg(const QMap<int,QSet<QString>> &mapDomainUuid);
|
||||
|
||||
void removeAlarmMsg(const QMap<int,QSet<QString>> &mapDomainUuid);
|
||||
|
||||
void removeAlarmMsgByDomainID(const int &domainId);
|
||||
|
||||
void handleSignal();
|
||||
|
||||
void loadConfig();
|
||||
|
||||
bool hasAlarm();
|
||||
|
||||
bool setGpio(QString value);
|
||||
|
||||
private:
|
||||
CAlarmSignalManage();
|
||||
|
||||
private:
|
||||
static CAlarmSignalManage * pInstance;
|
||||
|
||||
QMap<int,QSet<QString>> m_mapDomainUuid;
|
||||
QMutex m_mutex;
|
||||
|
||||
|
||||
QString m_strAlmIO;
|
||||
QString m_strAlmActValue;
|
||||
QString m_strAlmClrValue;
|
||||
|
||||
bool m_bActive=false;
|
||||
|
||||
};
|
||||
11
product/src/application/signal_srv/main.cpp
Normal file
11
product/src/application/signal_srv/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "SignalSrvApp.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
iot_service::SignalSrvApp objApp;
|
||||
return objApp.main(argc,argv);
|
||||
}
|
||||
@ -0,0 +1,171 @@
|
||||
#include "CProcessCheckSignalManage.h"
|
||||
#include "SignalSrvCommon.h"
|
||||
#include "QSet"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/error/en.h"
|
||||
#include <QDomComment>
|
||||
#include <QFile>
|
||||
#include "pub_utility_api/FileUtil.h"
|
||||
#include <QProcess>
|
||||
#include "pub_logger_api/logger.h"
|
||||
#include "CProcessQueryCommon.h"
|
||||
|
||||
|
||||
|
||||
static QMutex g_mutex;
|
||||
CProcessCheckSignalManage *CProcessCheckSignalManage::pInstance = NULL;
|
||||
|
||||
CProcessCheckSignalManage *CProcessCheckSignalManage::instance()
|
||||
{
|
||||
QMutexLocker locker(&g_mutex);
|
||||
if(pInstance == NULL)
|
||||
{
|
||||
pInstance = new CProcessCheckSignalManage();
|
||||
}
|
||||
return pInstance;
|
||||
}
|
||||
|
||||
void CProcessCheckSignalManage::initialize()
|
||||
{
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
bool CProcessCheckSignalManage::setGpio(QString value)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
#else
|
||||
QFile file(m_strAlmIO);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
LOGERROR("open %s faild %s when want to write %s",m_strAlmIO.toStdString().c_str(),file.errorString().toStdString().c_str(),value.toStdString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
file.write(value.toUtf8());
|
||||
file.close();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CProcessCheckSignalManage::updateProSatus(QString processName, int proStatus)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if(processName==m_sSprocess.m_procName)
|
||||
{
|
||||
m_mapProcessStatus[processName]=proStatus;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CProcessCheckSignalManage::handleSignal()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if(!m_bActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_mapProcessStatus.contains(m_sSprocess.m_procName)&&m_mapProcessStatus[m_sSprocess.m_procName]==EN_PROC_STATUS::EN_PROC_RUNNING)
|
||||
{
|
||||
setGpio(m_strAlmClrValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
setGpio(m_strAlmActValue);
|
||||
}
|
||||
}
|
||||
|
||||
void CProcessCheckSignalManage::loadConfig()
|
||||
{
|
||||
QDomDocument doc;
|
||||
QString strCfg = iot_public::CFileUtil::getPathOfCfgFile(iot_service::CN_CFG_NAME,CN_DIR_PRODUCT).c_str();
|
||||
|
||||
QFile file(strCfg);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
LOGERROR("signal_srv can not found file(%s)",strCfg.toStdString().c_str());
|
||||
return;
|
||||
}
|
||||
if (!doc.setContent(&file)){
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
file.close();
|
||||
QDomElement root = doc.documentElement();
|
||||
QDomElement alarmSignalNode= root.firstChildElement("proc_check_signal");
|
||||
|
||||
if (alarmSignalNode.isNull()) {
|
||||
LOGINFO("signal_srv can not found proc_check_signal node,and not outputsignal");
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
QDomElement almIoElem = alarmSignalNode.firstChildElement("alm_io");
|
||||
if (!almIoElem.isNull())
|
||||
{
|
||||
m_strAlmIO=almIoElem.attribute("file");
|
||||
LOGINFO("alm_io file: %s",almIoElem.attribute("file").toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("alm_io can not find!");
|
||||
return ;
|
||||
}
|
||||
|
||||
QDomElement proCheckElem = alarmSignalNode.firstChildElement("proc_check");
|
||||
QDomElement almActElem = alarmSignalNode.firstChildElement("alm_act");
|
||||
QDomElement almClrElem = alarmSignalNode.firstChildElement("alm_clr");
|
||||
|
||||
if(!proCheckElem.isNull())
|
||||
{
|
||||
m_sSprocess.m_procName=proCheckElem.attribute("name");
|
||||
m_sSprocess.m_domainId=proCheckElem.attribute("domain_id").toInt();
|
||||
m_sSprocess.m_appId=proCheckElem.attribute("app_id").toInt();
|
||||
LOGINFO("proc_check name: %s domain_id %s app_id %s",proCheckElem.attribute("name").toStdString().c_str(),
|
||||
proCheckElem.attribute("domain_id").toStdString().c_str(),proCheckElem.attribute("domain_id").toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("proc_check name can not find!");
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
if (!almActElem.isNull())
|
||||
{
|
||||
m_strAlmActValue=almActElem.attribute("value");
|
||||
LOGINFO("alm_act value: %s",almActElem.attribute("value").toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("alm_act value can not find!");
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
if (!almClrElem.isNull())
|
||||
{
|
||||
m_strAlmClrValue=almClrElem.attribute("value");
|
||||
LOGINFO("alm_clr value: %s",almClrElem.attribute("value").toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGERROR("alm_clr value can not find!");
|
||||
return ;
|
||||
}
|
||||
|
||||
m_bActive=true;
|
||||
LOGINFO("proc_check_signal load config ok and will use");
|
||||
}
|
||||
|
||||
SProcess &CProcessCheckSignalManage::getProcessInfo()
|
||||
{
|
||||
return m_sSprocess;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CProcessCheckSignalManage::CProcessCheckSignalManage()
|
||||
{
|
||||
loadConfig();
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#include <QString>
|
||||
#include <QMutex>
|
||||
#include <QMap>
|
||||
#include "CProcessQueryCommon.h"
|
||||
|
||||
|
||||
class CProcessCheckSignalManage
|
||||
{
|
||||
public:
|
||||
static CProcessCheckSignalManage * instance();
|
||||
|
||||
~CProcessCheckSignalManage();
|
||||
|
||||
|
||||
void initialize();
|
||||
|
||||
bool setGpio(QString value);
|
||||
|
||||
void updateProSatus(QString processName,int proStatus);
|
||||
|
||||
void handleSignal();
|
||||
|
||||
void loadConfig();
|
||||
|
||||
SProcess& getProcessInfo();
|
||||
|
||||
private:
|
||||
CProcessCheckSignalManage();
|
||||
|
||||
private:
|
||||
static CProcessCheckSignalManage * pInstance;
|
||||
bool m_bActive=false;
|
||||
QMutex m_mutex;
|
||||
|
||||
QString m_strAlmIO;
|
||||
QString m_strAlmActValue;
|
||||
QString m_strAlmClrValue;
|
||||
SProcess m_sSprocess;
|
||||
|
||||
QMap<QString,int> m_mapProcessStatus;
|
||||
|
||||
|
||||
};
|
||||
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include <QString>
|
||||
const std::string CN_TN_SysRunProcInfo = "sys_run_proc_info";
|
||||
struct SProcess
|
||||
{
|
||||
std::string m_nodeName;
|
||||
std::string m_procDesc;
|
||||
QString m_procName;
|
||||
std::string m_procParam;
|
||||
long long m_procId;
|
||||
int m_appId;
|
||||
int m_domainId;
|
||||
std::string m_appDesc;
|
||||
int m_isStartUp;
|
||||
int m_toQuit;
|
||||
int m_isQuit;
|
||||
float m_cpu;
|
||||
int m_procNum;
|
||||
float m_disk;
|
||||
int m_isMaster ;
|
||||
int m_isSlave ;
|
||||
|
||||
SProcess()
|
||||
{
|
||||
m_nodeName = "";
|
||||
m_procDesc = "";
|
||||
m_procName = "";
|
||||
m_procId = -1;
|
||||
m_appId = -1;
|
||||
m_appDesc = "";
|
||||
m_isStartUp = 0;
|
||||
m_toQuit = 0;
|
||||
m_isQuit = 0;
|
||||
m_cpu = 0.0;
|
||||
m_procNum = -1;
|
||||
m_disk = 0.0;
|
||||
m_isMaster = 0;
|
||||
m_isSlave = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum EN_PROC_STATUS
|
||||
{
|
||||
EN_PROC_STOP = 0, //<已停止
|
||||
EN_PROC_RUNNING, //<正在运行
|
||||
EN_PROC_UNKNOW //<未知
|
||||
};
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
#include "CProcessQueryThread.h"
|
||||
#include "CProcessQueryCommon.h"
|
||||
#include "CProcessCheckSignalManage.h"
|
||||
#include "rdb_net_api/CRdbNetApi.h"
|
||||
#include "pub_logger_api/logger.h"
|
||||
|
||||
|
||||
static QMutex g_mutex;
|
||||
CProcessQueryThread *CProcessQueryThread::m_pInstance = NULL;
|
||||
|
||||
CProcessQueryThread *CProcessQueryThread::instance()
|
||||
{
|
||||
QMutexLocker locker(&g_mutex);
|
||||
if(m_pInstance == NULL)
|
||||
{
|
||||
m_pInstance = new CProcessQueryThread();
|
||||
}
|
||||
return m_pInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CProcessQueryThread::CProcessQueryThread():CTimerThreadBase("CProcessQueryThread",2000)
|
||||
{
|
||||
initData();
|
||||
}
|
||||
|
||||
|
||||
CProcessQueryThread::~CProcessQueryThread()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CProcessQueryThread::execute()
|
||||
{
|
||||
queryProcRunInfo();
|
||||
}
|
||||
|
||||
void CProcessQueryThread::initialize()
|
||||
{
|
||||
resume();
|
||||
LOGINFO("CProcessQueryThread::initialize()");
|
||||
|
||||
}
|
||||
|
||||
void CProcessQueryThread::release()
|
||||
{
|
||||
suspend();
|
||||
LOGINFO("CProcessQueryThread::release()");
|
||||
}
|
||||
|
||||
bool CProcessQueryThread::queryProcRunInfo()
|
||||
{
|
||||
bool bRet = false;
|
||||
iot_idl::RdbRet objRdbRet;
|
||||
std::vector <std::string> vecColumn = {"app_id","node_name","proc_name","proc_param","proc_id","is_startup","to_quit","is_quit","is_master","is_slave"};
|
||||
|
||||
bRet=m_objRdbNetApi.queryTotal(CN_TN_SysRunProcInfo,vecColumn,objRdbRet,false,false,5);
|
||||
|
||||
if(!bRet ||objRdbRet.msgrecord_size() < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i=0;i<objRdbRet.msgrecord_size();++i)
|
||||
{
|
||||
SProcess proc;
|
||||
// proc.m_appId = objRdbRet.msgrecord(i).msgvaluearray(0).nvalue();
|
||||
// proc.m_nodeName = objRdbRet.msgrecord(i).msgvaluearray(1).strvalue();
|
||||
proc.m_procName=QString::fromStdString(objRdbRet.msgrecord(i).msgvaluearray(2).strvalue());
|
||||
// proc.m_procParam = objRdbRet.msgrecord(i).msgvaluearray(3).strvalue();
|
||||
// proc.m_procId = objRdbRet.msgrecord(i).msgvaluearray(4).lvalue();
|
||||
proc.m_isStartUp = objRdbRet.msgrecord(i).msgvaluearray(5).nvalue();
|
||||
// proc.m_toQuit = objRdbRet.msgrecord(i).msgvaluearray(6).nvalue();
|
||||
// proc.m_isQuit = objRdbRet.msgrecord(i).msgvaluearray(7).nvalue();
|
||||
// proc.m_isMaster = objRdbRet.msgrecord(i).msgvaluearray(8).nvalue();
|
||||
// proc.m_isSlave = objRdbRet.msgrecord(i).msgvaluearray(9).nvalue();
|
||||
|
||||
CProcessCheckSignalManage::instance()->updateProSatus(proc.m_procName, proc.m_isStartUp);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CProcessQueryThread::initData()
|
||||
{
|
||||
SProcess tmp=CProcessCheckSignalManage::instance()->getProcessInfo();
|
||||
m_objRdbNetApi.connect(tmp.m_domainId,tmp.m_appId);
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
#include "CProcessQueryThread.h"
|
||||
#include "pub_utility_api/TimerThreadBase.h"
|
||||
#include "rdb_net_api/CRdbNetApi.h"
|
||||
#include "CProcessQueryCommon.h"
|
||||
|
||||
using namespace iot_dbms;
|
||||
class CProcessQueryThread : public iot_public::CTimerThreadBase
|
||||
{
|
||||
|
||||
public:
|
||||
static CProcessQueryThread *instance();
|
||||
|
||||
virtual ~CProcessQueryThread();
|
||||
|
||||
/**
|
||||
* @brief execute 业务处理函数,必须继承实现自己的业务逻辑
|
||||
*/
|
||||
virtual void execute();
|
||||
|
||||
|
||||
void initialize();
|
||||
|
||||
void release();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief queryProcRunInfo 查询进程信息
|
||||
* @return true-成功 false-失败
|
||||
*/
|
||||
bool queryProcRunInfo();
|
||||
|
||||
void initData();
|
||||
|
||||
CProcessQueryThread();
|
||||
|
||||
|
||||
private:
|
||||
static CProcessQueryThread * m_pInstance;
|
||||
CRdbNetApi m_objRdbNetApi; //< 网络查询对象
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
66
product/src/application/signal_srv/signal_srv.pro
Normal file
66
product/src/application/signal_srv/signal_srv.pro
Normal file
@ -0,0 +1,66 @@
|
||||
QT -= gui
|
||||
QT += xml
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = signal_srv
|
||||
CONFIG += console
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which as been marked deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += main.cpp \
|
||||
SignalSrvApp.cpp \
|
||||
SignalSrvMng.cpp \
|
||||
SignalSrvThread.cpp \
|
||||
alarm/CAlarmDataCollect.cpp \
|
||||
alarm/CAlarmSignalManage.cpp \
|
||||
processCheck/CProcessQueryThread.cpp \
|
||||
processCheck/CProcessCheckSignalManage.cpp
|
||||
|
||||
HEADERS += \
|
||||
SignalSrvApp.h \
|
||||
SignalSrvMng.h \
|
||||
SignalSrvThread.h \
|
||||
alarm/CAlarmDataCollect.h \
|
||||
SignalSrvCommon.h \
|
||||
alarm/CAlarmSignalManage.h \
|
||||
processCheck/CProcessQueryThread.h \
|
||||
processCheck/CProcessCheckSignalManage.h \
|
||||
processCheck/CProcessQueryCommon.h
|
||||
|
||||
|
||||
LIBS +=\
|
||||
-lboost_system \
|
||||
-lprotobuf \
|
||||
-llog4cplus \
|
||||
-lpub_logger_api \
|
||||
-lboost_filesystem \
|
||||
-lpub_sysinfo_api \
|
||||
-lsys_node_mng_api \
|
||||
-lsys_proc_mng_api \
|
||||
-lpub_utility_api \
|
||||
-lboost_program_options \
|
||||
-lpub_sysinfo_api \
|
||||
-lnet_msg_bus_api \
|
||||
-lrdb_api \
|
||||
-lboost_chrono
|
||||
|
||||
|
||||
LIBS += -lalarm_server_api -lrdb_net_api
|
||||
|
||||
include($$PWD/../../idl_files/idl_files.pri)
|
||||
#-------------------------------------------------------------------
|
||||
COMMON_PRI=$$PWD/../../common.pri
|
||||
exists($$COMMON_PRI) {
|
||||
include($$COMMON_PRI)
|
||||
}else {
|
||||
error("FATAL error: can not find common.pri")
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user