diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:18:43 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 14:18:43 +0000 |
commit | 215e8c7210756d6d9033f8d742a6cd0e9be132aa (patch) | |
tree | d1a56131d83c8298e6183cf17b912037ae63b9c9 /store/workben |
initial import
Diffstat (limited to 'store/workben')
-rw-r--r-- | store/workben/makefile.mk | 135 | ||||
-rw-r--r-- | store/workben/t_base.cxx | 376 | ||||
-rw-r--r-- | store/workben/t_file.cxx | 166 | ||||
-rw-r--r-- | store/workben/t_store.cxx | 634 |
4 files changed, 1311 insertions, 0 deletions
diff --git a/store/workben/makefile.mk b/store/workben/makefile.mk new file mode 100644 index 000000000..1d2965f9b --- /dev/null +++ b/store/workben/makefile.mk @@ -0,0 +1,135 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 15:18:32 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=.. + +PRJNAME=store +TARGET=workben + +LIBTARGET=NO +TARGETTYPE=CUI + +# --- Settings --- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +.IF "$(STORELIB)" == "" +.IF "$(GUI)" == "UNX" +STOLIB= -lsto$(UPD)$(DLLPOSTFIX) +.ELSE # unx +STOLIB= $(LB)$/istore.lib +.ENDIF # unx +.ENDIF # storelib + +.IF "$(GUI)" == "UNX" +STODBGLIB= $(LB)$/libstodbg.a +.ELSE # unx +STODBGLIB= $(LB)$/stodbg.lib +.ENDIF # unx + +CFLAGS+= -I..$/source + +# --- Files --- + +CXXFILES= \ + t_file.cxx \ + t_base.cxx \ + t_store.cxx + +OBJFILES= \ + $(OBJ)$/t_file.obj \ + $(OBJ)$/t_base.obj \ + $(OBJ)$/t_store.obj + +APP1TARGET= t_file +APP1OBJS= $(OBJ)$/t_file.obj +APP1STDLIBS= $(STODBGLIB) +APP1STDLIBS+= $(VOSLIB) $(SALLIB) +APP1DEPN= \ + $(STODBGLIB) \ + $(L)$/ivos.lib \ + $(L)$/isal.lib + +APP2TARGET= t_base +APP2OBJS= $(OBJ)$/t_base.obj +APP2STDLIBS= $(STODBGLIB) +APP2STDLIBS+= $(VOSLIB) $(SALLIB) +APP2DEPN= \ + $(STODBGLIB) \ + $(L)$/ivos.lib \ + $(L)$/isal.lib + +APP3TARGET= t_store +APP3OBJS= $(OBJ)$/t_store.obj +APP3STDLIBS= $(STORELIB) +APP3STDLIBS+= $(VOSLIB) $(SALLIB) +APP3DEPN= \ + $(SLB)$/store.lib \ + $(L)$/ivos.lib \ + $(L)$/isal.lib + +# --- Targets --- + +.INCLUDE : target.mk + diff --git a/store/workben/t_base.cxx b/store/workben/t_base.cxx new file mode 100644 index 000000000..078bf1aea --- /dev/null +++ b/store/workben/t_base.cxx @@ -0,0 +1,376 @@ +/************************************************************************* + * + * $RCSfile: t_base.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:32 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _T_BASE_CXX "$Revision: 1.1.1.1 $" + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#ifndef _RTL_MEMORY_H_ +#include <rtl/memory.h> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _VOS_MACROS_HXX_ +#include <vos/macros.hxx> +#endif +#ifndef _VOS_REF_HXX_ +#include <vos/ref.hxx> +#endif + +#ifndef _STORE_FILELCKB_HXX_ +#include <store/filelckb.hxx> +#endif + +#ifndef _STORE_STORBASE_HXX_ +#include "storbase.hxx" +#endif + +#ifdef _USE_NAMESPACE +using namespace store; +#endif + +#define TEST_PAGESIZE 1024 + +/*======================================================================== + * + * OTestBIOS. + * + *======================================================================*/ +class OTestBIOS : public NAMESPACE_STORE(OStorePageBIOS) +{ + typedef NAMESPACE_STORE(OStorePageBIOS) base; + +public: + OTestBIOS (void); + + virtual storeError initialize ( + ILockBytes *pLockBytes, + storeAccessMode eAccessMode); + +protected: + virtual ~OTestBIOS (void); +}; + +OTestBIOS::OTestBIOS (void) +{ +} + +OTestBIOS::~OTestBIOS (void) +{ +} + +storeError OTestBIOS::initialize ( + ILockBytes *pLockBytes, storeAccessMode eAccessMode) +{ + storeError eErrCode = base::initialize (pLockBytes, eAccessMode); + if (eErrCode != store_E_None) + { + if (eAccessMode == store_AccessReadWrite) + return eErrCode; + if (eAccessMode == store_AccessReadOnly) + return eErrCode; + if (eErrCode != store_E_NotExists) + return eErrCode; + + eErrCode = base::create (TEST_PAGESIZE); + } + return eErrCode; +} + +/*======================================================================== + * + * unicode. + * + *======================================================================*/ +static void __store_string_newFromUnicode_WithLength ( + rtl_String **newString, const sal_Unicode *value, sal_Int32 length) +{ + rtl_uString2String ( + newString, + value, length, + RTL_TEXTENCODING_UTF8, + OUSTRING_TO_OSTRING_CVTFLAGS); +} + +static void __store_string_newFromUnicode ( + rtl_String **newString, const rtl_uString *value) +{ + __store_string_newFromUnicode_WithLength ( + newString, value->buffer, value->length); +} + +static void __store_string_newFromUnicode ( + rtl_String **newString, const sal_Unicode *value) +{ + __store_string_newFromUnicode_WithLength ( + newString, value, rtl_ustr_getLength (value)); +} + +static storeError __store_namei ( + const NAMESPACE_RTL(OString) &rPath, + const NAMESPACE_RTL(OString) &rName, + OStorePageKey &rKey) +{ +} + +static storeError __store_namei ( + const sal_Unicode *pszPath, + const sal_Unicode *pszName, + OStorePageKey &rKey) +{ + NAMESPACE_RTL(OString) aName ( + pszName, rtl_ustr_getLength (pszName), RTL_TEXTENCODING_UTF8); + + + rtl_String *pszNameA = 0; + __store_string_newFromUnicode (&pszNameA, pszName); + + storeError eErrCode = store_E_NameTooLong; + if (pszNameA->length < sizeof(sal_Char[STORE_MAXIMUM_NAMESIZE])) + { + rtl_String *pszPathA = 0; + __store_string_newFromUnicode (&pszPathA, pszPath); + + typedef OStorePageGuard G; + rKey.m_nLow = G::crc32 (0, pszNameA->buffer, pszNameA->length); + rKey.m_nHigh = G::crc32 (0, pszPathA->buffer, pszPathA->length); + + rtl_string_release (pszPathA); + eErrCode = store_E_None; + } + + rtl_string_release (pszNameA); + return eErrCode; +} + +static sal_Int32 __store_convertTextToUnicode ( + rtl_TextToUnicodeConverter hConvert, + const sal_Char *pszText, sal_Int32 nTextLen, + sal_Unicode *pBuffer, sal_Int32 nBuffer) +{ + sal_uInt32 nInfo, nSrcLen = 0; + + sal_Int32 nDstLen = rtl_convertTextToUnicode ( + hConvert, 0, + pszText, nTextLen, + pBuffer, nBuffer, + OSTRING_TO_OUSTRING_CVTFLAGS, + &nInfo, &nSrcLen); + + pBuffer[nDstLen] = 0; + return nDstLen; +} + +struct MyFindData +{ + sal_Unicode m_pszName[STORE_MAXIMUM_NAMESIZE]; + sal_Int32 m_nLength; + sal_uInt32 m_nAttrib; + sal_uInt32 m_nSize; + sal_uInt32 m_nReserved; +}; + +static void __store_testUnicode (const sal_Char *pszFilename) +{ + // ... + rtl_TextToUnicodeConverter hConvert; + hConvert = rtl_createTextToUnicodeConverter (RTL_TEXTENCODING_UTF8); + + MyFindData it; + rtl_zeroMemory (&it, sizeof(it)); + + sal_Int32 n = rtl_str_getLength (pszFilename); + n = __store_convertTextToUnicode ( + hConvert, pszFilename, n, + it.m_pszName, STORE_MAXIMUM_NAMESIZE - 1); + if (it.m_nLength > n) + rtl_zeroMemory ( + &it.m_pszName[n], ((it.m_nLength - n) * sizeof(sal_Unicode))); + it.m_nLength = n; + + rtl_destroyTextToUnicodeConverter (hConvert); + + // ... + rtl_String *pszFileA = NULL; + rtl_uString *pszFileW = NULL; + + // rtl_uString_newFromAscii (&pszFileW, pszFilename); + + // ... + rtl_string_newFromStr (&pszFileA, pszFilename); + + rtl_string2UString ( + &pszFileW, + pszFileA->buffer, pszFileA->length, + RTL_TEXTENCODING_MS_1252, + OSTRING_TO_OUSTRING_CVTFLAGS); + + rtl_string_release (pszFileA); + + // ... + OStorePageKey aKey; + __store_namei (pszFileW->buffer, pszFileW->buffer, aKey); + + // ... + rtl_uString2String ( + &pszFileA, + pszFileW->buffer, pszFileW->length, + RTL_TEXTENCODING_UTF8, + OUSTRING_TO_OSTRING_CVTFLAGS); + + rtl_uString_release (pszFileW); + + // ... + rtl_string_release (pszFileA); +} + +/*======================================================================== + * + * __store_getProcessTextEncoding. + * + *======================================================================*/ +inline rtl_TextEncoding __store_getProcessTextEncoding (void) +{ + rtl_TextEncoding eEncoding; +#if defined(SAL_OS2) + eEncoding = RTL_TEXTENCODING_IBM850; +#elif defined(SAL_UNX) + eEncoding = RTL_TEXTENCODING_ISO8859_1; +#elif defined(SAL_W32) + eEncoding = RTL_TEXTENCODING_MS_1252; +#else + eEncoding = RTL_TEXTENCODING_ASCII_US; +#endif + return eEncoding; +} + +/*======================================================================== + * + * main. + * + *======================================================================*/ +int SAL_CALL main (int argc, char **argv) +{ + if (argc < 2) + return 0; + +#if 0 /* EXP */ + __store_testUnicode (argv[1]); +#endif /* EXP */ + + NAMESPACE_VOS(ORef)<OFileLockBytes> xLockBytes (new OFileLockBytes()); + if (!xLockBytes.isValid()) + return 0; + + NAMESPACE_RTL(OUString) aFilename ( + argv[1], rtl_str_getLength(argv[1]), + __store_getProcessTextEncoding()); + + storeError eErrCode = xLockBytes->create ( + aFilename.pData, store_AccessReadCreate); + if (eErrCode != store_E_None) + return eErrCode; + + NAMESPACE_VOS(ORef)<OTestBIOS> xBIOS (new OTestBIOS()); + if (!xBIOS.isValid()) + return 0; + + eErrCode = xBIOS->initialize (&*xLockBytes, store_AccessReadWrite); + if (eErrCode != store_E_None) + { + // Check reason. + if (eErrCode != store_E_NotExists) + return eErrCode; + + // Create. + eErrCode = xBIOS->initialize (&*xLockBytes, store_AccessReadCreate); + if (eErrCode != store_E_None) + return eErrCode; + } + xLockBytes.unbind(); + + sal_Char pBuffer[TEST_PAGESIZE]; + rtl_zeroMemory (pBuffer, sizeof (pBuffer)); + rtl_copyMemory (pBuffer, argv[0], rtl_str_getLength(argv[0]) + 1); + + eErrCode = xBIOS->acquireLock (TEST_PAGESIZE, sizeof(pBuffer)); + if (eErrCode != store_E_None) + return eErrCode; + + eErrCode = xBIOS->write (TEST_PAGESIZE, pBuffer, sizeof (pBuffer)); + if (eErrCode != store_E_None) + { + xBIOS->releaseLock (TEST_PAGESIZE, sizeof(pBuffer)); + return eErrCode; + } + + eErrCode = xBIOS->releaseLock (TEST_PAGESIZE, sizeof(pBuffer)); + if (eErrCode != store_E_None) + return eErrCode; + + xBIOS.unbind(); + return 0; +} + diff --git a/store/workben/t_file.cxx b/store/workben/t_file.cxx new file mode 100644 index 000000000..eddebc8db --- /dev/null +++ b/store/workben/t_file.cxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * $RCSfile: t_file.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:32 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _T_FILE_CXX "$Revision: 1.1.1.1 $" + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _VOS_MACROS_HXX_ +#include <vos/macros.hxx> +#endif +#ifndef _VOS_REF_HXX_ +#include <vos/ref.hxx> +#endif + +#ifndef _STORE_FILELCKB_HXX_ +#include <store/filelckb.hxx> +#endif + +#ifdef _USE_NAMESPACE +using namespace store; +#endif + +/*======================================================================== + * + * __store_getProcessTextEncoding. + * + *======================================================================*/ +inline rtl_TextEncoding __store_getProcessTextEncoding (void) +{ + rtl_TextEncoding eEncoding; +#if defined(SAL_OS2) + eEncoding = RTL_TEXTENCODING_IBM850; +#elif defined(SAL_UNX) + eEncoding = RTL_TEXTENCODING_ISO8859_1; +#elif defined(SAL_W32) + eEncoding = RTL_TEXTENCODING_MS_1252; +#else + eEncoding = RTL_TEXTENCODING_ASCII_US; +#endif + return eEncoding; +} + +/*======================================================================== + * + * main. + * + *======================================================================*/ +int SAL_CALL main (int argc, char **argv) +{ + if (argc < 2) + return 0; + + NAMESPACE_VOS(ORef)<OFileLockBytes> xLockBytes (new OFileLockBytes()); + if (!xLockBytes.isValid()) + return 0; + + NAMESPACE_RTL(OUString) aFilename ( + argv[1], rtl_str_getLength(argv[1]), + __store_getProcessTextEncoding()); + + storeError eErrCode = xLockBytes->create ( + aFilename.pData, store_AccessReadWrite); + if (eErrCode != store_E_None) + { + // Check reason. + if (eErrCode != store_E_NotExists) + return eErrCode; + + // Create. + eErrCode = xLockBytes->create ( + aFilename.pData, store_AccessReadCreate); + if (eErrCode != store_E_None) + return eErrCode; + } + + sal_uInt32 k = 0; + eErrCode = xLockBytes->writeAt ( + 0, argv[0], rtl_str_getLength(argv[0]), k); + if (eErrCode != store_E_None) + return eErrCode; + + eErrCode = xLockBytes->setSize (1024); + if (eErrCode != store_E_None) + return eErrCode; + + eErrCode = xLockBytes->writeAt ( + 1024, argv[1], rtl_str_getLength(argv[1]), k); + if (eErrCode != store_E_None) + return eErrCode; + + eErrCode = xLockBytes->setSize (2048); + if (eErrCode != store_E_None) + return eErrCode; + + eErrCode = xLockBytes->flush(); + if (eErrCode != store_E_None) + return eErrCode; + + xLockBytes.unbind(); + return 0; +} + diff --git a/store/workben/t_store.cxx b/store/workben/t_store.cxx new file mode 100644 index 000000000..d017e92dd --- /dev/null +++ b/store/workben/t_store.cxx @@ -0,0 +1,634 @@ +/************************************************************************* + * + * $RCSfile: t_store.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 15:18:32 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _T_STORE_CXX "$Revision: 1.1.1.1 $" + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _OSL_TIME_H_ +#include <osl/time.h> +#endif + +#ifndef _RTL_CHAR_H_ +#include <rtl/char.h> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _VOS_THREAD_HXX_ +#include <vos/thread.hxx> +#endif + +#ifndef _STORE_MACROS_HXX_ +#include <store/macros.hxx> +#endif +#ifndef _STORE_STORE_HXX_ +#include <store/store.hxx> +#endif + +#include <stdio.h> + +#if (defined(WNT) && defined(PROFILE)) +extern "C" +{ + void StartCAP (void); + void StopCAP (void); + void DumpCAP (void); +} +#endif /* PROFILE */ + +using namespace rtl; + +/*======================================================================== + * + * Internals. + * + *======================================================================*/ +#define _DEMOSTOR_BUFSIZ 512 /* 4096, 1024, 512 */ +#define _DEMOSTOR_LOOPS 1000 /* 1000, 2000 */ + +#define _DEMOSTOR_REMOVE 0 +#define _DEMOSTOR_REBUILD 0 + +enum Options +{ + OPTION_HELP = 0x0001, + OPTION_FILE = 0x0002, + OPTION_PAUSE = 0x0004, + OPTION_REBUILD = 0x0008, + + OPTION_DUMP = 0x0010, + OPTION_ITER = 0x0020, + OPTION_LINK = 0x0040, + + OPTION_READ = 0x0100, + OPTION_WRITE = 0x0200, + OPTION_CREAT = 0x0400, + OPTION_TRUNC = 0x0800 +}; + +/*======================================================================== + * + * Timing. + * + *======================================================================*/ +struct OTime : public TimeValue +{ + OTime (void) + { + Seconds = 0; + Nanosec = 0; + } + + static OTime getSystemTime (void) + { + OTime tv; + osl_getSystemTime (&tv); + return tv; + } + + OTime& operator-= (const OTime& rPast) + { + Seconds -= rPast.Seconds; + if (Nanosec < rPast.Nanosec) + { + Seconds -= 1; + Nanosec += 1000000000; + } + Nanosec -= rPast.Nanosec; + return *this; + } + + friend OTime operator- (const OTime& rTimeA, const OTime& rTimeB) + { + OTime aTimeC (rTimeA); + aTimeC -= rTimeB; + return aTimeC; + } +}; + +/*======================================================================== + * + * DirectoryTraveller. + * + *======================================================================*/ +typedef NAMESPACE_STORE(OStoreDirectory) Directory; + +class DirectoryTraveller : public Directory::traveller +{ + typedef NAMESPACE_STORE(OStoreFile) file; + typedef Directory::iterator iter; + + NAMESPACE_STORE(OStoreFile) m_aFile; + OUString m_aPath; + + sal_uInt32 m_nOptions; + sal_uInt32 m_nLevel; + sal_uInt32 m_nCount; + +public: + DirectoryTraveller ( + const file& rFile, + const OUString &rPath, + const OUString &rName, + sal_uInt32 nOptions, + sal_uInt32 nLevel = 0); + + virtual ~DirectoryTraveller (void); + + virtual sal_Bool visit (const iter& it); +}; + +/* + * DirectoryTraveller. + */ +DirectoryTraveller::DirectoryTraveller ( + const file& rFile, + const OUString &rPath, + const OUString &rName, + sal_uInt32 nOptions, + sal_uInt32 nLevel) + : m_aFile (rFile), + m_aPath (rPath), + m_nOptions (nOptions), + m_nLevel (nLevel), + m_nCount (0) +{ + m_aPath += rName; + m_aPath += OUString::createFromAscii("/"); +} + +/* + * ~DirectoryTraveller. + */ +DirectoryTraveller::~DirectoryTraveller (void) +{ +} + +/* + * visit. + */ +sal_Bool DirectoryTraveller::visit (const iter& it) +{ + m_nCount++; + if (m_nOptions & OPTION_DUMP) + { + OString aName (it.m_pszName, it.m_nLength, RTL_TEXTENCODING_UTF8); + printf ("Visit(%d,%d): %s [0x%08x] %d [Bytes]\n", + m_nLevel, m_nCount, + aName.pData->buffer, it.m_nAttrib, it.m_nSize); + } + if (it.m_nAttrib & STORE_ATTRIB_ISDIR) + { + OUString aName (it.m_pszName, it.m_nLength); + Directory aSubDir; + + storeError eErrCode = aSubDir.create ( + m_aFile, m_aPath, aName, store_AccessReadOnly); + if (eErrCode == store_E_None) + { + sal_uInt32 nRefCount = 0; + m_aFile.getRefererCount (nRefCount); + + DirectoryTraveller aSubTraveller ( + m_aFile, m_aPath, aName, m_nOptions, m_nLevel + 1); + aSubDir.travel (aSubTraveller); + } + } + return sal_True; +} + +/*======================================================================== + * + * __store_getProcessTextEncoding. + * + *======================================================================*/ +inline rtl_TextEncoding __store_getProcessTextEncoding (void) +{ + rtl_TextEncoding eEncoding; +#if defined(SAL_OS2) + eEncoding = RTL_TEXTENCODING_IBM850; +#elif defined(SAL_UNX) + eEncoding = RTL_TEXTENCODING_ISO8859_1; +#elif defined(SAL_W32) + eEncoding = RTL_TEXTENCODING_MS_1252; +#else + eEncoding = RTL_TEXTENCODING_ASCII_US; +#endif + return eEncoding; +} + +/*======================================================================== + * + * main. + * + *======================================================================*/ +int SAL_CALL main (int argc, char **argv) +{ +#if (defined(WNT) && defined(PROFILE)) + StartCAP(); +#else + OTime aStartTime (OTime::getSystemTime()); +#endif /* PROFILE */ + + NAMESPACE_STORE(OStoreFile) aFile; + storeError eErrCode = store_E_None; + + sal_uInt32 nOptions = 0; + for (int i = 1; i < argc; i++) + { + const char *opt = argv[i]; + if (opt[0] == '-') + { + switch (rtl_char_toLowerCase(opt[1])) + { + case 'f': + nOptions |= OPTION_FILE; + break; + + case 'd': + nOptions |= OPTION_DUMP; + break; + case 'i': + nOptions |= OPTION_ITER; + break; + case 'l': + nOptions |= OPTION_LINK; + break; + + case 'r': + nOptions |= OPTION_READ; + break; + case 'w': + nOptions |= OPTION_WRITE; + break; + case 'c': + nOptions |= OPTION_CREAT; + break; + case 't': + nOptions |= OPTION_TRUNC; + break; + + case 'p': + nOptions |= OPTION_PAUSE; + break; + + case 'h': + default: + nOptions |= OPTION_HELP; + break; + } + } + else + { + if (nOptions & OPTION_FILE) + { + OUString aName ( + argv[i], rtl_str_getLength(argv[i]), + __store_getProcessTextEncoding()); + if ((nOptions & OPTION_CREAT) && (nOptions & OPTION_TRUNC)) + eErrCode = aFile.create (aName, store_AccessCreate); + else if (nOptions & OPTION_CREAT) + eErrCode = aFile.create (aName, store_AccessReadCreate); + else if (nOptions & OPTION_WRITE) + eErrCode = aFile.create (aName, store_AccessReadWrite); + else + eErrCode = aFile.create (aName, store_AccessReadOnly); + if (eErrCode != store_E_None) + { + printf ("Error: can't open file: %s\n", argv[i]); + exit (0); + } + } + } + } + + if ((nOptions == 0) || (nOptions & OPTION_HELP)) + { + printf ("Options:\n"); + printf ("-f\tfilename\n"); + printf ("-h\thelp\n"); + exit (0); + } + + if (!aFile.isValid()) + { + eErrCode = aFile.createInMemory(); + if (eErrCode != store_E_None) + { + printf ("Error: can't create memory file\n"); + exit (0); + } + } + + // Stream Read/Write. + OUString aPath (RTL_CONSTASCII_USTRINGPARAM("/")); + if ((nOptions & OPTION_READ) || (nOptions & OPTION_WRITE)) + { + // Mode. + storeAccessMode eMode = store_AccessReadOnly; + if (nOptions & OPTION_WRITE) + eMode = store_AccessReadWrite; + if (nOptions & OPTION_CREAT) + eMode = store_AccessCreate; + + // Buffer. + char pBuffer[_DEMOSTOR_BUFSIZ] = "Hello World"; + pBuffer[_DEMOSTOR_BUFSIZ - 2] = 'B'; + pBuffer[_DEMOSTOR_BUFSIZ - 1] = '\0'; + + // Load/Save. +#ifndef PROFILE + OTime aStartTime (OTime::getSystemTime()); +#endif /* PROFILE */ + + for (sal_Int32 i = 0; i < _DEMOSTOR_LOOPS; i++) + { + OUString aName (RTL_CONSTASCII_USTRINGPARAM("demostor-")); + aName += OUString::valueOf ((sal_Int32)(i + 1), 10); + aName += OUString::createFromAscii (".dat"); + +#if (_DEMOSTOR_REMOVE == 1) + eErrCode = aFile.remove (aPath, aName); + if ((eErrCode != store_E_None ) && + (eErrCode != store_E_NotExists) ) + break; +#endif /* _REMOVE */ + + NAMESPACE_STORE(OStoreStream) aStream; + eErrCode = aStream.create (aFile, aPath, aName, eMode); + if (eErrCode != store_E_None) + break; + + if (nOptions & OPTION_TRUNC) + { + eErrCode = aStream.setSize(0); + if (eErrCode != store_E_None) + break; + } + + sal_uInt32 nDone = 0; + if (nOptions & OPTION_WRITE) + { + eErrCode = aStream.writeAt ( + 0, pBuffer, sizeof(pBuffer), nDone); + if (eErrCode != store_E_None) + break; + } + + if (nOptions & OPTION_READ) + { + sal_uInt32 nOffset = 0; + for (;;) + { + eErrCode = aStream.readAt ( + nOffset, pBuffer, sizeof(pBuffer), nDone); + if (eErrCode != store_E_None) + break; + if (nDone == 0) + break; + nOffset += nDone; + } + } + + aStream.close(); + +#ifndef PROFILE + if (((i + 1) % (_DEMOSTOR_LOOPS/10)) == 0) + { + OTime aDelta (OTime::getSystemTime() - aStartTime); + + sal_uInt32 nDelta = aDelta.Seconds * 1000000; + nDelta += (aDelta.Nanosec / 1000); + + printf ("%d: %12.4g[usec]\n", (i+1), + (double)(nDelta)/(double)(i+1)); + } +#endif /* PROFILE */ + } + +#ifndef PROFILE + OTime aDelta (OTime::getSystemTime() - aStartTime); + + sal_uInt32 nDelta = aDelta.Seconds * 1000000; + nDelta += (aDelta.Nanosec / 1000); + + printf ("Total(rd,wr): %d[usec]\n", nDelta); +#endif /* PROFILE */ + } + + // Link/Rename. + if (nOptions & OPTION_LINK) + { + // Create symlink to (root) directory. + eErrCode = aFile.symlink ( + aPath, OUString::createFromAscii("000000/"), + OUString(), aPath); + VOS_POSTCOND( + ((eErrCode == store_E_None ) || + (eErrCode == store_E_AlreadyExists) ), + "t_store::main(): store_symlink() failed"); + + // Create symlink to file. + OUString aLinkName (RTL_CONSTASCII_USTRINGPARAM("demostor-1.lnk")); + + eErrCode = aFile.symlink ( + aPath, aLinkName, + aPath, OUString::createFromAscii("demostor-1.dat")); + VOS_POSTCOND( + ((eErrCode == store_E_None ) || + (eErrCode == store_E_AlreadyExists) ), + "t_store::main(): store_symlink() failed"); + if ((eErrCode == store_E_None ) || + (eErrCode == store_E_AlreadyExists) ) + { + OUString aShortcut ( + RTL_CONSTASCII_USTRINGPARAM("Shortcut to demostor-1.dat")); + eErrCode = aFile.rename ( + aPath, aLinkName, + aPath, aShortcut); + VOS_POSTCOND( + ((eErrCode == store_E_None ) || + (eErrCode == store_E_AlreadyExists) ), + "t_store::main(): store_rename() failed"); + } + + // Create directory. + OUString aDirName (RTL_CONSTASCII_USTRINGPARAM("demostor-1.dir")); + NAMESPACE_STORE(OStoreDirectory) aDir; + + eErrCode = aDir.create ( + aFile, aPath, aDirName, store_AccessReadCreate); + VOS_POSTCOND( + (eErrCode == store_E_None), + "t_store::main(): store_createDirectory() failed"); + if (eErrCode == store_E_None) + { +#if 0 /* NYI */ + // Rename directory. + eErrCode = aFile.rename ( + aPath, "demostor-1.dir/", + aPath, "Renamed demostor-1.dir"); + VOS_POSTCOND( + ((eErrCode == store_E_None ) || + (eErrCode == store_E_AlreadyExists) ), + "t_store::main(): store_rename() failed"); + + eErrCode = aFile.rename ( + aPath, "Renamed demostor-1.dir/", + aPath, "demostor-1.dir"); + VOS_POSTCOND( + (eErrCode == store_E_None), + "t_store::main(): store_rename() failed"); +#endif /* NYI */ + } + } + + // Directory iteration. + if (nOptions & OPTION_ITER) + { +#ifndef PROFILE + OTime aStartTime (OTime::getSystemTime()); +#endif /* PROFILE */ + OUString aEmpty; + + // Root directory. + NAMESPACE_STORE(OStoreDirectory) aRootDir; + if (nOptions & OPTION_LINK) + { + // Open symlink entry. + eErrCode = aRootDir.create ( + aFile, aPath, OUString::createFromAscii("000000"), + store_AccessReadOnly); + } + else + { + // Open direct entry. + if (nOptions & OPTION_CREAT) + eErrCode = aRootDir.create ( + aFile, aEmpty, aEmpty, store_AccessReadCreate); + else if (nOptions & OPTION_WRITE) + eErrCode = aRootDir.create ( + aFile, aEmpty, aEmpty, store_AccessReadWrite); + else + eErrCode = aRootDir.create ( + aFile, aEmpty, aEmpty, store_AccessReadOnly); + } + + if (eErrCode == store_E_None) + { + // Traverse directory tree. + DirectoryTraveller aTraveller ( + aFile, aEmpty, aEmpty, nOptions, 0); + aRootDir.travel (aTraveller); + } + else + { + // Failure. + printf ("Error: can't open directory: \"/\"\n"); + } + +#ifndef PROFILE + OTime aDelta (OTime::getSystemTime() - aStartTime); + + sal_uInt32 nDelta = aDelta.Seconds * 1000000; + nDelta += (aDelta.Nanosec / 1000); + + printf ("Total(iter): %d[usec]\n", nDelta); +#endif /* PROFILE */ + } + + if (nOptions & OPTION_PAUSE) + { + TimeValue tv; + tv.Seconds = 300; + tv.Nanosec = 0; + NAMESPACE_VOS(OThread)::wait (tv); + } + + // Size. + sal_uInt32 nSize = 0; + aFile.getSize (nSize); + + // Done. + aFile.close(); + +#if (defined(WNT) && defined(PROFILE)) + StopCAP(); + DumpCAP(); +#endif /* PROFILE */ +#ifndef PROFILE + OTime aDelta (OTime::getSystemTime() - aStartTime); + + sal_uInt32 nDelta = aDelta.Seconds * 1000000; + nDelta += (aDelta.Nanosec / 1000); + + printf ("Total: %d[usec]\n", nDelta); +#endif /* PROFILE */ + + return 0; +} + |