/** @brief Removes the element containing the specified user data from the list. The data itself is not deleted. @return OpcUa_BadInternalError if a_pList is null @return OpcUa_BadInternalError if a_pElementData is null @return OpcUa_Good on success; @param a_pList [in] Location of the list @param a_pElementData [in] Location of the data to remove from the list */ OpcUa_StatusCode OpcUa_List_DeleteElement(OpcUa_List* a_pList, OpcUa_Void* a_pElementData) { OpcUa_StatusCode uStatus = OpcUa_BadNotFound; /* initialise with error */ OpcUa_ListElement* safeCurrentElement = OpcUa_Null; OpcUa_Void* currentElementData = OpcUa_Null; OpcUa_DeclareErrorTraceModule(OpcUa_Module_List); OpcUa_GotoErrorIfArgumentNull(a_pList); OpcUa_GotoErrorIfArgumentNull(a_pElementData); /* current element is target */ if((a_pList->currtElement != OpcUa_Null) && (a_pElementData == a_pList->currtElement->data)) { OpcUa_List_DeleteCurrentElement(a_pList); return OpcUa_Good; } /* target may be elsewhere in the list */ safeCurrentElement = a_pList->currtElement; /* begin search from start of list */ OpcUa_List_ResetCurrent(a_pList); currentElementData = OpcUa_List_GetCurrentElement(a_pList); while(currentElementData != OpcUa_Null) { if(currentElementData == a_pElementData) { OpcUa_List_DeleteCurrentElement(a_pList); uStatus = OpcUa_Good; break; } else { currentElementData = OpcUa_List_GetNextElement(a_pList); } } /* restore prior cursor */ a_pList->currtElement = safeCurrentElement; Error: return uStatus; }
/** @brief Remove the first element, return its data, and reset the cursor This function is used along with OpcUa_List_AddElementToEnd to make the list behave like a queue @return OpcUa_Null if a_pList is null @return OpcUa_Null if the list is empty @return the user data from the first element otherwise @param a_pList [in] Location of the list */ OpcUa_Void* OpcUa_List_RemoveFirstElement(OpcUa_List* a_pList) { OpcUa_StatusCode uStatus = 0; OpcUa_Void* returnElement = OpcUa_Null; OpcUa_DeclareErrorTraceModule(OpcUa_Module_List); OpcUa_GotoErrorIfArgumentNull(a_pList); OpcUa_GotoErrorIfArgumentNull(a_pList->firstElement); returnElement = a_pList->firstElement->data; a_pList->firstElement->data = OpcUa_Null; OpcUa_List_ResetCurrent(a_pList); OpcUa_List_DeleteCurrentElement(a_pList); return returnElement; Error: return OpcUa_Null; }
/* Iterates over all connections, closes and deletes each. The given callback is called everytime. */ OpcUa_StatusCode OpcUa_TcpListener_ConnectionManager_RemoveConnections( OpcUa_TcpListener_ConnectionManager* a_pConnectionManager, OpcUa_TcpListener_ConnectionDeleteCB a_fConnectionDeleteCB) { OpcUa_StatusCode uStatus = OpcUa_Good; OpcUa_TcpListener_Connection* tcpConnection = OpcUa_Null; OpcUa_DeclareErrorTraceModule(OpcUa_Module_TcpListener); OpcUa_ReturnErrorIfArgumentNull(a_pConnectionManager); /*OpcUa_ReturnErrorIfArgumentNull(a_fConnectionDeleteCB);*/ /* obtain lock on the list */ OpcUa_List_Enter(a_pConnectionManager->Connections); /* prepare cursor for iteration over all elements */ OpcUa_List_ResetCurrent(a_pConnectionManager->Connections); tcpConnection = (OpcUa_TcpListener_Connection*)OpcUa_List_GetCurrentElement(a_pConnectionManager->Connections); /* check every Connection for deletion */ while(tcpConnection != OpcUa_Null) { if(a_fConnectionDeleteCB != OpcUa_Null) { a_fConnectionDeleteCB( a_pConnectionManager->Listener, tcpConnection); } OpcUa_TcpListener_Connection_Delete((&tcpConnection)); OpcUa_List_DeleteCurrentElement(a_pConnectionManager->Connections); tcpConnection = (OpcUa_TcpListener_Connection*)OpcUa_List_GetCurrentElement(a_pConnectionManager->Connections); } /* list must be empty here */ /* leave it */ OpcUa_List_Leave(a_pConnectionManager->Connections); return uStatus; }