static sAttribute * findAttribute ( sObject *op, pwr_sAttrRef *aref, pwr_tClassId cid ) { LstLink(sAttribute) *al; sAttribute *ap = NULL; for (al = LstFir(&op->attr_l); al != LstEnd(&op->attr_l); al = LstNex(al)) { if (aref->Offset == LstObj(al)->aref.Offset) { ap = LstObj(al); break; } } if (ap == NULL) { ap = (sAttribute *)calloc(1, sizeof(*ap)); if (ap == NULL) exit(2); LstIni(&ap->attr_l); LstIni(&ap->sup_l); (void)LstIns(&op->attr_l, ap, attr_l); op->attr_c++; ap->cid = cid; ap->aref = *aref; } return ap; }
static void WriteFacility(FILE *cfp, char *branch) { LstLink(sFacilityCB) *fl; int i = 0; fprintf(cfp, "static msg_sFacility *Facilities[] = {\n"); for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { if (i++) fprintf(cfp, ",\n"); fprintf(cfp, "\t%-20s /* %4d */", LstObj(fl)->facnam, LstObj(fl)->facnum); } fprintf(cfp, "};\n\n"); if (LstFir(&lFacH) == LstEnd(&lFacH)) fprintf(cfp, "msg_sHead %sMsgHead = {0, 0};\n", branch ? branch : "pwrp"); else fprintf(cfp, "msg_sHead %sMsgHead = {MSG_NOF(Facilities), Facilities};\n", branch ? branch : "pwrp"); }
static sNode * get_nodes ( pwr_tObjid oid ) { LstLink(sNode) *nl; for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { if (cdh_ObjidIsEqual(LstObj(nl)->oid, oid)) return LstObj(nl); } return NULL; }
static void insertTimer ( sTimer *tp ) { LstLink(sTimer) *tl; sTimer *tip; if (LstEmp(&timer_lh)) { (void)LstIns(LstEnd(&timer_lh), tp, ll); return; } for (tl = LstLas(&timer_lh); tl != LstEnd(&timer_lh); tl = LstPre(tl)) { tip = LstObj(tl); if (tp->wrapped) { if (!tip->wrapped || tip->clock < tp->clock) break; } else if (!tip->wrapped && tip->clock < tp->clock) break; } tl = LstNex(tl); (void)LstIns(tl, tp, ll); }
static void reinit_nodes () { pwr_tStatus sts; LstLink(sNode) *nl; sNode *np; pwr_tObjid oid; /* Mark all links in the NodeLink list */ for (nl= LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) LstObj(nl)->found = FALSE; for ( sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts); sts = gdh_GetNextObject(oid, &oid) ) { if ((np = get_nodes(oid)) == NULL) { np = init_node(oid, NULL, 1); if (np != NULL) { nl = LstIns(nl, np, node_l); np->found = TRUE; } } else { update_node(np); } } for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { np = LstObj(nl); if (!np->found) { nl = LstPre(&np->node_l); LstRem(&np->node_l); LstNul(&np->node_l); gdh_SubUnrefObjectInfo (np->o->SubId); gdh_DLUnrefObjectInfo(np->dlid); free(np); } } }
static void dump() { static int cnt = 1; LstLink(sFacilityCB) *fl; printf("dump: %d\n", cnt++); for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) printf("%s\n", LstObj(fl)->facnam); printf("dump finished\n\n"); }
void lex_MsgName(const char *MsgName) { sMsgCB *msgp = (sMsgCB *)calloc(1, sizeof(sMsgCB)); int i; int len = strlen(MsgName); msgp->m.MsgName = malloc(len + 1); for (i = 0; i < len; i++) msgp->m.MsgName[i] = toupper(MsgName[i]); msgp->m.MsgName[i] = '\0'; (void) LstIns(&LstObj(LstLas(&lFacH))->MsgH, msgp, MsgL); }
static void scan_timers () { LstLink(sNode) *nl, *nxtnl; plc_sTimer *tp; for (nl = LstFir(&timer_l); nl != LstEnd(&timer_l); nl = nxtnl) { tp = LstObj(nl)->timer; nxtnl = LstNex(nl); if (tp->TimerCount <= 1 || !tp->TimerFlag) { tp->TimerCount = 0; tp->TimerFlag = FALSE; LstRem(nl); LstNul(nl); } else { tp->TimerCount--; } } }
static sTimer * allocTimer ( ) { const int cAllocCount = 100; sTimer *ftp; LstLink(sTimer) *ftl; int i; if (LstEmp(&free_lh)) { ftp = (sTimer *) calloc(cAllocCount, sizeof(sTimer)); for (i=0; i < cAllocCount; i++, ftp++) { LstIns(&LstEnd(free_lh), ftp, ll); } } ftl = LstFir(&free_lh); LstRem(ftl); return LstObj(ftl); }
static void scan_nodes () { LstLink(sNode) *nl; pwr_tStatus sts; pwr_tBoolean Old; pwr_tTime LastUpdate, Timeout, CurrentTime; pwr_tDeltaTime Delta; pwr_tBoolean LinkUp; time_GetTime(&CurrentTime); for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { sNode *np = LstObj(nl); pwr_sClass_NodeLinkSup *o = np->o; LinkUp = 0; sts = gdh_GetSubscriptionOldness (o->SubId, &Old, &LastUpdate, NULL); if (ODD(sts)) { /* IF (CurrentTime < LastUpdate + TimeoutTime) THEN LinkUp */ Delta.tv_sec = o->TimeoutTime; Delta.tv_nsec = 0; time_Aadd(&Timeout, &LastUpdate, &Delta); if (time_Acomp(&CurrentTime, &Timeout) < 0) LinkUp = 1; o->SystemStatus = *np->subvalue; } if (o->LinkUp && !LinkUp) { o->LinkUp = 0; o->DownTime = CurrentTime; o->SystemStatus = PWR__NETTIMEOUT; } else if (!o->LinkUp && LinkUp) { o->LinkUp = 1; o->UpTime = CurrentTime; o->UpCount++; } detect(o, 1, np); } }
void lex_FacNum(int facnum) { LstLink(sFacilityCB) *fl; /* * To do: Check that the facility number is within the valid range * */ /* Insert in ascending order */ for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { if (LstObj(fl)->facnum > facnum) { break; } } CurrFac->facnum = facnum; LstIns(fl, CurrFac, FacL); CurrFac = NULL; }
static alimsrv_sSupDataBuf * buildBuffer ( alimsrv_sRequest *rqp, unsigned int *size ) { alimsrv_sSupDataBuf *bp = NULL; alimsrv_sAttrSupList *bap; alimsrv_sSupObjEntry *bsp; sObject *op; sAttribute *ap; sSupObject *sp; LstLink(sAttribute) *al; LstLink(sSupObject) *sl; pwr_tStatus sts; *size = 0; op = tree_Find(&sts, ltp, &rqp->Attribute.Objid); if (op == NULL) return NULL; if (op->attr_c == 0) return NULL; *size = sizeof(alimsrv_sSupDataBuf) - sizeof(alimsrv_sAttrSupList) + op->attr_c * sizeof(alimsrv_sAttrSupList) + (op->sup_c - op->attr_c) * sizeof(alimsrv_sSupObjEntry); bp = (alimsrv_sSupDataBuf *)calloc(1, *size); if (bp == NULL) return NULL; bp->NoOfSupAttr = op->attr_c; bap = bp->AttrSupList; for (al = LstFir(&op->attr_l); al != LstEnd(&op->attr_l); al = LstNex(al)) { ap = LstObj(al); bap->SupAttr = ap->aref; bap->NoOfSupObjs = ap->sup_c; bap->SupClass = ap->cid; bsp = bap->SupList; for (sl = LstFir(&ap->sup_l); sl != LstEnd(&ap->sup_l); sl = LstNex(sl)) { sp = LstObj(sl); bsp->SupObjid = sp->oid; if (ap->cid == pwr_cClass_ASup) { pwr_sClass_ASup *asup = (pwr_sClass_ASup *) sp->p; bsp->SupData.A.EvType = asup->EventType; bsp->SupData.A.EvPrio = asup->EventPriority; bsp->SupData.A.High = asup->High; bsp->SupData.A.Limit = asup->CtrlLimit; bsp->SupData.A.Hyst = asup->Hysteres; bsp->SupData.A.MsgOn = asup->DetectOn; } else if (ap->cid == pwr_cClass_DSup) { pwr_sClass_DSup *dsup = (pwr_sClass_DSup *) sp->p; bsp->SupData.D.EvType = dsup->EventType; bsp->SupData.D.EvPrio = dsup->EventPriority; bsp->SupData.D.CtrlPos = dsup->CtrlPosition; } bsp++; } bap = (void *)bsp; } return bp; }
void lex_FacNum(int FacNum) { LstObj(LstLas(&lFacH))->f.FacNum = FacNum; }
/* * Local routines */ static void WriteFiles(char *fname, FILE *cfp, FILE *hfp) { LstLink(sFacilityCB) *fl; LstLink(sMsgCB) *ml; int idx; int facid; char prefix[32]; char name[64]; char msgName[64]; int msg; fprintf(hfp, "#ifndef %s_h\n", fname); fprintf(hfp, "#define %s_h\n\n", fname); for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { facid = 0x800 + LstObj(fl)->f.FacNum; #if defined OS_VMS || OS_ELN snprintf(name, sizeof(name), "%s$_FACILITY", LstObj(fl)->f.FacName); #else snprintf(name, sizeof(name), "%s_FACILITY", LstObj(fl)->f.FacName); #endif fprintf(hfp, "#define %-29s %9d /* x%08x */\n", name, facid, facid); facid = facid << 16; if (LstObj(fl)->f.Prefix) strncpy(prefix, LstObj(fl)->f.Prefix, sizeof(prefix)); else snprintf(prefix, sizeof(prefix), "%s_", LstObj(fl)->f.FacName); snprintf(msgName, sizeof(msgName), "%smsg", LstObj(fl)->f.FacName); fprintf(cfp, "static msg_sMsg %s[] = {\n", msgName); for (idx = 1, ml = LstFir(&LstObj(fl)->MsgH); ml != LstEnd(&LstObj(fl)->MsgH); ml = LstNex(ml), idx++) { if (idx != 1) fprintf(cfp, ",\n"); msg = facid + 0x8000 + (idx << 3) + LstObj(ml)->Severity; snprintf(name, sizeof(name), "%s%s", prefix, LstObj(ml)->m.MsgName); fprintf(hfp, "#define %-29s %9.9d /* x%08x */\n", name, msg, msg); fprintf(cfp, "\t{\"%s\", \"%s\"}", LstObj(ml)->m.MsgName, LstObj(ml)->m.MsgTxt); } fprintf(cfp, "\n};\n\n"); fprintf(cfp, "static msg_sFacility %sfacility[] = {\n\t", LstObj(fl)->f.FacName); fprintf(cfp, "{%d, \"%s\", \"%s\", MSG_NOF(%s), %s}\n", LstObj(fl)->f.FacNum, LstObj(fl)->f.FacName, prefix, msgName, msgName); fprintf(cfp, "};\n\n"); } fprintf(hfp, "\n#endif\n"); }
void lex_MsgSeverity(msg_eSeverity Severity) { LstLink(sMsgCB) *ml = LstLas(&LstObj(LstLas(&lFacH))->MsgH); LstObj(ml)->Severity = Severity; }
void lex_MsgText(const char *Text) { LstLink(sMsgCB) *ml = LstLas(&LstObj(LstLas(&lFacH))->MsgH); TranslateFormatSpec(Text, &LstObj(ml)->m.MsgTxt); /* convert any VMS-style form spec */ }
void lex_FacPrefix(const char *Prefix) { LstObj(LstLas(&lFacH))->f.Prefix = MSG_NEW_STRING(Prefix); }