⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gateserver.cc

📁 EPICS CA gateway, base on channel access protocol
💻 CC
📖 第 1 页 / 共 5 页
字号:
{	gateAsEntry *pEntry;	int i;#if DEBUG_ACCESS	printf("gateServer::newAs pv_list: %d con_list: %d\n",	  (int)pv_list.count(),(int)pv_con_list.count());	int count=0;#endif		// We need to eliminate all the members (gateAsEntry's) and	// clients (gateAsClient's).  The clients must be removed before	// the members can be.  This has to be done because the base	// access security assumes the members (PVs in an IOC) do not	// change and asInitialize copies the old members back into the	// new ASBASE.  Out members do change.	// gatePVData's, gateVCData's, and gateChan's have pointers to	// gateAsEntry's and gateChan's have gateAsClient's.  First NULL	// the pointers and delete the gateAsClients.  These items are in	// the pv_list, pv_con_list, and statTable array.	//  Treat the pv_list and pv_con_list the same way.  i=0 is	// pv_list and i=1 is the pv_con_list.	for(i=0; i < 2; i++) {		tsDLHashList<gatePvNode> *list;		if(i == 0) list=&pv_list;		else list=&pv_con_list;		tsDLIter<gatePvNode> iter=list->firstIter();		while(iter.valid())	{			gatePvNode *pNode=iter.pointer();			gatePvData *pv=pNode->getData();			// NULL the entry			pv->removeEntry();			// NULL the entry in the gateVcData and its channels and			// delete the gateAsClients			gateVcData *vc=pv->VC();			if(vc) {				vc->removeEntry();			}			iter++;		}	}#if statCount	// Do the statTable	for(i=0; i < statCount; i++) {		// See if the pv has been created		if(!stat_table[i].pv) {#if DEBUG_ACCESS			printf("  i=%d No pv for %s\n",i,stat_table[i].name);#endif			}  else {			// NULL the entry in the gateStat and its channels and delete			// the gateAsClients#if DEBUG_ACCESS			printf("  i=%d %s %s\n",i,			  stat_table[i].name,stat_table[i].pv->getName());#endif			stat_table[i].pv->removeEntry();		}		// See if the desc pv has been created		if(!stat_table[i].descPv) {#if DEBUG_ACCESS			printf("  i=%d No descPv for %s\n",i,stat_table[i].name);#endif			}  else {			// NULL the entry in the gateStat and its channels and delete			// the gateAsClients#if DEBUG_ACCESS			printf("  i=%d %s %s\n",i,			  stat_table[i].name,stat_table[i].descPv->getName());#endif			stat_table[i].descPv->removeEntry();		}	}#endif // #if statCount	// Reinitialize access security	long rc=as->reInitialize(global_resources->accessFile(),	  global_resources->listFile());	if(rc) {		printf("%s gateServer::newAs Failed to remove old entries\n",		  timeStamp());		printf("  Suggest restarting this Gateway\n");	}	// Now check the access and reinstall all the gateAsEntry's and	// gateAsClient's.  Remove the PVs if they are now DENY'ed.	// pv_list and pv_con_list	for(i=0; i < 2; i++) {		tsDLHashList<gatePvNode> *list;		if(i == 0) list=&pv_list;		else list=&pv_con_list;		tsDLIter<gatePvNode> iter=list->firstIter();		while(iter.valid())	{			gatePvNode *pNode=iter.pointer();			gatePvData *pv=pNode->getData();			tsDLIter<gatePvNode> tmpIter = iter;			tmpIter++;			#if DEBUG_ACCESS			printf("  i=%d count=%d %s\n",i,count,pv->name()?pv->name():"NULL");#endif				// See if it is allowed			pEntry=getAs()->findEntry(pv->name());			if(!pEntry) {#if DEBUG_ACCESS				printf("    Not allowed\n");#endif					// Denied, kill it (handles statistics) then remove it				// now, rather than leaving it for inactiveDeadCleanup				pv->death();				int status=list->remove(pv->name(),pNode);				if(status) printf("%s gateServer::newAs: "				  "Could not remove denied pv: %s.\n",timeStamp(),pv->name());				pNode->destroy();			} else {#if DEBUG_ACCESS				printf("    Allowed\n");#endif					// Allowed, replace gateAsEntry				pv->resetEntry(pEntry);				// Replace the entry in the gateVcData and its channels				gateVcData *vc=pv->VC();				if(vc) {					vc->resetEntry(pEntry);				}			}			iter=tmpIter;		}	}#if statCount	// Do internal PVs.	for(i=0; i < statCount; i++) {		// See if the pv has been created		if(!stat_table[i].pv) {#if DEBUG_ACCESS			printf("  i=%d No pv for %s\n",i,stat_table[i].name);#endif			} else {			// Replace the entry in the gateStat and its channels#if DEBUG_ACCESS			printf("  i=%d %s %s\n",i,			  stat_table[i].name,stat_table[i].pv->getName());#endif			pEntry=getAs()->findEntry(stat_table[i].pv->getName());			if(!pEntry) {				// Denied, uncreate it				delete stat_table[i].pv;				stat_table[i].pv=NULL;			} else {				// Allowed, replace gateAsEntry				stat_table[i].pv->resetEntry(pEntry);			}		}		// See if the desc pv has been created		if(!stat_table[i].descPv) {#if DEBUG_ACCESS			printf("  i=%d No descPv for %s\n",i,stat_table[i].name);#endif			} else {			// Replace the entry in the gateStat and its channels#if DEBUG_ACCESS			printf("  i=%d %s %s\n",i,			  stat_table[i].name,stat_table[i].descPv->getName());#endif			pEntry=getAs()->findEntry(stat_table[i].descPv->getName());			if(!pEntry) {				// Denied, uncreate it				delete stat_table[i].descPv;				stat_table[i].descPv=NULL;			} else {				// Allowed, replace gateAsEntry				stat_table[i].descPv->resetEntry(pEntry);			}		}	}#endif // #if statCount	// Generate a beacon anomaly since new PVs may have become	// available	generateBeaconAnomaly();}void gateServer::report1(void){	FILE* fp;	time_t t;	printf("%s Starting Report1 (Active Virtual Connection Report)\n",	  timeStamp());	time(&t);	// Open the report file	const char *filename=global_resources->reportFile();	if(!filename || !*filename || !strcmp(filename,"NULL")) {		printf("  Report1: Bad report filename\n");		return;	}#ifdef RESERVE_FOPEN_FD	fp=global_resources->fopen(filename,"a");#else	fp=fopen(filename,"a");#endif	if(!fp) {		printf("  Report1: Cannot open %s for appending\n",filename);		return;	}	fprintf(fp,"---------------------------------------"	  "------------------------------------\n"	  "Active Virtual Connection Report: %s",ctime(&t));#if statCount	// Stat PVs	for(int i=0; i < statCount; i++) {		if(stat_table[i].pv) stat_table[i].pv->report(fp);		if(stat_table[i].descPv) stat_table[i].descPv->report(fp);	}#endif	// Virtual PVs	tsDLIter<gateVcData> iter=vc_list.firstIter();	while(iter.valid()) {		iter->report(fp);		iter++;	}	fprintf(fp,"---------------------------------------"	  "------------------------------------\n");#ifdef RESERVE_FOPEN_FD	global_resources->fclose(fp);#else	fclose(fp);#endif		printf("  Report1 written to %s\n",filename);}void gateServer::report2(void){	FILE* fp;	gatePvData *pv;	gateStat *pStat;	gateAsEntry *pEntry;	time_t t,diff;	double rate;	int tot_dead=0,tot_inactive=0,tot_active=0,tot_connect=0,tot_disconnect=0;	int tot_stat=0, tot_stat_desc=0;	printf("%s Starting Report2 (PV Summary Report)\n",	  timeStamp());	time(&t);	diff=t-start_time;	rate=diff?(double)exist_count/(double)diff:0;	// Open the report file	const char *filename=global_resources->reportFile();	if(!filename || !*filename || !strcmp(filename,"NULL")) {		printf("  Report2: Bad report filename\n");		return;	}#ifdef RESERVE_FOPEN_FD	fp=global_resources->fopen(filename,"a");#else	fp=fopen(filename,"a");#endif	if(!fp) {		printf("  Report2: Cannot open %s for appending\n",filename);		return;	}	fprintf(fp,"---------------------------------------"	  "------------------------------------\n");	fprintf(fp,"PV Summary Report: %s\n",ctime(&t));	fprintf(fp,"Exist test rate = %f\n",rate);	fprintf(fp,"Total real PV count = %d\n",(int)pv_list.count());	fprintf(fp,"Total virtual PV count = %d\n",(int)vc_list.count());	fprintf(fp,"Total connecting PV count = %d\n",(int)pv_con_list.count());	tsDLIter<gatePvNode> iter=pv_list.firstIter();	while(iter.valid())	{		switch(iter->getData()->getState())		{		case gatePvDead: tot_dead++; break;		case gatePvInactive: tot_inactive++; break;		case gatePvActive: tot_active++; break;		case gatePvConnect: tot_connect++; break;		case gatePvDisconnect: tot_disconnect++; break;		}		iter++;	}	fprintf(fp,"Total connecting PVs: %d\n",tot_connect);	fprintf(fp,"Total dead PVs: %d\n",tot_dead);	fprintf(fp,"Total disconnected PVs: %d\n",tot_disconnect);	fprintf(fp,"Total inactive PVs: %d\n",tot_inactive);	fprintf(fp,"Total active PVs: %d\n",tot_active);#if statCount	tot_stat=tot_stat_desc=0;	for(int i=0; i < statCount; i++) if(stat_table[i].pv) tot_stat++;	for(int i=0; i < statCount; i++) if(stat_table[i].descPv) tot_stat_desc++;	fprintf(fp,"Total active stat PVs: %d [of %d]\n",tot_stat,statCount);	fprintf(fp,"Total active stat DESC PVs: %d [of %d]\n",tot_stat_desc,	  statCount);	fprintf(fp,"\nInternal PVs [INT]:\n"	  " State Name                            Group        Level Pattern\n");	// Stat PVs	for(int i=0; i < statCount; i++) {		pStat=stat_table[i].pv;		if(pStat && pStat->getName()) {			fprintf(fp," INT %-33s",pStat->getName());			pEntry=pStat->getEntry();			if(pEntry) {				fprintf(fp," %-16s %d %s\n",				  pEntry->group?pEntry->group:"None",				  pEntry->level,				  pEntry->pattern?pEntry->pattern:"None");			} else {				fprintf(fp,"\n");							}		}	}	// Stat PV DESCs	for(int i=0; i < statCount; i++) {		pStat=stat_table[i].descPv;		if(pStat && pStat->getName()) {			fprintf(fp," INT %-33s",pStat->getName());			pEntry=pStat->getEntry();			if(pEntry) {				fprintf(fp," %-16s %d %s\n",				  pEntry->group?pEntry->group:"None",				  pEntry->level,				  pEntry->pattern?pEntry->pattern:"None");			} else {				fprintf(fp,"\n");			}		}	}#endif	fprintf(fp,"\nConnecting PVs [CON]:\n"	  " State Name                            Time         Group        Level Pattern\n");	iter=pv_list.firstIter();	while(iter.valid())	{		pv=iter->getData();		if(pv && pv->getState() == gatePvConnect && pv->name()) {			fprintf(fp," CON %-33s %s",pv->name(),			  timeString(pv->timeConnecting()));			pEntry=pv->getEntry();			if(pEntry) {				fprintf(fp," %-16s %d %s\n",				  pEntry->group?pEntry->group:"None",				  pEntry->level,				  pEntry->pattern?pEntry->pattern:"None");			} else {				fprintf(fp,"\n");			}		}		iter++;	}		fprintf(fp,"\nDead PVs [DEA]:\n"	  " State Name                            Time         Group        Level Pattern\n");	iter=pv_list.firstIter();	while(iter.valid())	{		pv=iter->getData();		if(pv && pv->getState() == gatePvDead && pv->name()) {			fprintf(fp," DEA %-33s %s",pv->name(),			  timeString(pv->timeDead()));			pEntry=pv->getEntry();			if(pEntry) {				fprintf(fp," %-16s %d %s\n",				  pEntry->group?pEntry->group:"None",				  pEntry->level,				  pEntry->pattern?pEntry->pattern:"None");			} else {				fprintf(fp,"\n");			}		}		iter++;	}	fprintf(fp,"\nDisconnected PVs [DIS]:\n"	  " State Name                            Time         Group        Level Pattern\n");	iter=pv_list.firstIter();	while(iter.valid())	{		pv=iter->getData();		if(pv &&  pv->getState() == gatePvDisconnect &&pv->name()) {			fprintf(fp," DIS %-33s %s",pv->name(),			  timeString(pv->timeDisconnected()));			pEntry=pv->getEntry();			if(pEntry) {				fprintf(fp," %-16s %d %s\n",				  pEntry->group?pEntry->group:"None",				  pEntry->level,				  pEntry->pattern?pEntry->pattern:"None");			} else {				fprintf(fp,"\n");			}		}		iter++;	}	fprintf(fp,"\nInactive PVs [INA]:\n"	  " State Name                            Time         Group        Level Pattern\n");	iter=pv_list.firstIter();	while(iter.valid())	{		pv=iter->getData();		if(pv && pv->getState() == gatePvInactive && pv->name()) {			fprintf(fp," INA %-33s %s",pv->name(),			  timeString(pv->timeInactive()));			pEntry=pv->getEntry();			if(pEntry) {				fprintf(fp," %-16s %d %s\n",				  pEntry->group?pEntry->group:"None",				  pEntry->level,				  pEntry->pattern?pEntry->pattern:"None");			} else {				fprintf(fp,"\n");			}		}		iter++;	}	fprintf(fp,"\nActive PVs [ACT]:\n"	  " State Name                            Time         Group        Level Pattern\n");	iter=pv_list.firstIter();	while(iter.valid())	{		pv=iter->getData();		if(pv && pv->getState() == gatePvActive && pv->name()) {			fprintf(fp," ACT %-33s %s",pv->name(),			  timeString(pv->timeActive()));			pEntry=pv->getEntry();			if(pEntry) {				fprintf(fp," %-16s %d %s\n",				  pEntry->group?pEntry->group:"None",				  pEntry->level,				  pEntry->pattern?pEntry->pattern:"None");			} else {				fprintf(fp,"\n");			}		}		iter++;	}	fprintf(fp,"---------------------------------------"	  "------------------------------------\n");#ifdef RESERVE_FOPEN_FD	global_resources->fclose(fp);#else	fclose(fp);#endif		printf("  Report2 written to %s\n",filename);}void gateServer::report3(void){	FILE* fp;	printf("%s Starting Report3 (Access Security Report)\n",	  timeStamp());	// Open the report file	const char *filename=global_resources->reportFile();	if(!filename || !*filename || !strcmp(filename,"NULL")) {		printf("  Report3: Bad report filename\n");		return;	}#ifdef RESERVE_FOPEN_FD

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -