1*234bd5c5SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*234bd5c5SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*234bd5c5SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*234bd5c5SAndrew Rist * distributed with this work for additional information 6*234bd5c5SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*234bd5c5SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*234bd5c5SAndrew Rist * "License"); you may not use this file except in compliance 9*234bd5c5SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*234bd5c5SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*234bd5c5SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*234bd5c5SAndrew Rist * software distributed under the License is distributed on an 15*234bd5c5SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*234bd5c5SAndrew Rist * KIND, either express or implied. See the License for the 17*234bd5c5SAndrew Rist * specific language governing permissions and limitations 18*234bd5c5SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*234bd5c5SAndrew Rist *************************************************************/ 21*234bd5c5SAndrew Rist 22*234bd5c5SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _SBIOSYS_HXX 25cdf0e10cSrcweir #define _SBIOSYS_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <tools/stream.hxx> 28cdf0e10cSrcweir #ifndef _SBERRORS_HXX 29cdf0e10cSrcweir #include <basic/sberrors.hxx> 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir 32cdf0e10cSrcweir class SvStream; 33cdf0e10cSrcweir 34cdf0e10cSrcweir // Zur Zeit sind globale Dateien (Kanalnummern 256 bis 511) 35cdf0e10cSrcweir // nicht implementiert. 36cdf0e10cSrcweir 37cdf0e10cSrcweir #define CHANNELS 256 38cdf0e10cSrcweir #define CONSOLE 0 39cdf0e10cSrcweir 40cdf0e10cSrcweir #define SBSTRM_INPUT 0x0001 // Input 41cdf0e10cSrcweir #define SBSTRM_OUTPUT 0x0002 // Output 42cdf0e10cSrcweir #define SBSTRM_RANDOM 0x0004 // Random 43cdf0e10cSrcweir #define SBSTRM_APPEND 0x0008 // Append 44cdf0e10cSrcweir #define SBSTRM_BINARY 0x0010 // Binary 45cdf0e10cSrcweir 46cdf0e10cSrcweir class SbiStream { 47cdf0e10cSrcweir SvStream* pStrm; // der Stream 48cdf0e10cSrcweir sal_uIntPtr nExpandOnWriteTo; // bei Schreibzugriff, den Stream 49cdf0e10cSrcweir // bis zu dieser Groesse aufblasen 50cdf0e10cSrcweir ByteString aLine; // aktuelle Zeile 51cdf0e10cSrcweir sal_uIntPtr nLine; // aktuelle Zeilennummer 52cdf0e10cSrcweir short nLen; // Pufferlaenge 53cdf0e10cSrcweir short nMode; // Bits: 54cdf0e10cSrcweir short nChan; // aktueller Kanal 55cdf0e10cSrcweir SbError nError; // letzter Fehlercode 56cdf0e10cSrcweir void MapError(); // Fehlercode mappen 57cdf0e10cSrcweir 58cdf0e10cSrcweir public: 59cdf0e10cSrcweir SbiStream(); 60cdf0e10cSrcweir ~SbiStream(); 61cdf0e10cSrcweir SbError Open( short, const ByteString&, short, short, short ); 62cdf0e10cSrcweir SbError Close(); 63cdf0e10cSrcweir SbError Read( ByteString&, sal_uInt16 = 0, bool bForceReadingPerByte=false ); 64cdf0e10cSrcweir SbError Read( char& ); 65cdf0e10cSrcweir SbError Write( const ByteString&, sal_uInt16 = 0 ); 66cdf0e10cSrcweir IsText() const67cdf0e10cSrcweir bool IsText() const { return (nMode & SBSTRM_BINARY) == 0; } IsRandom() const68cdf0e10cSrcweir bool IsRandom() const { return (nMode & SBSTRM_RANDOM) != 0; } IsBinary() const69cdf0e10cSrcweir bool IsBinary() const { return (nMode & SBSTRM_BINARY) != 0; } IsSeq() const70cdf0e10cSrcweir bool IsSeq() const { return (nMode & SBSTRM_RANDOM) == 0; } IsAppend() const71cdf0e10cSrcweir bool IsAppend() const { return (nMode & SBSTRM_APPEND) != 0; } GetBlockLen() const72cdf0e10cSrcweir short GetBlockLen() const { return nLen; } GetMode() const73cdf0e10cSrcweir short GetMode() const { return nMode; } GetLine() const74cdf0e10cSrcweir sal_uIntPtr GetLine() const { return nLine; } SetExpandOnWriteTo(sal_uIntPtr n)75cdf0e10cSrcweir void SetExpandOnWriteTo( sal_uIntPtr n ) { nExpandOnWriteTo = n; } 76cdf0e10cSrcweir void ExpandFile(); GetStrm()77cdf0e10cSrcweir SvStream* GetStrm() { return pStrm; } 78cdf0e10cSrcweir }; 79cdf0e10cSrcweir 80cdf0e10cSrcweir class SbiIoSystem { 81cdf0e10cSrcweir SbiStream* pChan[ CHANNELS ]; 82cdf0e10cSrcweir ByteString aPrompt; // Input-Prompt 83cdf0e10cSrcweir ByteString aIn, aOut; // Console-Buffer 84cdf0e10cSrcweir short nChan; // aktueller Kanal 85cdf0e10cSrcweir SbError nError; // letzter Fehlercode 86cdf0e10cSrcweir void ReadCon( ByteString& ); 87cdf0e10cSrcweir void WriteCon( const ByteString& ); 88cdf0e10cSrcweir public: 89cdf0e10cSrcweir SbiIoSystem(); 90cdf0e10cSrcweir ~SbiIoSystem(); 91cdf0e10cSrcweir SbError GetError(); 92cdf0e10cSrcweir void Shutdown(); SetPrompt(const ByteString & r)93cdf0e10cSrcweir void SetPrompt( const ByteString& r ) { aPrompt = r; } SetChannel(short n)94cdf0e10cSrcweir void SetChannel( short n ) { nChan = n; } GetChannel() const95cdf0e10cSrcweir short GetChannel() const { return nChan;} ResetChannel()96cdf0e10cSrcweir void ResetChannel() { nChan = 0; } 97cdf0e10cSrcweir void Open( short, const ByteString&, short, short, short ); 98cdf0e10cSrcweir void Close(); 99cdf0e10cSrcweir void Read( ByteString&, short = 0 ); 100cdf0e10cSrcweir char Read(); 101cdf0e10cSrcweir void Write( const ByteString&, short = 0 ); 102cdf0e10cSrcweir short NextChannel(); 103cdf0e10cSrcweir // 0 == bad channel or no SvStream (nChannel=0..CHANNELS-1) 104cdf0e10cSrcweir SbiStream* GetStream( short nChannel ) const; 105cdf0e10cSrcweir void CloseAll(); // JSM 106cdf0e10cSrcweir }; 107cdf0e10cSrcweir 108cdf0e10cSrcweir #endif 109cdf0e10cSrcweir 110