Commit 2e4c846c authored by Christoffer Ackelman's avatar Christoffer Ackelman

Refactored pwr_lst to remove redundant pointer to data,

the data struct already contain the linked list,
so the linked list do not need pointers to the data.
parent a557a8ee
...@@ -59,27 +59,24 @@ typedef struct sAttribute sAttribute; ...@@ -59,27 +59,24 @@ typedef struct sAttribute sAttribute;
typedef struct sObject sObject; typedef struct sObject sObject;
typedef struct sSupObject sSupObject; typedef struct sSupObject sSupObject;
LstType(sAttribute);
LstType(sSupObject);
struct sObject { struct sObject {
tree_sNode tn; tree_sNode tn;
pwr_tObjid oid; pwr_tObjid oid;
int sup_c; int sup_c;
int attr_c; int attr_c;
LstHead(sAttribute) attr_l; struct LstHead attr_l;
}; };
struct sAttribute { struct sAttribute {
LstLink(sAttribute) attr_l; struct LstHead attr_l;
pwr_sAttrRef aref; pwr_sAttrRef aref;
pwr_tClassId cid; pwr_tClassId cid;
int sup_c; int sup_c;
LstHead(sSupObject) sup_l; struct LstHead sup_l;
}; };
struct sSupObject { struct sSupObject {
LstLink(sSupObject) sup_l; struct LstHead sup_l;
pwr_tObjid oid; pwr_tObjid oid;
void* p; void* p;
}; };
...@@ -100,8 +97,8 @@ static alimsrv_sSupDataBuf* buildBuffer( ...@@ -100,8 +97,8 @@ static alimsrv_sSupDataBuf* buildBuffer(
sObject* op; sObject* op;
sAttribute* ap; sAttribute* ap;
sSupObject* sp; sSupObject* sp;
LstLink(sAttribute) * al; struct LstHead * al;
LstLink(sSupObject) * sl; struct LstHead * sl;
pwr_tStatus sts; pwr_tStatus sts;
*size = 0; *size = 0;
...@@ -123,15 +120,15 @@ static alimsrv_sSupDataBuf* buildBuffer( ...@@ -123,15 +120,15 @@ static alimsrv_sSupDataBuf* buildBuffer(
bp->NoOfSupAttr = op->attr_c; bp->NoOfSupAttr = op->attr_c;
bap = bp->AttrSupList; bap = bp->AttrSupList;
for (al = LstFir(&op->attr_l); al != LstEnd(&op->attr_l); al = LstNex(al)) { LstForEach(al, &op->attr_l) {
ap = LstObj(al); ap = LstEntry(al, sAttribute, attr_l);
bap->SupAttr = ap->aref; bap->SupAttr = ap->aref;
bap->NoOfSupObjs = ap->sup_c; bap->NoOfSupObjs = ap->sup_c;
bap->SupClass = ap->cid; bap->SupClass = ap->cid;
bsp = bap->SupList; bsp = bap->SupList;
for (sl = LstFir(&ap->sup_l); sl != LstEnd(&ap->sup_l); sl = LstNex(sl)) { LstForEach(sl, &ap->sup_l) {
sp = LstObj(sl); sp = LstEntry(sl, sSupObject, sup_l);
bsp->SupObjid = sp->oid; bsp->SupObjid = sp->oid;
if (ap->cid == pwr_cClass_ASup) { if (ap->cid == pwr_cClass_ASup) {
pwr_sClass_ASup* asup = (pwr_sClass_ASup*)sp->p; pwr_sClass_ASup* asup = (pwr_sClass_ASup*)sp->p;
...@@ -160,12 +157,12 @@ static alimsrv_sSupDataBuf* buildBuffer( ...@@ -160,12 +157,12 @@ static alimsrv_sSupDataBuf* buildBuffer(
static sAttribute* findAttribute( static sAttribute* findAttribute(
sObject* op, pwr_sAttrRef* aref, pwr_tClassId cid) sObject* op, pwr_sAttrRef* aref, pwr_tClassId cid)
{ {
LstLink(sAttribute) * al; struct LstHead * al;
sAttribute* ap = NULL; sAttribute* ap = NULL;
for (al = LstFir(&op->attr_l); al != LstEnd(&op->attr_l); al = LstNex(al)) { LstForEach(al, &op->attr_l) {
if (aref->Offset == LstObj(al)->aref.Offset) { if (aref->Offset == LstEntry(al, sAttribute, attr_l)->aref.Offset) {
ap = LstObj(al); ap = LstEntry(al, sAttribute, attr_l);
break; break;
} }
} }
...@@ -175,9 +172,9 @@ static sAttribute* findAttribute( ...@@ -175,9 +172,9 @@ static sAttribute* findAttribute(
if (ap == NULL) if (ap == NULL)
exit(2); exit(2);
LstIni(&ap->attr_l); LstInit(&ap->attr_l);
LstIni(&ap->sup_l); LstInit(&ap->sup_l);
(void)LstIns(&op->attr_l, ap, attr_l); LstInsert(&op->attr_l, &ap->attr_l);
op->attr_c++; op->attr_c++;
ap->cid = cid; ap->cid = cid;
ap->aref = *aref; ap->aref = *aref;
...@@ -204,13 +201,13 @@ static void init() ...@@ -204,13 +201,13 @@ static void init()
op = tree_Find(&sts, ltp, &asp->Attribute.Objid); op = tree_Find(&sts, ltp, &asp->Attribute.Objid);
if (op == NULL) { if (op == NULL) {
op = tree_Insert(&sts, ltp, &asp->Attribute.Objid); op = tree_Insert(&sts, ltp, &asp->Attribute.Objid);
LstIni(&op->attr_l); LstInit(&op->attr_l);
} }
ap = findAttribute(op, &asp->Attribute, pwr_cClass_ASup); ap = findAttribute(op, &asp->Attribute, pwr_cClass_ASup);
sp = calloc(1, sizeof(*sp)); sp = calloc(1, sizeof(*sp));
(void)LstIns(LstEnd(&ap->sup_l), sp, sup_l); LstInsert(&ap->sup_l, &sp->sup_l);
sp->oid = oid; sp->oid = oid;
sp->p = asp; sp->p = asp;
op->sup_c++; op->sup_c++;
...@@ -225,13 +222,13 @@ static void init() ...@@ -225,13 +222,13 @@ static void init()
op = tree_Find(&sts, ltp, &dsp->Attribute.Objid); op = tree_Find(&sts, ltp, &dsp->Attribute.Objid);
if (op == NULL) { if (op == NULL) {
op = tree_Insert(&sts, ltp, &dsp->Attribute.Objid); op = tree_Insert(&sts, ltp, &dsp->Attribute.Objid);
LstIni(&op->attr_l); LstInit(&op->attr_l);
} }
ap = findAttribute(op, &dsp->Attribute, pwr_cClass_DSup); ap = findAttribute(op, &dsp->Attribute, pwr_cClass_DSup);
sp = calloc(1, sizeof(*sp)); sp = calloc(1, sizeof(*sp));
(void)LstIns(LstEnd(&ap->sup_l), sp, sup_l); LstInsert(&ap->sup_l, &sp->sup_l);
sp->oid = oid; sp->oid = oid;
sp->p = dsp; sp->p = dsp;
op->sup_c++; op->sup_c++;
......
...@@ -92,16 +92,8 @@ typedef struct s_DSup sDSup; ...@@ -92,16 +92,8 @@ typedef struct s_DSup sDSup;
typedef struct s_DSupComp sDSupComp; typedef struct s_DSupComp sDSupComp;
typedef union u_Event uEvent; typedef union u_Event uEvent;
LstType(sActive);
LstType(sApplActive);
LstType(sAppl);
LstType(sBlock);
LstType(sOutunit);
LstType(sProcLink);
LstType(sSupActive);
struct s_ProcLink { struct s_ProcLink {
LstLink(sProcLink) proc_l; struct LstHead proc_l;
mh_eSource source; mh_eSource source;
pwr_tNodeIndex nix; pwr_tNodeIndex nix;
qcom_sQid qid; qcom_sQid qid;
...@@ -111,8 +103,8 @@ struct s_ProcLink { ...@@ -111,8 +103,8 @@ struct s_ProcLink {
struct s_Appl { struct s_Appl {
sProcLink link; /* Link in process list */ sProcLink link; /* Link in process list */
LstLink(sAppl) appl_l; /* Link in application list */ struct LstHead appl_l; /* Link in application list */
LstHead(sApplActive) active_l; /* Head of application alarm list */ struct LstHead active_l; /* Head of application alarm list */
pwr_tUInt32 activeMessages; /* Active messages */ pwr_tUInt32 activeMessages; /* Active messages */
mh_eApplState state; mh_eApplState state;
mh_eApplState oldState; mh_eApplState oldState;
...@@ -121,7 +113,7 @@ struct s_Appl { ...@@ -121,7 +113,7 @@ struct s_Appl {
}; };
struct s_Active { struct s_Active {
LstLink(sActive) active_l; /* Link in active list */ struct LstHead active_l; /* Link in active list */
pwr_tUInt32 idx; /* Event index of alarm */ pwr_tUInt32 idx; /* Event index of alarm */
pwr_tUInt32 returnIdx; /* Event index of return message */ pwr_tUInt32 returnIdx; /* Event index of return message */
pwr_tUInt32 ackIdx; /* Event index of ack message */ pwr_tUInt32 ackIdx; /* Event index of ack message */
...@@ -161,7 +153,7 @@ struct s_NodeInfo { ...@@ -161,7 +153,7 @@ struct s_NodeInfo {
struct s_Block { struct s_Block {
sActive link; sActive link;
LstLink(sBlock) block_l; struct LstHead block_l;
mh_sOutunitBlock outunitBlock; mh_sOutunitBlock outunitBlock;
mh_sOutunitBlock outunitUnblock; mh_sOutunitBlock outunitUnblock;
mh_sEventId targetId; mh_sEventId targetId;
...@@ -254,9 +246,9 @@ struct s_Sup { ...@@ -254,9 +246,9 @@ struct s_Sup {
struct s_SupActive { struct s_SupActive {
sActive link; sActive link;
LstLink(sSupActive) sup_l; struct LstHead sup_l;
LstLink(sSupActive) detect_l; struct LstHead detect_l;
LstLink(sSupActive) timer_l; struct LstHead timer_l;
mh_eAgent agent; mh_eAgent agent;
mh_uEventInfo alarmVisibility; mh_uEventInfo alarmVisibility;
mh_eSupType supType; mh_eSupType supType;
...@@ -304,7 +296,7 @@ struct s_DSupComp { ...@@ -304,7 +296,7 @@ struct s_DSupComp {
struct s_ApplActive { struct s_ApplActive {
sActive link; sActive link;
LstLink(sApplActive) active_l; struct LstHead active_l;
mh_sApplMessage message; mh_sApplMessage message;
pwr_tTime ackTime; pwr_tTime ackTime;
pwr_tObjid ackOutunit; pwr_tObjid ackOutunit;
...@@ -316,7 +308,7 @@ struct s_ApplActive { ...@@ -316,7 +308,7 @@ struct s_ApplActive {
struct s_Outunit { struct s_Outunit {
sProcLink link; /* Link in process list */ sProcLink link; /* Link in process list */
LstLink(sOutunit) outunit_l; /* Link in outunit list */ struct LstHead outunit_l; /* Link in outunit list */
pwr_tTime birthTime; /* Time when outunit was started */ pwr_tTime birthTime; /* Time when outunit was started */
pwr_tObjid outunit; /* Object id of outunit object */ pwr_tObjid outunit; /* Object id of outunit object */
mh_eOutunitType type; /* Type of outunit */ mh_eOutunitType type; /* Type of outunit */
...@@ -376,18 +368,18 @@ struct sLocal { ...@@ -376,18 +368,18 @@ struct sLocal {
pwr_sClass_MessageHandler* emon; pwr_sClass_MessageHandler* emon;
pwr_tOName emonName; pwr_tOName emonName;
pwr_tObjid emonObject; pwr_tObjid emonObject;
LstHead(sOutunit) outunit_l; struct LstHead outunit_l;
mh_sHead head; mh_sHead head;
LstHead(sActive) active_l; struct LstHead active_l;
sEventList* event_l; sEventList* event_l;
LstHead(sProcLink) proc_l; struct LstHead proc_l;
LstHead(sAppl) appl_l; struct LstHead appl_l;
LstHead(sSupActive) sup_l; struct LstHead sup_l;
LstHead(sBlock) block_l; struct LstHead block_l;
LstHead(sBlock) blockFree_l; struct LstHead blockFree_l;
LstHead(sSupActive) detect_l; struct LstHead detect_l;
LstHead(sSupActive) timer_l; struct LstHead timer_l;
LstHead(sApplActive) handlerFree_l; struct LstHead handlerFree_l;
eSupListState supListState; eSupListState supListState;
tree_sTable* eventTab; tree_sTable* eventTab;
pwr_tBoolean newBlock; pwr_tBoolean newBlock;
...@@ -603,16 +595,16 @@ int main() ...@@ -603,16 +595,16 @@ int main()
eventListInit(); eventListInit();
LstIni(&l.outunit_l); LstInit(&l.outunit_l);
LstIni(&l.active_l); LstInit(&l.active_l);
LstIni(&l.proc_l); LstInit(&l.proc_l);
LstIni(&l.appl_l); LstInit(&l.appl_l);
LstIni(&l.sup_l); LstInit(&l.sup_l);
LstIni(&l.block_l); LstInit(&l.block_l);
LstIni(&l.blockFree_l); LstInit(&l.blockFree_l);
LstIni(&l.detect_l); LstInit(&l.detect_l);
LstIni(&l.timer_l); LstInit(&l.timer_l);
LstIni(&l.handlerFree_l); LstInit(&l.handlerFree_l);
l.supListState = eSupListState_Init; l.supListState = eSupListState_Init;
...@@ -659,13 +651,13 @@ static sActive* activeListGet(pwr_tUInt32 idx) ...@@ -659,13 +651,13 @@ static sActive* activeListGet(pwr_tUInt32 idx)
static void activeListInsert(sActive* ap, sEvent* ep, mh_eSource source) static void activeListInsert(sActive* ap, sEvent* ep, mh_eSource source)
{ {
int inserted; int inserted;
LstLink(sActive) * al; struct LstHead * al;
LstLink(sBlock) * bl; struct LstHead * bl;
/* Check that not already inserted */ /* Check that not already inserted */
inserted = 0; inserted = 0;
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); al = LstNex(al)) { LstForEach(al, &l.active_l) {
if (ap == LstObj(al)) { if (ap == LstEntry(al, sActive, active_l)) {
inserted = 1; inserted = 1;
break; break;
} }
...@@ -675,8 +667,8 @@ static void activeListInsert(sActive* ap, sEvent* ep, mh_eSource source) ...@@ -675,8 +667,8 @@ static void activeListInsert(sActive* ap, sEvent* ep, mh_eSource source)
ap->source = source; ap->source = source;
if (!inserted) { if (!inserted) {
al = LstEnd(&l.active_l); al = &l.active_l;
LstIns(al, ap, active_l); LstInsert(al, &ap->active_l);
} }
switch (ap->event) { switch (ap->event) {
...@@ -691,8 +683,8 @@ static void activeListInsert(sActive* ap, sEvent* ep, mh_eSource source) ...@@ -691,8 +683,8 @@ static void activeListInsert(sActive* ap, sEvent* ep, mh_eSource source)
break; break;
case mh_eEvent_Block: case mh_eEvent_Block:
case mh_eEvent_Reblock: case mh_eEvent_Reblock:
bl = LstEnd(&l.block_l); bl = &l.block_l;
LstIns(bl, (sBlock*)ap, block_l); LstInsert(bl, &((sBlock*)ap)->block_l);
++l.emon->BlockCount; ++l.emon->BlockCount;
break; break;
case mh_eEvent_Info: case mh_eEvent_Info:
...@@ -712,11 +704,11 @@ static void activeListRemove(sActive* ap) ...@@ -712,11 +704,11 @@ static void activeListRemove(sActive* ap)
sApplActive* aap; sApplActive* aap;
sBlock* bp; sBlock* bp;
if (LstIsNul(&ap->active_l)) if (LstIsNull(&ap->active_l))
return; return;
LstRem(&ap->active_l); LstRemove(&ap->active_l);
LstNul(&ap->active_l); LstNull(&ap->active_l);
ap->idx = 0; ap->idx = 0;
ap->ackIdx = 0; ap->ackIdx = 0;
ap->returnIdx = 0; ap->returnIdx = 0;
...@@ -736,8 +728,8 @@ static void activeListRemove(sActive* ap) ...@@ -736,8 +728,8 @@ static void activeListRemove(sActive* ap)
case mh_eEvent_Reblock: case mh_eEvent_Reblock:
case mh_eEvent_CancelBlock: case mh_eEvent_CancelBlock:
bp = (sBlock*)ap; bp = (sBlock*)ap;
LstRem(&bp->block_l); LstRemove(&bp->block_l);
LstNul(&bp->block_l); LstNull(&bp->block_l);
--l.emon->BlockCount; --l.emon->BlockCount;
break; break;
case mh_eEvent_Info: case mh_eEvent_Info:
...@@ -773,8 +765,8 @@ static void activeListRemove(sActive* ap) ...@@ -773,8 +765,8 @@ static void activeListRemove(sActive* ap)
|| ap->source == mh_eSource_Handler) { || ap->source == mh_eSource_Handler) {
aap = (sApplActive*)ap; aap = (sApplActive*)ap;
LstRem(&aap->active_l); /* Remove from application alarm list */ LstRemove(&aap->active_l); /* Remove from application alarm list */
LstNul(&aap->active_l); LstNull(&aap->active_l);
if (aap->ap->activeMessages > 0) if (aap->ap->activeMessages > 0)
--aap->ap->activeMessages; --aap->ap->activeMessages;
if (ap->source == mh_eSource_Application) if (ap->source == mh_eSource_Application)
...@@ -814,10 +806,10 @@ static void applDisconnect(mh_sHead* hp, sAppl* ap, mh_uApplReply* Reply) ...@@ -814,10 +806,10 @@ static void applDisconnect(mh_sHead* hp, sAppl* ap, mh_uApplReply* Reply)
/* Cancel all active messages */ /* Cancel all active messages */
LstRem(&ap->appl_l); /* Remove from application list */ LstRemove(&ap->appl_l); /* Remove from application list */
LstNul(&ap->appl_l); LstNull(&ap->appl_l);
LstRem(&ap->link.proc_l); /* Remove from process link */ LstRemove(&ap->link.proc_l); /* Remove from process link */
LstNul(&ap->link.proc_l); LstNull(&ap->link.proc_l);
free(ap); /* Free control block */ free(ap); /* Free control block */
Reply->Sts = MH__SUCCESS; Reply->Sts = MH__SUCCESS;
} }
...@@ -844,7 +836,7 @@ static void applGetMsgInfo(mh_sHead* hp, sAppl* ap, mh_uApplReply* Reply) ...@@ -844,7 +836,7 @@ static void applGetMsgInfo(mh_sHead* hp, sAppl* ap, mh_uApplReply* Reply)
{ {
pwr_tUInt32* TargetIdxP = (pwr_tUInt32*)(hp + 1); pwr_tUInt32* TargetIdxP = (pwr_tUInt32*)(hp + 1);
sApplActive* aap; sApplActive* aap;
LstLink(sApplActive) * al; struct LstHead * al;
switch (ap->state) { switch (ap->state) {
case mh_eApplState_Connected: case mh_eApplState_Connected:
...@@ -861,12 +853,12 @@ static void applGetMsgInfo(mh_sHead* hp, sAppl* ap, mh_uApplReply* Reply) ...@@ -861,12 +853,12 @@ static void applGetMsgInfo(mh_sHead* hp, sAppl* ap, mh_uApplReply* Reply)
return; return;
} }
for (al = LstFir(&ap->active_l); al != LstEnd(&ap->active_l); al = LstNex(al)) LstForEach(al, &l.active_l)
if (LstObj(al)->link.idx >= *TargetIdxP) if (LstEntry(al, sApplActive, active_l)->link.idx >= *TargetIdxP)
break; break;
if (al != LstEnd(&ap->active_l)) { if (al != &ap->active_l) {
aap = LstObj(al); aap = LstEntry(al, sApplActive, active_l);
Reply->Info.Sts = MH__SUCCESS; Reply->Info.Sts = MH__SUCCESS;
Reply->Info.Message = aap->message; Reply->Info.Message = aap->message;
} else } else
...@@ -947,7 +939,7 @@ static void applMessage(mh_sHead* hp, sAppl* ap, mh_uApplReply* reply) ...@@ -947,7 +939,7 @@ static void applMessage(mh_sHead* hp, sAppl* ap, mh_uApplReply* reply)
} }
/* Insert in application alarm list */ /* Insert in application alarm list */
(void)LstIns(&ap->active_l, aap, active_l); LstInsert(&ap->active_l, &aap->active_l);
aap->ap = ap; aap->ap = ap;
++ap->activeMessages; ++ap->activeMessages;
...@@ -1070,35 +1062,35 @@ static void applReturn(mh_sHead* hp, sAppl* ApplP, mh_uApplReply* reply) ...@@ -1070,35 +1062,35 @@ static void applReturn(mh_sHead* hp, sAppl* ApplP, mh_uApplReply* reply)
static sBlock* blockListAlloc() static sBlock* blockListAlloc()
{ {
LstLink(sBlock) * bl; struct LstHead * bl;
LstHead(sBlock) * ll; struct LstHead * ll;
sBlock* bp; sBlock* bp;
const int alloc = 100; const int alloc = 100;
int i; int i;
ll = &l.blockFree_l; ll = &l.blockFree_l;
if (LstEmp(ll)) { if (LstEmpty(ll)) {
bp = (sBlock*)calloc(alloc, sizeof(sBlock)); bp = (sBlock*)calloc(alloc, sizeof(sBlock));
if (bp != NULL) { if (bp != NULL) {
for (i = 0; i < alloc; i++, bp++) for (i = 0; i < alloc; i++, bp++)
LstIns(ll, bp, link.active_l); LstInsert(ll, &bp->link.active_l);
l.emon->FreeCount += alloc; l.emon->FreeCount += alloc;
} else { } else {
return NULL; return NULL;
} }
} }
bl = LstFir(ll); bl = ll->next;
LstRem(bl); LstRemove(bl);
--l.emon->FreeCount; --l.emon->FreeCount;
return LstObj(bl); return LstEntry(bl, sBlock, block_l);
} }
static void blockListFree(sBlock* bp) static void blockListFree(sBlock* bp)
{ {
memset(bp, 0, sizeof(*bp)); memset(bp, 0, sizeof(*bp));
LstIns(&l.blockFree_l, bp, link.active_l); LstInsert(&l.blockFree_l, &bp->link.active_l);
++l.emon->FreeCount; ++l.emon->FreeCount;
return; return;
} }
...@@ -1189,7 +1181,7 @@ static void cancelAlarm(sActive* ap, char* text) ...@@ -1189,7 +1181,7 @@ static void cancelAlarm(sActive* ap, char* text)
static void sendAlarmStatus(sOutunit* op) static void sendAlarmStatus(sOutunit* op)
{ {
LstLink(sActive) * al; struct LstHead * al;
sEvent* ep; sEvent* ep;
sActive* ap; sActive* ap;
mh_sAlarmStatus* msg; mh_sAlarmStatus* msg;
...@@ -1199,8 +1191,8 @@ static void sendAlarmStatus(sOutunit* op) ...@@ -1199,8 +1191,8 @@ static void sendAlarmStatus(sOutunit* op)
/* Count alarms */ /* Count alarms */
int count = 0; int count = 0;
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); al = LstNex(al)) { LstForEach(al, &l.active_l) {
ap = LstObj(al); ap = LstEntry(al, sActive, active_l);
if (!ap->detect_etp) if (!ap->detect_etp)
continue; continue;
...@@ -1247,8 +1239,8 @@ static void sendAlarmStatus(sOutunit* op) ...@@ -1247,8 +1239,8 @@ static void sendAlarmStatus(sOutunit* op)
msg->Count = count; msg->Count = count;
count = 0; count = 0;
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); al = LstNex(al)) { LstForEach(al, &l.active_l) {
ap = LstObj(al); ap = LstEntry(al, sActive, active_l);
if (!ap->detect_etp) if (!ap->detect_etp)
continue; continue;
...@@ -1299,10 +1291,10 @@ static void sendAlarmStatus(sOutunit* op) ...@@ -1299,10 +1291,10 @@ static void sendAlarmStatus(sOutunit* op)
static void checkOutunits() static void checkOutunits()
{ {
sOutunit* op; sOutunit* op;
LstLink(sOutunit) * ol; struct LstHead * ol;
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); ol = LstNex(ol)) { LstForEach(ol, &l.outunit_l) {
op = LstObj(ol); op = LstEntry(ol, sOutunit, outunit_l);
if (op->linkUp && op->type == mh_eOutunitType_Operator && op->ver >= 5) if (op->linkUp && op->type == mh_eOutunitType_Operator && op->ver >= 5)
/* Set alarm status to operator */ /* Set alarm status to operator */
...@@ -1578,11 +1570,11 @@ static sEvent* eventListInsert(mh_eEvent event, char* text, sActive* ap) ...@@ -1578,11 +1570,11 @@ static sEvent* eventListInsert(mh_eEvent event, char* text, sActive* ap)
static void eventToOutunits(sEvent* ep) static void eventToOutunits(sEvent* ep)
{ {
LstLink(sOutunit) * ol; struct LstHead * ol;
sOutunit* op; sOutunit* op;
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); ol = LstNex(ol)) { LstForEach(ol, &l.outunit_l) {
op = LstObj(ol); op = LstEntry(ol, sOutunit, outunit_l);
if (op->syncedIdx == op->eventIdx) if (op->syncedIdx == op->eventIdx)
sendEventListToOutunit(op); sendEventListToOutunit(op);
} }
...@@ -2085,7 +2077,7 @@ static void fromEvent(qcom_sGet* get) ...@@ -2085,7 +2077,7 @@ static void fromEvent(qcom_sGet* get)
new_event.m = ep->mask; new_event.m = ep->mask;
if (new_event.b.swapDone & !cur_event.b.swapDone) { if (new_event.b.swapDone & !cur_event.b.swapDone) {
LstLink(sOutunit) * ol; struct LstHead * ol;
sOutunit* op; sOutunit* op;
errh_Info("Warm restart completed."); errh_Info("Warm restart completed.");
...@@ -2093,10 +2085,10 @@ static void fromEvent(qcom_sGet* get) ...@@ -2093,10 +2085,10 @@ static void fromEvent(qcom_sGet* get)
handlerEvent(pwr_eSystemEventTypeEnum_NodeRestart, l.head.nix, 0); handlerEvent(pwr_eSystemEventTypeEnum_NodeRestart, l.head.nix, 0);
reInitSupList(); reInitSupList();
if (!LstEmp(&l.sup_l)) { if (!LstEmpty(&l.sup_l)) {
l.supListState = eSupListState_Scan; l.supListState = eSupListState_Scan;
setTimerActive(cMessageIdx, TRUE); setTimerActive(cMessageIdx, TRUE);
if (!LstEmp(&l.detect_l)) { if (!LstEmpty(&l.detect_l)) {
scanTimerList(); scanTimerList();
scanDetectList(); scanDetectList();
setTimerActive(cDetectIdx, TRUE); setTimerActive(cDetectIdx, TRUE);
...@@ -2107,14 +2099,12 @@ static void fromEvent(qcom_sGet* get) ...@@ -2107,14 +2099,12 @@ static void fromEvent(qcom_sGet* get)
setTimerActive(cMessageIdx, FALSE); setTimerActive(cMessageIdx, FALSE);
errh_Info("No supervise objects."); errh_Info("No supervise objects.");
} }
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); LstForEach(ol, &l.outunit_l) {
ol = LstNex(ol)) { op = LstEntry(ol, sOutunit, outunit_l);
op = LstObj(ol);
sendToOutunit(op, mh_eMsg_OutunitClear, 0, 0, NULL, 0); sendToOutunit(op, mh_eMsg_OutunitClear, 0, 0, NULL, 0);
} }
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); LstForEach(ol, &l.outunit_l) {
ol = LstNex(ol)) { op = LstEntry(ol, sOutunit, outunit_l);
op = LstObj(ol);
sendEventListToOutunit(op); sendEventListToOutunit(op);
} }
pwrb_IOHandler_Exec(handlerEvent_cb, 1); pwrb_IOHandler_Exec(handlerEvent_cb, 1);
...@@ -2124,15 +2114,14 @@ static void fromEvent(qcom_sGet* get) ...@@ -2124,15 +2114,14 @@ static void fromEvent(qcom_sGet* get)
errh_Info("Warm restart initiated."); errh_Info("Warm restart initiated.");
handlerEvent(pwr_eSystemEventTypeEnum_NodeRestart, l.head.nix, 1); handlerEvent(pwr_eSystemEventTypeEnum_NodeRestart, l.head.nix, 1);
} else if (new_event.b.simLoadStart & !cur_event.b.simLoadStart) { } else if (new_event.b.simLoadStart & !cur_event.b.simLoadStart) {
LstLink(sOutunit) * ol; struct LstHead * ol;
sOutunit* op; sOutunit* op;
l.supListState = eSupListState_Wait; l.supListState = eSupListState_Wait;
handlerEvent(pwr_eSystemEventTypeEnum_SimulateLoad, l.head.nix, 1); handlerEvent(pwr_eSystemEventTypeEnum_SimulateLoad, l.head.nix, 1);
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); LstForEach(ol, &l.outunit_l) {
ol = LstNex(ol)) { op = LstEntry(ol, sOutunit, outunit_l);
op = LstObj(ol);
if (op->syncedIdx == op->eventIdx) if (op->syncedIdx == op->eventIdx)
sendToOutunit(op, mh_eMsg_OutunitClear, 0, 0, NULL, 0); sendToOutunit(op, mh_eMsg_OutunitClear, 0, 0, NULL, 0);
} }
...@@ -2142,10 +2131,10 @@ static void fromEvent(qcom_sGet* get) ...@@ -2142,10 +2131,10 @@ static void fromEvent(qcom_sGet* get)
handlerEvent(pwr_eSystemEventTypeEnum_SimulateLoad, l.head.nix, 0); handlerEvent(pwr_eSystemEventTypeEnum_SimulateLoad, l.head.nix, 0);
reInitSupList(); reInitSupList();
if (!LstEmp(&l.sup_l)) { if (!LstEmpty(&l.sup_l)) {
l.supListState = eSupListState_Scan; l.supListState = eSupListState_Scan;
setTimerActive(cMessageIdx, TRUE); setTimerActive(cMessageIdx, TRUE);
if (!LstEmp(&l.detect_l)) { if (!LstEmpty(&l.detect_l)) {
scanTimerList(); scanTimerList();
scanDetectList(); scanDetectList();
setTimerActive(cDetectIdx, TRUE); setTimerActive(cDetectIdx, TRUE);
...@@ -2521,7 +2510,7 @@ static void handlerEvent( ...@@ -2521,7 +2510,7 @@ static void handlerEvent(
gdh_ArefANameToAref(&aref, attr, &hp->link.supObject); gdh_ArefANameToAref(&aref, attr, &hp->link.supObject);
/* Insert in application alarm list */ /* Insert in application alarm list */
(void)LstIns(&node->appl.active_l, hp, active_l); LstInsert(&node->appl.active_l, &hp->active_l);
hp->ap = (sAppl*)&node->appl; hp->ap = (sAppl*)&node->appl;
++hp->ap->activeMessages; ++hp->ap->activeMessages;
ep = eventListInsert(ssup->EventType, NULL, (sActive*)hp); ep = eventListInsert(ssup->EventType, NULL, (sActive*)hp);
...@@ -2564,8 +2553,8 @@ static void handlerEvent_cb(int event, int status) ...@@ -2564,8 +2553,8 @@ static void handlerEvent_cb(int event, int status)
static sApplActive* handlerListAlloc(pwr_eSystemEventTypeEnum event) static sApplActive* handlerListAlloc(pwr_eSystemEventTypeEnum event)
{ {
LstLink(sApplActive) * hl; struct LstHead * hl;
LstHead(sApplActive) * ll; struct LstHead * ll;
sApplActive* hp; sApplActive* hp;
const int Alloc = 50; const int Alloc = 50;
int i; int i;
...@@ -2581,31 +2570,31 @@ static sApplActive* handlerListAlloc(pwr_eSystemEventTypeEnum event) ...@@ -2581,31 +2570,31 @@ static sApplActive* handlerListAlloc(pwr_eSystemEventTypeEnum event)
ll = &l.handlerFree_l; ll = &l.handlerFree_l;
if (LstEmp(ll)) { if (LstEmpty(ll)) {
hp = (sApplActive*)calloc(Alloc, sizeof(sApplActive)); hp = (sApplActive*)calloc(Alloc, sizeof(sApplActive));
if (hp != NULL) { if (hp != NULL) {
for (i = 0; i < Alloc; i++, hp++) for (i = 0; i < Alloc; i++, hp++)
LstIns(ll, hp, link.active_l); LstInsert(ll, &hp->link.active_l);
l.emon->AlarmMaxCount += Alloc; l.emon->AlarmMaxCount += Alloc;
} else { } else {
return NULL; return NULL;
} }
} }
hl = LstFir(ll); hl = ll->next;
LstRem(hl); LstRemove(hl);
LstNul(hl); LstNull(hl);
--l.emon->AlarmMaxCount; --l.emon->AlarmMaxCount;
l.handlerListCount++; l.handlerListCount++;
return LstObj(hl); return LstEntry(hl, sApplActive, active_l);
} }
static void handlerListFree(sApplActive* hp) static void handlerListFree(sApplActive* hp)
{ {
// return; // return;
memset(hp, 0, sizeof(*hp)); memset(hp, 0, sizeof(*hp));
LstIns(&l.handlerFree_l, hp, link.active_l); LstInsert(&l.handlerFree_l, &hp->link.active_l);
++l.emon->AlarmMaxCount; ++l.emon->AlarmMaxCount;
l.handlerListCount--; l.handlerListCount--;
return; return;
...@@ -2707,7 +2696,7 @@ static void initNodeDb() ...@@ -2707,7 +2696,7 @@ static void initNodeDb()
strncpy(np->name, qnode.name, sizeof(np->name)); strncpy(np->name, qnode.name, sizeof(np->name));
for (i = 0; i < cNodes; i++) { for (i = 0; i < cNodes; i++) {
LstIni(&l.nodeDb[i].appl.active_l); LstInit(&l.nodeDb[i].appl.active_l);
} }
} }
...@@ -2968,7 +2957,7 @@ static pwr_tStatus initSupList() ...@@ -2968,7 +2957,7 @@ static pwr_tStatus initSupList()
if (EVEN(sts)) if (EVEN(sts))
errh_Error("Initialize list of CycleSup's\n%m", sts); errh_Error("Initialize list of CycleSup's\n%m", sts);
if (LstEmp(&l.sup_l)) if (LstEmpty(&l.sup_l))
errh_Info("No sup objects"); errh_Info("No sup objects");
return (sts); return (sts);
...@@ -2977,13 +2966,13 @@ static pwr_tStatus initSupList() ...@@ -2977,13 +2966,13 @@ static pwr_tStatus initSupList()
static pwr_tStatus initSupListClass(pwr_tClassId cid) static pwr_tStatus initSupListClass(pwr_tClassId cid)
{ {
pwr_tStatus sts; pwr_tStatus sts;
LstLink(sSupActive) * sl; struct LstHead * sl;
LstLink(sSupActive) * dl; struct LstHead * dl;
sSupActive* sp; sSupActive* sp;
pwr_tAttrRef aref; pwr_tAttrRef aref;
sl = LstEnd(&l.sup_l); sl = &l.sup_l;
dl = LstEnd(&l.detect_l); dl = &l.detect_l;
/* Loop trough objects in class list. */ /* Loop trough objects in class list. */
...@@ -2994,10 +2983,12 @@ static pwr_tStatus initSupListClass(pwr_tClassId cid) ...@@ -2994,10 +2983,12 @@ static pwr_tStatus initSupListClass(pwr_tClassId cid)
sts = initSupActiveCB(&aref, cid, &sp, 1, 1); sts = initSupActiveCB(&aref, cid, &sp, 1, 1);
if (ODD(sts)) { if (ODD(sts)) {
sl = LstIns(sl, sp, sup_l); LstInsert(sl, &sp->sup_l);
sl = &sp->sup_l;
l.emon->BlockMaxCount++; l.emon->BlockMaxCount++;
if (sp->agent == mh_eAgent_MH) { if (sp->agent == mh_eAgent_MH) {
dl = LstIns(dl, sp, detect_l); LstInsert(dl, &sp->detect_l);
dl = &sp->detect_l;
l.emon->EventFirstIdx++; l.emon->EventFirstIdx++;
} }
} }
...@@ -3049,7 +3040,7 @@ static pwr_tBoolean isValidApplication( ...@@ -3049,7 +3040,7 @@ static pwr_tBoolean isValidApplication(
mh_sHead* hp, qcom_sAid* aid, sAppl** appl, mh_uApplReply* Reply) mh_sHead* hp, qcom_sAid* aid, sAppl** appl, mh_uApplReply* Reply)
{ {
sAppl* ap; sAppl* ap;
LstLink(sAppl) * al; struct LstHead * al;
if (!(hp->ver == mh_cVersion if (!(hp->ver == mh_cVersion
|| (mh_cVersion == 5 || (mh_cVersion == 5
...@@ -3064,11 +3055,11 @@ static pwr_tBoolean isValidApplication( ...@@ -3064,11 +3055,11 @@ static pwr_tBoolean isValidApplication(
/* Find outunit in outunit list */ /* Find outunit in outunit list */
for (al = LstFir(&l.appl_l); al != LstEnd(&l.appl_l); al = LstNex(al)) LstForEach(al, &l.appl_l)
if (cdh_ObjidIsEqual(LstObj(al)->aid, hp->aid)) if (cdh_ObjidIsEqual(LstEntry(al, sAppl, appl_l)->aid, hp->aid))
break; break;
if (al == LstEnd(&l.appl_l)) { if (al == &l.appl_l) {
/* Application not known, make it known */ /* Application not known, make it known */
ap = (sAppl*)calloc(1, sizeof(*ap)); ap = (sAppl*)calloc(1, sizeof(*ap));
if (ap == NULL) { if (ap == NULL) {
...@@ -3084,12 +3075,12 @@ static pwr_tBoolean isValidApplication( ...@@ -3084,12 +3075,12 @@ static pwr_tBoolean isValidApplication(
ap->aid = hp->aid; ap->aid = hp->aid;
ap->state = mh_eApplState_New; ap->state = mh_eApplState_New;
/* Insert in application list */ /* Insert in application list */
LstIns(&l.appl_l, ap, appl_l); LstInsert(&l.appl_l, &ap->appl_l);
/* Insert in process list */ /* Insert in process list */
LstIns(&l.proc_l, ap, link.proc_l); LstInsert(&l.proc_l, &ap->link.proc_l);
LstIni(&ap->active_l); /* Init application alarm list */ LstInit(&ap->active_l); /* Init application alarm list */
} else { } else {
ap = LstObj(al); ap = LstEntry(al, sAppl, appl_l);
if (ap->birthTime.tv_sec != hp->birthTime.tv_sec) { if (ap->birthTime.tv_sec != hp->birthTime.tv_sec) {
/* Different times, i.e. the application is restarted */ /* Different times, i.e. the application is restarted */
...@@ -3113,7 +3104,7 @@ static pwr_tBoolean isValidOutunit( ...@@ -3113,7 +3104,7 @@ static pwr_tBoolean isValidOutunit(
mh_sHead* hp, qcom_sAid* aid, sOutunit** outunit) mh_sHead* hp, qcom_sAid* aid, sOutunit** outunit)
{ {
sOutunit* op; sOutunit* op;
LstLink(sOutunit) * ol; struct LstHead * ol;
if (!(hp->ver == mh_cVersion if (!(hp->ver == mh_cVersion
|| (mh_cVersion == 5 || (mh_cVersion == 5
...@@ -3127,11 +3118,11 @@ static pwr_tBoolean isValidOutunit( ...@@ -3127,11 +3118,11 @@ static pwr_tBoolean isValidOutunit(
/* Find outunit in outunit list */ /* Find outunit in outunit list */
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); ol = LstNex(ol)) LstForEach(ol, &l.outunit_l)
if (cdh_ObjidIsEqual(LstObj(ol)->outunit, hp->outunit)) if (cdh_ObjidIsEqual(LstEntry(ol, sOutunit, outunit_l)->outunit, hp->outunit))
break; break;
if (ol == LstEnd(&l.outunit_l)) { if (ol == &l.outunit_l) {
/* Outunit not known, make it known */ /* Outunit not known, make it known */
op = (sOutunit*)calloc(1, sizeof(*op)); op = (sOutunit*)calloc(1, sizeof(*op));
if (op == NULL) { if (op == NULL) {
...@@ -3147,13 +3138,13 @@ static pwr_tBoolean isValidOutunit( ...@@ -3147,13 +3138,13 @@ static pwr_tBoolean isValidOutunit(
op->ver = hp->ver; op->ver = hp->ver;
op->outunit = hp->outunit; op->outunit = hp->outunit;
/* Insert in outunit list */ /* Insert in outunit list */
LstIns(&l.outunit_l, op, outunit_l); LstInsert(&l.outunit_l, &op->outunit_l);
/* Insert in process list */ /* Insert in process list */
LstIns(&l.proc_l, op, link.proc_l); LstInsert(&l.proc_l, &op->link.proc_l);
op->linkUp = TRUE; op->linkUp = TRUE;
outunitLog(op, "New outunit"); outunitLog(op, "New outunit");
} else { } else {
op = LstObj(ol); op = LstEntry(ol, sOutunit, outunit_l);
if (op->birthTime.tv_sec != hp->birthTime.tv_sec) { if (op->birthTime.tv_sec != hp->birthTime.tv_sec) {
if (hp->type == mh_eMsg_OutunitInfo) { if (hp->type == mh_eMsg_OutunitInfo) {
...@@ -3198,7 +3189,7 @@ static void linkActive(qcom_sGet* msg) ...@@ -3198,7 +3189,7 @@ static void linkActive(qcom_sGet* msg)
static void linkConnect(qcom_sGet* msg) static void linkConnect(qcom_sGet* msg)
{ {
pwr_tStatus sts; pwr_tStatus sts;
LstLink(sOutunit) * ol; struct LstHead * ol;
qcom_sNode* qnode = (qcom_sNode*)msg->data; qcom_sNode* qnode = (qcom_sNode*)msg->data;
int nix = qnode->nid; int nix = qnode->nid;
...@@ -3215,9 +3206,9 @@ static void linkConnect(qcom_sGet* msg) ...@@ -3215,9 +3206,9 @@ static void linkConnect(qcom_sGet* msg)
node->newLinkState = gdh_eLinkState_Up; node->newLinkState = gdh_eLinkState_Up;
node->check = TRUE; node->check = TRUE;
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); ol = LstNex(ol)) LstForEach(ol, &l.outunit_l)
if (nix == LstObj(ol)->link.qid.nid) { if (nix == LstEntry(ol, sOutunit, outunit_l)->link.qid.nid) {
LstObj(ol)->linkUp = TRUE; LstEntry(ol, sOutunit, outunit_l)->linkUp = TRUE;
} }
sts = sendMessage(mh_eMsg_HandlerHello, NULL, NULL, NULL, sts = sendMessage(mh_eMsg_HandlerHello, NULL, NULL, NULL,
...@@ -3226,7 +3217,7 @@ static void linkConnect(qcom_sGet* msg) ...@@ -3226,7 +3217,7 @@ static void linkConnect(qcom_sGet* msg)
static void linkDisconnect(qcom_sGet* msg) static void linkDisconnect(qcom_sGet* msg)
{ {
LstLink(sOutunit) * ol; struct LstHead * ol;
qcom_sNode* qnode = (qcom_sNode*)msg->data; qcom_sNode* qnode = (qcom_sNode*)msg->data;
int nix = qnode->nid; int nix = qnode->nid;
...@@ -3243,9 +3234,9 @@ static void linkDisconnect(qcom_sGet* msg) ...@@ -3243,9 +3234,9 @@ static void linkDisconnect(qcom_sGet* msg)
node->check = TRUE; node->check = TRUE;
} }
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); ol = LstNex(ol)) LstForEach(ol, &l.outunit_l)
if (nix == LstObj(ol)->link.qid.nid) { if (nix == LstEntry(ol, sOutunit, outunit_l)->link.qid.nid) {
LstObj(ol)->linkUp = FALSE; LstEntry(ol, sOutunit, outunit_l)->linkUp = FALSE;
} }
} }
...@@ -3264,10 +3255,10 @@ static void outunitAborted(sOutunit* op) ...@@ -3264,10 +3255,10 @@ static void outunitAborted(sOutunit* op)
{ {
outunitLog(op, "Outunit aborted"); outunitLog(op, "Outunit aborted");
LstRem(&op->outunit_l); /* Remove from outunit list */ LstRemove(&op->outunit_l); /* Remove from outunit list */
LstNul(&op->outunit_l); LstNull(&op->outunit_l);
LstRem(&op->link.proc_l); /* Remove from process link */ LstRemove(&op->link.proc_l); /* Remove from process link */
LstNul(&op->link.proc_l); LstNull(&op->link.proc_l);
free(op); /* Free control block */ free(op); /* Free control block */
} }
...@@ -3340,15 +3331,15 @@ static void outunitBlock(mh_sHead* hp, sOutunit* op) ...@@ -3340,15 +3331,15 @@ static void outunitBlock(mh_sHead* hp, sOutunit* op)
sBlock* bp = NULL; sBlock* bp = NULL;
mh_sOutunitBlock* ip = (mh_sOutunitBlock*)(hp + 1); mh_sOutunitBlock* ip = (mh_sOutunitBlock*)(hp + 1);
sEvent* ep; sEvent* ep;
LstLink(sBlock) * bl; struct LstHead * bl;
pwr_tNodeIndex nix; pwr_tNodeIndex nix;
op->blockGen = ip->blockGen; op->blockGen = ip->blockGen;
sendToOutunit(op, mh_eMsg_Sync, 0, 0, NULL, 0); sendToOutunit(op, mh_eMsg_Sync, 0, 0, NULL, 0);
for (bl = LstFir(&l.block_l); bl != LstEnd(&l.block_l); bl = LstNex(bl)) LstForEach(bl, &l.block_l)
if (cdh_ObjidIsEqual(ip->object, LstObj(bl)->link.object.Objid)) if (cdh_ObjidIsEqual(ip->object, LstEntry(bl, sBlock, block_l)->link.object.Objid))
bp = LstObj(bl); bp = LstEntry(bl, sBlock, block_l);
if (bp == NULL) { if (bp == NULL) {
sts = gdh_GetObjectNodeIndex(ip->object, &nix); sts = gdh_GetObjectNodeIndex(ip->object, &nix);
...@@ -3473,10 +3464,10 @@ static void outunitDisconnect(mh_sHead* hp, sOutunit* op) ...@@ -3473,10 +3464,10 @@ static void outunitDisconnect(mh_sHead* hp, sOutunit* op)
{ {
outunitLog(op, "Outunit disconnected"); outunitLog(op, "Outunit disconnected");
LstRem(&op->outunit_l); /* Remove from outunit list */ LstRemove(&op->outunit_l); /* Remove from outunit list */
LstNul(&op->outunit_l); LstNull(&op->outunit_l);
LstRem(&op->link.proc_l); /* Remove from process link */ LstRemove(&op->link.proc_l); /* Remove from process link */
LstNul(&op->link.proc_l); LstNull(&op->link.proc_l);
free(op); /* Free control block */ free(op); /* Free control block */
} }
...@@ -3511,14 +3502,14 @@ static void outunitAlarmReq(mh_sHead* hp, sOutunit* op) ...@@ -3511,14 +3502,14 @@ static void outunitAlarmReq(mh_sHead* hp, sOutunit* op)
{ {
mh_sOutunitAlarmReq* msg = (mh_sOutunitAlarmReq*)(hp + 1); mh_sOutunitAlarmReq* msg = (mh_sOutunitAlarmReq*)(hp + 1);
int i; int i;
LstLink(sActive) * al; struct LstHead * al;
sActive* ap; sActive* ap;
int ok; int ok;
/* Find events in active list */ /* Find events in active list */
for (i = 0; i < msg->Count; i++) { for (i = 0; i < msg->Count; i++) {
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); al = LstNex(al)) { LstForEach(al, &l.active_l) {
ap = LstObj(al); ap = LstEntry(al, sActive, active_l);
if (ap->idx == msg->Idx[i]) { if (ap->idx == msg->Idx[i]) {
if (!ap->detect_etp->ap) if (!ap->detect_etp->ap)
...@@ -3543,19 +3534,19 @@ static void outunitAlarmReq(mh_sHead* hp, sOutunit* op) ...@@ -3543,19 +3534,19 @@ static void outunitAlarmReq(mh_sHead* hp, sOutunit* op)
static void procDown(qcom_sAid* aid) static void procDown(qcom_sAid* aid)
{ {
LstLink(sProcLink) * pl; struct LstHead * pl;
for (pl = LstFir(&l.proc_l); pl != LstEnd(&l.proc_l); pl = LstNex(pl)) LstForEach(pl, &l.proc_l)
if (LstObj(pl)->aid.nid == aid->nid && LstObj(pl)->aid.aix == aid->aix) { if (LstEntry(pl, sProcLink, proc_l)->aid.nid == aid->nid && LstEntry(pl, sProcLink, proc_l)->aid.aix == aid->aix) {
switch (LstObj(pl)->source) { switch (LstEntry(pl, sProcLink, proc_l)->source) {
case mh_eSource_Outunit: case mh_eSource_Outunit:
outunitAborted((sOutunit*)LstObj(pl)); outunitAborted((sOutunit*)LstEntry(pl, sProcLink, proc_l));
break; break;
case mh_eSource_Application: case mh_eSource_Application:
break; break;
default: default:
errh_Error( errh_Error(
"procDown, programming error, source: %d", LstObj(pl)->source); "procDown, programming error, source: %d", LstEntry(pl, sProcLink, proc_l)->source);
break; break;
} }
return; return;
...@@ -3585,7 +3576,7 @@ static void receive(qcom_sQid myQ) ...@@ -3585,7 +3576,7 @@ static void receive(qcom_sQid myQ)
if (l.redu && l.nodep->RedundancyState == pwr_eRedundancyState_Passive) { if (l.redu && l.nodep->RedundancyState == pwr_eRedundancyState_Passive) {
if (l.supListState == eSupListState_Init) { if (l.supListState == eSupListState_Init) {
initSupList(); initSupList();
if (!LstEmp(&l.sup_l)) if (!LstEmpty(&l.sup_l))
l.supListState = eSupListState_Scan; l.supListState = eSupListState_Scan;
else else
l.supListState = eSupListState_NoSup; l.supListState = eSupListState_NoSup;
...@@ -3645,12 +3636,12 @@ static void receive(qcom_sQid myQ) ...@@ -3645,12 +3636,12 @@ static void receive(qcom_sQid myQ)
static void reInitSupList() static void reInitSupList()
{ {
pwr_tStatus sts; pwr_tStatus sts;
LstLink(sSupActive) * sl; struct LstHead * sl;
sSupActive* sp; sSupActive* sp;
sActive* ap; sActive* ap;
for (sl = LstFir(&l.sup_l); sl != LstEnd(&l.sup_l); sl = LstNex(sl)) LstForEach(sl, &l.sup_l)
LstObj(sl)->found = FALSE; LstEntry(sl, sSupActive, sup_l)->found = FALSE;
sts = reInitSupListClass(pwr_cClass_ASup); sts = reInitSupListClass(pwr_cClass_ASup);
if (EVEN(sts)) if (EVEN(sts))
...@@ -3668,26 +3659,26 @@ static void reInitSupList() ...@@ -3668,26 +3659,26 @@ static void reInitSupList()
if (EVEN(sts)) if (EVEN(sts))
errh_Error("Reinitialize list of CycleSup's\n%m", sts); errh_Error("Reinitialize list of CycleSup's\n%m", sts);
for (sl = LstFir(&l.sup_l); sl != LstEnd(&l.sup_l); sl = LstNex(sl)) { LstForEach(sl, &l.sup_l) {
sp = LstObj(sl); sp = LstEntry(sl, sSupActive, sup_l);
if (!sp->found) { if (!sp->found) {
if ((ap = activeListGet(sp->link.idx)) != NULL) if ((ap = activeListGet(sp->link.idx)) != NULL)
cancelAlarm(ap, cText_Restart); cancelAlarm(ap, cText_Restart);
sl = LstPre(&sp->sup_l); sl = sp->sup_l.prev;
LstRem(&sp->sup_l); LstRemove(&sp->sup_l);
LstNul(&sp->sup_l); LstNull(&sp->sup_l);
l.emon->BlockMaxCount--; l.emon->BlockMaxCount--;
gdh_DLUnrefObjectInfo(sp->supDlid); gdh_DLUnrefObjectInfo(sp->supDlid);
if (sp->agent == mh_eAgent_MH) { if (sp->agent == mh_eAgent_MH) {
gdh_DLUnrefObjectInfo(sp->attrDlid); gdh_DLUnrefObjectInfo(sp->attrDlid);
if (LstInl(&sp->timer_l)) { if (!LstIsNull(&sp->timer_l)) {
LstRem(&sp->timer_l); LstRemove(&sp->timer_l);
LstNul(&sp->timer_l); LstNull(&sp->timer_l);
l.emon->EventLastIdx--; l.emon->EventLastIdx--;
} }
LstRem(&sp->detect_l); LstRemove(&sp->detect_l);
LstNul(&sp->detect_l); LstNull(&sp->detect_l);
l.emon->EventFirstIdx--; l.emon->EventFirstIdx--;
} }
free(sp); free(sp);
...@@ -3698,13 +3689,13 @@ static void reInitSupList() ...@@ -3698,13 +3689,13 @@ static void reInitSupList()
static pwr_tStatus reInitSupListClass(pwr_tClassId cid) static pwr_tStatus reInitSupListClass(pwr_tClassId cid)
{ {
pwr_tStatus sts; pwr_tStatus sts;
LstLink(sSupActive) * sl; struct LstHead * sl;
LstLink(sSupActive) * dl; struct LstHead * dl;
sSupActive* sp; sSupActive* sp;
pwr_tAttrRef aref; pwr_tAttrRef aref;
dl = LstEnd(&l.detect_l); dl = &l.detect_l;
sl = LstEnd(&l.sup_l); sl = &l.sup_l;
/* Loop through objects in class list. */ /* Loop through objects in class list. */
...@@ -3716,11 +3707,13 @@ static pwr_tStatus reInitSupListClass(pwr_tClassId cid) ...@@ -3716,11 +3707,13 @@ static pwr_tStatus reInitSupListClass(pwr_tClassId cid)
if ((sp = supListGet(&aref)) == NULL) { if ((sp = supListGet(&aref)) == NULL) {
sts = initSupActiveCB(&aref, cid, &sp, 1, 1); sts = initSupActiveCB(&aref, cid, &sp, 1, 1);
if (ODD(sts)) { if (ODD(sts)) {
sl = LstIns(sl, sp, sup_l); LstInsert(sl, &sp->sup_l);
sl = &sp->sup_l;
l.emon->BlockMaxCount++; l.emon->BlockMaxCount++;
sp->found = TRUE; sp->found = TRUE;
if (sp->agent == mh_eAgent_MH) { if (sp->agent == mh_eAgent_MH) {
dl = LstIns(dl, sp, detect_l); LstInsert(dl, &sp->detect_l);
dl = &sp->detect_l;
l.emon->EventFirstIdx++; l.emon->EventFirstIdx++;
} }
} }
...@@ -3800,7 +3793,7 @@ static void saveBlockList() ...@@ -3800,7 +3793,7 @@ static void saveBlockList()
{ {
unsigned long size; unsigned long size;
sSaveBlock* sp; sSaveBlock* sp;
LstLink(sBlock) * bl; struct LstHead * bl;
sBlock* bp; sBlock* bp;
if (l.blockDb == NULL) if (l.blockDb == NULL)
...@@ -3816,12 +3809,14 @@ static void saveBlockList() ...@@ -3816,12 +3809,14 @@ static void saveBlockList()
} }
} }
for (bl = LstFir(&l.block_l), sp = l.blockSave, size = 0; sp = l.blockSave;
bl != LstEnd(&l.block_l); size = 0;
bl = LstNex(bl), sp++, size += sizeof(sSaveBlock)) { LstForEach(bl, &l.block_l) {
bp = LstObj(bl); bp = LstEntry(bl, sBlock, block_l);
sp->outunitBlock = bp->outunitBlock; sp->outunitBlock = bp->outunitBlock;
sp->targetId = bp->targetId; sp->targetId = bp->targetId;
sp++;
size += sizeof(sSaveBlock);
} }
l.blockDb = mh_BlockDbPut(l.blockDb, size, (char*)l.blockSave); l.blockDb = mh_BlockDbPut(l.blockDb, size, (char*)l.blockSave);
...@@ -3829,10 +3824,10 @@ static void saveBlockList() ...@@ -3829,10 +3824,10 @@ static void saveBlockList()
static void scanDetectList() static void scanDetectList()
{ {
LstLink(sSupActive) * dl; struct LstHead * dl;
for (dl = LstFir(&l.detect_l); dl != LstEnd(&l.detect_l); dl = LstNex(dl)) { LstForEach(dl, &l.detect_l) {
sSupActive* sp = LstObj(dl); sSupActive* sp = LstEntry(dl, sSupActive, detect_l);
if (sp->detect_exec != NULL) if (sp->detect_exec != NULL)
sp->detect_exec(sp); sp->detect_exec(sp);
} }
...@@ -3843,10 +3838,10 @@ static void scanSupList() ...@@ -3843,10 +3838,10 @@ static void scanSupList()
pwr_tStatus sts; pwr_tStatus sts;
mh_uEventInfo AlarmVisibility; mh_uEventInfo AlarmVisibility;
sSupActive* sp; sSupActive* sp;
LstLink(sSupActive) * sl; struct LstHead * sl;
for (sl = LstFir(&l.sup_l); sl != LstEnd(&l.sup_l); sl = LstNex(sl)) { LstForEach(sl, &l.sup_l) {
sp = LstObj(sl); sp = LstEntry(sl, sSupActive, sup_l);
if (l.newBlock) { if (l.newBlock) {
sts = gdh_GetAlarmInfo( sts = gdh_GetAlarmInfo(
sp->link.object.Objid, NULL, NULL, NULL, NULL, &AlarmVisibility.All); sp->link.object.Objid, NULL, NULL, NULL, NULL, &AlarmVisibility.All);
...@@ -3894,17 +3889,17 @@ static void scanSupList() ...@@ -3894,17 +3889,17 @@ static void scanSupList()
static void scanTimerList() static void scanTimerList()
{ {
LstLink(sSupActive) * sl, *nsl; struct LstHead * sl, *nsl;
sTimer* tp; sTimer* tp;
for (sl = LstFir(&l.timer_l); sl != LstEnd(&l.timer_l); sl = nsl) { for (sl = l.timer_l.next; sl != &l.timer_l; sl = nsl) {
tp = LstObj(sl)->timer; tp = LstEntry(sl, sSupActive, timer_l)->timer;
nsl = LstNex(sl); nsl = sl->next;
if (tp->TimerCount <= 1 || !tp->TimerFlag) { if (tp->TimerCount <= 1 || !tp->TimerFlag) {
tp->TimerCount = 0; tp->TimerCount = 0;
tp->TimerFlag = FALSE; tp->TimerFlag = FALSE;
LstRem(sl); LstRemove(sl);
LstNul(sl); LstNull(sl);
l.emon->EventLastIdx--; l.emon->EventLastIdx--;
} else { } else {
tp->TimerCount--; tp->TimerCount--;
...@@ -4102,10 +4097,10 @@ static void setTimerActive(int timerIdx, pwr_tBoolean active) ...@@ -4102,10 +4097,10 @@ static void setTimerActive(int timerIdx, pwr_tBoolean active)
static sSupActive* supListGet(pwr_tAttrRef* arp) static sSupActive* supListGet(pwr_tAttrRef* arp)
{ {
LstLink(sSupActive) * sl; struct LstHead * sl;
for (sl = LstFir(&l.sup_l); sl != LstEnd(&l.sup_l); sl = LstNex(sl)) { LstForEach(sl, &l.sup_l) {
sSupActive* sp = LstObj(sl); sSupActive* sp = LstEntry(sl, sSupActive, sup_l);
if (cdh_ArefIsEqual(&sp->link.supObject, arp)) if (cdh_ArefIsEqual(&sp->link.supObject, arp))
return sp; return sp;
...@@ -4135,9 +4130,9 @@ static void timeOut() ...@@ -4135,9 +4130,9 @@ static void timeOut()
} else if (l.supListState == eSupListState_Init) { } else if (l.supListState == eSupListState_Init) {
if (qcom_EventMask(NULL, &qcom_cQini) & ini_mEvent_newPlcStartDone) { if (qcom_EventMask(NULL, &qcom_cQini) & ini_mEvent_newPlcStartDone) {
initSupList(); initSupList();
if (!LstEmp(&l.sup_l)) { if (!LstEmpty(&l.sup_l)) {
l.supListState = eSupListState_Scan; l.supListState = eSupListState_Scan;
if (!LstEmp(&l.detect_l)) { if (!LstEmpty(&l.detect_l)) {
scanTimerList(); scanTimerList();
scanDetectList(); scanDetectList();
setTimerActive(cDetectIdx, TRUE); setTimerActive(cDetectIdx, TRUE);
...@@ -4176,8 +4171,8 @@ static void timerIn(sSupActive* s, sTimer* t) ...@@ -4176,8 +4171,8 @@ static void timerIn(sSupActive* s, sTimer* t)
{ {
t->TimerCount = t->TimerTime / l.detectTimerTime; t->TimerCount = t->TimerTime / l.detectTimerTime;
if (!t->TimerFlag && t->TimerCount > 0) { if (!t->TimerFlag && t->TimerCount > 0) {
if (!LstInl(&s->timer_l)) { if (LstIsNull(&s->timer_l)) {
LstIns(&l.timer_l, s, timer_l); LstInsert(&l.timer_l, &s->timer_l);
l.emon->EventLastIdx++; l.emon->EventLastIdx++;
} }
t->TimerFlag = TRUE; t->TimerFlag = TRUE;
...@@ -4278,7 +4273,7 @@ static void updateAlarm(sActive* ap, sEvent* ep) ...@@ -4278,7 +4273,7 @@ static void updateAlarm(sActive* ap, sEvent* ep)
static void updateAlarmInfo(sActive* iap) static void updateAlarmInfo(sActive* iap)
{ {
sActive* ap; sActive* ap;
LstLink(sActive) * al; struct LstHead * al;
mh_uEventInfo maxAlarm; mh_uEventInfo maxAlarm;
if (cdh_ObjidIsEqual(iap->object.Objid, if (cdh_ObjidIsEqual(iap->object.Objid,
...@@ -4287,8 +4282,8 @@ static void updateAlarmInfo(sActive* iap) ...@@ -4287,8 +4282,8 @@ static void updateAlarmInfo(sActive* iap)
/* Search alarm list for ocurrence of object */ /* Search alarm list for ocurrence of object */
maxAlarm.All = 0; maxAlarm.All = 0;
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); al = LstNex(al)) { LstForEach(al, &l.active_l) {
ap = LstObj(al); ap = LstEntry(al, sActive, active_l);
if (cdh_ArefIsEqual(&iap->object, &ap->object)) if (cdh_ArefIsEqual(&iap->object, &ap->object))
if (ap->event == mh_eEvent_Alarm if (ap->event == mh_eEvent_Alarm
|| ap->event == mh_eEvent_MaintenanceAlarm || ap->event == mh_eEvent_MaintenanceAlarm
...@@ -4315,7 +4310,7 @@ static void updateSupActive(sSupActive* sp) ...@@ -4315,7 +4310,7 @@ static void updateSupActive(sSupActive* sp)
mh_eAgent agent; mh_eAgent agent;
pwr_tClassId cid = 0; pwr_tClassId cid = 0;
pwr_tBoolean newAttribute; pwr_tBoolean newAttribute;
LstLink(sSupActive)* dl = LstEnd(&l.detect_l); struct LstHead* dl = &l.detect_l;
/* Get pointer to supervisory object */ /* Get pointer to supervisory object */
...@@ -4373,15 +4368,15 @@ static void updateSupActive(sSupActive* sp) ...@@ -4373,15 +4368,15 @@ static void updateSupActive(sSupActive* sp)
sp->found = TRUE; sp->found = TRUE;
if (sp->agent != agent) { if (sp->agent != agent) {
if (sp->agent == mh_eAgent_MH) { if (sp->agent == mh_eAgent_MH) {
LstIns(dl, sp, detect_l); LstInsert(dl, &sp->detect_l);
l.emon->EventFirstIdx++; l.emon->EventFirstIdx++;
} else { } else {
LstRem(&sp->detect_l); LstRemove(&sp->detect_l);
LstNul(&sp->detect_l); LstNull(&sp->detect_l);
l.emon->EventFirstIdx--; l.emon->EventFirstIdx--;
if (LstInl(&sp->timer_l)) { if (!LstIsNull(&sp->timer_l)) {
LstRem(&sp->timer_l); LstRemove(&sp->timer_l);
LstNul(&sp->timer_l); LstNull(&sp->timer_l);
l.emon->EventLastIdx--; l.emon->EventLastIdx--;
} }
} }
...@@ -4570,7 +4565,7 @@ static pwr_tStatus emon_redu_send() ...@@ -4570,7 +4565,7 @@ static pwr_tStatus emon_redu_send()
{ {
pwr_tStatus sts; pwr_tStatus sts;
void* msg; void* msg;
LstLink(sActive) * al; struct LstHead * al;
sActive* ap; sActive* ap;
sSupActive* sp; sSupActive* sp;
int size; int size;
...@@ -4582,19 +4577,19 @@ static pwr_tStatus emon_redu_send() ...@@ -4582,19 +4577,19 @@ static pwr_tStatus emon_redu_send()
redu_sEvEventList* eventlistp; redu_sEvEventList* eventlistp;
redu_sEvEvent* eventp; redu_sEvEvent* eventp;
sOutunit* op; sOutunit* op;
LstLink(sOutunit) * ol; struct LstHead * ol;
sEvent* ep; sEvent* ep;
int i; int i;
// Count active // Count active
active_cnt = 0; active_cnt = 0;
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); al = LstNex(al)) LstForEach(al, &l.active_l)
active_cnt++; active_cnt++;
// Count outunits // Count outunits
outunit_cnt = 0; outunit_cnt = 0;
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); ol = LstNex(ol)) { LstForEach(ol, &l.outunit_l) {
op = LstObj(ol); op = LstEntry(ol, sOutunit, outunit_l);
if (op->outunit.vid != l.nodeObject.vid) if (op->outunit.vid != l.nodeObject.vid)
outunit_cnt++; outunit_cnt++;
...@@ -4615,8 +4610,8 @@ static pwr_tStatus emon_redu_send() ...@@ -4615,8 +4610,8 @@ static pwr_tStatus emon_redu_send()
((redu_sEvMsgHeader*)msg)->events = event_cnt; ((redu_sEvMsgHeader*)msg)->events = event_cnt;
activep = (redu_sEvActive*)((char*)msg + sizeof(redu_sEvMsgHeader)); activep = (redu_sEvActive*)((char*)msg + sizeof(redu_sEvMsgHeader));
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); al = LstNex(al)) { LstForEach(al, &l.active_l) {
ap = LstObj(al); ap = LstEntry(al, sActive, active_l);
activep->idx = ap->idx; activep->idx = ap->idx;
activep->returnIdx = ap->returnIdx; activep->returnIdx = ap->returnIdx;
...@@ -4656,8 +4651,8 @@ static pwr_tStatus emon_redu_send() ...@@ -4656,8 +4651,8 @@ static pwr_tStatus emon_redu_send()
/* Outunits, only remote */ /* Outunits, only remote */
outunitp = (redu_sEvOutunit*)activep; outunitp = (redu_sEvOutunit*)activep;
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l); ol = LstNex(ol)) { LstForEach(ol, &l.outunit_l) {
op = LstObj(ol); op = LstEntry(ol, sOutunit, outunit_l);
if (op->outunit.vid != l.nodeObject.vid) { if (op->outunit.vid != l.nodeObject.vid) {
outunitp->outunit = op->outunit; outunitp->outunit = op->outunit;
...@@ -4748,12 +4743,12 @@ static pwr_tStatus emon_redu_receive() ...@@ -4748,12 +4743,12 @@ static pwr_tStatus emon_redu_receive()
int outunits; int outunits;
int events; int events;
int i; int i;
LstLink(sActive) * al; struct LstHead * al;
sActive *ap = NULL, *tp; sActive *ap = NULL, *tp;
sSupActive* sp; sSupActive* sp;
sEvent* ep; sEvent* ep;
sOutunit* op; sOutunit* op;
LstLink(sOutunit) * ol; struct LstHead * ol;
int found; int found;
sts = redu_receive(l.redu, timeout, &size, &msg); sts = redu_receive(l.redu, timeout, &size, &msg);
...@@ -4819,8 +4814,8 @@ static pwr_tStatus emon_redu_receive() ...@@ -4819,8 +4814,8 @@ static pwr_tStatus emon_redu_receive()
/* Active list */ /* Active list */
/* Find removed elements in active list */ /* Find removed elements in active list */
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); al = LstNex(al)) { LstForEach(al, &l.active_l) {
ap = LstObj(al); ap = LstEntry(al, sActive, active_l);
if (ap->source == mh_eSource_Scanner if (ap->source == mh_eSource_Scanner
|| ap->source == mh_eSource_Handler) { || ap->source == mh_eSource_Handler) {
sp = (sSupActive*)ap; sp = (sSupActive*)ap;
...@@ -4832,9 +4827,8 @@ static pwr_tStatus emon_redu_receive() ...@@ -4832,9 +4827,8 @@ static pwr_tStatus emon_redu_receive()
for (i = 0; i < actives; i++) { for (i = 0; i < actives; i++) {
if (activep->source == mh_eSource_Scanner if (activep->source == mh_eSource_Scanner
|| activep->source == mh_eSource_Handler) { || activep->source == mh_eSource_Handler) {
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); LstForEach(al, &l.active_l) {
al = LstNex(al)) { ap = LstEntry(al, sActive, active_l);
ap = LstObj(al);
if ((activep->source == mh_eSource_Scanner if ((activep->source == mh_eSource_Scanner
|| activep->source == mh_eSource_Handler) || activep->source == mh_eSource_Handler)
&& cdh_ArefIsEqual(&activep->supObject, &ap->supObject)) { && cdh_ArefIsEqual(&activep->supObject, &ap->supObject)) {
...@@ -4847,9 +4841,9 @@ static pwr_tStatus emon_redu_receive() ...@@ -4847,9 +4841,9 @@ static pwr_tStatus emon_redu_receive()
activep++; activep++;
} }
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l);) { for (al = l.active_l.next; al != &l.active_l;) {
ap = LstObj(al); ap = LstEntry(al, sActive, active_l);
al = LstNex(al); al = al->next;
if (ap->source == mh_eSource_Scanner if (ap->source == mh_eSource_Scanner
|| ap->source == mh_eSource_Handler) { || ap->source == mh_eSource_Handler) {
sp = (sSupActive*)ap; sp = (sSupActive*)ap;
...@@ -4875,9 +4869,8 @@ static pwr_tStatus emon_redu_receive() ...@@ -4875,9 +4869,8 @@ static pwr_tStatus emon_redu_receive()
found = 0; found = 0;
if (activep->source == mh_eSource_Scanner if (activep->source == mh_eSource_Scanner
|| activep->source == mh_eSource_Handler) { || activep->source == mh_eSource_Handler) {
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); LstForEach(al, &l.active_l) {
al = LstNex(al)) { ap = LstEntry(al, sActive, active_l);
ap = LstObj(al);
if ((activep->source == mh_eSource_Scanner if ((activep->source == mh_eSource_Scanner
|| activep->source == mh_eSource_Handler) || activep->source == mh_eSource_Handler)
&& cdh_ArefIsEqual(&activep->supObject, &ap->supObject)) { && cdh_ArefIsEqual(&activep->supObject, &ap->supObject)) {
...@@ -4896,9 +4889,8 @@ static pwr_tStatus emon_redu_receive() ...@@ -4896,9 +4889,8 @@ static pwr_tStatus emon_redu_receive()
activep++; activep++;
continue; continue;
} }
for (al = LstFir(&l.active_l); al != LstEnd(&l.active_l); LstForEach(al, &l.active_l) {
al = LstNex(al)) { tp = LstEntry(al, sActive, active_l);
tp = LstObj(al);
if (ap == tp) if (ap == tp)
/* Already in active list */ /* Already in active list */
found = 1; found = 1;
...@@ -4956,8 +4948,8 @@ static pwr_tStatus emon_redu_receive() ...@@ -4956,8 +4948,8 @@ static pwr_tStatus emon_redu_receive()
continue; continue;
} }
if (!found) { if (!found) {
LstLink(sActive) * al; struct LstHead * al;
LstLink(sBlock) * bl; struct LstHead * bl;
// printf( "Active add, idx %d %s\n", ap->detect_etp->idx, // printf( "Active add, idx %d %s\n", ap->detect_etp->idx,
// ap->detect_etp->ep ? ap->detect_etp->ep->objName : ""); // ap->detect_etp->ep ? ap->detect_etp->ep->objName : "");
...@@ -4972,8 +4964,8 @@ static pwr_tStatus emon_redu_receive() ...@@ -4972,8 +4964,8 @@ static pwr_tStatus emon_redu_receive()
//} //}
/* Insert in active list */ /* Insert in active list */
al = LstEnd(&l.active_l); al = &l.active_l;
LstIns(al, ap, active_l); LstInsert(al, &ap->active_l);
switch (ap->event) { switch (ap->event) {
case mh_eEvent_Alarm: case mh_eEvent_Alarm:
...@@ -4987,8 +4979,8 @@ static pwr_tStatus emon_redu_receive() ...@@ -4987,8 +4979,8 @@ static pwr_tStatus emon_redu_receive()
break; break;
case mh_eEvent_Block: case mh_eEvent_Block:
case mh_eEvent_Reblock: case mh_eEvent_Reblock:
bl = LstEnd(&l.block_l); bl = &l.block_l;
LstIns(bl, (sBlock*)ap, block_l); LstInsert(bl, &((sBlock*)ap)->block_l);
++l.emon->BlockCount; ++l.emon->BlockCount;
break; break;
case mh_eEvent_Info: case mh_eEvent_Info:
...@@ -5012,9 +5004,9 @@ static pwr_tStatus emon_redu_receive() ...@@ -5012,9 +5004,9 @@ static pwr_tStatus emon_redu_receive()
outunit_start = (redu_sEvOutunit*)activep; outunit_start = (redu_sEvOutunit*)activep;
/* Remove outunits */ /* Remove outunits */
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l);) { for (ol = l.outunit_l.next; ol != &l.outunit_l;) {
op = LstObj(ol); op = LstEntry(ol, sOutunit, outunit_l);
ol = LstNex(ol); ol = ol->next;
if (op->outunit.vid == l.nodeObject.vid) if (op->outunit.vid == l.nodeObject.vid)
continue; continue;
...@@ -5038,9 +5030,9 @@ static pwr_tStatus emon_redu_receive() ...@@ -5038,9 +5030,9 @@ static pwr_tStatus emon_redu_receive()
outunitp = outunit_start; outunitp = outunit_start;
for (i = 0; i < outunits; i++) { for (i = 0; i < outunits; i++) {
found = 0; found = 0;
for (ol = LstFir(&l.outunit_l); ol != LstEnd(&l.outunit_l);) { for (ol = l.outunit_l.next; ol != &l.outunit_l;) {
op = LstObj(ol); op = LstEntry(ol, sOutunit, outunit_l);
ol = LstNex(ol); ol = ol->next;
if (cdh_ObjidIsEqual(outunitp->outunit, op->outunit)) { if (cdh_ObjidIsEqual(outunitp->outunit, op->outunit)) {
found = 1; found = 1;
...@@ -5087,9 +5079,9 @@ static pwr_tStatus emon_redu_receive() ...@@ -5087,9 +5079,9 @@ static pwr_tStatus emon_redu_receive()
op->selSize = outunitp->selSize; op->selSize = outunitp->selSize;
memcpy(op->sel_l, outunitp->sel_l, sizeof(op->sel_l)); memcpy(op->sel_l, outunitp->sel_l, sizeof(op->sel_l));
/* Insert in outunit list */ /* Insert in outunit list */
LstIns(&l.outunit_l, op, outunit_l); LstInsert(&l.outunit_l, &op->outunit_l);
/* Insert in process list */ /* Insert in process list */
LstIns(&l.proc_l, op, link.proc_l); LstInsert(&l.proc_l, &op->link.proc_l);
op->linkUp = TRUE; op->linkUp = TRUE;
outunitLog(op, "New outunit"); outunitLog(op, "New outunit");
printf("Outunit added, (%d,%d)\n", op->outunit.oix, op->outunit.vid); printf("Outunit added, (%d,%d)\n", op->outunit.oix, op->outunit.vid);
......
...@@ -69,11 +69,9 @@ typedef enum { eTimer_ScanMessage = 1 } eTimer; ...@@ -69,11 +69,9 @@ typedef enum { eTimer_ScanMessage = 1 } eTimer;
typedef struct s_Node sNode; typedef struct s_Node sNode;
LstType(sNode);
struct s_Node { struct s_Node {
LstLink(sNode) node_l; struct LstHead node_l;
LstLink(sNode) timer_l; struct LstHead timer_l;
pwr_tObjid oid; pwr_tObjid oid;
pwr_sClass_NodeLinkSup node; pwr_sClass_NodeLinkSup node;
pwr_sClass_NodeLinkSup* o; pwr_sClass_NodeLinkSup* o;
...@@ -84,8 +82,8 @@ struct s_Node { ...@@ -84,8 +82,8 @@ struct s_Node {
}; };
static eListState list_state = eListState_Init; static eListState list_state = eListState_Init;
static LstHead(sNode) node_l; static struct LstHead node_l;
static LstHead(sNode) timer_l; static struct LstHead timer_l;
static void detect(pwr_sClass_NodeLinkSup*, pwr_tBoolean, sNode*); static void detect(pwr_sClass_NodeLinkSup*, pwr_tBoolean, sNode*);
static void event(qcom_sGet*); static void event(qcom_sGet*);
...@@ -137,11 +135,11 @@ int main(int argc, char** argv) ...@@ -137,11 +135,11 @@ int main(int argc, char** argv)
plc_UtlWaitForPlc(); plc_UtlWaitForPlc();
LstIni(&node_l); LstInit(&node_l);
LstIni(&timer_l); LstInit(&timer_l);
init_nodes(); init_nodes();
if (!LstEmp(&node_l)) { if (!LstEmpty(&node_l)) {
list_state = eListState_Scan; list_state = eListState_Scan;
} else { } else {
errh_Info("No nodes to supervise, exiting"); errh_Info("No nodes to supervise, exiting");
...@@ -195,8 +193,8 @@ static void detect(pwr_sClass_NodeLinkSup* o, pwr_tBoolean con, sNode* np) ...@@ -195,8 +193,8 @@ static void detect(pwr_sClass_NodeLinkSup* o, pwr_tBoolean con, sNode* np)
if (o->DetectCheck) { if (o->DetectCheck) {
o->TimerCount = (o->TimerTime * 1000) / cTimerTimeDetect; o->TimerCount = (o->TimerTime * 1000) / cTimerTimeDetect;
if (!o->TimerFlag && o->TimerCount > 0) { if (!o->TimerFlag && o->TimerCount > 0) {
if (!LstInl(&np->timer_l)) { if (LstIsNull(&np->timer_l)) {
LstIns(&timer_l, np, timer_l); LstInsert(&timer_l, &np->timer_l);
} }
o->TimerFlag = TRUE; o->TimerFlag = TRUE;
} }
...@@ -229,7 +227,7 @@ static void event(qcom_sGet* get) ...@@ -229,7 +227,7 @@ static void event(qcom_sGet* get)
if (new_event.b.swapDone & !cur_event.b.swapDone) { if (new_event.b.swapDone & !cur_event.b.swapDone) {
errh_Info("Warm restart completed."); errh_Info("Warm restart completed.");
reinit_nodes(); reinit_nodes();
if (!LstEmp(&node_l)) { if (!LstEmpty(&node_l)) {
list_state = eListState_Scan; list_state = eListState_Scan;
scan_timers(); scan_timers();
scan_nodes(); scan_nodes();
...@@ -322,21 +320,22 @@ static sNode* init_node(pwr_tObjid oid, sNode* np, pwr_tBoolean new_sub) ...@@ -322,21 +320,22 @@ static sNode* init_node(pwr_tObjid oid, sNode* np, pwr_tBoolean new_sub)
static pwr_tStatus init_nodes() static pwr_tStatus init_nodes()
{ {
pwr_tStatus sts; pwr_tStatus sts;
LstLink(sNode) * nl; struct LstHead * nl;
sNode* np; sNode* np;
pwr_tObjid oid; pwr_tObjid oid;
nl = LstEnd(&node_l); nl = &node_l;
for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts); for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) { sts = gdh_GetNextObject(oid, &oid)) {
np = init_node(oid, NULL, 1); np = init_node(oid, NULL, 1);
if (np != NULL) { if (np != NULL) {
nl = LstIns(nl, np, node_l); LstInsert(nl, &np->node_l);
nl = &np->node_l;
} }
} }
if (LstEmp(&node_l)) if (LstEmpty(&node_l))
errh_Info("No NodeLink objects"); errh_Info("No NodeLink objects");
return (sts); return (sts);
...@@ -346,11 +345,11 @@ static pwr_tStatus init_nodes() ...@@ -346,11 +345,11 @@ static pwr_tStatus init_nodes()
static sNode* get_nodes(pwr_tObjid oid) static sNode* get_nodes(pwr_tObjid oid)
{ {
LstLink(sNode) * nl; struct LstHead * nl;
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { LstForEach(nl, &node_l) {
if (cdh_ObjidIsEqual(LstObj(nl)->oid, oid)) if (cdh_ObjidIsEqual(LstEntry(nl, sNode, node_l)->oid, oid))
return LstObj(nl); return LstEntry(nl, sNode, node_l);
} }
return NULL; return NULL;
...@@ -359,20 +358,21 @@ static sNode* get_nodes(pwr_tObjid oid) ...@@ -359,20 +358,21 @@ static sNode* get_nodes(pwr_tObjid oid)
static void reinit_nodes() static void reinit_nodes()
{ {
pwr_tStatus sts; pwr_tStatus sts;
LstLink(sNode) * nl; struct LstHead * nl;
sNode* np; sNode* np;
pwr_tObjid oid; pwr_tObjid oid;
/* Mark all links in the NodeLink list */ /* Mark all links in the NodeLink list */
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) LstForEach(nl, &node_l)
LstObj(nl)->found = FALSE; LstEntry(nl, sNode, node_l)->found = FALSE;
for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts); for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) { sts = gdh_GetNextObject(oid, &oid)) {
if ((np = get_nodes(oid)) == NULL) { if ((np = get_nodes(oid)) == NULL) {
np = init_node(oid, NULL, 1); np = init_node(oid, NULL, 1);
if (np != NULL) { if (np != NULL) {
nl = LstIns(nl, np, node_l); LstInsert(nl, &np->node_l);
nl = &np->node_l;
np->found = TRUE; np->found = TRUE;
} }
} else { } else {
...@@ -380,12 +380,12 @@ static void reinit_nodes() ...@@ -380,12 +380,12 @@ static void reinit_nodes()
} }
} }
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { LstForEach(nl, &node_l) {
np = LstObj(nl); np = LstEntry(nl, sNode, node_l);
if (!np->found) { if (!np->found) {
nl = LstPre(&np->node_l); nl = np->node_l.prev;
LstRem(&np->node_l); LstRemove(&np->node_l);
LstNul(&np->node_l); LstNull(&np->node_l);
gdh_SubUnrefObjectInfo(np->o->SubId); gdh_SubUnrefObjectInfo(np->o->SubId);
gdh_DLUnrefObjectInfo(np->dlid); gdh_DLUnrefObjectInfo(np->dlid);
free(np); free(np);
...@@ -395,7 +395,7 @@ static void reinit_nodes() ...@@ -395,7 +395,7 @@ static void reinit_nodes()
static void scan_nodes() static void scan_nodes()
{ {
LstLink(sNode) * nl; struct LstHead * nl;
pwr_tStatus sts; pwr_tStatus sts;
pwr_tBoolean Old; pwr_tBoolean Old;
pwr_tTime LastUpdate, Timeout, CurrentTime; pwr_tTime LastUpdate, Timeout, CurrentTime;
...@@ -404,8 +404,8 @@ static void scan_nodes() ...@@ -404,8 +404,8 @@ static void scan_nodes()
time_GetTime(&CurrentTime); time_GetTime(&CurrentTime);
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { LstForEach(nl, &node_l) {
sNode* np = LstObj(nl); sNode* np = LstEntry(nl, sNode, node_l);
pwr_sClass_NodeLinkSup* o = np->o; pwr_sClass_NodeLinkSup* o = np->o;
LinkUp = 0; LinkUp = 0;
sts = gdh_GetSubscriptionOldness(o->SubId, &Old, &LastUpdate, NULL); sts = gdh_GetSubscriptionOldness(o->SubId, &Old, &LastUpdate, NULL);
...@@ -435,17 +435,17 @@ static void scan_nodes() ...@@ -435,17 +435,17 @@ static void scan_nodes()
static void scan_timers() static void scan_timers()
{ {
LstLink(sNode) * nl, *nxtnl; struct LstHead * nl, *nxtnl;
plc_sTimer* tp; plc_sTimer* tp;
for (nl = LstFir(&timer_l); nl != LstEnd(&timer_l); nl = nxtnl) { for (nl = timer_l.next; nl != &timer_l; nl = nxtnl) {
tp = LstObj(nl)->timer; tp = LstEntry(nl, sNode, timer_l)->timer;
nxtnl = LstNex(nl); nxtnl = nl->next;
if (tp->TimerCount <= 1 || !tp->TimerFlag) { if (tp->TimerCount <= 1 || !tp->TimerFlag) {
tp->TimerCount = 0; tp->TimerCount = 0;
tp->TimerFlag = FALSE; tp->TimerFlag = FALSE;
LstRem(nl); LstRemove(nl);
LstNul(nl); LstNull(nl);
} else { } else {
tp->TimerCount--; tp->TimerCount--;
} }
......
...@@ -57,19 +57,17 @@ ...@@ -57,19 +57,17 @@
typedef struct s_Timer sTimer; typedef struct s_Timer sTimer;
LstType(sTimer);
struct s_Timer { struct s_Timer {
LstLink(sTimer) ll; struct LstHead ll;
time_tClock clock; time_tClock clock;
pwr_tBoolean wrapped; pwr_tBoolean wrapped;
void* data; void* data;
void (*exec)(); void (*exec)();
}; };
static LstHead(sTimer) timer_lh; static struct LstHead timer_lh;
static LstHead(sTimer) wrap_lh; static struct LstHead wrap_lh;
static LstHead(sTimer) free_lh; static struct LstHead free_lh;
static time_tClock now_clock; static time_tClock now_clock;
static time_tClock last_clock; static time_tClock last_clock;
...@@ -104,7 +102,7 @@ static void waitClock(time_tClock c, int* tmo_ms); ...@@ -104,7 +102,7 @@ static void waitClock(time_tClock c, int* tmo_ms);
static void setInterval(time_tClock* c, pwr_tUInt32 i); static void setInterval(time_tClock* c, pwr_tUInt32 i);
static void executeExpired(LstHead(sTimer) * lh, pwr_tBoolean force); static void executeExpired(struct LstHead * lh, pwr_tBoolean force);
static void getNewTimers(); static void getNewTimers();
...@@ -370,16 +368,16 @@ static void cacheTrim(sTimer* tp) ...@@ -370,16 +368,16 @@ static void cacheTrim(sTimer* tp)
static void insertTimer(sTimer* tp) static void insertTimer(sTimer* tp)
{ {
LstLink(sTimer) * tl; struct LstHead * tl;
sTimer* tip; sTimer* tip;
if (LstEmp(&timer_lh)) { if (LstEmpty(&timer_lh)) {
(void)LstIns(LstEnd(&timer_lh), tp, ll); LstInsert(&timer_lh, &tp->ll);
return; return;
} }
for (tl = LstLas(&timer_lh); tl != LstEnd(&timer_lh); tl = LstPre(tl)) { for (tl = timer_lh.prev; tl != &timer_lh; tl = tl->prev) {
tip = LstObj(tl); tip = LstEntry(tl, sTimer, ll);
if (tp->wrapped) { if (tp->wrapped) {
if (!tip->wrapped || tip->clock < tp->clock) if (!tip->wrapped || tip->clock < tp->clock)
...@@ -388,8 +386,8 @@ static void insertTimer(sTimer* tp) ...@@ -388,8 +386,8 @@ static void insertTimer(sTimer* tp)
break; break;
} }
tl = LstNex(tl); tl = tl->next;
(void)LstIns(tl, tp, ll); LstInsert(tl, &tp->ll);
} }
/* . */ /* . */
...@@ -416,7 +414,7 @@ static sTimer* newTimer(time_tClock* clock, void* data, void (*exec)()) ...@@ -416,7 +414,7 @@ static sTimer* newTimer(time_tClock* clock, void* data, void (*exec)())
static void freeTimer(sTimer* tp) static void freeTimer(sTimer* tp)
{ {
memset(tp, 0, sizeof(*tp)); memset(tp, 0, sizeof(*tp));
LstIns(&LstEnd(free_lh), tp, ll); LstInsert(&free_lh, &tp->ll);
} }
/* . */ /* . */
...@@ -425,19 +423,19 @@ static sTimer* allocTimer() ...@@ -425,19 +423,19 @@ static sTimer* allocTimer()
{ {
const int cAllocCount = 100; const int cAllocCount = 100;
sTimer* ftp; sTimer* ftp;
LstLink(sTimer) * ftl; struct LstHead * ftl;
int i; int i;
if (LstEmp(&free_lh)) { if (LstEmpty(&free_lh)) {
ftp = (sTimer*)calloc(cAllocCount, sizeof(sTimer)); ftp = (sTimer*)calloc(cAllocCount, sizeof(sTimer));
for (i = 0; i < cAllocCount; i++, ftp++) { for (i = 0; i < cAllocCount; i++, ftp++) {
LstIns(&LstEnd(free_lh), ftp, ll); LstInsert(&free_lh, &ftp->ll);
} }
} }
ftl = LstFir(&free_lh); ftl = free_lh.next;
LstRem(ftl); LstRemove(ftl);
return LstObj(ftl); return LstEntry(ftl, sTimer, ll);
} }
static void setTimer(sTimer* tp, time_tClock offs) static void setTimer(sTimer* tp, time_tClock offs)
...@@ -498,21 +496,21 @@ static void setInterval(time_tClock* c, ...@@ -498,21 +496,21 @@ static void setInterval(time_tClock* c,
#endif #endif
} }
static void executeExpired(LstHead(sTimer) * lh, pwr_tBoolean force) static void executeExpired(struct LstHead * lh, pwr_tBoolean force)
{ {
LstLink(sTimer) * tl; struct LstHead * tl;
sTimer* tp; sTimer* tp;
gdb_AssumeUnlocked; gdb_AssumeUnlocked;
gdb_ScopeLock gdb_ScopeLock
{ {
for (tl = LstFir(lh); tl != LstEnd(lh); tl = LstFir(lh)) { LstForEach(tl, lh) {
tp = LstObj(tl); tp = LstEntry(tl, sTimer, ll);
if (force || (!tp->wrapped && tp->clock <= now_clock)) { if (force || (!tp->wrapped && tp->clock <= now_clock)) {
LstRem(tl); LstRemove(tl);
LstNul(tl); LstNull(tl);
tp->exec(tp); tp->exec(tp);
} else } else
break; break;
...@@ -560,11 +558,11 @@ static void getNewTimers() ...@@ -560,11 +558,11 @@ static void getNewTimers()
static void getWaitClock(time_tClock* wait_clock, time_tClock last_clock) static void getWaitClock(time_tClock* wait_clock, time_tClock last_clock)
{ {
int diff; int diff;
LstLink(sTimer) * tl; struct LstHead * tl;
sTimer* tp; sTimer* tp;
tl = LstFir(&timer_lh); tl = timer_lh.next;
tp = LstObj(tl); tp = LstEntry(tl, sTimer, ll);
if (now_clock < last_clock) { if (now_clock < last_clock) {
if (tp->wrapped) { if (tp->wrapped) {
...@@ -610,9 +608,9 @@ static void init() ...@@ -610,9 +608,9 @@ static void init()
gdbroot->db->tmon = gdbroot->my_qid; gdbroot->db->tmon = gdbroot->my_qid;
gdbroot->is_tmon = 1; gdbroot->is_tmon = 1;
LstIni(&timer_lh); LstInit(&timer_lh);
LstIni(&wrap_lh); LstInit(&wrap_lh);
LstIni(&free_lh); LstInit(&free_lh);
last_clock = now_clock = time_Clock(NULL, NULL); last_clock = now_clock = time_Clock(NULL, NULL);
...@@ -631,18 +629,18 @@ static void init() ...@@ -631,18 +629,18 @@ static void init()
static void toggleWrapped() static void toggleWrapped()
{ {
LstLink(sTimer) * tl; struct LstHead * tl;
LstLink(sTimer) * ntl; struct LstHead * ntl;
sTimer* tp; sTimer* tp;
LstHead(sTimer)* tlh = &timer_lh; struct LstHead* tlh = &timer_lh;
for (tl = LstFir(tlh); tl != LstEnd(tlh); tl = ntl) { for (tl = tlh->next; tl != tlh; tl = ntl) {
tp = LstObj(tl); tp = LstEntry(tl, sTimer, ll);
ntl = LstNex(tl); ntl = tl->next;
if (!tp->wrapped) { if (!tp->wrapped) {
LstRem(tl); LstRemove(tl);
(void)LstIns(LstEnd(&wrap_lh), tp, ll); LstInsert(&wrap_lh, &tp->ll);
} else } else
tp->wrapped = 0; tp->wrapped = 0;
} }
......
...@@ -40,33 +40,96 @@ ...@@ -40,33 +40,96 @@
/* pwr_lst.h -- list macros /* pwr_lst.h -- list macros
*/ */
#define LstType(a) \ struct LstHead {
typedef struct s_LstLink_##a sLstLink_##a; \ struct LstHead *next, *prev;
struct s_LstLink_##a { \ };
sLstLink_##a* nex; \
sLstLink_##a* pre; \
a* obj; \
}
#define LstLink(a) sLstLink_##a /*
* LstInsert(s_LstLink_T* next, s_LstLink_T elem) inserts the element \a into
* the linked list before the element \a next.
*
* Before:
* a <-> c
*
* Calling LstInsert(c, b)
* a <- b (a <- b)
* b -> c (a <- b -> c)
* a -> b (a <-> b -> c)
* b <- c (a <-> b <-> c)
*/
static inline void LstInsert(struct LstHead *p, struct LstHead *e)
{
e->prev = p->prev;
e->next = p;
p->prev->next = e;
p->prev = e;
}
/*
* LstRemove(s_LstLink_T) removes the element from the linked list, which is
* done by modifying the next element to point at the previous and vice versa.
*/
static inline void LstRemove(struct LstHead *p)
{
p->next->prev = p->prev;
p->prev->next = p->next;
}
#define LstHead(a) sLstLink_##a /*
* LstNull(s_LstLink_T) sets the linked list to NULL.
*/
static inline void LstNull(struct LstHead *p)
{
p->next = p->prev = NULL;
}
#define LstNex(p) ((p)->nex) /*
#define LstPre(p) ((p)->pre) * LstIsNull(s_LstLink_T) checks if the linked list is NULL.
#define LstLas(h) ((h)->pre) */
#define LstFir(h) ((h)->nex) static inline int LstIsNull(struct LstHead *p)
#define LstEnd(h) (h) {
#define LstIns(p, o, e) \ return (p->next == NULL && p->prev == NULL);
((o)->e.obj = (void*)o, (o)->e.pre = (void*)((p)->pre), \ }
(o)->e.nex = (void*)(p), (p)->pre->nex = (void*)(&(o)->e), \
(p)->pre = (void*)(&(o)->e)) /*
#define LstRem(p) ((p)->nex->pre = (p)->pre, (p)->pre->nex = (p)->nex) * LstInit(s_LstLink_T) initializes the linked list.
#define LstNul(p) ((p)->nex = (p)->pre = NULL) */
#define LstIsNul(p) ((p)->nex == NULL && (p)->pre == NULL) static inline void LstInit(struct LstHead *h)
#define LstInl(p) ((p)->nex != NULL && (p)->pre != NULL) {
#define LstIni(h) ((h)->nex = (h)->pre = (h)) h->next = h->prev = h;
#define LstObj(p) ((p)->obj) }
#define LstEmp(h) ((h) == (h)->nex)
/*
* LstEntry(s_LstLink_T*, sTimer, ll) fetches the struct sTimer corresponding to
* the list pointer \a ptr.
* It does this by calculating the offset of a list pointers \a ll within the
* struct sTimer, and then subtracts that from the list pointer \a ptr.
*/
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#define LstEntry(ptr, type, member) container_of(ptr, type, member)
/*
* LstEmpty(s_LstLink_T) checks if the linked list is empty.
*/
static inline int LstEmpty(struct LstHead *h)
{
return h->next == h;
}
/*
* LstForEach(i, listHead) is a convenience macro for:
* for (i = listHead->next; i != listHead, i = i->next)
*/
#define LstForEach(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#endif #endif
...@@ -51,31 +51,28 @@ ...@@ -51,31 +51,28 @@
typedef struct s_Ack sAck; typedef struct s_Ack sAck;
typedef struct s_Block sBlock; typedef struct s_Block sBlock;
typedef struct s_Handler sHandler; typedef struct s_Handler sHandler;
LstType(sAck);
LstType(sBlock);
LstType(sHandler);
struct s_Ack { struct s_Ack {
LstLink(sAck) ack_l; struct LstHead ack_l;
mh_sOutunitAck ack; mh_sOutunitAck ack;
}; };
struct s_Block { struct s_Block {
LstLink(sBlock) block_l; struct LstHead block_l;
mh_sOutunitBlock block; mh_sOutunitBlock block;
}; };
struct s_Handler { struct s_Handler {
LstLink(sHandler) handler_l; struct LstHead handler_l;
LstLink(sHandler) sync_l; struct LstHead sync_l;
pwr_tTime birthTime; /* Time when handler started */ pwr_tTime birthTime; /* Time when handler started */
qcom_sQid qid; /* Qcom queue of handler */ qcom_sQid qid; /* Qcom queue of handler */
qcom_sAid aid; /* Qcom application id */ qcom_sAid aid; /* Qcom application id */
co_sPlatform platform; /* Platform identity */ co_sPlatform platform; /* Platform identity */
pwr_tNodeIndex nix; /* Node index of handler */ pwr_tNodeIndex nix; /* Node index of handler */
LstHead(sAck) ack_l; /* Head to ack list */ struct LstHead ack_l; /* Head to ack list */
pwr_tUInt32 ackGen; /* Ack generation */ pwr_tUInt32 ackGen; /* Ack generation */
LstHead(sBlock) block_l; /* Head to block list */ struct LstHead block_l; /* Head to block list */
pwr_tUInt32 blockGen; /* Block generation */ pwr_tUInt32 blockGen; /* Block generation */
pwr_tBoolean isDummy; pwr_tBoolean isDummy;
pwr_tBoolean linkUp; pwr_tBoolean linkUp;
...@@ -100,8 +97,8 @@ typedef struct { ...@@ -100,8 +97,8 @@ typedef struct {
pwr_tStatus (*cbInfo)(mh_sMessage*); pwr_tStatus (*cbInfo)(mh_sMessage*);
pwr_tStatus (*cbReturn)(mh_sReturn*); pwr_tStatus (*cbReturn)(mh_sReturn*);
pwr_tStatus (*cbAlarmStatus)(mh_sAlarmStatus*); pwr_tStatus (*cbAlarmStatus)(mh_sAlarmStatus*);
LstHead(sHandler) handler_l; struct LstHead handler_l;
LstHead(sHandler) sync_l; struct LstHead sync_l;
pwr_tUInt32 selGen; pwr_tUInt32 selGen;
pwr_tUInt32 selSize; pwr_tUInt32 selSize;
pwr_tString80 (*pSelL)[]; pwr_tString80 (*pSelL)[];
...@@ -153,18 +150,18 @@ pwr_tStatus mh_OutunitAck(mh_sEventId* targetId /**< The identity of an alarm.*/ ...@@ -153,18 +150,18 @@ pwr_tStatus mh_OutunitAck(mh_sEventId* targetId /**< The identity of an alarm.*/
{ {
pwr_tStatus sts = MH__SUCCESS; pwr_tStatus sts = MH__SUCCESS;
sHandler* hp; sHandler* hp;
LstLink(sHandler) * hl; struct LstHead * hl;
/* Find originating handler */ /* Find originating handler */
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); hl = LstNex(hl)) LstForEach(hl, &l.handler_l)
if (LstObj(hl)->nix == targetId->Nix) if (LstEntry(hl, sHandler, handler_l)->nix == targetId->Nix)
break; break;
if (hl == LstEnd(&l.handler_l)) { if (hl == &l.handler_l) {
return MH__HANDLERDOWN; return MH__HANDLERDOWN;
} else { } else {
hp = LstObj(hl); hp = LstEntry(hl, sHandler, handler_l);
} }
ackListInsert(hp, targetId->Idx); ackListInsert(hp, targetId->Idx);
...@@ -183,7 +180,7 @@ pwr_tStatus mh_OutunitBlock( ...@@ -183,7 +180,7 @@ pwr_tStatus mh_OutunitBlock(
{ {
pwr_tStatus sts; pwr_tStatus sts;
sHandler* hp; sHandler* hp;
LstLink(sHandler) * hl; struct LstHead * hl;
pwr_tNodeIndex nix; pwr_tNodeIndex nix;
pwr_tBoolean is_mount_clean; pwr_tBoolean is_mount_clean;
...@@ -193,18 +190,18 @@ pwr_tStatus mh_OutunitBlock( ...@@ -193,18 +190,18 @@ pwr_tStatus mh_OutunitBlock(
if (EVEN(sts)) if (EVEN(sts))
return sts; return sts;
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); hl = LstNex(hl)) { LstForEach(hl, &l.handler_l) {
if (!hl) if (!hl)
return MH__HANDLERDOWN; return MH__HANDLERDOWN;
if (LstObj(hl)->nix == nix) if (LstEntry(hl, sHandler, handler_l)->nix == nix)
break; break;
} }
if (hl == LstEnd(&l.handler_l)) { if (hl == &l.handler_l) {
return MH__HANDLERDOWN; return MH__HANDLERDOWN;
} else { } else {
hp = LstObj(hl); hp = LstEntry(hl, sHandler, handler_l);
} }
blockListInsert(hp, &object, prio); blockListInsert(hp, &object, prio);
...@@ -359,13 +356,13 @@ pwr_tStatus mh_OutunitConnect( ...@@ -359,13 +356,13 @@ pwr_tStatus mh_OutunitConnect(
l.cbReturn = cbReturn; l.cbReturn = cbReturn;
l.cbAlarmStatus = cbAlarmStatus; l.cbAlarmStatus = cbAlarmStatus;
LstIni(&l.handler_l); LstInit(&l.handler_l);
LstIni(&l.sync_l); LstInit(&l.sync_l);
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
hp = (sHandler*)calloc(1, sizeof(*hp)); hp = (sHandler*)calloc(1, sizeof(*hp));
hp->isDummy = TRUE; hp->isDummy = TRUE;
LstIns(&l.sync_l, hp, sync_l); LstInsert(&l.sync_l, &hp->sync_l);
} }
getSelectList(); getSelectList();
...@@ -397,18 +394,17 @@ pwr_tStatus mh_OutunitConnect( ...@@ -397,18 +394,17 @@ pwr_tStatus mh_OutunitConnect(
pwr_tStatus mh_OutunitDisconnect() pwr_tStatus mh_OutunitDisconnect()
{ {
sHandler* hp; sHandler* hp;
LstLink(sHandler) * hl; struct LstHead * hl;
/* Disconnect all handlers and free memory */ /* Disconnect all handlers and free memory */
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); LstForEach(hl, &l.handler_l) {
hl = LstFir(&l.handler_l)) { hp = LstEntry(hl, sHandler, handler_l);
hp = LstObj(hl);
sendToHandler(hp, mh_eMsg_OutunitDisconnect, 0, NULL); sendToHandler(hp, mh_eMsg_OutunitDisconnect, 0, NULL);
ackListDestroy(hp); ackListDestroy(hp);
blockListDestroy(hp); blockListDestroy(hp);
LstRem(hl); LstRemove(hl);
LstNul(hl); LstNull(hl);
free(hp); free(hp);
} }
...@@ -494,12 +490,12 @@ pwr_tStatus mh_OutunitSetTimeout(int timeout /**< The timeout in ms. */ ...@@ -494,12 +490,12 @@ pwr_tStatus mh_OutunitSetTimeout(int timeout /**< The timeout in ms. */
pwr_tStatus mh_OutunitUpdate() pwr_tStatus mh_OutunitUpdate()
{ {
LstLink(sHandler) * hl; struct LstHead * hl;
getSelectList(); getSelectList();
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); hl = LstNex(hl)) LstForEach(hl, &l.handler_l)
sendInfo(LstObj(hl)); sendInfo(LstEntry(hl, sHandler, handler_l));
return MH__SUCCESS; return MH__SUCCESS;
} }
...@@ -512,18 +508,18 @@ pwr_tStatus mh_OutunitUpdate() ...@@ -512,18 +508,18 @@ pwr_tStatus mh_OutunitUpdate()
pwr_tStatus mh_OutunitAlarmRequest(mh_sOutunitAlarmReq* msg) pwr_tStatus mh_OutunitAlarmRequest(mh_sOutunitAlarmReq* msg)
{ {
sHandler* hp; sHandler* hp;
LstLink(sHandler) * hl; struct LstHead * hl;
/* Find originating handler */ /* Find originating handler */
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); hl = LstNex(hl)) LstForEach(hl, &l.handler_l)
if (LstObj(hl)->nix == msg->Nix) if (LstEntry(hl, sHandler, handler_l)->nix == msg->Nix)
break; break;
if (hl == LstEnd(&l.handler_l)) { if (hl == &l.handler_l) {
return MH__HANDLERDOWN; return MH__HANDLERDOWN;
} else { } else {
hp = LstObj(hl); hp = LstEntry(hl, sHandler, handler_l);
} }
sendToHandler(hp, mh_eMsg_OutunitAlarmReq, sizeof(*msg), (void*)msg); sendToHandler(hp, mh_eMsg_OutunitAlarmReq, sizeof(*msg), (void*)msg);
...@@ -533,10 +529,8 @@ pwr_tStatus mh_OutunitAlarmRequest(mh_sOutunitAlarmReq* msg) ...@@ -533,10 +529,8 @@ pwr_tStatus mh_OutunitAlarmRequest(mh_sOutunitAlarmReq* msg)
static void ackListDelete(sHandler* hp, sAck* ap) static void ackListDelete(sHandler* hp, sAck* ap)
{ {
LstLink(sAck) * al; LstRemove(&ap->ack_l);
LstNull(&ap->ack_l);
al = LstRem(&ap->ack_l);
LstNul(&ap->ack_l);
free(ap); free(ap);
checkSyncListDelete(hp); checkSyncListDelete(hp);
...@@ -545,13 +539,12 @@ static void ackListDelete(sHandler* hp, sAck* ap) ...@@ -545,13 +539,12 @@ static void ackListDelete(sHandler* hp, sAck* ap)
static void ackListDestroy(sHandler* hp) static void ackListDestroy(sHandler* hp)
{ {
sAck* ap; sAck* ap;
LstLink(sAck) * al; struct LstHead * al;
for (al = LstFir(&hp->ack_l); al != LstEnd(&hp->ack_l); LstForEach(al, &hp->ack_l) {
al = LstFir(&hp->ack_l)) { ap = LstEntry(al, sAck, ack_l);
ap = LstObj(al); LstRemove(al);
LstRem(al); LstNull(al);
LstNul(al);
free(ap); free(ap);
} }
...@@ -562,34 +555,32 @@ static void ackListDestroy(sHandler* hp) ...@@ -562,34 +555,32 @@ static void ackListDestroy(sHandler* hp)
static void ackListInsert(sHandler* hp, pwr_tUInt32 targetIdx) static void ackListInsert(sHandler* hp, pwr_tUInt32 targetIdx)
{ {
sAck* ap; sAck* ap;
LstLink(sAck) * al; struct LstHead * al;
/* Don't insert if already present */ /* Don't insert if already present */
for (al = LstFir(&hp->ack_l); al != LstEnd(&hp->ack_l); al = LstNex(al)) LstForEach(al, &hp->ack_l)
if (LstObj(al)->ack.targetIdx == targetIdx) if (LstEntry(al, sAck, ack_l)->ack.targetIdx == targetIdx)
return; return;
ap = (sAck*)calloc(1, sizeof(*ap)); ap = (sAck*)calloc(1, sizeof(*ap));
ap->ack.ackGen = ++hp->ackGen; ap->ack.ackGen = ++hp->ackGen;
ap->ack.targetIdx = targetIdx; ap->ack.targetIdx = targetIdx;
al = LstEnd(&hp->ack_l); al = &hp->ack_l;
LstIns(al, ap, ack_l); LstInsert(al, &ap->ack_l);
if (!LstInl(&hp->sync_l)) { if (LstIsNull(&hp->sync_l)) {
LstIns(LstEnd(&l.sync_l), hp, sync_l); LstInsert(&l.sync_l, &hp->sync_l);
} }
if (ap == LstObj(LstFir(&hp->ack_l))) { if (ap == LstEntry(hp->ack_l.next, sAck, ack_l)) {
sendToHandler(hp, mh_eMsg_OutunitAck, sizeof(ap->ack), (void*)&ap->ack); sendToHandler(hp, mh_eMsg_OutunitAck, sizeof(ap->ack), (void*)&ap->ack);
} }
} }
static void blockListDelete(sHandler* hp, sBlock* bp) static void blockListDelete(sHandler* hp, sBlock* bp)
{ {
LstLink(sBlock) * bl; LstRemove(&bp->block_l);
LstNull(&bp->block_l);
bl = LstRem(&bp->block_l);
LstNul(&bp->block_l);
free(bp); free(bp);
checkSyncListDelete(hp); checkSyncListDelete(hp);
...@@ -598,13 +589,12 @@ static void blockListDelete(sHandler* hp, sBlock* bp) ...@@ -598,13 +589,12 @@ static void blockListDelete(sHandler* hp, sBlock* bp)
static void blockListDestroy(sHandler* hp) static void blockListDestroy(sHandler* hp)
{ {
sBlock* bp; sBlock* bp;
LstLink(sBlock) * bl; struct LstHead * bl;
for (bl = LstFir(&hp->block_l); bl != LstEnd(&hp->block_l); LstForEach(bl, &hp->block_l) {
bl = LstFir(&hp->block_l)) { bp = LstEntry(bl, sBlock, block_l);
bp = LstObj(bl); LstRemove(bl);
LstRem(bl); LstNull(bl);
LstNul(bl);
free(bp); free(bp);
} }
...@@ -615,21 +605,21 @@ static void blockListDestroy(sHandler* hp) ...@@ -615,21 +605,21 @@ static void blockListDestroy(sHandler* hp)
static void blockListInsert(sHandler* hp, pwr_tObjid* op, pwr_tUInt32 prio) static void blockListInsert(sHandler* hp, pwr_tObjid* op, pwr_tUInt32 prio)
{ {
sBlock* bp; sBlock* bp;
LstLink(sBlock) * bl; struct LstHead * bl;
bp = (sBlock*)calloc(1, sizeof(*bp)); bp = (sBlock*)calloc(1, sizeof(*bp));
bp->block.blockGen = ++hp->blockGen; bp->block.blockGen = ++hp->blockGen;
bp->block.object = *op; bp->block.object = *op;
bp->block.outunit = l.head.outunit; bp->block.outunit = l.head.outunit;
bp->block.prio = prio; bp->block.prio = prio;
bl = LstEnd(&hp->block_l); bl = &hp->block_l;
LstIns(bl, bp, block_l); LstInsert(bl, &bp->block_l);
if (!LstInl(&hp->sync_l)) { if (LstIsNull(&hp->sync_l)) {
LstIns(LstEnd(&l.sync_l), hp, sync_l); LstInsert(&l.sync_l, &hp->sync_l);
} }
if (bp == LstObj(LstFir(&hp->block_l))) { if (bp == LstEntry(hp->block_l.next, sBlock, block_l)) {
sendToHandler( sendToHandler(
hp, mh_eMsg_OutunitBlock, sizeof(bp->block), (void*)&bp->block); hp, mh_eMsg_OutunitBlock, sizeof(bp->block), (void*)&bp->block);
} }
...@@ -637,14 +627,13 @@ static void blockListInsert(sHandler* hp, pwr_tObjid* op, pwr_tUInt32 prio) ...@@ -637,14 +627,13 @@ static void blockListInsert(sHandler* hp, pwr_tObjid* op, pwr_tUInt32 prio)
static void checkSync() static void checkSync()
{ {
LstLink(sHandler) * sl; struct LstHead * sl;
sHandler* hp; sHandler* hp;
for (sl = LstFir(&l.sync_l); sl != LstEnd(&l.sync_l); LstForEach(sl, &l.sync_l) {
sl = LstFir(&l.sync_l)) { hp = LstEntry(sl, sHandler, sync_l);
hp = LstObj(sl); LstRemove(sl);
LstRem(sl); LstInsert(&l.sync_l, &hp->sync_l);
LstIns(LstEnd(&l.sync_l), hp, sync_l);
if (hp->isDummy) if (hp->isDummy)
return; return;
if (!hp->linkUp) if (!hp->linkUp)
...@@ -656,39 +645,39 @@ static void checkSync() ...@@ -656,39 +645,39 @@ static void checkSync()
static void checkSyncListDelete(sHandler* hp) static void checkSyncListDelete(sHandler* hp)
{ {
if (!LstInl(&hp->sync_l)) if (LstIsNull(&hp->sync_l))
return; return;
if (!LstEmp(&hp->ack_l)) if (!LstEmpty(&hp->ack_l))
return; return;
if (!LstEmp(&hp->block_l)) if (!LstEmpty(&hp->block_l))
return; return;
if (hp->selGen != l.selGen) if (hp->selGen != l.selGen)
return; return;
LstRem(&hp->sync_l); LstRemove(&hp->sync_l);
LstNul(&hp->sync_l); LstNull(&hp->sync_l);
} }
static void checkSyncReply(sHandler* hp) static void checkSyncReply(sHandler* hp)
{ {
if (hp->selGen != l.selGen) { if (hp->selGen != l.selGen) {
sendInfo(hp); sendInfo(hp);
} else if (!LstEmp(&hp->block_l)) { } else if (!LstEmpty(&hp->block_l)) {
sBlock* bp; sBlock* bp;
bp = LstObj(LstNex(&hp->block_l)); bp = LstEntry(hp->block_l.next, sBlock, block_l);
sendToHandler( sendToHandler(
hp, mh_eMsg_OutunitBlock, sizeof(bp->block), (void*)&bp->block); hp, mh_eMsg_OutunitBlock, sizeof(bp->block), (void*)&bp->block);
} else if (!LstEmp(&hp->ack_l)) { } else if (!LstEmpty(&hp->ack_l)) {
sAck* ap; sAck* ap;
ap = LstObj(LstNex(&hp->ack_l)); ap = LstEntry(hp->ack_l.next, sAck, ack_l);
sendToHandler(hp, mh_eMsg_OutunitAck, sizeof(ap->ack), (void*)&ap->ack); sendToHandler(hp, mh_eMsg_OutunitAck, sizeof(ap->ack), (void*)&ap->ack);
} }
if (LstInl(&hp->sync_l)) { if (!LstIsNull(&hp->sync_l)) {
LstRem(&hp->sync_l); LstRemove(&hp->sync_l);
LstIns(LstEnd(&l.sync_l), hp, sync_l); LstInsert(&l.sync_l, &hp->sync_l);
} }
} }
...@@ -823,7 +812,7 @@ static void handlerEvent(sHandler* hp, mh_sHead* p) ...@@ -823,7 +812,7 @@ static void handlerEvent(sHandler* hp, mh_sHead* p)
{ {
pwr_tStatus sts; pwr_tStatus sts;
mh_sMsgInfo* mp = (mh_sMsgInfo*)(p + 1); mh_sMsgInfo* mp = (mh_sMsgInfo*)(p + 1);
LstLink(sAck) * al; struct LstHead * al;
mh_sAck* ap; mh_sAck* ap;
mh_sReturn* cp; mh_sReturn* cp;
...@@ -852,9 +841,9 @@ static void handlerEvent(sHandler* hp, mh_sHead* p) ...@@ -852,9 +841,9 @@ static void handlerEvent(sHandler* hp, mh_sHead* p)
ap = (mh_sAck*)mp; ap = (mh_sAck*)mp;
for (al = LstFir(&hp->ack_l); al != LstEnd(&hp->ack_l); al = LstNex(al)) LstForEach(al, &hp->ack_l)
if (LstObj(al)->ack.targetIdx == ap->TargetId.Idx) { if (LstEntry(al, sAck, ack_l)->ack.targetIdx == ap->TargetId.Idx) {
ackListDelete(hp, LstObj(al)); ackListDelete(hp, LstEntry(al, sAck, ack_l));
break; break;
} }
...@@ -883,9 +872,9 @@ static void handlerEvent(sHandler* hp, mh_sHead* p) ...@@ -883,9 +872,9 @@ static void handlerEvent(sHandler* hp, mh_sHead* p)
cp = (mh_sReturn*)mp; cp = (mh_sReturn*)mp;
for (al = LstFir(&hp->ack_l); al != LstEnd(&hp->ack_l); al = LstNex(al)) LstForEach(al, &hp->ack_l)
if (LstObj(al)->ack.targetIdx == cp->TargetId.Idx) { if (LstEntry(al, sAck, ack_l)->ack.targetIdx == cp->TargetId.Idx) {
ackListDelete(hp, LstObj(al)); ackListDelete(hp, LstEntry(al, sAck, ack_l));
break; break;
} }
...@@ -915,18 +904,18 @@ static void handlerLog(sHandler* hp, char* s) ...@@ -915,18 +904,18 @@ static void handlerLog(sHandler* hp, char* s)
static void handlerSync(sHandler* hp, mh_sHead* p) static void handlerSync(sHandler* hp, mh_sHead* p)
{ {
if (!LstEmp(&hp->ack_l)) { if (!LstEmpty(&hp->ack_l)) {
sAck* ap; sAck* ap;
ap = LstObj(LstNex(&hp->ack_l)); ap = LstEntry(hp->ack_l.next, sAck, ack_l);
if (ap->ack.ackGen == p->ackGen) if (ap->ack.ackGen == p->ackGen)
ackListDelete(hp, ap); ackListDelete(hp, ap);
} }
if (!LstEmp(&hp->block_l)) { if (!LstEmpty(&hp->block_l)) {
sBlock* bp; sBlock* bp;
bp = LstObj(LstNex(&hp->block_l)); bp = LstEntry(hp->block_l.next, sBlock, block_l);
if (bp->block.blockGen == p->blockGen) if (bp->block.blockGen == p->blockGen)
blockListDelete(hp, bp); blockListDelete(hp, bp);
} }
...@@ -953,7 +942,7 @@ static void handlerAlarmStatus(sHandler* hp, mh_sHead* p) ...@@ -953,7 +942,7 @@ static void handlerAlarmStatus(sHandler* hp, mh_sHead* p)
static pwr_tBoolean isValidHandler(mh_sHead* p, qcom_sAid* aid, sHandler** h) static pwr_tBoolean isValidHandler(mh_sHead* p, qcom_sAid* aid, sHandler** h)
{ {
sHandler* hp; sHandler* hp;
LstLink(sHandler) * hl; struct LstHead * hl;
if (!(p->ver == mh_cVersion if (!(p->ver == mh_cVersion
|| (mh_cVersion == 5 || (mh_cVersion == 5
...@@ -969,11 +958,11 @@ static pwr_tBoolean isValidHandler(mh_sHead* p, qcom_sAid* aid, sHandler** h) ...@@ -969,11 +958,11 @@ static pwr_tBoolean isValidHandler(mh_sHead* p, qcom_sAid* aid, sHandler** h)
/* Find handler in handler list */ /* Find handler in handler list */
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); hl = LstNex(hl)) LstForEach(hl, &l.handler_l)
if (LstObj(hl)->qid.qix == p->qid.qix && LstObj(hl)->qid.nid == p->qid.nid) if (LstEntry(hl, sHandler, handler_l)->qid.qix == p->qid.qix && LstEntry(hl, sHandler, handler_l)->qid.nid == p->qid.nid)
break; break;
if (hl == LstEnd(&l.handler_l)) { if (hl == &l.handler_l) {
/* Handler not known, make it known */ /* Handler not known, make it known */
hp = (sHandler*)calloc(1, sizeof(*hp)); hp = (sHandler*)calloc(1, sizeof(*hp));
hp->birthTime = net_NetTimeToTime(&p->birthTime); hp->birthTime = net_NetTimeToTime(&p->birthTime);
...@@ -982,12 +971,12 @@ static pwr_tBoolean isValidHandler(mh_sHead* p, qcom_sAid* aid, sHandler** h) ...@@ -982,12 +971,12 @@ static pwr_tBoolean isValidHandler(mh_sHead* p, qcom_sAid* aid, sHandler** h)
hp->platform = p->platform; hp->platform = p->platform;
hp->nix = p->nix; hp->nix = p->nix;
hp->linkUp = TRUE; hp->linkUp = TRUE;
LstIns(&l.handler_l, hp, handler_l); LstInsert(&l.handler_l, &hp->handler_l);
LstIni(&hp->ack_l); LstInit(&hp->ack_l);
LstIni(&hp->block_l); LstInit(&hp->block_l);
handlerLog(hp, "New handler"); handlerLog(hp, "New handler");
} else { } else {
hp = LstObj(hl); hp = LstEntry(hl, sHandler, handler_l);
if (hp->birthTime.tv_sec != p->birthTime.tv_sec) { if (hp->birthTime.tv_sec != p->birthTime.tv_sec) {
/* Different times, i.e. the handler is restarted */ /* Different times, i.e. the handler is restarted */
...@@ -1010,12 +999,12 @@ static pwr_tBoolean isValidHandler(mh_sHead* p, qcom_sAid* aid, sHandler** h) ...@@ -1010,12 +999,12 @@ static pwr_tBoolean isValidHandler(mh_sHead* p, qcom_sAid* aid, sHandler** h)
static void linkDown(qcom_sNode* nodep) static void linkDown(qcom_sNode* nodep)
{ {
LstLink(sHandler) * hl; struct LstHead * hl;
sHandler* hp; sHandler* hp;
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); hl = LstNex(hl)) LstForEach(hl, &l.handler_l)
if (LstObj(hl)->qid.nid == nodep->nid) { if (LstEntry(hl, sHandler, handler_l)->qid.nid == nodep->nid) {
hp = LstObj(hl); hp = LstEntry(hl, sHandler, handler_l);
hp->linkUp = FALSE; hp->linkUp = FALSE;
handlerLog(hp, "Link down"); handlerLog(hp, "Link down");
return; return;
...@@ -1024,12 +1013,12 @@ static void linkDown(qcom_sNode* nodep) ...@@ -1024,12 +1013,12 @@ static void linkDown(qcom_sNode* nodep)
static void linkUp(qcom_sNode* nodep) static void linkUp(qcom_sNode* nodep)
{ {
LstLink(sHandler) * hl; struct LstHead * hl;
sHandler* hp; sHandler* hp;
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); hl = LstNex(hl)) LstForEach(hl, &l.handler_l)
if (LstObj(hl)->qid.nid == nodep->nid) { if (LstEntry(hl, sHandler, handler_l)->qid.nid == nodep->nid) {
hp = LstObj(hl); hp = LstEntry(hl, sHandler, handler_l);
hp->linkUp = TRUE; hp->linkUp = TRUE;
handlerLog(hp, "Link up"); handlerLog(hp, "Link up");
return; return;
...@@ -1039,20 +1028,21 @@ static void linkUp(qcom_sNode* nodep) ...@@ -1039,20 +1028,21 @@ static void linkUp(qcom_sNode* nodep)
static void procDown(qcom_sAid* aid) static void procDown(qcom_sAid* aid)
{ {
sHandler* hp; sHandler* hp;
LstLink(sHandler) * hl; struct LstHead * hl;
for (hl = LstFir(&l.handler_l); hl != LstEnd(&l.handler_l); hl = LstNex(hl)) LstForEach(hl, &l.handler_l) {
if (LstObj(hl)->aid.aix == aid->aix && LstObj(hl)->aid.nid == aid->nid) { hp = LstEntry(hl, sHandler, handler_l);
if (hp->aid.aix == aid->aix && hp->aid.nid == aid->nid) {
/* Delete this handler from handler list */ /* Delete this handler from handler list */
hp = LstObj(hl);
handlerLog(hp, "Handler aborted"); handlerLog(hp, "Handler aborted");
ackListDestroy(hp); ackListDestroy(hp);
blockListDestroy(hp); blockListDestroy(hp);
LstRem(hl); LstRemove(hl);
LstNul(hl); LstNull(hl);
free(hp); free(hp);
return; return;
} }
}
} }
static void sendInfo(sHandler* hp) static void sendInfo(sHandler* hp)
...@@ -1081,8 +1071,8 @@ static void sendInfo(sHandler* hp) ...@@ -1081,8 +1071,8 @@ static void sendInfo(sHandler* hp)
free(mp); free(mp);
if (!LstInl(&hp->sync_l)) { if (LstIsNull(&hp->sync_l)) {
LstIns(LstEnd(&l.sync_l), hp, sync_l); LstInsert(&l.sync_l, &hp->sync_l);
} }
} }
......
...@@ -64,10 +64,8 @@ ...@@ -64,10 +64,8 @@
typedef struct s_FacilityCB sFacilityCB; typedef struct s_FacilityCB sFacilityCB;
LstType(sFacilityCB);
struct s_FacilityCB { struct s_FacilityCB {
LstLink(sFacilityCB) FacL; struct LstHead FacL;
char* facnam; char* facnam;
int facnum; int facnum;
}; };
...@@ -76,7 +74,7 @@ extern int lineno; ...@@ -76,7 +74,7 @@ extern int lineno;
static int SyntaxError; static int SyntaxError;
static LstHead(sFacilityCB) lFacH; static struct LstHead lFacH;
static sFacilityCB* CurrFac = NULL; static sFacilityCB* CurrFac = NULL;
static void CopyFile(FILE* ifp, FILE* ofp); static void CopyFile(FILE* ifp, FILE* ofp);
...@@ -122,7 +120,7 @@ int main(int argc, char** argv) ...@@ -122,7 +120,7 @@ int main(int argc, char** argv)
exit(1); exit(1);
} }
LstIni(&lFacH); LstInit(&lFacH);
SyntaxError = 0; SyntaxError = 0;
lineno = 1; lineno = 1;
...@@ -159,7 +157,7 @@ void lex_FacName(char* facnam) ...@@ -159,7 +157,7 @@ void lex_FacName(char* facnam)
void lex_FacNum(int facnum) void lex_FacNum(int facnum)
{ {
LstLink(sFacilityCB) * fl; struct LstHead * fl;
/* /*
* To do: Check that the facility number is within the valid range * To do: Check that the facility number is within the valid range
...@@ -167,14 +165,14 @@ void lex_FacNum(int facnum) ...@@ -167,14 +165,14 @@ void lex_FacNum(int facnum)
*/ */
/* Insert in ascending order */ /* Insert in ascending order */
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { LstForEach(fl, &lFacH) {
if (LstObj(fl)->facnum > facnum) { if (LstEntry(fl, sFacilityCB, FacL)->facnum > facnum) {
break; break;
} }
} }
CurrFac->facnum = facnum; CurrFac->facnum = facnum;
LstIns(fl, CurrFac, FacL); LstInsert(fl, &CurrFac->FacL);
CurrFac = NULL; CurrFac = NULL;
} }
...@@ -192,20 +190,20 @@ static void CopyFile(FILE* ifp, FILE* ofp) ...@@ -192,20 +190,20 @@ static void CopyFile(FILE* ifp, FILE* ofp)
static void WriteFacility(FILE* cfp, char* branch) static void WriteFacility(FILE* cfp, char* branch)
{ {
LstLink(sFacilityCB) * fl; struct LstHead * fl;
int i = 0; int i = 0;
fprintf(cfp, "static msg_sFacility *Facilities[] = {\n"); fprintf(cfp, "static msg_sFacility *Facilities[] = {\n");
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { LstForEach(fl, &lFacH) {
if (i++) if (i++)
fprintf(cfp, ",\n"); fprintf(cfp, ",\n");
fprintf(cfp, "\t%-20s /* %4d */", LstObj(fl)->facnam, LstObj(fl)->facnum); fprintf(cfp, "\t%-20s /* %4d */", LstEntry(fl, sFacilityCB, FacL)->facnam, LstEntry(fl, sFacilityCB, FacL)->facnum);
} }
fprintf(cfp, "};\n\n"); fprintf(cfp, "};\n\n");
if (LstFir(&lFacH) == LstEnd(&lFacH)) if (LstEmpty(&lFacH))
fprintf(cfp, "msg_sHead %sMsgHead = {0, 0};\n", branch ? branch : "pwrp"); fprintf(cfp, "msg_sHead %sMsgHead = {0, 0};\n", branch ? branch : "pwrp");
else else
fprintf(cfp, "msg_sHead %sMsgHead = {MSG_NOF(Facilities), Facilities};\n", fprintf(cfp, "msg_sHead %sMsgHead = {MSG_NOF(Facilities), Facilities};\n",
......
...@@ -61,18 +61,15 @@ ...@@ -61,18 +61,15 @@
typedef struct s_FacilityCB sFacilityCB; typedef struct s_FacilityCB sFacilityCB;
typedef struct s_MsgCB sMsgCB; typedef struct s_MsgCB sMsgCB;
LstType(sFacilityCB);
LstType(sMsgCB);
struct s_MsgCB { struct s_MsgCB {
LstLink(sMsgCB) MsgL; struct LstHead MsgL;
msg_sMsg m; msg_sMsg m;
msg_eSeverity Severity; msg_eSeverity Severity;
}; };
struct s_FacilityCB { struct s_FacilityCB {
LstLink(sFacilityCB) FacL; struct LstHead FacL;
LstHead(sMsgCB) MsgH; struct LstHead MsgH;
msg_sFacility f; msg_sFacility f;
}; };
...@@ -81,7 +78,7 @@ extern int lineno; ...@@ -81,7 +78,7 @@ extern int lineno;
static int SyntaxError; static int SyntaxError;
static LstHead(sFacilityCB) lFacH; static struct LstHead lFacH;
/* /*
* Local functions * Local functions
...@@ -125,7 +122,7 @@ int main(int argc, char** argv) ...@@ -125,7 +122,7 @@ int main(int argc, char** argv)
exit(2); exit(2);
} }
LstIni(&lFacH); LstInit(&lFacH);
SyntaxError = 0; SyntaxError = 0;
lineno = 1; lineno = 1;
yylex(); yylex();
...@@ -160,20 +157,20 @@ void lex_FacName(const char* FacName) ...@@ -160,20 +157,20 @@ void lex_FacName(const char* FacName)
{ {
sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB)); sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB));
LstIni(&facp->MsgH); LstInit(&facp->MsgH);
facp->f.FacName = MSG_NEW_STRING(FacName); facp->f.FacName = MSG_NEW_STRING(FacName);
LstIns(&lFacH, facp, FacL); LstInsert(&lFacH, &facp->FacL);
} }
void lex_FacNum(int FacNum) void lex_FacNum(int FacNum)
{ {
LstObj(LstLas(&lFacH))->f.FacNum = FacNum; LstEntry(lFacH.prev, sFacilityCB, FacL)->f.FacNum = FacNum;
} }
void lex_FacPrefix(const char* Prefix) void lex_FacPrefix(const char* Prefix)
{ {
LstObj(LstLas(&lFacH))->f.Prefix = MSG_NEW_STRING(Prefix); LstEntry(lFacH.prev, sFacilityCB, FacL)->f.Prefix = MSG_NEW_STRING(Prefix);
} }
void lex_MsgName(const char* MsgName) void lex_MsgName(const char* MsgName)
...@@ -187,21 +184,21 @@ void lex_MsgName(const char* MsgName) ...@@ -187,21 +184,21 @@ void lex_MsgName(const char* MsgName)
msgp->m.MsgName[i] = toupper(MsgName[i]); msgp->m.MsgName[i] = toupper(MsgName[i]);
msgp->m.MsgName[i] = '\0'; msgp->m.MsgName[i] = '\0';
(void)LstIns(&LstObj(LstLas(&lFacH))->MsgH, msgp, MsgL); LstInsert(&LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH, &msgp->MsgL);
} }
void lex_MsgText(const char* Text) void lex_MsgText(const char* Text)
{ {
LstLink(sMsgCB)* ml = LstLas(&LstObj(LstLas(&lFacH))->MsgH); struct LstHead* ml = LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH.prev;
TranslateFormatSpec( TranslateFormatSpec(
Text, &LstObj(ml)->m.MsgTxt); /* convert any VMS-style form spec */ Text, &LstEntry(ml, sMsgCB, MsgL)->m.MsgTxt); /* convert any VMS-style form spec */
} }
void lex_MsgSeverity(msg_eSeverity Severity) void lex_MsgSeverity(msg_eSeverity Severity)
{ {
LstLink(sMsgCB)* ml = LstLas(&LstObj(LstLas(&lFacH))->MsgH); struct LstHead* ml = LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH.prev;
LstObj(ml)->Severity = Severity; LstEntry(ml, sMsgCB, MsgL)->Severity = Severity;
} }
void lex_LexError(int Lineno, char* Str) void lex_LexError(int Lineno, char* Str)
...@@ -215,8 +212,8 @@ void lex_LexError(int Lineno, char* Str) ...@@ -215,8 +212,8 @@ void lex_LexError(int Lineno, char* Str)
*/ */
static void WriteFiles(char* fname, FILE* cfp, FILE* hfp) static void WriteFiles(char* fname, FILE* cfp, FILE* hfp)
{ {
LstLink(sFacilityCB) * fl; struct LstHead * fl;
LstLink(sMsgCB) * ml; struct LstHead * ml;
int idx; int idx;
int facid; int facid;
char prefix[32]; char prefix[32];
...@@ -227,37 +224,38 @@ static void WriteFiles(char* fname, FILE* cfp, FILE* hfp) ...@@ -227,37 +224,38 @@ static void WriteFiles(char* fname, FILE* cfp, FILE* hfp)
fprintf(hfp, "#ifndef %s_h\n", fname); fprintf(hfp, "#ifndef %s_h\n", fname);
fprintf(hfp, "#define %s_h\n\n", fname); fprintf(hfp, "#define %s_h\n\n", fname);
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { LstForEach(fl, &lFacH) {
facid = 0x800 + LstObj(fl)->f.FacNum; facid = 0x800 + LstEntry(fl, sFacilityCB, FacL)->f.FacNum;
snprintf(name, sizeof(name), "%s_FACILITY", LstObj(fl)->f.FacName); snprintf(name, sizeof(name), "%s_FACILITY", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(hfp, "#define %-29s %9d /* x%08x */\n", name, facid, facid); fprintf(hfp, "#define %-29s %9d /* x%08x */\n", name, facid, facid);
facid = facid << 16; facid = facid << 16;
if (LstObj(fl)->f.Prefix) if (LstEntry(fl, sFacilityCB, FacL)->f.Prefix)
strncpy(prefix, LstObj(fl)->f.Prefix, sizeof(prefix)); strncpy(prefix, LstEntry(fl, sFacilityCB, FacL)->f.Prefix, sizeof(prefix));
else else
snprintf(prefix, sizeof(prefix), "%s_", LstObj(fl)->f.FacName); snprintf(prefix, sizeof(prefix), "%s_", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
snprintf(msgName, sizeof(msgName), "%smsg", LstObj(fl)->f.FacName); snprintf(msgName, sizeof(msgName), "%smsg", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(cfp, "static msg_sMsg %s[] = {\n", msgName); fprintf(cfp, "static msg_sMsg %s[] = {\n", msgName);
for (idx = 1, ml = LstFir(&LstObj(fl)->MsgH); idx = 1;
ml != LstEnd(&LstObj(fl)->MsgH); ml = LstNex(ml), idx++) { LstForEach(ml, &LstEntry(fl, sFacilityCB, FacL)->MsgH) {
if (idx != 1) if (idx != 1)
fprintf(cfp, ",\n"); fprintf(cfp, ",\n");
msg = facid + 0x8000 + (idx << 3) + LstObj(ml)->Severity; msg = facid + 0x8000 + (idx << 3) + LstEntry(ml, sMsgCB, MsgL)->Severity;
snprintf(name, sizeof(name), "%s%s", prefix, LstObj(ml)->m.MsgName); snprintf(name, sizeof(name), "%s%s", prefix, LstEntry(ml, sMsgCB, MsgL)->m.MsgName);
fprintf(hfp, "#define %-29s %9.9d /* x%08x */\n", name, msg, msg); fprintf(hfp, "#define %-29s %9.9d /* x%08x */\n", name, msg, msg);
fprintf(cfp, "\t{\"%s\", \"%s\"}", LstObj(ml)->m.MsgName, fprintf(cfp, "\t{\"%s\", \"%s\"}", LstEntry(ml, sMsgCB, MsgL)->m.MsgName,
LstObj(ml)->m.MsgTxt); LstEntry(ml, sMsgCB, MsgL)->m.MsgTxt);
idx++;
} }
fprintf(cfp, "\n};\n\n"); fprintf(cfp, "\n};\n\n");
fprintf(cfp, "static msg_sFacility %sfacility[] = {\n\t", fprintf(cfp, "static msg_sFacility %sfacility[] = {\n\t",
LstObj(fl)->f.FacName); LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(cfp, "{%d, \"%s\", \"%s\", MSG_NOF(%s), %s}\n", fprintf(cfp, "{%d, \"%s\", \"%s\", MSG_NOF(%s), %s}\n",
LstObj(fl)->f.FacNum, LstObj(fl)->f.FacName, prefix, msgName, msgName); LstEntry(fl, sFacilityCB, FacL)->f.FacNum, LstEntry(fl, sFacilityCB, FacL)->f.FacName, prefix, msgName, msgName);
fprintf(cfp, "};\n\n"); fprintf(cfp, "};\n\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment