Still original version
This commit is contained in:
+43
-24
@@ -52,6 +52,7 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
|
||||
* .01 03-22-94 mrk Initial Implementation
|
||||
*/
|
||||
|
||||
/*This module is separate from asDbLib because CA uses old database access*/
|
||||
#include <vxWorks.h>
|
||||
#include <taskLib.h>
|
||||
#include <string.h>
|
||||
@@ -59,6 +60,7 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <dbDefs.h>
|
||||
#include <taskwd.h>
|
||||
#include <asLib.h>
|
||||
#include <cadef.h>
|
||||
#include <caerr.h>
|
||||
@@ -77,36 +79,47 @@ typedef struct {
|
||||
evid evid;
|
||||
} CAPVT;
|
||||
|
||||
void connectCallback(struct connection_handler_args cha)
|
||||
static void connectCallback(struct connection_handler_args cha)
|
||||
{
|
||||
chid chid = cha.chid;
|
||||
ASGINP *pasginp = (ASGINP *)ca_puser(chid);
|
||||
ASG *pasg = (ASG *)pasginp->pasg;
|
||||
ASGINP *pasginp;
|
||||
ASG *pasg;
|
||||
CAPVT *pcapvt;
|
||||
enum channel_state state;
|
||||
int Ilocked=FALSE;
|
||||
|
||||
pasginp = (ASGINP *)ellFirst(&pasg->inpList);
|
||||
pcapvt = pasginp->capvt;
|
||||
if(ca_state(pcapvt->chid)!=cs_conn) {
|
||||
pasg->inpBad |= (1<<pasginp->inpIndex);
|
||||
if(!caInitializing) {
|
||||
FASTLOCK(&asLock);
|
||||
asComputeAsg(pasg);
|
||||
FASTUNLOCK(&asLock);
|
||||
}
|
||||
if(!caInitializing) {
|
||||
FASTLOCK(&asLock);
|
||||
Ilocked = TRUE;
|
||||
}
|
||||
pasginp = (ASGINP *)ca_puser(chid);
|
||||
pasg = (ASG *)pasginp->pasg;
|
||||
pcapvt = pasginp->capvt;
|
||||
if(ca_state(chid)!=cs_conn) {
|
||||
pasg->inpBad |= (1<<pasginp->inpIndex);
|
||||
if(!caInitializing) asComputeAsg(pasg);
|
||||
} /*eventCallback will set inpBad false*/
|
||||
if(Ilocked) FASTUNLOCK(&asLock);
|
||||
}
|
||||
|
||||
void eventCallback(struct event_handler_args eha)
|
||||
static void eventCallback(struct event_handler_args eha)
|
||||
{
|
||||
ASGINP *pasginp = (ASGINP *)eha.usr;
|
||||
CAPVT *pcapvt = (CAPVT *)pasginp->capvt;
|
||||
ASG *pasg = (ASG *)pasginp->pasg;
|
||||
ASGINP *pasginp;
|
||||
CAPVT *pcapvt;
|
||||
ASG *pasg;
|
||||
int inpOk=TRUE;
|
||||
enum channel_state state;
|
||||
struct dbr_sts_double *pdata = eha.dbr;
|
||||
int Ilocked=FALSE;
|
||||
|
||||
|
||||
if(!caInitializing) {
|
||||
FASTLOCK(&asLock);
|
||||
Ilocked = TRUE;
|
||||
}
|
||||
pasginp = (ASGINP *)eha.usr;
|
||||
pcapvt = (CAPVT *)pasginp->capvt;
|
||||
pasg = (ASG *)pasginp->pasg;
|
||||
pcapvt->rtndata = *pdata; /*structure copy*/
|
||||
if(pdata->severity==INVALID_ALARM) {
|
||||
pasg->inpBad |= (1<<pasginp->inpIndex);
|
||||
@@ -114,11 +127,9 @@ void eventCallback(struct event_handler_args eha)
|
||||
pasg->inpBad &= ~((1<<pasginp->inpIndex));
|
||||
pasg->pavalue[pasginp->inpIndex] = pdata->value;
|
||||
}
|
||||
if(!caInitializing) {
|
||||
FASTLOCK(&asLock);
|
||||
asComputeAsg(pasg);
|
||||
FASTUNLOCK(&asLock);
|
||||
}
|
||||
pasg->inpChanged |= (1<<pasginp->inpIndex);
|
||||
if(!caInitializing) asComputeAsg(pasg);
|
||||
if(Ilocked) FASTUNLOCK(&asLock);
|
||||
}
|
||||
|
||||
static void asCaTask(void)
|
||||
@@ -127,6 +138,7 @@ static void asCaTask(void)
|
||||
ASGINP *pasginp;
|
||||
CAPVT *pcapvt;
|
||||
|
||||
taskwdInsert(taskIdSelf(),NULL,NULL);
|
||||
SEVCHK(ca_task_initialize(),"ca_task_initialize");
|
||||
caInitializing = TRUE;
|
||||
pasg = (ASG *)ellFirst(&pasbase->asgList);
|
||||
@@ -145,19 +157,25 @@ static void asCaTask(void)
|
||||
}
|
||||
pasg = (ASG *)ellNext((ELLNODE *)pasg);
|
||||
}
|
||||
FASTLOCK(&asLock);
|
||||
asComputeAllAsg();
|
||||
caInitializing = FALSE;
|
||||
FASTUNLOCK(&asLock);
|
||||
SEVCHK(ca_pend_event(0.0),"ca_pend_event");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
void asCaStart(void)
|
||||
{
|
||||
taskid = taskSpawn("asCa",CA_CLIENT_PRI-1,VX_FP_TASK,CA_CLIENT_STACK,
|
||||
(FUNCPTR)asCaTask,0,0,0,0,0,0,0,0,0,0);
|
||||
if(taskid==ERROR) errMessage(0,"asCaStart: taskSpawn Failure\n");
|
||||
if(taskid==ERROR) {
|
||||
errMessage(0,"asCaStart: taskSpawn Failure\n");
|
||||
} else {
|
||||
taskDelay(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void asCaStop(void)
|
||||
{
|
||||
ASG *pasg;
|
||||
@@ -166,6 +184,7 @@ void asCaStop(void)
|
||||
STATUS status;
|
||||
|
||||
if(taskid==0 || taskid==ERROR) return;
|
||||
taskwdRemove(taskid);
|
||||
status = taskDelete(taskid);
|
||||
if(status!=OK) errMessage(0,"asCaStop: taskDelete Failure\n");
|
||||
while(taskIdVerify(taskid)==OK) {
|
||||
|
||||
+87
-22
@@ -59,6 +59,7 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dbDefs.h>
|
||||
#include <taskwd.h>
|
||||
#include <dbStaticLib.h>
|
||||
#include <asLib.h>
|
||||
#include <asDbLib.h>
|
||||
@@ -66,7 +67,7 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
|
||||
#include <recSup.h>
|
||||
#include <subRecord.h>
|
||||
#include <task_params.h>
|
||||
|
||||
|
||||
extern struct dbBase *pdbBase;
|
||||
static FILE *stream;
|
||||
|
||||
@@ -78,6 +79,7 @@ FAST_LOCK asLock;
|
||||
int asLockInit=TRUE;
|
||||
static int initTaskId=0;
|
||||
|
||||
|
||||
static int my_yyinput(char *buf, int max_size)
|
||||
{
|
||||
int l,n;
|
||||
@@ -118,7 +120,7 @@ static long asDbAddRecords(void)
|
||||
dbFinishEntry(pdbentry);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
int asSetFilename(char *acf)
|
||||
{
|
||||
if(asLockInit) {
|
||||
@@ -127,83 +129,137 @@ int asSetFilename(char *acf)
|
||||
}
|
||||
FASTLOCK(&asLock);
|
||||
if(pacf) free ((void *)pacf);
|
||||
pacf = calloc(1,strlen(acf)+1);
|
||||
if(!pacf) {
|
||||
errMessage(0,"asSetFilename calloc failure");
|
||||
FASTUNLOCK(&asLock);
|
||||
return(-1);
|
||||
if(acf) {
|
||||
pacf = calloc(1,strlen(acf)+1);
|
||||
if(!pacf) {
|
||||
errMessage(0,"asSetFilename calloc failure");
|
||||
} else {
|
||||
strcpy(pacf,acf);
|
||||
}
|
||||
} else {
|
||||
pacf = NULL;
|
||||
}
|
||||
strcpy(pacf,acf);
|
||||
FASTUNLOCK(&asLock);
|
||||
return(0);
|
||||
}
|
||||
|
||||
static void wdCallback(ASDBCALLBACK *pcallback)
|
||||
{
|
||||
pcallback->status = S_asLib_InitFailed;
|
||||
callbackRequest(&pcallback->callback);
|
||||
}
|
||||
|
||||
static void asInitTask(void)
|
||||
static void asInitTask(ASDBCALLBACK *pcallback)
|
||||
{
|
||||
long status;
|
||||
|
||||
taskwdInsert(taskIdSelf(),wdCallback,pcallback);
|
||||
if(asLockInit) {
|
||||
FASTLOCKINIT(&asLock);
|
||||
asLockInit = FALSE;
|
||||
}
|
||||
FASTLOCK(&asLock);
|
||||
asCaStop();
|
||||
my_buffer = calloc(1,BUF_SIZE);
|
||||
my_buffer_ptr = my_buffer;
|
||||
if(!my_buffer) {
|
||||
errMessage(0,"asInit malloc failure");
|
||||
FASTUNLOCK(&asLock);
|
||||
taskwdRemove(taskIdSelf());
|
||||
return;
|
||||
}
|
||||
stream = fopen(pacf,"r");
|
||||
if(!stream) {
|
||||
errMessage(0,"asInit failure");
|
||||
FASTUNLOCK(&asLock);
|
||||
taskwdRemove(taskIdSelf());
|
||||
return;
|
||||
}
|
||||
status = asInitialize(my_yyinput);
|
||||
if(fclose(stream)==EOF) errMessage(0,"asInit fclose failure");
|
||||
free((void *)my_buffer);
|
||||
asDbAddRecords();
|
||||
asCaStart();
|
||||
taskDelay(60);
|
||||
asComputeAllAsg();
|
||||
if(!status) {
|
||||
asCaStop();
|
||||
asDbAddRecords();
|
||||
asCaStart();
|
||||
}
|
||||
FASTUNLOCK(&asLock);
|
||||
if(pcallback) {
|
||||
pcallback->status = status;
|
||||
callbackRequest(&pcallback->callback);
|
||||
}
|
||||
taskwdRemove(taskIdSelf());
|
||||
initTaskId = 0;
|
||||
status = taskDelete(taskIdSelf());
|
||||
if(status!=OK) errMessage(0,"asInitTask: taskDelete Failure");
|
||||
}
|
||||
|
||||
int asInit(void)
|
||||
|
||||
int asInit(ASDBCALLBACK *pcallback)
|
||||
{
|
||||
long status;
|
||||
|
||||
if(!pacf) return(0);
|
||||
if(initTaskId) {
|
||||
errMessage(-1,"asInit: asInitTask already active");
|
||||
if(pcallback) {
|
||||
pcallback->status = S_asLib_InitFailed;
|
||||
callbackRequest(&pcallback->callback);
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
initTaskId = taskSpawn("asInitTask",CA_CLIENT_PRI-1,VX_FP_TASK,CA_CLIENT_STACK,
|
||||
(FUNCPTR)asInitTask,0,0,0,0,0,0,0,0,0,0);
|
||||
(FUNCPTR)asInitTask,(int)pcallback,0,0,0,0,0,0,0,0,0);
|
||||
if(initTaskId==ERROR) {
|
||||
errMessage(0,"asInit: taskSpawn Error");
|
||||
if(pcallback) {
|
||||
pcallback->status = S_asLib_InitFailed;
|
||||
callbackRequest(&pcallback->callback);
|
||||
}
|
||||
initTaskId = 0;
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*Interface to subroutine record*/
|
||||
static void myCallback(CALLBACK *pcallback)
|
||||
{
|
||||
ASDBCALLBACK *pasdbcallback = (ASDBCALLBACK *)pcallback;
|
||||
struct subRecord *precord;
|
||||
struct rset *prset;
|
||||
|
||||
callbackGetUser(precord,pcallback);
|
||||
prset=(struct rset *)(precord->rset);
|
||||
precord->val = 0.0;
|
||||
if(pasdbcallback->status) {
|
||||
recGblSetSevr(precord,READ_ALARM,INVALID_ALARM);
|
||||
recGblRecordError(pasdbcallback->status,precord,"asInit Failed");
|
||||
}
|
||||
dbScanLock((struct dbCommon *)precord);
|
||||
(*prset->process)((struct dbCommon *)precord);
|
||||
dbScanUnlock((struct dbCommon *)precord);
|
||||
}
|
||||
|
||||
long asSubInit(struct subRecord *precord,int pass)
|
||||
{
|
||||
ASDBCALLBACK *pcallback;
|
||||
|
||||
pcallback = (ASDBCALLBACK *)calloc(1,sizeof(ASDBCALLBACK));
|
||||
precord->dpvt = (void *)pcallback;
|
||||
callbackSetCallback(myCallback,&pcallback->callback);
|
||||
callbackSetUser(precord,&pcallback->callback);
|
||||
return(0);
|
||||
}
|
||||
|
||||
long asSubProcess(struct subRecord *precord)
|
||||
{
|
||||
if(precord->val!=1.0) return(0);
|
||||
asInit();
|
||||
db_post_events(precord,&precord->val,DBE_VALUE);
|
||||
precord->val=0.0;
|
||||
ASDBCALLBACK *pcallback = (ASDBCALLBACK *)precord->dpvt;
|
||||
|
||||
if(!precord->pact && precord->val==1.0) {
|
||||
db_post_events(precord,&precord->val,DBE_VALUE);
|
||||
callbackSetPriority(precord->prio,&pcallback->callback);
|
||||
asInit(pcallback);
|
||||
precord->pact=TRUE;
|
||||
return(1);
|
||||
}
|
||||
db_post_events(precord,&precord->val,DBE_VALUE);
|
||||
return(0);
|
||||
}
|
||||
@@ -226,6 +282,13 @@ ASMEMBERPVT asDbGetMemberPvt(void *paddress)
|
||||
return((ASMEMBERPVT)precord->asp);
|
||||
}
|
||||
|
||||
static void astacCallback(ASCLIENTPVT clientPvt,asClientStatus status)
|
||||
{
|
||||
printf("astac callback: status=%d",status);
|
||||
printf(" get %s put %s\n",(asCheckGet(clientPvt) ? "Yes" : "No"),
|
||||
(asCheckPut(clientPvt) ? "Yes" : "No"));
|
||||
}
|
||||
|
||||
int astac(char *pname,char *user,char *location)
|
||||
{
|
||||
struct dbAddr *paddr;
|
||||
@@ -248,12 +311,14 @@ int astac(char *pname,char *user,char *location)
|
||||
if(status) {
|
||||
errMessage(status,"asAddClient error");
|
||||
return(1);
|
||||
} else {
|
||||
asRegisterClientCallback(*pasclientpvt,astacCallback);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
static char *asAccessName[] = {"NONE","READ","WRITE"};
|
||||
void static myMemberCallback(ASMEMBERPVT memPvt)
|
||||
static void myMemberCallback(ASMEMBERPVT memPvt)
|
||||
{
|
||||
struct dbCommon *precord;
|
||||
|
||||
|
||||
+7
-2
@@ -3,6 +3,7 @@ static int yyerror();
|
||||
static int yy_start;
|
||||
static int myParse();
|
||||
#include "asLibRoutines.c"
|
||||
static int yyFailed = FALSE;
|
||||
static int line_num=1;
|
||||
static UAG *yyUag=NULL;
|
||||
static LAG *yyLag=NULL;
|
||||
@@ -217,18 +218,22 @@ static int yyerror(str)
|
||||
char *str;
|
||||
{
|
||||
fprintf(stderr,"Error line %d : %s %s\n",line_num,str,yytext);
|
||||
yyFailed = TRUE;
|
||||
return(0);
|
||||
}
|
||||
static int myParse(ASINPUTFUNCPTR inputfunction)
|
||||
{
|
||||
static int FirstFlag = 1;
|
||||
static int FirstFlag = 1;
|
||||
int rtnval;
|
||||
|
||||
my_yyinput = &inputfunction;
|
||||
if (!FirstFlag) {
|
||||
line_num=1;
|
||||
yyFailed = FALSE;
|
||||
yyreset(NULL);
|
||||
yyrestart(NULL);
|
||||
}
|
||||
FirstFlag = 0;
|
||||
return(yyparse());
|
||||
rtnval = yyparse();
|
||||
if(rtnval!=0 || yyFailed) return(-1); else return(0);
|
||||
}
|
||||
|
||||
+145
-100
@@ -58,6 +58,7 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <gpHash.h>
|
||||
#ifdef vxWorks
|
||||
#include <taskLib.h>
|
||||
#endif
|
||||
@@ -92,6 +93,11 @@ long asInitialize(ASINPUTFUNCPTR inputfunction)
|
||||
ASG *pasg;
|
||||
long status;
|
||||
ASBASE *pasbaseold;
|
||||
GPHENTRY *pgphentry;
|
||||
UAG *puag;
|
||||
UAGNAME *puagname;
|
||||
LAG *plag;
|
||||
LAGNAME *plagname;
|
||||
|
||||
pasbaseold = pasbase;
|
||||
pasbase = asCalloc(1,sizeof(ASBASE));
|
||||
@@ -106,12 +112,34 @@ long asInitialize(ASINPUTFUNCPTR inputfunction)
|
||||
pasbase = pasbaseold;
|
||||
return(status);
|
||||
}
|
||||
asActive = TRUE;
|
||||
pasg = (ASG *)ellFirst(&pasbase->asgList);
|
||||
while(pasg) {
|
||||
pasg->pavalue = asCalloc(ASMAXINP,sizeof(double));
|
||||
pasg = (ASG *)ellNext((ELLNODE *)pasg);
|
||||
}
|
||||
gphInitPvt(&pasbase->phash);
|
||||
/*Hash each uagname and each lagname*/
|
||||
puag = (UAG *)ellFirst(&pasbase->uagList);
|
||||
while(puag) {
|
||||
puagname = (UAGNAME *)ellFirst(&puag->list);
|
||||
while(puagname) {
|
||||
pgphentry = gphAdd(pasbase->phash,puagname->user,puag);
|
||||
if(!pgphentry) errMessage(-1,"asInitialize: gphAdd logic error");
|
||||
puagname = (UAGNAME *)ellNext((ELLNODE *)puagname);
|
||||
}
|
||||
puag = (UAG *)ellNext((ELLNODE *)puag);
|
||||
}
|
||||
plag = (LAG *)ellFirst(&pasbase->lagList);
|
||||
while(plag) {
|
||||
plagname = (LAGNAME *)ellFirst(&plag->list);
|
||||
while(plagname) {
|
||||
pgphentry = gphAdd(pasbase->phash,plagname->location,plag);
|
||||
if(!pgphentry) errMessage(-1,"asInitialize: gphAdd logic error");
|
||||
plagname = (LAGNAME *)ellNext((ELLNODE *)plagname);
|
||||
}
|
||||
plag = (LAG *)ellNext((ELLNODE *)plag);
|
||||
}
|
||||
asActive = TRUE;
|
||||
if(pasbaseold) {
|
||||
ASG *poldasg;
|
||||
ASGMEMBER *poldmem;
|
||||
@@ -137,6 +165,7 @@ long asAddMember(ASMEMBERPVT *pasMemberPvt,char *asgName)
|
||||
{
|
||||
ASGMEMBER *pasgmember;
|
||||
ASG *pgroup;
|
||||
ASGCLIENT *pclient;
|
||||
long status;
|
||||
|
||||
if(!asActive) return(0);
|
||||
@@ -188,7 +217,6 @@ long asRemoveMember(ASMEMBERPVT *asMemberPvt)
|
||||
long asChangeGroup(ASMEMBERPVT *asMemberPvt,char *newAsgName)
|
||||
{
|
||||
ASGMEMBER *pasgmember;
|
||||
ASGCLIENT *pclient;
|
||||
long status;
|
||||
|
||||
if(!asActive) return(0);
|
||||
@@ -206,14 +234,6 @@ long asChangeGroup(ASMEMBERPVT *asMemberPvt,char *newAsgName)
|
||||
exit(-1);
|
||||
}
|
||||
status = asAddMember(asMemberPvt,newAsgName);
|
||||
pclient = (ASGCLIENT *)ellFirst(&pasgmember->clientList);
|
||||
while(pclient) {
|
||||
status = asCompute(pclient);
|
||||
if(status) {
|
||||
errMessage(status,"asAddMember");
|
||||
}
|
||||
pclient = (ASGCLIENT *)ellNext((ELLNODE *)pclient);
|
||||
}
|
||||
#ifdef vxWorks
|
||||
FASTUNLOCK(&asLock);
|
||||
#endif
|
||||
@@ -306,6 +326,14 @@ long asRemoveClient(ASCLIENTPVT *asClientPvt)
|
||||
*asClientPvt = NULL;
|
||||
return(0);
|
||||
}
|
||||
|
||||
void asRegisterClientCallback(ASCLIENTPVT asClientPvt,
|
||||
ASCLIENTCALLBACK pcallback)
|
||||
{
|
||||
ASGCLIENT *pasclient = asClientPvt;
|
||||
|
||||
pasclient->pcallback = pcallback;
|
||||
}
|
||||
|
||||
void *asGetClientPvt(ASCLIENTPVT asClientPvt)
|
||||
{
|
||||
@@ -323,7 +351,7 @@ void asPutClientPvt(ASCLIENTPVT asClientPvt,void *userPvt)
|
||||
if(!pasclient) return;
|
||||
pasclient->userPvt = userPvt;
|
||||
}
|
||||
|
||||
|
||||
long asComputeAllAsg(void)
|
||||
{
|
||||
ASG *pasg;
|
||||
@@ -338,10 +366,28 @@ long asComputeAllAsg(void)
|
||||
|
||||
long asComputeAsg(ASG *pasg)
|
||||
{
|
||||
ASGLEVEL *pasglevel;
|
||||
ASGMEMBER *pasgmember;
|
||||
ASGCLIENT *pasgclient;
|
||||
|
||||
if(!asActive) return(0);
|
||||
pasglevel = (ASGLEVEL *)ellFirst(&pasg->levelList);
|
||||
while(pasglevel) {
|
||||
double result;
|
||||
long status;
|
||||
|
||||
if(pasglevel->calc && (pasg->inpChanged & pasglevel->inpUsed)) {
|
||||
status = calcPerform(pasg->pavalue,&result,pasglevel->rpcl);
|
||||
if(status) {
|
||||
pasglevel->result = 0;
|
||||
errMessage(status,"asComputeAsg");
|
||||
} else {
|
||||
pasglevel->result = ((result>.99) && (result<1.01)) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
pasglevel = (ASGLEVEL *)ellNext((ELLNODE *)pasglevel);
|
||||
}
|
||||
pasg->inpChanged = FALSE;
|
||||
pasgmember = (ASGMEMBER *)ellFirst(&pasg->memberList);
|
||||
while(pasgmember) {
|
||||
pasgclient = (ASGCLIENT *)ellFirst(&pasgmember->clientList);
|
||||
@@ -360,87 +406,64 @@ long asCompute(ASCLIENTPVT asClientPvt)
|
||||
ASGMEMBER *pasgMember = pasgClient->pasgMember;
|
||||
ASG *pasg = pasgMember->pasg;
|
||||
ASGLEVEL *pasglevel;
|
||||
double result;
|
||||
long status;
|
||||
asAccessRights oldaccess=pasgClient->access;
|
||||
GPHENTRY *pgphentry;
|
||||
|
||||
if(!pasg) return(0);
|
||||
while(TRUE) {
|
||||
pasglevel = (ASGLEVEL *)ellFirst(&pasg->levelList);
|
||||
while(pasglevel) {
|
||||
if(access == asWRITE) break;
|
||||
if(access>=pasglevel->access) goto next_level;
|
||||
if(pasgClient->level > pasglevel->level) goto next_level;
|
||||
/*if uagList is empty then no need to check uag*/
|
||||
if(ellCount(&pasglevel->uagList)>0){
|
||||
ASGUAG *pasguag;
|
||||
UAG *puag;
|
||||
UAGNAME *puagname;
|
||||
|
||||
pasguag = (ASGUAG *)ellFirst(&pasglevel->uagList);
|
||||
while(pasguag) {
|
||||
if(puag = pasguag->puag) {
|
||||
puagname = (UAGNAME *)ellFirst(&puag->list);
|
||||
while(puagname) {
|
||||
if(strcmp(pasgClient->user,puagname->user)==0)
|
||||
goto check_lag;
|
||||
puagname = (UAGNAME *)ellNext((ELLNODE *)puagname);
|
||||
}
|
||||
}
|
||||
pasguag = (ASGUAG *)ellNext((ELLNODE *)pasguag);
|
||||
}
|
||||
goto next_level;
|
||||
}
|
||||
check_lag:
|
||||
/*if lagList is empty then no need to check lag*/
|
||||
if(ellCount(&pasglevel->lagList)>0) {
|
||||
ASGLAG *pasglag;
|
||||
LAG *plag;
|
||||
LAGNAME *plagname;
|
||||
|
||||
pasglag = (ASGLAG *)ellFirst(&pasglevel->lagList);
|
||||
while(pasglag) {
|
||||
if(plag = pasglag->plag) {
|
||||
plagname = (LAGNAME *)ellFirst(&plag->list);
|
||||
while(plagname) {
|
||||
if(strcmp(pasgClient->location,plagname->location)==0)
|
||||
goto check_calc;
|
||||
plagname = (LAGNAME *)ellNext((ELLNODE *)plagname);
|
||||
}
|
||||
}
|
||||
pasglag = (ASGLAG *)ellNext((ELLNODE *)pasglag);
|
||||
}
|
||||
goto next_level;
|
||||
}
|
||||
check_calc:
|
||||
if(!pasglevel->calc) {
|
||||
access = pasglevel->access;
|
||||
goto next_level;
|
||||
} else {/*If any INP used in calc is bad NO_ACCESS*/
|
||||
if(pasg->inpBad & pasglevel->inpUsed) goto next_level;
|
||||
}
|
||||
status = calcPerform(pasg->pavalue,&result,pasglevel->rpcl);
|
||||
if(!status && result==1e0) access = pasglevel->access;
|
||||
next_level:
|
||||
pasglevel = (ASGLEVEL *)ellNext((ELLNODE *)pasglevel);
|
||||
}
|
||||
/*Also check DEFAULT*/
|
||||
pasglevel = (ASGLEVEL *)ellFirst(&pasg->levelList);
|
||||
while(pasglevel) {
|
||||
if(access == asWRITE) break;
|
||||
if(strcmp(pasg->name,DEFAULT)==0) break;
|
||||
pasg = (ASG *)ellFirst(&pasbase->asgList);
|
||||
while(pasg) {
|
||||
if(strcmp(pasg->name,DEFAULT)==0) goto again;
|
||||
pasg = (ASG *)ellNext((ELLNODE *)pasg);
|
||||
if(access>=pasglevel->access) goto next_level;
|
||||
if(pasgClient->level > pasglevel->level) goto next_level;
|
||||
/*if uagList is empty then no need to check uag*/
|
||||
if(ellCount(&pasglevel->uagList)>0){
|
||||
ASGUAG *pasguag;
|
||||
UAG *puag;
|
||||
UAGNAME *puagname;
|
||||
|
||||
pasguag = (ASGUAG *)ellFirst(&pasglevel->uagList);
|
||||
while(pasguag) {
|
||||
if(puag = pasguag->puag) {
|
||||
pgphentry = gphFind(pasbase->phash,pasgClient->user,puag);
|
||||
if(pgphentry) goto check_lag;
|
||||
}
|
||||
pasguag = (ASGUAG *)ellNext((ELLNODE *)pasguag);
|
||||
}
|
||||
goto next_level;
|
||||
}
|
||||
errMessage(-1,"Logic Error in asCompute");
|
||||
break;
|
||||
again:
|
||||
continue;
|
||||
check_lag:
|
||||
/*if lagList is empty then no need to check lag*/
|
||||
if(ellCount(&pasglevel->lagList)>0) {
|
||||
ASGLAG *pasglag;
|
||||
LAG *plag;
|
||||
LAGNAME *plagname;
|
||||
|
||||
pasglag = (ASGLAG *)ellFirst(&pasglevel->lagList);
|
||||
while(pasglag) {
|
||||
if(plag = pasglag->plag) {
|
||||
pgphentry=gphFind(pasbase->phash,pasgClient->location,plag);
|
||||
if(pgphentry) goto check_calc;
|
||||
}
|
||||
pasglag = (ASGLAG *)ellNext((ELLNODE *)pasglag);
|
||||
}
|
||||
goto next_level;
|
||||
}
|
||||
check_calc:
|
||||
if(!pasglevel->calc
|
||||
|| (!(pasg->inpBad & pasglevel->inpUsed) && (pasglevel->result==1)))
|
||||
access = pasglevel->access;
|
||||
next_level:
|
||||
pasglevel = (ASGLEVEL *)ellNext((ELLNODE *)pasglevel);
|
||||
}
|
||||
pasgClient->access = access;
|
||||
if(pasgClient->pcallback && oldaccess!=access) {
|
||||
(*pasgClient->pcallback)(pasgClient,asClientCOAR);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
static char *asAccessName[] = {"NONE","READ","WRITE"};
|
||||
static char *asLevelName[] = {"ASL0","ASL1"};
|
||||
int asDump(
|
||||
void (*memcallback)(struct asgMember *),
|
||||
void (*clientcallback)(struct asgClient *),
|
||||
@@ -501,14 +524,14 @@ int asDump(
|
||||
print_end_brace = FALSE;
|
||||
}
|
||||
while(pasginp) {
|
||||
int bad;
|
||||
double value;
|
||||
|
||||
printf("\tINP%c(%s)",(pasginp->inpIndex + 'A'),pasginp->inp);
|
||||
if(verbose) {
|
||||
value = pasg->pavalue[pasginp->inpIndex];
|
||||
bad = (pasg->inpBad & (1<<pasginp->inpIndex)) ? 1 : 0;
|
||||
printf(" Bad=%d value=%f",bad,value);
|
||||
if((pasg->inpBad & (1<<pasginp->inpIndex)))
|
||||
printf(" INVALID");
|
||||
else
|
||||
printf(" VALID");
|
||||
printf(" value=%f",pasg->pavalue[pasginp->inpIndex]);
|
||||
}
|
||||
printf("\n");
|
||||
pasginp = (ASGINP *)ellNext((ELLNODE *)pasginp);
|
||||
@@ -540,11 +563,17 @@ int asDump(
|
||||
pasglag = (ASGLAG *)ellNext((ELLNODE *)pasglag);
|
||||
if(pasglag) printf(","); else printf(")\n");
|
||||
}
|
||||
if(pasglevel->calc) printf("\t\tCALC(\"%s\")\n",pasglevel->calc);
|
||||
if(pasglevel->calc) {
|
||||
printf("\t\tCALC(\"%s\")",pasglevel->calc);
|
||||
if(verbose)
|
||||
printf(" result=%s",(pasglevel->result ? "TRUE" : "FALSE"));
|
||||
printf("\n");
|
||||
}
|
||||
if(print_end_brace) printf("\t}\n");
|
||||
pasglevel = (ASGLEVEL *)ellNext((ELLNODE *)pasglevel);
|
||||
}
|
||||
pasgmember = (ASGMEMBER *)ellFirst(&pasg->memberList);
|
||||
if(!verbose) pasgmember = NULL;
|
||||
if(pasgmember) printf("\tMEMBERLIST\n");
|
||||
while(pasgmember) {
|
||||
if(strlen(pasgmember->asgName)==0)
|
||||
@@ -555,9 +584,15 @@ int asDump(
|
||||
printf("\n");
|
||||
pasgclient = (ASGCLIENT *)ellFirst(&pasgmember->clientList);
|
||||
while(pasgclient) {
|
||||
printf("\t\t\t %s %s %d %d",
|
||||
pasgclient->user,pasgclient->location,
|
||||
pasgclient->level,pasgclient->access);
|
||||
printf("\t\t\t %s %s",pasgclient->user,pasgclient->location);
|
||||
if(pasgclient->level>=0 && pasgclient->level<=1)
|
||||
printf(" %s",asLevelName[pasgclient->level]);
|
||||
else
|
||||
printf(" Illegal Level %d",pasgclient->level);
|
||||
if(pasgclient->access>=0 && pasgclient->access<=2)
|
||||
printf(" %s",asAccessName[pasgclient->access]);
|
||||
else
|
||||
printf(" Illegal Access %d",pasgclient->access);
|
||||
if(clientcallback) clientcallback(pasgclient);
|
||||
printf("\n");
|
||||
pasgclient = (ASGCLIENT *)ellNext((ELLNODE *)pasgclient);
|
||||
@@ -651,13 +686,10 @@ int asDumpLev(char *asgname)
|
||||
print_end_brace = FALSE;
|
||||
}
|
||||
while(pasginp) {
|
||||
int bad;
|
||||
double value;
|
||||
|
||||
printf("\tINP%c(%s)",(pasginp->inpIndex + 'A'),pasginp->inp);
|
||||
value = pasg->pavalue[pasginp->inpIndex];
|
||||
bad = (pasg->inpBad & (1<<pasginp->inpIndex)) ? 1 : 0;
|
||||
printf(" Bad=%d value=%f",bad,value);
|
||||
if((pasg->inpBad & (1<<pasginp->inpIndex))) printf(" INVALID");
|
||||
printf(" value=%f",pasg->pavalue[pasginp->inpIndex]);
|
||||
printf("\n");
|
||||
pasginp = (ASGINP *)ellNext((ELLNODE *)pasginp);
|
||||
}
|
||||
@@ -688,7 +720,11 @@ int asDumpLev(char *asgname)
|
||||
pasglag = (ASGLAG *)ellNext((ELLNODE *)pasglag);
|
||||
if(pasglag) printf(","); else printf(")\n");
|
||||
}
|
||||
if(pasglevel->calc) printf("\t\tCALC(\"%s\")\n",pasglevel->calc);
|
||||
if(pasglevel->calc) {
|
||||
printf("\t\tCALC(\"%s\")",pasglevel->calc);
|
||||
printf(" result=%s",(pasglevel->result ? "TRUE" : "FALSE"));
|
||||
printf("\n");
|
||||
}
|
||||
if(print_end_brace) printf("\t}\n");
|
||||
pasglevel = (ASGLEVEL *)ellNext((ELLNODE *)pasglevel);
|
||||
}
|
||||
@@ -727,9 +763,16 @@ int asDumpMem(char *asgname,void (*memcallback)(ASMEMBERPVT),int clients)
|
||||
pasgclient = (ASGCLIENT *)ellFirst(&pasgmember->clientList);
|
||||
if(!clients) pasgclient = NULL;
|
||||
while(pasgclient) {
|
||||
printf("\t\t\t %s %s %d %d",
|
||||
pasgclient->user,pasgclient->location,
|
||||
pasgclient->level,pasgclient->access);
|
||||
printf("\t\t\t %s %s",
|
||||
pasgclient->user,pasgclient->location);
|
||||
if(pasgclient->level>=0 && pasgclient->level<=1)
|
||||
printf(" %s",asLevelName[pasgclient->level]);
|
||||
else
|
||||
printf(" Illegal Level %d",pasgclient->level);
|
||||
if(pasgclient->access>=0 && pasgclient->access<=2)
|
||||
printf(" %s",asAccessName[pasgclient->access]);
|
||||
else
|
||||
printf(" Illegal Access %d",pasgclient->access);
|
||||
printf("\n");
|
||||
pasgclient = (ASGCLIENT *)ellNext((ELLNODE *)pasgclient);
|
||||
}
|
||||
@@ -834,6 +877,7 @@ static void asFreeAll(ASBASE *pasbase)
|
||||
free((void *)pasg);
|
||||
pasg = pnext;
|
||||
}
|
||||
gphFreeMem(pasbase->phash);
|
||||
free((void *)pasbase);
|
||||
}
|
||||
|
||||
@@ -1050,6 +1094,7 @@ static long asAsgLevelCalc(ASGLEVEL *pasglevel,char *calc)
|
||||
|
||||
for(i=0; i<ASMAXINP; i++) {
|
||||
if(strchr(calc,'A'+i)) pasglevel->inpUsed |= (1<<i);
|
||||
if(strchr(calc,'a'+i)) pasglevel->inpUsed |= (1<<i);
|
||||
}
|
||||
}
|
||||
return(status);
|
||||
|
||||
Reference in New Issue
Block a user