Beispiel #1
0
/*============================================================================
 * Unlock the mutex.
 *===========================================================================*/
OpcUa_Void OPCUA_DLLCALL OpcUa_P_Mutex_UnlockImp(OpcUa_Mutex hMutex, char* file, int line)
{
    OpcUa_P_InternalMutex* pInternalMutex = OpcUa_Null;

    if(hMutex == OpcUa_Null)
    {
        /* debug */
        printf("InvalidArgument Error in OpcUa_P_Mutex_Unlock: File: %s, Line: %d\n", file, line);
        return;
    }

    pInternalMutex = (OpcUa_P_InternalMutex*)hMutex;

    if(pInternalMutex->nLockCount == 0)
    {
        printf("(ERROR) Unlocking Mutex%d ThreadID: %d, Count: %d, File: %s, Line: %d\n", pInternalMutex->nMutexId, pInternalMutex->uThreadId, pInternalMutex->nLockCount, file, line);
        return;
    }

    if(pInternalMutex->uThreadId != OpcUa_P_Thread_GetCurrentThreadId())
    {
        printf("(ERROR) Unlocking Mutex%d ThreadID: %d, Count: %d, File: %s, Line: %d\n", pInternalMutex->nMutexId, pInternalMutex->uThreadId, pInternalMutex->nLockCount, file, line);
        return;
    }

    pInternalMutex->nLockCount--;

    /* printf("Unlocked Mutex%d ThreadID: %d, New LockCount: %d, File: %s, Line: %d\n", pInternalMutex->nMutexId, pInternalMutex->uThreadId, pInternalMutex->nLockCount, file, line); */

    hMutex = (OpcUa_Mutex)pInternalMutex;

    LeaveCriticalSection((CRITICAL_SECTION*)pInternalMutex->pSystemMutex);

    return;
}
OpcUa_Void OPCUA_DLLCALL OpcUa_P_Trace(
#if OPCUA_TRACE_FILE_LINE_INFO
                                        OpcUa_UInt32 level,
                                        OpcUa_CharA* sFile,
                                        OpcUa_UInt32 line,
#endif
                                        OpcUa_CharA* a_sMessage)
{
#if OPCUA_TRACE_FILE_LINE_INFO
    OpcUa_ReferenceParameter(level);
    OpcUa_ReferenceParameter(sFile);
    OpcUa_ReferenceParameter(line);
#endif

    /* send to tracehook if registered */
    if(g_OpcUa_P_TraceHook != OpcUa_Null)
    {
        g_OpcUa_P_TraceHook(a_sMessage);
    }
    else /* send to console */
    {
        char dtbuffer[25];
        OpcUa_DateTime timestamp;

        timestamp = OpcUa_P_DateTime_UtcNow();
        OpcUa_P_DateTime_GetStringFromDateTime(timestamp, dtbuffer, 25);

        printf("|%ld| %s %s", OpcUa_P_Thread_GetCurrentThreadId(), &dtbuffer[11], a_sMessage);
    }
}
Beispiel #3
0
/*============================================================================
 * Lock the mutex.
 *===========================================================================*/
OpcUa_Void OPCUA_DLLCALL OpcUa_P_Mutex_LockImp(OpcUa_Mutex hMutex, char* file, int line)
{
    OpcUa_P_InternalMutex* pInternalMutex = OpcUa_Null;

    if(hMutex == OpcUa_Null)
    {
        /* Debug */
        printf("InvalidArgument Error in OpcUa_P_Mutex_Lock: File: %s, Line: %d\n", file, line);
        return;
    }

    pInternalMutex = (OpcUa_P_InternalMutex*)hMutex;

    EnterCriticalSection((CRITICAL_SECTION*)pInternalMutex->pSystemMutex);

    pInternalMutex->nLockCount++;

    pInternalMutex->uThreadId = OpcUa_P_Thread_GetCurrentThreadId();

    /* printf("Locked   Mutex%d ThreadID: %d, LockCount: %d, File: %s, Line: %d\n", pInternalMutex->nMutexId, pInternalMutex->uThreadId, pInternalMutex->nLockCount, file, line); */

    hMutex = (OpcUa_Mutex)pInternalMutex;

    return;
}
Beispiel #4
0
/*============================================================================
 * Retrieve the id of the active thread.
 *===========================================================================*/
OpcUa_UInt32 OpcUa_Thread_GetCurrentThreadId(OpcUa_Void)
{
    return (OpcUa_UInt32)OpcUa_P_Thread_GetCurrentThreadId();
}
Beispiel #5
0
/**
 * Writes the given string to the trace device, if the given trace level is
 * activated in the header file.
 */
OpcUa_Void OPCUA_DLLCALL OpcUa_P_Trace(
#if OPCUA_TRACE_FILE_LINE_INFO
                                        OpcUa_UInt32 level,
                                        OpcUa_CharA* sFile,
                                        OpcUa_UInt32 line,
#endif
                                        OpcUa_CharA* a_sMessage)
{
#if OPCUA_TRACE_FILE_LINE_INFO
    OpcUa_ReferenceParameter(level);
    OpcUa_ReferenceParameter(sFile);
    OpcUa_ReferenceParameter(line);
#endif

    /* send to tracehook if registered */
    if(g_OpcUa_P_TraceHook != OpcUa_Null)
    {
        g_OpcUa_P_TraceHook(a_sMessage);
    }
    else /* send to console */
    {
#ifdef OPCUA_P_ENABLE_VS_CONSOLE
        /* visual studio debug console output */
        char buffer[20];
#endif /* OPCUA_P_ENABLE_VS_CONSOLE */

#if OPCUA_P_TRACE_ENABLE_TIME
        char dtbuffer[25];
#endif

#if OPCUA_P_TRACE_ENABLE_TIME
        OpcUa_P_DateTime_GetStringFromDateTime(OpcUa_P_DateTime_UtcNow(), dtbuffer, 25);
#endif /* OPCUA_P_TRACE_ENABLE_TIME */

#ifdef OPCUA_P_ENABLE_VS_CONSOLE
        /* visual studio debug console output */
        _snprintf(buffer, 20, "|%d| ", OpcUa_P_Thread_GetCurrentThreadId());
#if OPCUA_P_TRACE_ENABLE_TIME
        OutputDebugStringA(dtbuffer);
#endif /* OPCUA_P_TRACE_ENABLE_TIME */
        OutputDebugStringA(buffer);
        OutputDebugStringA(a_sMessage);
#endif /* OPCUA_P_ENABLE_VS_CONSOLE */

#ifndef OPCUA_P_TRACE_ENABLE_TIME
        printf("|%d| %s", OpcUa_P_Thread_GetCurrentThreadId(), a_sMessage);
#else
        printf("|%d| %s %s", OpcUa_P_Thread_GetCurrentThreadId(), &dtbuffer[11], a_sMessage);
#endif /* OPCUA_P_TRACE_ENABLE_TIME */

#if OPCUA_P_TRACE_TO_FILE
        if(OpcUa_P_Trace_g_hOutFile != NULL)
        {
            fprintf(OpcUa_P_Trace_g_hOutFile, "|%d| %s %s", OpcUa_P_Thread_GetCurrentThreadId(), &dtbuffer[11], a_sMessage);
#if OPCUA_P_TRACE_FFLUSH_IMMEDIATELY
            fflush(OpcUa_P_Trace_g_hOutFile);
#endif
            OpcUa_P_Trace_g_hOutFileNoOfEntries++;
        }
        if(OpcUa_P_Trace_g_hOutFileNoOfEntries >= OpcUa_P_Trace_g_hOutFileNoOfEntriesMax)
        {
            /* delete backup store and rename current file and create new one */
            fflush(OpcUa_P_Trace_g_hOutFile);
            fclose(OpcUa_P_Trace_g_hOutFile);
            OpcUa_P_Trace_g_hOutFile = NULL;
            OpcUa_Unlink(OPCUA_P_TRACE_G_OUTFILE_BACKUP);
            OpcUa_Rename(OPCUA_P_TRACE_G_OUTFILE, OPCUA_P_TRACE_G_OUTFILE_BACKUP);
            OpcUa_P_Trace_g_hOutFile = fopen(OPCUA_P_TRACE_G_OUTFILE, "w");
            OpcUa_P_Trace_g_hOutFileNoOfEntries = 0;
        }
#endif /* OPCUA_P_TRACE_TO_FILE */
    }
}