📄 baseflow.cpp
字号:
#include "stdafx.h"
#include "monitor.h"
#include "baseflow.h"
#include "global.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
BOOL CBaseFlow::BStart(int iNum,UniVar * pVar)
{
m_FlowParam.Clear();
for(int i=0;i<iNum;i++){
m_FlowParam.Add(pVar[i]);
}
return Start();
}
BOOL CBaseFlow::BStart(UniVar uvi,...)
{
m_FlowParam.Clear();
if(UniVar::ValidVar(&uvi)){
m_FlowParam.Add(uvi);
va_list varl;
va_start(varl,uvi);
UniVar uv;
while(1){
uv=va_arg(varl,UniVar);
if(UniVar::ValidVar(&uv)){
m_FlowParam.Add(uv);
}
else break;
};
va_end(varl);
}
return Start();
}
COMMANDRESULT CBaseFlow::DefaultParse(DWORD dwCommand,UniVar * pdwCommandList,int iNum)
{
switch(dwCommand){
case FLOWDataLen:
if(pdwCommandList[0].it==DATA_TYPE_STRING){
pdwCommandList[1]=(int)pdwCommandList[0].GetDataLength()-1;
}
else {
pdwCommandList[1]=(int)pdwCommandList[0].GetDataLength();
}
break;
case FLOWtrimleft :
{
CString cs=(char *)pdwCommandList[0];
cs.TrimLeft();
pdwCommandList[0]=UniVar(cs);
}
break;
case FLOWtrimright :
{
CString cs=(char *)pdwCommandList[0];
cs.TrimRight();
pdwCommandList[0]=UniVar(cs);
}
break;
case FLOWsubstr :
{
CString cs=(char *)pdwCommandList[0];
pdwCommandList[0] = UniVar(cs.Mid((int)pdwCommandList[1],(int)pdwCommandList[2]));
}
break;
case FLOWsubinsert :
{
CString cs=(char *)pdwCommandList[0];
int i=cs.GetLength();
if((int)pdwCommandList[1]<0||(int)pdwCommandList[1]>=i)break;
cs.Insert((int)pdwCommandList[1],(char *)pdwCommandList[2]);
pdwCommandList[0]=((LPSTR)(LPCTSTR)cs);
}
break;
case FLOWreplease :
{
CString cs=(char *)pdwCommandList[0];
pdwCommandList[3]=cs.Replace((char *)pdwCommandList[1],(char *)pdwCommandList[2]);
pdwCommandList[0]=((LPSTR)(LPCTSTR)cs);
}
break;
case FLOWfindstr :
{
CString cs=(char *)pdwCommandList[0];
pdwCommandList[2]=cs.Find((char *)pdwCommandList[1],(int)pdwCommandList[2]);
}
break;
case FLOWisempty :
pdwCommandList[1]=(int)(pdwCommandList[0].IsEmpty());
break;
case FLOWleftstr :
{
CString cs=(char *)pdwCommandList[0];
pdwCommandList[0]=UniVar(cs.Left((int)pdwCommandList[1]));
}
break;
case FLOWrightstr :
{
CString cs=(char *)pdwCommandList[0];
pdwCommandList[0]=UniVar(cs.Right((int)pdwCommandList[1]));
}
break;
case FLOWatoi :
pdwCommandList[1]=atoi((char *)pdwCommandList[0]);
break;
case FLOWitoa :
{
CString cs;
cs.Format("%ld",(int)pdwCommandList[1]);
pdwCommandList[0]=(LPSTR)(LPCTSTR)cs;
}
break;
case FLOWatof :
pdwCommandList[1]=(float)atof((char *)pdwCommandList[0]);
break;
case FLOWftoa :
{
CString cs;
cs.Format("%f",(double)pdwCommandList[1]);
pdwCommandList[0]=(LPSTR)(LPCTSTR)cs;
}
break;
case FLOWcopyfile :
pdwCommandList[2]=CopyFile((char *)pdwCommandList[0],(char *)pdwCommandList[1],TRUE);
break;
case FLOWmovefile :
pdwCommandList[2]=MoveFile((char *)pdwCommandList[0],(char *)pdwCommandList[1]);
break;
case FLOWremovefile :
pdwCommandList[1]=DeleteFile((char *)pdwCommandList[0]);
break;
case FLOWblockopr :
pdwCommandList[0].BlockSet((UniVar::BLOCKOPRATOR)(int)pdwCommandList[2],pdwCommandList[1],(int)pdwCommandList[3],(int)pdwCommandList[4],(int)pdwCommandList[5]);
break;
case FLOWbyteget :
{
switch(pdwCommandList[0].it){
case DATA_TYPE_HANDLE:
case DATA_TYPE_STRING:
{
int idx=(int)pdwCommandList[2];
if(idx<0)idx=0;
int ul=(int)pdwCommandList[3];
if(ul!=1&&ul!=2&&ul!=4)ul=1;
if(idx*ul+ul<=pdwCommandList[0].GetDataLength()){
BYTE * pD=(BYTE *)pdwCommandList[0].uv.cv+idx*ul;
if(ul==1){
pdwCommandList[1]=(int)(((BYTE *)pD)[0]);
}
else if(ul==2){
pdwCommandList[1]=(int)(((WORD *)pD)[0]);
}
else {
pdwCommandList[1]=(int)(((DWORD *)pD)[0]);
}
}
else{
pdwCommandList[1]=0;
}
}
break;
default:
pdwCommandList[1]=pdwCommandList[0].uv.iv;
break;
}
}
break;
case FLOWIsFileExist :
{
CFileFind cff;
pdwCommandList[1]=cff.FindFile((char *)pdwCommandList[0]);
}
break;
case FLOWbyteset :
{
switch(pdwCommandList[0].it){
case DATA_TYPE_HANDLE:
case DATA_TYPE_STRING:
{
int idx=(int)pdwCommandList[2];
if(idx<0)idx=0;
int ul=(int)pdwCommandList[3];
if(ul!=1&&ul!=2&&ul!=4)ul=1;
if(idx*ul+ul<=pdwCommandList[0].GetDataLength()){
BYTE * pD=(BYTE * )pdwCommandList[0].uv.cv+idx*ul;
if(ul==1){
((BYTE *)pD)[0]=(BYTE)(int)pdwCommandList[1];
}
else if(ul==2){
((short *)pD)[0]=(short)(int)pdwCommandList[1];
}
else {
((DWORD *)pD)[0]=(DWORD)pdwCommandList[1];
}
}
else{
}
}
}
}
break;
case FLOWtostring :
pdwCommandList[0].ToA();
break;
case FLOWapidefinetype :
gDllGlobalManager.GetBus()->m_pEdauDllProxy->SetApiType(pdwCommandList[0].uv.pv,pdwCommandList+1,iNum-1);
break;
case FLOWapiloaddll :
gDllGlobalManager.GetBus()->m_pEdauDllProxy->LoadAPILibrary((LPSTR)pdwCommandList[1],pdwCommandList[0].uv.pv);
break;
case FLOWapicalldll :
gDllGlobalManager.GetBus()->m_pEdauDllProxy->CallAPIFunction((DWORD)pdwCommandList[0],(DWORD)pdwCommandList[1],(LPSTR)pdwCommandList[2],pdwCommandList[3].uv.iv,pdwCommandList[4],pdwCommandList+5,iNum-5);
break;
case APIBUSGetLastError ://int & errorcode
pdwCommandList[0]=m_iErrorCode;
m_iErrorCode=0;
break;
case APIBUSSetLastError ://int & errorcode
m_iErrorCode=(int)pdwCommandList[0];
break;
case APIBUSSetFlowParam ://datablock 0 param,INDEX int idx=0xffffffff
if((int)pdwCommandList[1]>=0&&(int)pdwCommandList[1]<m_FlowParam.GetSize()){
pdwCommandList[0]=m_FlowParam.GetAt((int)pdwCommandList[1]);
}
else{
m_FlowParam.Add(pdwCommandList[0]);
}
break;
case APIBUSClearFlowParam://
m_FlowParam.Clear();
break;
case APIBUSGetFlowParam ://datablock 0 & param,int idx
if((int)pdwCommandList[1]>=0&&(int)pdwCommandList[1]<m_FlowParam.GetSize()){
pdwCommandList[0]=m_FlowParam.GetAt((int)pdwCommandList[1]);
}
else{
pdwCommandList[0]=0;
}
break;
case APIBUSGetAllFlowParam://
{
for(int i=0;i<iNum&&i<m_FlowParam.GetSize();i++){
pdwCommandList[i]=m_FlowParam.GetAt(i);
}
}
break;
case APIBUSGetFlowParamNum ://int & idx
pdwCommandList[0]=m_FlowParam.GetSize();
break;
case APIBUSGetErrMsg ://int errorcode, ERRMSG string & errormsg
pdwCommandList[1]=GetErrorMsg((int)pdwCommandList[0]);
break;
case APIBUSGetTimeHandle ://int & time
pdwCommandList[0]=(int)GetTimeStamp();
break;
case APIBUSSetTimeString ://int time,string & tmstr
{
int im=(int)pdwCommandList[0];
if(!im)im=GetTimeStamp();
CTime tm(im);
CString cs=tm.Format("%Y-%m-%d %H:%M:%S");
pdwCommandList[1]=(LPSTR)(LPCTSTR)cs;
}
break;
case APIBUSGetDate ://int & year,int & month,int & day,int & dayofweek,TNHND int tm=0
{
int im=(int)pdwCommandList[4];
if(!im)im=GetTimeStamp();
CTime tm(im);
pdwCommandList[0]=tm.GetYear();
pdwCommandList[1]=tm.GetMonth();
pdwCommandList[2]=tm.GetDay();
pdwCommandList[3]=tm.GetDayOfWeek();
}
break;
case APIBUSGetTime ://int & hour,int & minute,int & second,TNHND int tm=0
{
int im=(int)pdwCommandList[3];
if(!im)im=GetTimeStamp();
CTime tm(im);
pdwCommandList[0]=tm.GetHour();
pdwCommandList[1]=tm.GetMinute();
pdwCommandList[2]=tm.GetSecond();
}
break;
case APIBUSFlowLog:
LogEvent((LOGTYPE)(int)pdwCommandList[0],(int)pdwCommandList[1],(int)pdwCommandList[2],(char * )pdwCommandList[3],(char * )pdwCommandList[4]);
break;
case APIBUSOpenMoniterObjector ://int & iHandle,SFLAG int iflag=0,string strGroupName,string strObjectName,...
pdwCommandList[0]=(int)(gUserMonitorManager.CreateUserMonitorObject(
pdwCommandList[2],
pdwCommandList[3],
iNum-4,
pdwCommandList+4,
(int)pdwCommandList[1]));
break;
case APIBUSSetMoniterObValue ://int iHandle,SFLAG int iflag=0,int idx,datablock 0 uvValue
{
CUserMonitor * pUm=(CUserMonitor *)((int)pdwCommandList[0]);
// if(CUserMonitor::IsValid(pUm)){
if(pUm->IsValid(pUm)){
if(!(int)pdwCommandList[1]){
pUm->SetFValueVar((int)pdwCommandList[2],pdwCommandList[3]);
}
else{
pUm->SetRelationVar((int)pdwCommandList[2],pdwCommandList[3]);
}
}
}
break;
case APIBUSGetMoniterObValue ://int iHandle,SFLAG int iflag=0,int idx,datablock 0 & uvValue
{
CUserMonitor * pUm=(CUserMonitor *)((int)pdwCommandList[0]);
if(pUm->IsValid(pUm)){
if(!(int)pdwCommandList[1]){
pUm->GetFValueVar((int)pdwCommandList[2],pdwCommandList[3]);
}
else{
pUm->GetRelationVar((int)pdwCommandList[2],pdwCommandList[3]);
}
}
}
break;
case APIBUSErrorMsgBox ://string strMsg
if(!pdwCommandList[0].IsEmpty()){
AfxMessageBox((char *)pdwCommandList[0]);
}
break;
case APIBUSAddMessageInfo ://int id,string strinfo
AddErrorMsg((int)pdwCommandList[0],(char *)pdwCommandList[1]);
break;
case APIBUSGetMessageInfo ://int id,string & strinfo
pdwCommandList[1]=GetErrorMsg((int)pdwCommandList[0]);
break;
case APIBUSFlowTrace :// 0x00f0001f //string strInfo
{
if(gDllGlobalManager.m_pGlobalApi)
gDllGlobalManager.m_pGlobalApi->insertmessage((char *)pdwCommandList[0]);
}
break;
/* case APIBUSFlowSmardLog :// 0x00f00022 //CHAN int iChannel=0,string szFunction,int & iRetCode,...
{
if(!m_pBus||!m_pBus->m_pDataBaseObject){
m_iErrorCode=-1;
}
else{
CUniMsg um;
um.SetMessage(NULL,m_pBus->m_pDataBaseObject,CMD_TASK_RUNTASK,MSG_EVENT);
for(int i=0;i<iNum;i++)
um.Add(pdwCommandList[i]);
SendMsg(&um,3,NULL,-1);
}
}
break;
*/
case APIBUSGetRTStructInfo ://0x00f10023 //datablock 0 rstruct,RET int & ret=0,LINE int line=0,COLUM icol=0,NEXT int bHasNext=0,HANDLE int handle=0,SID int isid=0,CRET int bHasRet=0,KEY string szkey='',ERRMSG string szErrMsg ='',UTYPE int uType=0
{
if(pdwCommandList[0].GetDataLength()>=sizeof(RESULT)){
//datablock 0 rstruct,
RESULT * pResult=(RESULT * )(void *)pdwCommandList[0];
//RET int & ret=0,
pdwCommandList[1]=pResult->iRet;
//LINE int line=0,
pdwCommandList[2]=pResult->retData.rtArray.iRow;
//COLUM icol=0,
pdwCommandList[3]=pResult->retData.rtArray.iCol;
//NEXT int bHasNext=0,
pdwCommandList[4]=pResult->bHasNext;
//HANDLE int handle=0,
pdwCommandList[5]=pResult->iRetHandle;
//SID int isid=0,
pdwCommandList[6]=pResult->iSid;
//CRET int bHasRet=0,
pdwCommandList[7]=pResult->bHasRet;
//KEY string szkey='',
pdwCommandList[8];//=pResult->bHasRet;
//ERRMSG string szErrMsg ='',
pdwCommandList[9]=pResult->szErrMsg;
//UTYPE int uType=0
pdwCommandList[10]=(int)pResult->uType;
}
}
break;
case APIBUSGetRTStructUnit ://0x00f10024 //datablock 0 rstruct,int lin,int col,string & unit,...
{
if(pdwCommandList[0].GetDataLength()>=sizeof(RESULT)){
//datablock 0 rstruct,
RESULT * pResult=(RESULT * )(void *)pdwCommandList[0];
int line=(int)pdwCommandList[1];
if(pResult->retData.rtArray.iRow<=line||line<0)break;
int col=(int)pdwCommandList[2];
if(col!=-1)
if(col>=pResult->retData.rtArray.iCol||col<0)break;
if(col!=-1){
pdwCommandList[3]=(char *)pResult->retData.rtArray.Array[line][col];
}
else {
for(int i=0;i<pResult->retData.rtArray.iCol&&i<iNum-3;i++){
pdwCommandList[i+3]=(char *)pResult->retData.rtArray.Array[line][i];
}
}
}
}
break;
case APIBUSRegeisterWorker ://0x00f10026 //int iregisterid
{
BOOL ret=Register((int)pdwCommandList[0]);
if(iNum==2)pdwCommandList[1]=ret;
}
break;
case APIBUSSetBusLogLevel ://0x00f10028 //int ilevel
if(m_pBus)m_pBus->SetLogWriteLevel((int)pdwCommandList[0]);
break;
case APIBUSGetBlockUnit ://0x00f1002a //datablock 0 uv,int first,dword dwtyp,...
{
if(pdwCommandList[0].it!=DATA_TYPE_HANDLE||!pdwCommandList[0].uv.cv||pdwCommandList[0].GetDataLength()<(int)pdwCommandList[1]||iNum<=3)break;
m_pBus->m_pEdauDllProxy->GetBlockUnit(pdwCommandList[0].uv.bv+(DWORD)pdwCommandList[1],pdwCommandList[0].GetDataLength()-(DWORD)pdwCommandList[1],(DWORD)pdwCommandList[2],pdwCommandList+3,iNum-3);
}
break;
case APIBUSSetBlockUnit ://0x00f1002b //datablock 0 & uv,int first,dword dwtyp,...
{
if(pdwCommandList[0].it!=DATA_TYPE_HANDLE||!pdwCommandList[0].uv.cv||pdwCommandList[0].GetDataLength()<(int)pdwCommandList[1]||iNum<=3)break;
m_pBus->m_pEdauDllProxy->GetBlockUnit(pdwCommandList[0].uv.bv+(DWORD)pdwCommandList[1],pdwCommandList[0].GetDataLength()-(DWORD)pdwCommandList[1],(DWORD)pdwCommandList[2],pdwCommandList+3,iNum-3);
}
break;
case APIBUSSetTimeHandle ://0x00f1002d //int & time,int year,int month,int day,int hour,int minute,int second
{
CTime tm((int)pdwCommandList[1],
(int)pdwCommandList[2],
(int)pdwCommandList[3],
(int)pdwCommandList[4],
(int)pdwCommandList[5],
(int)pdwCommandList[6]);
pdwCommandList[0]=(int)tm.GetTime();
}
break;
case APIBUSGetTimeDiff ://0x00f1002e //int tm1,int tm2,DAYS int & day=0,HOURS int & hour=0,MINUTES int & minute=0,SECONDS int & second=0,ALLHOURS int allhours=0,ALLMINUTES int & allminutes=0,ALLSECONDS int & allseconds=0
{
CTime tm1((time_t)(int)pdwCommandList[0]),tm2((time_t)(int)pdwCommandList[1]);
CTimeSpan tms=tm1-tm2;
pdwCommandList[2]=(int)tms.GetDays();
pdwCommandList[3]=(int)tms.GetHours();
pdwCommandList[4]=(int)tms.GetMinutes();
pdwCommandList[5]=(int)tms.GetSeconds();
pdwCommandList[6]=(int)tms.GetTotalHours();
pdwCommandList[7]=(int)tms.GetTotalMinutes();
pdwCommandList[8]=(int)tms.GetTotalSeconds();
}
break;
/* case APIBUSInitSmard ://0x00f1002f //int & suc,string szlib,TIMEOUT int timeout=60,THREADNUM int tnum=1
{
if(!m_pBus){
pdwCommandList[0]=0;
}
else {
pdwCommandList[0]=m_pBus->OpenSmard((char *)pdwCommandList[1],(int)pdwCommandList[2],(int)pdwCommandList[3]);
}
}
break;
*/
case APIBUSInitEdau ://0x00f10030 //int & suc,TIMEOUT int timeout=60,THREADNUM int tnum=5
{
if(!m_pBus){
pdwCommandList[0]=0;
}
else {
m_pBus->OpenEdau((int)pdwCommandList[1],(int)pdwCommandList[2]);
pdwCommandList[0]=1;
}
}
break;
case APIBUSOpenEdauLib ://0x00f10031 //int & suc,string szLib,string szAlis
{
if(!m_pBus){
pdwCommandList[0]=0;
}
else {
pdwCommandList[0]=m_pBus->AddEdauLib((char *)pdwCommandList[1],(char *)pdwCommandList[2]);
}
}
break;
case APIBUSFindData ://0x00f1002c //datablock 0 uv,datablock 0 uv1,int first,int & pos
{
pdwCommandList[3]=-1;
int iclen=pdwCommandList[1].GetDataLength();
if(pdwCommandList[0].it!=DATA_TYPE_HANDLE||!pdwCommandList[0].uv.cv||pdwCommandList[0].GetDataLength()<(int)pdwCommandList[2]||!iclen)break;
int ialen=pdwCommandList[0].GetDataLength()-(int)pdwCommandList[2];
BYTE * p1=pdwCommandList[0].uv.bv+(int)pdwCommandList[2];
BYTE * p2=pdwCommandList[1].uv.bv;
switch(iclen){
case 1:
{
for(int i=0;i+iclen<=ialen;i++){
if(p1[i]==p2[0]){
pdwCommandList[3]=i+(int)pdwCommandList[2];
return LINE_CONTINUE;
}
}
}
break;
case 2:
{
for(int i=0;i+iclen<=ialen;i++){
if(((short*)(p1+i))[0]==((short *)p2)[0]){
pdwCommandList[3]=i+(int)pdwCommandList[2];
return LINE_CONTINUE;
}
}
}
break;
case 4:
{
for(int i=0;i+iclen<=ialen;i++){
if(((int*)(p1+i))[0]==((int *)p2)[0]){
pdwCommandList[3]=i+(int)pdwCommandList[2];
return LINE_CONTINUE;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -