コード例 #1
0
ファイル: opcua_p_mutex.c プロジェクト: biancode/UA-AnsiC
/*============================================================================
 * Allocate the mutex.
 *===========================================================================*/
OpcUa_StatusCode OPCUA_DLLCALL OpcUa_P_Mutex_Create(OpcUa_Mutex* a_phMutex)
{
    OpcUa_StatusCode uStatus        = OpcUa_Good;
    OpcUa_Mutex      hMutex;

    if(a_phMutex == OpcUa_Null)
    {
        return OpcUa_BadInvalidArgument;
    }

    hMutex = (OpcUa_Mutex)malloc(sizeof(pthread_mutex_t));
    OpcUa_ReturnErrorIfAllocFailed(hMutex);

    uStatus = OpcUa_P_Mutex_Initialize(hMutex);

    if(OpcUa_IsBad(uStatus))
    {
        free(hMutex);
    }
    else
    {
        *a_phMutex = hMutex;
    }

    return uStatus;
}
コード例 #2
0
ファイル: opcua_p_mutex.c プロジェクト: biancode/UA-AnsiC
/*============================================================================
 * Allocate the mutex.
 *===========================================================================*/
OpcUa_StatusCode OPCUA_DLLCALL OpcUa_P_Mutex_Create(OpcUa_Mutex* phMutex)
{
    OpcUa_StatusCode uStatus        = OpcUa_Good;
    pthread_mutex_t* pPosixMutex    = OpcUa_Null;

    if(phMutex == OpcUa_Null)
    {
        return OpcUa_BadInvalidArgument;
    }

    pPosixMutex = OpcUa_P_Memory_Alloc(sizeof(pthread_mutex_t));
    OpcUa_ReturnErrorIfAllocFailed(pPosixMutex);

    uStatus = OpcUa_P_Mutex_Initialize((OpcUa_Mutex)pPosixMutex);
    if(OpcUa_IsBad(uStatus))
    {
        OpcUa_P_Mutex_Delete((OpcUa_Mutex*)&pPosixMutex);
    }
    else
    {
        *phMutex = (OpcUa_Mutex)pPosixMutex;
    }

    return uStatus;
}
コード例 #3
0
ファイル: opcua_list.c プロジェクト: OPCFoundation/UA-AnsiC
/**
  @brief Creates and initializes a new list element

  @return OpcUa_Good on success

  @param a_ppNewElement [in/out]    Location of a pointer to the new List Element
*/
OpcUa_StatusCode OpcUa_ListElement_Create(OpcUa_ListElement** a_ppNewElement)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);
    OpcUa_ReturnErrorIfArgumentNull(a_ppNewElement);

    *a_ppNewElement = (OpcUa_ListElement*)OpcUa_Alloc(sizeof(OpcUa_ListElement));

    OpcUa_ReturnErrorIfAllocFailed(*a_ppNewElement);

    OpcUa_ListElement_Initialize(*a_ppNewElement);

    return OpcUa_Good;
}
コード例 #4
0
/**
* @brief Allocate and initialize a new OpcUa_TcpListener_Connection object.
*
* @return Bad status on fail; Good status on success;
*/
OpcUa_StatusCode OpcUa_TcpListener_Connection_Create(OpcUa_TcpListener_Connection** a_ppConnection)
{
    OpcUa_TcpListener_Connection*   pConnection = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_TcpListener);

    pConnection = (OpcUa_TcpListener_Connection*) OpcUa_Alloc(sizeof(OpcUa_TcpListener_Connection));
    OpcUa_ReturnErrorIfAllocFailed(pConnection);
    OpcUa_MemSet(pConnection, 0, sizeof(OpcUa_TcpListener_Connection));

    pConnection->uCurrentChunk  = 0;

    OpcUa_TcpListener_Connection_Initialize(pConnection);

    *a_ppConnection = pConnection;
    return OpcUa_Good;
}
コード例 #5
0
/*============================================================================
 * Create a platform thread
 *===========================================================================*/
OpcUa_StatusCode OPCUA_DLLCALL OpcUa_P_Thread_Create(OpcUa_RawThread* pRawThread)
{
    OpcUa_StatusCode   uStatus     = OpcUa_Good;
    OpcUa_P_ThreadArg* pThreadArgs = OpcUa_Null;

    *pRawThread = OpcUa_Null;

    pThreadArgs = (OpcUa_P_ThreadArg*)OpcUa_P_Memory_Alloc(sizeof(OpcUa_P_ThreadArg));
    OpcUa_ReturnErrorIfAllocFailed(pThreadArgs);

    pThreadArgs->hThread                = INVALID_HANDLE_VALUE;
    pThreadArgs->pfnInternalThreadMain  = OpcUa_Null;
    pThreadArgs->ThreadArgs             = OpcUa_Null;

    *pRawThread = (OpcUa_RawThread)pThreadArgs;

    return uStatus;
}
コード例 #6
0
ファイル: opcua_thread.c プロジェクト: OPCFoundation/UA-AnsiC
/*============================================================================
 * Create
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Thread_Create(   OpcUa_Thread*           a_pThread,
                                        OpcUa_PfnThreadMain*    a_pThreadMain,
                                        OpcUa_Void*             a_pThreadArgument)
{
    OpcUa_StatusCode        uStatus = OpcUa_Good;
    OpcUa_ThreadInternal*   pThread = OpcUa_Null;

    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Thread);

    OpcUa_ReturnErrorIfArgumentNull(a_pThread);
    OpcUa_ReturnErrorIfArgumentNull(a_pThreadMain);

    pThread = (OpcUa_ThreadInternal*)OpcUa_Alloc(sizeof(OpcUa_ThreadInternal));

    OpcUa_ReturnErrorIfAllocFailed(pThread);

    OpcUa_MemSet(pThread, 0, sizeof(OpcUa_ThreadInternal));

    pThread->IsRunning      = OpcUa_False;
    pThread->ThreadMain     = a_pThreadMain;
    pThread->ThreadData     = a_pThreadArgument;
    pThread->Mutex          = OpcUa_Null;
    pThread->ShutdownEvent  = OpcUa_Null;

    uStatus = OpcUa_P_Thread_Create(&(pThread->RawThread));
    OpcUa_GotoErrorIfBad(uStatus);

    uStatus = OPCUA_P_SEMAPHORE_CREATE( &(pThread->ShutdownEvent),
                                        1,  /* the initial value is 1 (signalled, 1 free resource) */
                                        1); /* the maximum value is 1 */
    OpcUa_GotoErrorIfBad(uStatus);

    uStatus = OPCUA_P_MUTEX_CREATE(&(pThread->Mutex));
    OpcUa_GotoErrorIfBad(uStatus);

    *a_pThread = pThread;

    return OpcUa_Good;

Error:

    return uStatus;
}
コード例 #7
0
/**
 * Create a new connection manager
 * @param a_ppConnectionManager Description
 * @return StatusCode
 */
OpcUa_StatusCode OpcUa_TcpListener_ConnectionManager_Create(
    OpcUa_TcpListener_ConnectionManager** a_ppConnectionManager)
{
    OpcUa_TcpListener_ConnectionManager *pConnMngr  = OpcUa_Null;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_TcpListener);

    OpcUa_ReturnErrorIfArgumentNull(a_ppConnectionManager);

    *a_ppConnectionManager = OpcUa_Null;

    pConnMngr = (OpcUa_TcpListener_ConnectionManager*)OpcUa_Alloc(sizeof(OpcUa_TcpListener_ConnectionManager));
    OpcUa_ReturnErrorIfAllocFailed(pConnMngr);

    OpcUa_TcpListener_ConnectionManager_Initialize(pConnMngr);

    if(pConnMngr->Connections == OpcUa_Null)
    {
        OpcUa_TcpListener_ConnectionManager_Delete(&pConnMngr);
    }

    *a_ppConnectionManager = pConnMngr;
    return OpcUa_Good;
}
コード例 #8
0
ファイル: opcua_list.c プロジェクト: OPCFoundation/UA-AnsiC
/**
  @brief Creates a new empty list.

  Crashes if a_ppNewList is null
  @return OpcUa_Good on success

  @param a_ppNewList    [in/out]    Location of a pointer to the new list
*/
 OpcUa_StatusCode OpcUa_List_Create(OpcUa_List** a_ppNewList)
{
    OpcUa_List*         pNewList    = OpcUa_Null;
    OpcUa_StatusCode    uStatus     = OpcUa_Good;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_List);

    OpcUa_ReturnErrorIfArgumentNull(a_ppNewList);

    *a_ppNewList = OpcUa_Null;

    pNewList = (OpcUa_List*)OpcUa_Alloc(sizeof(OpcUa_List));
    OpcUa_ReturnErrorIfAllocFailed(pNewList);

    uStatus = OpcUa_List_Initialize(pNewList);
    if(OpcUa_IsBad(uStatus))
    {
        /* error during initialize -> Cleanup */
        OpcUa_List_Delete(&pNewList);
    }

    *a_ppNewList = pNewList;

    return uStatus;
}
コード例 #9
0
/*============================================================================
 * OpcUa_TcpSecureChannel_Create
 *===========================================================================*/
OpcUa_StatusCode OpcUa_TcpSecureChannel_Create(OpcUa_SecureChannel** a_ppSecureChannel)
{
    OpcUa_TcpSecureChannel* pTcpSecureChannel = OpcUa_Null;

OpcUa_InitializeStatus(OpcUa_Module_SecureChannel, "Create");

    *a_ppSecureChannel = OpcUa_Null;

    pTcpSecureChannel = (OpcUa_TcpSecureChannel*)OpcUa_Alloc(sizeof(OpcUa_TcpSecureChannel));
    OpcUa_ReturnErrorIfAllocFailed(pTcpSecureChannel);
    OpcUa_MemSet(pTcpSecureChannel, 0, sizeof(OpcUa_TcpSecureChannel));

    *a_ppSecureChannel = (OpcUa_SecureChannel*)OpcUa_Alloc(sizeof(OpcUa_SecureChannel));
    OpcUa_GotoErrorIfAllocFailed(*a_ppSecureChannel);
    OpcUa_MemSet(*a_ppSecureChannel, 0, sizeof(OpcUa_SecureChannel));

    (*a_ppSecureChannel)->SecureChannelId           = OPCUA_SECURECHANNEL_ID_INVALID;
    (*a_ppSecureChannel)->NextTokenId               = 1;
    (*a_ppSecureChannel)->uLastSequenceNumberRcvd   = 0xFFFFFFFFU;
    (*a_ppSecureChannel)->uLastSequenceNumberSent   = OPCUA_SECURECHANNEL_STARTING_SEQUENCE_NUMBER;
    (*a_ppSecureChannel)->Handle                    = pTcpSecureChannel;
    (*a_ppSecureChannel)->Open                      = OpcUa_TcpSecureChannel_Open;
    (*a_ppSecureChannel)->Renew                     = OpcUa_TcpSecureChannel_Renew;
    (*a_ppSecureChannel)->Close                     = OpcUa_TcpSecureChannel_Close;
    (*a_ppSecureChannel)->GenerateSecurityToken     = OpcUa_TcpSecureChannel_GenerateSecurityToken;
    (*a_ppSecureChannel)->RenewSecurityToken        = OpcUa_TcpSecureChannel_RenewSecurityToken;
    (*a_ppSecureChannel)->GetSecuritySet            = OpcUa_TcpSecureChannel_GetSecuritySet;
    (*a_ppSecureChannel)->GetCurrentSecuritySet     = OpcUa_TcpSecureChannel_GetCurrentSecuritySet;
    (*a_ppSecureChannel)->ReleaseSecuritySet        = OpcUa_TcpSecureChannel_ReleaseSecuritySet;
    (*a_ppSecureChannel)->GetSequenceNumber         = OpcUa_TcpSecureChannel_GetSequenceNumber;
    (*a_ppSecureChannel)->CheckSequenceNumber       = OpcUa_TcpSecureChannel_CheckSequenceNumber;
    (*a_ppSecureChannel)->LockWriteMutex            = OpcUa_TcpSecureChannel_LockWriteMutex;
    (*a_ppSecureChannel)->UnlockWriteMutex          = OpcUa_TcpSecureChannel_UnlockWriteMutex;
    (*a_ppSecureChannel)->IsOpen                    = OpcUa_SecureChannel_IsOpen;
    (*a_ppSecureChannel)->DiscoveryOnly             = OpcUa_False;
    (*a_ppSecureChannel)->MessageSecurityMode       = OpcUa_MessageSecurityMode_None;

    uStatus = OPCUA_P_MUTEX_CREATE(&((*a_ppSecureChannel)->hSyncAccess));
    OpcUa_GotoErrorIfBad(uStatus);
    uStatus = OPCUA_P_MUTEX_CREATE(&((*a_ppSecureChannel)->hWriteMutex));
    OpcUa_GotoErrorIfBad(uStatus);
    OpcUa_String_Initialize(&((*a_ppSecureChannel)->SecurityPolicyUri));
    OpcUa_String_Initialize(&((*a_ppSecureChannel)->sPeerInfo));

OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;

    if (*a_ppSecureChannel != OpcUa_Null)
    {
        if((*a_ppSecureChannel)->hSyncAccess != OpcUa_Null)
        {
            OPCUA_P_MUTEX_DELETE(&((*a_ppSecureChannel)->hSyncAccess));
        }

        if((*a_ppSecureChannel)->hWriteMutex != OpcUa_Null)
        {
            OPCUA_P_MUTEX_DELETE(&((*a_ppSecureChannel)->hWriteMutex));
        }

        OpcUa_Free(*a_ppSecureChannel);
        *a_ppSecureChannel = OpcUa_Null;
    }

    OpcUa_Free(pTcpSecureChannel);

OpcUa_FinishErrorHandling;
}