コード例 #1
0
ファイル: opcua_thread.c プロジェクト: OPCFoundation/UA-AnsiC
/*============================================================================
 * Start a created thread.
 *===========================================================================*/
OpcUa_StatusCode OpcUa_Thread_Start(OpcUa_Thread a_Thread)
{
    OpcUa_StatusCode        uStatus     = OpcUa_Good;
    OpcUa_ThreadInternal*   pThread     = OpcUa_Null;
    OpcUa_Int32             intThreadId = 0;

    OpcUa_ReturnErrorIfArgumentNull(a_Thread);

    pThread = (OpcUa_ThreadInternal*)a_Thread;

    OPCUA_P_MUTEX_LOCK(pThread->Mutex);
    if(pThread->IsRunning != OpcUa_False)
    {
        OPCUA_P_MUTEX_UNLOCK(pThread->Mutex);
        return OpcUa_Good;
    }

    /* set semaphore to waitable */
    uStatus = OPCUA_P_SEMAPHORE_WAIT((pThread->ShutdownEvent));
    OpcUa_GotoErrorIfBad(uStatus);

    pThread->IsRunning = OpcUa_True;

    intThreadId = OpcUa_P_Thread_Start( pThread->RawThread,
                                        InternalThreadMain,
                                        (OpcUa_Void*)pThread);

    if(intThreadId != 0)
    {
        pThread->IsRunning = OpcUa_False;

        OPCUA_P_MUTEX_UNLOCK(pThread->Mutex);
        uStatus = OpcUa_BadInternalError;
        OpcUa_Trace(OPCUA_TRACE_LEVEL_ERROR, "OpcUa_Thread_Start: Error during thread creation!\n");
        goto Error;
    }
    OPCUA_P_MUTEX_UNLOCK(pThread->Mutex);

    return OpcUa_Good;

Error:

    return uStatus;
}
コード例 #2
0
ファイル: opcua_thread.c プロジェクト: OPCFoundation/UA-AnsiC
/* conversion is done internally, the parameter must be filled with a value representing milliseconds */
OpcUa_StatusCode OpcUa_Thread_WaitForShutdown(  OpcUa_Thread a_Thread,
                                                OpcUa_UInt32 a_msecTimeout)
{
    OpcUa_StatusCode        uStatus = OpcUa_Good;
    OpcUa_ThreadInternal*   Thread  = OpcUa_Null;
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_Thread);

    Thread = (OpcUa_ThreadInternal*)a_Thread;

    OpcUa_ReturnErrorIfArgumentNull(Thread);

    OPCUA_P_MUTEX_LOCK(Thread->Mutex);
    if(Thread->IsRunning == OpcUa_False)
    {
        /* printf("wait for shutdown: thread is not running\n");*/
        OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);
        return OpcUa_Good;
    }
    OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);

    uStatus = OPCUA_P_SEMAPHORE_TIMEDWAIT(Thread->ShutdownEvent, a_msecTimeout);
    if(OpcUa_IsBad(uStatus))
    {
        return uStatus;
    }

    OPCUA_P_MUTEX_LOCK(Thread->Mutex);
    if(Thread->IsRunning == OpcUa_False)
    {
        /* Release the semaphore again to enable other threads waiting on it to get unlocked. */
        uStatus = OPCUA_P_SEMAPHORE_POST(   Thread->ShutdownEvent,
                                            1);
        /*printf("wait for shutdown: thread stopped\n");*/
        OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);
        return OpcUa_Good;
    }

    OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);

    /* printf("wait for shutdown: thread is still running\n");*/

    return OpcUa_GoodNonCriticalTimeout;
}
コード例 #3
0
/*============================================================================
 * OpcUa_ProxyStub_Clear
 *===========================================================================*/
OpcUa_Void OPCUA_DLLCALL OpcUa_ProxyStub_Clear(OpcUa_Void)
{
    OpcUa_Boolean bSkip = OpcUa_False;

    if(OpcUa_ProxyStub_g_PlatformLayerCalltable == OpcUa_Null)
    {
        /* error */
        return;
    }
    else
    {
#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_LOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

        OpcUa_ProxyStub_g_uNoOfInits--;

        if(OpcUa_ProxyStub_g_uNoOfInits > 0)
        {
            bSkip = OpcUa_True;
        }

#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_UNLOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

        if(bSkip == OpcUa_False)
        {
            if(OpcUa_ProxyStub_g_pConfigString != OpcUa_Null)
            {
                OpcUa_Free(OpcUa_ProxyStub_g_pConfigString);
                OpcUa_ProxyStub_g_pConfigString = OpcUa_Null;
            }

            /* P-Layer resource */
            OpcUa_Trace(OPCUA_TRACE_LEVEL_INFO, "OpcUa_ProxyStub_Clear: Network Module...\n");
            OPCUA_P_CLEANUPNETWORK();
            OPCUA_P_CLEANUPTIMERS(); /* Forces a stop of all timers not yet deleted. Leads to callbacks! */
#if OPCUA_USE_SYNCHRONISATION
            OPCUA_P_MUTEX_DELETE(&OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */
            OpcUa_Trace(OPCUA_TRACE_LEVEL_INFO, "OpcUa_ProxyStub_Clear: Network Module done!\n");

#if OPCUA_TRACE_ENABLE
            /* internal resource */
            OpcUa_Trace_Clear();
#endif /* OPCUA_TRACE_ENABLE */

            OpcUa_EncodeableTypeTable_Delete(&OpcUa_ProxyStub_g_EncodeableTypes);
            OpcUa_StringTable_Clear(&OpcUa_ProxyStub_g_NamespaceUris);

            OpcUa_ProxyStub_g_PlatformLayerCalltable = OpcUa_Null;
        }
    }
}
コード例 #4
0
ファイル: opcua_list.c プロジェクト: OPCFoundation/UA-AnsiC
/**
  @brief Unlocks the internal mutex and allows other threads to enter the list.

  Takes no action if a_pList is null
  Takes no action if the mutex is null

  @param a_pList    [in]    Location of the list to leave
*/
OpcUa_Void OpcUa_List_Leave(OpcUa_List* a_pList)
{
#if OPCUA_USE_SYNCHRONISATION
    if(a_pList != OpcUa_Null && a_pList->pMutex != OpcUa_Null)
    {
        OPCUA_P_MUTEX_UNLOCK(a_pList->pMutex);
    }
#else /* OPCUA_USE_SYNCHRONISATION */
    OpcUa_ReferenceParameter(a_pList);
#endif /* OPCUA_USE_SYNCHRONISATION */
}
コード例 #5
0
/*============================================================================
 * OpcUa_ProxyStub_DeRegisterEndpoint
 *===========================================================================*/
OpcUa_Void OpcUa_ProxyStub_DeRegisterEndpoint(OpcUa_Void)
{
#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_LOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

    --OpcUa_ProxyStub_g_uNoOfEndpoints;

#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_UNLOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */
}
コード例 #6
0
/*============================================================================
 * OpcUa_ProxyStub_RegisterChannel
 *===========================================================================*/
OpcUa_Void OpcUa_ProxyStub_RegisterChannel(OpcUa_Void)
{
#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_LOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

    ++OpcUa_ProxyStub_g_uNoOfChannels;

#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_UNLOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */
}
コード例 #7
0
/** 
 * Activate or deactivate trace output during runtime.
 * @param a_uNewTraceLevel Description
 */
OpcUa_Void OPCUA_DLLCALL OpcUa_Trace_ChangeTraceLevel(OpcUa_UInt32 a_uNewTraceLevel)
{
#if OPCUA_USE_SYNCHRONISATION
    if(OpcUa_Trace_s_pLock == OpcUa_Null)
    {
        return;
    }
    OPCUA_P_MUTEX_LOCK(OpcUa_Trace_s_pLock);
#endif /* OPCUA_USE_SYNCHRONISATION */

    OpcUa_ProxyStub_g_Configuration.uProxyStub_Trace_Level = a_uNewTraceLevel;

#if OPCUA_USE_SYNCHRONISATION
    OPCUA_P_MUTEX_UNLOCK(OpcUa_Trace_s_pLock);
#endif /* OPCUA_USE_SYNCHRONISATION */

    return;
}
コード例 #8
0
ファイル: opcua_thread.c プロジェクト: OPCFoundation/UA-AnsiC
/*============================================================================
 * The internal main entry function.
 *===========================================================================*/
static
OpcUa_Void InternalThreadMain(OpcUa_Void* a_Thread)
{
    OpcUa_ThreadInternal* Thread = (OpcUa_ThreadInternal*)a_Thread;

    if(Thread == OpcUa_Null)
    {
        return;
    }

    /* call the user function */
    Thread->ThreadMain(Thread->ThreadData);

    OPCUA_P_MUTEX_LOCK(Thread->Mutex);
    Thread->IsRunning = OpcUa_False;
    OPCUA_P_SEMAPHORE_POST(Thread->ShutdownEvent, 1);
    OPCUA_P_MUTEX_UNLOCK(Thread->Mutex);
}
コード例 #9
0
ファイル: opcua_thread.c プロジェクト: OPCFoundation/UA-AnsiC
/*============================================================================
 * Check if the main function of the given thread object is running.
 *===========================================================================*/
OpcUa_Boolean OpcUa_Thread_IsRunning(OpcUa_Thread a_hThread)
{
    OpcUa_ThreadInternal* pThread = (OpcUa_ThreadInternal*)a_hThread;
    OpcUa_Boolean bTemp = OpcUa_False;

    if(OpcUa_Null == pThread)
    {
        return OpcUa_False;
    }

    OPCUA_P_MUTEX_LOCK(pThread->Mutex);

    bTemp = pThread->IsRunning;

    OPCUA_P_MUTEX_UNLOCK(pThread->Mutex);

    return bTemp;
}
コード例 #10
0
/** 
 * Activate or deactivate trace output during runtime.
 * @param a_bActive Description 
 */
OpcUa_Void OPCUA_DLLCALL OpcUa_Trace_Toggle(OpcUa_Boolean a_bActive)
{
#if OPCUA_USE_SYNCHRONISATION
    if(OpcUa_Trace_s_pLock == OpcUa_Null)
    {
        return;
    }
    OPCUA_P_MUTEX_LOCK(OpcUa_Trace_s_pLock);
#endif /* OPCUA_USE_SYNCHRONISATION */

    /* check if app wants trace output */
    OpcUa_ProxyStub_g_Configuration.bProxyStub_Trace_Enabled = a_bActive;

#if OPCUA_USE_SYNCHRONISATION
    OPCUA_P_MUTEX_UNLOCK(OpcUa_Trace_s_pLock);
#endif /* OPCUA_USE_SYNCHRONISATION */

    return;
}
コード例 #11
0
/*============================================================================
 * OpcUa_ProxyStub_UpdateConfigString
 *===========================================================================*/
static OpcUa_StatusCode OpcUa_ProxyStub_UpdateConfigString()
{
    OpcUa_Int  iRes  = 0;
    OpcUa_Int  iPos  = 0;

OpcUa_InitializeStatus(OpcUa_Module_ProxyStub, "UpdateConfigString");

#if OPCUA_USE_SYNCHRONISATION
    OPCUA_P_MUTEX_LOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

    if(OpcUa_ProxyStub_g_pConfigString == OpcUa_Null)
    {
        OpcUa_ProxyStub_g_pConfigString = (OpcUa_StringA) OpcUa_Alloc(OPCUA_CONFIG_STRING_SIZE + 1);
        OpcUa_GotoErrorIfAllocFailed(OpcUa_ProxyStub_g_pConfigString);
        OpcUa_MemSet(OpcUa_ProxyStub_g_pConfigString, 0, OPCUA_CONFIG_STRING_SIZE + 1);
    }

#if OPCUA_USE_SAFE_FUNCTIONS

    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "TraceEnabled", (OpcUa_ProxyStub_g_Configuration.bProxyStub_Trace_Enabled != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadInternalError);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "TraceLevel", OpcUa_ProxyStub_g_Configuration.uProxyStub_Trace_Level);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxAlloc", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxAlloc);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxStringLength", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxStringLength);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxByteStringLength", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxByteStringLength);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxArrayLength", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxArrayLength);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxMessageSize", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxMessageSize);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "bSecureListener_ThreadPool_Enabled", (OpcUa_ProxyStub_g_Configuration.bSecureListener_ThreadPool_Enabled != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSecureListener_ThreadPool_MinThreads", OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MinThreads);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSecureListener_ThreadPool_MaxThreads", OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MaxThreads);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSecureListener_ThreadPool_MaxJobs", OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MaxJobs);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "bSecureListener_ThreadPool_BlockOnAdd", (OpcUa_ProxyStub_g_Configuration.bSecureListener_ThreadPool_BlockOnAdd != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "uSecureListener_ThreadPool_Timeout", OpcUa_ProxyStub_g_Configuration.uSecureListener_ThreadPool_Timeout);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "bTcpListener_ClientThreadsEnabled", (OpcUa_ProxyStub_g_Configuration.bTcpListener_ClientThreadsEnabled != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iTcpListener_DefaultChunkSize", OpcUa_ProxyStub_g_Configuration.iTcpListener_DefaultChunkSize);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iTcpConnection_DefaultChunkSize", OpcUa_ProxyStub_g_Configuration.iTcpConnection_DefaultChunkSize);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iTcpTransport_MaxMessageLength", OpcUa_ProxyStub_g_Configuration.iTcpTransport_MaxMessageLength);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iTcpTransport_MaxChunkCount", OpcUa_ProxyStub_g_Configuration.iTcpTransport_MaxChunkCount);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "bTcpStream_ExpectWriteToBlock", (OpcUa_ProxyStub_g_Configuration.bTcpStream_ExpectWriteToBlock != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}

#else /* OPCUA_USE_SAFE_FUNCTIONS */

    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "TraceEnabled", (OpcUa_ProxyStub_g_Configuration.bProxyStub_Trace_Enabled != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadInternalError);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "TraceLevel", OpcUa_ProxyStub_g_Configuration.uProxyStub_Trace_Level);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxAlloc", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxAlloc);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxStringLength", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxStringLength);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxByteStringLength", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxByteStringLength);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxArrayLength", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxArrayLength);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSerializer_MaxMessageSize", OpcUa_ProxyStub_g_Configuration.iSerializer_MaxMessageSize);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "bSecureListener_ThreadPool_Enabled", (OpcUa_ProxyStub_g_Configuration.bSecureListener_ThreadPool_Enabled != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSecureListener_ThreadPool_MinThreads", OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MinThreads);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSecureListener_ThreadPool_MaxThreads", OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MaxThreads);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iSecureListener_ThreadPool_MaxJobs", OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MaxJobs);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "bSecureListener_ThreadPool_BlockOnAdd", (OpcUa_ProxyStub_g_Configuration.bSecureListener_ThreadPool_BlockOnAdd != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "uSecureListener_ThreadPool_Timeout", OpcUa_ProxyStub_g_Configuration.uSecureListener_ThreadPool_Timeout);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "bTcpListener_ClientThreadsEnabled", (OpcUa_ProxyStub_g_Configuration.bTcpListener_ClientThreadsEnabled != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iTcpListener_DefaultChunkSize", OpcUa_ProxyStub_g_Configuration.iTcpListener_DefaultChunkSize);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iTcpConnection_DefaultChunkSize", OpcUa_ProxyStub_g_Configuration.iTcpConnection_DefaultChunkSize);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iTcpTransport_MaxMessageLength", OpcUa_ProxyStub_g_Configuration.iTcpTransport_MaxMessageLength);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%i\\", "iTcpTransport_MaxChunkCount", OpcUa_ProxyStub_g_Configuration.iTcpTransport_MaxChunkCount);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}
    iRes = OpcUa_SnPrintfA(&OpcUa_ProxyStub_g_pConfigString[iPos], OPCUA_CONFIG_STRING_SIZE - iPos, "%s:%u\\", "bTcpStream_ExpectWriteToBlock", (OpcUa_ProxyStub_g_Configuration.bTcpStream_ExpectWriteToBlock != 0)?1:0);
    if(iRes > 0){iPos += iRes;}else{OpcUa_GotoErrorWithStatus(OpcUa_BadOutOfMemory);}

#endif /* OPCUA_USE_SAFE_FUNCTIONS */

#if OPCUA_USE_SYNCHRONISATION
    OPCUA_P_MUTEX_UNLOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
コード例 #12
0
/*============================================================================
 * OpcUa_ProxyStub_Initialize
 *===========================================================================*/
OpcUa_StatusCode OPCUA_DLLCALL OpcUa_ProxyStub_Initialize(OpcUa_Handle                  a_pPlatformLayerCalltable,
                                                          OpcUa_ProxyStubConfiguration* a_pProxyStubConfiguration)
{
    OpcUa_Boolean bSkip = OpcUa_False;

OpcUa_InitializeStatus(OpcUa_Module_ProxyStub, "Initialize");

    OpcUa_ReturnErrorIfArgumentNull(a_pProxyStubConfiguration)
    OpcUa_ReturnErrorIfArgumentNull(a_pPlatformLayerCalltable);

    /* set global platform layer handle */
    OpcUa_ProxyStub_g_PlatformLayerCalltable = (OpcUa_Port_CallTable *)a_pPlatformLayerCalltable;

#if OPCUA_USE_SYNCHRONISATION
    if(OpcUa_ProxyStub_g_hGlobalsMutex == OpcUa_Null)
    {
        uStatus = OPCUA_P_MUTEX_CREATE(&OpcUa_ProxyStub_g_hGlobalsMutex);
        OpcUa_GotoErrorIfBad(uStatus);
    }
#endif /* OPCUA_USE_SYNCHRONISATION */

#if OPCUA_USE_SYNCHRONISATION
    OPCUA_P_MUTEX_LOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

    OpcUa_ProxyStub_g_uNoOfInits++;

    if(OpcUa_ProxyStub_g_uNoOfInits > 1)
    {
        bSkip = OpcUa_True;
    }

#if OPCUA_USE_SYNCHRONISATION
    OPCUA_P_MUTEX_UNLOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

    if(bSkip == OpcUa_False)
    {
        /* set global configuration object */
        uStatus = OpcUa_ProxyStub_ReInitialize(a_pProxyStubConfiguration);
        OpcUa_GotoErrorIfBad(uStatus);

        /* initialize tracer */
#if OPCUA_TRACE_ENABLE
        uStatus = OpcUa_Trace_Initialize();
        OpcUa_GotoErrorIfBad(uStatus);
        OpcUa_Trace(OPCUA_TRACE_LEVEL_INFO, "OpcUa_ProxyStub_Initialize: Tracer has been initialized!\n");
#endif /* OPCUA_TRACE_ENABLE */

        /* initialize networking. */
        OpcUa_Trace(OPCUA_TRACE_LEVEL_INFO, "OpcUa_ProxyStub_Initialize: Network Module...\n");
        uStatus = OPCUA_P_INITIALIZENETWORK();
        OpcUa_GotoErrorIfBad(uStatus);
        OpcUa_Trace(OPCUA_TRACE_LEVEL_INFO, "OpcUa_ProxyStub_Initialize: Network Module done!\n");

        uStatus = OpcUa_EncodeableTypeTable_Create(&OpcUa_ProxyStub_g_EncodeableTypes);
        OpcUa_GotoErrorIfBad(uStatus);

        uStatus = OpcUa_EncodeableTypeTable_AddTypes(&OpcUa_ProxyStub_g_EncodeableTypes, OpcUa_KnownEncodeableTypes);
        OpcUa_GotoErrorIfBad(uStatus);

        OpcUa_StringTable_Initialize(&OpcUa_ProxyStub_g_NamespaceUris);
        uStatus = OpcUa_StringTable_AddStringList(&OpcUa_ProxyStub_g_NamespaceUris, OpcUa_ProxyStub_StandardNamespaceUris);
        OpcUa_GotoErrorIfBad(uStatus);
    }

OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;

    OpcUa_ProxyStub_Clear();

OpcUa_FinishErrorHandling;
}
コード例 #13
0
/*============================================================================
 * OpcUa_ProxyStub_ReInitialize
 *===========================================================================*/
OpcUa_StatusCode OPCUA_DLLCALL OpcUa_ProxyStub_ReInitialize(OpcUa_ProxyStubConfiguration* a_pProxyStubConfiguration)
{
OpcUa_InitializeStatus(OpcUa_Module_ProxyStub, "ReInitialize");

#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_LOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

    OpcUa_GotoErrorIfArgumentNull(a_pProxyStubConfiguration);

    if((OpcUa_ProxyStub_g_uNoOfChannels != 0) || (OpcUa_ProxyStub_g_uNoOfEndpoints != 0))
    {
        OpcUa_GotoErrorWithStatus(OpcUa_BadInvalidState);
    }

    /* set global configuration object */
    OpcUa_ProxyStub_g_Configuration = *a_pProxyStubConfiguration;

    /* check for negative values and fall back to default values in opcua_config.h */
    if(OpcUa_ProxyStub_g_Configuration.iSerializer_MaxAlloc == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iSerializer_MaxAlloc                     = OPCUA_SERIALIZER_MAXALLOC; /* currently unused */
    }
    if(OpcUa_ProxyStub_g_Configuration.iSerializer_MaxStringLength == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iSerializer_MaxStringLength              = OPCUA_ENCODER_MAXSTRINGLENGTH;
    }
    if(OpcUa_ProxyStub_g_Configuration.iSerializer_MaxByteStringLength == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iSerializer_MaxByteStringLength          = OPCUA_ENCODER_MAXBYTESTRINGLENGTH;
    }
    if(OpcUa_ProxyStub_g_Configuration.iSerializer_MaxArrayLength == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iSerializer_MaxArrayLength               = OPCUA_ENCODER_MAXARRAYLENGTH;
    }
    if(OpcUa_ProxyStub_g_Configuration.iSerializer_MaxMessageSize == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iSerializer_MaxMessageSize               = OPCUA_ENCODER_MAXMESSAGELENGTH;
    }
    if(OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MinThreads == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MinThreads    = OPCUA_SECURELISTENER_THREADPOOL_MINTHREADS;
    }
    if(OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MaxThreads == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MaxThreads    = OPCUA_SECURELISTENER_THREADPOOL_MAXTHREADS;
    }
    if(OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MaxJobs == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iSecureListener_ThreadPool_MaxJobs       = OPCUA_SECURELISTENER_THREADPOOL_MAXJOBS;
    }
    if(OpcUa_ProxyStub_g_Configuration.iTcpListener_DefaultChunkSize == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iTcpListener_DefaultChunkSize            = OPCUA_TCPLISTENER_DEFAULTCHUNKSIZE;
    }
    if(OpcUa_ProxyStub_g_Configuration.iTcpConnection_DefaultChunkSize == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iTcpConnection_DefaultChunkSize          = OPCUA_TCPCONNECTION_DEFAULTCHUNKSIZE;
    }
    if(OpcUa_ProxyStub_g_Configuration.iTcpTransport_MaxChunkCount == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iTcpTransport_MaxChunkCount              = 0;
    }
    if(OpcUa_ProxyStub_g_Configuration.iTcpTransport_MaxMessageLength == -1)
    {
        OpcUa_ProxyStub_g_Configuration.iTcpTransport_MaxMessageLength           = OPCUA_ENCODER_MAXMESSAGELENGTH;
    }

#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_UNLOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;

#if OPCUA_USE_SYNCHRONISATION
    OPCUA_P_MUTEX_UNLOCK(OpcUa_ProxyStub_g_hGlobalsMutex);
#endif /* OPCUA_USE_SYNCHRONISATION */

OpcUa_FinishErrorHandling;
}
コード例 #14
0
/**
* Writes the given string and the parameters to the trace device, if the given 
* trace level is activated.
*/
OpcUa_Boolean OPCUA_DLLCALL OpcUa_Trace_Imp(OpcUa_UInt32    a_uTraceLevel,
#if OPCUA_TRACE_FILE_LINE_INFO
                                            OpcUa_CharA*    a_sFile,
                                            OpcUa_UInt32    a_sLine,
#endif /* OPCUA_TRACE_FILE_LINE_INFO */
                                            OpcUa_CharA*    a_sFormat,
                                            ...)
{
#if OPCUA_TRACE_ENABLE
    OpcUa_Boolean bTraced = OpcUa_False;

#if OPCUA_USE_SYNCHRONISATION
    if(OpcUa_Trace_s_pLock == OpcUa_Null)
    {
        return OpcUa_False;
    }

    OPCUA_P_MUTEX_LOCK(OpcUa_Trace_s_pLock);
#endif /* OPCUA_USE_SYNCHRONISATION */

    /* check if app wants trace output */
    if(OpcUa_ProxyStub_g_Configuration.bProxyStub_Trace_Enabled == OpcUa_False)
    {
#if OPCUA_USE_SYNCHRONISATION
        OPCUA_P_MUTEX_UNLOCK(OpcUa_Trace_s_pLock);
#endif /* OPCUA_USE_SYNCHRONISATION */
        return OpcUa_False;
    }

    if(a_uTraceLevel & OpcUa_ProxyStub_g_Configuration.uProxyStub_Trace_Level)
    {
        varg_list argumentList;
        VA_START(argumentList, a_sFormat);

        OPCUA_P_STRINGA_VSNPRINTF(OpcUa_Trace_g_aTraceBuffer,
                                  OPCUA_TRACE_MAXLENGTH,
                                  a_sFormat, 
                                  argumentList);

        /* send trace buffer to platform trace device */
#if OPCUA_TRACE_FILE_LINE_INFO
        OPCUA_P_TRACE(a_uTraceLevel, a_sFile, a_sLine, OpcUa_Trace_g_aTraceBuffer);
#else
        OPCUA_P_TRACE(OpcUa_Trace_g_aTraceBuffer);
#endif
        bTraced = OpcUa_True;
        VA_END(argumentList);
    }

#if OPCUA_USE_SYNCHRONISATION
    OPCUA_P_MUTEX_UNLOCK(OpcUa_Trace_s_pLock);
#endif /* OPCUA_USE_SYNCHRONISATION */

    return bTraced;

#else /* OPCUA_TRACE_ENABLE == NO */

    OpcUa_ReferenceParameter(a_uTraceLevel);
    OpcUa_ReferenceParameter(a_sFormat);
#if OPCUA_TRACE_FILE_LINE_INFO
    OpcUa_ReferenceParameter(a_sFile);
    OpcUa_ReferenceParameter(a_sLine);
#endif /* OPCUA_TRACE_FILE_LINE_INFO */

    return OpcUa_False;

#endif /* if OPCUA_TRACE_ENABLE == YES */
}