// 收到打开完成消息后调用该函数 void CMFPI::WR_OpenComplete(DWORD dwCommand, HRESULT hResult, LPVOID lpBuffer) { //异步打开成功 if(LFS_SUCCESS == hResult) { DWORD dwEvent = SERVICE_EVENTS | USER_EVENTS | SYSTEM_EVENTS | EXECUTE_EVENTS; int ret = m_apiCtrl.LFSAsyncRegister(dwEvent,&m_CurrRequestID); if(LFS_SUCCESS != ret) { N_Close(); emit OpenFailed(); LOGERROR("%s,注册事件失败,错误码:ret = %d",__FUNCTION__,ret); Alarm("07000000"); } } else { emit OpenFailed(); LOGERROR("%s,打开失败,错误码:hResult = %d",__FUNCTION__,hResult); Alarm("07000000"); } }
int CMFPI::N_Open() { int ret = m_apiCtrl.LFSAsyncOpen(m_szLogicalName,HM_MIDDLE_TIMEOUT,&m_CurrRequestID); if(LFS_SUCCESS!=ret) { LOGERROR("%s,打开失败!错误码:ret = %d",__FUNCTION__,ret); Alarm("07000000"); emit OpenFailed(); } /////获取产商 m_Fpiprovider=help.GetPrivateProfileInt("MFPI","Fpiprovider",2,m_strConfigPath); return ret; }
void CMFPI::WR_RegisterComplete(DWORD dwCommand, HRESULT hResult, LPVOID lpBuffer) { if(LFS_SUCCESS != hResult) { N_Close(); emit OpenFailed(); LOGERROR("%s,注册事件失败,错误码:hResult = %d",__FUNCTION__,hResult); Alarm("07000000"); } else { m_bOpened = true; emit ConnectionOpened(); LOGINFO("%s,事件:ConnectionOpened()",__FUNCTION__); } }
void cStructLoaderPlain::Load(bool reload) { if(SL_TSTFLAG(SL_DISABLED) || reload) return; FILE *f=fopen(path,"r"); if(f) { PreLoad(); ListLock(true); SL_SETFLAG(SL_LOADED); PRINTF(L_GEN_INFO,"loading %s from %s",type,path); CheckAccess(); int lineNum=0; char buff[4096]; while(fgets(buff,sizeof(buff),f)) { lineNum++; if(!index(buff,'\n') && !feof(f)) { PRINTF(L_GEN_ERROR,"file %s readbuffer overflow line#%d",path,lineNum); SL_CLRFLAG(SL_LOADED); break; } strreplace(buff,'\n',0); strreplace(buff,'\r',0); // chomp bool hasContent=false; char *ls; for(ls=buff; *ls; ls++) { if(*ls==';' || *ls=='#') break; if(*ls>' ') hasContent=true; } if(hasContent) { *ls=0; if(!ParseLinePlain(skipspace(buff))) PRINTF(L_GEN_ERROR,"file %s has error in line #%d",path,lineNum); } } ListUnlock(); PostLoad(); fclose(f); LoadFinished(); } else OpenFailed(); }
void cStructLoader::Load(bool reload) { if(SL_TSTFLAG(SL_DISABLED) || (reload && !SL_TSTFLAG(SL_WATCH))) return; FILE *f=fopen(path,"r"); if(f) { PreLoad(); int curr_mtime=MTime(true); ListLock(true); bool doload=false; if(!reload) { Clear(); Modified(false); mtime=curr_mtime; doload=true; } else if(mtime<curr_mtime) { PRINTF(L_CORE_LOAD,"detected change of %s",path); if(IsModified()) PRINTF(L_CORE_LOAD,"discarding in-memory changes"); for(cStructItem *a=First(); a; a=Next(a)) DelItem(a); Modified(false); mtime=curr_mtime; doload=true; } if(doload) { SL_SETFLAG(SL_LOADED); PRINTF(L_GEN_INFO,"loading %s from %s",type,path); CheckAccess(); int lineNum=0, num=0; char buff[4096]; while(fgets(buff,sizeof(buff),f)) { lineNum++; if(!index(buff,'\n') && !feof(f)) { PRINTF(L_GEN_ERROR,"file %s readbuffer overflow line#%d",path,lineNum); SL_CLRFLAG(SL_LOADED); break; } strreplace(buff,'\n',0); strreplace(buff,'\r',0); // chomp bool hasContent=false; char *ls; for(ls=buff; *ls; ls++) { if(*ls==';' || *ls=='#') { // comment if(hasContent) while(ls>buff && ls[-1]<=' ') ls--; // search back to non-whitespace break; } if(*ls>' ') hasContent=true; // line contains something usefull } cStructItem *it=0; if(hasContent) { char save=*ls; *ls=0; it=ParseLine(skipspace(buff)); *ls=save; if(!it) { PRINTF(L_GEN_ERROR,"file %s has error in line #%d",path,lineNum); ls=buff; } else num++; } else ls=buff; if(!it) it=new cCommentItem; if(it) { it->SetComment(ls); Add(it); } else { PRINTF(L_GEN_ERROR,"out of memory loading file %s",path); SL_CLRFLAG(SL_LOADED); break; } } ListUnlock(); PRINTF(L_CORE_LOAD,"loaded %d %s from %s",num,type,path); PostLoad(); } else ListUnlock(); fclose(f); LoadFinished(); } else OpenFailed(); }