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
This commit is contained in:
dsandersoremutah
2006-09-21 14:48:17 +00:00
parent 9814449322
commit 270f6f1713
13 changed files with 1474 additions and 201 deletions

View File

@@ -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;
}
}
}

View File

@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// Desc:
// Desc: Native C routines to support C# Backup class
//
// Tabs: 3
//

View File

@@ -34,6 +34,8 @@ namespace xflaim
/// </summary>
public class Backup
{
private ulong m_pBackup; // Pointer to IF_Backup object in unmanaged space
private Db m_db;
/// <summary>
/// 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
//-----------------------------------------------------------------------------
/// <summary>
/// Get the transaction ID for this backup operation.
/// </summary>
@@ -96,6 +106,14 @@ namespace xflaim
return( xflaim_Backup_getBackupTransId( m_pBackup));
}
[DllImport("xflaim")]
private static extern ulong xflaim_Backup_getBackupTransId(
ulong pBackup);
//-----------------------------------------------------------------------------
// getLastBackupTransId
//-----------------------------------------------------------------------------
/// <summary>
/// Gets the transaction ID for the last backup job run on this database.
/// </summary>
@@ -108,6 +126,14 @@ namespace xflaim
return( xflaim_Backup_getLastBackupTransId( m_pBackup));
}
[DllImport("xflaim")]
private static extern ulong xflaim_Backup_getLastBackupTransId(
ulong pBackup);
//-----------------------------------------------------------------------------
// backup
//-----------------------------------------------------------------------------
/// <summary>
/// Performs the backup operation. The <paramref name="sBackupPath"/> and
/// <paramref name="backupClient"/> 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
//-----------------------------------------------------------------------------
/// <summary>
/// Ends the backup operation.
/// </summary>
@@ -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;
}
}

View File

@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// Desc:
// Desc: Native C routines to support C# Db class
//
// Tabs: 3
//

View File

@@ -36,6 +36,8 @@ namespace xflaim
/// </remarks>
public class Db
{
private ulong m_pDb; // Pointer to IF_Db object in unmanaged space
private DbSystem m_dbSystem;
/// <summary>
/// Db constructor.
@@ -46,7 +48,7 @@ namespace xflaim
/// <param name="dbSystem">
/// DbSystem object that this Db object is associated with.
/// </param>
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.
/// </summary>
/// <returns>Returns a pointer to the IF_Db object.</returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Sets up a backup operation.
/// </summary>
@@ -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);
/// <summary>
/// Reference to C++ IF_Db object.
/// </summary>
public ulong m_pDb;
private DbSystem m_dbSystem;
}
}

View File

@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// Desc: Database Info
// Desc: Native C routines to support C# DbInfo class
//
// Tabs: 3
//

View File

@@ -124,13 +124,15 @@ namespace xflaim
/// </summary>
public class DbInfo
{
private ulong m_pDbInfo; // Pointer to IF_DbInfo object in unmanaged space
/// <summary>
/// Constructor
/// </summary>
/// <param name="pDbInfo">
/// Pointer to IF_DbInfo object allocated in unmanaged space.
/// </param>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Returns the number of collections in the database.
/// </summary>
@@ -162,6 +172,14 @@ namespace xflaim
return( xflaim_DbInfo_getNumCollections( m_pDbInfo));
}
[DllImport("xflaim")]
private static extern uint xflaim_DbInfo_getNumCollections(
ulong pDbInfo);
//-----------------------------------------------------------------------------
// getNumIndexes
//-----------------------------------------------------------------------------
/// <summary>
/// Returns the number of indexes in the database.
/// </summary>
@@ -171,6 +189,14 @@ namespace xflaim
return( xflaim_DbInfo_getNumIndexes( m_pDbInfo));
}
[DllImport("xflaim")]
private static extern uint xflaim_DbInfo_getNumIndexes(
ulong pDbInfo);
//-----------------------------------------------------------------------------
// getNumLogicalFiles
//-----------------------------------------------------------------------------
/// <summary>
/// Returns the total number of collections and indexes in the database.
/// </summary>
@@ -180,6 +206,14 @@ namespace xflaim
return( xflaim_DbInfo_getNumLogicalFiles( m_pDbInfo));
}
[DllImport("xflaim")]
private static extern uint xflaim_DbInfo_getNumLogicalFiles(
ulong pDbInfo);
//-----------------------------------------------------------------------------
// getDatabaseSize
//-----------------------------------------------------------------------------
/// <summary>
/// Returns the total size of the database (in bytes).
/// </summary>
@@ -189,6 +223,14 @@ namespace xflaim
return( xflaim_DbInfo_getDatabaseSize( m_pDbInfo));
}
[DllImport("xflaim")]
private static extern ulong xflaim_DbInfo_getDatabaseSize(
ulong pDbInfo);
//-----------------------------------------------------------------------------
// getDbHdr
//-----------------------------------------------------------------------------
/// <summary>
/// Get the database header
/// </summary>
@@ -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
//-----------------------------------------------------------------------------
/// <summary>
/// Return statistics on blocks in the avail list.
/// </summary>
@@ -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
//-----------------------------------------------------------------------------
/// <summary>
/// Return statistics for blocks in the logical file header block list.
/// </summary>
@@ -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
//-----------------------------------------------------------------------------
/// <summary>
/// Returns information about a particular B-Tree in the database
/// </summary>
@@ -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
//-----------------------------------------------------------------------------
/// <summary>
/// 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;
}
}

View File

@@ -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));
}

View File

@@ -250,6 +250,7 @@ namespace xflaim
/// </remarks>
public class DbSystem
{
private ulong m_pDbSystem; // Pointer to IF_DbSystem object in unmanaged space
/// <summary>
/// DbSystem constructor.
@@ -264,6 +265,10 @@ namespace xflaim
}
}
[DllImport("xflaim")]
private static extern int xflaim_DbSystem_createDbSystem(
out ulong ppDbSystem);
/// <summary>
/// DbSystem destructor.
/// </summary>
@@ -273,11 +278,15 @@ namespace xflaim
m_pDbSystem = 0;
}
[DllImport("xflaim")]
private static extern int xflaim_DbSystem_Release(
ulong pDbSystem);
/// <summary>
/// Called by <see cref="Db"/> class to silence compiler warning.
/// Has no other important use!
/// </summary>
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);
/// <summary>
/// Open an input stream that reads from a string buffer.
/// </summary>
/// <param name="sBuffer">
/// String the input stream is to read from.
/// </param>
/// <returns>
/// Returns an <see cref="IStream"/> object that can then be passed to
/// methods which require an IStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Open an input stream that reads from a file.
/// </summary>
/// <param name="sFileName">
/// Name of the file the input stream is to read from.
/// </param>
/// <returns>
/// Returns an <see cref="IStream"/> object that can then be passed to
/// methods which require an IStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Open an input stream that reads from multiple files.
/// </summary>
/// <param name="sDirectory">
/// Name of the directory where the multiple files are to be found.
/// </param>
/// <param name="sBaseName">
/// 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.
/// </param>
/// <returns>
/// Returns an <see cref="IStream"/> object that can then be passed to
/// methods which require an IStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Open an input stream that buffers an existing input stream.
/// </summary>
/// <param name="inputIStream">
/// Input stream that is to be buffered.
/// </param>
/// <param name="uiBufferSize">
/// 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.
/// </param>
/// <returns>
/// Returns an <see cref="IStream"/> object that can then be passed to
/// methods which require an IStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// 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.
/// </summary>
/// <param name="inputIStream">
/// Input stream whose data is to be decompressed.
/// </param>
/// <returns>
/// Returns an <see cref="IStream"/> object that can then be passed to
/// methods which require an IStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// 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.
/// </summary>
/// <param name="inputIStream">
/// Input stream whose data is to be base 64 encoded.
/// </param>
/// <param name="bInsertLineBreaks">
/// Flag indicating whether or not line breaks
/// should be inserted into the data as it is base 64 encoded.
/// </param>
/// <returns>
/// Returns an <see cref="IStream"/> object that can then be passed to
/// methods which require an IStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// 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.
/// </summary>
/// <param name="inputIStream">
/// Input stream whose data is to be decoded. It is assumed that data read
/// from this stream is base 64 encoded.
/// </param>
/// <returns>
/// Returns an <see cref="IStream"/> object that can then be passed to
/// methods which require an IStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Open an output stream that writes data to a file.
/// </summary>
/// <param name="sFileName">
/// Name of file to write data to.
/// </param>
/// <param name="bTruncateIfExists">
/// Flag indicating whether or not the output file
/// should be truncated if it already exists. If false, the file will be
/// appended to.
/// </param>
/// <returns>
/// Returns an <see cref="OStream"/> object that can then be passed to
/// methods which require an OStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Open a multi-file output stream. Data is written to one or more files.
/// </summary>
/// <param name="sDirectory">
/// Directory where output files are to be created.
/// </param>
/// <param name="sBaseName">
/// 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.
/// </param>
/// <param name="uiMaxFileSize">
/// Maximum number of bytes to write to each file in the multi-file set.
/// </param>
/// <param name="bOkToOverwrite">
/// Flag indicating whether or not the output files
/// should be overwritten if they already exist.
/// </param>
/// <returns>
/// Returns an <see cref="OStream"/> object that can then be passed to
/// methods which require an OStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Remove a multi-file output stream from disk.
/// </summary>
/// <param name="sDirectory">
/// Directory where the files belonging to the output stream are located.
/// </param>
/// <param name="sBaseName">
/// 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.
/// </param>
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
//-----------------------------------------------------------------------------
/// <summary>
/// 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.
/// </summary>
/// <param name="inputOStream">
/// Output stream that the data is ultimately going to be written to - but it
/// will be buffered before being written.
/// </param>
/// <param name="uiBufferSize">
/// Size of the buffer to be used for buffering output.
/// </param>
/// <returns>
/// Returns an <see cref="OStream"/> object that can then be passed to
/// methods which require an OStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// Open a compressing output stream. Data is compressed before writing it
/// out to the passed in output stream object.
/// </summary>
/// <param name="inputOStream">
/// Output stream that the data is ultimately going to be written to - but it
/// will be compressed before being written.
/// </param>
/// <returns>
/// Returns an <see cref="OStream"/> object that can then be passed to
/// methods which require an OStream object.
/// </returns>
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
//-----------------------------------------------------------------------------
/// <summary>
/// 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.
/// </summary>
/// <param name="istream">
/// Input stream data is to be read from.
/// </param>
/// <param name="ostream">
/// Output stream data is to be written to.
/// </param>
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);
}
}

View File

@@ -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();
}
}

View File

@@ -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
{
/// <summary>
/// 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 <see cref="DbSystem"/> class,
/// such as <see cref="DbSystem.openBufferIStream"/>,
/// <see cref="DbSystem.openFileIStream"/>, etc.
/// </summary>
public class IStream
{
private ulong m_pIStream; // Pointer to IF_IStream object allocated in unmanaged space.
private DbSystem m_dbSystem;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="pIStream">
/// Pointer to IF_IStream object that was allocated from unmanaged space.
/// </param>
/// <param name="dbSystem">
/// Pointer to <see cref="DbSystem"/> object.
/// </param>
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");
}
}
/// <summary>
/// Destructor
/// </summary>
~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);
}
}
}

View File

@@ -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();
}
}

View File

@@ -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
{
/// <summary>
/// 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 <see cref="DbSystem"/> class,
/// such as <see cref="DbSystem.openFileOStream"/>,
/// <see cref="DbSystem.openMultiFileOStream"/>, etc.
/// </summary>
public class OStream
{
private ulong m_pOStream; // Pointer to IF_OStream object allocated in unmanaged space.
private DbSystem m_dbSystem;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="pOStream">
/// Pointer to IF_OStream object that was allocated from unmanaged space.
/// </param>
/// <param name="dbSystem">
/// Pointer to <see cref="DbSystem"/> object.
/// </param>
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");
}
}
/// <summary>
/// Destructor
/// </summary>
~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);
}
}
}