Exemple #1
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);
}
Exemple #2
0
XN_C_API XnStatus xnOSLoadFile(const XnChar* cpFileName, 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_OUTPUT_PTR(pBuffer);
	
	if (nBufferSize == 0)
	{
		return XN_STATUS_NULL_OUTPUT_PTR;
	}

	nRetVal = xnOSOpenFile(cpFileName, XN_OS_FILE_READ, &FileHandle);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = xnOSReadFile(FileHandle, pBuffer, &nReadBytes);
	if ((nRetVal != XN_STATUS_OK) || (nReadBytes != nBufferSize))
	{
		xnOSCloseFile(&FileHandle);
		return (XN_STATUS_OS_FILE_READ_FAILED);
	}

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

	// All is good...
	return (XN_STATUS_OK);
}
Exemple #3
0
XN_C_API XnStatus xnOSGetFileSize(const XnChar* cpFileName, XnUInt32* pnFileSize)
{
	// Local function variables
	XN_FILE_HANDLE FileHandle;
	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_OUTPUT_PTR(pnFileSize);

	nRetVal = xnOSOpenFile(cpFileName, XN_OS_FILE_READ, &FileHandle);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = xnOSSeekFile(FileHandle, XN_OS_SEEK_END, 0);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = xnOSTellFile(FileHandle, pnFileSize);
	XN_IS_STATUS_OK(nRetVal);

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

	// All is good...
	return (XN_STATUS_OK);
}
Exemple #4
0
OniStatus Recorder::initialize(const char* fileName)
{
    m_fileName = fileName;

    // Probe if we can actually open the file.
    XN_FILE_HANDLE fileHandle = XN_INVALID_FILE_HANDLE;
    XnStatus status = xnOSOpenFile(
            /* file name  = */ fileName, 
            /* open flags = */ XN_OS_FILE_WRITE | XN_OS_FILE_TRUNCATE, 
            /* out handle = */ &fileHandle);
    if (XN_STATUS_OK != status)
    {
        return ONI_STATUS_ERROR;
    }
    xnOSCloseFile(&fileHandle);

    m_assembler.initialize();   
    
    status = xnOSCreateThread(threadMain, this, &m_thread);
    if (XN_STATUS_OK != status)
    {
        return ONI_STATUS_ERROR;
    }
    
    send(Message::MESSAGE_INITIALIZE);
    return ONI_STATUS_OK;
}
XN_C_API XnStatus xnOSGetFileSize64(const XnChar* cpFileName, XnUInt64* pnFileSize)
{
	// Local function variables
	XN_FILE_HANDLE FileHandle;
	XnStatus nRetVal = XN_STATUS_OK;
	LARGE_INTEGER liSize;
	BOOL bSucceeded = 0;

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

	nRetVal = xnOSOpenFile(cpFileName, XN_OS_FILE_READ, &FileHandle);
	XN_IS_STATUS_OK(nRetVal);

	bSucceeded = GetFileSizeEx(FileHandle, &liSize);
	if (!bSucceeded)
		return XN_STATUS_OS_FILE_GET_SIZE_FAILED;
	*pnFileSize = liSize.QuadPart;

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

	// All is good...
	return (XN_STATUS_OK);
}
Exemple #6
0
XN_C_API void xnDumpClose(XnDump* pDump)
{
    if (pDump->hFile != XN_INVALID_FILE_HANDLE)
    {
        xnOSCloseFile(&pDump->hFile);
        *pDump = XN_DUMP_CLOSED;
    }
}
Exemple #7
0
void XnLogFileWriter::CloseFile()
{
	if (m_fLogFile != XN_INVALID_FILE_HANDLE)
	{
		xnOSCloseFile(&m_fLogFile);
		m_fLogFile = XN_INVALID_FILE_HANDLE;
	}
}
Exemple #8
0
	void CloseFile()
	{
		m_bBannerPrinted = FALSE;
		if (m_fLogFile != XN_INVALID_FILE_HANDLE)
		{
			xnOSCloseFile(&m_fLogFile);
			m_fLogFile = XN_INVALID_FILE_HANDLE; 
		}
		m_csTime[0] = '\0';
	}
Exemple #9
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;
}
Exemple #10
0
void XnDumpFileWriter::CloseFile(XnDumpWriterFileHandle hFile)
{
	XN_FILE_HANDLE* phFileOS = (XN_FILE_HANDLE*)hFile.pInternal;
	xnOSCloseFile(phFileOS);
	xnOSFree(phFileOS);
}
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);
}
Exemple #12
0
void XN_CALLBACK_TYPE PlayerDriver::FileClose(void* pCookie)
{
	PlayerDriver* pThis = (PlayerDriver*)pCookie;
	xnOSCloseFile(&pThis->m_fileHandle);
	pThis->m_fileHandle = 0;
}
Exemple #13
0
XnStatus XnIOFileStream::Free()
{
	return xnOSCloseFile(&m_hFile);
}