📄 gateserver.cc
字号:
int status=pv_list.remove(pv->name(),pNode);#if DEBUG_PV_LIST if(ifirst) { ifirst=0; } printf("%s gateServer::inactiveDeadCleanup(inactive): [%lu|%lu|%lu,%lu|%lu,%lu,%lu]: " "name=%s time=%ld count=%d state=%s\n", timeStamp(), total_vc,total_pv,total_active,total_inactive, total_connecting,total_dead,total_disconnected, pv->name(),pv->timeInactive(),pv->totalElements(),pv->getStateName());#endif if(status) printf("%s Clean inactive PV from PV list failed for pvname=%s.\n", timeStamp(),pv->name()); pNode->destroy(); } else if(pv->disconnected() && pv->timeDisconnected()>=global_resources->inactiveTimeout()) { gateDebug1(3,"gateServer::inactiveDeadCleanup disconnected PV %s\n", pv->name()); int status=pv_list.remove(pv->name(),pNode);#if DEBUG_PV_LIST if(ifirst) { ifirst=0; } printf("%s gateServer::inactiveDeadCleanup(disconnected): [%lu|%lu|%lu,%lu|%lu,%lu,%lu]: " "name=%s time=%ld count=%d state=%s\n", timeStamp(), total_vc,total_pv,total_active,total_inactive, total_connecting,total_dead,total_disconnected, pv->name(),pv->timeInactive(),pv->totalElements(),pv->getStateName());#endif if(status) printf("%s Clean disconnected PV from PV list failed for pvname=%s.\n", timeStamp(),pv->name()); pNode->destroy(); } iter=tmpIter; } setDeadCheckTime(); setInactiveCheckTime();}pvExistReturn gateServer::pvExistTest(const casCtx& ctx, const caNetAddr&, const char* pvname){ return pvExistTest(ctx, pvname);}pvExistReturn gateServer::pvExistTest(const casCtx& ctx, const char* pvname){ gateDebug2(5,"gateServer::pvExistTest(ctx=%p,pv=%s)\n",(void *)&ctx,pvname); gatePvData* pv; pvExistReturn rc; gateAsEntry* pEntry; char real_name[GATE_MAX_PVNAME_LENGTH];#if DEBUG_FDMGR static double cumTime=0.0; epicsTime startTime, endTime;#endif ++exist_count;#if DEBUG_EXIST printf("%s pvExistTest: %s\n",timeStamp(),pvname?pvname:"NULL");#endif#if DEBUG_HISTORY if(!strncmp(HISTNAME,pvname,HISTNUM)) { printf("%s gateServer::pvExistTest: loop_count=%lu %s\n", timeStamp(),loop_count,pvname); }#endif#if DEBUG_FDMGR startTime=epicsTime::getCurrent(); if(exist_count%1000 == 0) { printf("%s pvExistTest: exist_count=%lu cumTime=%.3f\n", timeStamp(),exist_count,cumTime); }#endif#ifdef USE_DENYFROM // Getting the host name is expensive. Only do it if the // deny_from_list is used if(getAs()->isDenyFromListUsed()) { char hostname[GATE_MAX_HOSTNAME_LENGTH]; // Get the hostname and check if it is allowed getClientHostName(ctx, hostname, sizeof(hostname)); // See if requested name is allowed and check for aliases if ( !(pEntry = getAs()->findEntry(pvname, hostname)) ) { gateDebug2(1,"gateServer::pvExistTest() %s (from %s) is not allowed\n", pvname, hostname);#if DEBUG_FDMGR endTime=epicsTime::getCurrent(); cumTime+=(endTime-startTime);#endif return pverDoesNotExistHere; } } else { // See if requested name is allowed and check for aliases. // NULL will avoid checking the deny_from_list if ( !(pEntry = getAs()->findEntry(pvname, NULL)) ) { gateDebug1(1,"gateServer::pvExistTest() %s is not allowed\n", pvname);#if DEBUG_FDMGR endTime=epicsTime::getCurrent(); cumTime+=(endTime-startTime);#endif return pverDoesNotExistHere; } }#else // See if requested name is allowed and check for aliases. Uses // information in .pvlist, not .access. if ( !(pEntry = getAs()->findEntry(pvname)) ) { gateDebug1(1,"gateServer::pvExistTest() %s is not allowed\n", pvname);#if DEBUG_FDMGR endTime=epicsTime::getCurrent(); cumTime+=(endTime-startTime);#endif return pverDoesNotExistHere; }#endif pEntry->getRealName(pvname, real_name, sizeof(real_name));#ifdef USE_DENYFROM gateDebug3(1,"gateServer::pvExistTest() %s (from %s) real name %s\n", pvname, hostname, real_name);#else gateDebug2(1,"gateServer::pvExistTest() %s real name %s\n", pvname, real_name);#endif#if statCount // Check internal PVs if(!strncmp(stat_prefix,real_name,stat_prefix_len)) { for(int i=0; i < statCount; i++) { if(strcmp(real_name,stat_table[i].pvName)==0) {#if DEBUG_DESC printf(" pattern=%s alias=%s group=%s\n", pEntry->pattern?pEntry->pattern:"NULL", pEntry->alias?pEntry->alias:"NULL", pEntry->group?pEntry->group:"NULL"); printf(" pverExistsHere\n"); #endif#if DEBUG_FDMGR endTime=epicsTime::getCurrent(); cumTime+=(endTime-startTime);#endif return pverExistsHere; } if(strcmp(real_name,stat_table[i].descPvName)==0) {#if DEBUG_DESC printf(" pverExistsHere\n"); #endif#if DEBUG_FDMGR endTime=epicsTime::getCurrent(); cumTime+=(endTime-startTime);#endif return pverExistsHere; } } }#endif // Check if we have it if(pvFind(real_name,pv)==0) { // Is in pv_list switch(pv->getState()) { case gatePvInactive: case gatePvActive: // We are connected to the PV gateDebug2(5,"gateServer::pvExistTest() %s exists (%s)\n", real_name,pv->getStateName()); rc=pverExistsHere; break; default: // We are not currently connected gateDebug2(5,"gateServer::pvExistTest() %s is %s\n", real_name,pv->getStateName()); rc=pverDoesNotExistHere; break; }#if DEBUG_DELAY if(!strncmp("Xorbit",pvname,6)) { printf("%s gateServer::pvExistTest [pvFind]: loop_count=%lu %s\n", timeStamp(),loop_count,pvname); }#endif#if DEBUG_HISTORY if(!strncmp(HISTNAME,pvname,HISTNUM)) { printf("%s gateServer::pvExistTest [pvFind]: loop_count=%lu %s\n", timeStamp(),loop_count,pvname); }#endif } else if(conFind(real_name,pv)==0) { // Is in pv_con_list -- connect is pending gateDebug1(5,"gateServer::pvExistTest() %s Connecting (new async ET)\n",real_name); pv->addET(ctx);#if DEBUG_DELAY if(!strncmp("Xorbit",pvname,6)) { printf("%s gateServer::pvExistTest [conFind]: loop_count=%lu %s\n", timeStamp(),loop_count,pvname); }#endif#if DEBUG_HISTORY if(!strncmp(HISTNAME,pvname,HISTNUM)) { printf("%s gateServer::pvExistTest [conFind]: loop_count=%lu %s\n", timeStamp(),loop_count,pvname); }#endif rc=pverAsyncCompletion; } else { // We don't have it so make a new gatePvData gateDebug1(5,"gateServer::pvExistTest() %s creating new gatePv\n",real_name); pv=new gatePvData(this,pEntry,real_name);#if DEBUG_DELAY if(!strncmp("Xorbit",pvname,6)) { printf("\n%s gateServer::pvExistTest: loop_count=%lu %s\n", timeStamp(),loop_count,pvname); }#endif#if DEBUG_HISTORY if(!strncmp(HISTNAME,pvname,HISTNUM)) { printf("\n%s gateServer::pvExistTest: loop_count=%lu %s\n", timeStamp(),loop_count,pvname); }#endif switch(pv->getState()) { case gatePvConnect: gateDebug2(5,"gateServer::pvExistTest() %s %s (new async ET)\n", real_name,pv->getStateName()); pv->addET(ctx); rc=pverAsyncCompletion; break; case gatePvInactive: case gatePvActive: gateDebug2(5,"gateServer::pvExistTest() %s %s ?\n", real_name,pv->getStateName()); rc=pverExistsHere; break; default: gateDebug2(5,"gateServer::pvExistTest() %s %s ?\n", real_name,pv->getStateName()); rc=pverDoesNotExistHere; break; } } #if DEBUG_DELAY if(rc.getStatus() == pverAsyncCompletion) { printf(" pverAsyncCompletion\n"); } else if(rc.getStatus() == pverExistsHere) { printf(" pverExistsHere\n"); } else if(rc.getStatus() == pverDoesNotExistHere) { printf(" pverDoesNotExistHere\n"); } else { printf(" Other return code\n"); }#endif#if DEBUG_HISTORY if(!strncmp(HISTNAME,pv->name(),HISTNUM)) { if(rc.getStatus() == pverAsyncCompletion) { printf(" pverAsyncCompletion\n"); } else if(rc.getStatus() == pverExistsHere) { printf(" pverExistsHere\n"); } else if(rc.getStatus() == pverDoesNotExistHere) { printf(" pverDoesNotExistHere\n"); } else { printf(" Other return code\n"); } }#endif #if DEBUG_FDMGR endTime=epicsTime::getCurrent(); cumTime+=(endTime-startTime);#endif return rc;}pvAttachReturn gateServer::pvAttach(const casCtx& /*c*/,const char* pvname){ gateDebug1(5,"gateServer::pvAttach() PV %s\n",pvname); gateVcData* rc; gateAsEntry* pEntry; char real_name[GATE_MAX_PVNAME_LENGTH]; // See if requested name is allowed and check for aliases. Uses // information in .pvlist, not .access. if ( !(pEntry = getAs()->findEntry(pvname)) ) { gateDebug1(2,"gateServer::pvAttach() called for denied PV %s " " - this should not happen!\n", pvname); return pvAttachReturn(S_casApp_pvNotFound); } pEntry->getRealName(pvname, real_name, sizeof(real_name));#if statCount // Trap (and create if needed) server stats PVs if(!strncmp(stat_prefix,real_name,stat_prefix_len)) { for(int i=0; i < statCount; i++) { if(strcmp(real_name,stat_table[i].pvName) == 0) { if(stat_table[i].pv == NULL) stat_table[i].pv=new gateStat(this,pEntry,real_name,i);#if DEBUG_DESC printf("gateServer::pvAttach: %s\n",stat_table[i].pv->getName());#endif return pvAttachReturn(*stat_table[i].pv); } if(strcmp(real_name,stat_table[i].descPvName) == 0) { if(stat_table[i].descPv == NULL) stat_table[i].descPv=new gateStatDesc(this,pEntry,real_name,i);#if DEBUG_DESC printf("gateServer::pvAttach: %s\n",stat_table[i].descPv->getName());#endif return pvAttachReturn(*stat_table[i].descPv); } } }#endif#if DEBUG_DELAY if(!strncmp("Xorbit",real_name,6)) { printf("%s gateServer::pvAttach: loop_count=%lu %s\n", timeStamp(),loop_count,real_name); }#endif // See if we have a gateVcData if(vcFind(real_name,rc) < 0) { // We don't have it, create a new one rc=new gateVcData(this,real_name); if(rc->getStatus()) { gateDebug1(5,"gateServer::pvAttach() bad PV %s\n",real_name); delete rc; rc=NULL; } }#if DEBUG_HISTORY if(!strncmp(HISTNAME,real_name,HISTNUM)) { printf("%s gateServer::pvAttach: loop_count=%lu %s %s\n", timeStamp(),loop_count, rc?"Found":"Not Found", real_name); }#endif return rc?pvCreateReturn(*rc):pvCreateReturn(S_casApp_pvNotFound);}#if statCount// Routines for gateway internal routinesvoid gateServer::setStat(int type, double val){ if(stat_table[type].pv) stat_table[type].pv->postData(val);#if DEBUG_SET_STAT > 1 printf("setStat(dbl): type=%d val=%g\n",type,val);#endif}void gateServer::setStat(int type, unsigned long val){ if(stat_table[type].pv) stat_table[type].pv->postData(val);#if DEBUG_SET_STAT printf("setStat(ul): type=%d val=%ld\n",type,val);#endif}caStatus gateServer::processStat(int type, double val){ caStatus retVal=S_casApp_success; switch(type) { case statCommandFlag: if(val > 0.0) command_flag=1; break; case statReport1Flag: if(val > 0.0) report1_flag=1; break; case statReport2Flag: if(val > 0.0) report2_flag=1; break; case statReport3Flag: if(val > 0.0) report3_flag=1; break; case statNewAsFlag: if(val > 0.0) newAs_flag=1; break; case statQuitFlag: if(val > 0.0) quit_flag=1; break; case statQuitServerFlag: if(val > 0.0) quitserver_flag=1; break; default: retVal=S_casApp_noSupport; break; } #if DEBUG_PROCESS_STAT print("gateServer::processStat:\n" "val=%.2f nCheck=%d nPrint=%d nSigma=%d nLimit=%.2f\n", val,nCheck,nPrint,nSigma,nLimit);#endif return retVal;}void gateServer::initStats(char *prefix){ int i; static unsigned long zero=0u; // Define the prefix for the server stats if(prefix) { // Use the specified one stat_prefix=prefix; } else { // Make one up stat_prefix=getComputerName(); if(!stat_prefix || !stat_prefix[0]) stat_prefix=strDup("gateway"); } stat_prefix_len=strlen(stat_prefix); // Set up PV names for server stats and fill them into the // stat_table. Note that initialization is to a pointer to the // value. The value may have changed before the stat pvs are // created. This allows the value at the time of creation to be // used. for(i=0; i < statCount; i++) { switch(i) {#ifdef STAT_PVS case statVcTotal: stat_table[i].name="vctotal"; stat_table[i].desc="Total VCs"; stat_table[i].init_value=&total_vc; stat_table[i].units=""; stat_table[i].precision=0; break; case statPvTotal: stat_table[i].name="pvtotal"; stat_table[i].desc="Total PVs"; stat_table[i].init_value=&total_pv; stat_table[i].units=""; stat_table[i].precision=0; break; case statAlive: stat_table[i].name="connected"; stat_table[i].desc="Connected PVs"; stat_table[i].init_value=&total_alive; stat_table[i].units=""; stat_table[i].precision=0; break; case statActive: stat_table[i].name="active"; stat_table[i].desc="Active PVs"; stat_table[i].init_value=&total_active; stat_table[i].units="";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -