?? global.cpp
字號:
#include "stdafx.h"
#include "global.h"
HMODULE hDebugLib=NULL;
CGlobalApi gApi;
CGlobalManager gDllGlobalManager;
BOOL bCreateDebuger=FALSE;
typedef BOOL (APIENTRY * RUNCOMMAND)(DWORD,HANDLE,HANDLE&);
typedef BOOL (APIENTRY * OPENDEBUGX)(RUNCOMMAND pRun);
typedef BOOL (APIENTRY * OPENDEBUG)();
typedef void (APIENTRY * ADDSTYLEKEY)(LPCTSTR);
typedef void (APIENTRY * SETCOMFN)(HANDLE);
typedef void (APIENTRY * SETLINEFN)(HANDLE,DWORD);
typedef BOOL (APIENTRY * BREAKLINEFN)(HANDLE,DWORD);
typedef void (APIENTRY * APISETFLOWVARIANT)(LPCTSTR lpName,LPCTSTR lpValue,LPCTSTR lpId,int itype,int idx);
APISETFLOWVARIANT pAPISetFlowVariant=NULL;
OPENDEBUGX pOpenDebug=NULL;
OPENDEBUG pCloseDebug=NULL;
ADDSTYLEKEY pAddStyleKey=NULL,pinsertmessage=NULL,pAPIAddOpenFile=NULL,pAPIRemoveOpenFile=NULL;
SETCOMFN pAPIStartDebug=NULL,pAPIEndDebug=NULL,pAPIOnStart=NULL,pCanTraceFlow=NULL,pCancelTraceFlow=NULL;
SETLINEFN pAPISetLine=NULL;
BREAKLINEFN pAPIIsBreakPoint=NULL;
BOOL WINAPI RunCommand(DWORD dwCommand,HANDLE hParam,HANDLE & hResult);
CGlobalManager::CGlobalManager()
{
m_pGlobalApi=NULL;
m_bOwnBus=FALSE;
char szDir[400];
GetCurrentDirectory(400,szDir);
strcat(szDir,"\\UniBus.ini");
char sxBuffer[400];
GetPrivateProfileString("BusConfig","BusFlowName","busmg.txt",sxBuffer,400,szDir);
m_csBusFlow=sxBuffer;
GetPrivateProfileString("BusConfig","BusLogFile","buslog.txt",sxBuffer,400,szDir);
csLogfilename=sxBuffer;
m_iLogmaxlevel=(int)GetPrivateProfileInt("BusConfig","LogLevel",3,szDir);
m_iBusRoadNum=(int)GetPrivateProfileInt("BusConfig","RoadNum",5,szDir);
bCreateDebuger=(int)GetPrivateProfileInt("BusConfig","Createdebuger",1,szDir);
}
void CGlobalApi::insertmessage(char * cs)
{
if(pinsertmessage){
pinsertmessage(cs);
}
else if(m_bRecordMessage){
CStdioFile csf;
if(csf.Open(m_csRecordFileName,CFile::modeWrite|CFile::modeCreate|CFile::modeNoTruncate|CFile::typeText)){
csf.Seek(0,CFile::end);
csf.WriteString(cs);
csf.WriteString("\n");
csf.Close();
}
}
}
void CGlobalApi::APIStartDebug(CUserControl * p){
if(pAPIStartDebug)pAPIStartDebug((HANDLE)p);
};
void CGlobalApi::APIEndDebug(CUserControl * p){
if(pAPIEndDebug)pAPIEndDebug((HANDLE)p);
};
void CGlobalApi::APIOnStart(CUserControl * p){
if(pAPIOnStart)pAPIOnStart((HANDLE)p);
};
void CGlobalApi::APISetLine(CUserControl * p,int iLine){
if(pAPISetLine)pAPISetLine((HANDLE)p,(DWORD)iLine);
};
BOOL CGlobalApi::APIIsBreakPoint(CUserControl * p,int iLine){
if(pAPIIsBreakPoint)
return pAPIIsBreakPoint((HANDLE)p,(DWORD)iLine);
return FALSE;
};
void CGlobalApi::CanTraceFlow(CUserControl * p){
if(pCanTraceFlow)pCanTraceFlow(p);
};
void CGlobalApi::CancelTraceFlow(CUserControl * p){
if(pCancelTraceFlow)pCancelTraceFlow(p);
};
void CGlobalApi::APIAddOpenFile(char * lpFlowFile){
if(pAPIAddOpenFile)pAPIAddOpenFile(lpFlowFile);
};
void CGlobalApi::APIRemovepenFile(char * lpFlowFile){
if(pAPIRemoveOpenFile)pAPIRemoveOpenFile(lpFlowFile);
};
void CGlobalApi::APISetFlowVariant(LPCTSTR lpName,LPCTSTR lpValue,LPCTSTR lpId,int itype,int idx)
{
if(pAPISetFlowVariant)pAPISetFlowVariant(lpName,lpValue,lpId,itype,idx);
}
void CGlobalApi::GLogEvent(LOGTYPE logtype,int icommand,int ilevel,char * lpszdescripe,char * lpLogFileName)
{
gDllGlobalManager.LogEvent(logtype,icommand,ilevel,lpszdescripe,lpLogFileName);
};
CGlobalManager::~CGlobalManager()
{
ClearApiInterface();
}
void CGlobalManager::ClearBus()
{
if(m_bOwnBus&&m_pBus){
if(m_pBus->IsValid(m_pBus))
delete m_pBus;
}
m_bOwnBus=FALSE;
m_pBus=NULL;
}
static LPTSTR s_apszCppKeywordList[] =
{
_T("int"),
_T("dword"),
_T("float"),
_T("string"),
_T("datablock"),
_T("defcommand"),
_T("defevent"),
_T("variant"),
_T("bvariant"),
_T("bnode"),
_T("startmain"),
_T("endmain"),
_T("startproc"),
_T("endproc"),
_T("startevent"),
_T("endevent"),
_T("defproc"),
_T("if"),
_T("else"),
_T("endif"),
_T("then"),
_T("switch"),
_T("case"),
_T("endswitch"),
_T("while"),
_T("endwhile"),
_T("setvalue"),
_T("setblock"),
_T("version"),
_T("style"),
_T("backnode"),
_T("resetnode"),
_T("resume"),
_T("suspend"),
_T("goto"),
_T("jump"),
_T("ret"),
_T("exit"),
_T("default"),
_T("continue"),
_T("#include"),
_T("static"),
_T("const"),
_T("parentstyle"),
_T("break")
};
CDataBus * CGlobalManager::InitBus()
{
if(m_bOwnBus&&m_pBus){
return m_pBus;
}
m_pBus=new CDataBus((LPSTR)(LPCTSTR)csLogfilename,m_iLogmaxlevel,m_iBusRoadNum);//,m_iBusTimeRoad,m_iDefaultRoad,m_iBusTimer);
m_bOwnBus=TRUE;
if(m_pGlobalApi&&!m_pGlobalApi->m_UserName.IsEmpty())
m_pBus->m_csName=m_pGlobalApi->m_UserName;
m_EvtObj.SetBus(m_pBus);
m_LinkObj.SetBus(m_pBus);
m_LinkObj.PointeRoad(1);
PointeRoad(1,-1,true);
if(bCreateDebuger){
hDebugLib=AfxLoadLibrary("edit.dll");
if(!hDebugLib){
bCreateDebuger=FALSE;
}
else{
pOpenDebug=(OPENDEBUGX)GetProcAddress(hDebugLib,"OpenDebug");
pCloseDebug=(OPENDEBUG)GetProcAddress(hDebugLib,"CloseDebug");
pAddStyleKey=(ADDSTYLEKEY)GetProcAddress(hDebugLib,"AddStyleKeyW");
pinsertmessage=(ADDSTYLEKEY)GetProcAddress(hDebugLib,"insertmessage");
pAPIAddOpenFile=(ADDSTYLEKEY)GetProcAddress(hDebugLib,"APIAddOpenFile");
pAPIRemoveOpenFile=(ADDSTYLEKEY)GetProcAddress(hDebugLib,"APIRemoveOpenFile");
pAPIStartDebug=(SETCOMFN)GetProcAddress(hDebugLib,"APIStartDebug");
pAPIEndDebug=(SETCOMFN)GetProcAddress(hDebugLib,"APIEndDebug");
pCanTraceFlow=(SETCOMFN)GetProcAddress(hDebugLib,"CanTraceFlow");
pCancelTraceFlow=(SETCOMFN)GetProcAddress(hDebugLib,"CancelTraceFlow");
pAPIOnStart=(SETCOMFN)GetProcAddress(hDebugLib,"APIOnStart");
pAPISetLine=(SETLINEFN)GetProcAddress(hDebugLib,"APISetLine");
pAPIIsBreakPoint=(BREAKLINEFN)GetProcAddress(hDebugLib,"APIIsBreakPoint");
pAPISetFlowVariant=(APISETFLOWVARIANT)GetProcAddress(hDebugLib,"APISetFlowVariant");
if(pOpenDebug){
pOpenDebug(RunCommand);
if(pAddStyleKey){
for(int i=0;i<sizeof(s_apszCppKeywordList)/sizeof(s_apszCppKeywordList[0]);i++){
pAddStyleKey(s_apszCppKeywordList[i]);
}
CScanner scrfile1("basedrv.cmd"),scrfile2("busdrv.cmd");
DWORD dwId;
int iline=-1,ioline=-1,il=-1;
BOOL bf=TRUE;
char * pName;
while(1){
char * pszWord=scrfile1.ReadWord(pName,dwId,iline);
if(il!=iline){
bf=TRUE;
il=iline;
}
if(ioline!=iline&&pszWord&&!bf){
if(dwId==WORD_IDENTY){
ioline=iline;
pAddStyleKey(pszWord);
}
}
if(bf&&il==iline){
bf=!bf;
}
if(dwId==WORD_ENDOFFILE||!pszWord)break;
}
iline=-1,ioline=-1,il=-1;
bf=TRUE;
while(1){
char * pszWord=scrfile2.ReadWord(pName,dwId,iline);
if(il!=iline){
bf=TRUE;
il=iline;
}
if(ioline!=iline&&pszWord&&!bf){
if(dwId==WORD_IDENTY){
ioline=iline;
pAddStyleKey(pszWord);
}
}
if(bf&&il==iline){
bf=!bf;
}
if(dwId==WORD_ENDOFFILE||!pszWord)break;
}
}
}
}
}
return m_pBus;
}
void CGlobalManager::SetApiInterface(CGlobalApi *pt)
{
m_pGlobalApi=pt;
}
void CGlobalManager::ClearApiInterface()
{
if(m_pBus&&!m_csFlowName.IsEmpty()){
SendEvent(&gDllGlobalManager,ID_CMD_CLOSE);
WaitForEnd(100000);
}
m_pGlobalApi=NULL;
for(int i=0;i<m_CommandList.GetSize();i++){
delete m_CommandList[i];
};
m_CommandList.RemoveAll();
ClearBus();
gFlowMg.CloseAll();
for(i=0;i<m_FlowList.GetSize();i++){
if(m_FlowList[i]->IsValid()&&m_FlowList[i]->ControlValid()){
delete m_FlowList[i];
m_FlowList[i]=NULL;
}
}
m_FlowList.RemoveAll();
if(bCreateDebuger){
if(hDebugLib){
if(pCloseDebug)
pCloseDebug();
pOpenDebug=NULL;
pCloseDebug=NULL;
pAddStyleKey=NULL;
pinsertmessage=NULL;
pAPIAddOpenFile=NULL;
pAPIRemoveOpenFile=NULL;
pAPIStartDebug=NULL;
pAPIEndDebug=NULL;
pAPIOnStart=NULL;
pCanTraceFlow=NULL;
pCancelTraceFlow=NULL;
pAPISetLine=NULL;
pAPIIsBreakPoint=NULL;
AfxFreeLibrary(hDebugLib);
}
bCreateDebuger=FALSE;
}
Sleep(500);
}
#include "HopeKingDatabase.h"
AFX_EXT_CLASS CDataBus * SetInterface(CGlobalApi * papi,
CDataBus * pdb,
BOOL bRunBusFlow)
{
CDataBus * pretb=pdb;
if(papi)
gDllGlobalManager.SetApiInterface(papi);
else gDllGlobalManager.SetApiInterface(&gApi);
if(pdb){
if((DWORD)pdb!=0xffffffff)
gDllGlobalManager.SetBus(pdb);
}
else {
pretb=gDllGlobalManager.InitBus();
}
if(bRunBusFlow){
gDllGlobalManager.m_bBoolCanTrace=TRUE;
gDllGlobalManager.SetFlowDescripe("總線驅動流程");
if(!gDllGlobalManager.CreateFlow((LPSTR)(LPCTSTR)gDllGlobalManager.m_csBusFlow)){
return NULL;
}
gDllGlobalManager.GetBus()->Register(0x10001000,&gDllGlobalManager);
gDllGlobalManager.GetBus()->pRemoteControl=(CAsynWorker *)&gDllGlobalManager;
gDllGlobalManager.Start();
gDllGlobalManager.SendEvent(&gDllGlobalManager,ID_CMD_INIT);
gDllGlobalManager.m_bBoolCanTrace=FALSE;
}
pretb=gDllGlobalManager.GetBus();
return pretb;
}
AFX_EXT_CLASS void ClearInterface()
{
gDllGlobalManager.ClearApiInterface();
}
void AsEventObject::OnMsgEvent(CUniMsg * pMsg)
{
switch(pMsg->m_dwCommand){
case EVT_SETEVENT_LINK:
if(gDllGlobalManager.m_pGlobalApi)
gDllGlobalManager.m_pGlobalApi->OnLinkStatusChanged(
(DWORD)pMsg->m_pTV[0],
(LPCTSTR)(LPSTR)pMsg->m_pTV[1],
(int)pMsg->m_pTV[2]);
return;
default:
CAsynWorker::OnMsgEvent(pMsg);
}
}
void AsLinkObject::OnMsgEvent(CUniMsg * pMsg)
{
switch(pMsg->m_dwCommand){
case EVT_LINK_ALL:
{
DWORD dwHandle=(DWORD)(CAsynWorker *)&gDllGlobalManager;
m_pBus->LinkAll(CommDllCallBack,dwHandle);
}
return;
default:
CAsynWorker::OnMsgEvent(pMsg);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -