From 270f6f17132700a0b37dd001815473ab0e328986 Mon Sep 17 00:00:00 2001 From: dsandersoremutah Date: Thu, 21 Sep 2006 14:48:17 +0000 Subject: [PATCH] Added IStream and OStream to C# classes - along with methods in DbSystem class to create objects of these types. git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@880 0109f412-320b-0410-ab79-c3e0c5ffbbe6 --- xflaim/csharp/cstest/cstest.cs | 86 ++++ xflaim/csharp/xflaim/Backup.cpp | 2 +- xflaim/csharp/xflaim/Backup.cs | 69 +-- xflaim/csharp/xflaim/Db.cpp | 2 +- xflaim/csharp/xflaim/Db.cs | 28 +- xflaim/csharp/xflaim/DbInfo.cpp | 2 +- xflaim/csharp/xflaim/DbInfo.cs | 144 +++--- xflaim/csharp/xflaim/DbSystem.cpp | 332 +++++++++++++- xflaim/csharp/xflaim/DbSystem.cs | 718 ++++++++++++++++++++++++++---- xflaim/csharp/xflaim/IStream.cpp | 40 ++ xflaim/csharp/xflaim/IStream.cs | 106 +++++ xflaim/csharp/xflaim/OStream.cpp | 40 ++ xflaim/csharp/xflaim/OStream.cs | 106 +++++ 13 files changed, 1474 insertions(+), 201 deletions(-) create mode 100644 xflaim/csharp/xflaim/IStream.cpp create mode 100644 xflaim/csharp/xflaim/IStream.cs create mode 100644 xflaim/csharp/xflaim/OStream.cpp create mode 100644 xflaim/csharp/xflaim/OStream.cs diff --git a/xflaim/csharp/cstest/cstest.cs b/xflaim/csharp/cstest/cstest.cs index c6e99c9..3214fdf 100644 --- a/xflaim/csharp/cstest/cstest.cs +++ b/xflaim/csharp/cstest/cstest.cs @@ -24,6 +24,7 @@ //------------------------------------------------------------------------------ using System; +using System.IO; using System.Runtime.InteropServices; using xflaim; @@ -38,6 +39,7 @@ namespace cstest private const string RESTORE_DB_NAME = "restore.db"; private const string BACKUP_PATH = "backup"; private const string REBUILD_DB_NAME = "rebuild.db"; + private const string TEST_STREAM_STRING = "abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ0123456789"; //-------------------------------------------------------------------------- // Begin a test. @@ -446,6 +448,83 @@ namespace cstest return( true); } + //-------------------------------------------------------------------------- + // Stream tests + //-------------------------------------------------------------------------- + static bool streamTests( + DbSystem dbSystem) + { + IStream bufferStream; + IStream encoderStream; + IStream decoderStream; + OStream fileOStream; + Stream s; + StreamReader sr; + + beginTest( "Creating IStream from buffer"); + try + { + bufferStream = dbSystem.openBufferIStream( TEST_STREAM_STRING); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling openBufferIStream"); + return( false); + } + + try + { + encoderStream = dbSystem.openBase64Encoder( bufferStream, true); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling openBase64Encoder"); + return( false); + } + + try + { + decoderStream = dbSystem.openBase64Decoder( encoderStream); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling openBase64Decoder"); + return( false); + } + + try + { + fileOStream = dbSystem.openFileOStream( "Output_Stream", true); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling openFileOStream"); + return( false); + } + try + { + dbSystem.writeToOStream( decoderStream, fileOStream); + } + catch (XFlaimException ex) + { + endTest( false, ex, "calling writeToOStream"); + return( false); + } + fileOStream = null; + + s = File.OpenRead( "Output_Sream"); + sr = new StreamReader( s); + if (sr.ReadLine() != TEST_STREAM_STRING) + { + endTest( true, false); + System.Console.WriteLine( "Stream data does not match original string"); + return( false); + } + + endTest( false, true); + return( true); + } + //-------------------------------------------------------------------------- // Main for tester program //-------------------------------------------------------------------------- @@ -551,6 +630,13 @@ namespace cstest { return; } + + // Input and Output stream tests + + if (!streamTests( dbSystem)) + { + return; + } } } diff --git a/xflaim/csharp/xflaim/Backup.cpp b/xflaim/csharp/xflaim/Backup.cpp index 6a46cce..924e55f 100644 --- a/xflaim/csharp/xflaim/Backup.cpp +++ b/xflaim/csharp/xflaim/Backup.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Desc: +// Desc: Native C routines to support C# Backup class // // Tabs: 3 // diff --git a/xflaim/csharp/xflaim/Backup.cs b/xflaim/csharp/xflaim/Backup.cs index ddf4b2b..9504e11 100644 --- a/xflaim/csharp/xflaim/Backup.cs +++ b/xflaim/csharp/xflaim/Backup.cs @@ -34,6 +34,8 @@ namespace xflaim /// public class Backup { + private ulong m_pBackup; // Pointer to IF_Backup object in unmanaged space + private Db m_db; /// /// This constructor doesn't need to do much of anything; it's here mostly @@ -69,7 +71,7 @@ namespace xflaim // no need to make the following call. if (m_db.getDb() == 0) { - throw new XFlaimException( "Invalid Db.getRef()"); + throw new XFlaimException( "Invalid Db.IF_Db object"); } } @@ -87,6 +89,14 @@ namespace xflaim m_db = null; } + [DllImport("xflaim")] + private static extern int xflaim_Backup_Release( + ulong pBackup); + +//----------------------------------------------------------------------------- +// getBackupTransId +//----------------------------------------------------------------------------- + /// /// Get the transaction ID for this backup operation. /// @@ -96,6 +106,14 @@ namespace xflaim return( xflaim_Backup_getBackupTransId( m_pBackup)); } + [DllImport("xflaim")] + private static extern ulong xflaim_Backup_getBackupTransId( + ulong pBackup); + +//----------------------------------------------------------------------------- +// getLastBackupTransId +//----------------------------------------------------------------------------- + /// /// Gets the transaction ID for the last backup job run on this database. /// @@ -108,6 +126,14 @@ namespace xflaim return( xflaim_Backup_getLastBackupTransId( m_pBackup)); } + [DllImport("xflaim")] + private static extern ulong xflaim_Backup_getLastBackupTransId( + ulong pBackup); + +//----------------------------------------------------------------------------- +// backup +//----------------------------------------------------------------------------- + /// /// Performs the backup operation. The and /// parameters are mutually exclusive. If @@ -170,6 +196,17 @@ namespace xflaim return( uiSeqNum); } + [DllImport("xflaim")] + private static extern int xflaim_Backup_backup( + ulong pBackup, + [MarshalAs(UnmanagedType.LPStr)] + string sBackupPath, + [MarshalAs(UnmanagedType.LPStr)] + string sPassword, + out uint uiSeqNum, + BackupClientCallback fnBackupClient, + BackupStatusCallback fnBackupStatus); + private delegate RCODE BackupClientCallback( IntPtr pvData, uint uiDataLen); @@ -222,6 +259,10 @@ namespace xflaim private BackupStatus m_backupStatus; } +//----------------------------------------------------------------------------- +// endBackup +//----------------------------------------------------------------------------- + /// /// Ends the backup operation. /// @@ -235,35 +276,9 @@ namespace xflaim } } - // PRIVATE METHODS THAT ARE IMPLEMENTED IN C AND C++ - - [DllImport("xflaim")] - private static extern int xflaim_Backup_Release( - ulong pBackup); - - [DllImport("xflaim")] - private static extern ulong xflaim_Backup_getBackupTransId( - ulong pBackup); - - [DllImport("xflaim")] - private static extern ulong xflaim_Backup_getLastBackupTransId( - ulong pBackup); - - [DllImport("xflaim")] - private static extern int xflaim_Backup_backup( - ulong pBackup, - [MarshalAs(UnmanagedType.LPStr)] string sBackupPath, - [MarshalAs(UnmanagedType.LPStr)] string sPassword, - out uint uiSeqNum, - BackupClientCallback fnBackupClient, - BackupStatusCallback fnBackupStatus); - [DllImport("xflaim")] private static extern int xflaim_Backup_endBackup( ulong pBackup); - private ulong m_pBackup; - private Db m_db; } } - diff --git a/xflaim/csharp/xflaim/Db.cpp b/xflaim/csharp/xflaim/Db.cpp index f05434f..d7fa748 100644 --- a/xflaim/csharp/xflaim/Db.cpp +++ b/xflaim/csharp/xflaim/Db.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Desc: +// Desc: Native C routines to support C# Db class // // Tabs: 3 // diff --git a/xflaim/csharp/xflaim/Db.cs b/xflaim/csharp/xflaim/Db.cs index 1a4c9b1..336e87d 100644 --- a/xflaim/csharp/xflaim/Db.cs +++ b/xflaim/csharp/xflaim/Db.cs @@ -36,6 +36,8 @@ namespace xflaim /// public class Db { + private ulong m_pDb; // Pointer to IF_Db object in unmanaged space + private DbSystem m_dbSystem; /// /// Db constructor. @@ -46,7 +48,7 @@ namespace xflaim /// /// DbSystem object that this Db object is associated with. /// - public Db( + internal Db( ulong pDb, DbSystem dbSystem) { @@ -70,7 +72,7 @@ namespace xflaim // no need to make the following call. if (m_dbSystem.getDbSystem() == 0) { - throw new XFlaimException( "Invalid DbSystem.getRef()"); + throw new XFlaimException( "Invalid DbSystem.IF_DbSystem object"); } } @@ -86,7 +88,7 @@ namespace xflaim /// Return the pointer to the IF_Db object. /// /// Returns a pointer to the IF_Db object. - public ulong getDb() + internal ulong getDb() { return( m_pDb); } @@ -109,6 +111,14 @@ namespace xflaim m_dbSystem = null; } + [DllImport("xflaim")] + private static extern void xflaim_Db_Release( + ulong pDb); + +//----------------------------------------------------------------------------- +// backupBegin +//----------------------------------------------------------------------------- + /// /// Sets up a backup operation. /// @@ -145,12 +155,6 @@ namespace xflaim return( new Backup( pBackup, this)); } - // PRIVATE METHODS THAT ARE IMPLEMENTED IN C AND C++ - - [DllImport("xflaim")] - private static extern void xflaim_Db_Release( - ulong pDb); - [DllImport("xflaim")] private static extern int xflaim_Db_backupBegin( ulong pDb, @@ -158,11 +162,5 @@ namespace xflaim int bLockDb, uint uiMaxLockWait, out ulong ulBackupRef); - - /// - /// Reference to C++ IF_Db object. - /// - public ulong m_pDb; - private DbSystem m_dbSystem; } } diff --git a/xflaim/csharp/xflaim/DbInfo.cpp b/xflaim/csharp/xflaim/DbInfo.cpp index 075285a..51a3ca3 100644 --- a/xflaim/csharp/xflaim/DbInfo.cpp +++ b/xflaim/csharp/xflaim/DbInfo.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Desc: Database Info +// Desc: Native C routines to support C# DbInfo class // // Tabs: 3 // diff --git a/xflaim/csharp/xflaim/DbInfo.cs b/xflaim/csharp/xflaim/DbInfo.cs index 0af1d2e..271e235 100644 --- a/xflaim/csharp/xflaim/DbInfo.cs +++ b/xflaim/csharp/xflaim/DbInfo.cs @@ -124,13 +124,15 @@ namespace xflaim /// public class DbInfo { + private ulong m_pDbInfo; // Pointer to IF_DbInfo object in unmanaged space + /// /// Constructor /// /// /// Pointer to IF_DbInfo object allocated in unmanaged space. /// - public DbInfo( + internal DbInfo( ulong pDbInfo) { if (pDbInfo == 0) @@ -153,6 +155,14 @@ namespace xflaim } } + [DllImport("xflaim")] + private static extern void xflaim_DbInfo_Release( + ulong pDbInfo); + +//----------------------------------------------------------------------------- +// getNumCollections +//----------------------------------------------------------------------------- + /// /// Returns the number of collections in the database. /// @@ -162,6 +172,14 @@ namespace xflaim return( xflaim_DbInfo_getNumCollections( m_pDbInfo)); } + [DllImport("xflaim")] + private static extern uint xflaim_DbInfo_getNumCollections( + ulong pDbInfo); + +//----------------------------------------------------------------------------- +// getNumIndexes +//----------------------------------------------------------------------------- + /// /// Returns the number of indexes in the database. /// @@ -171,6 +189,14 @@ namespace xflaim return( xflaim_DbInfo_getNumIndexes( m_pDbInfo)); } + [DllImport("xflaim")] + private static extern uint xflaim_DbInfo_getNumIndexes( + ulong pDbInfo); + +//----------------------------------------------------------------------------- +// getNumLogicalFiles +//----------------------------------------------------------------------------- + /// /// Returns the total number of collections and indexes in the database. /// @@ -180,6 +206,14 @@ namespace xflaim return( xflaim_DbInfo_getNumLogicalFiles( m_pDbInfo)); } + [DllImport("xflaim")] + private static extern uint xflaim_DbInfo_getNumLogicalFiles( + ulong pDbInfo); + +//----------------------------------------------------------------------------- +// getDatabaseSize +//----------------------------------------------------------------------------- + /// /// Returns the total size of the database (in bytes). /// @@ -189,6 +223,14 @@ namespace xflaim return( xflaim_DbInfo_getDatabaseSize( m_pDbInfo)); } + [DllImport("xflaim")] + private static extern ulong xflaim_DbInfo_getDatabaseSize( + ulong pDbInfo); + +//----------------------------------------------------------------------------- +// getDbHdr +//----------------------------------------------------------------------------- + /// /// Get the database header /// @@ -201,6 +243,15 @@ namespace xflaim xflaim_DbInfo_getDbHdr( m_pDbInfo, pDbHdr); } + [DllImport("xflaim")] + private static extern void xflaim_DbInfo_getDbHdr( + [In] ulong m_pDbInfo, + [Out] XFLM_DB_HDR pDbHdr); + +//----------------------------------------------------------------------------- +// getAvailBlockStats +//----------------------------------------------------------------------------- + /// /// Return statistics on blocks in the avail list. /// @@ -227,6 +278,18 @@ namespace xflaim out peLastError, out puiNumErrors); } + [DllImport("xflaim")] + private static extern void xflaim_DbInfo_getAvailBlockStats( + ulong pDbInfo, + out ulong pulBytesUsed, + out uint puiBlockCount, + out FlmCorruptionCode peLastError, + out uint puiNumErrors); + +//----------------------------------------------------------------------------- +// getLFHBlockStats +//----------------------------------------------------------------------------- + /// /// Return statistics for blocks in the logical file header block list. /// @@ -253,6 +316,18 @@ namespace xflaim out peLastError, out puiNumErrors); } + [DllImport("xflaim")] + private static extern void xflaim_DbInfo_getLFHBlockStats( + ulong pDbInfo, + out ulong pulBytesUsed, + out uint puiBlockCount, + out FlmCorruptionCode peLastError, + out uint puiNumErrors); + +//----------------------------------------------------------------------------- +// getBTreeInfo +//----------------------------------------------------------------------------- + /// /// Returns information about a particular B-Tree in the database /// @@ -287,6 +362,19 @@ namespace xflaim out peLfType, out puiRootBlkAddress, out puiNumLevels); } + [DllImport("xflaim")] + private static extern void xflaim_DbInfo_getBTreeInfo( + ulong pDbInfo, + uint uiNthLogicalFile, + out uint puiLfNum, + out eLFileType peLfType, + out uint puiRootBlkAddress, + out uint puiNumLevels); + +//----------------------------------------------------------------------------- +// getBTreeBlockStats +//----------------------------------------------------------------------------- + /// /// Return the statistics for a specific logical file at a specific level /// in the logical file's b-tree. @@ -343,53 +431,6 @@ namespace xflaim out pulContElmBytes, out puiBlockCount, out peLastError, out puiNumErrors); } - // PRIVATE METHODS THAT ARE IMPLEMENTED IN C AND C++ - - [DllImport("xflaim")] - private static extern void xflaim_DbInfo_Release( - ulong pDbInfo); - - [DllImport("xflaim")] - private static extern uint xflaim_DbInfo_getNumCollections( - ulong pDbInfo); - - [DllImport("xflaim")] - private static extern uint xflaim_DbInfo_getNumIndexes( - ulong pDbInfo); - - [DllImport("xflaim")] - private static extern uint xflaim_DbInfo_getNumLogicalFiles( - ulong pDbInfo); - - [DllImport("xflaim")] - private static extern ulong xflaim_DbInfo_getDatabaseSize( - ulong pDbInfo); - - [DllImport("xflaim")] - private static extern void xflaim_DbInfo_getAvailBlockStats( - ulong pDbInfo, - out ulong pulBytesUsed, - out uint puiBlockCount, - out FlmCorruptionCode peLastError, - out uint puiNumErrors); - - [DllImport("xflaim")] - private static extern void xflaim_DbInfo_getLFHBlockStats( - ulong pDbInfo, - out ulong pulBytesUsed, - out uint puiBlockCount, - out FlmCorruptionCode peLastError, - out uint puiNumErrors); - - [DllImport("xflaim")] - private static extern void xflaim_DbInfo_getBTreeInfo( - ulong pDbInfo, - uint uiNthLogicalFile, - out uint puiLfNum, - out eLFileType peLfType, - out uint puiRootBlkAddress, - out uint puiNumLevels); - [DllImport("xflaim")] private static extern void xflaim_DbInfo_getBTreeBlockStats( ulong pDbInfo, @@ -403,12 +444,5 @@ namespace xflaim out uint puiBlockCount, out FlmCorruptionCode peLastError, out uint puiNumErrors); - - [DllImport("xflaim")] - private static extern void xflaim_DbInfo_getDbHdr( - [In] ulong m_pDbInfo, - [Out] XFLM_DB_HDR pDbHdr); - - private ulong m_pDbInfo; } } diff --git a/xflaim/csharp/xflaim/DbSystem.cpp b/xflaim/csharp/xflaim/DbSystem.cpp index 5f2d4cc..306aee7 100644 --- a/xflaim/csharp/xflaim/DbSystem.cpp +++ b/xflaim/csharp/xflaim/DbSystem.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Desc: +// Desc: Native C routines to support C# DbSystem class // // Tabs: 3 // @@ -52,7 +52,7 @@ Desc: FLMEXTC FLMEXP void FLMAPI xflaim_DbSystem_Release( FLMUINT64 ui64This) { - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); if (pDbSystem) { @@ -75,7 +75,7 @@ FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbCreate( { RCODE rc = NE_XFLM_OK; IF_Db * pDb = NULL; - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); if (RC_BAD( rc = pDbSystem->dbCreate( pszDbPath, pszDataDir, pszRflDir, pszDictFileName, pszDictBuf, @@ -104,7 +104,7 @@ FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbOpen( { RCODE rc = NE_XFLM_OK; IF_Db * pDb = NULL; - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); if (RC_BAD( rc = pDbSystem->dbOpen( pszDbPath, pszDataDir, pszRflDir, pszPassword, bAllowLimited, (IF_Db **)&pDb))) @@ -128,7 +128,7 @@ FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbRemove( const char * pszRflDir, FLMBOOL bRemoveRflFiles) { - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); return( pDbSystem->dbRemove( pszDbPath, pszDataDir, pszRflDir, bRemoveRflFiles)); } @@ -594,7 +594,7 @@ FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbRestore( RESTORE_STATUS fnRestoreStatus) { RCODE rc = NE_XFLM_OK; - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); IF_RestoreClient * pRestoreClient = NULL; IF_RestoreStatus * pRestoreStatus = NULL; @@ -693,7 +693,7 @@ FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbCheck( FLMUINT64 * pui64DbInfo) { RCODE rc = NE_XFLM_OK; - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); IF_DbCheckStatus * pDbCheckStatus = NULL; IF_DbInfo * pDbInfo = NULL; @@ -779,7 +779,7 @@ FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbCopy( DB_COPY_STATUS fnCopyStatus) { RCODE rc = NE_XFLM_OK; - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); IF_DbCopyStatus * pDbCopyStatus = NULL; if (fnCopyStatus) @@ -854,7 +854,7 @@ FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbRename( DB_RENAME_STATUS fnRenameStatus) { RCODE rc = NE_XFLM_OK; - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); IF_DbRenameStatus * pDbRenameStatus = NULL; if (fnRenameStatus) @@ -937,7 +937,7 @@ FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbRebuild( DB_REBUILD_STATUS fnRebuildStatus) { RCODE rc = NE_XFLM_OK; - IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This); + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); IF_DbRebuildStatus * pDbRebuildStatus = NULL; FLMUINT64 ui64TotNodes; FLMUINT64 ui64NodesRecov; @@ -970,3 +970,315 @@ Exit: return( rc); } + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openBufferIStream( + const char * pszBuffer, + FLMUINT64 * pui64IStream) +{ + RCODE rc = NE_XFLM_OK; + FLMUINT uiStrCharCount = f_strlen( pszBuffer) + 1; + F_BufferIStream * pIStream = NULL; + char * pszAllocBuffer = NULL; + + // Create the buffer stream object. + + if ((pIStream = f_new F_BufferIStream) == NULL) + { + rc = RC_SET( NE_FLM_MEM); + goto Exit; + } + + // Call the openStream method so that it will allocate a buffer internally. + + if (RC_BAD( rc = pIStream->openStream( NULL, uiStrCharCount, &pszAllocBuffer))) + { + goto Exit; + } + + // Copy the data from the passed in string into pucBuffer, including the NULL. + + f_memcpy( pszAllocBuffer, pszBuffer, uiStrCharCount); + +Exit: + + *pui64IStream = (FLMUINT64)((FLMUINT)pIStream); + + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openFileIStream( + FLMUINT64 ui64This, + const char * pszFileName, + FLMUINT64 * pui64IStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_PosIStream * pIStream = NULL; + + if (RC_BAD( rc = pDbSystem->openFileIStream( pszFileName, &pIStream))) + { + goto Exit; + } + +Exit: + + *pui64IStream = (FLMUINT64)((FLMUINT)pIStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openMultiFileIStream( + FLMUINT64 ui64This, + const char * pszDirectory, + const char * pszBaseName, + FLMUINT64 * pui64IStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_IStream * pIStream = NULL; + + if (RC_BAD( rc = pDbSystem->openMultiFileIStream( pszDirectory, pszBaseName, &pIStream))) + { + goto Exit; + } + +Exit: + + *pui64IStream = (FLMUINT64)((FLMUINT)pIStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openBufferedIStream( + FLMUINT64 ui64This, + FLMUINT64 ui64InputIStream, + FLMUINT uiBufferSize, + FLMUINT64 * pui64IStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_IStream * pInputStream = (IF_IStream *)((FLMUINT)ui64InputIStream); + IF_IStream * pIStream = NULL; + + if (RC_BAD( rc = pDbSystem->openBufferedIStream( pInputStream, uiBufferSize, &pIStream))) + { + goto Exit; + } + +Exit: + + *pui64IStream = (FLMUINT64)((FLMUINT)pIStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openUncompressingIStream( + FLMUINT64 ui64This, + FLMUINT64 ui64InputIStream, + FLMUINT64 * pui64IStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_IStream * pInputStream = (IF_IStream *)((FLMUINT)ui64InputIStream); + IF_IStream * pIStream = NULL; + + if (RC_BAD( rc = pDbSystem->openUncompressingIStream( pInputStream, &pIStream))) + { + goto Exit; + } + +Exit: + + *pui64IStream = (FLMUINT64)((FLMUINT)pIStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openBase64Encoder( + FLMUINT64 ui64This, + FLMUINT64 ui64InputIStream, + FLMBOOL bInsertLineBreaks, + FLMUINT64 * pui64IStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_IStream * pInputStream = (IF_IStream *)((FLMUINT)ui64InputIStream); + IF_IStream * pIStream = NULL; + + if (RC_BAD( rc = pDbSystem->openBase64Encoder( pInputStream, bInsertLineBreaks, &pIStream))) + { + goto Exit; + } + +Exit: + + *pui64IStream = (FLMUINT64)((FLMUINT)pIStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openBase64Decoder( + FLMUINT64 ui64This, + FLMUINT64 ui64InputIStream, + FLMUINT64 * pui64IStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_IStream * pInputStream = (IF_IStream *)((FLMUINT)ui64InputIStream); + IF_IStream * pIStream = NULL; + + if (RC_BAD( rc = pDbSystem->openBase64Decoder( pInputStream, &pIStream))) + { + goto Exit; + } + +Exit: + + *pui64IStream = (FLMUINT64)((FLMUINT)pIStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openFileOStream( + FLMUINT64 ui64This, + const char * pszFileName, + FLMBOOL bTruncateIfExists, + FLMUINT64 * pui64OStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_OStream * pOStream = NULL; + + if (RC_BAD( rc = pDbSystem->openFileOStream( pszFileName, bTruncateIfExists, &pOStream))) + { + goto Exit; + } + +Exit: + + *pui64OStream = (FLMUINT64)((FLMUINT)pOStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openMultiFileOStream( + FLMUINT64 ui64This, + const char * pszDirectory, + const char * pszBaseName, + FLMUINT uiMaxFileSize, + FLMBOOL bOkToOverwrite, + FLMUINT64 * pui64OStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_OStream * pOStream = NULL; + + if (RC_BAD( rc = pDbSystem->openMultiFileOStream( pszDirectory, pszBaseName, + uiMaxFileSize, bOkToOverwrite, &pOStream))) + { + goto Exit; + } + +Exit: + + *pui64OStream = (FLMUINT64)((FLMUINT)pOStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_removeMultiFileStream( + FLMUINT64 ui64This, + const char * pszDirectory, + const char * pszBaseName) +{ + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + + return( pDbSystem->removeMultiFileStream( pszDirectory, pszBaseName)); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openBufferedOStream( + FLMUINT64 ui64This, + FLMUINT64 ui64InputOStream, + FLMUINT uiBufferSize, + FLMUINT64 * pui64OStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_OStream * pInputOStream = (IF_OStream *)((FLMUINT)ui64InputOStream); + IF_OStream * pOStream = NULL; + + if (RC_BAD( rc = pDbSystem->openBufferedOStream( pInputOStream, + uiBufferSize, &pOStream))) + { + goto Exit; + } + +Exit: + + *pui64OStream = (FLMUINT64)((FLMUINT)pOStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_openCompressingOStream( + FLMUINT64 ui64This, + FLMUINT64 ui64InputOStream, + FLMUINT64 * pui64OStream) +{ + RCODE rc = NE_XFLM_OK; + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_OStream * pInputOStream = (IF_OStream *)((FLMUINT)ui64InputOStream); + IF_OStream * pOStream = NULL; + + if (RC_BAD( rc = pDbSystem->openCompressingOStream( pInputOStream, &pOStream))) + { + goto Exit; + } + +Exit: + + *pui64OStream = (FLMUINT64)((FLMUINT)pOStream); + return( rc); +} + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_writeToOStream( + FLMUINT64 ui64This, + FLMUINT64 ui64IStream, + FLMUINT64 ui64OStream) +{ + IF_DbSystem * pDbSystem = (IF_DbSystem *)((FLMUINT)ui64This); + IF_IStream * pIStream = (IF_IStream *)((FLMUINT)ui64IStream); + IF_OStream * pOStream = (IF_OStream *)((FLMUINT)ui64OStream); + + return( pDbSystem->writeToOStream( pIStream, pOStream)); +} diff --git a/xflaim/csharp/xflaim/DbSystem.cs b/xflaim/csharp/xflaim/DbSystem.cs index eab8563..3d8845d 100644 --- a/xflaim/csharp/xflaim/DbSystem.cs +++ b/xflaim/csharp/xflaim/DbSystem.cs @@ -250,6 +250,7 @@ namespace xflaim /// public class DbSystem { + private ulong m_pDbSystem; // Pointer to IF_DbSystem object in unmanaged space /// /// DbSystem constructor. @@ -264,6 +265,10 @@ namespace xflaim } } + [DllImport("xflaim")] + private static extern int xflaim_DbSystem_createDbSystem( + out ulong ppDbSystem); + /// /// DbSystem destructor. /// @@ -273,11 +278,15 @@ namespace xflaim m_pDbSystem = 0; } + [DllImport("xflaim")] + private static extern int xflaim_DbSystem_Release( + ulong pDbSystem); + /// /// Called by class to silence compiler warning. /// Has no other important use! /// - public ulong getDbSystem() + internal ulong getDbSystem() { return m_pDbSystem; } @@ -337,7 +346,6 @@ namespace xflaim string sDictBuf, CREATE_OPTS createOpts) { - Db db = null; ulong pDb; int rc; @@ -346,14 +354,25 @@ namespace xflaim { throw new XFlaimException( rc); } - - if (pDb != 0) - { - db = new Db( pDb, this); - } - return( db); + return( new Db( pDb, this)); } + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_dbCreate( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszDbFileName, + [MarshalAs(UnmanagedType.LPStr)] + string pszDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszRflDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszDictFileName, + [MarshalAs(UnmanagedType.LPStr)] + string pszDictBuf, + CREATE_OPTS pCreateOpts, + out ulong ppDb); + //----------------------------------------------------------------------------- // dbOpen //----------------------------------------------------------------------------- @@ -387,7 +406,6 @@ namespace xflaim string sPassword, bool bAllowLimited) { - Db db = null; ulong pDb; int rc; @@ -397,13 +415,23 @@ namespace xflaim throw new XFlaimException( rc); } - if (pDb != 0) - { - db = new Db( pDb, this); - } - return( db); + return( new Db( pDb, this)); } + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_dbOpen( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszDbFileName, + [MarshalAs(UnmanagedType.LPStr)] + string pszDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszRflDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszPassword, + int bAllowLimited, + out ulong ppDb); + //----------------------------------------------------------------------------- // dbRemove //----------------------------------------------------------------------------- @@ -439,6 +467,17 @@ namespace xflaim } } + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_dbRemove( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszDbFileName, + [MarshalAs(UnmanagedType.LPStr)] + string pszDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszRflDir, + int bRemoveRflFiles); + //----------------------------------------------------------------------------- // dbRestore //----------------------------------------------------------------------------- @@ -514,6 +553,22 @@ namespace xflaim } } + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_dbRestore( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszDbFileName, + [MarshalAs(UnmanagedType.LPStr)] + string pszDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszRflDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszBackupPath, + [MarshalAs(UnmanagedType.LPStr)] + string pszPassword, + RestoreClientCallback fnRestoreClient, + RestoreStatusCallback fnRestoreStatus); + // WARNING NOTE: Any changes to this enum should also be reflected in DbSystem.cpp private enum RestoreClientAction { @@ -796,6 +851,21 @@ namespace xflaim return( new DbInfo( pDbInfo)); } + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_dbCheck( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszDbName, + [MarshalAs(UnmanagedType.LPStr)] + string pszDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszRflDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszPassword, + DbCheckFlags eFlags, + DbCheckStatusCallback fnDbCheckStatus, + out ulong ppDbInfo); + private delegate RCODE DbCheckStatusCallback( int bHaveProgressInfo, IntPtr pProgressInfo, @@ -896,6 +966,23 @@ namespace xflaim } } + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_dbCopy( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszSrcDbName, + [MarshalAs(UnmanagedType.LPStr)] + string pszSrcDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszSrcRflDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszDestDbName, + [MarshalAs(UnmanagedType.LPStr)] + string pszDestDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszDestRflDir, + DbCopyStatusCallback fnDbCopyStatus); + private delegate RCODE DbCopyStatusCallback( ulong ulBytesToCopy, ulong ulBytesCopied, @@ -990,6 +1077,20 @@ namespace xflaim } } + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_dbRename( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszSrcDbName, + [MarshalAs(UnmanagedType.LPStr)] + string pszSrcDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszSrcRflDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszDestDbName, + int bOverwriteDestOk, + DbRenameStatusCallback fnDbRenameStatus); + private delegate RCODE DbRenameStatusCallback( IntPtr pszSrcFileName, IntPtr pszDestFileName); @@ -1090,6 +1191,26 @@ namespace xflaim } } + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_dbRebuild( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszSourceDbPath, + [MarshalAs(UnmanagedType.LPStr)] + string pszSourceDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszDestDbPath, + [MarshalAs(UnmanagedType.LPStr)] + string pszDestDataDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszDestRflDir, + [MarshalAs(UnmanagedType.LPStr)] + string pszDictPath, + [MarshalAs(UnmanagedType.LPStr)] + string pszPassword, + CREATE_OPTS pCreateOpts, + DbRebuildStatusCallback fnDbRebuildStatus); + private delegate RCODE DbRebuildStatusCallback( int bHaveRebuildInfo, IntPtr pRebuildInfo, @@ -1133,102 +1254,517 @@ namespace xflaim } //----------------------------------------------------------------------------- -// PRIVATE METHODS THAT ARE IMPLEMENTED IN C AND C++ +// openBufferIStream //----------------------------------------------------------------------------- - [DllImport("xflaim")] - private static extern int xflaim_DbSystem_createDbSystem( - out ulong ppDbSystem); + /// + /// Open an input stream that reads from a string buffer. + /// + /// + /// String the input stream is to read from. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an IStream object. + /// + public IStream openBufferIStream( + string sBuffer) + { + int rc; + ulong pIStream = 0; - [DllImport("xflaim")] - private static extern int xflaim_DbSystem_Release( - ulong pDbSystem); + if ((rc = xflaim_DbSystem_openBufferIStream( sBuffer, out pIStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new IStream( pIStream, this)); + } [DllImport("xflaim",CharSet=CharSet.Ansi)] - private static extern int xflaim_DbSystem_dbCreate( - ulong pDbSystem, - [MarshalAs(UnmanagedType.LPStr)] string pszDbFileName, - [MarshalAs(UnmanagedType.LPStr)] string pszDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszRflDir, - [MarshalAs(UnmanagedType.LPStr)] string pszDictFileName, - [MarshalAs(UnmanagedType.LPStr)] string pszDictBuf, - CREATE_OPTS pCreateOpts, - out ulong ppDb); + private static extern int xflaim_DbSystem_openBufferIStream( + [MarshalAs(UnmanagedType.LPStr)] + string pszBuffer, + out ulong ppIStream); + +//----------------------------------------------------------------------------- +// openFileIStream +//----------------------------------------------------------------------------- + + /// + /// Open an input stream that reads from a file. + /// + /// + /// Name of the file the input stream is to read from. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an IStream object. + /// + public IStream openFileIStream( + string sFileName) + { + int rc; + ulong pIStream = 0; + + if ((rc = xflaim_DbSystem_openFileIStream( m_pDbSystem, sFileName, out pIStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new IStream( pIStream, this)); + } [DllImport("xflaim",CharSet=CharSet.Ansi)] - private static extern int xflaim_DbSystem_dbOpen( - ulong pDbSystem, - [MarshalAs(UnmanagedType.LPStr)] string pszDbFileName, - [MarshalAs(UnmanagedType.LPStr)] string pszDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszRflDir, - [MarshalAs(UnmanagedType.LPStr)] string pszPassword, - int bAllowLimited, - out ulong ppDb); + private static extern int xflaim_DbSystem_openFileIStream( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszFileName, + out ulong ppIStream); + +//----------------------------------------------------------------------------- +// openMultiFileIStream +//----------------------------------------------------------------------------- + + /// + /// Open an input stream that reads from multiple files. + /// + /// + /// Name of the directory where the multiple files are to be found. + /// + /// + /// Base name of the input files. Files that constitute the + /// input stream are sBaseName, sBaseName.00000001, sBaseName.00000002, etc. - where + /// the extension is a Hex number. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an IStream object. + /// + public IStream openMultiFileIStream( + string sDirectory, + string sBaseName) + { + int rc; + ulong pIStream = 0; + + if ((rc = xflaim_DbSystem_openMultiFileIStream( m_pDbSystem, sDirectory, + sBaseName, out pIStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new IStream( pIStream, this)); + } [DllImport("xflaim",CharSet=CharSet.Ansi)] - private static extern int xflaim_DbSystem_dbRemove( - ulong pDbSystem, - [MarshalAs(UnmanagedType.LPStr)] string pszDbFileName, - [MarshalAs(UnmanagedType.LPStr)] string pszDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszRflDir, - int bRemoveRflFiles); + private static extern int xflaim_DbSystem_openMultiFileIStream( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszDirectory, + [MarshalAs(UnmanagedType.LPStr)] + string pszBaseName, + out ulong ppIStream); + +//----------------------------------------------------------------------------- +// openBufferedIStream +//----------------------------------------------------------------------------- + + /// + /// Open an input stream that buffers an existing input stream. + /// + /// + /// Input stream that is to be buffered. + /// + /// + /// iBufferSize The size (in bytes) of the buffer to use for the + /// input stream. Data will be read into the buffer in chunks of this size. + /// This will help performance by preventing lots of smaller reads from + /// the original input stream. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an IStream object. + /// + public IStream openBufferedIStream( + IStream inputIStream, + uint uiBufferSize) + { + int rc; + ulong pIStream = 0; + + if ((rc = xflaim_DbSystem_openBufferedIStream( m_pDbSystem, + inputIStream.getIStream(), uiBufferSize, out pIStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new IStream( pIStream, this)); + } [DllImport("xflaim",CharSet=CharSet.Ansi)] - private static extern int xflaim_DbSystem_dbRestore( - ulong pDbSystem, - [MarshalAs(UnmanagedType.LPStr)] string pszDbFileName, - [MarshalAs(UnmanagedType.LPStr)] string pszDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszRflDir, - [MarshalAs(UnmanagedType.LPStr)] string pszBackupPath, - [MarshalAs(UnmanagedType.LPStr)] string pszPassword, - RestoreClientCallback fnRestoreClient, - RestoreStatusCallback fnRestoreStatus); + private static extern int xflaim_DbSystem_openBufferedIStream( + ulong pDbSystem, + ulong pInputIStream, + uint uiBufferSize, + out ulong ppIStream); + +//----------------------------------------------------------------------------- +// openUncompressingIStream +//----------------------------------------------------------------------------- + + /// + /// Open an input stream that decompresses data from another input stream. It + /// is assumed that data coming out of the other input stream is compressed. + /// + /// + /// Input stream whose data is to be decompressed. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an IStream object. + /// + public IStream openUncompressingIStream( + IStream inputIStream) + { + int rc; + ulong pIStream = 0; + + if ((rc = xflaim_DbSystem_openUncompressingIStream( m_pDbSystem, + inputIStream.getIStream(), out pIStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new IStream( pIStream, this)); + } [DllImport("xflaim",CharSet=CharSet.Ansi)] - private static extern int xflaim_DbSystem_dbCheck( - ulong pDbSystem, - [MarshalAs(UnmanagedType.LPStr)] string pszDbName, - [MarshalAs(UnmanagedType.LPStr)] string pszDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszRflDir, - [MarshalAs(UnmanagedType.LPStr)] string pszPassword, - DbCheckFlags eFlags, - DbCheckStatusCallback fnDbCheckStatus, - out ulong ppDbInfo); + private static extern int xflaim_DbSystem_openUncompressingIStream( + ulong pDbSystem, + ulong pInputIStream, + out ulong ppIStream); + +//----------------------------------------------------------------------------- +// openBase64Encoder +//----------------------------------------------------------------------------- + + /// + /// Open an input stream that encodes data from another input stream into + /// base 64 encoded binary. Data read from the stream object returned by + /// this method will be base 64 encoded. + /// + /// + /// Input stream whose data is to be base 64 encoded. + /// + /// + /// Flag indicating whether or not line breaks + /// should be inserted into the data as it is base 64 encoded. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an IStream object. + /// + public IStream openBase64Encoder( + IStream inputIStream, + bool bInsertLineBreaks) + { + int rc; + ulong pIStream = 0; + + if ((rc = xflaim_DbSystem_openBase64Encoder( m_pDbSystem, + inputIStream.getIStream(), (int)(bInsertLineBreaks ? 1 : 0), + out pIStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new IStream( pIStream, this)); + } [DllImport("xflaim",CharSet=CharSet.Ansi)] - private static extern int xflaim_DbSystem_dbCopy( - ulong pDbSystem, - [MarshalAs(UnmanagedType.LPStr)] string pszSrcDbName, - [MarshalAs(UnmanagedType.LPStr)] string pszSrcDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszSrcRflDir, - [MarshalAs(UnmanagedType.LPStr)] string pszDestDbName, - [MarshalAs(UnmanagedType.LPStr)] string pszDestDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszDestRflDir, - DbCopyStatusCallback fnDbCopyStatus); + private static extern int xflaim_DbSystem_openBase64Encoder( + ulong pDbSystem, + ulong pInputIStream, + int bInsertLineBreaks, + out ulong ppIStream); + +//----------------------------------------------------------------------------- +// openBase64Decoder +//----------------------------------------------------------------------------- + + /// + /// Open an input stream that decodes data from another input stream. It is + /// assumed that data read from the original input stream is base 64 + /// encoded. + /// + /// + /// Input stream whose data is to be decoded. It is assumed that data read + /// from this stream is base 64 encoded. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an IStream object. + /// + public IStream openBase64Decoder( + IStream inputIStream) + { + int rc; + ulong pIStream = 0; + + if ((rc = xflaim_DbSystem_openBase64Decoder( m_pDbSystem, + inputIStream.getIStream(), out pIStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new IStream( pIStream, this)); + } [DllImport("xflaim",CharSet=CharSet.Ansi)] - private static extern int xflaim_DbSystem_dbRename( - ulong pDbSystem, - [MarshalAs(UnmanagedType.LPStr)] string pszSrcDbName, - [MarshalAs(UnmanagedType.LPStr)] string pszSrcDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszSrcRflDir, - [MarshalAs(UnmanagedType.LPStr)] string pszDestDbName, - int bOverwriteDestOk, - DbRenameStatusCallback fnDbRenameStatus); + private static extern int xflaim_DbSystem_openBase64Decoder( + ulong pDbSystem, + ulong pInputIStream, + out ulong ppIStream); + +//----------------------------------------------------------------------------- +// openFileOStream +//----------------------------------------------------------------------------- + + /// + /// Open an output stream that writes data to a file. + /// + /// + /// Name of file to write data to. + /// + /// + /// Flag indicating whether or not the output file + /// should be truncated if it already exists. If false, the file will be + /// appended to. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an OStream object. + /// + public OStream openFileOStream( + string sFileName, + bool bTruncateIfExists) + { + int rc; + ulong pOStream = 0; + + if ((rc = xflaim_DbSystem_openFileOStream( m_pDbSystem, + sFileName, (int)(bTruncateIfExists ? 1 : 0), out pOStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new OStream( pOStream, this)); + } [DllImport("xflaim",CharSet=CharSet.Ansi)] - private static extern int xflaim_DbSystem_dbRebuild( - ulong pDbSystem, - [MarshalAs(UnmanagedType.LPStr)] string pszSourceDbPath, - [MarshalAs(UnmanagedType.LPStr)] string pszSourceDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszDestDbPath, - [MarshalAs(UnmanagedType.LPStr)] string pszDestDataDir, - [MarshalAs(UnmanagedType.LPStr)] string pszDestRflDir, - [MarshalAs(UnmanagedType.LPStr)] string pszDictPath, - [MarshalAs(UnmanagedType.LPStr)] string pszPassword, - CREATE_OPTS pCreateOpts, - DbRebuildStatusCallback fnDbRebuildStatus); + private static extern int xflaim_DbSystem_openFileOStream( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszFileName, + int bTruncateIfExists, + out ulong ppOStream); - private ulong m_pDbSystem; +//----------------------------------------------------------------------------- +// openMultiFileOStream +//----------------------------------------------------------------------------- + + /// + /// Open a multi-file output stream. Data is written to one or more files. + /// + /// + /// Directory where output files are to be created. + /// + /// + /// Base name for creating file names. The first file will + /// be called sBaseName. Subsequent files will be named sBaseName.00000001, + /// sBaseName.00000002, etc. The extension is a hex number. + /// + /// + /// Maximum number of bytes to write to each file in the multi-file set. + /// + /// + /// Flag indicating whether or not the output files + /// should be overwritten if they already exist. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an OStream object. + /// + public OStream openMultiFileOStream( + string sDirectory, + string sBaseName, + uint uiMaxFileSize, + bool bOkToOverwrite) + { + int rc; + ulong pOStream = 0; + + if ((rc = xflaim_DbSystem_openMultiFileOStream( m_pDbSystem, + sDirectory, sBaseName, uiMaxFileSize, + (int)(bOkToOverwrite ? 1 : 0), out pOStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new OStream( pOStream, this)); + } + + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_openMultiFileOStream( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszDirectory, + [MarshalAs(UnmanagedType.LPStr)] + string sBaseName, + uint uiMaxFileSize, + int bOkToOverwrite, + out ulong ppOStream); + +//----------------------------------------------------------------------------- +// removeMultiFileStream +//----------------------------------------------------------------------------- + + /// + /// Remove a multi-file output stream from disk. + /// + /// + /// Directory where the files belonging to the output stream are located. + /// + /// + /// Base name for files belonging to the output stream. The first file will + /// be called sBaseName. Subsequent files will be named sBaseName.00000001, + /// sBaseName.00000002, etc. The extension is a hex number. + /// + public void removeMultiFileStream( + string sDirectory, + string sBaseName) + { + int rc; + + if ((rc = xflaim_DbSystem_removeMultiFileStream( m_pDbSystem, + sDirectory, sBaseName)) != 0) + { + throw new XFlaimException( rc); + } + } + + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_removeMultiFileStream( + ulong pDbSystem, + [MarshalAs(UnmanagedType.LPStr)] + string pszDirectory, + [MarshalAs(UnmanagedType.LPStr)] + string sBaseName); + +//----------------------------------------------------------------------------- +// openBufferedOStream +//----------------------------------------------------------------------------- + + /// + /// Open a buffered output stream. A buffer is allocated for writing data to + /// the original output stream. Instead of writing small chunks of data to + /// the original output stream, it is first gathered into the output buffer. + /// When the output buffer fills, the entire buffer is sent to the original + /// output stream with a single write. The idea is that by buffering the + /// output data, performance can be improved. + /// + /// + /// Output stream that the data is ultimately going to be written to - but it + /// will be buffered before being written. + /// + /// + /// Size of the buffer to be used for buffering output. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an OStream object. + /// + public OStream openBufferedOStream( + OStream inputOStream, + uint uiBufferSize) + { + int rc; + ulong pOStream = 0; + + if ((rc = xflaim_DbSystem_openBufferedOStream( m_pDbSystem, + inputOStream.getOStream(), uiBufferSize, out pOStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new OStream( pOStream, this)); + } + + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_openBufferedOStream( + ulong pDbSystem, + ulong pInputOStream, + uint uiBufferSize, + out ulong ppOStream); + +//----------------------------------------------------------------------------- +// openCompressingOStream +//----------------------------------------------------------------------------- + + /// + /// Open a compressing output stream. Data is compressed before writing it + /// out to the passed in output stream object. + /// + /// + /// Output stream that the data is ultimately going to be written to - but it + /// will be compressed before being written. + /// + /// + /// Returns an object that can then be passed to + /// methods which require an OStream object. + /// + public OStream openCompressingOStream( + OStream inputOStream) + { + int rc; + ulong pOStream = 0; + + if ((rc = xflaim_DbSystem_openCompressingOStream( m_pDbSystem, + inputOStream.getOStream(), out pOStream)) != 0) + { + throw new XFlaimException( rc); + } + return( new OStream( pOStream, this)); + } + + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_openCompressingOStream( + ulong pDbSystem, + ulong pInputOStream, + out ulong ppOStream); + +//----------------------------------------------------------------------------- +// writeToOStream +//----------------------------------------------------------------------------- + + /// + /// Read data from an input stream and write it out to an output stream. This + /// is a quick way to copy all data from an input stream to an output stream. + /// + /// + /// Input stream data is to be read from. + /// + /// + /// Output stream data is to be written to. + /// + public void writeToOStream( + IStream istream, + OStream ostream) + { + int rc; + + if ((rc = xflaim_DbSystem_writeToOStream( m_pDbSystem, + istream.getIStream(), ostream.getOStream())) != 0) + { + throw new XFlaimException( rc); + } + } + + [DllImport("xflaim",CharSet=CharSet.Ansi)] + private static extern int xflaim_DbSystem_writeToOStream( + ulong pDbSystem, + ulong pIStream, + ulong pOStream); } } diff --git a/xflaim/csharp/xflaim/IStream.cpp b/xflaim/csharp/xflaim/IStream.cpp new file mode 100644 index 0000000..8ad940a --- /dev/null +++ b/xflaim/csharp/xflaim/IStream.cpp @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +// Desc: Native C routines to support C# IStream class +// +// Tabs: 3 +// +// Copyright (c) 2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id$ +//------------------------------------------------------------------------------ + +#include "xflaim.h" + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP void FLMAPI xflaim_IStream_Release( + FLMUINT64 ui64This) +{ + IF_IStream * pIStream = ((IF_IStream *)(FLMUINT)ui64This); + + if (pIStream) + { + pIStream->Release(); + } +} diff --git a/xflaim/csharp/xflaim/IStream.cs b/xflaim/csharp/xflaim/IStream.cs new file mode 100644 index 0000000..eb225b4 --- /dev/null +++ b/xflaim/csharp/xflaim/IStream.cs @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// Desc: Input Stream +// +// Tabs: 3 +// +// Copyright (c) 2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id$ +//------------------------------------------------------------------------------ + +using System; +using System.Runtime.InteropServices; + +namespace xflaim +{ + + /// + /// The IStream class encapsulates an IF_IStream object that was allocated + /// in unmanaged space. It will make sure that the stream object will be + /// freed when the C# IStream object goes away. + /// NOTE: This object should NEVER be allocated by an application directly. + /// It is returned from various methods in the class, + /// such as , + /// , etc. + /// + public class IStream + { + private ulong m_pIStream; // Pointer to IF_IStream object allocated in unmanaged space. + private DbSystem m_dbSystem; + + /// + /// Constructor. + /// + /// + /// Pointer to IF_IStream object that was allocated from unmanaged space. + /// + /// + /// Pointer to object. + /// + internal IStream( + ulong pIStream, + DbSystem dbSystem) + { + if (pIStream == 0) + { + throw new XFlaimException( "Invalid IF_IStream object pointer"); + } + + m_pIStream = pIStream; + + if (dbSystem == null) + { + throw new XFlaimException( "Invalid DbSystem object"); + } + + m_dbSystem = dbSystem; + + // Must call something inside of DbSystem. Otherwise, the + // m_dbSystem object gets a compiler warning on linux because + // it is not used anywhere. Other than that, there is really + // no need to make the following call. + if (m_dbSystem.getDbSystem() == 0) + { + throw new XFlaimException( "Invalid DbSystem.IF_DbSystem object"); + } + } + + /// + /// Destructor + /// + ~IStream() + { + if (m_pIStream != 0) + { + xflaim_IStream_Release( m_pIStream); + m_pIStream = 0; + } + + m_dbSystem = null; + } + + [DllImport("xflaim")] + private static extern void xflaim_IStream_Release( + ulong pIStream); + + internal ulong getIStream() + { + return( m_pIStream); + } + } +} diff --git a/xflaim/csharp/xflaim/OStream.cpp b/xflaim/csharp/xflaim/OStream.cpp new file mode 100644 index 0000000..1abcc64 --- /dev/null +++ b/xflaim/csharp/xflaim/OStream.cpp @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +// Desc: Native C routines to support C# OStream class +// +// Tabs: 3 +// +// Copyright (c) 2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id$ +//------------------------------------------------------------------------------ + +#include "xflaim.h" + +/**************************************************************************** +Desc: +****************************************************************************/ +FLMEXTC FLMEXP void FLMAPI xflaim_OStream_Release( + FLMUINT64 ui64This) +{ + IF_OStream * pOStream = ((IF_OStream *)(FLMUINT)ui64This); + + if (pOStream) + { + pOStream->Release(); + } +} diff --git a/xflaim/csharp/xflaim/OStream.cs b/xflaim/csharp/xflaim/OStream.cs new file mode 100644 index 0000000..93e354a --- /dev/null +++ b/xflaim/csharp/xflaim/OStream.cs @@ -0,0 +1,106 @@ +//------------------------------------------------------------------------------ +// Desc: Output Stream +// +// Tabs: 3 +// +// Copyright (c) 2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id$ +//------------------------------------------------------------------------------ + +using System; +using System.Runtime.InteropServices; + +namespace xflaim +{ + + /// + /// The OStream class encapsulates an IF_OStream object that was allocated + /// in unmanaged space. It will make sure that the stream object will be + /// freed when the C# OStream object goes away. + /// NOTE: This object should NEVER be allocated by an application directly. + /// It is returned from various methods in the class, + /// such as , + /// , etc. + /// + public class OStream + { + private ulong m_pOStream; // Pointer to IF_OStream object allocated in unmanaged space. + private DbSystem m_dbSystem; + + /// + /// Constructor. + /// + /// + /// Pointer to IF_OStream object that was allocated from unmanaged space. + /// + /// + /// Pointer to object. + /// + internal OStream( + ulong pOStream, + DbSystem dbSystem) + { + if (pOStream == 0) + { + throw new XFlaimException( "Invalid IF_OStream object pointer"); + } + + m_pOStream = pOStream; + + if (dbSystem == null) + { + throw new XFlaimException( "Invalid DbSystem object"); + } + + m_dbSystem = dbSystem; + + // Must call something inside of DbSystem. Otherwise, the + // m_dbSystem object gets a compiler warning on linux because + // it is not used anywhere. Other than that, there is really + // no need to make the following call. + if (m_dbSystem.getDbSystem() == 0) + { + throw new XFlaimException( "Invalid DbSystem.IF_DbSystem object"); + } + } + + /// + /// Destructor + /// + ~OStream() + { + if (m_pOStream != 0) + { + xflaim_OStream_Release( m_pOStream); + m_pOStream = 0; + } + + m_dbSystem = null; + } + + [DllImport("xflaim")] + private static extern void xflaim_OStream_Release( + ulong pOStream); + + internal ulong getOStream() + { + return( m_pOStream); + } + } +}