//============================================================================== /// <summary> /// Gets the branched (trunk/source) message information. /// Uses the toCompID and branchMsgID to find the branch msg. Having found the /// branch, I can then return the trunk. /// </summary> /// <param name="trunkMsgType"></param> /// <param name="toCompID"></param> /// <param name="branchMsgID"></param> /// <param name="msgFound">A ref to the trunk msg found.</param> /// <returns>True if the message is found.</returns> // N.Herrmann Nov 2004 //============================================================================== public bool getBranch(uint trunkMsgType, uint toCompID, uint branchMsgID, ref TTrunkMsg msgFound) { TTrunkMsg bMsg; TCompItem msgItem; int i; int b; bool found = false; i = trunkMsgList.Count - 1; while (!found && (i >= 0)) { //while more message trunks bMsg = trunkMsgList[i]; if (bMsg.inMsgType == trunkMsgType) //if the incoming request was this type { //now look through the branches to find the correct trunk b = 0; while (!found && (b < bMsg.branchMsgList.Count)) { //while more branches msgItem = bMsg.branchMsgList[b]; if ((msgItem.itemID == branchMsgID) && (msgItem.compID == toCompID)) { //if the branch is found found = true; //set found msgFound = bMsg; //store the trunk msg } b++; } } i--; } return(found); }
//============================================================================== /// <summary> /// Find the trunk message for this branch and remove the branch. If there are no remaining branches then /// the trunk with be removed also. /// This function combines getBranch(), pruneBranch() and removeTrunk() /// </summary> /// <param name="trunkMsgType"></param> /// <param name="toCompID"></param> /// <param name="branchMsgID"></param> /// <param name="msgFound">A ref to the trunk msg found.</param> /// <param name="remainingBranches">The number of branches remaining after this one is removed</param> /// <returns>True if the branch is found</returns> //============================================================================== public bool pullBranch(uint trunkMsgType, uint toCompID, uint branchMsgID, ref TTrunkMsg msgFound, ref uint remainingBranches) { TTrunkMsg bMsg; TCompItem msgItem; int i; int b; bool found = false; i = trunkMsgList.Count - 1; while (!found && (i >= 0)) { //while more message trunks bMsg = trunkMsgList[i]; if (bMsg.inMsgType == trunkMsgType) //if the incoming request was this type { //now look through the branches to find the correct trunk b = 0; while (!found && (b < bMsg.branchMsgList.Count)) { //while more branches msgItem = bMsg.branchMsgList[b]; if ((msgItem.itemID == branchMsgID) && (msgItem.compID == toCompID)) //if the branch is found { found = true; //set found msgFound = bMsg; //store the trunk msg if (bMsg.branchCount <= 1) // if this is the last branched msg { //clear branch list and deactivate the trunk bMsg.branchMsgList.Clear(); bMsg.branchCount = 0; bMsg.inMsgID = 0; //flag unused remainingBranches = 0; } else { //there are more branches so just deactivate this branch msgItem.compID = 0; //flag unused bMsg.branchMsgList[b] = msgItem; bMsg.branchCount--; remainingBranches = bMsg.branchCount; //store the count of branches } trunkMsgList[i] = bMsg; //store } b++; } } i--; } return(found); }
//============================================================================ /// <summary> /// Stores the details of an incoming msg (trunk) that can later contain /// references to branched msgs. /// </summary> /// <param name="returnToCompID"></param> /// <param name="trunkMsgID"></param> /// <param name="trunkMsgType"></param> /// <param name="propID"></param> /// <param name="toAck"></param> /// <returns></returns> // N.Herrmann May 2001 //============================================================================ public TTrunkMsg addMsgTrunk(uint returnToCompID, uint trunkMsgID, int trunkMsgType, int propID, int toAck) { TTrunkMsg trunk; int listPos = -1; int i = 0; while ((listPos < 0) && (i < trunkMsgList.Count)) { if (trunkMsgList[i].inMsgID == 0) { //if unused then trunk = trunkMsgList[i]; //reuse it trunk.branchMsgList.Clear(); trunk.branchCount = 0; listPos = i; } i++; } if (listPos < 0) { trunk = new TTrunkMsg(); trunkMsgList.Add(trunk); listPos = trunkMsgList.Count - 1; } trunk.returnToCompID = returnToCompID; trunk.inMsgID = trunkMsgID; //incoming msgID trunk.inMsgType = trunkMsgType; trunk.propID = propID; //incoming property ID trunk.toAck = toAck; trunk.branchCount = 0; trunk.branchMsgList = new List <TCompItem>(); //0 items trunkMsgList[listPos] = trunk; //store the changes return(trunk); }
//============================================================================== /// <summary> /// Tests the outgoing message ID's to see if it is listed as a branch of /// any incoming message id's. /// </summary> /// <param name="trunkMsgType"></param> /// <param name="toCompID"></param> /// <param name="branchMsgID"></param> /// <returns></returns> // N.Herrmann Nov 2004 //============================================================================== public bool isABranch(uint trunkMsgType, uint toCompID, uint branchMsgID) { TTrunkMsg bMsg = new TTrunkMsg(); return(getBranch(trunkMsgType, toCompID, branchMsgID, ref bMsg)); }