#include "CScaOp.h"
#include "CScaOpadd.cpp"
int g_HasDb;
short g_ctx_no;
char g_CtxName[64];
extern CScaCommon *g_ScaComm;
extern long tokenid_tmp;
CScaOpadd scada_opadd;
CScaOp::CScaOp()
{
//CMsgBusFactory *msgBusFactory;
//
//getmsgbusfactory(&msgBusFactory);
//m_ScadaOpBus = msgBusFactory->MsgBusFactory("scada_op", "scada_op");
//msgBusFactory->release();
int ret;
m_vec_key.clear();
m_vec_field.clear();
ret = m_ScadaOpBus.messageInit(g_CtxName,AF_SCADA_NAME,"sca_op");
if (ret <= 0)
{
m_msg_flag = 0;
TRACE("messageInit() error!\n");
}
else
{
m_msg_flag = 1;
TRACE("messageInit() success!\n");
}
m_ScadaTableOp = new CTableOp;
m_PublicTableOp = new CTableOp;
m_ScadaApiOp = new CApiOp(AP_SCADA);
m_SerManage = new CServicesManage;
m_SendMsgBuf = NULL;
m_priv_access = NULL;
m_SendMsgType = 0;
m_YkJudgeShm = NULL;
m_modify_db = 1;
m_pDbInterface = new CDbCommitClient();
//m_pDbInterface->set_try_invoke_times(0);
m_app_id = AP_SCADA;
m_node_id = -1;
m_sec_flag = 0;
static int tmp_int_0 = 0;
static int tmp_int_1 = 1;
static int tmp_int_2 = 20;
static int tmp_int_6 = 15;
static int tmp_int_7 = 240;
static int tmp_int_8 = 300;
static int tmp_int_9 = 0;
is_flag9= &tmp_int_0;;
is_flag10= &tmp_int_0;;
m_YkResult = &tmp_int_1;
m_DwResult = &tmp_int_0;
m_DwDelay = &tmp_int_2;
m_SyncSimOp = &tmp_int_0;
m_DwOpTime = &tmp_int_6;
m_YkOpTime = &tmp_int_6;
m_CStatDelay = &tmp_int_7;
m_ServiceYk = &tmp_int_0; //added by smy for service yk 20111128
m_token_rly = &tmp_int_1;
m_bay_token_rly=&tmp_int_1;
m_max_token_num=&tmp_int_8;
m_fac_yx_dw = &tmp_int_9;
g_ScaComm->IntParaAt("is_token_rly", &m_token_rly);
g_ScaComm->IntParaAt("is_bay_token_rly", &m_bay_token_rly);
g_ScaComm->IntParaAt("sync_sim_op", &m_SyncSimOp);
g_ScaComm->IntParaAt("yk_result",&m_YkResult);
g_ScaComm->IntParaAt("dw_result",&m_DwResult);
g_ScaComm->IntParaAt("dw_delay",&m_DwDelay);
g_ScaComm->IntParaAt("dw_op_time", &m_DwOpTime);
g_ScaComm->IntParaAt("yk_op_time", &m_YkOpTime);
g_ScaComm->IntParaAt("service_yk", &m_ServiceYk); //added by smy for service yk 20111128
g_ScaComm->IntParaAt("cstat_delay", &m_CStatDelay);
g_ScaComm->IntParaAt("max_token_num", &m_max_token_num);
g_ScaComm->IntParaAt("fac_yx_dw", &m_fac_yx_dw);//added by ts for servic fac_yx_dw20190103
if (*m_CStatDelay < 60 || *m_CStatDelay > 3600)
m_CStatDelay = &tmp_int_7;
if (*m_max_token_num < 300 || *m_max_token_num > 600)
m_max_token_num = &tmp_int_8;
//m_PublicTableOp->Open(AP_PUBLIC, SYS_COLUMN_INFO_NO);
m_PublicTableOp->Open(AP_PUBLIC, SYS_PRIV_USER_D_DEF_NO);
m_PublicTableOp->Open(AP_PUBLIC, SYS_PRIV_GRP_DEF_NO);
m_PublicTableOp->Open(AP_PUBLIC, MNG_NODE_INFO_NO);
//added by smy for service yk 20111128
if (*m_ServiceYk == 1)
{
int shm_key;
int shm_id;
int sem_key;
shm_key = CContext::ShiftSemKey(SCA_SERVICE_YK_SHM_KEY);
shm_id = g_ScaComm->init_shm((key_t)shm_key,SCA_SERVICE_YK_SHM_SIZE);
if (shm_id < 0)
{
TRACE("service yk shmget error %x %d\n",shm_key,shm_id);
exit(0);
}
m_SerYkShm = (ServiceYkShm *)shmat(shm_id,0,0);
if ((void *)m_SerYkShm == (void *)(-1))
{
TRACE("service yk shmat error\n");
exit(0);
}
sem_key = CContext::ShiftSemKey(SCA_SERVICE_YK_SEM_KEY);
m_SemId = g_ScaComm->init_sem(sem_key);
if (m_SemId < 0)
{
TRACE("init_sem error %x %d\n",sem_key,m_SemId);
exit(0);
}
init_secmod();//added by smy for secure yk 20120222
}
//end added
char filename[200];
bzero(filename,200);
char* home_path = getenv(HOME_ENV_NAME);
sprintf(filename,"%s/var/log/sca_op.log.ctx%d",home_path,g_ctx_no);
m_fp = fopen(filename, "ab");
if( m_fp == NULL )
{
TRACE("open %s fail!\n", localfile);
}
get_meas_filed_no();
}
CScaOp::~CScaOp()
{
#ifndef _IBM
m_ScadaOpBus.messageExit();
delete m_ScadaTableOp;
delete m_PublicTableOp;
delete m_ScadaApiOp;
delete m_SerManage;
if (m_SendMsgBuf)
delete m_SendMsgBuf;
delete m_pDbInterface;
if (m_priv_access)
delete m_priv_access;
#endif
shmdt((char *)m_YkJudgeShm);
//added by smy for service yk 20111128
if (*m_ServiceYk == 1)
shmdt((char *)m_SerYkShm);
if( m_fp!= NULL )
fclose(m_fp);
//end added
}
/*
int CScaOp::UpdateLockInfo(LockInfoStru lock_info,int update_type)
{
struct lock_info_stru
{
KEY_ID_STRU key_id;
int fac_id;
unsigned char type;
};
int table_no;
int ret_code;
int i,rec_num;
char sql_sentence[300];
string tmp_name;
::CBuffer buf_base;
lock_info_stru *lock_buf;
int write_len;
static int s_info_flag=-1;
if (s_info_flag < 0)
{
int tmp_fno;
ret_code = m_ScadaTableOp->Open(AP_SCADA,LOCK_INFO_NO);
if (ret_code == DB_OK)
{
ret_code = m_ScadaTableOp->GetFieldNoByName(tmp_fno,"real_value");
if (ret_code < 0)
s_info_flag = 0;
else
s_info_flag = 1;
}
}
if (s_info_flag == 1)
{
if (update_type == 1)
{
lock_info.resp_area = 0;
table_no = lock_info.key_id.record_id/KEY_DIV_VALUE;
ret_code = m_ScadaTableOp->Open(AP_SCADA,table_no);
if (ret_code == DB_OK)
{
ret_code = m_ScadaTableOp->TableGetByKey((char *)&lock_info.key_id.record_id,"resp_area",
(char *)&lock_info.resp_area,sizeof(int));
}
}
write_len = sizeof(LockInfoStru);
}
else
{
write_len = sizeof(LockInfoStru) - sizeof(int) - 64;
}
ret_code = m_ScadaTableOp->Open(m_app_id,LOCK_INFO_NO);
if (ret_code != DB_OK)
{
TRACE("lock_info open error %d\n",ret_code);
return -1;
}
if (update_type == 1)
{
ret_code = m_ScadaTableOp->TableWrite((char *)&lock_info,write_len);
if (ret_code <= 0)
{
ret_code = m_ScadaTableOp->TableUpdate((char *)&lock_info,write_len);
if (ret_code < 0)
{
TRACE("lock_info update error %d\n",ret_code);
return -1;
}
sprintf(sql_sentence,"update lock_info set lock_value = '%s',op_person = '%s',op_time = %d ,name= '%s' where key_id = '%010d%04d'",
lock_info.lock_value,lock_info.op_person,lock_info.op_time,lock_info.name,lock_info.key_id.record_id,lock_info.key_id.column_id);
AddOneSql(sql_sentence);
}
else
{
if (s_info_flag == 1)
{
sprintf(sql_sentence,"insert into lock_info(key_id,fac_id,name,type,lock_value,op_person,op_time,real_value,resp_area) values('%010d%04d',%d,'%s',%d,'%s','%s',%d,'%s',%d)",
lock_info.key_id.record_id,lock_info.key_id.column_id,lock_info.fac_id,lock_info.name,
lock_info.type,lock_info.lock_value,lock_info.op_person,lock_info.op_time,
lock_info.real_value,
lock_info.resp_area);
}
else
{
sprintf(sql_sentence,"insert into lock_info(key_id,fac_id,name,type,lock_value,op_person,op_time) values('%010d%04d',%d,'%s',%d,'%s','%s',%d)",
lock_info.key_id.record_id,lock_info.key_id.column_id,lock_info.fac_id,lock_info.name,
lock_info.type,lock_info.lock_value,lock_info.op_person,lock_info.op_time);
}
AddOneSql(sql_sentence);
}
}
else if (update_type == 0)
{
ret_code = m_ScadaTableOp->DeleteRecord((char *)&lock_info.key_id);
if (ret_code < 0)
{
TRACE("delete record error\n");
}
sprintf(sql_sentence,"delete from lock_info where key_id = '%010d%04d'",lock_info.key_id.record_id,lock_info.key_id.column_id);
AddOneSql(sql_sentence);
}
else if (update_type == -1)
{
ret_code = m_ScadaTableOp->TableGet("key_id,fac_id,type",buf_base);
if (ret_code < 0)
{
return -1;
}
lock_buf = (lock_info_stru *)buf_base.GetBufPtr();
rec_num = buf_base.GetLength() / sizeof(lock_info_stru);
if (lock_info.fac_id > 0)
{
for (i=0; i<rec_num; i++)
{
if (lock_buf[i].fac_id == lock_info.fac_id && lock_buf[i].type == lock_info.type)
{
ret_code = m_ScadaTableOp->DeleteRecord((char *)&lock_buf[i].key_id);
if (ret_code < 0)
{
TRACE("delete record error\n");
}
}
}
sprintf(sql_sentence,"delete from lock_info where fac_id = %d and type = %d",lock_info.fac_id,lock_info.type);
AddOneSql(sql_sentence);
}
else
{
for (i=0; i<rec_num; i++)
{
- 1
- 2
前往页