Пример #1
0
XN_C_API void xnDumpWriteBufferImpl(XnDump dump, const void* pBuffer, XnUInt32 nBufferSize)
{
    if (dump.hFile != XN_INVALID_FILE_HANDLE)
    {
        xnOSWriteFile(dump.hFile, pBuffer, nBufferSize);
    }
}
Пример #2
0
XN_C_API XnStatus xnOSAppendFile(const XnChar* cpFileName, const void* pBuffer, const XnUInt32 nBufferSize)
{
	// Local function variables
	XN_FILE_HANDLE FileHandle;
	XnUInt32 nReadBytes = nBufferSize;
	XnStatus nRetVal = XN_STATUS_OK;

	// Validate the input/output pointers (to make sure none of them is NULL)
	XN_VALIDATE_INPUT_PTR(cpFileName);
	XN_VALIDATE_INPUT_PTR(pBuffer);

	nRetVal = xnOSOpenFile(cpFileName, XN_OS_FILE_WRITE | XN_OS_FILE_APPEND, &FileHandle);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = xnOSWriteFile(FileHandle, pBuffer, nBufferSize);
	if (nRetVal != XN_STATUS_OK)
	{
		xnOSCloseFile(&FileHandle);
		return (XN_STATUS_OS_FILE_WRITE_FAILED);
	}

	nRetVal = xnOSCloseFile(&FileHandle);
	XN_IS_STATUS_OK(nRetVal);

	// All is good...
	return (XN_STATUS_OK);
}
Пример #3
0
XnStatus xnDumpCreate(XnDump* pDump, const XnChar* csHeader, const XnChar* csFileNameFormat, va_list args)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XnChar strFileName[XN_FILE_MAX_PATH];
    XnUInt32 nChars;
    nRetVal = xnOSStrFormatV(strFileName, XN_FILE_MAX_PATH, &nChars, csFileNameFormat, args);
    XN_IS_STATUS_OK(nRetVal);

    XnChar strFullPath[XN_FILE_MAX_PATH];
    nRetVal = xnLogCreateNewFile(strFileName, TRUE, strFullPath, XN_FILE_MAX_PATH, &pDump->hFile);
    if (nRetVal != XN_STATUS_OK)
    {
        // we don't have much to do if files can't be open. Dump will not be written
        xnLogWarning(XN_MASK_LOG, "Couldn't create dump file %s! Dump will not be written", strFileName);
        pDump->hFile = XN_INVALID_FILE_HANDLE;
        return nRetVal;
    }

    if (csHeader != NULL)
    {
        xnOSWriteFile(pDump->hFile, csHeader, (XnUInt32)strlen(csHeader));
    }

    return XN_STATUS_OK;
}
Пример #4
0
XN_C_API void xnLogWriteNoEntry(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFormat, ...)
{
	if (!xnLogIsEnabled(csLogMask, nSeverity))
		return;

	if (g_xnLoggerData.m_bWriteToFile)
	{
		va_list args;
		va_start(args, csFormat);

		const XnUInt32 nMaxMessageSize = 1024;
		XnChar csMessage[nMaxMessageSize+1];
		XnUInt32 nChars;
		xnOSStrFormatV(csMessage, nMaxMessageSize, &nChars, csFormat, args);

		va_end(args);

		xnOSWriteFile(g_xnLoggerData.m_fLogFile, csMessage, nChars);
	}

	if (g_xnLoggerData.m_bWriteToConsole)
	{
		va_list args;
		va_start(args, csFormat);
		vprintf(csFormat, args);
		va_end(args);
	}
}
Пример #5
0
void xnLogWriteImplV(const XnChar* /*csLogMask*/, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, const XnChar* csFormat, va_list args)
{
	// take time
	XnUInt64 nNow;
	xnOSGetHighResTimeStamp(&nNow);

	// write timestamp and severity
	const XnChar* csSeverity = xnLogGetSeverityString(nSeverity);

	const XnUInt32 nMaxMessageSize = 2047;
	XnChar csMessage[nMaxMessageSize+1];
	XnUInt32 nChars = 0;
	XnUInt32 nMessageLen = 0;

	// write timestamp
	xnOSStrFormat(csMessage + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, "%8llu\t[%s]\t", nNow, csSeverity);
	nMessageLen += nChars;

	XnUInt32 nLineInfoBegin = nMessageLen;

	if (g_xnLoggerData.m_bWriteLineInfo)
	{
		// write line info
		XnChar fileName[XN_FILE_MAX_PATH];
		XnStatus nRetVal = xnOSGetFileName(csFile, fileName, sizeof(fileName));
		if (nRetVal == XN_STATUS_OK)
		{
			xnOSStrFormat(csMessage + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, "%s\t%d\t", fileName, nLine);
			nMessageLen += nChars;
		}
	}

	XnUInt32 nLineInfoEnd = nMessageLen;

	// write message
	xnOSStrFormatV(csMessage + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, csFormat, args);
	nMessageLen += nChars;
	XnUInt32 nUserMsgLen = nChars;

	// write end-of-line
	xnOSStrFormat(csMessage + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, XN_NEW_LINE_SEP);
	nMessageLen += nChars;

	if (g_xnLoggerData.m_bWriteToFile)
	{
		xnOSWriteFile(g_xnLoggerData.m_fLogFile, csMessage, nMessageLen);
	}

	if (g_xnLoggerData.m_bWriteToConsole)
	{
		// Write to console without line info
		XnChar cSaveChar = csMessage[nLineInfoBegin];
		csMessage[nLineInfoBegin] = '\0';
		printf("%s", csMessage);
		csMessage[nLineInfoBegin] = cSaveChar;
		//printf should know how to translate '\n' to proper newline on every platform so we don't need XN_NEW_LINE_SEP here
		printf("%s", csMessage + nLineInfoEnd);
	}

}
Пример #6
0
void XnLogFileWriter::WriteEntry(const XnLogEntry* pEntry)
{
	// make sure file is open
	if (m_fLogFile == XN_INVALID_FILE_HANDLE)
	{
		return;
	}

	// write timestamp and severity
	const XnUInt32 nMaxMessageSize = 2047;
	XnChar strBuffer[nMaxMessageSize + 1];

	XnUInt32 nMessageLen = 0;
	XnUInt32 nChars = 0;
	xnOSStrFormat(strBuffer + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, "%9llu\t%-10s\t%s\t", pEntry->nTimestamp, pEntry->strSeverity, pEntry->strMask);
	nMessageLen += nChars;

	if (m_bWriteLineInfo)
	{
		// write line info
		XnChar fileName[XN_FILE_MAX_PATH];
		XnStatus nRetVal = xnOSGetFileName(pEntry->strFile, fileName, sizeof(fileName));
		if (nRetVal == XN_STATUS_OK)
		{
			xnOSStrFormat(strBuffer + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, "%s\t%d\t", fileName, pEntry->nLine);
			nMessageLen += nChars;
		}
	}

	xnOSStrFormat(strBuffer + nMessageLen, nMaxMessageSize - nMessageLen, &nChars, "%s\n", pEntry->strMessage);
	nMessageLen += nChars;

	xnOSWriteFile(m_fLogFile, strBuffer, nMessageLen);
}
Пример #7
0
OniStatus RecordAssembler::serialize(XN_FILE_HANDLE file)
{
    // NOTE(oleksii): strange, but fieldsSize includes the size of header as
    // well...
    XnUInt32 serializedSize_bytes = 
        m_header->fieldsSize +
        m_header->payloadSize;
    XnStatus status = xnOSWriteFile(file, m_pBuffer, serializedSize_bytes);
    return XN_STATUS_OK == status ? ONI_STATUS_OK : ONI_STATUS_ERROR;
}
Пример #8
0
XN_C_API void xnDumpWriteStringImpl(XnDump dump, const XnChar* csFormat, ...)
{
    if (dump.hFile != XN_INVALID_FILE_HANDLE)
    {
        const XnUInt32 nStringLength = 1024;
        XnChar csString[1024];

        va_list args;
        va_start(args, csFormat);

        // format message
        XnUInt32 nChars;
        xnOSStrFormatV(csString, nStringLength, &nChars, csFormat, args);

        // and write it to file
        xnOSWriteFile(dump.hFile, csString, nChars);

        va_end(args);
    }
}
Пример #9
0
void Recorder::onInitialize()
{
    XnStatus status = xnOSOpenFile(
        /* file name  = */ m_fileName.Data(), 
        /* open flags = */ XN_OS_FILE_WRITE | XN_OS_FILE_TRUNCATE, 
        /* out handle = */ &m_file);

    if (XN_STATUS_OK == status)
    {
        FileHeaderData fileHeader = 
        {
            /* identity     = */ { 'N', 'I', '1', '0' },
            /* version      = */ {   1,   0,  1,   0  },
            /* maxTimeStamp = */ XN_MAX_UINT64,
            /* maxNodeId    = */ m_maxId,
        };
        m_fileHeader = fileHeader;
        xnOSWriteFile(m_file, &m_fileHeader, sizeof(m_fileHeader));
    }
}
Пример #10
0
void Recorder::onTerminate()
{
    // Truncate the file to it's last offset, so that undone records
    // will not be serialized.
    XnUInt64 truncationOffset = XN_UINT64_C(0);
    if (XN_STATUS_OK == xnOSTellFile64(m_file, &truncationOffset))
    {
        xnOSTruncateFile64(m_file, truncationOffset);
    }

    Memento undoPoint(this);
    EMIT(RECORD_END())
    undoPoint.Release();

    // The file header needs being patched, because its maxNodeId field has become
    // irrelevant by now.
    m_fileHeader.maxNodeId = m_maxId;
    xnOSSeekFile64(m_file, XN_OS_SEEK_SET, XN_UINT64_C(0));
    xnOSWriteFile(m_file, &m_fileHeader, sizeof(m_fileHeader));

    xnOSCloseFile(&m_file);
    m_file = XN_INVALID_FILE_HANDLE;
}
Пример #11
0
void XnDumpFileWriter::Write(XnDumpWriterFileHandle hFile, const void* pBuffer, XnUInt32 nBufferSize)
{
	XN_FILE_HANDLE* phFileOS = (XN_FILE_HANDLE*)hFile.pInternal;
	xnOSWriteFile(*phFileOS, pBuffer, nBufferSize);
}
Пример #12
0
XN_C_API void xnOSWriteMemoryReport(const XnChar* csFileName)
{
	XN_FILE_HANDLE FileHandle;
	XnStatus nRetVal = xnOSOpenFile(csFileName, XN_OS_FILE_WRITE | XN_OS_FILE_TRUNCATE, &FileHandle);
	if (nRetVal != XN_STATUS_OK) return;

	const XnUInt32 nReportLineMaxSize = 2048;
	XnChar csReportLine[nReportLineMaxSize];
	XnUInt32 nReportLength = 0;

	XnUInt32 nChars;

	XnUInt32 nSum = 0;
	xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "Allocated memory blocks:\n");
	nReportLength += nChars;
	xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "============================================\n");
	nReportLength += nChars;

	xnOSWriteFile(FileHandle, csReportLine, nReportLength);
	nReportLength = 0;

	{
		XnAutoCSLocker lock(g_hCS);
		for (XnMemBlockDataNode* pNode = g_allocatedMemory.pFirst; pNode != NULL; pNode = pNode->pNext)
		{
			xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "%d bytes allocated at 0x%08x using %s", pNode->Data.nBytes, pNode->Data.pMemBlock, XnGetAllocTypeString(pNode->Data.nAllocType));
			nReportLength += nChars;

			if (pNode->Data.csAdditional != NULL)
			{
				xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, " (%s)", pNode->Data.csAdditional);
				nReportLength += nChars;
			}

			xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, " at %s [%s, %d]\n", pNode->Data.csFunction, pNode->Data.csFile, pNode->Data.nLine);
			nReportLength += nChars;

			if (pNode->Data.nFrames > 0)
			{
				xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "Callstack:\n");
				nReportLength += nChars;

				for (XnUInt i = 0; i < pNode->Data.nFrames; ++i)
				{
					xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "\t%s\n", pNode->Data.aFrames[i]);
					nReportLength += nChars;
				}
			}

			xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "\n");
			nReportLength += nChars;

			xnOSWriteFile(FileHandle, csReportLine, nReportLength);
			nReportLength = 0;

			nSum += pNode->Data.nBytes;
		}
	}

	xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "*******************************************************************\n\n");
	nReportLength += nChars;
	xnOSStrFormat(csReportLine + nReportLength, nReportLineMaxSize - nReportLength, &nChars, "Total allocated memory: %d bytes\n", nSum);
	nReportLength += nChars;

	xnOSWriteFile(FileHandle, csReportLine, nReportLength);
	nReportLength = 0;

	xnOSCloseFile(&FileHandle);
}
Пример #13
0
void XnLogFileWriter::WriteUnformatted(const XnChar* strMessage)
{
	xnOSWriteFile(m_fLogFile, strMessage, xnOSStrLen(strMessage) + 1);
}
Пример #14
0
XnStatus XnIOFileStream::WriteData(const XnUChar *pData, XnUInt32 nDataSize)
{
	return xnOSWriteFile(m_hFile, pData, nDataSize);
}