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); } }
/** * CreateGuid generates a global unique identifier. It calls the * Win32 API function for doing this. */ OpcUa_Guid* OPCUA_DLLCALL OpcUa_P_Guid_Create(OpcUa_Guid* Guid) { #ifndef _GUID_CREATE_NOT_AVAILABLE if(UuidCreate((UUID*)Guid) != RPC_S_OK) { /* Error */ Guid = OpcUa_Null; return OpcUa_Null; } /* Good */ return Guid; #else unsigned int *data = (unsigned int*)Guid; int chunks = 16 / sizeof(unsigned int); static const int intbits = sizeof(int)*8; static int randbits = 0; if (!randbits) { OpcUa_DateTime now; int max = RAND_MAX; do { ++randbits; } while ((max=max>>1)); now = OpcUa_P_DateTime_UtcNow(); srand(now.dwLowDateTime^now.dwHighDateTime); rand(); /* Skip first */ }
/** * 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 */ } }