diff --git a/ftk/src/ftk.h b/ftk/src/ftk.h index 03830bd..48525e4 100644 --- a/ftk/src/ftk.h +++ b/ftk/src/ftk.h @@ -463,6 +463,10 @@ #define FLM_CS_LANG 37 // Chinese-Simplified #define FLM_LA_LANG 38 // another Asian language + #define FLM_LAST_LANG (FLM_LA_LANG + 1) + #define FLM_FIRST_DBCS_LANG (FLM_JP_LANG) + #define FLM_LAST_DBCS_LANG (FLM_LA_LANG) + /**************************************************************************** Desc: I/O Flags ****************************************************************************/ @@ -622,87 +626,67 @@ void FLMAPI ftkShutdown( void); /**************************************************************************** - Desc: Reference Counting class + Desc: Object base class ****************************************************************************/ - class F_RefCount + flminterface IF_Object + { + virtual FLMINT FLMAPI getRefCount( void) = 0; + + virtual FLMINT FLMAPI AddRef( void) = 0; + + virtual FLMINT FLMAPI Release( void) = 0; + }; + + /**************************************************************************** + Desc: + ****************************************************************************/ + class F_Object : public IF_Object { public: - F_RefCount() + F_Object() { m_refCnt = 1; } - virtual ~F_RefCount() + virtual ~F_Object() { } - virtual FINLINE FLMINT FLMAPI getRefCount( void) - { - return( m_refCnt); - } + virtual FLMINT FLMAPI getRefCount( void); - virtual FINLINE FLMINT FLMAPI AddRef( void) - { - return( ++m_refCnt); - } + virtual FLMINT FLMAPI AddRef( void); - virtual FINLINE FLMINT FLMAPI Release( void) - { - FLMINT iRefCnt = --m_refCnt; + virtual FLMINT FLMAPI Release( void); - if( !iRefCnt) - { - delete this; - } - - return( iRefCnt); - } + void * FLMAPI operator new( + FLMSIZET uiSize, + const char * pszFile, + int iLine); + + void * FLMAPI operator new[]( + FLMSIZET uiSize, + const char * pszFile, + int iLine); + + void FLMAPI operator delete( + void * ptr); + + void FLMAPI operator delete( + void * ptr, + const char * file, + int line); + + void FLMAPI operator delete[]( + void * ptr, + const char * file, + int line); protected: FLMATOMIC m_refCnt; }; - - /**************************************************************************** - Desc: Base class - ****************************************************************************/ - class F_Base - { - public: - F_Base() - { - } - - virtual ~F_Base() - { - } - - void * operator new( - FLMSIZET uiSize, - const char * pszFile, - int iLine); - - void * operator new[]( - FLMSIZET uiSize, - const char * pszFile, - int iLine); - - void operator delete( - void * ptr); - - void operator delete( - void * ptr, - const char * file, - int line); - - void operator delete[]( - void * ptr, - const char * file, - int line); - }; - /**************************************************************************** Desc: Internal base class ****************************************************************************/ @@ -794,6 +778,9 @@ #define f_assert( c) \ (void)((c) ? 0 : f_enterDebugger( __FILE__, __LINE__)) + + #define flmAssert( c) \ + f_assert( c) #else #define RC_SET( rc) (rc) #define RC_SET_AND_ASSERT( rc) (rc) @@ -804,7 +791,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_ThreadInfo : public F_RefCount + flminterface IF_ThreadInfo : public F_Object { virtual FLMUINT FLMAPI getNumThreads( void) = 0; @@ -817,11 +804,14 @@ const char ** ppszThreadName, const char ** ppszThreadStatus) = 0; }; + + RCODE FLMAPI FlmGetThreadInfo( + IF_ThreadInfo ** ppThreadInfo); /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_IStream : public F_RefCount + flminterface IF_IStream : public F_Object { virtual RCODE FLMAPI read( void * pvBuffer, @@ -852,9 +842,9 @@ flminterface IF_BufferIStream : public IF_PosIStream { virtual RCODE FLMAPI open( - const FLMBYTE * pucBuffer, - FLMUINT uiLength, - FLMBYTE ** ppucAllocatedBuffer = NULL) = 0; + const char * pucBuffer, + FLMUINT uiLength, + char ** ppucAllocatedBuffer = NULL) = 0; virtual FLMUINT64 FLMAPI totalSize( void) = 0; @@ -863,32 +853,89 @@ virtual RCODE FLMAPI close( void) = 0; virtual RCODE FLMAPI positionTo( - FLMUINT64 ui64Position) = 0; + FLMUINT64 ui64Position) = 0; virtual FLMUINT64 FLMAPI getCurrPosition( void) = 0; + virtual void FLMAPI truncate( + FLMUINT64 ui64Offset) = 0; + virtual RCODE FLMAPI read( - void * pvBuffer, - FLMUINT uiBytesToRead, - FLMUINT * puiBytesRead) = 0; + void * pvBuffer, + FLMUINT uiBytesToRead, + FLMUINT * puiBytesRead) = 0; + + virtual const FLMBYTE * FLMAPI getBufferAtCurrentOffset( void) = 0; }; RCODE FLMAPI FlmAllocBufferIStream( IF_BufferIStream ** ppIStream); - RCODE FLMAPI FlmAllocBase64EncoderIStream( + RCODE FLMAPI FlmOpenBufferIStream( + const char * pucBuffer, + FLMUINT uiLength, + IF_PosIStream ** ppIStream); + + RCODE FLMAPI FlmOpenBase64EncoderIStream( IF_IStream * pSourceIStream, FLMBOOL bLineBreaks, IF_IStream ** ppIStream); - RCODE FLMAPI FlmAllocBase64DecoderIStream( + RCODE FLMAPI FlmOpenBase64DecoderIStream( IF_IStream * pSourceIStream, IF_IStream ** ppIStream); + RCODE FLMAPI FlmOpenFileIStream( + const char * pszPath, + IF_PosIStream ** ppIStream); + + RCODE FLMAPI FlmOpenMultiFileIStream( + const char * pszDirectory, + const char * pszBaseName, + IF_IStream ** ppIStream); + + RCODE FLMAPI FlmOpenBufferedIStream( + IF_IStream * pSourceIStream, + FLMUINT uiBufferSize, + IF_IStream ** ppIStream); + + RCODE FLMAPI FlmOpenUncompressingIStream( + IF_IStream * pIStream, + IF_IStream ** ppIStream); + + RCODE FLMAPI FlmOpenFileOStream( + const char * pszFileName, + FLMBOOL bTruncateIfExists, + IF_OStream ** ppOStream); + + RCODE FLMAPI FlmOpenMultiFileOStream( + const char * pszDirectory, + const char * pszBaseName, + FLMUINT uiMaxFileSize, + FLMBOOL bOkToOverwrite, + IF_OStream ** ppStream); + + RCODE FLMAPI FlmOpenBufferedOStream( + IF_OStream * pOStream, + FLMUINT uiBufferSize, + IF_OStream ** ppOStream); + + RCODE FLMAPI FlmOpenCompressingOStream( + IF_OStream * pOStream, + IF_OStream ** ppOStream); + + RCODE FLMAPI FlmRemoveMultiFileStream( + const char * pszDirectory, + const char * pszBaseName); + + RCODE FLMAPI FlmWriteToOStream( + IF_IStream * pIStream, + IF_OStream * pOStream); + /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_OStream : public F_RefCount + flminterface IF_OStream : public F_Object { virtual RCODE FLMAPI write( const void * pvBuffer, @@ -908,7 +955,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_LoggerClient : public F_RefCount + flminterface IF_LoggerClient : public F_Object { virtual IF_LogMessageClient * FLMAPI beginMessage( FLMUINT uiMsgType) = 0; @@ -917,7 +964,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_LogMessageClient : public F_RefCount + flminterface IF_LogMessageClient : public F_Object { virtual void FLMAPI changeColor( eColorType eForeColor, @@ -942,7 +989,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_FileSystem : public F_RefCount + flminterface IF_FileSystem : public F_Object { virtual RCODE FLMAPI createFile( const char * pszFileName, @@ -1007,6 +1054,14 @@ FLMBOOL bOverwrite, FLMUINT64 * pui64BytesCopied) = 0; + virtual RCODE FLMAPI copyPartialFile( + IF_FileHdl * pSrcFileHdl, + FLMUINT64 ui64SrcOffset, + FLMUINT64 ui64SrcSize, + IF_FileHdl * pDestFileHdl, + FLMUINT64 ui64DestOffset, + FLMUINT64 * pui64BytesCopiedRV) = 0; + virtual RCODE FLMAPI renameFile( const char * pszFileName, const char * pszNewFileName) = 0; @@ -1045,50 +1100,15 @@ virtual FLMBOOL FLMAPI doesFileMatch( const char * pszFileName, const char * pszTemplate) = 0; - - virtual RCODE FLMAPI writeToOStream( - IF_IStream * pIStream, - IF_OStream * pOStream) = 0; }; RCODE FLMAPI FlmGetFileSystem( IF_FileSystem ** ppFileSystem); - /*************************************************************************** - Desc: - ***************************************************************************/ - flminterface IF_FileHdlMgr : public F_RefCount - { - virtual void FLMAPI setOpenThreshold( - FLMUINT uiOpenThreshold) = 0; - - virtual void FLMAPI setMaxAvailTime( - FLMUINT uiMaxAvailTime) = 0; - - virtual FLMUINT FLMAPI getUniqueId( void) = 0; - - virtual void FLMAPI findAvail( - FLMUINT uiFileId, - FLMBOOL bReadOnlyFlag, - IF_FileHdl ** ppFileHdl) = 0; - - virtual void FLMAPI removeFileHdls( - FLMUINT uiFileId) = 0; - - virtual void FLMAPI checkAgedFileHdls( - FLMUINT uiMinSecondsOpened) = 0; - - virtual FLMUINT FLMAPI getOpenThreshold( void) = 0; - - virtual FLMUINT FLMAPI getOpenedFiles( void) = 0; - - virtual FLMUINT FLMAPI getMaxAvailTime( void) = 0; - }; - /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_FileHdl : public F_RefCount + flminterface IF_FileHdl : public F_Object { virtual RCODE FLMAPI flush( void) = 0; @@ -1151,17 +1171,12 @@ virtual FLMUINT FLMAPI getSectorSize( void) = 0; virtual FLMBOOL FLMAPI isReadOnly( void) = 0; - - virtual void FLMAPI setFileId( - FLMUINT uiFileId) = 0; - - virtual FLMUINT FLMAPI getFileId( void) = 0; }; /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_MultiFileHdl : public F_RefCount + flminterface IF_MultiFileHdl : public F_Object { virtual RCODE FLMAPI create( const char * pszPath) = 0; @@ -1209,7 +1224,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_IOBufferMgr : public F_RefCount + flminterface IF_IOBufferMgr : public F_Object { virtual RCODE FLMAPI waitForAllPendingIO( void) = 0; @@ -1234,6 +1249,8 @@ RCODE FLMAPI FlmAllocIOBufferMgr( IF_IOBufferMgr ** ppBufferMgr); + #define FLM_MAX_IO_BUFFER_BLOCKS 16 + /**************************************************************************** Desc: ****************************************************************************/ @@ -1243,7 +1260,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_IOBuffer : public F_RefCount + flminterface IF_IOBuffer : public F_Object { typedef enum { @@ -1286,7 +1303,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_DirHdl : public F_RefCount + flminterface IF_DirHdl : public F_Object { virtual RCODE FLMAPI next( void) = 0; @@ -1303,7 +1320,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_ResultSetCompare : public F_RefCount + flminterface IF_ResultSetCompare : public F_Object { virtual RCODE FLMAPI compare( const void * pvData1, @@ -1316,7 +1333,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_ResultSetSortStatus : public F_RefCount + flminterface IF_ResultSetSortStatus : public F_Object { virtual RCODE FLMAPI reportSortStatus( FLMUINT64 ui64EstTotalUnits, @@ -1326,7 +1343,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_ResultSet : public F_RefCount + flminterface IF_ResultSet : public F_Object { virtual RCODE FLMAPI setupResultSet( const char * pszPath, @@ -1405,7 +1422,7 @@ /***************************************************************************** Desc: *****************************************************************************/ - flminterface IF_BtResultSet : public F_RefCount + flminterface IF_BtResultSet : public F_Object { virtual RCODE FLMAPI setupResultSet( const char * pszPath, @@ -1415,73 +1432,73 @@ IF_ResultSetSortStatus * pSortStatus) = 0; virtual RCODE FLMAPI addEntry( - FLMBYTE * pucKey, - FLMUINT uiKeyLength, - FLMBYTE * pucEntry, - FLMUINT uiEntryLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyLength, + FLMBYTE * pucEntry, + FLMUINT uiEntryLength) = 0; virtual RCODE FLMAPI modifyEntry( - FLMBYTE * pucKey, - FLMUINT uiKeyLength, - FLMBYTE * pucEntry, - FLMUINT uiEntryLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyLength, + FLMBYTE * pucEntry, + FLMUINT uiEntryLength) = 0; virtual RCODE FLMAPI getCurrent( - FLMBYTE * pucKey, - FLMUINT uiKeyLength, - FLMBYTE * pucEntry, - FLMUINT uiEntryLength, - FLMUINT * puiReturnLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyLength, + FLMBYTE * pucEntry, + FLMUINT uiEntryLength, + FLMUINT * puiReturnLength) = 0; virtual RCODE FLMAPI getNext( - FLMBYTE * pucKey, - FLMUINT uiKeyBufLen, - FLMUINT * puiKeylen, - FLMBYTE * pucBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyBufLen, + FLMUINT * puiKeylen, + FLMBYTE * pucBuffer, + FLMUINT uiBufferLength, + FLMUINT * puiReturnLength) = 0; virtual RCODE FLMAPI getPrev( - FLMBYTE * pucKey, - FLMUINT uiKeyBufLen, - FLMUINT * puiKeylen, - FLMBYTE * pucBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyBufLen, + FLMUINT * puiKeylen, + FLMBYTE * pucBuffer, + FLMUINT uiBufferLength, + FLMUINT * puiReturnLength) = 0; virtual RCODE FLMAPI getFirst( - FLMBYTE * pucKey, - FLMUINT uiKeyBufLen, - FLMUINT * puiKeylen, - FLMBYTE * pucBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyBufLen, + FLMUINT * puiKeylen, + FLMBYTE * pucBuffer, + FLMUINT uiBufferLength, + FLMUINT * puiReturnLength) = 0; virtual RCODE FLMAPI getLast( - FLMBYTE * pucKey, - FLMUINT uiKeyBufLen, - FLMUINT * puiKeylen, - FLMBYTE * pucBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyBufLen, + FLMUINT * puiKeylen, + FLMBYTE * pucBuffer, + FLMUINT uiBufferLength, + FLMUINT * puiReturnLength) = 0; virtual RCODE FLMAPI findEntry( - FLMBYTE * pucKey, - FLMUINT uiKeyBufLen, - FLMUINT * puiKeylen, - FLMBYTE * pucBuffer, - FLMUINT uiBufferLength, - FLMUINT * puiReturnLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyBufLen, + FLMUINT * puiKeylen, + FLMBYTE * pucBuffer, + FLMUINT uiBufferLength, + FLMUINT * puiReturnLength) = 0; virtual RCODE FLMAPI deleteEntry( - FLMBYTE * pucKey, - FLMUINT uiKeyLength) = 0; + FLMBYTE * pucKey, + FLMUINT uiKeyLength) = 0; }; /**************************************************************************** Desc: Pool memory allocator ****************************************************************************/ - flminterface IF_Pool : public F_RefCount + flminterface IF_Pool : public F_Object { virtual void FLMAPI poolInit( FLMUINT uiBlockSize) = 0; @@ -1508,12 +1525,12 @@ }; RCODE FLMAPI FlmAllocPool( - IF_Pool ** ppPool); + IF_Pool ** ppPool); /**************************************************************************** Desc: Dynamic buffer ****************************************************************************/ - flminterface IF_DynaBuf : public F_RefCount + flminterface IF_DynaBuf : public F_Object { virtual void FLMAPI truncateData( FLMUINT uiSize) = 0; @@ -1547,7 +1564,7 @@ /**************************************************************************** Desc: Random numbers ****************************************************************************/ - flminterface IF_RandomGenerator : public F_RefCount + flminterface IF_RandomGenerator : public F_Object { virtual void FLMAPI randomize( void) = 0; @@ -1623,7 +1640,7 @@ /**************************************************************************** Desc: Thread manager ****************************************************************************/ - flminterface IF_ThreadMgr : public F_RefCount + flminterface IF_ThreadMgr : public F_Object { virtual RCODE FLMAPI setupThreadMgr( void) = 0; @@ -1661,15 +1678,17 @@ virtual FLMUINT FLMAPI getThreadGroupCount( FLMUINT uiThreadGroup) = 0; + + virtual FLMUINT FLMAPI allocGroupId( void) = 0; }; RCODE FLMAPI FlmGetThreadMgr( - IF_ThreadMgr ** ppThreadMgr); + IF_ThreadMgr ** ppThreadMgr); /**************************************************************************** Desc: Thread ****************************************************************************/ - flminterface IF_Thread : public F_RefCount + flminterface IF_Thread : public F_Object { virtual RCODE FLMAPI startThread( F_THREAD_FUNC fnThread, @@ -1726,7 +1745,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_IniFile : public F_RefCount + flminterface IF_IniFile : public F_Object { virtual RCODE FLMAPI read( const char * pszFileName) = 0; @@ -1828,16 +1847,19 @@ FLMUNICODE * puzDestStr, const FLMUNICODE * puzSrcStr); + FLMBOOL FLMAPI f_uniIsUpper( + FLMUNICODE uChar); + FLMBOOL FLMAPI f_uniIsLower( - FLMUNICODE uzChar); + FLMUNICODE uChar); FLMBOOL FLMAPI f_uniIsAlpha( - FLMUNICODE uzChar); + FLMUNICODE uChar); FLMBOOL FLMAPI f_uniIsDecimalDigit( - FLMUNICODE uzChar); + FLMUNICODE uChar); - FLMUNICODE FLMAPI f_unitolower( + FLMUNICODE FLMAPI f_uniToLower( FLMUNICODE uChar); FLMINT FLMAPI f_unicmp( @@ -2131,7 +2153,7 @@ FINLINE FLMBOOL f_isvowel( FLMUNICODE uChar) { - uChar = f_unitolower( uChar); + uChar = f_uniToLower( uChar); if( uChar == FLM_UNICODE_a || uChar == FLM_UNICODE_e || @@ -2514,6 +2536,10 @@ const char * pszFormat, ...); + FLMINT FLMAPI f_printf( + const char * pszFormat, + ...); + /**************************************************************************** Desc: ****************************************************************************/ @@ -2589,7 +2615,7 @@ const char * pszSrc, FLMSIZET uiLength); - FLMINT FLMAPI f_strlen( + FLMUINT FLMAPI f_strlen( const char * pszStr); RCODE FLMAPI f_getCharFromUTF8Buf( @@ -2689,6 +2715,10 @@ void FLMAPI f_freeAlignedBuffer( void ** ppvAlloc); + RCODE f_getMemoryInfo( + FLMUINT64 * pui64TotalPhysMem, + FLMUINT64 * pui64AvailPhysMem); + /**************************************************************************** Desc: Logging ****************************************************************************/ @@ -2711,7 +2741,7 @@ /**************************************************************************** Desc: XML ****************************************************************************/ - flminterface IF_XML : public F_RefCount + flminterface IF_XML : public F_Object { public: @@ -2758,7 +2788,7 @@ /**************************************************************************** Desc: Name table ****************************************************************************/ - flminterface IF_NameTable : public F_RefCount + flminterface IF_NameTable : public F_Object { virtual RCODE FLMAPI setupNameTable( void) = 0; @@ -2830,7 +2860,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_DeleteStatus : public F_RefCount + flminterface IF_DeleteStatus : public F_Object { virtual RCODE FLMAPI reportDelete( FLMUINT uiBlocksDeleted, @@ -2840,7 +2870,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_Relocator : public F_RefCount + flminterface IF_Relocator : public F_Object { virtual void FLMAPI relocate( void * pvOldAlloc, @@ -2853,7 +2883,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_SlabManager : public F_RefCount + flminterface IF_SlabManager : public F_Object { virtual RCODE FLMAPI setup( FLMUINT uiPreallocSize) = 0; @@ -2899,7 +2929,7 @@ Desc: Class to provide an efficient means of providing many allocations of a fixed size. ****************************************************************************/ - flminterface IF_FixedAlloc : public F_RefCount + flminterface IF_FixedAlloc : public F_Object { virtual RCODE FLMAPI setup( IF_Relocator * pRelocator, @@ -2926,10 +2956,13 @@ virtual void FLMAPI defragmentMemory( void) = 0; }; + RCODE FLMAPI FlmAllocFixedAllocator( + IF_FixedAlloc ** ppFixedAllocator); + /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_BufferAlloc : public F_RefCount + flminterface IF_BufferAlloc : public F_Object { virtual RCODE FLMAPI setup( IF_SlabManager * pSlabManager, @@ -2965,10 +2998,13 @@ virtual void FLMAPI defragmentMemory( void) = 0; }; + RCODE FLMAPI FlmAllocBufferAllocator( + IF_BufferAlloc ** ppBufferAllocator); + /**************************************************************************** Desc: ****************************************************************************/ - flminterface IF_MultiAlloc : public F_RefCount + flminterface IF_MultiAlloc : public F_Object { virtual RCODE FLMAPI setup( IF_SlabManager * pSlabManager, @@ -2995,13 +3031,14 @@ virtual FLMUINT FLMAPI getTrueSize( FLMBYTE * pucBuffer) = 0; - virtual FLMUINT FLMAPI getMaxCellSize( void) = 0; - virtual void FLMAPI lockMutex( void) = 0; virtual void FLMAPI unlockMutex( void) = 0; }; + RCODE FLMAPI FlmAllocMultiAllocator( + IF_MultiAlloc ** ppMultiAllocator); + /**************************************************************************** Desc: Misc. ****************************************************************************/ @@ -3017,6 +3054,76 @@ #define f_swap( a, b, tmp) \ ((tmp) = (a), (a) = (b), (b) = (tmp)) + FINLINE FLMBOOL f_isHexChar( + FLMBYTE ucChar) + { + if( (ucChar >= '0' && ucChar <= '9') || + (ucChar >= 'A' && ucChar <= 'F') || + (ucChar >= 'a' && ucChar <= 'f')) + { + return( TRUE); + } + + return( FALSE); + } + + FINLINE FLMBOOL f_isHexChar( + FLMUNICODE uChar) + { + if( uChar > 127) + { + return( FALSE); + } + + return( f_isHexChar( f_tonative( (FLMBYTE)uChar))); + } + + FINLINE FLMBYTE f_getHexVal( + FLMBYTE ucChar) + { + if( ucChar >= '0' && ucChar <= '9') + { + return( (FLMBYTE)(ucChar - '0')); + } + else if( ucChar >= 'A' && ucChar <= 'F') + { + return( (FLMBYTE)((ucChar - 'A') + 10)); + } + else if( ucChar >= 'a' && ucChar <= 'f') + { + return( (FLMBYTE)((ucChar - 'a') + 10)); + } + + return( 0); + } + + FINLINE FLMBYTE f_getHexVal( + FLMUNICODE uChar) + { + return( f_getHexVal( f_tonative( (FLMBYTE)uChar))); + } + + FINLINE FLMBOOL f_isValidHexNum( + const FLMBYTE * pszString) + { + if( *pszString == 0) + { + return( FALSE); + } + + while( *pszString) + { + if( !f_isHexChar( *pszString)) + { + return( TRUE); + } + + pszString++; + } + + return( TRUE); + } + RCODE FLMAPI f_filecpy( const char * pszSourceFile, const char * pszData); @@ -3025,14 +3132,6 @@ const char * pszSourceFile, const char * pszData); - RCODE FLMAPI f_copyPartial( - IF_FileHdl * pSrcFileHdl, - FLMUINT64 ui64SrcOffset, - FLMUINT64 ui64SrcSize, - IF_FileHdl * pDestFileHdl, - FLMUINT64 ui64DestOffset, - FLMUINT64 * pui64BytesCopiedRV); - /**************************************************************************** Desc: Status and return codes ****************************************************************************/ @@ -3545,38 +3644,43 @@ #define NE_FLM_FAILURE FTK_ERROR_BASE( 0x108) // NE_RECOVERABLE_FAILURE - Internal failure. #define NE_FLM_BOF_HIT FTK_ERROR_BASE( 0x109) // Beginning of results encountered. This error is may be returned when reading query results in reverse order (from last to first). #define NE_FLM_EOF_HIT FTK_ERROR_BASE( 0x10A) // End of results encountered. This error may be returned when reading query results in forward order (first to last). - #define NE_FLM_END FTK_ERROR_BASE( 0x10B) // End of roll-forward log packets encountered. NOTE: This error code should never be returned to an application. - #define NE_FLM_CONV_BAD_DIGIT FTK_ERROR_BASE( 0x10C) // Non-numeric digit found in text to numeric conversion. - #define NE_FLM_CONV_DEST_OVERFLOW FTK_ERROR_BASE( 0x10D) // Destination buffer not large enough to hold data. - #define NE_FLM_CONV_ILLEGAL FTK_ERROR_BASE( 0x10E) // Attempt to convert between data types is an unsupported conversion. - #define NE_FLM_CONV_NULL_SRC FTK_ERROR_BASE( 0x10F) // Data source cannot be NULL when doing data conversion. - #define NE_FLM_CONV_NUM_OVERFLOW FTK_ERROR_BASE( 0x110) // Numeric overflow (> upper bound) converting to numeric type. - #define NE_FLM_CONV_NUM_UNDERFLOW FTK_ERROR_BASE( 0x111) // Numeric underflow (< lower bound) converting to numeric type. - #define NE_FLM_SYNTAX FTK_ERROR_BASE( 0x112) // Syntax error while parsing XML or query. - #define NE_FLM_UNSUPPORTED_FEATURE FTK_ERROR_BASE( 0x113) // Attempting to use a feature for which full support has been disabled. - #define NE_FLM_FILE_EXISTS FTK_ERROR_BASE( 0x114) // Attempt to create a database, but the file already exists. - #define NE_FLM_COULD_NOT_CREATE_SEMAPHORE FTK_ERROR_BASE( 0x115) // Could not create a semaphore. - #define NE_FLM_BAD_UTF8 FTK_ERROR_BASE( 0x116) // An invalid byte sequence was found in a UTF-8 string - #define NE_FLM_ERROR_WAITING_ON_SEMPAHORE FTK_ERROR_BASE( 0x117) // Error occurred while waiting on a sempahore. - #define NE_FLM_BAD_PLATFORM_FORMAT FTK_ERROR_BASE( 0x118) // Cannot support platform format. NOTE: No need to document this one, it is strictly internal. - #define NE_FLM_BAD_SEN FTK_ERROR_BASE( 0x119) // Invalid simple encoded number. - #define NE_FLM_UNSUPPORTED_INTERFACE FTK_ERROR_BASE( 0x11A) // Requested COM interface is not supported. - #define NE_FLM_BAD_RCODE_TABLE FTK_ERROR_BASE( 0x11B) // The error code tables are incorrect. NOTE: This is an internal error that does not need to be documented. - #define NE_FLM_BUFFER_OVERFLOW FTK_ERROR_BASE( 0x11C) // Buffer overflow. - #define NE_FLM_INVALID_XML FTK_ERROR_BASE( 0x11D) // Invalid XML encountered while parsing document. - #define NE_FLM_ILLEGAL_FLAG FTK_ERROR_BASE( 0x11E) // Illegal flag passed to getChildElement method. Must be zero for elements that can have non-unique child elements. - #define NE_FLM_ILLEGAL_OP FTK_ERROR_BASE( 0x11F) // Illegal operation - #define NE_FLM_COULD_NOT_START_THREAD FTK_ERROR_BASE( 0x120) // Problem starting a new thread - #define NE_FLM_BAD_BASE64_ENCODING FTK_ERROR_BASE( 0x121) // Invalid base64 sequence encountered - #define NE_FLM_STREAM_EXISTS FTK_ERROR_BASE( 0x122) // Stream file already exists - #define NE_FLM_MULTIPLE_MATCHES FTK_ERROR_BASE( 0x123) // Multiple items matched but only one match was expected - #define NE_FLM_NOT_UNIQUE FTK_ERROR_BASE( 0x124) // Non-unique key - #define NE_FLM_BTREE_ERROR FTK_ERROR_BASE( 0x125) // Generic b-tree error - #define NE_FLM_BTREE_KEY_SIZE FTK_ERROR_BASE( 0x126) // Invalid b-tree key size - #define NE_FLM_BTREE_FULL FTK_ERROR_BASE( 0x127) // B-tree cannot grow beyond current size - #define NE_FLM_BTREE_BAD_STATE FTK_ERROR_BASE( 0x128) // B-tree operation cannot be completed - #define NE_FLM_COULD_NOT_CREATE_MUTEX FTK_ERROR_BASE( 0x129) // Mutex alloc / init failed - #define NE_FLM_LAST_GENERAL_ERROR FTK_ERROR_BASE( 0x12A) // NOTE: This is not an error code - do not document + #define NE_FLM_CONV_BAD_DIGIT FTK_ERROR_BASE( 0x10B) // Non-numeric digit found in text to numeric conversion. + #define NE_FLM_CONV_DEST_OVERFLOW FTK_ERROR_BASE( 0x10C) // Destination buffer not large enough to hold data. + #define NE_FLM_CONV_ILLEGAL FTK_ERROR_BASE( 0x10D) // Attempt to convert between data types is an unsupported conversion. + #define NE_FLM_CONV_NULL_SRC FTK_ERROR_BASE( 0x10E) // Data source cannot be NULL when doing data conversion. + #define NE_FLM_CONV_NUM_OVERFLOW FTK_ERROR_BASE( 0x10F) // Numeric overflow (> upper bound) converting to numeric type. + #define NE_FLM_CONV_NUM_UNDERFLOW FTK_ERROR_BASE( 0x110) // Numeric underflow (< lower bound) converting to numeric type. + #define NE_FLM_SYNTAX FTK_ERROR_BASE( 0x111) // Syntax error while parsing XML or query. + #define NE_FLM_UNSUPPORTED_FEATURE FTK_ERROR_BASE( 0x112) // Attempting to use a feature for which full support has been disabled. + #define NE_FLM_FILE_EXISTS FTK_ERROR_BASE( 0x113) // Attempt to create a database, but the file already exists. + #define NE_FLM_COULD_NOT_CREATE_SEMAPHORE FTK_ERROR_BASE( 0x114) // Could not create a semaphore. + #define NE_FLM_BAD_UTF8 FTK_ERROR_BASE( 0x115) // An invalid byte sequence was found in a UTF-8 string + #define NE_FLM_ERROR_WAITING_ON_SEMPAHORE FTK_ERROR_BASE( 0x116) // Error occurred while waiting on a sempahore. + #define NE_FLM_BAD_PLATFORM_FORMAT FTK_ERROR_BASE( 0x117) // Cannot support platform format. NOTE: No need to document this one, it is strictly internal. + #define NE_FLM_BAD_SEN FTK_ERROR_BASE( 0x118) // Invalid simple encoded number. + #define NE_FLM_UNSUPPORTED_INTERFACE FTK_ERROR_BASE( 0x119) // Requested COM interface is not supported. + #define NE_FLM_BAD_RCODE_TABLE FTK_ERROR_BASE( 0x11A) // The error code tables are incorrect. NOTE: This is an internal error that does not need to be documented. + #define NE_FLM_BUFFER_OVERFLOW FTK_ERROR_BASE( 0x11B) // Buffer overflow. + #define NE_FLM_INVALID_XML FTK_ERROR_BASE( 0x11C) // Invalid XML encountered while parsing document. + #define NE_FLM_ILLEGAL_FLAG FTK_ERROR_BASE( 0x11D) // Illegal flag passed to getChildElement method. Must be zero for elements that can have non-unique child elements. + #define NE_FLM_ILLEGAL_OP FTK_ERROR_BASE( 0x11E) // Illegal operation + #define NE_FLM_COULD_NOT_START_THREAD FTK_ERROR_BASE( 0x11F) // Problem starting a new thread + #define NE_FLM_BAD_BASE64_ENCODING FTK_ERROR_BASE( 0x120) // Invalid base64 sequence encountered + #define NE_FLM_STREAM_EXISTS FTK_ERROR_BASE( 0x121) // Stream file already exists + #define NE_FLM_MULTIPLE_MATCHES FTK_ERROR_BASE( 0x122) // Multiple items matched but only one match was expected + #define NE_FLM_NOT_UNIQUE FTK_ERROR_BASE( 0x123) // Non-unique key + #define NE_FLM_BTREE_ERROR FTK_ERROR_BASE( 0x124) // Generic b-tree error + #define NE_FLM_BTREE_KEY_SIZE FTK_ERROR_BASE( 0x125) // Invalid b-tree key size + #define NE_FLM_BTREE_FULL FTK_ERROR_BASE( 0x126) // B-tree cannot grow beyond current size + #define NE_FLM_BTREE_BAD_STATE FTK_ERROR_BASE( 0x127) // B-tree operation cannot be completed + #define NE_FLM_COULD_NOT_CREATE_MUTEX FTK_ERROR_BASE( 0x128) // Mutex alloc / init failed + #define NE_FLM_DATA_ERROR FTK_ERROR_BASE( 0x129) + #define NE_FLM_CLASS_NOT_AVAILABLE FTK_ERROR_BASE( 0x12A) + #define NE_FLM_BAD_DATA_TYPE FTK_ERROR_BASE( 0x12B) + #define NE_FLM_READ_ONLY FTK_ERROR_BASE( 0x12C) + #define NE_FLM_KEY_OVERFLOW FTK_ERROR_BASE( 0x12D) + #define NE_FLM_UNEXPECTED_END_OF_INPUT FTK_ERROR_BASE( 0x12E) + #define NE_FLM_LAST_GENERAL_ERROR FTK_ERROR_BASE( 0x12F) // NOTE: This is not an error code - do not document /**************************************************************************** Desc: I/O Errors diff --git a/ftk/src/ftkbtree.cpp b/ftk/src/ftkbtree.cpp index 7266fa6..33ebb4a 100644 --- a/ftk/src/ftkbtree.cpp +++ b/ftk/src/ftkbtree.cpp @@ -24,6 +24,7 @@ //------------------------------------------------------------------------------ #include "ftksys.h" +#if 0 FSTATIC FLMUINT btGetEntryDataLength( FLMBYTE * pucEntry, @@ -505,7 +506,7 @@ typedef struct /**************************************************************************** Desc: ****************************************************************************/ -class F_Btree : public IF_Btree, public F_Base +class F_Btree : public IF_Btree { public: @@ -12235,3 +12236,4 @@ Exit: return( rc); } +#endif diff --git a/ftk/src/ftkdir.cpp b/ftk/src/ftkdir.cpp index f160a85..ba8f266 100644 --- a/ftk/src/ftkdir.cpp +++ b/ftk/src/ftkdir.cpp @@ -148,7 +148,7 @@ FINLINE void FLMAPI F_DirHdl::currentItemPath( if( RC_OK( m_rc)) { f_strcpy( pszPath, m_szDirectoryPath); - gv_pFileSystem->pathAppend( pszPath, m_szFileName); + f_getFileSysPtr()->pathAppend( pszPath, m_szFileName); } } @@ -186,10 +186,11 @@ Desc: Get the next item in a directory ****************************************************************************/ RCODE FLMAPI F_DirHdl::next( void) { - char szFoundPath[ F_PATH_MAX_SIZE]; - char szDummyPath[ F_PATH_MAX_SIZE]; - FLMUINT uiSearchAttributes; - FLMUINT uiFoundAttrib; + char szFoundPath[ F_PATH_MAX_SIZE]; + char szDummyPath[ F_PATH_MAX_SIZE]; + FLMUINT uiSearchAttributes; + FLMUINT uiFoundAttrib; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( RC_BAD( m_rc)) { @@ -225,13 +226,13 @@ RCODE FLMAPI F_DirHdl::next( void) m_uiAttrib = uiFoundAttrib; } - if( RC_BAD( m_rc = gv_pFileSystem->pathReduce( szFoundPath, + if( RC_BAD( m_rc = pFileSystem->pathReduce( szFoundPath, szDummyPath, m_szFileName))) { goto Exit; } - if( gv_pFileSystem->doesFileMatch( m_szFileName, m_szPattern)) + if( pFileSystem->doesFileMatch( m_szFileName, m_szPattern)) { break; } @@ -281,8 +282,9 @@ Desc: Create a directory (and parent directories if necessary). RCODE FLMAPI F_DirHdl::createDir( const char * pszDirPath) { - char * pszParentDir = NULL; - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + char * pszParentDir = NULL; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( RC_BAD( rc = f_alloc( F_PATH_MAX_SIZE, &pszParentDir))) { @@ -291,7 +293,7 @@ RCODE FLMAPI F_DirHdl::createDir( // Discover the parent directory of the given one - if( RC_BAD( rc = gv_pFileSystem->pathReduce( pszDirPath, + if( RC_BAD( rc = pFileSystem->pathReduce( pszDirPath, pszParentDir, NULL))) { goto Exit; @@ -312,9 +314,9 @@ RCODE FLMAPI F_DirHdl::createDir( { // If the "parent" is actually a regular file we need to return an error - if( RC_OK( gv_pFileSystem->doesFileExist( pszParentDir))) + if( RC_OK( pFileSystem->doesFileExist( pszParentDir))) { - if( !gv_pFileSystem->isDir( pszParentDir)) + if( !pFileSystem->isDir( pszParentDir)) { rc = RC_SET( NE_FLM_IO_ACCESS_DENIED); goto Exit; @@ -391,9 +393,10 @@ RCODE f_fileFindFirst( FLMUINT * puiFoundAttrib) { #ifdef FLM_WIN - char szTmpPath[ F_PATH_MAX_SIZE]; - char * pszWildCard = "*.*"; - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + char szTmpPath[ F_PATH_MAX_SIZE]; + char * pszWildCard = "*.*"; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); f_memset( pFindData, 0, sizeof( F_IO_FIND_DATA)); pFindData->findHandle = INVALID_HANDLE_VALUE; @@ -414,7 +417,7 @@ RCODE f_fileFindFirst( f_strcpy( szTmpPath, pszSearchPath); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( szTmpPath, pszWildCard))) + if( RC_BAD( rc = pFileSystem->pathAppend( szTmpPath, pszWildCard))) { goto Exit; } @@ -447,7 +450,7 @@ RCODE f_fileFindFirst( f_strcpy( pszFoundPath, pFindData->szSearchPath); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( pszFoundPath, + if( RC_BAD( rc = pFileSystem->pathAppend( pszFoundPath, (char *)pFindData->findBuffer.cFileName))) { goto Exit; @@ -468,11 +471,12 @@ Exit: return( rc); #else - + + RCODE rc = NE_FLM_OK; char szTmpPath[ F_PATH_MAX_SIZE]; FSTATIC char pszWildCard[] = {'*',0}; int iRetVal; - RCODE rc = NE_FLM_OK; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( !pszSearchPath) { @@ -481,7 +485,7 @@ Exit: } f_strcpy( szTmpPath, pszSearchPath); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( szTmpPath, pszWildCard))) + if( RC_BAD( rc = pFileSystem->pathAppend( szTmpPath, pszWildCard))) { goto Exit; } @@ -550,7 +554,7 @@ Exit: f_strcpy( pszFoundPath, pszSearchPath); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( pszFoundPath, + if( RC_BAD( rc = pFileSystem->pathAppend( pszFoundPath, (char *)pFindData->name))) { goto Exit; @@ -578,7 +582,8 @@ RCODE f_fileFindNext( char * pszFoundPath, FLMUINT * puiFoundAttrib) { - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); #ifdef FLM_WIN @@ -610,7 +615,7 @@ RCODE f_fileFindNext( f_strcpy( pszFoundPath, pFindData->szSearchPath); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( pszFoundPath, + if( RC_BAD( rc = pFileSystem->pathAppend( pszFoundPath, (char *)pFindData->findBuffer.cFileName))) { goto Exit; @@ -642,7 +647,7 @@ RCODE f_fileFindNext( f_strcpy( pszFoundPath, pFindData->search_path); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( pszFoundPath, + if( RC_BAD( rc = pFileSystem->pathAppend( pszFoundPath, (char *)pFindData->name))) { goto Exit; diff --git a/ftk/src/ftkerror.cpp b/ftk/src/ftkerror.cpp index 75bef6e..6bc4d59 100644 --- a/ftk/src/ftkerror.cpp +++ b/ftk/src/ftkerror.cpp @@ -36,7 +36,7 @@ typedef struct /**************************************************************************** Desc: ****************************************************************************/ -F_ERROR_CODE_MAP gv_FlmGeneralErrors[ +F_ERROR_CODE_MAP gv_FtkGeneralErrors[ NE_FLM_LAST_GENERAL_ERROR - NE_FLM_FIRST_GENERAL_ERROR - 1] = { flmErrorCodeEntry( NE_FLM_NOT_IMPLEMENTED), @@ -49,7 +49,6 @@ F_ERROR_CODE_MAP gv_FlmGeneralErrors[ flmErrorCodeEntry( NE_FLM_FAILURE), flmErrorCodeEntry( NE_FLM_BOF_HIT), flmErrorCodeEntry( NE_FLM_EOF_HIT), - flmErrorCodeEntry( NE_FLM_END), flmErrorCodeEntry( NE_FLM_CONV_BAD_DIGIT), flmErrorCodeEntry( NE_FLM_CONV_DEST_OVERFLOW), flmErrorCodeEntry( NE_FLM_CONV_ILLEGAL), @@ -79,13 +78,19 @@ F_ERROR_CODE_MAP gv_FlmGeneralErrors[ flmErrorCodeEntry( NE_FLM_BTREE_KEY_SIZE), flmErrorCodeEntry( NE_FLM_BTREE_FULL), flmErrorCodeEntry( NE_FLM_BTREE_BAD_STATE), - flmErrorCodeEntry( NE_FLM_COULD_NOT_CREATE_MUTEX) + flmErrorCodeEntry( NE_FLM_COULD_NOT_CREATE_MUTEX), + flmErrorCodeEntry( NE_FLM_DATA_ERROR), + flmErrorCodeEntry( NE_FLM_CLASS_NOT_AVAILABLE), + flmErrorCodeEntry( NE_FLM_BAD_DATA_TYPE), + flmErrorCodeEntry( NE_FLM_READ_ONLY), + flmErrorCodeEntry( NE_FLM_KEY_OVERFLOW), + flmErrorCodeEntry( NE_FLM_UNEXPECTED_END_OF_INPUT) }; /**************************************************************************** Desc: ****************************************************************************/ -F_ERROR_CODE_MAP gv_FlmIoErrors[ +F_ERROR_CODE_MAP gv_FtkIoErrors[ NE_FLM_LAST_IO_ERROR - NE_FLM_FIRST_IO_ERROR - 1] = { flmErrorCodeEntry( NE_FLM_IO_ACCESS_DENIED), @@ -136,7 +141,7 @@ F_ERROR_CODE_MAP gv_FlmIoErrors[ /**************************************************************************** Desc: ****************************************************************************/ -F_ERROR_CODE_MAP gv_FlmNetErrors[ +F_ERROR_CODE_MAP gv_FtkNetErrors[ NE_FLM_LAST_NET_ERROR - NE_FLM_FIRST_NET_ERROR - 1] = { flmErrorCodeEntry( NE_FLM_NOIP_ADDR), @@ -158,7 +163,7 @@ F_ERROR_CODE_MAP gv_FlmNetErrors[ /**************************************************************************** Desc: ****************************************************************************/ -F_ERROR_CODE_MAP gv_FlmStreamErrors[ +F_ERROR_CODE_MAP gv_FtkStreamErrors[ NE_FLM_LAST_STREAM_ERROR - NE_FLM_FIRST_STREAM_ERROR - 1] = { flmErrorCodeEntry( NE_FLM_STREAM_DECOMPRESS_ERROR), @@ -193,8 +198,6 @@ RCODE FLMAPI f_makeErr( break; case NE_FLM_EOF_HIT: break; - case NE_FLM_END: - break; case NE_FLM_EXISTS: break; case NE_FLM_NOT_FOUND: @@ -258,25 +261,25 @@ const char * FLMAPI f_errorString( else if( rc > NE_FLM_FIRST_GENERAL_ERROR && rc < NE_FLM_LAST_GENERAL_ERROR) { - pszErrorStr = gv_FlmGeneralErrors[ + pszErrorStr = gv_FtkGeneralErrors[ rc - NE_FLM_FIRST_GENERAL_ERROR - 1].pszErrorStr; } else if( rc > NE_FLM_FIRST_IO_ERROR && rc < NE_FLM_LAST_IO_ERROR) { - pszErrorStr = gv_FlmIoErrors[ + pszErrorStr = gv_FtkIoErrors[ rc - NE_FLM_FIRST_IO_ERROR - 1].pszErrorStr; } else if( rc > NE_FLM_FIRST_NET_ERROR && rc < NE_FLM_LAST_NET_ERROR) { - pszErrorStr = gv_FlmNetErrors[ + pszErrorStr = gv_FtkNetErrors[ rc - NE_FLM_FIRST_NET_ERROR - 1].pszErrorStr; } else if( rc > NE_FLM_FIRST_STREAM_ERROR && rc < NE_FLM_LAST_STREAM_ERROR) { - pszErrorStr = gv_FlmStreamErrors[ + pszErrorStr = gv_FtkStreamErrors[ rc - NE_FLM_FIRST_STREAM_ERROR - 1].pszErrorStr; } else @@ -455,7 +458,7 @@ RCODE f_checkErrorCodeTables( void) uiLoop < (NE_FLM_LAST_GENERAL_ERROR - NE_FLM_FIRST_GENERAL_ERROR - 1); uiLoop++) { - if( gv_FlmGeneralErrors[ uiLoop].rc != + if( gv_FtkGeneralErrors[ uiLoop].rc != (RCODE)(uiLoop + NE_FLM_FIRST_GENERAL_ERROR + 1)) { rc = RC_SET_AND_ASSERT( NE_FLM_BAD_RCODE_TABLE); @@ -467,7 +470,7 @@ RCODE f_checkErrorCodeTables( void) uiLoop < (NE_FLM_LAST_IO_ERROR - NE_FLM_FIRST_IO_ERROR - 1); uiLoop++) { - if( gv_FlmIoErrors[ uiLoop].rc != + if( gv_FtkIoErrors[ uiLoop].rc != (RCODE)(uiLoop + NE_FLM_FIRST_IO_ERROR + 1)) { rc = RC_SET_AND_ASSERT( NE_FLM_BAD_RCODE_TABLE); @@ -479,7 +482,7 @@ RCODE f_checkErrorCodeTables( void) uiLoop < (NE_FLM_LAST_NET_ERROR - NE_FLM_FIRST_NET_ERROR - 1); uiLoop++) { - if( gv_FlmNetErrors[ uiLoop].rc != + if( gv_FtkNetErrors[ uiLoop].rc != (RCODE)(uiLoop + NE_FLM_FIRST_NET_ERROR + 1)) { rc = RC_SET_AND_ASSERT( NE_FLM_BAD_RCODE_TABLE); @@ -491,7 +494,7 @@ RCODE f_checkErrorCodeTables( void) uiLoop < (NE_FLM_LAST_STREAM_ERROR - NE_FLM_FIRST_STREAM_ERROR - 1); uiLoop++) { - if( gv_FlmStreamErrors[ uiLoop].rc != + if( gv_FtkStreamErrors[ uiLoop].rc != (RCODE)(uiLoop + NE_FLM_FIRST_STREAM_ERROR + 1)) { rc = RC_SET_AND_ASSERT( NE_FLM_BAD_RCODE_TABLE); diff --git a/ftk/src/ftkfsys.cpp b/ftk/src/ftkfsys.cpp index 14d46f5..da18201 100644 --- a/ftk/src/ftkfsys.cpp +++ b/ftk/src/ftkfsys.cpp @@ -59,7 +59,7 @@ FINLINE void f_setupTime( /**************************************************************************** Desc: ****************************************************************************/ -class F_FileSystem : public IF_FileSystem, public F_Base +class F_FileSystem : public IF_FileSystem { public: @@ -134,6 +134,14 @@ public: FLMBOOL bOverwrite, FLMUINT64 * pui64BytesCopied); + RCODE FLMAPI copyPartialFile( + IF_FileHdl * pSrcFileHdl, + FLMUINT64 ui64SrcOffset, + FLMUINT64 ui64SrcSize, + IF_FileHdl * pDestFileHdl, + FLMUINT64 ui64DestOffset, + FLMUINT64 * pui64BytesCopiedRV); + RCODE FLMAPI renameFile( const char * pszFileName, const char * pszNewFileName); @@ -177,12 +185,11 @@ public: const char * pszFileName, FLMBOOL bReadOnly); - RCODE FLMAPI writeToOStream( - IF_IStream * pIStream, - IF_OStream * pOStream); - private: + RCODE removeEmptyDir( + const char * pszDirName); + #if defined( FLM_UNIX) RCODE unix_RenameSafe( const char * pszSrcFile, @@ -392,7 +399,7 @@ Desc: RCODE FLMAPI FlmGetFileSystem( IF_FileSystem ** ppFileSystem) { - *ppFileSystem = gv_pFileSystem; + *ppFileSystem = f_getFileSysPtr(); (*ppFileSystem)->AddRef(); return( NE_FLM_OK); } @@ -712,7 +719,7 @@ RCODE FLMAPI F_FileSystem::removeDir( pDirHdl = NULL; } - if( RC_BAD( rc = removeDir( pszDirName))) + if( RC_BAD( rc = removeEmptyDir( pszDirName))) { goto Exit; } @@ -727,6 +734,65 @@ Exit: return( rc); } +/**************************************************************************** +Desc: Remove an empty directory +****************************************************************************/ +RCODE F_FileSystem::removeEmptyDir( + const char * pszDirPath) +{ +#if defined( FLM_WIN) + + if( !RemoveDirectory( (LPTSTR)pszDirPath)) + { + return( f_mapPlatformError( GetLastError(), NE_FLM_IO_DELETING_FILE)); + } + + return( NE_FLM_OK); + +#elif defined( FLM_UNIX) + + if( rmdir( pszDirPath) == -1 ) + { + return( f_mapPlatformError( errno, NE_FLM_IO_DELETING_FILE)); + } + + return( NE_FLM_OK); + +#elif defined( FLM_NLM) + RCODE rc = NE_FLM_OK; + FLMBYTE pucPseudoLNamePath[ F_PATH_MAX_SIZE + 1]; + FLMBYTE pucLNamePath[ F_PATH_MAX_SIZE]; + LONG lVolumeID; + LONG lPathID; + LONG lLNamePathCount; + LONG lErrorCode; + + f_strcpy( (char *)&pucPseudoLNamePath[1], pszDirPath); + pucPseudoLNamePath[0] = (FLMBYTE)f_strlen( pszDirPath); + + if( (lErrorCode = ConvertPathString( 0, 0, pucPseudoLNamePath, &lVolumeID, + &lPathID, pucLNamePath, &lLNamePathCount)) != 0) + { + goto Exit; + } + + if( (lErrorCode = DeleteDirectory( 0, lVolumeID, lPathID, pucLNamePath, + lLNamePathCount, LONGNameSpace)) != 0) + { + goto Exit; + } + +Exit: + + if( lErrorCode) + { + rc = f_mapPlatformError( lErrorCode, NE_FLM_IO_DELETING_FILE); + } + + return( rc); +#endif +} + /**************************************************************************** Desc: Determine if a file or directory exists. ****************************************************************************/ @@ -999,7 +1065,7 @@ RCODE FLMAPI F_FileSystem::copyFile( // Do the copy. - if( RC_BAD( rc = f_copyPartial( pSrcFileHdl, 0, ui64SrcSize, + if( RC_BAD( rc = copyPartialFile( pSrcFileHdl, 0, ui64SrcSize, pDestFileHdl, 0, pui64BytesCopied))) { goto Exit; @@ -1032,6 +1098,121 @@ Exit: return( rc); } +/**************************************************************************** +Desc: Do a partial copy from one file into another file. +****************************************************************************/ +RCODE FLMAPI F_FileSystem::copyPartialFile( + IF_FileHdl * pSrcFileHdl, // Source file handle. + FLMUINT64 ui64SrcOffset, // Offset to start copying from. + FLMUINT64 ui64SrcSize, // Bytes to copy + IF_FileHdl * pDestFileHdl, // Destination file handle + FLMUINT64 ui64DestOffset, // Destination start offset. + FLMUINT64 * pui64BytesCopiedRV) // Returns number of bytes copied +{ + RCODE rc = NE_FLM_OK; + FLMBYTE * pucBuffer = NULL; + FLMUINT uiAllocSize = 65536; + FLMUINT uiBytesToRead; + FLMUINT64 ui64CopySize; + FLMUINT64 ui64FileOffset; + FLMUINT uiBytesRead; + FLMUINT uiBytesWritten; + + ui64CopySize = ui64SrcSize; + *pui64BytesCopiedRV = 0; + + // Set the buffer size for use during the file copy + + if( ui64CopySize < uiAllocSize) + { + uiAllocSize = (FLMUINT)ui64CopySize; + } + + // Allocate a buffer + + if( RC_BAD( rc = f_alloc( uiAllocSize, &pucBuffer))) + { + goto Exit; + } + + // Position the file pointers + + if( RC_BAD( rc = pSrcFileHdl->seek( ui64SrcOffset, FLM_IO_SEEK_SET, + &ui64FileOffset))) + { + goto Exit; + } + + if( RC_BAD( rc = pDestFileHdl->seek( ui64DestOffset, FLM_IO_SEEK_SET, + &ui64FileOffset))) + { + goto Exit; + } + + // Begin copying the data + + while( ui64CopySize) + { + if( ui64CopySize > uiAllocSize) + { + uiBytesToRead = uiAllocSize; + } + else + { + uiBytesToRead = (FLMUINT)ui64CopySize; + } + + rc = pSrcFileHdl->read( FLM_IO_CURRENT_POS, uiBytesToRead, + pucBuffer, &uiBytesRead); + + if (rc == NE_FLM_IO_END_OF_FILE) + { + rc = NE_FLM_OK; + } + + if (RC_BAD( rc)) + { + rc = RC_SET( NE_FLM_IO_COPY_ERR); + goto Exit; + } + + uiBytesWritten = 0; + if( RC_BAD( rc = pDestFileHdl->write( FLM_IO_CURRENT_POS, uiBytesRead, + pucBuffer, &uiBytesWritten))) + { + if (rc == NE_FLM_IO_DISK_FULL) + { + *pui64BytesCopiedRV += uiBytesWritten; + } + else + { + rc = RC_SET( NE_FLM_IO_COPY_ERR); + } + + goto Exit; + } + + *pui64BytesCopiedRV += uiBytesWritten; + + if( uiBytesRead < uiBytesToRead) + { + rc = RC_SET( NE_FLM_IO_END_OF_FILE); + goto Exit; + } + + ui64CopySize -= uiBytesRead; + } + +Exit: + + if (pucBuffer) + { + (void)f_free( &pucBuffer); + } + + return( rc); +} + /**************************************************************************** Desc: Rename a file. ****************************************************************************/ @@ -1343,121 +1524,6 @@ Exit: } #endif -/**************************************************************************** -Desc: Do a partial copy from one file into another file. -****************************************************************************/ -RCODE FLMAPI f_copyPartial( - IF_FileHdl * pSrcFileHdl, // Source file handle. - FLMUINT64 ui64SrcOffset, // Offset to start copying from. - FLMUINT64 ui64SrcSize, // Bytes to copy - IF_FileHdl * pDestFileHdl, // Destination file handle - FLMUINT64 ui64DestOffset, // Destination start offset. - FLMUINT64 * pui64BytesCopiedRV) // Returns number of bytes copied -{ - RCODE rc = NE_FLM_OK; - FLMBYTE * pucBuffer = NULL; - FLMUINT uiAllocSize = 65536; - FLMUINT uiBytesToRead; - FLMUINT64 ui64CopySize; - FLMUINT64 ui64FileOffset; - FLMUINT uiBytesRead; - FLMUINT uiBytesWritten; - - ui64CopySize = ui64SrcSize; - *pui64BytesCopiedRV = 0; - - // Set the buffer size for use during the file copy - - if( ui64CopySize < uiAllocSize) - { - uiAllocSize = (FLMUINT)ui64CopySize; - } - - // Allocate a buffer - - if( RC_BAD( rc = f_alloc( uiAllocSize, &pucBuffer))) - { - goto Exit; - } - - // Position the file pointers - - if( RC_BAD( rc = pSrcFileHdl->seek( ui64SrcOffset, FLM_IO_SEEK_SET, - &ui64FileOffset))) - { - goto Exit; - } - - if( RC_BAD( rc = pDestFileHdl->seek( ui64DestOffset, FLM_IO_SEEK_SET, - &ui64FileOffset))) - { - goto Exit; - } - - // Begin copying the data - - while( ui64CopySize) - { - if( ui64CopySize > uiAllocSize) - { - uiBytesToRead = uiAllocSize; - } - else - { - uiBytesToRead = (FLMUINT)ui64CopySize; - } - - rc = pSrcFileHdl->read( FLM_IO_CURRENT_POS, uiBytesToRead, - pucBuffer, &uiBytesRead); - - if (rc == NE_FLM_IO_END_OF_FILE) - { - rc = NE_FLM_OK; - } - - if (RC_BAD( rc)) - { - rc = RC_SET( NE_FLM_IO_COPY_ERR); - goto Exit; - } - - uiBytesWritten = 0; - if( RC_BAD( rc = pDestFileHdl->write( FLM_IO_CURRENT_POS, uiBytesRead, - pucBuffer, &uiBytesWritten))) - { - if (rc == NE_FLM_IO_DISK_FULL) - { - *pui64BytesCopiedRV += uiBytesWritten; - } - else - { - rc = RC_SET( NE_FLM_IO_COPY_ERR); - } - - goto Exit; - } - - *pui64BytesCopiedRV += uiBytesWritten; - - if( uiBytesRead < uiBytesToRead) - { - rc = RC_SET( NE_FLM_IO_END_OF_FILE); - goto Exit; - } - - ui64CopySize -= uiBytesRead; - } - -Exit: - - if (pucBuffer) - { - (void)f_free( &pucBuffer); - } - - return( rc); -} - /**************************************************************************** Desc: ****************************************************************************/ @@ -1513,12 +1579,13 @@ RCODE FLMAPI f_filecat( IF_FileHdl * pFileHdl = NULL; FLMUINT64 ui64FileSize = 0; FLMUINT uiBytesWritten = 0; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); - if (RC_BAD( rc = gv_pFileSystem->doesFileExist( pszSourceFile))) + if (RC_BAD( rc = pFileSystem->doesFileExist( pszSourceFile))) { if( rc == NE_FLM_IO_PATH_NOT_FOUND) { - if( RC_BAD( rc = gv_pFileSystem->createFile( + if( RC_BAD( rc = pFileSystem->createFile( pszSourceFile, FLM_IO_RDWR, &pFileHdl))) { goto Exit; @@ -1531,7 +1598,7 @@ RCODE FLMAPI f_filecat( } else { - if( RC_BAD( rc = gv_pFileSystem->openFile( pszSourceFile, + if( RC_BAD( rc = pFileSystem->openFile( pszSourceFile, FLM_IO_RDWR, &pFileHdl))) { goto Exit; @@ -1594,18 +1661,19 @@ Example: pFileName "autoexec.ncf" ****************************************************************************/ void FLMAPI F_FileSystem::pathParse( - const char * pszInputPath, - char * pszServer, - char * pszVolume, - char * pszDirPath, - char * pszFileName) + const char * pszInputPath, + char * pszServer, + char * pszVolume, + char * pszDirPath, + char * pszFileName) { - char szInput[ F_PATH_MAX_SIZE]; - char * pszNext; - char * pszColon; - char * pszComponent; - FLMUINT uiEndChar; - FLMBOOL bUNC = FALSE; + char szInput[ F_PATH_MAX_SIZE]; + char * pszNext; + char * pszColon; + char * pszComponent; + FLMUINT uiEndChar; + FLMBOOL bUNC = FALSE; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); // Initialize return buffers @@ -1627,7 +1695,7 @@ void FLMAPI F_FileSystem::pathParse( // Get the file name *pszFileName = 0; - gv_pFileSystem->pathReduce( pszInputPath, szInput, pszFileName); + pFileSystem->pathReduce( pszInputPath, szInput, pszFileName); } else { @@ -2135,46 +2203,3 @@ Exit: return( rc); } - -/****************************************************************************** -Desc: Read all data from input stream and write to the output stream. -******************************************************************************/ -RCODE FLMAPI F_FileSystem::writeToOStream( - IF_IStream * pIStream, - IF_OStream * pOStream) -{ - RCODE rc = NE_FLM_OK; - FLMBYTE ucBuffer[ 512]; - FLMUINT uiBufferSize = sizeof( ucBuffer); - FLMUINT uiBytesToWrite; - FLMUINT uiBytesRead; - - for (;;) - { - if( RC_BAD( rc = pIStream->read( - ucBuffer, uiBufferSize, &uiBytesRead))) - { - if( rc != NE_FLM_EOF_HIT) - { - goto Exit; - } - - rc = NE_FLM_OK; - - if (!uiBytesRead) - { - goto Exit; - } - } - - uiBytesToWrite = uiBytesRead; - if( RC_BAD( rc = pOStream->write( ucBuffer, uiBytesToWrite))) - { - goto Exit; - } - } - -Exit: - - return( rc); -} diff --git a/ftk/src/ftkftx.cpp b/ftk/src/ftkftx.cpp index 1dee311..07f9595 100644 --- a/ftk/src/ftkftx.cpp +++ b/ftk/src/ftkftx.cpp @@ -607,16 +607,17 @@ static FLMUINT ScanCodeToFKB[] = { Desc: Initializes the FTX environment. ****************************************************************************/ RCODE FLMAPI FTXInit( - const char * pszAppName, - FLMUINT uiCols, - FLMUINT uiRows, - eColorType backgroundColor, - eColorType foregroundColor, - KEY_HANDLER pKeyHandler, - void * pvKeyHandlerData) + const char * pszAppName, + FLMUINT uiCols, + FLMUINT uiRows, + eColorType backgroundColor, + eColorType foregroundColor, + KEY_HANDLER pKeyHandler, + void * pvKeyHandlerData) { - RCODE rc = NE_FLM_OK; - FTX_INFO * pFtxInfo; + RCODE rc = NE_FLM_OK; + FTX_INFO * pFtxInfo; + IF_ThreadMgr * pThreadMgr = f_getThreadMgrPtr(); if( gv_bInitialized) { @@ -682,7 +683,7 @@ RCODE FLMAPI FTXInit( #endif - if( RC_BAD( rc = gv_pThreadMgr->createThread( &gv_pFtxInfo->pBackgroundThrd, + if( RC_BAD( rc = pThreadMgr->createThread( &gv_pFtxInfo->pBackgroundThrd, _ftxBackgroundThread, "ftx_background"))) { goto Exit; @@ -691,7 +692,7 @@ RCODE FLMAPI FTXInit( gv_pFtxInfo->backgroundColor = backgroundColor; gv_pFtxInfo->foregroundColor = foregroundColor; - if( RC_BAD( rc = gv_pThreadMgr->createThread( &gv_pFtxInfo->pDisplayThrd, + if( RC_BAD( rc = pThreadMgr->createThread( &gv_pFtxInfo->pDisplayThrd, _ftxDefaultDisplayHandler, "ftx_display"))) { goto Exit; @@ -704,7 +705,7 @@ RCODE FLMAPI FTXInit( gv_pFtxInfo->pKeyHandler = pKeyHandler; gv_pFtxInfo->pvKeyHandlerData = pvKeyHandlerData; - if( RC_BAD( rc = gv_pThreadMgr->createThread( &gv_pFtxInfo->pKeyboardThrd, + if( RC_BAD( rc = pThreadMgr->createThread( &gv_pFtxInfo->pKeyboardThrd, _ftxDefaultKeyboardHandler, "ftx_keyboard"))) { goto Exit; diff --git a/ftk/src/ftkini.cpp b/ftk/src/ftkini.cpp index 9ab2e15..6d040eb 100644 --- a/ftk/src/ftkini.cpp +++ b/ftk/src/ftkini.cpp @@ -40,7 +40,7 @@ typedef struct INI_LINE /**************************************************************************** Desc: ****************************************************************************/ -class F_IniFile : public IF_IniFile, public F_Base +class F_IniFile : public IF_IniFile { public: @@ -244,17 +244,18 @@ Exit: Desc: Read the ini file and parse its contents ****************************************************************************/ RCODE FLMAPI F_IniFile::read( - const char * pszFileName) + const char * pszFileName) { - RCODE rc = NE_FLM_OK; - FLMBOOL bMore = FALSE; - FLMBOOL bEOF = FALSE; + RCODE rc = NE_FLM_OK; + FLMBOOL bMore = FALSE; + FLMBOOL bEOF = FALSE; #define INITIAL_READ_BUF_SIZE 100 - FLMUINT uiReadBufSize = 0; - FLMUINT uiBytesAvail = 0; - FLMUINT uiBytesInLine = 0; - char * pszReadBuf = NULL; - FLMUINT uiLineNum = 0; + FLMUINT uiReadBufSize = 0; + FLMUINT uiBytesAvail = 0; + FLMUINT uiBytesInLine = 0; + char * pszReadBuf = NULL; + FLMUINT uiLineNum = 0; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); f_assert( m_bReady); f_assert( !m_pFileHdl); @@ -271,7 +272,7 @@ RCODE FLMAPI F_IniFile::read( // It's not an error if the file doesn't exist. If it does exist, // we'll read in its data. - if( RC_BAD( gv_pFileSystem->openFile( pszFileName, + if( RC_BAD( pFileSystem->openFile( pszFileName, FLM_IO_RDONLY, &m_pFileHdl))) { goto Exit; @@ -383,10 +384,11 @@ Desc: Copies the data stored in the INI_LINE structs to the ini file ****************************************************************************/ RCODE FLMAPI F_IniFile::write( void) { - RCODE rc = NE_FLM_OK; - FLMUINT uiBytesWritten; - INI_LINE * pCurLine = NULL; - FLMBOOL uiFileOffset = 0; + RCODE rc = NE_FLM_OK; + FLMUINT uiBytesWritten; + INI_LINE * pCurLine = NULL; + FLMBOOL uiFileOffset = 0; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); f_assert( m_bReady); @@ -401,7 +403,7 @@ RCODE FLMAPI F_IniFile::write( void) f_assert( !m_pFileHdl); - if (RC_BAD( rc = gv_pFileSystem->createFile( m_pszFileName, + if (RC_BAD( rc = pFileSystem->createFile( m_pszFileName, FLM_IO_RDWR, &m_pFileHdl))) { goto Exit; diff --git a/ftk/src/ftkiobuf.cpp b/ftk/src/ftkiobuf.cpp index c82823d..532ef81 100644 --- a/ftk/src/ftkiobuf.cpp +++ b/ftk/src/ftkiobuf.cpp @@ -28,7 +28,7 @@ /**************************************************************************** Desc: ****************************************************************************/ -class F_IOBufferMgr : public IF_IOBufferMgr, public F_Base +class F_IOBufferMgr : public IF_IOBufferMgr { public: @@ -95,6 +95,20 @@ friend class F_IOBuffer; }; +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmAllocIOBufferMgr( + IF_IOBufferMgr ** ppIOBufferMgr) +{ + if( (*ppIOBufferMgr = f_new F_IOBufferMgr) == NULL) + { + return( RC_SET( NE_FLM_MEM)); + } + + return( NE_FLM_OK); +} + /**************************************************************************** Desc: ****************************************************************************/ diff --git a/ftk/src/ftkmem.cpp b/ftk/src/ftkmem.cpp index 4dbbc82..85a4d83 100644 --- a/ftk/src/ftkmem.cpp +++ b/ftk/src/ftkmem.cpp @@ -152,7 +152,7 @@ FSTATIC void freeMemTrackingInfo( /**************************************************************************** Desc: ****************************************************************************/ -class F_SlabManager : public IF_SlabManager, public F_Base +class F_SlabManager : public IF_SlabManager { public: @@ -288,7 +288,7 @@ friend class F_FixedAlloc; Desc: Class to provide an efficient means of providing many allocations of a fixed size. ****************************************************************************/ -class F_FixedAlloc : public IF_FixedAlloc, public F_Base +class F_FixedAlloc : public IF_FixedAlloc { public: @@ -476,7 +476,7 @@ friend class F_MultiAlloc; /**************************************************************************** Desc: ****************************************************************************/ -class F_BufferAlloc : public IF_BufferAlloc, public F_Base +class F_BufferAlloc : public IF_BufferAlloc { public: @@ -517,6 +517,11 @@ public: FLMUINT uiSize, FLMBYTE * pucBuffer); + FLMUINT FLMAPI getMaxCellSize( void) + { + return( MAX_CELL_SIZE); + } + void FLMAPI defragmentMemory( void); private: @@ -531,7 +536,7 @@ private: /**************************************************************************** Desc: ****************************************************************************/ -class F_MultiAlloc : public IF_MultiAlloc, public F_Base +class F_MultiAlloc : public IF_MultiAlloc { public: @@ -548,7 +553,7 @@ public: } RCODE FLMAPI setup( - F_SlabManager * pSlabManager, + IF_SlabManager * pSlabManager, FLMUINT * puiCellSizes, FLM_SLAB_USAGE * pUsageStats); @@ -610,7 +615,7 @@ private: /**************************************************************************** Desc: This class is used to do pool memory allocations. ****************************************************************************/ -class F_Pool : public IF_Pool, public F_Base +class F_Pool : public IF_Pool { public: @@ -723,6 +728,76 @@ private: POOL_STATS * m_pPoolStats; }; +/************************************************************************ +Desc: +*************************************************************************/ +RCODE FLMAPI FlmAllocPool( + IF_Pool ** ppPool) +{ + if( (*ppPool = f_new F_Pool) == NULL) + { + return( RC_SET( NE_FLM_MEM)); + } + + return( NE_FLM_OK); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmAllocSlabManager( + IF_SlabManager ** ppSlabManager) +{ + if( (*ppSlabManager = f_new F_SlabManager) == NULL) + { + return( RC_SET( NE_FLM_MEM)); + } + + return( NE_FLM_OK); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmAllocFixedAllocator( + IF_FixedAlloc ** ppFixedAllocator) +{ + if( (*ppFixedAllocator = f_new F_FixedAlloc) == NULL) + { + return( RC_SET( NE_FLM_MEM)); + } + + return( NE_FLM_OK); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmAllocBufferAllocator( + IF_BufferAlloc ** ppBufferAllocator) +{ + if( (*ppBufferAllocator = f_new F_BufferAlloc) == NULL) + { + return( RC_SET( NE_FLM_MEM)); + } + + return( NE_FLM_OK); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmAllocMultiAllocator( + IF_MultiAlloc ** ppMultiAllocator) +{ + if( (*ppMultiAllocator = f_new F_MultiAlloc) == NULL) + { + return( RC_SET( NE_FLM_MEM)); + } + + return( NE_FLM_OK); +} + /************************************************************************ Desc: *************************************************************************/ @@ -1318,7 +1393,8 @@ void logMemLeak( } #ifdef FLM_WIN - FLMINT iRet; + FLMINT iRet; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); iRet = MessageBox( NULL, (LPCTSTR)pszMessageBuffer, "WIN32 Memory Testing", MB_ABORTRETRYIGNORE | MB_ICONINFORMATION | MB_TASKMODAL @@ -1335,7 +1411,7 @@ void logMemLeak( gv_bLogLeaks = TRUE; #endif - if (gv_bLogLeaks && gv_pFileSystem) + if (gv_bLogLeaks && pFileSystem) { RCODE rc; FLMUINT uiDummy; @@ -1345,12 +1421,12 @@ void logMemLeak( const char * pszErrPath = "memtest.ert"; #endif - if (RC_BAD( rc = gv_pFileSystem->openFile( pszErrPath, + if (RC_BAD( rc = pFileSystem->openFile( pszErrPath, FLM_IO_RDWR | FLM_IO_SH_DENYNONE, &pFileHdl))) { if (rc == NE_FLM_IO_PATH_NOT_FOUND) { - rc = gv_pFileSystem->createFile( pszErrPath, + rc = pFileSystem->createFile( pszErrPath, FLM_IO_RDWR | FLM_IO_SH_DENYNONE, &pFileHdl); } } @@ -1792,20 +1868,6 @@ void f_resetStackInfoImp( #endif } -/************************************************************************ -Desc: -*************************************************************************/ -RCODE FLMAPI FlmAllocPool( - IF_Pool ** ppPool) -{ - if( (*ppPool = f_new F_Pool) == NULL) - { - return( RC_SET( NE_FLM_MEM)); - } - - return( NE_FLM_OK); -} - /************************************************************************ Desc: Destructor *************************************************************************/ @@ -2695,6 +2757,11 @@ F_FixedAlloc::~F_FixedAlloc() { m_pSlabManager->Release(); } + + if( m_pRelocator) + { + m_pRelocator->Release(); + } } /**************************************************************************** @@ -2713,9 +2780,16 @@ RCODE F_FixedAlloc::setup( f_assert( pUsageStats != NULL); m_pUsageStats = pUsageStats; + m_pSlabManager = pSlabManager; m_pSlabManager->AddRef(); - m_pRelocator = pRelocator; + + if( pRelocator) + { + m_pRelocator = pRelocator; + m_pRelocator->AddRef(); + } + m_uiCellSize = uiCellSize; m_uiSlabSize = m_pSlabManager->getSlabSize(); @@ -3944,7 +4018,7 @@ IF_FixedAlloc * F_BufferAlloc::getAllocator( Desc: ****************************************************************************/ RCODE F_MultiAlloc::setup( - F_SlabManager * pSlabManager, + IF_SlabManager * pSlabManager, FLMUINT * puiCellSizes, FLM_SLAB_USAGE * pUsageStats) { @@ -4260,12 +4334,209 @@ Exit: return( rc); } +/**************************************************************************** +Desc: +****************************************************************************/ +void FLMAPI f_freeAlignedBuffer( + void ** ppvAlloc) +{ + if( *ppvAlloc) + { +#ifdef FLM_WIN + (void)VirtualFree( *ppvAlloc, 0, MEM_RELEASE); + *ppvAlloc = NULL; +#elif defined( FLM_LINUX) || defined( FLM_SOLARIS) + free( *ppvAlloc); + *ppvAlloc = NULL; +#else + f_free( ppvAlloc); +#endif + } +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE f_getMemoryInfo( + FLMUINT64 * pui64TotalPhysMem, + FLMUINT64 * pui64AvailPhysMem) +{ + RCODE rc = NE_FLM_OK; + FLMUINT64 ui64TotalPhysMem = 0; + FLMUINT64 ui64AvailPhysMem = 0; + +#ifdef FLM_WIN + { + MEMORYSTATUS MemStatus; + + GlobalMemoryStatus( &MemStatus); + + ui64TotalPhysMem = MemStatus.dwTotalPhys; + ui64AvailPhysMem = MemStatus.dwAvailPhys; + + // There could be more physical memory in the system than we could + // actually allocate in our virtual address space. Thus, we need to + // make sure that we never exceed our total virtual address space. + + if (ui64TotalPhysMem > (FLMUINT)MemStatus.dwTotalVirtual) + { + ui64TotalPhysMem = (FLMUINT)MemStatus.dwTotalVirtual; + } + + if( ui64AvailPhysMem > ui64TotalPhysMem) + { + ui64AvailPhysMem = ui64TotalPhysMem; + } + } +#elif defined( FLM_UNIX) + { + FLMUINT uiProcMemLimit = HIGH_FLMUINT; + FLMUINT uiProcVMemLimit = HIGH_FLMUINT; + + #if defined( RLIMIT_VMEM) + { + struct rlimit rlim; + + // Bump the process soft virtual limit up to the hard limit + + if( getrlimit( RLIMIT_VMEM, &rlim) == 0) + { + if( rlim.rlim_cur < rlim.rlim_max) + { + rlim.rlim_cur = rlim.rlim_max; + (void)setrlimit( RLIMIT_VMEM, &rlim); + if( getrlimit( RLIMIT_VMEM, &rlim) != 0) + { + rlim.rlim_cur = RLIM_INFINITY; + rlim.rlim_max = RLIM_INFINITY; + } + } + + if( rlim.rlim_cur != RLIM_INFINITY) + { + uiProcVMemLimit = (FLMUINT)rlim.rlim_cur; + } + } + } + #endif + + #if defined( RLIMIT_DATA) + { + struct rlimit rlim; + + // Bump the process soft heap limit up to the hard limit + + if( getrlimit( RLIMIT_DATA, &rlim) == 0) + { + if( rlim.rlim_cur < rlim.rlim_max) + { + rlim.rlim_cur = rlim.rlim_max; + (void)setrlimit( RLIMIT_DATA, &rlim); + if( getrlimit( RLIMIT_DATA, &rlim) != 0) + { + rlim.rlim_cur = RLIM_INFINITY; + rlim.rlim_max = RLIM_INFINITY; + } + } + + if( rlim.rlim_cur != RLIM_INFINITY) + { + uiProcMemLimit = (FLMUINT)rlim.rlim_cur; + } + } + } + #endif + + #ifdef FLM_AIX + struct vminfo tmpvminfo; + #ifdef _SC_PAGESIZE + long iPageSize = sysconf(_SC_PAGESIZE); + #else + long iPageSize = 4096; + #endif + + if( iPageSize == -1) + { + // If sysconf returned an error, resort to using the default + // page size for the Power architecture. + + iPageSize = 4096; + } + + ui64TotalPhysMem = HIGH_FLMUINT; + ui64AvailPhysMem = HIGH_FLMUINT; + + if( vmgetinfo( &tmpvminfo, VMINFO, sizeof( tmpvminfo)) != -1) + { + ui64TotalPhysMem = tmpvminfo.memsizepgs * iPageSize; + ui64AvailPhysMem = tmpvminfo.numfrb * iPageSize; + } + + #elif defined( FLM_LINUX) + + flmGetLinuxMemInfo( &ui64TotalPhysMem, &ui64AvailPhysMem); + + #else + + long iPageSize = sysconf( _SC_PAGESIZE); + + // Get the amount of memory available to the system + + ui64TotalPhysMem = sysconf(_SC_PHYS_PAGES) * iPageSize; + ui64AvailPhysMem = sysconf(_SC_AVPHYS_PAGES) * iPageSize; + + #endif + + // The process might be limited in the amount of memory it + // can access. + + if( ui64TotalPhysMem > uiProcMemLimit) + { + ui64TotalPhysMem = uiProcMemLimit; + } + + if( ui64TotalPhysMem > uiProcVMemLimit) + { + ui64TotalPhysMem = uiProcVMemLimit; + } + } +#elif defined( FLM_NLM) + { + #ifndef _SC_PHYS_PAGES + #define _SC_PHYS_PAGES 56 + #endif + #ifndef _SCAVPHYS_PAGES + #define _SC_AVPHYS_PAGES 57 + #endif + + long iPageSize = sysconf( _SC_PAGESIZE); + + // Get the amount of memory available to the system + + ui64TotalPhysMem = sysconf(_SC_PHYS_PAGES) * iPageSize; + ui64AvailPhysMem = sysconf(_SC_AVPHYS_PAGES) * iPageSize; + } +#else + rc = RC_SET( NE_FLM_NOT_IMPLEMENTED); +#endif + + if( ui64AvailPhysMem > ui64TotalPhysMem) + { + ui64AvailPhysMem = ui64TotalPhysMem; + } + + *pui64TotalPhysMem = ui64TotalPhysMem; + *pui64AvailPhysMem = ui64AvailPhysMem; + + return( rc); +} + #undef new #undef delete /**************************************************************************** Desc: ****************************************************************************/ -void * F_Base::operator new( +void * F_Object::operator new( FLMSIZET uiSize, const char * pszFile, int iLine) @@ -4287,7 +4558,7 @@ void * F_Base::operator new( /**************************************************************************** Desc: ****************************************************************************/ -void * F_Base::operator new[]( +void * F_Object::operator new[]( FLMSIZET uiSize, const char * pszFile, int iLine) @@ -4309,7 +4580,7 @@ void * F_Base::operator new[]( /**************************************************************************** Desc: ****************************************************************************/ -void F_Base::operator delete( +void F_Object::operator delete( void * ptr) { if( !ptr) @@ -4323,7 +4594,7 @@ void F_Base::operator delete( /**************************************************************************** Desc: ****************************************************************************/ -void F_Base::operator delete( +void F_Object::operator delete( void * ptr, const char *, // file int) // line @@ -4339,7 +4610,7 @@ void F_Base::operator delete( /**************************************************************************** Desc: ****************************************************************************/ -void F_Base::operator delete[]( +void F_Object::operator delete[]( void * ptr, const char *, // file int) // line diff --git a/ftk/src/ftkmfh.cpp b/ftk/src/ftkmfh.cpp index 08dd569..84cd146 100644 --- a/ftk/src/ftkmfh.cpp +++ b/ftk/src/ftkmfh.cpp @@ -41,7 +41,7 @@ typedef struct /**************************************************************************** Desc: ****************************************************************************/ -class F_MultiFileHdl : public IF_MultiFileHdl, public F_Base +class F_MultiFileHdl : public IF_MultiFileHdl { public: @@ -130,8 +130,8 @@ private: // Delete the lock file f_strcpy( szTmpPath, pszBasePath); - gv_pFileSystem->pathAppend( szTmpPath, "64.LCK"); - gv_pFileSystem->deleteFile( szTmpPath); + pFileSystem->pathAppend( szTmpPath, "64.LCK"); + pFileSystem->deleteFile( szTmpPath); } #endif } @@ -152,11 +152,12 @@ private: FLMUINT uiFileNum, char * pszPath) { - char szFileName[ 13]; + char szFileName[ 13]; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); f_strcpy( pszPath, m_szPath); formatFileNum( uiFileNum, szFileName); - gv_pFileSystem->pathAppend( pszPath, szFileName); + pFileSystem->pathAppend( pszPath, szFileName); } FINLINE FLMUINT getFileNum( @@ -230,10 +231,11 @@ Desc: Closes all data files associated with the object void F_MultiFileHdl::close( FLMBOOL bDelete) { - FLMUINT uiLoop; - IF_DirHdl * pDir = NULL; - char szTmpPath[ F_PATH_MAX_SIZE]; - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + FLMUINT uiLoop; + IF_DirHdl * pDir = NULL; + char szTmpPath[ F_PATH_MAX_SIZE]; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( !m_bOpen) { @@ -259,35 +261,29 @@ void F_MultiFileHdl::close( if( bDelete) { - if( RC_OK( gv_pFileSystem->openDir( + if( RC_OK( pFileSystem->openDir( m_szPath, "*.64", &pDir))) { - /* - Remove all data files - */ + // Remove all data files for( rc = pDir->next(); !RC_BAD( rc) ; rc = pDir->next()) { pDir->currentItemPath( szTmpPath); f_assert( f_strstr( szTmpPath, ".64") != 0); - (void)gv_pFileSystem->deleteFile( szTmpPath); + (void)pFileSystem->deleteFile( szTmpPath); } pDir->Release(); pDir = NULL; } - /* - Release and delete the lock file - */ + // Release and delete the lock file (void)releaseLockFile( m_szPath, TRUE); - /* - Remove the directory - */ + // Remove the directory - (void)gv_pFileSystem->removeDir( m_szPath); + (void)pFileSystem->removeDir( m_szPath); } else { @@ -301,9 +297,10 @@ Desc: Removes a 64-bit file RCODE F_MultiFileHdl::deleteMultiFile( const char * pszPath) { - IF_DirHdl * pDir = NULL; - char szTmpPath[ F_PATH_MAX_SIZE]; - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + IF_DirHdl * pDir = NULL; + char szTmpPath[ F_PATH_MAX_SIZE]; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); // Can't use this handle to delete something if we already // have a file open. @@ -316,19 +313,17 @@ RCODE F_MultiFileHdl::deleteMultiFile( return( RC_SET_AND_ASSERT( NE_FLM_FAILURE)); } - if( RC_BAD( rc = gv_pFileSystem->doesFileExist( pszPath))) + if( RC_BAD( rc = pFileSystem->doesFileExist( pszPath))) { goto Exit; } - if( !gv_pFileSystem->isDir( pszPath)) + if( !pFileSystem->isDir( pszPath)) { - /* - If the path specifies a single file rather than a - 64-bit directory, just go ahead and delete the file. - */ + // If the path specifies a single file rather than a + // 64-bit directory, just go ahead and delete the file. - rc = gv_pFileSystem->deleteFile( pszPath); + rc = pFileSystem->deleteFile( pszPath); goto Exit; } @@ -337,17 +332,15 @@ RCODE F_MultiFileHdl::deleteMultiFile( goto Exit; } - if( RC_OK( gv_pFileSystem->openDir( pszPath, "*.64", &pDir))) + if( RC_OK( pFileSystem->openDir( pszPath, "*.64", &pDir))) { - /* - Remove all data files - */ + // Remove all data files for( rc = pDir->next(); !RC_BAD( rc) ; rc = pDir->next()) { pDir->currentItemPath( szTmpPath); f_assert( f_strstr( szTmpPath, ".64") != 0); - (void)gv_pFileSystem->deleteFile( szTmpPath); + (void)pFileSystem->deleteFile( szTmpPath); } pDir->Release(); @@ -355,17 +348,13 @@ RCODE F_MultiFileHdl::deleteMultiFile( rc = NE_FLM_OK; } - /* - Release and delete the lock file - */ + // Release and delete the lock file (void)releaseLockFile( pszPath, TRUE); - /* - Remove the directory - */ + // Remove the directory - (void)gv_pFileSystem->removeDir( pszPath); + (void)pFileSystem->removeDir( pszPath); Exit: @@ -380,8 +369,9 @@ Desc: Creates a new 64-bit "file" RCODE F_MultiFileHdl::create( const char * pszPath) { - FLMBOOL bCreatedDir = FALSE; - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + FLMBOOL bCreatedDir = FALSE; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( m_bOpen) { @@ -389,7 +379,7 @@ RCODE F_MultiFileHdl::create( goto Exit; } - if( RC_BAD( rc = gv_pFileSystem->createDir( pszPath))) + if( RC_BAD( rc = pFileSystem->createDir( pszPath))) { goto Exit; } @@ -397,18 +387,14 @@ RCODE F_MultiFileHdl::create( f_strcpy( m_szPath, pszPath); bCreatedDir = TRUE; - /* - Create the lock file - */ + // Create the lock file if( RC_BAD( rc = createLockFile( m_szPath))) { goto Exit; } - /* - Initialize the EOF to 0 and set the state to open - */ + // Initialize the EOF to 0 and set the state to open m_ui64EOF = 0; m_bOpen = TRUE; @@ -424,7 +410,7 @@ Exit: (void)releaseLockFile( m_szPath, TRUE); if( bCreatedDir) { - (void)gv_pFileSystem->removeDir( m_szPath); + (void)pFileSystem->removeDir( m_szPath); } } @@ -435,18 +421,19 @@ Exit: Desc: Creates a new 64-bit file with a unique, generated name ****************************************************************************/ RCODE F_MultiFileHdl::createUnique( - const char * pszPath, // Directory where the file is to be created - const char * pszFileExtension) // Extension to be used on the new file. + const char * pszPath, // Directory where the file is to be created + const char * pszFileExtension) // Extension to be used on the new file. { - FLMUINT uiCount; - FLMBOOL bModext = TRUE; - FLMBOOL bCreatedDir = FALSE; - FLMUINT uiBaseTime = 0; - FLMBYTE ucHighByte = 0; - char szDirName[ F_FILENAME_SIZE]; - char szTmpPath[ F_PATH_MAX_SIZE]; - char szBasePath[ F_PATH_MAX_SIZE]; - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + FLMUINT uiCount; + FLMBOOL bModext = TRUE; + FLMBOOL bCreatedDir = FALSE; + FLMUINT uiBaseTime = 0; + FLMBYTE ucHighByte = 0; + char szDirName[ F_FILENAME_SIZE]; + char szTmpPath[ F_PATH_MAX_SIZE]; + char szBasePath[ F_PATH_MAX_SIZE]; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( m_bOpen) { @@ -478,12 +465,12 @@ RCODE F_MultiFileHdl::createUnique( szDirName[ 0] = '\0'; do { - gv_pFileSystem->pathCreateUniqueName( &uiBaseTime, szDirName, pszFileExtension, - &ucHighByte, bModext); + pFileSystem->pathCreateUniqueName( &uiBaseTime, szDirName, + pszFileExtension, &ucHighByte, bModext); f_strcpy( szTmpPath, szBasePath); - gv_pFileSystem->pathAppend( szTmpPath, szDirName); - rc = gv_pFileSystem->createDir( szTmpPath); + pFileSystem->pathAppend( szTmpPath, szDirName); + rc = pFileSystem->createDir( szTmpPath); } while ((rc != NE_FLM_OK) && (uiCount++ < 20)); if( RC_BAD( rc)) @@ -522,7 +509,7 @@ Exit: if( bCreatedDir) { - (void)gv_pFileSystem->removeDir( m_szPath); + (void)pFileSystem->removeDir( m_szPath); } } @@ -535,11 +522,12 @@ Desc: Opens an existing 64-bit file RCODE F_MultiFileHdl::open( const char * pszPath) { - IF_DirHdl * pDir = NULL; - FLMUINT uiTmp; - FLMUINT uiHighFileNum = 0; - FLMUINT64 ui64HighOffset = 0; - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); + IF_DirHdl * pDir = NULL; + FLMUINT uiTmp; + FLMUINT uiHighFileNum = 0; + FLMUINT64 ui64HighOffset = 0; if( m_bOpen) { @@ -547,8 +535,8 @@ RCODE F_MultiFileHdl::open( goto Exit; } - if( RC_BAD( gv_pFileSystem->doesFileExist( pszPath)) || - !gv_pFileSystem->isDir( pszPath)) + if( RC_BAD( pFileSystem->doesFileExist( pszPath)) || + !pFileSystem->isDir( pszPath)) { rc = RC_SET( NE_FLM_IO_PATH_NOT_FOUND); goto Exit; @@ -569,8 +557,7 @@ RCODE F_MultiFileHdl::open( Need to determine the current EOF */ - if( RC_BAD( rc = gv_pFileSystem->openDir( - m_szPath, (char *)"*.64", &pDir))) + if( RC_BAD( rc = pFileSystem->openDir( m_szPath, (char *)"*.64", &pDir))) { goto Exit; } @@ -824,14 +811,15 @@ Exit: Desc: Returns the requested file handle ****************************************************************************/ RCODE F_MultiFileHdl::getFileHdl( - FLMUINT uiFileNum, - FLMBOOL bGetForWrite, - IF_FileHdl ** ppFileHdl) + FLMUINT uiFileNum, + FLMBOOL bGetForWrite, + IF_FileHdl ** ppFileHdl) { - FLMUINT uiSlot; - IF_FileHdl * pTmpHdl; - char szPath[ F_PATH_MAX_SIZE]; - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); + FLMUINT uiSlot; + IF_FileHdl * pTmpHdl; + char szPath[ F_PATH_MAX_SIZE]; f_assert( m_bOpen); @@ -857,12 +845,12 @@ RCODE F_MultiFileHdl::getFileHdl( if( !pTmpHdl) { dataFilePath( uiFileNum, szPath); - if( RC_BAD( rc = gv_pFileSystem->openFile( szPath, + if( RC_BAD( rc = pFileSystem->openFile( szPath, FLM_IO_RDWR, &pTmpHdl))) { if( rc == NE_FLM_IO_PATH_NOT_FOUND && bGetForWrite) { - if( RC_BAD( rc = gv_pFileSystem->createFile( szPath, + if( RC_BAD( rc = pFileSystem->createFile( szPath, FLM_IO_RDWR, &pTmpHdl))) { goto Exit; @@ -953,15 +941,16 @@ Desc: This routine obtains exclusive access to a 64-bit file by creating 64-bit file is open. ****************************************************************************/ RCODE F_MultiFileHdl::createLockFile( - const char * pszBasePath) + const char * pszBasePath) { - RCODE rc = NE_FLM_OK; - char szLockPath [F_PATH_MAX_SIZE]; - F_FileHdl * pLockFileHdl = NULL; - FLMUINT uiIoFlags = FLM_IO_RDWR | FLM_IO_EXCL | FLM_IO_SH_DENYRW; + RCODE rc = NE_FLM_OK; + char szLockPath [F_PATH_MAX_SIZE]; + F_FileHdl * pLockFileHdl = NULL; + FLMUINT uiIoFlags = FLM_IO_RDWR | FLM_IO_EXCL | FLM_IO_SH_DENYRW; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); f_strcpy( szLockPath, pszBasePath); - gv_pFileSystem->pathAppend( szLockPath, "64.LCK"); + pFileSystem->pathAppend( szLockPath, "64.LCK"); // Attempt to create the lock file. If it fails, the lock file // may have been left because of a crash. Hence, we first try @@ -984,7 +973,7 @@ RCODE F_MultiFileHdl::createLockFile( if( RC_BAD( pLockFileHdl->create( szLockPath, uiIoFlags))) { #ifndef FLM_UNIX - if (RC_BAD( gv_pFileSystem->deleteFile( szLockPath))) + if (RC_BAD( pFileSystem->deleteFile( szLockPath))) { rc = RC_SET( NE_FLM_IO_ACCESS_DENIED); goto Exit; @@ -1051,3 +1040,13 @@ Exit: return( rc); } + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI F_MultiFileHdl::getPath( + char * pszPath) +{ + f_strcpy( pszPath, m_szPath); + return( NE_FLM_OK); +} diff --git a/ftk/src/ftkmisc.cpp b/ftk/src/ftkmisc.cpp index 1b5776e..234ebe2 100644 --- a/ftk/src/ftkmisc.cpp +++ b/ftk/src/ftkmisc.cpp @@ -25,25 +25,27 @@ #include "ftksys.h" -FLMUINT gv_uiStartupCount = 0; -FLMUINT gv_uiSerialInitCount = 0; -F_MUTEX gv_hSerialMutex = F_MUTEX_NULL; -FLMBOOL gv_bOkToDoAsyncWrites = TRUE; -FLMUINT gv_uiMaxFileSize = FLM_MAXIMUM_FILE_SIZE; -IF_FileSystem * gv_pFileSystem = NULL; -IF_RandomGenerator * gv_pSerialRandom = NULL; -IF_ThreadMgr * gv_pThreadMgr = NULL; +static FLMUINT gv_uiStartupCount = 0; +static FLMUINT gv_uiSerialInitCount = 0; +static F_MUTEX gv_hSerialMutex = F_MUTEX_NULL; +static IF_RandomGenerator * gv_pSerialRandom = NULL; +static FLMUINT32 * gv_pui32CRCTbl = NULL; +static IF_ThreadMgr * gv_pThreadMgr = NULL; +static IF_FileSystem * gv_pFileSystem = NULL; #ifdef FLM_LINUX -FLMUINT gv_uiLinuxMajorVer = 0; -FLMUINT gv_uiLinuxMinorVer = 0; -FLMUINT gv_uiLinuxRevision = 0; +static FLMUINT gv_uiLinuxMajorVer = 0; +static FLMUINT gv_uiLinuxMinorVer = 0; +static FLMUINT gv_uiLinuxRevision = 0; #endif FSTATIC RCODE f_initSerialNumberGenerator( void); FSTATIC void f_freeSerialNumberGenerator( void); +FSTATIC RCODE f_initCRCTable( + FLMUINT32 ** ppui32CRCTbl); + #ifdef FLM_AIX #ifndef nsleep extern "C" @@ -82,6 +84,11 @@ RCODE FLMAPI ftkStartup( void) goto Exit; } + if( RC_BAD( rc = f_initCRCTable( &gv_pui32CRCTbl))) + { + goto Exit; + } + if( RC_BAD( rc = f_checkErrorCodeTables())) { goto Exit; @@ -138,6 +145,11 @@ void FLMAPI ftkShutdown( void) gv_pFileSystem = NULL; } + if( gv_pui32CRCTbl) + { + f_free( &gv_pui32CRCTbl); + } + f_freeSerialNumberGenerator(); f_memoryCleanup(); } @@ -327,10 +339,10 @@ Exit: /**************************************************************************** Desc: Generates a table of remainders for each 8-bit byte. The resulting - table is used by flmUpdateCRC to calculate a CRC value. The table - must be freed via a call to f_freeCRCTable. + table is used by f_updateCRC to calculate a CRC value. The table + must be freed via a call to f_free. *****************************************************************************/ -RCODE f_initCRCTable( +FSTATIC RCODE f_initCRCTable( FLMUINT32 ** ppui32CRCTbl) { RCODE rc = NE_FLM_OK; @@ -393,19 +405,19 @@ Desc: Computes the CRC of the passed-in data buffer. Multiple calls can *pui32CRC should be initialized to 0xFFFFFFFF and the ones complement of the resulting CRC should be computed. *****************************************************************************/ -void f_updateCRC( - FLMUINT32 * pui32CRCTbl, - FLMBYTE * pucBlk, - FLMUINT uiBlkSize, - FLMUINT32 * pui32CRC) +void FLMAPI f_updateCRC( + const void * pvBuffer, + FLMUINT uiCount, + FLMUINT32 * pui32CRC) { - FLMUINT32 ui32CRC = *pui32CRC; - FLMUINT uiLoop; + FLMBYTE * pucBuffer = (FLMBYTE *)pvBuffer; + FLMUINT32 ui32CRC = *pui32CRC; + FLMUINT uiLoop; - for( uiLoop = 0; uiLoop < uiBlkSize; uiLoop++) + for( uiLoop = 0; uiLoop < uiCount; uiLoop++) { - ui32CRC = (ui32CRC >> 8) ^ pui32CRCTbl[ - ((FLMBYTE)(ui32CRC & 0x000000FF)) ^ pucBlk[ uiLoop]]; + ui32CRC = (ui32CRC >> 8) ^ gv_pui32CRCTbl[ + ((FLMBYTE)(ui32CRC & 0x000000FF)) ^ pucBuffer[ uiLoop]]; } *pui32CRC = ui32CRC; @@ -605,3 +617,404 @@ void FLMAPI f_qsortUINTSwap( puiArray[ uiPos1] = puiArray[ uiPos2]; puiArray[ uiPos2] = uiTmp; } + +/**************************************************************************** +Desc: +****************************************************************************/ +void * FLMAPI f_memcpy( + void * pvDest, + const void * pvSrc, + FLMSIZET iSize) +{ + if( iSize == 1) + { + *((FLMBYTE *)pvDest) = *((FLMBYTE *)pvSrc); + return( pvDest); + } + else + { + return( memcpy( pvDest, pvSrc, iSize)); + } +} + +/**************************************************************************** +Desc: +****************************************************************************/ +void * FLMAPI f_memmove( + void * pvDest, + const void * pvSrc, + FLMSIZET uiLength) +{ + return( memmove( pvDest, pvSrc, uiLength)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +void * FLMAPI f_memset( + void * pvDest, + unsigned char ucByte, + FLMSIZET uiLength) +{ + return( memset( pvDest, ucByte, uiLength)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMINT FLMAPI f_memcmp( + const void * pvMem1, + const void * pvMem2, + FLMSIZET uiLength) +{ + return( memcmp( pvMem1, pvMem2, uiLength)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +char * FLMAPI f_strcpy( + char * pszDest, + const char * pszSrc) +{ + return( strcpy( pszDest, pszSrc)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +char * FLMAPI f_strncpy( + char * pszDest, + const char * pszSrc, + FLMSIZET uiLength) +{ + return( strncpy( pszDest, pszSrc, uiLength)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMUINT FLMAPI f_strlen( + const char * pszStr) +{ + return( strlen( pszStr)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMINT FLMAPI f_strcmp( + const char * pszStr1, + const char * pszStr2) +{ + return( strcmp( pszStr1, pszStr2)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +FLMINT FLMAPI f_stricmp( + const char * pszStr1, + const char * pszStr2) +{ + return( _stricmp( pszStr1, pszStr2)); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMINT FLMAPI f_strncmp( + const char * pszStr1, + const char * pszStr2, + FLMSIZET uiLength) +{ + return( strncmp( pszStr1, pszStr2, uiLength)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +FLMINT FLMAPI f_strnicmp( + const char * pszStr1, + const char * pszStr2, + FLMSIZET uiLength) +{ + return( _strnicmp( pszStr1, pszStr2, uiLength)); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +char * FLMAPI f_strcat( + char * pszDest, + const char * pszSrc) +{ + return( strcat( pszDest, pszSrc)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +char * FLMAPI f_strncat( + char * pszDest, + const char * pszSrc, + FLMSIZET uiLength) +{ + return( strncat( pszDest, pszSrc, uiLength)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +char * FLMAPI f_strchr( + const char * pszStr, + unsigned char ucByte) +{ + return( strchr( pszStr, ucByte)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +char * FLMAPI f_strrchr( + const char * pszStr, + unsigned char ucByte) +{ + return( strrchr( pszStr, ucByte)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +char * FLMAPI f_strstr( + const char * pszStr1, + const char * pszStr2) +{ + return( strstr( pszStr1, pszStr2)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +char * FLMAPI f_strupr( + char * pszStr) +{ + return( _strupr( pszStr)); +} +#endif + +/********************************************************************** +Desc: +**********************************************************************/ +FLMINT32 FLMAPI f_atomicInc( + FLMATOMIC * piTarget) +{ + #if defined( FLM_NLM) + { + return( (FLMINT32)nlm_AtomicIncrement( (volatile LONG *)piTarget)); + } + #elif defined( FLM_WIN) + { + return( (FLMINT32)InterlockedIncrement( (volatile LONG *)piTarget)); + } + #elif defined( FLM_AIX) + { + return( (FLMINT32)aix_atomic_add( piTarget, 1)); + } + #elif defined( FLM_OSX) + { + return( (FLMINT32)OSAtomicIncrement32( (int32_t *)piTarget)); + } + #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) + { + return( sparc_atomic_add_32( piTarget, 1)); + } + #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) + { + FLMINT32 i32Tmp; + + __asm__ __volatile__ ( + "lock;" + "xaddl %0, %1" + : "=r" (i32Tmp), "=m" (*piTarget) + : "0" (1), "m" (*piTarget)); + + return( i32Tmp + 1); + } + #elif defined( FLM_UNIX) + return( posix_atomic_add_32( piTarget, 1)); + #else + #error Atomic operations are not supported + #endif +} + +/********************************************************************** +Desc: +**********************************************************************/ +FLMINT32 FLMAPI f_atomicDec( + FLMATOMIC * piTarget) +{ + #if defined( FLM_NLM) + { + return( (FLMINT32)nlm_AtomicDecrement( (volatile LONG *)piTarget)); + } + #elif defined( FLM_WIN) + { + return( (FLMINT32)InterlockedDecrement( (volatile LONG *)piTarget)); + } + #elif defined( FLM_AIX) + { + return( (FLMINT32)aix_atomic_add( piTarget, -1)); + } + #elif defined( FLM_OSX) + { + return( (FLMINT32)OSAtomicDecrement32( (int32_t *)piTarget)); + } + #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) + { + return( sparc_atomic_add_32( piTarget, -1)); + } + #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) + { + FLMINT32 i32Tmp; + + __asm__ __volatile__ ( + "lock;" + "xaddl %0, %1" + : "=r" (i32Tmp), "=m" (*piTarget) + : "0" (-1), "m" (*piTarget)); + + return( i32Tmp - 1); + } + #elif defined( FLM_UNIX) + return( posix_atomic_add_32( piTarget, -1)); + #else + #error Atomic operations are not supported + #endif +} + +/********************************************************************** +Desc: +**********************************************************************/ +FLMINT32 FLMAPI f_atomicExchange( + FLMATOMIC * piTarget, + FLMINT32 i32NewVal) +{ + #if defined( FLM_NLM) + { + return( (FLMINT32)nlm_AtomicExchange( + (volatile LONG *)piTarget, i32NewVal)); + } + #elif defined( FLM_WIN) + { + return( (FLMINT32)InterlockedExchange( (volatile LONG *)piTarget, + i32NewVal)); + } + #elif defined( FLM_AIX) + { + int iOldVal; + + for( ;;) + { + iOldVal = (int)*piTarget; + + if( compare_and_swap( (int *)piTarget, &iOldVal, i32NewVal)) + { + break; + } + } + + return( (FLMINT32)iOldVal); + } + #elif defined( FLM_OSX) + { + int32_t iOldVal; + + for( ;;) + { + iOldVal = (int32_t)*piTarget; + + if( OSAtomicCompareAndSwap32( iOldVal, i32NewVal, + (int32_t *)piTarget)) + { + break; + } + } + + return( (FLMINT32)iOldVal); + } + #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) + { + return( sparc_atomic_xchg_32( piTarget, i32NewVal)); + } + #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) + { + FLMINT32 i32OldVal; + + __asm__ __volatile__ ( + "1: lock;" + " cmpxchgl %2, %0;" + " jne 1b" + : "=m" (*piTarget), "=a" (i32OldVal) + : "r" (i32NewVal), "m" (*piTarget), "a" (*piTarget)); + + return( i32OldVal); + } + #elif defined( FLM_UNIX) + return( posix_atomic_xchg_32( piTarget, i32NewVal)); + #else + #error Atomic operations are not supported + #endif +} + +/********************************************************************** +Desc: +**********************************************************************/ +FLMINT FLMAPI F_Object::getRefCount( void) +{ + return( m_refCnt); +} + +/********************************************************************** +Desc: +**********************************************************************/ +FLMINT FLMAPI F_Object::AddRef( void) +{ + return( ++m_refCnt); +} + +/********************************************************************** +Desc: +**********************************************************************/ +FLMINT FLMAPI F_Object::Release( void) +{ + FLMINT iRefCnt = --m_refCnt; + + if( !iRefCnt) + { + delete this; + } + + return( iRefCnt); +} + +/********************************************************************** +Desc: +**********************************************************************/ +IF_FileSystem * f_getFileSysPtr( void) +{ + return( gv_pFileSystem); +} + +/********************************************************************** +Desc: +**********************************************************************/ +IF_ThreadMgr * f_getThreadMgrPtr( void) +{ + return( gv_pThreadMgr); +} diff --git a/ftk/src/ftkntab.cpp b/ftk/src/ftkntab.cpp index c7623a5..a609b85 100644 --- a/ftk/src/ftkntab.cpp +++ b/ftk/src/ftkntab.cpp @@ -24,6 +24,7 @@ //------------------------------------------------------------------------------ #include "ftksys.h" +#if 0 #define MAX_ELEMENTS_TO_LOAD 0xFFFF #define MAX_ATTRIBUTES_TO_LOAD 0xFFFF @@ -63,7 +64,7 @@ FSTATIC void sortTagTbl( /**************************************************************************** Desc: Class for name/number lookup. ****************************************************************************/ -class F_NameTable : public IF_NameTable, public F_Base +class F_NameTable : public IF_NameTable { public: @@ -1916,3 +1917,4 @@ FLMINT FLMAPI F_NameTable::Release( void) return( iRefCnt); } +#endif diff --git a/ftk/src/ftkprntf.cpp b/ftk/src/ftkprntf.cpp index a639647..f2c72b5 100644 --- a/ftk/src/ftkprntf.cpp +++ b/ftk/src/ftkprntf.cpp @@ -767,3 +767,20 @@ FLMINT FLMAPI f_sprintf( return( iLen); } + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMINT FLMAPI f_printf( + const char * pszFormat, + ...) +{ + FLMINT iLen; + va_list args; + + va_start(args, pszFormat); + iLen = vprintf( pszFormat, args); + va_end(args); + + return( iLen); +} diff --git a/ftk/src/ftkrand.cpp b/ftk/src/ftkrand.cpp index 74c538f..a39c32d 100644 --- a/ftk/src/ftkrand.cpp +++ b/ftk/src/ftkrand.cpp @@ -66,7 +66,7 @@ implementation is correct. /**************************************************************************** Desc: ****************************************************************************/ -class F_RandomGenerator : public IF_RandomGenerator, public F_Base +class F_RandomGenerator : public IF_RandomGenerator { public: diff --git a/ftk/src/ftkrset.cpp b/ftk/src/ftkrset.cpp index 869a7a5..3493f8e 100644 --- a/ftk/src/ftkrset.cpp +++ b/ftk/src/ftkrset.cpp @@ -130,7 +130,7 @@ typedef struct /**************************************************************************** Desc: ****************************************************************************/ -class F_ResultSetBlk : public F_RefCount, public F_Base +class F_ResultSetBlk : public F_Object { public: @@ -338,7 +338,7 @@ private: /***************************************************************************** Desc: *****************************************************************************/ -class F_ResultSet : public IF_ResultSet, public F_Base +class F_ResultSet : public IF_ResultSet { public: @@ -534,7 +534,8 @@ private: /***************************************************************************** Desc: *****************************************************************************/ -class F_BtResultSet : public IF_BtResultSet, public F_Base +#if 0 +class F_BtResultSet : public IF_BtResultSet { public: @@ -629,6 +630,7 @@ private: IF_Btree * m_pBtree; IF_ResultSetCompare * m_pCompare; }; +#endif /***************************************************************************** Desc: @@ -913,7 +915,7 @@ RCODE FLMAPI F_ResultSet::setupResultSet( { f_strcpy( m_szIoFilePath1, m_szIoDefaultPath); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( + if( RC_BAD( rc = f_getFileSysPtr()->pathAppend( m_szIoFilePath1, pszInputFileName))) { goto Exit; @@ -3866,6 +3868,7 @@ Exit: /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::addEntry( FLMBYTE * pucKey, FLMUINT uiKeyLength, @@ -3893,10 +3896,12 @@ Exit: return( rc); } +#endif /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::modifyEntry( FLMBYTE * pucKey, FLMUINT uiKeyLength, @@ -3917,10 +3922,12 @@ Exit: return( rc); } +#endif /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::deleteEntry( FLMBYTE * pucKey, FLMUINT uiKeyLength) @@ -3939,10 +3946,12 @@ Exit: return( rc); } +#endif /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::findEntry( FLMBYTE * pucKey, FLMUINT uiKeyBufLen, @@ -3979,10 +3988,12 @@ Exit: return( rc); } +#endif /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::getCurrent( FLMBYTE * pucKey, FLMUINT uiKeyLength, @@ -4004,10 +4015,12 @@ Exit: return( rc); } +#endif /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::getNext( FLMBYTE * pucKey, FLMUINT uiKeyBufLen, @@ -4039,10 +4052,12 @@ Exit: return( rc); } +#endif /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::getPrev( FLMBYTE * pucKey, FLMUINT uiKeyBufLen, @@ -4074,10 +4089,12 @@ Exit: return( rc); } +#endif /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::getFirst( FLMBYTE * pucKey, FLMUINT uiKeyBufLen, @@ -4110,10 +4127,12 @@ Exit: return( rc); } +#endif /**************************************************************************** Desc: ****************************************************************************/ +#if 0 RCODE F_BtResultSet::getLast( FLMBYTE * pucKey, FLMUINT uiKeyBufLen, @@ -4145,3 +4164,18 @@ Exit: return( rc); } +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmAllocResultSet( + IF_ResultSet ** ppResultSet) +{ + if( (*ppResultSet = f_new F_ResultSet) == NULL) + { + return( RC_SET( NE_FLM_MEM)); + } + + return( NE_FLM_OK); +} diff --git a/ftk/src/ftksem.cpp b/ftk/src/ftksem.cpp index eb08524..43a845a 100644 --- a/ftk/src/ftksem.cpp +++ b/ftk/src/ftksem.cpp @@ -159,6 +159,38 @@ void FLMAPI f_mutexDestroy( } #endif +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_UNIX +void FLMAPI f_mutexLock( + F_MUTEX hMutex) +{ + (void)pthread_mutex_lock( (pthread_mutex_t *)hMutex); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_UNIX +void FLMAPI f_mutexUnlock( + F_MUTEX hMutex) +{ + (void)pthread_mutex_unlock( (pthread_mutex_t *)hMutex); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_UNIX +void FLMAPI f_assertMutexLocked( + F_MUTEX) +{ +} +#endif + /**************************************************************************** Desc: Initializes a semaphore handle on UNIX ****************************************************************************/ @@ -401,11 +433,258 @@ void FLMAPI f_semSignal( #endif /**************************************************************************** -Desc: Get the lock on a semaphore - p operation +Desc: ****************************************************************************/ -#if defined( FLM_WATCOM_NLM) -int gv_DummyFtksem(void) +#ifdef FLM_NLM +RCODE FLMAPI f_mutexCreate( + F_MUTEX * phMutex) { - return( 0); + if( (*phMutex = (F_MUTEX)kMutexAlloc( (BYTE *)"NOVDB")) == F_MUTEX_NULL) + { + return RC_SET( NE_FLM_MEM); + } + + return NE_FLM_OK; +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_NLM +void FLMAPI f_mutexDestroy( + F_MUTEX * phMutex) +{ + if (*phMutex != F_MUTEX_NULL) + { + if( kMutexFree( (MUTEX)(*phMutex))) + { + f_assert( 0); + } + + *phMutex = F_MUTEX_NULL; + } +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_NLM +void FLMAPI f_mutexLock( + F_MUTEX hMutex) +{ + (void)kMutexLock( (MUTEX)hMutex); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_NLM +void FLMAPI f_mutexUnlock( + F_MUTEX hMutex) +{ + (void)kMutexUnlock( (MUTEX)hMutex); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_NLM +void FLMAPI f_assertMutexLocked( + F_MUTEX) +{ +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_NLM +RCODE FLMAPI f_semCreate( + F_SEM * phSem) +{ + if( (*phSem = (F_SEM)kSemaphoreAlloc( (BYTE *)"NOVDB", 0)) == F_SEM_NULL) + { + return RC_SET( NE_FLM_MEM); + } + + return NE_FLM_OK; +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_NLM +void FLMAPI f_semDestroy( + F_SEM * phSem) +{ + if (*phSem != F_SEM_NULL) + { + (void)kSemaphoreFree( (SEMAPHORE)(*phSem)); + *phSem = F_SEM_NULL; + } +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_NLM +RCODE FLMAPI f_semWait( + F_SEM hSem, + FLMUINT uiTimeout) +{ + RCODE rc = NE_FLM_OK; + + if( uiTimeout == F_SEM_WAITFOREVER) + { + if( kSemaphoreWait( (SEMAPHORE)hSem) != 0) + { + rc = RC_SET( NE_FLM_ERROR_WAITING_ON_SEMPAHORE); + } + } + else + { + if( kSemaphoreTimedWait( (SEMAPHORE)hSem, (UINT)uiTimeout) != 0) + { + rc = RC_SET( NE_FLM_ERROR_WAITING_ON_SEMPAHORE); + } + } + + return( rc); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_NLM +void FLMAPI f_semSignal( + F_SEM hSem) +{ + (void)kSemaphoreSignal( (SEMAPHORE)hSem); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +void FLMAPI f_mutexLock( + F_MUTEX hMutex) +{ + F_INTERLOCK * pInterlock = (F_INTERLOCK *)hMutex; + + while( f_atomicExchange( &pInterlock->locked, 1) != 0) + { +#ifdef FLM_DEBUG + f_atomicInc( &(((F_INTERLOCK *)hMutex)->waitCount)); +#endif + Sleep( 0); + } + +#ifdef FLM_DEBUG + f_assert( ((F_INTERLOCK *)hMutex)->uiThreadId == 0); + ((F_INTERLOCK *)hMutex)->uiThreadId = _threadid; + f_atomicInc( &(((F_INTERLOCK *)hMutex)->lockedCount)); +#endif +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +void FLMAPI f_mutexUnlock( + F_MUTEX hMutex) +{ + f_assert( ((F_INTERLOCK *)hMutex)->locked == 1); +#ifdef FLM_DEBUG + f_assert( ((F_INTERLOCK *)hMutex)->uiThreadId == _threadid); + ((F_INTERLOCK *)hMutex)->uiThreadId = 0; +#endif + f_atomicExchange( &(((F_INTERLOCK *)hMutex)->locked), 0); +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +void FLMAPI f_assertMutexLocked( + F_MUTEX hMutex) +{ +#ifdef FLM_DEBUG + f_assert( ((F_INTERLOCK *)hMutex)->locked == 1); + f_assert( ((F_INTERLOCK *)hMutex)->uiThreadId == _threadid); +#else + F_UNREFERENCED_PARM( hMutex); +#endif +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +RCODE FLMAPI f_semCreate( + F_SEM * phSem) +{ + if( (*phSem = CreateSemaphore( (LPSECURITY_ATTRIBUTES)NULL, + 0, 10000, NULL )) == NULL) + { + return( RC_SET( NE_FLM_COULD_NOT_CREATE_SEMAPHORE)); + } + + return NE_FLM_OK; +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +void FLMAPI f_semDestroy( + F_SEM * phSem) +{ + if (*phSem != F_SEM_NULL) + { + CloseHandle( *phSem); + *phSem = F_SEM_NULL; + } +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +RCODE FLMAPI f_semWait( + F_SEM hSem, + FLMUINT uiTimeout) +{ + if( WaitForSingleObject( hSem, uiTimeout ) == WAIT_OBJECT_0) + { + return( NE_FLM_OK); + } + else + { + return( RC_SET( NE_FLM_ERROR_WAITING_ON_SEMPAHORE)); + } +} +#endif + +/**************************************************************************** +Desc: +****************************************************************************/ +#ifdef FLM_WIN +void FLMAPI f_semSignal( + F_SEM hSem) +{ + (void)ReleaseSemaphore( hSem, 1, NULL); } #endif diff --git a/ftk/src/ftkstrm.cpp b/ftk/src/ftkstrm.cpp index 77f7dce..f126037 100644 --- a/ftk/src/ftkstrm.cpp +++ b/ftk/src/ftkstrm.cpp @@ -38,7 +38,7 @@ /**************************************************************************** Desc: Decodes an ASCII base64 stream to binary ****************************************************************************/ -class F_Base64DecoderIStream : public F_IStream +class F_Base64DecoderIStream : public IF_IStream { public: @@ -437,6 +437,436 @@ private: unsigned long m_ulRemoteAddr; }; +/***************************************************************************** +Desc: +******************************************************************************/ +RCODE FLMAPI FlmAllocBufferIStream( + IF_BufferIStream ** ppIStream) +{ + if( (*ppIStream = f_new F_BufferIStream) == NULL) + { + return( RC_SET( NE_FLM_MEM)); + } + + return( NE_FLM_OK); +} + +/***************************************************************************** +Desc: +******************************************************************************/ +RCODE FLMAPI FlmOpenBufferIStream( + const char * pucBuffer, + FLMUINT uiLength, + IF_PosIStream ** ppIStream) +{ + RCODE rc = NE_FLM_OK; + F_BufferIStream * pIStream = NULL; + + if( (pIStream = f_new F_BufferIStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pIStream->open( pucBuffer, uiLength))) + { + goto Exit; + } + + *ppIStream = pIStream; + pIStream = NULL; + +Exit: + + if( pIStream) + { + pIStream->Release(); + } + + return( rc); +} + +/***************************************************************************** +Desc: +******************************************************************************/ +RCODE FLMAPI FlmOpenBase64EncoderIStream( + IF_IStream * pSourceIStream, + FLMBOOL bLineBreaks, + IF_IStream ** ppIStream) +{ + RCODE rc = NE_FLM_OK; + F_Base64EncoderIStream * pIStream = NULL; + + if( (pIStream = f_new F_Base64EncoderIStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pIStream->open( pSourceIStream, bLineBreaks))) + { + goto Exit; + } + + *ppIStream = pIStream; + pIStream = NULL; + +Exit: + + if( pIStream) + { + pIStream->Release(); + } + + return( rc); +} + +/***************************************************************************** +Desc: +******************************************************************************/ +RCODE FLMAPI FlmOpenBase64DecoderIStream( + IF_IStream * pSourceIStream, + IF_IStream ** ppIStream) +{ + RCODE rc = NE_FLM_OK; + F_Base64DecoderIStream * pIStream = NULL; + + if( (pIStream = f_new F_Base64DecoderIStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pIStream->open( pSourceIStream))) + { + goto Exit; + } + + *ppIStream = pIStream; + pIStream = NULL; + +Exit: + + if( pIStream) + { + pIStream->Release(); + } + + return( rc); +} + +/***************************************************************************** +Desc: +******************************************************************************/ +RCODE FLMAPI FlmOpenFileIStream( + const char * pszPath, + IF_PosIStream ** ppIStream) +{ + RCODE rc = NE_FLM_OK; + F_FileIStream * pIStream = NULL; + + if( (pIStream = f_new F_FileIStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pIStream->open( pszPath))) + { + goto Exit; + } + + *ppIStream = pIStream; + pIStream = NULL; + +Exit: + + if( pIStream) + { + pIStream->Release(); + } + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmOpenMultiFileIStream( + const char * pszDirectory, + const char * pszBaseName, + IF_IStream ** ppIStream) +{ + RCODE rc = NE_FLM_OK; + F_MultiFileIStream * pIStream = NULL; + + if( (pIStream = f_new F_MultiFileIStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pIStream->open( pszDirectory, pszBaseName))) + { + goto Exit; + } + + *ppIStream = pIStream; + pIStream = NULL; + +Exit: + + if( pIStream) + { + pIStream->Release(); + } + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmOpenBufferedIStream( + IF_IStream * pSourceIStream, + FLMUINT uiBufferSize, + IF_IStream ** ppIStream) +{ + RCODE rc = NE_FLM_OK; + F_BufferedIStream * pIStream = NULL; + + if( (pIStream = f_new F_BufferedIStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pIStream->open( pSourceIStream, uiBufferSize))) + { + goto Exit; + } + + *ppIStream = pIStream; + pIStream = NULL; + +Exit: + + if( pIStream) + { + pIStream->Release(); + } + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmOpenUncompressingIStream( + IF_IStream * pSourceIStream, + IF_IStream ** ppIStream) +{ + RCODE rc = NE_FLM_OK; + F_UncompressingIStream * pIStream = NULL; + + if( (pIStream = f_new F_UncompressingIStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pIStream->open( pSourceIStream))) + { + goto Exit; + } + + *ppIStream = pIStream; + pIStream = NULL; + +Exit: + + if( pIStream) + { + pIStream->Release(); + } + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmOpenFileOStream( + const char * pszPath, + FLMBOOL bTruncateIfExists, + IF_OStream ** ppOStream) +{ + RCODE rc = NE_FLM_OK; + F_FileOStream * pOStream = NULL; + + if( (pOStream = f_new F_FileOStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pOStream->open( pszPath, bTruncateIfExists))) + { + goto Exit; + } + + *ppOStream = pOStream; + pOStream = NULL; + +Exit: + + if( pOStream) + { + pOStream->Release(); + } + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmOpenMultiFileOStream( + const char * pszDirectory, + const char * pszBaseName, + FLMUINT uiMaxFileSize, + FLMBOOL bOkToOverwrite, + IF_OStream ** ppOStream) +{ + RCODE rc = NE_FLM_OK; + F_MultiFileOStream * pOStream = NULL; + + if( (pOStream = f_new F_MultiFileOStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pOStream->create( pszDirectory, pszBaseName, + uiMaxFileSize, bOkToOverwrite))) + { + goto Exit; + } + + *ppOStream = pOStream; + pOStream = NULL; + +Exit: + + if( pOStream) + { + pOStream->Release(); + } + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmOpenBufferedOStream( + IF_OStream * pDestOStream, + FLMUINT uiBufferSize, + IF_OStream ** ppOStream) +{ + RCODE rc = NE_FLM_OK; + F_BufferedOStream * pOStream = NULL; + + if( (pOStream = f_new F_BufferedOStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pOStream->open( pDestOStream, uiBufferSize))) + { + goto Exit; + } + + *ppOStream = pOStream; + pOStream = NULL; + +Exit: + + if( pOStream) + { + pOStream->Release(); + } + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmOpenCompressingOStream( + IF_OStream * pDestOStream, + IF_OStream ** ppOStream) +{ + RCODE rc = NE_FLM_OK; + F_CompressingOStream * pOStream = NULL; + + if( (pOStream = f_new F_CompressingOStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pOStream->open( pDestOStream))) + { + goto Exit; + } + + *ppOStream = pOStream; + pOStream = NULL; + +Exit: + + if( pOStream) + { + pOStream->Release(); + } + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmRemoveMultiFileStream( + const char * pszDirectory, + const char * pszBaseName) +{ + RCODE rc = NE_FLM_OK; + F_MultiFileOStream * pMultiStream = NULL; + + if( (pMultiStream = f_new F_MultiFileOStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = pMultiStream->processDirectory( + pszDirectory, pszBaseName, TRUE))) + { + goto Exit; + } + +Exit: + + if( pMultiStream) + { + pMultiStream->Release(); + } + + return( rc); +} + /**************************************************************************** Desc: ****************************************************************************/ @@ -489,7 +919,7 @@ RCODE FLMAPI F_FileIStream::open( close(); - if( RC_BAD( rc = gv_pFileSystem->openFile( (char *)pszFilePath, + if( RC_BAD( rc = f_getFileSysPtr()->openFile( (char *)pszFilePath, FLM_IO_RDONLY | FLM_IO_SH_DENYNONE, &m_pFileHdl))) { goto Exit; @@ -738,10 +1168,11 @@ RCODE FLMAPI F_BufferedIStream::close( void) Desc: *****************************************************************************/ RCODE FLMAPI F_FileOStream::open( - const char * pszFilePath, - FLMBOOL bTruncateIfExists) + const char * pszFilePath, + FLMBOOL bTruncateIfExists) { - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( m_pFileHdl) { @@ -751,7 +1182,7 @@ RCODE FLMAPI F_FileOStream::open( if( bTruncateIfExists) { - if( RC_BAD( rc = gv_pFileSystem->deleteFile( (char *)pszFilePath))) + if( RC_BAD( rc = pFileSystem->deleteFile( (char *)pszFilePath))) { if( rc != NE_FLM_IO_PATH_NOT_FOUND) { @@ -759,7 +1190,7 @@ RCODE FLMAPI F_FileOStream::open( } } - if( RC_BAD( rc = gv_pFileSystem->createFile( + if( RC_BAD( rc = pFileSystem->createFile( (char *)pszFilePath, FLM_IO_RDWR, &m_pFileHdl))) { goto Exit; @@ -767,7 +1198,7 @@ RCODE FLMAPI F_FileOStream::open( } else { - if( RC_BAD( rc = gv_pFileSystem->openFile( + if( RC_BAD( rc = pFileSystem->openFile( (char *)pszFilePath, FLM_IO_RDWR, &m_pFileHdl))) { if( rc != NE_FLM_IO_PATH_NOT_FOUND) @@ -775,7 +1206,7 @@ RCODE FLMAPI F_FileOStream::open( goto Exit; } - if( RC_BAD( rc = gv_pFileSystem->createFile( + if( RC_BAD( rc = pFileSystem->createFile( (char *)pszFilePath, FLM_IO_RDWR, &m_pFileHdl))) { goto Exit; @@ -889,6 +1320,7 @@ RCODE F_MultiFileIStream::rollToNextFile( void) FLMUINT uiNewFileNum = 0; char szFilePath[ F_PATH_MAX_SIZE + 1]; char szFileName[ F_PATH_MAX_SIZE + 1]; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( m_pIStream) { @@ -914,7 +1346,7 @@ RCODE F_MultiFileIStream::rollToNextFile( void) } f_strcpy( szFilePath, m_szDirectory); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( + if( RC_BAD( rc = pFileSystem->pathAppend( (char *)szFilePath, (char *)szFileName))) { goto Exit; @@ -1113,16 +1545,17 @@ Exit: Desc: *****************************************************************************/ RCODE F_MultiFileOStream::processDirectory( - const char * pszDirectory, - const char * pszBaseName, - FLMBOOL bOkToDelete) + const char * pszDirectory, + const char * pszBaseName, + FLMBOOL bOkToDelete) { - RCODE rc = NE_FLM_OK; - IF_DirHdl * pDirHandle = NULL; - FLMUINT uiBaseNameLen = f_strlen( pszBaseName); - const char * pszName = NULL; - char szSearchPattern[ F_PATH_MAX_SIZE + 1]; - char szFilePath[ F_PATH_MAX_SIZE + 1]; + RCODE rc = NE_FLM_OK; + IF_DirHdl * pDirHandle = NULL; + FLMUINT uiBaseNameLen = f_strlen( pszBaseName); + const char * pszName = NULL; + char szSearchPattern[ F_PATH_MAX_SIZE + 1]; + char szFilePath[ F_PATH_MAX_SIZE + 1]; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); f_sprintf( szSearchPattern, "%s*", pszBaseName); @@ -1131,7 +1564,7 @@ RCODE F_MultiFileOStream::processDirectory( pszDirectory = "."; } - if( RC_BAD( rc = gv_pFileSystem->openDir( + if( RC_BAD( rc = pFileSystem->openDir( (char *)pszDirectory, szSearchPattern, &pDirHandle))) { goto Exit; @@ -1168,13 +1601,13 @@ RCODE F_MultiFileOStream::processDirectory( f_strcpy( szFilePath, pszDirectory); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( + if( RC_BAD( rc = pFileSystem->pathAppend( szFilePath, pszName))) { goto Exit; } - if( RC_BAD( gv_pFileSystem->deleteFile( szFilePath))) + if( RC_BAD( pFileSystem->deleteFile( szFilePath))) { if (rc != NE_FLM_IO_PATH_NOT_FOUND) { @@ -1208,6 +1641,7 @@ RCODE F_MultiFileOStream::rollToNextFile( void) FLMUINT uiNewFileNum = 0; char szFilePath[ F_PATH_MAX_SIZE + 1]; char szFileName[ F_PATH_MAX_SIZE + 1]; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); if( m_pOStream) { @@ -1239,7 +1673,7 @@ RCODE F_MultiFileOStream::rollToNextFile( void) f_strcpy( szFilePath, m_szDirectory); - if( RC_BAD( rc = gv_pFileSystem->pathAppend( + if( RC_BAD( rc = pFileSystem->pathAppend( (char *)szFilePath, (char *)szFileName))) { goto Exit; @@ -1510,20 +1944,6 @@ RCODE FLMAPI F_BufferedOStream::close( void) return( rc); } -/***************************************************************************** -Desc: -******************************************************************************/ -RCODE FLMAPI FlmAllocBufferIStream( - IF_BufferIStream ** ppIStream) -{ - if( (*ppIStream = f_new F_BufferIStream) == NULL) - { - return( RC_SET( NE_FLM_MEM)); - } - - return( NE_FLM_OK); -} - /***************************************************************************** Desc: ******************************************************************************/ @@ -1536,11 +1956,11 @@ F_BufferIStream::~F_BufferIStream() Desc: ******************************************************************************/ RCODE FLMAPI F_BufferIStream::open( - const FLMBYTE * pucBuffer, - FLMUINT uiLength, - FLMBYTE ** ppucAllocatedBuffer) + const char * pucBuffer, + FLMUINT uiLength, + char ** ppucAllocatedBuffer) { - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; f_assert( !m_pucBuffer); @@ -1553,14 +1973,14 @@ RCODE FLMAPI F_BufferIStream::open( if( ppucAllocatedBuffer) { - *ppucAllocatedBuffer = (FLMBYTE *)m_pucBuffer; + *ppucAllocatedBuffer = (char *)m_pucBuffer; } m_bAllocatedBuffer = TRUE; } else { - m_pucBuffer = pucBuffer; + m_pucBuffer = (FLMBYTE *)pucBuffer; } m_uiBufferLen = uiLength; @@ -3177,3 +3597,46 @@ Exit: return( NE_FLM_OK); } + +/****************************************************************************** +Desc: Read all data from input stream and write to the output stream. +******************************************************************************/ +RCODE FLMAPI FlmWriteToOStream( + IF_IStream * pIStream, + IF_OStream * pOStream) +{ + RCODE rc = NE_FLM_OK; + FLMBYTE ucBuffer[ 512]; + FLMUINT uiBufferSize = sizeof( ucBuffer); + FLMUINT uiBytesToWrite; + FLMUINT uiBytesRead; + + for (;;) + { + if( RC_BAD( rc = pIStream->read( + ucBuffer, uiBufferSize, &uiBytesRead))) + { + if( rc != NE_FLM_EOF_HIT) + { + goto Exit; + } + + rc = NE_FLM_OK; + + if (!uiBytesRead) + { + goto Exit; + } + } + + uiBytesToWrite = uiBytesRead; + if( RC_BAD( rc = pOStream->write( ucBuffer, uiBytesToWrite))) + { + goto Exit; + } + } + +Exit: + + return( rc); +} diff --git a/ftk/src/ftksys.h b/ftk/src/ftksys.h index 553565b..68023fa 100644 --- a/ftk/src/ftksys.h +++ b/ftk/src/ftksys.h @@ -41,17 +41,8 @@ Desc: Global data ****************************************************************************/ - #ifndef ALLOCATE_SYS_DATA - extern IF_FileSystem * gv_pFileSystem; - extern IF_ThreadMgr * gv_pThreadMgr; - #else - IF_FileSystem * gv_pFileSystem; - IF_ThreadMgr * gv_pThreadMgr; - #endif - #define FLM_DEFAULT_OPEN_THRESHOLD 100 #define FLM_DEFAULT_MAX_AVAIL_TIME 900 - #define FLM_MAX_KEY_SIZE 1024 /**************************************************************************** @@ -280,196 +271,6 @@ #endif - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE void * FLMAPI f_memcpy( - void * pvDest, - const void * pvSrc, - FLMSIZET iSize) - { - if( iSize == 1) - { - *((FLMBYTE *)pvDest) = *((FLMBYTE *)pvSrc); - return( pvDest); - } - else - { - return( memcpy( pvDest, pvSrc, iSize)); - } - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE void * FLMAPI f_memmove( - void * pvDest, - const void * pvSrc, - FLMSIZET uiLength) - { - return( memmove( pvDest, pvSrc, uiLength)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE void * FLMAPI f_memset( - void * pvDest, - unsigned char ucByte, - FLMSIZET uiLength) - { - return( memset( pvDest, ucByte, uiLength)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE FLMINT FLMAPI f_memcmp( - const void * pvMem1, - const void * pvMem2, - FLMSIZET uiLength) - { - return( memcmp( pvMem1, pvMem2, uiLength)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE char * FLMAPI f_strcpy( - char * pszDest, - const char * pszSrc) - { - return( strcpy( pszDest, pszSrc)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE char * FLMAPI f_strncpy( - char * pszDest, - const char * pszSrc, - FLMSIZET uiLength) - { - return( strncpy( pszDest, pszSrc, uiLength)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE FLMINT FLMAPI f_strlen( - const char * pszStr) - { - return( strlen( pszStr)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE FLMINT FLMAPI f_strcmp( - const char * pszStr1, - const char * pszStr2) - { - return( strcmp( pszStr1, pszStr2)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - #ifdef FLM_WIN - FINLINE FLMINT FLMAPI f_stricmp( - const char * pszStr1, - const char * pszStr2) - { - return( _stricmp( pszStr1, pszStr2)); - } - #endif - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE FLMINT FLMAPI f_strncmp( - const char * pszStr1, - const char * pszStr2, - FLMSIZET uiLength) - { - return( strncmp( pszStr1, pszStr2, uiLength)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - #ifdef FLM_WIN - FINLINE FLMINT FLMAPI f_strnicmp( - const char * pszStr1, - const char * pszStr2, - FLMSIZET uiLength) - { - return( _strnicmp( pszStr1, pszStr2, uiLength)); - } - #endif - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE char * FLMAPI f_strcat( - char * pszDest, - const char * pszSrc) - { - return( strcat( pszDest, pszSrc)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE char * FLMAPI f_strncat( - char * pszDest, - const char * pszSrc, - FLMSIZET uiLength) - { - return( strncat( pszDest, pszSrc, uiLength)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE char * FLMAPI f_strchr( - char * pszStr, - unsigned char ucByte) - { - return( strchr( pszStr, ucByte)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE char * FLMAPI f_strrchr( - char * pszStr, - unsigned char ucByte) - { - return( strrchr( pszStr, ucByte)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - FINLINE char * FLMAPI f_strstr( - const char * pszStr1, - const char * pszStr2) - { - return( strstr( pszStr1, pszStr2)); - } - - /**************************************************************************** - Desc: - ****************************************************************************/ - #ifdef FLM_WIN - FINLINE char * FLMAPI f_strupr( - char * pszStr) - { - return( _strupr( pszStr)); - } - #endif - #if defined( __va_copy) #define f_va_copy(to, from) __va_copy(to, from) #else @@ -524,273 +325,14 @@ FLMINT32 iNewValue); #endif - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 FLMAPI f_atomicInc( - FLMATOMIC * piTarget) - { - #if defined( FLM_NLM) - { - return( (FLMINT32)nlm_AtomicIncrement( (volatile LONG *)piTarget)); - } - #elif defined( FLM_WIN) - { - return( (FLMINT32)InterlockedIncrement( (volatile LONG *)piTarget)); - } - #elif defined( FLM_AIX) - { - return( (FLMINT32)aix_atomic_add( piTarget, 1)); - } - #elif defined( FLM_OSX) - { - return( (FLMINT32)OSAtomicIncrement32( (int32_t *)piTarget)); - } - #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) - { - return( sparc_atomic_add_32( piTarget, 1)); - } - #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) - { - FLMINT32 i32Tmp; - - __asm__ __volatile__ ( - "lock;" - "xaddl %0, %1" - : "=r" (i32Tmp), "=m" (*piTarget) - : "0" (1), "m" (*piTarget)); - - return( i32Tmp + 1); - } - #elif defined( FLM_UNIX) - return( posix_atomic_add_32( piTarget, 1)); - #else - #error Atomic operations are not supported - #endif - } - - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 FLMAPI f_atomicDec( - FLMATOMIC * piTarget) - { - #if defined( FLM_NLM) - { - return( (FLMINT32)nlm_AtomicDecrement( (volatile LONG *)piTarget)); - } - #elif defined( FLM_WIN) - { - return( (FLMINT32)InterlockedDecrement( (volatile LONG *)piTarget)); - } - #elif defined( FLM_AIX) - { - return( (FLMINT32)aix_atomic_add( piTarget, -1)); - } - #elif defined( FLM_OSX) - { - return( (FLMINT32)OSAtomicDecrement32( (int32_t *)piTarget)); - } - #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) - { - return( sparc_atomic_add_32( piTarget, -1)); - } - #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) - { - FLMINT32 i32Tmp; - - __asm__ __volatile__ ( - "lock;" - "xaddl %0, %1" - : "=r" (i32Tmp), "=m" (*piTarget) - : "0" (-1), "m" (*piTarget)); - - return( i32Tmp - 1); - } - #elif defined( FLM_UNIX) - return( posix_atomic_add_32( piTarget, -1)); - #else - #error Atomic operations are not supported - #endif - } - - /********************************************************************** - Desc: - **********************************************************************/ - FINLINE FLMINT32 FLMAPI f_atomicExchange( - FLMATOMIC * piTarget, - FLMINT32 i32NewVal) - { - #if defined( FLM_NLM) - { - return( (FLMINT32)nlm_AtomicExchange( - (volatile LONG *)piTarget, i32NewVal)); - } - #elif defined( FLM_WIN) - { - return( (FLMINT32)InterlockedExchange( (volatile LONG *)piTarget, - i32NewVal)); - } - #elif defined( FLM_AIX) - { - int iOldVal; - - for( ;;) - { - iOldVal = (int)*piTarget; - - if( compare_and_swap( (int *)piTarget, &iOldVal, i32NewVal)) - { - break; - } - } - - return( (FLMINT32)iOldVal); - } - #elif defined( FLM_OSX) - { - int32_t iOldVal; - - for( ;;) - { - iOldVal = (int32_t)*piTarget; - - if( OSAtomicCompareAndSwap32( iOldVal, i32NewVal, - (int32_t *)piTarget)) - { - break; - } - } - - return( (FLMINT32)iOldVal); - } - #elif defined( FLM_SOLARIS) && defined( FLM_SPARC) && !defined( FLM_GNUC) - { - return( sparc_atomic_xchg_32( piTarget, i32NewVal)); - } - #elif (defined( __i386__) || defined( __x86_64__)) && defined( FLM_GNUC) - { - FLMINT32 i32OldVal; - - __asm__ __volatile__ ( - "1: lock;" - " cmpxchgl %2, %0;" - " jne 1b" - : "=m" (*piTarget), "=a" (i32OldVal) - : "r" (i32NewVal), "m" (*piTarget), "a" (*piTarget)); - - return( i32OldVal); - } - #elif defined( FLM_UNIX) - return( posix_atomic_xchg_32( piTarget, i32NewVal)); - #else - #error Atomic operations are not supported - #endif - } - /**************************************************************************** Desc: Mutex and semaphore routines ****************************************************************************/ #ifdef FLM_NLM - FINLINE RCODE FLMAPI f_mutexCreate( - F_MUTEX * phMutex) - { - if( (*phMutex = (F_MUTEX)kMutexAlloc( (BYTE *)"NOVDB")) == F_MUTEX_NULL) - { - return RC_SET( NE_FLM_MEM); - } - - return NE_FLM_OK; - } - - FINLINE void FLMAPI f_mutexDestroy( - F_MUTEX * phMutex) - { - if (*phMutex != F_MUTEX_NULL) - { - if( kMutexFree( (MUTEX)(*phMutex))) - { - f_assert( 0); - } - - *phMutex = F_MUTEX_NULL; - } - } - - FINLINE void FLMAPI f_mutexLock( - F_MUTEX hMutex) - { - (void)kMutexLock( (MUTEX)hMutex); - } - - FINLINE void FLMAPI f_mutexUnlock( - F_MUTEX hMutex) - { - (void)kMutexUnlock( (MUTEX)hMutex); - } - - FINLINE void FLMAPI f_assertMutexLocked( - F_MUTEX) - { - } - typedef SEMAPHORE F_SEM; typedef SEMAPHORE * F_SEM_p; #define F_SEM_NULL 0 - - FINLINE RCODE FLMAPI f_semCreate( - F_SEM * phSem) - { - if( (*phSem = (F_SEM)kSemaphoreAlloc( (BYTE *)"NOVDB", 0)) == F_SEM_NULL) - { - return RC_SET( NE_FLM_MEM); - } - - return NE_FLM_OK; - } - - FINLINE void FLMAPI f_semDestroy( - F_SEM * phSem) - { - if (*phSem != F_SEM_NULL) - { - (void)kSemaphoreFree( (SEMAPHORE)(*phSem)); - *phSem = F_SEM_NULL; - } - } - - FINLINE RCODE FLMAPI f_semWait( - F_SEM hSem, - FLMUINT uiTimeout) - { - RCODE rc = NE_FLM_OK; - - if( uiTimeout == F_SEM_WAITFOREVER) - { - if( kSemaphoreWait( (SEMAPHORE)hSem) != 0) - { - rc = RC_SET( NE_FLM_ERROR_WAITING_ON_SEMPAHORE); - } - } - else - { - if( kSemaphoreTimedWait( (SEMAPHORE)hSem, (UINT)uiTimeout) != 0) - { - rc = RC_SET( NE_FLM_ERROR_WAITING_ON_SEMPAHORE); - } - } - - return( rc); - } - - FINLINE void FLMAPI f_semSignal( - F_SEM hSem) - { - (void)kSemaphoreSignal( (SEMAPHORE)hSem); - } - #elif defined( FLM_WIN) - typedef struct { FLMATOMIC locked; @@ -800,206 +342,8 @@ FLMATOMIC waitCount; #endif } F_INTERLOCK; - - RCODE FLMAPI f_mutexCreate( - F_MUTEX * phMutex); - - void FLMAPI f_mutexDestroy( - F_MUTEX * phMutex); - - FINLINE void FLMAPI f_mutexLock( - F_MUTEX hMutex) - { - F_INTERLOCK * pInterlock = (F_INTERLOCK *)hMutex; - - while( f_atomicExchange( &pInterlock->locked, 1) != 0) - { - #ifdef FLM_DEBUG - f_atomicInc( &(((F_INTERLOCK *)hMutex)->waitCount)); - #endif - Sleep( 0); - } - - #ifdef FLM_DEBUG - f_assert( ((F_INTERLOCK *)hMutex)->uiThreadId == 0); - ((F_INTERLOCK *)hMutex)->uiThreadId = _threadid; - f_atomicInc( &(((F_INTERLOCK *)hMutex)->lockedCount)); - #endif - } - - FINLINE void FLMAPI f_mutexUnlock( - F_MUTEX hMutex) - { - f_assert( ((F_INTERLOCK *)hMutex)->locked == 1); - #ifdef FLM_DEBUG - f_assert( ((F_INTERLOCK *)hMutex)->uiThreadId == _threadid); - ((F_INTERLOCK *)hMutex)->uiThreadId = 0; - #endif - f_atomicExchange( &(((F_INTERLOCK *)hMutex)->locked), 0); - } - - FINLINE void FLMAPI f_assertMutexLocked( - F_MUTEX hMutex) - { - #ifdef FLM_DEBUG - f_assert( ((F_INTERLOCK *)hMutex)->locked == 1); - f_assert( ((F_INTERLOCK *)hMutex)->uiThreadId == _threadid); - #else - F_UNREFERENCED_PARM( hMutex); - #endif - } - - FINLINE RCODE FLMAPI f_semCreate( - F_SEM * phSem) - { - if( (*phSem = CreateSemaphore( (LPSECURITY_ATTRIBUTES)NULL, - 0, 10000, NULL )) == NULL) - { - return( RC_SET( NE_FLM_COULD_NOT_CREATE_SEMAPHORE)); - } - - return NE_FLM_OK; - } - - FINLINE void FLMAPI f_semDestroy( - F_SEM * phSem) - { - if (*phSem != F_SEM_NULL) - { - CloseHandle( *phSem); - *phSem = F_SEM_NULL; - } - } - - FINLINE RCODE FLMAPI f_semWait( - F_SEM hSem, - FLMUINT uiTimeout) - { - if( WaitForSingleObject( hSem, uiTimeout ) == WAIT_OBJECT_0) - { - return( NE_FLM_OK); - } - else - { - return( RC_SET( NE_FLM_ERROR_WAITING_ON_SEMPAHORE)); - } - } - - FINLINE void FLMAPI f_semSignal( - F_SEM hSem) - { - (void)ReleaseSemaphore( hSem, 1, NULL); - } - #elif defined( FLM_UNIX) - RCODE FLMAPI f_mutexCreate( - F_MUTEX * phMutex); - - void f_mutexDestroy( - F_MUTEX * phMutex); - - FINLINE void FLMAPI f_mutexLock( - F_MUTEX hMutex) - { - (void)pthread_mutex_lock( (pthread_mutex_t *)hMutex); - } - - FINLINE void FLMAPI f_mutexUnlock( - F_MUTEX hMutex) - { - (void)pthread_mutex_unlock( (pthread_mutex_t *)hMutex); - } - - FINLINE void FLMAPI f_assertMutexLocked( - F_MUTEX) - { - } - - void FLMAPI f_semDestroy( - F_SEM * phSem); - - RCODE FLMAPI f_semCreate( - F_SEM * phSem); - - RCODE FLMAPI f_semWait( - F_SEM hSem, - FLMUINT uiTimeout); - #endif - /**************************************************************************** - Misc. - ****************************************************************************/ - - FINLINE FLMBOOL f_isHexChar( - FLMBYTE ucChar) - { - if( (ucChar >= '0' && ucChar <= '9') || - (ucChar >= 'A' && ucChar <= 'F') || - (ucChar >= 'a' && ucChar <= 'f')) - { - return( TRUE); - } - - return( FALSE); - } - - FINLINE FLMBOOL f_isHexChar( - FLMUNICODE uChar) - { - if( uChar > 127) - { - return( FALSE); - } - - return( f_isHexChar( f_tonative( (FLMBYTE)uChar))); - } - - FINLINE FLMBYTE f_getHexVal( - FLMBYTE ucChar) - { - if( ucChar >= '0' && ucChar <= '9') - { - return( (FLMBYTE)(ucChar - '0')); - } - else if( ucChar >= 'A' && ucChar <= 'F') - { - return( (FLMBYTE)((ucChar - 'A') + 10)); - } - else if( ucChar >= 'a' && ucChar <= 'f') - { - return( (FLMBYTE)((ucChar - 'a') + 10)); - } - - return( 0); - } - - FINLINE FLMBYTE f_getHexVal( - FLMUNICODE uChar) - { - return( f_getHexVal( f_tonative( (FLMBYTE)uChar))); - } - - FINLINE FLMBOOL f_isValidHexNum( - const FLMBYTE * pszString) - { - if( *pszString == 0) - { - return( FALSE); - } - - while( *pszString) - { - if( !f_isHexChar( *pszString)) - { - return( TRUE); - } - - pszString++; - } - - return( TRUE); - } - /**************************************************************************** Process ID Functions ****************************************************************************/ @@ -1110,9 +454,8 @@ /**************************************************************************** Desc: ****************************************************************************/ - class F_IOBuffer : public IF_IOBuffer, public F_Base + class F_IOBuffer : public IF_IOBuffer { - #define MAX_BUFFER_BLOCKS 16 public: F_IOBuffer(); @@ -1151,14 +494,14 @@ FLMUINT uiBlockNumber, void * pvData) { - f_assert( uiBlockNumber < MAX_BUFFER_BLOCKS); + f_assert( uiBlockNumber < FLM_MAX_IO_BUFFER_BLOCKS); m_UserData [uiBlockNumber] = pvData; } FINLINE void * FLMAPI getCompletionCallbackData( FLMUINT uiBlockNumber) { - f_assert( uiBlockNumber < MAX_BUFFER_BLOCKS); + f_assert( uiBlockNumber < FLM_MAX_IO_BUFFER_BLOCKS); return( m_UserData [uiBlockNumber]); } @@ -1214,7 +557,7 @@ F_IOBufferMgr * m_pIOBufferMgr; FLMBYTE * m_pucBuffer; - void * m_UserData [MAX_BUFFER_BLOCKS]; + void * m_UserData[ FLM_MAX_IO_BUFFER_BLOCKS]; FLMUINT m_uiBufferSize; FLMUINT m_uiBlockSize; eBufferMgrList m_eList; @@ -1466,7 +809,7 @@ Desc: ***************************************************************************/ #ifdef FLM_WIN - class F_FileHdl : public IF_FileHdl, public F_Base + class F_FileHdl : public IF_FileHdl { public: @@ -1585,17 +928,6 @@ return( m_uiBytesPerSector); } - FINLINE void FLMAPI setFileId( - FLMUINT uiFileId) - { - m_uiFileId = uiFileId; - } - - FINLINE FLMUINT FLMAPI getFileId( void) - { - return( m_uiFileId); - } - private: RCODE create( @@ -1663,7 +995,6 @@ RCODE allocAlignedBuffer( void); - FLMUINT m_uiFileId; FLMBOOL m_bFileOpened; FLMBOOL m_bDeleteOnRelease; FLMBOOL m_bOpenedReadOnly; @@ -1692,7 +1023,7 @@ Desc: ***************************************************************************/ #ifdef FLM_UNIX - class F_FileHdl : public IF_FileHdl, public F_Base + class F_FileHdl : public IF_FileHdl { public: @@ -1875,7 +1206,8 @@ /*************************************************************************** Desc: ***************************************************************************/ - class F_FileHdlMgr : public IF_FileHdlMgr, public F_Base + #if 0 + class F_FileHdlMgr : public IF_FileHdlMgr { public: @@ -1927,7 +1259,6 @@ void FLMAPI findAvail( FLMUINT uiFileId, - FLMBOOL bReadOnlyFlag, IF_FileHdl ** ppFileHdl); void FLMAPI removeFileHdls( @@ -1995,22 +1326,22 @@ } void insertInList( - FLMBOOL bMutexAlreadyLocked, - IF_FileHdl * pFileHdl, - FLMBOOL bInsertAtEnd, - IF_FileHdl ** ppFirst, - IF_FileHdl ** ppLast, - FLMUINT * puiCount); + FLMBOOL bMutexAlreadyLocked, + IF_FileHdl * pFileHdl, + FLMBOOL bInsertAtEnd, + IF_FileHdl ** ppFirst, + IF_FileHdl ** ppLast, + FLMUINT * puiCount); void removeFromList( - FLMBOOL bMutexAlreadyLocked, - IF_FileHdl * pFileHdl, - IF_FileHdl ** ppFirst, - IF_FileHdl ** ppLast, - FLMUINT * puiCount); + FLMBOOL bMutexAlreadyLocked, + IF_FileHdl * pFileHdl, + IF_FileHdl ** ppFirst, + IF_FileHdl ** ppLast, + FLMUINT * puiCount); FINLINE void lockMutex( - FLMBOOL bMutexAlreadyLocked) + FLMBOOL bMutexAlreadyLocked) { if (m_hMutex != F_MUTEX_NULL && !bMutexAlreadyLocked) { @@ -2019,7 +1350,7 @@ } FINLINE void unlockMutex( - FLMBOOL bMutexAlreadyLocked) + FLMBOOL bMutexAlreadyLocked) { if (m_hMutex != F_MUTEX_NULL && !bMutexAlreadyLocked) { @@ -2027,25 +1358,19 @@ } } - F_MUTEX m_hMutex; - FLMUINT m_uiOpenThreshold; // FileHdl open threshold. - FLMUINT m_uiMaxAvailTime; // Time to close any available files. - - // Used list - - IF_FileHdl * m_pFirstUsed; - IF_FileHdl * m_pLastUsed; - FLMUINT m_uiNumUsed; - - // Avail list - - IF_FileHdl * m_pFirstAvail; - IF_FileHdl * m_pLastAvail; - FLMUINT m_uiNumAvail; - - FLMBOOL m_bIsSetup; - FLMUINT m_uiFileIdCounter; + F_MUTEX m_hMutex; + FLMUINT m_uiOpenThreshold; + FLMUINT m_uiMaxAvailTime; + IF_FileHdl * m_pFirstUsed; + IF_FileHdl * m_pLastUsed; + FLMUINT m_uiNumUsed; + IF_FileHdl * m_pFirstAvail; + IF_FileHdl * m_pLastAvail; + FLMUINT m_uiNumAvail; + FLMBOOL m_bIsSetup; + FLMUINT m_uiFileIdCounter; }; + #endif /**************************************************************************** Desc: @@ -2083,7 +1408,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - class F_DirHdl : public IF_DirHdl, public F_Base + class F_DirHdl : public IF_DirHdl { public: @@ -2131,7 +1456,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - class F_IStream : public IF_IStream, public F_Base + class F_IStream : public IF_IStream { public: @@ -2143,7 +1468,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - class F_OStream : public IF_OStream, public F_Base + class F_OStream : public IF_OStream { public: @@ -2156,7 +1481,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - class F_PosIStream : public IF_PosIStream, public F_Base + class F_PosIStream : public IF_PosIStream { public: @@ -2169,7 +1494,7 @@ /**************************************************************************** Desc: ****************************************************************************/ - class F_BufferIStream : public IF_BufferIStream, public F_Base + class F_BufferIStream : public IF_BufferIStream { public: @@ -2185,9 +1510,9 @@ virtual ~F_BufferIStream(); RCODE FLMAPI open( - const FLMBYTE * pucBuffer, + const char * pucBuffer, FLMUINT uiLength, - FLMBYTE ** ppucAllocatedBuffer = NULL); + char ** ppucAllocatedBuffer = NULL); FINLINE FLMUINT64 FLMAPI totalSize( void) { @@ -2226,6 +1551,16 @@ return( m_uiOffset); } + FINLINE void FLMAPI truncate( + FLMUINT64 ui64Offset) + { + f_assert( m_bIsOpen); + f_assert( ui64Offset >= m_uiOffset); + f_assert( ui64Offset <= m_uiBufferLen); + + m_uiBufferLen = (FLMUINT)ui64Offset; + } + RCODE FLMAPI read( void * pvBuffer, FLMUINT uiBytesToRead, @@ -2237,22 +1572,12 @@ return( m_pucBuffer); } - FINLINE const FLMBYTE * getBufferAtCurrentOffset( void) + FINLINE const FLMBYTE * FLMAPI getBufferAtCurrentOffset( void) { f_assert( m_bIsOpen); return( m_pucBuffer ? &m_pucBuffer[ m_uiOffset] : NULL); } - FINLINE void truncate( - FLMUINT uiOffset) - { - f_assert( m_bIsOpen); - f_assert( uiOffset >= m_uiOffset); - f_assert( uiOffset <= m_uiBufferLen); - - m_uiBufferLen = uiOffset; - } - FINLINE FLMBOOL isOpen( void) { return( m_bIsOpen); @@ -2551,15 +1876,15 @@ RCODE FLMAPI close( void); - private: - - RCODE rollToNextFile( void); - RCODE processDirectory( const char * pszDirectory, const char * pszBaseName, FLMBOOL bOkToDelete); + private: + + RCODE rollToNextFile( void); + F_OStream * m_pOStream; FLMBOOL m_bOpen; FLMUINT m_uiFileNum; @@ -2579,100 +1904,6 @@ void flmDbgLogExit( void); void flmDbgLogFlush( void); - /**************************************************************************** - Desc: Timers - ****************************************************************************/ - #if defined( FLM_NLM) - - extern "C" void ConvertTicksToSeconds( - LONG ticks, - LONG * seconds, - LONG * tenthsOfSeconds); - - extern "C" void ConvertSecondsToTicks( - LONG seconds, - LONG tenthsOfSeconds, - LONG * ticks); - - #define FLM_GET_TIMER() \ - (FLMUINT)GetCurrentTime() - - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ConvertSecondsToTicks( (LONG)(uiSeconds), 0, (LONG *)(&(uiTU))) - - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - { \ - LONG udDummy; \ - ConvertTicksToSeconds( (LONG)(uiTU), (LONG *)(&(uiSeconds)), &udDummy); \ - } - - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - { \ - LONG udTenths; \ - LONG udSeconds; \ - ConvertTicksToSeconds( (LONG)(uiTU), (LONG *)(&(udSeconds)), &udTenths); \ - uiMilli = (FLMUINT)(udSeconds) * 1000 + (FLMUINT)udTenths * 100; \ - } - - #define FLM_MILLI_TO_TIMER_UNITS( uiMilliSeconds, uiTU) \ - { \ - LONG udTenths, udSeconds; \ - udSeconds = ((LONG) uiMilliSeconds) / 1000; \ - udTenths = (((LONG) uiMilliSeconds) % 1000) / 100; \ - ConvertSecondsToTicks( udSeconds, udTenths, (LONG *)(&(uiTU))); \ - } - - #elif defined( FLM_UNIX) - - // gettimeofday() is actually 4 times faster than time() on - // Solaris. gethrtime() is even faster. On Linux time() is the - // fastest; gettimeofday() is 50% slower. clock() is the - // slowest on both Solaris and Linux. We use a new function for - // millisec resolution. The implementation is OS dependent. - - #define FLM_GET_TIMER() \ - (FLMUINT) f_timeGetMilliTime() - - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ((uiTU) = ((uiSeconds) * 1000)) - - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - ((uiSeconds) = ((uiTU) / 1000)) - - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - ((uiMilli) = (uiTU)) - - #define FLM_MILLI_TO_TIMER_UNITS( uiMilli, uiTU) \ - ((uiTU) = (uiMilli)) - - #elif defined( FLM_WIN) - - #define FLM_GET_TIMER() \ - (FLMUINT)GetTickCount() - - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ((uiTU) = (uiSeconds) * 1000) - - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - ((uiSeconds) = (uiTU) / 1000) - - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - (uiMilli = (uiTU)) - - #define FLM_MILLI_TO_TIMER_UNITS( uiMilliSeconds, uiTU) \ - (uiTU = (uiMilliSeconds)) - - #endif - - // This macro for calculating elapsed time accounts for the - // possibility of the time wrapping - which it will for some - // of our counters (FLM_WIN is milliseconds and wraps in 49.7 days). - - #define FLM_ELAPSED_TIME(uiLaterTime,uiEarlierTime) \ - (FLMUINT)(((uiLaterTime) >= (uiEarlierTime)) \ - ? (FLMUINT)((uiLaterTime) - (uiEarlierTime)) \ - : (FLMUINT)((0xFFFFFFFF - (uiEarlierTime)) + (uiLaterTime))) - /**************************************************************************** Desc: Misc. ****************************************************************************/ @@ -2710,92 +1941,8 @@ RCODE f_allocDirHdl( F_DirHdl ** ppDirHdl); -#if defined( FLM_NLM) + IF_FileSystem * f_getFileSysPtr( void); - extern "C" - { - void ConvertTicksToSeconds( - LONG ticks, - LONG * seconds, - LONG * tenthsOfSeconds); + IF_ThreadMgr * f_getThreadMgrPtr( void); - void ConvertSecondsToTicks( - LONG seconds, - LONG tenthsOfSeconds, - LONG * ticks); - } - - #define FLM_GET_TIMER() (FLMUINT)GetCurrentTime() - - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ConvertSecondsToTicks( (LONG)(uiSeconds), 0, (LONG *)(&(uiTU))) - - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - { \ - LONG udDummy; \ - ConvertTicksToSeconds( (LONG)(uiTU), (LONG *)(&(uiSeconds)), &udDummy); \ - } - - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - { \ - LONG udTenths; \ - LONG udSeconds; \ - ConvertTicksToSeconds( (LONG)(uiTU), (LONG *)(&(udSeconds)), &udTenths); \ - uiMilli = (FLMUINT)(udSeconds) * 1000 + (FLMUINT)udTenths * 100; \ - } - #define FLM_MILLI_TO_TIMER_UNITS( uiMilliSeconds, uiTU) \ - { \ - LONG udTenths, udSeconds; \ - udSeconds = ((LONG) uiMilliSeconds) / 1000; \ - udTenths = (((LONG) uiMilliSeconds) % 1000) / 100; \ - ConvertSecondsToTicks( udSeconds, udTenths, (LONG *)(&(uiTU))); \ - } - -#elif defined( FLM_UNIX) - - // gettimeofday() is actually 4 times faster than time() on - // Solaris. gethrtime() is even faster. On Linux time() is the - // fastest; gettimeofday() is 50% slower. clock() is the - // slowest on both Solaris and Linux. We use a new function for - // millisec resolution. The implementation is OS dependent. - - #define FLM_GET_TIMER() (FLMUINT) f_timeGetMilliTime() - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ((uiTU) = ((uiSeconds) * 1000)) - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - ((uiSeconds) = ((uiTU) / 1000)) - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - ((uiMilli) = (uiTU)) - #define FLM_MILLI_TO_TIMER_UNITS( uiMilli, uiTU) \ - ((uiTU) = (uiMilli)) -#else /* FLM_WIN */ - - #define FLM_GET_TIMER() \ - (FLMUINT)GetTickCount() - - #define FLM_SECS_TO_TIMER_UNITS( uiSeconds, uiTU) \ - ((uiTU) = (uiSeconds) * 1000) - - #define FLM_TIMER_UNITS_TO_SECS( uiTU, uiSeconds) \ - ((uiSeconds) = (uiTU) / 1000) - - #define FLM_TIMER_UNITS_TO_MILLI( uiTU, uiMilli) \ - (uiMilli = (uiTU)) - - #define FLM_MILLI_TO_TIMER_UNITS( uiMilliSeconds, uiTU) \ - (uiTU = (uiMilliSeconds)) - -#endif - -// This macro for calculating elapsed time accounts for the -// possibility of the time wrapping - which it will for some -// of our counters (FLM_WIN is milliseconds and wraps in 49.7 days). - -#define FLM_ELAPSED_TIME(uiLaterTime,uiEarlierTime) \ - (FLMUINT)(((uiLaterTime) >= (uiEarlierTime)) \ - ? (FLMUINT)((uiLaterTime) - (uiEarlierTime)) \ - : (FLMUINT)((0xFFFFFFFF - (uiEarlierTime)) + (uiLaterTime))) - - - #endif // FTKSYS_H diff --git a/ftk/src/ftktext.cpp b/ftk/src/ftktext.cpp index cf678f8..2e9472c 100644 --- a/ftk/src/ftktext.cpp +++ b/ftk/src/ftktext.cpp @@ -2616,7 +2616,7 @@ FLMUNICODE * FLMAPI f_unicpy( /**************************************************************************** Desc: A rather trivial unicode monocase function. ****************************************************************************/ -FLMUNICODE FLMAPI f_unitolower( +FLMUNICODE FLMAPI f_uniToLower( FLMUNICODE uChar) { static const FLMUNICODE basicAlpha[ 0x600] = @@ -4721,13 +4721,13 @@ FLMINT FLMAPI f_uniicmp( const FLMUNICODE * puzStr1, const FLMUNICODE * puzStr2) { - while( f_unitolower( *puzStr1) == f_unitolower( *puzStr2) && *puzStr1) + while( f_uniToLower( *puzStr1) == f_uniToLower( *puzStr2) && *puzStr1) { puzStr1++; puzStr2++; } - return( (FLMINT)f_unitolower( *puzStr1) - (FLMINT)f_unitolower( *puzStr2)); + return( (FLMINT)f_uniToLower( *puzStr1) - (FLMINT)f_uniToLower( *puzStr2)); } /**************************************************************************** @@ -4866,15 +4866,6 @@ FLMBOOL FLMAPI f_uniIsDecimalDigit( return( bRV); } -/*************************************************************************** -Desc: -****************************************************************************/ -FLMUNICODE FLMAPI f_uniToLower( - FLMUNICODE uzChar) -{ - return( f_unitolower( uzChar)); -} - /*************************************************************************** Desc: ****************************************************************************/ @@ -5628,7 +5619,7 @@ RCODE FLMAPI f_getNextMetaphone( if( uiInputLen < (MAX_METAPHONE_INPUT_CHARS - 5)) { - uzInput[ uiInputLen++] = f_unitolower( uChar); + uzInput[ uiInputLen++] = f_uniToLower( uChar); if( !bSlavoGermanic && (uChar == FLM_UNICODE_w || @@ -7263,7 +7254,7 @@ RCODE f_verifyMetaphoneRoutines( void) } if( RC_BAD( rc = pBufferStream->open( - (FLMBYTE *)pMetaMap->pszWord, f_strlen( pMetaMap->pszWord)))) + pMetaMap->pszWord, f_strlen( pMetaMap->pszWord)))) { goto Exit; } diff --git a/ftk/src/ftkthrd.cpp b/ftk/src/ftkthrd.cpp index 63152f8..0502eb6 100644 --- a/ftk/src/ftkthrd.cpp +++ b/ftk/src/ftkthrd.cpp @@ -39,7 +39,7 @@ /**************************************************************************** Desc: ****************************************************************************/ -class F_ThreadMgr : public IF_ThreadMgr, public F_Base +class F_ThreadMgr : public IF_ThreadMgr { public: @@ -48,6 +48,7 @@ public: m_hMutex = F_MUTEX_NULL; m_pThreadList = NULL; m_uiNumThreads = 0; + m_groupCounter = 0; } virtual ~F_ThreadMgr(); @@ -89,6 +90,8 @@ public: FLMUINT FLMAPI getThreadGroupCount( FLMUINT uiThreadGroup); + FLMUINT FLMAPI allocGroupId( void); + inline void lockMutex( void) { f_mutexLock( m_hMutex); @@ -108,6 +111,7 @@ private: F_MUTEX m_hMutex; F_Thread * m_pThreadList; FLMUINT m_uiNumThreads; + FLMATOMIC m_groupCounter; friend class F_Thread; }; @@ -115,7 +119,7 @@ friend class F_Thread; /**************************************************************************** Desc: ****************************************************************************/ -class F_Thread : public IF_Thread, public F_Base +class F_Thread : public IF_Thread { public: @@ -248,6 +252,69 @@ public: friend class F_ThreadMgr; }; +/**************************************************************************** +Desc: +****************************************************************************/ +class F_ThreadInfo : public IF_ThreadInfo +{ +public: + + F_ThreadInfo() + { + m_pPool = NULL; + m_uiNumThreads = 0; + m_pThreadInfoArray = NULL; + } + + virtual ~F_ThreadInfo() + { + if( m_pPool) + { + m_pPool->Release(); + } + } + + FLMUINT FLMAPI getNumThreads( void) + { + return( m_uiNumThreads); + } + + FINLINE void FLMAPI getThreadInfo( + FLMUINT uiThreadNum, + FLMUINT * puiThreadId, + FLMUINT * puiThreadGroup, + FLMUINT * puiAppId, + FLMUINT * puiStartTime, + const char ** ppszThreadName, + const char ** ppszThreadStatus) + { + if (uiThreadNum < m_uiNumThreads) + { + F_THREAD_INFO * pThrdInfo = &m_pThreadInfoArray [uiThreadNum]; + + *puiThreadId = pThrdInfo->uiThreadId; + *puiThreadGroup = pThrdInfo->uiThreadGroup; + *puiAppId = pThrdInfo->uiAppId; + *puiStartTime = pThrdInfo->uiStartTime; + *ppszThreadName = pThrdInfo->pszThreadName; + *ppszThreadStatus = pThrdInfo->pszThreadStatus; + } + else + { + *puiThreadId = 0; + *puiThreadGroup = 0; + *puiAppId = 0; + *puiStartTime = 0; + *ppszThreadName = NULL; + *ppszThreadStatus = NULL; + } + } + + IF_Pool * m_pPool; + F_THREAD_INFO * m_pThreadInfoArray; + FLMUINT m_uiNumThreads; +}; + /**************************************************************************** Desc: ****************************************************************************/ @@ -286,7 +353,7 @@ Desc: RCODE FLMAPI FlmGetThreadMgr( IF_ThreadMgr ** ppThreadMgr) { - *ppThreadMgr = gv_pThreadMgr; + *ppThreadMgr = f_getThreadMgrPtr(); (*ppThreadMgr)->AddRef(); return( NE_FLM_OK); } @@ -326,21 +393,22 @@ RCODE FLMAPI F_Thread::startThread( void * pvParm2, FLMUINT uiStackSize) { - RCODE rc = NE_FLM_OK; - FLMBOOL bManagerMutexLocked = FALSE; + RCODE rc = NE_FLM_OK; + F_ThreadMgr * pThreadMgr = (F_ThreadMgr *)f_getThreadMgrPtr(); + FLMBOOL bManagerMutexLocked = FALSE; #ifdef FLM_NLM - pthread_attr_t thread_attr; - pthread_t uiThreadId; + pthread_attr_t thread_attr; + pthread_t uiThreadId; #endif #ifdef FLM_WIN - unsigned uiThreadId; + unsigned uiThreadId; #endif #if defined( FLM_UNIX) #if defined( _POSIX_THREADS) - pthread_attr_t thread_attr; - pthread_t uiThreadId; + pthread_attr_t thread_attr; + pthread_t uiThreadId; #else - threadid_p uiThreadId; + threadid_p uiThreadId; #endif #endif @@ -392,24 +460,24 @@ RCODE FLMAPI F_Thread::startThread( // Lock the thread manager's mutex. - f_mutexLock( ((F_ThreadMgr *)gv_pThreadMgr)->m_hMutex); + f_mutexLock( pThreadMgr->m_hMutex); bManagerMutexLocked = TRUE; // Increment the active thread count - ((F_ThreadMgr *)gv_pThreadMgr)->m_uiNumThreads++; + pThreadMgr->m_uiNumThreads++; // Link the thread into the manager's list. We can't link threads in order // by thread ID at this point, because we don't know what the new thread's // ID will be. - if( ((F_ThreadMgr *)gv_pThreadMgr)->m_pThreadList) + if( pThreadMgr->m_pThreadList) { - ((F_ThreadMgr *)gv_pThreadMgr)->m_pThreadList->m_pPrev = this; + pThreadMgr->m_pThreadList->m_pPrev = this; } - m_pNext = ((F_ThreadMgr *)gv_pThreadMgr)->m_pThreadList; - ((F_ThreadMgr *)gv_pThreadMgr)->m_pThreadList = this; + m_pNext = pThreadMgr->m_pThreadList; + pThreadMgr->m_pThreadList = this; // Increment the reference count of the thread object now // that it is linked into the thread manager's list. @@ -476,7 +544,7 @@ RCODE FLMAPI F_Thread::startThread( // Unlock the thread manager's mutex. - f_mutexUnlock( ((F_ThreadMgr *)gv_pThreadMgr)->m_hMutex); + f_mutexUnlock( pThreadMgr->m_hMutex); bManagerMutexLocked = FALSE; Exit: @@ -486,7 +554,7 @@ Exit: // Unlink the thread from the manager's list. This call // won't do anything if the thread was not linked above. - ((F_ThreadMgr *)gv_pThreadMgr)->unlinkThread( this, bManagerMutexLocked); + pThreadMgr->unlinkThread( this, bManagerMutexLocked); // Reset the thread object back to its initial state @@ -495,7 +563,7 @@ Exit: if( bManagerMutexLocked) { - f_mutexUnlock( ((F_ThreadMgr *)gv_pThreadMgr)->m_hMutex); + f_mutexUnlock( pThreadMgr->m_hMutex); } return( rc); @@ -535,7 +603,8 @@ void * threadStub( void * pvThread) #endif { - F_Thread * pThread = (F_Thread *)pvThread; + F_Thread * pThread = (F_Thread *)pvThread; + F_ThreadMgr * pThreadMgr = (F_ThreadMgr *)f_getThreadMgrPtr(); #if defined( FLM_UNIX) || defined( FLM_NLM) // Block all signals (main thread will handle all signals) @@ -547,7 +616,7 @@ void * threadStub( // Lock the manager's mutex - ((F_ThreadMgr *)gv_pThreadMgr)->lockMutex(); + pThreadMgr->lockMutex(); // At this point, the thread ID must match. @@ -559,7 +628,7 @@ void * threadStub( // Unlock the manager's mutex - ((F_ThreadMgr *)gv_pThreadMgr)->unlockMutex(); + pThreadMgr->unlockMutex(); // Call the thread's function @@ -573,7 +642,7 @@ void * threadStub( // Unlink the thread from the thread manager. - ((F_ThreadMgr *)gv_pThreadMgr)->unlinkThread( pThread, FALSE); + pThreadMgr->unlinkThread( pThread, FALSE); // Set the running flag to FALSE @@ -1184,6 +1253,14 @@ FLMUINT FLMAPI F_ThreadMgr::getThreadGroupCount( return( uiCount); } +/**************************************************************************** +Desc: +****************************************************************************/ +FLMUINT FLMAPI F_ThreadMgr::allocGroupId( void) +{ + return( f_atomicInc( &m_groupCounter)); +} + /**************************************************************************** Desc: Allocate a thread object and start the thread ****************************************************************************/ @@ -1253,3 +1330,44 @@ FLMUINT FLMAPI f_threadId( void) #error Platform not supprted #endif } + +/**************************************************************************** +Desc: +****************************************************************************/ +RCODE FLMAPI FlmGetThreadInfo( + IF_ThreadInfo ** ppThreadInfo) +{ + RCODE rc = NE_FLM_OK; + F_ThreadInfo * pThreadInfo = NULL; + + if( (pThreadInfo = f_new F_ThreadInfo) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + if( RC_BAD( rc = FlmAllocPool( &pThreadInfo->m_pPool))) + { + goto Exit; + } + + if( RC_BAD( rc = f_getThreadMgrPtr()->getThreadInfo( + pThreadInfo->m_pPool, + &pThreadInfo->m_pThreadInfoArray, + &pThreadInfo->m_uiNumThreads))) + { + goto Exit; + } + + *ppThreadInfo = pThreadInfo; + pThreadInfo = NULL; + +Exit: + + if( pThreadInfo) + { + pThreadInfo->Release(); + } + + return( rc); +} diff --git a/ftk/src/ftktime.cpp b/ftk/src/ftktime.cpp index 69c11f2..f61d68d 100644 --- a/ftk/src/ftktime.cpp +++ b/ftk/src/ftktime.cpp @@ -25,6 +25,19 @@ #include "ftksys.h" +#if defined( FLM_NLM) + + extern "C" void ConvertTicksToSeconds( + LONG ticks, + LONG * seconds, + LONG * tenthsOfSeconds); + + extern "C" void ConvertSecondsToTicks( + LONG seconds, + LONG tenthsOfSeconds, + LONG * ticks); +#endif + #define BASEYR 1970 // all gmt calcs done since 1970 #define SECONDSPERDAY 86400l // 24 hours * 60 minutes * 60 seconds #define SECONDSPERHOUR 3600 // 60 minutes * 60 seconds @@ -335,3 +348,104 @@ unsigned f_timeGetMilliTime() #endif } #endif + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMUINT FLMAPI FLM_GET_TIMER( void) +{ +#if defined( FLM_WIN) + return( (FLMUINT)GetTickCount()); +#elif defined( FLM_NLM) + return( (FLMUINT)GetCurrentTime()); +#else + return( f_timeGetMilliTime()); +#endif +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMUINT FLMAPI FLM_ELAPSED_TIME( + FLMUINT uiLaterTime, + FLMUINT uiEarlierTime) +{ + // This method of calculating elapsed time accounts for the + // possibility of the time wrapping - which it will for some + // of our counters (FLM_WIN is milliseconds and wraps in 49.7 days). + + return( (FLMUINT)(((uiLaterTime) >= (uiEarlierTime)) + ? (FLMUINT)((uiLaterTime) - (uiEarlierTime)) + : (FLMUINT)((0xFFFFFFFF - (uiEarlierTime)) + (uiLaterTime)))); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMUINT FLMAPI FLM_SECS_TO_TIMER_UNITS( + FLMUINT uiSeconds) +{ +#if defined( FLM_NLM) + LONG uiTu; + + ConvertSecondsToTicks( (LONG)(uiSeconds), 0, &uiTU); + return( (FLMUINT)uiTU); +#else + return( uiSeconds * 1000); +#endif +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMUINT FLMAPI FLM_TIMER_UNITS_TO_SECS( + FLMUINT uiTU) +{ +#if defined( FLM_NLM) + LONG udDummy; + LONG uiSeconds; + + ConvertTicksToSeconds( (LONG)(uiTU), &uiSeconds, &udDummy); + return( (FLMUINT)uiSeconds); +#else + return( uiTU / 1000); +#endif +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMUINT FLM_TIMER_UNITS_TO_MILLI( + FLMUINT uiTU) +{ +#if defined( FLM_NLM) + LONG udTenths; + LONG udSeconds; + + ConvertTicksToSeconds( (LONG)(uiTU), &udSeconds, &udTenths); + return( (FLMUINT)(udSeconds) * 1000 + (FLMUINT)udTenths * 100); +#else + return( uiTU); +#endif +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMUINT FLM_MILLI_TO_TIMER_UNITS( + FLMUINT uiMilliSeconds) +{ +#if defined( FLM_NLM) + LONG udTenths; + LONG udSeconds; + LONG uiTU; + + udSeconds = ((LONG) uiMilliSeconds) / 1000; + udTenths = (((LONG) uiMilliSeconds) % 1000) / 100; + + ConvertSecondsToTicks( udSeconds, udTenths, &uiTU); + return( (FLMUINT)uiTU); +#else + return( uiMilliSeconds); +#endif +} diff --git a/ftk/src/ftkwin.cpp b/ftk/src/ftkwin.cpp index 767817c..e8e601b 100644 --- a/ftk/src/ftkwin.cpp +++ b/ftk/src/ftkwin.cpp @@ -32,7 +32,6 @@ Desc: ****************************************************************************/ F_FileHdl::F_FileHdl() { - m_uiFileId = 0; m_bFileOpened = FALSE; m_bDeleteOnRelease = FALSE; m_bOpenedReadOnly = FALSE; @@ -88,13 +87,14 @@ RCODE F_FileHdl::openOrCreate( FLMUINT uiAccess, FLMBOOL bCreateFlag) { - RCODE rc = NE_FLM_OK; - char szSaveFileName[ F_PATH_MAX_SIZE]; - DWORD udAccessMode = 0; - DWORD udShareMode = 0; - DWORD udCreateMode = 0; - DWORD udAttrFlags = 0; - DWORD udErrCode; + RCODE rc = NE_FLM_OK; + char szSaveFileName[ F_PATH_MAX_SIZE]; + DWORD udAccessMode = 0; + DWORD udShareMode = 0; + DWORD udCreateMode = 0; + DWORD udAttrFlags = 0; + DWORD udErrCode; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); m_bDoDirectIO = (uiAccess & FLM_IO_DIRECT) ? TRUE : FALSE; @@ -115,7 +115,7 @@ RCODE F_FileHdl::openOrCreate( } else { - if (RC_BAD( rc = gv_pFileSystem->getSectorSize( + if (RC_BAD( rc = pFileSystem->getSectorSize( pszFileName, &m_uiBytesPerSector))) { goto Exit; @@ -218,10 +218,10 @@ Retry_Create: // Remove the file name for which we are creating the directory. - if( RC_OK( gv_pFileSystem->pathReduce( szSaveFileName, + if( RC_OK( pFileSystem->pathReduce( szSaveFileName, szDirPath, szTemp))) { - if( RC_OK( rc = gv_pFileSystem->createDir( szDirPath))) + if( RC_OK( rc = pFileSystem->createDir( szDirPath))) { goto Retry_Create; } @@ -304,19 +304,20 @@ Exit: Desc: Create a unique file name in the specified directory ****************************************************************************/ RCODE F_FileHdl::createUnique( - char * pszDirName, - const char * pszFileExtension, - FLMUINT uiIoFlags) + char * pszDirName, + const char * pszFileExtension, + FLMUINT uiIoFlags) { - RCODE rc = NE_FLM_OK; - char * pszTmp; - FLMBOOL bModext = TRUE; - FLMUINT uiBaseTime = 0; - FLMBYTE ucHighByte = 0; - char szFileName[ F_FILENAME_SIZE]; - char szDirPath[ F_PATH_MAX_SIZE]; - char szTmpPath[ F_PATH_MAX_SIZE]; - FLMUINT uiCount; + RCODE rc = NE_FLM_OK; + char * pszTmp; + FLMBOOL bModext = TRUE; + FLMUINT uiBaseTime = 0; + FLMBYTE ucHighByte = 0; + char szFileName[ F_FILENAME_SIZE]; + char szDirPath[ F_PATH_MAX_SIZE]; + char szTmpPath[ F_PATH_MAX_SIZE]; + FLMUINT uiCount; + IF_FileSystem * pFileSystem = f_getFileSysPtr(); szFileName[0] = '\0'; szTmpPath[0] = '\0'; @@ -365,11 +366,11 @@ RCODE F_FileHdl::createUnique( uiCount = 0; do { - gv_pFileSystem->pathCreateUniqueName( &uiBaseTime, szFileName, + pFileSystem->pathCreateUniqueName( &uiBaseTime, szFileName, pszFileExtension, &ucHighByte, bModext); f_strcpy( szTmpPath, szDirPath); - gv_pFileSystem->pathAppend( szTmpPath, szFileName); + pFileSystem->pathAppend( szTmpPath, szFileName); if( m_pszFileName) { f_free( &m_pszFileName); diff --git a/ftk/src/ftkxml.cpp b/ftk/src/ftkxml.cpp index 50462ce..a1692d1 100644 --- a/ftk/src/ftkxml.cpp +++ b/ftk/src/ftkxml.cpp @@ -24,6 +24,7 @@ //------------------------------------------------------------------------------ #include "ftksys.h" +#if 0 #define FLM_XML_BASE_CHAR 0x01 #define FLM_XML_IDEOGRAPHIC 0x02 @@ -400,7 +401,7 @@ static CHAR_TBL charTbl[] = /**************************************************************************** Desc: XML ****************************************************************************/ -class F_XML : public IF_XML, public virtual F_Base +class F_XML : public IF_XML { public: @@ -763,4 +764,4 @@ Exit: return( bValid); } - +#endif diff --git a/ftk/util/ftktest.cpp b/ftk/util/ftktest.cpp index 2629f25..776b9f4 100644 --- a/ftk/util/ftktest.cpp +++ b/ftk/util/ftktest.cpp @@ -29,19 +29,49 @@ Desc: ****************************************************************************/ int main( void) { - RCODE rc = NE_FLM_OK; + RCODE rc = NE_FLM_OK; + IF_DirHdl * pDirHdl = NULL; + IF_FileSystem * pFileSystem = NULL; if( RC_BAD( rc = ftkStartup())) { goto Exit; } + if( RC_BAD( rc = FlmGetFileSystem( &pFileSystem))) + { + goto Exit; + } + + if( RC_BAD( rc = pFileSystem->openDir( ".", "*.*", &pDirHdl))) + { + goto Exit; + } + + while( RC_OK( pDirHdl->next())) + { + f_printf( "%s\n", pDirHdl->currentItemName()); + } + + pDirHdl->Release(); + pDirHdl = NULL; + FTXInit(); f_sleep( 1000); FTXExit(); Exit: + if( pDirHdl) + { + pDirHdl->Release(); + } + + if( pFileSystem) + { + pFileSystem->Release(); + } + ftkShutdown(); return( (int)rc); }