Beispiel #1
0
/**
  @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 Retrieves a started stream for the connection identified by the socket.
 *
 * @return StatusCode
 */
OpcUa_StatusCode OpcUa_TcpListener_ConnectionManager_GetConnectionBySocket(
    OpcUa_TcpListener_ConnectionManager*    a_pConnectionManager,
    OpcUa_Socket                            a_pSocket,
    OpcUa_TcpListener_Connection**          a_ppConnection)
{
    OpcUa_StatusCode                uStatus         = OpcUa_Good;
    OpcUa_TcpListener_Connection*   tmpConnection   = OpcUa_Null;

    OpcUa_ReturnErrorIfArgumentNull(a_pConnectionManager);
    OpcUa_ReturnErrorIfArgumentNull(a_pConnectionManager->Connections);
    OpcUa_ReturnErrorIfArgumentNull(a_pSocket);
    OpcUa_ReturnErrorIfArgumentNull(a_ppConnection);

    *a_ppConnection = OpcUa_Null;

    OpcUa_List_Enter(a_pConnectionManager->Connections);

    uStatus = OpcUa_BadNotFound;

    OpcUa_List_ResetCurrent(a_pConnectionManager->Connections);
    tmpConnection = (OpcUa_TcpListener_Connection*)OpcUa_List_GetCurrentElement(a_pConnectionManager->Connections);

    while(tmpConnection != OpcUa_Null)
    {
        if(a_pSocket == tmpConnection->Socket)
        {
            *a_ppConnection = tmpConnection;

            uStatus = OpcUa_Good;
            break;
        }
        tmpConnection = (OpcUa_TcpListener_Connection *)OpcUa_List_GetNextElement(a_pConnectionManager->Connections);
    }

    OpcUa_List_Leave(a_pConnectionManager->Connections);

    return uStatus;
}