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 #2
0
/*============================================================================*/
OpcUa_StatusCode OpcUa_DateTime_GetStringFromDateTime(  OpcUa_DateTime  a_dateTime,
                                                        OpcUa_StringA   a_pBuffer,
                                                        OpcUa_UInt32    a_uLength)
{
    OpcUa_DeclareErrorTraceModule(OpcUa_Module_DateTime);
    OpcUa_ReturnErrorIfArgumentNull(a_pBuffer);

    if(a_uLength < 25)
    {
        return OpcUa_BadInvalidArgument;
    }

    return OpcUa_P_DateTime_GetStringFromDateTime(a_dateTime, a_pBuffer, a_uLength);
}
Beispiel #3
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 */
    }
}