Hi Mikhail, Thanks very much for your suggestions, I've modified the implementation and made 2 new patches, could you help to review them please?
And I might need your help on the following question: - About The private member SequenceInputStreamService::m_xFactory, I could not find it being used in any existing member functions, I tried to remove it from the implementation and find nothing affected. Could you please tell me for what the purpose does was it there, reserved for future use, I suppose? Should we keep it in SequenceOutputStreamService' implementation, too? Thanks and Best Regards :-) , Felix. Mikhail Voitenko 写道: > Hi Felix, > > The implementation looks good, except one problem you have already > mentioned. You are completely right, it is not allowed to have > out-parameter in the constructor. Sorry, my failure. The attached > implementation fills the sequence correctly, but unfortunately not the > original sequence provided from outside. So we should design it in > different way. I would suggest the following changes: > - introduce a new interface XSequenceOutputStream derived from > XOutputStream, that implements an additional method, kind of "sequence< > byte > getWrittenBytes() throws ( NotConnectedException, IOException )" > - let the service be derived from the interface > - let the service get no arguments in constructor, the sequence will be > just an internal member in the implementation > > Thus, the user will create the service, that will fill internal sequence > while being written, and then return the sequence. Before returning of > the stream, the sequence must get the correct length, since for > optimization reasons OSequenceOutputStream can let the sequence be > longer during the writing. Currently it is done in > OSequenceOutputStream::closeOutput(), but we do not need to close the > internal stream in case of getWrittenBytes() call. So I would suggest to > fix OSequenceOutputStream::flush() so that it sets the correct size to > the sequence, and use this method in getWrittenBytes() call. > > > As for the 'O' prefix, it is has no special meaning. There is no name > convention regarding class names of service implementations, so it is a > matter of taste. :) > > Best Regards, > Mikhail. > > > Zhang Xiaofei wrote: > >> Hi Mikhail, >> >> The attachment is the patches to udkapi and comphelper projects, the >> compilation to udkapi, offapi, offuh, comphelper projects all passed, >> and the application seems running fine after I delivered >> comphelp4MSC.dll explicitly to the install directory. Could you help >> to review them please? >> >> This time I have some questions as well: >> >> The first is about the ctor of SequenceOutputStream, I'm not sure if I >> got your statement in our last IRC meeting, that the service >> constructor should take sequence of bytes as output parameter, in the >> right way. At first I declared the ctor as: >> >> /_createStreamFromSequence( [out] sequence<byte> aData ); >> >> _/But then I was informed by the compiler that a parameter of a ctor >> may *not* be /out /or /inout, /I modified it to: >> >> /_createStreamFromSequence( [in] sequence<byte> aData ); >> >> _/then the compilation passed. However I don't know if this is >> semantically correct. Could you please give me some instructions here?/_ >> _/ >> The second is about naming conventions on classes, I find sometimes a >> class has an 'O' before its name, just like OSequenceOutputStream in >> /compehelper/inc/seqstream.hxx, and OTempFileService in our first >> task, too; but sometimes there isn't, like SequenceInputStream in >> seqstream.hxx, what does the 'O' stand for and when is it appropriate >> to have it? >> Does it has something to do with the class deriving from a typedef-ed >> base class, like OSequenceOutputStream_Base and OTempFileBase, I suppose? >> >> Best Regards, >> Felix. >> >> > > >
diff -urNpw @udkapi/com/sun/star/io/SequenceOutputStream.idl udkapi/com/sun/star/io/SequenceOutputStream.idl --- @udkapi/com/sun/star/io/SequenceOutputStream.idl 1970-01-01 08:00:00.000000000 +0800 +++ udkapi/com/sun/star/io/SequenceOutputStream.idl 2007-09-12 10:20:30.000000000 +0800 @@ -0,0 +1,56 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: SequenceInputStream.idl,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2007/06/26 16:08:11 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 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 + * + ************************************************************************/ +#ifndef __com_sun_star_io_SequenceOutputStream_idl__ +#define __com_sun_star_io_SequenceOutputStream_idl__ + +#ifndef __com_sun_star_io_XSequenceOutputStream_idl__ +#include <com/sun/star/io/XSequenceOutputStream.idl> +#endif + + +//============================================================================= + +module com { module sun { module star { module io { + +//============================================================================= +/** This service allows to wrap a sequence of bytes with a output stream object. + */ +service SequenceOutputStream : XSequenceOutputStream; + +//============================================================================= + +}; }; }; }; + +#endif diff -urNpw @udkapi/com/sun/star/io/XSequenceOutputStream.idl udkapi/com/sun/star/io/XSequenceOutputStream.idl --- @udkapi/com/sun/star/io/XSequenceOutputStream.idl 1970-01-01 08:00:00.000000000 +0800 +++ udkapi/com/sun/star/io/XSequenceOutputStream.idl 2007-09-12 10:18:30.000000000 +0800 @@ -0,0 +1,71 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: SequenceInputStream.idl,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2007/06/26 16:08:11 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 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 + * + ************************************************************************/ +#ifndef __com_sun_star_io_XSequenceOutputStream_idl__ +#define __com_sun_star_io_XSequenceOutputStream_idl__ + +#ifndef __com_sun_star_io_XOutputStream_idl__ +#include <com/sun/star/io/XOutputStream.idl> +#endif + +#ifndef __com_sun_star_io_NotConnectedException_idl__ +#include <com/sun/star/io/NotConnectedException.idl> +#endif + +#ifndef __com_sun_star_io_IOException_idl__ +#include <com/sun/star/io/IOException.idl> +#endif + + +//============================================================================= + +module com { module sun { module star { module io { + +//============================================================================= +/** This interface offers access to the written bytes +*/ +interface XSequenceOutputStream +{ + interface XOutputStream; + + sequence< byte > getWrittenBytes() + raises( com::sun::star::io::NotConnectedException, + com::sun::star::io::IOException ); +}; + +//============================================================================= + +}; }; }; }; + +#endif \ No newline at end of file diff -urNpw @udkapi/com/sun/star/io/makefile.mk udkapi/com/sun/star/io/makefile.mk --- @udkapi/com/sun/star/io/makefile.mk 2007-06-27 00:08:34.000000000 +0800 +++ udkapi/com/sun/star/io/makefile.mk 2007-09-12 10:18:10.000000000 +0800 @@ -61,6 +61,7 @@ IDLFILES=\ Pipe.idl\ Pump.idl\ SequenceInputStream.idl\ + SequenceOutputStream.idl\ UnexpectedEOFException.idl\ WrongFormatException.idl\ XActiveDataControl.idl\ @@ -84,6 +85,7 @@ IDLFILES=\ XStreamListener.idl\ XSeekable.idl\ XSeekableInputStream.idl\ + XSequenceOutputStream.idl\ TextInputStream.idl\ TextOutputStream.idl\ XTextInputStream.idl\
diff -urNpw @comphelper/source/streaming/makefile.mk comphelper/source/streaming/makefile.mk --- @comphelper/source/streaming/makefile.mk 2007-06-27 00:11:08.000000000 +0800 +++ comphelper/source/streaming/makefile.mk 2007-09-11 13:39:14.000000000 +0800 @@ -50,6 +50,7 @@ SLOFILES= $(SLO)$/basicio.obj \ $(SLO)$/oslfile2streamwrap.obj \ $(SLO)$/seqstream.obj \ $(SLO)$/seqinputstreamserv.obj \ + $(SLO)$/seqoutputstreamserv.obj \ $(SLO)$/streamsection.obj \ $(SLO)$/seekableinput.obj \ $(SLO)$/otransactedfilestream.obj \ diff -urNpw @comphelper/source/streaming/seqoutputstreamserv.cxx comphelper/source/streaming/seqoutputstreamserv.cxx --- @comphelper/source/streaming/seqoutputstreamserv.cxx 1970-01-01 08:00:00.000000000 +0800 +++ comphelper/source/streaming/seqoutputstreamserv.cxx 2007-09-12 14:00:20.000000000 +0800 @@ -0,0 +1,179 @@ +/************************************************************************* +* +* OpenOffice.org - a multi-platform office productivity suite +* +* $RCSfile: seqinputstreamserv.cxx,v $ +* +* $Revision: 1.2 $ +* +* last change: $Author: hr $ $Date: 2007/06/26 16:11:17 $ +* +* The Contents of this file are made available subject to +* the terms of GNU Lesser General Public License Version 2.1. +* +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2005 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 +* +************************************************************************/ + +#include "precompiled_comphelper.hxx" + +#include <sal/config.h> +#include <osl/mutex.hxx> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/implementationentry.hxx> +#include <cppuhelper/implbase2.hxx> +#include <comphelper/seqstream.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/io/XSequenceOutputStream.hpp> + +using namespace ::com::sun::star; + +::rtl::OUString SAL_CALL SequenceOutputStreamService_getImplementationName(); +uno::Sequence< ::rtl::OUString > SAL_CALL SequenceOutputStreamService_getSupportedServiceNames(); +uno::Reference< uno::XInterface > SAL_CALL SequenceOutputStreamService_createInstance( const uno::Reference< lang::XMultiServiceFactory > & xFactory ) SAL_THROW( (uno::Exception ) ); + + +namespace { + +class SequenceOutputStreamService: +public ::cppu::WeakImplHelper2 < lang::XServiceInfo, io::XOutputStream> +{ +public: + explicit SequenceOutputStreamService( uno::Reference< lang::XMultiServiceFactory > const & xFactory ); + + // ::com::sun::star::lang::XServiceInfo: + virtual ::rtl::OUString SAL_CALL getImplementationName() throw ( uno::RuntimeException ); + virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString & ServiceName ) throw ( uno::RuntimeException ); + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw ( uno::RuntimeException ); + + // ::com::sun::star::io::XOutputStream: + virtual void SAL_CALL writeBytes( const uno::Sequence< ::sal_Int8 > & aData ) throw ( io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException ); + virtual void SAL_CALL flush() throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException ); + virtual void SAL_CALL closeOutput() throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException ); + + // ::com::sun::star::io::XSequenceOutputStream: + virtual uno::Sequence< ::sal_Int8 > SAL_CALL getWrittenBytes( ) throw ( io::NotConnectedException, io::IOException, uno::RuntimeException); + +private: + SequenceOutputStreamService( SequenceOutputStreamService & ); //not defined + void operator =( SequenceOutputStreamService & ); //not defined + + virtual ~SequenceOutputStreamService() {}; + + + ::osl::Mutex m_aMutex; + uno::Reference< lang::XMultiServiceFactory > m_xFactory; + uno::Reference< io::XOutputStream > m_xOutputStream; + uno::Sequence< ::sal_Int8 > m_aSequence; +}; + +SequenceOutputStreamService::SequenceOutputStreamService( uno::Reference< lang::XMultiServiceFactory > const & xFactory ) +: m_xFactory( xFactory ) +{} + +// com.sun.star.uno.XServiceInfo: +::rtl::OUString SAL_CALL SequenceOutputStreamService::getImplementationName() throw ( uno::RuntimeException ) +{ + return SequenceOutputStreamService_getImplementationName(); +} + +::sal_Bool SAL_CALL SequenceOutputStreamService::supportsService( ::rtl::OUString const & serviceName ) throw ( uno::RuntimeException ) +{ + uno::Sequence< ::rtl::OUString > serviceNames = SequenceOutputStreamService_getSupportedServiceNames(); + for ( ::sal_Int32 i = 0; i < serviceNames.getLength(); ++i ) { + if ( serviceNames[i] == serviceName ) + return sal_True; + } + return sal_False; +} + +uno::Sequence< ::rtl::OUString > SAL_CALL SequenceOutputStreamService::getSupportedServiceNames() throw ( uno::RuntimeException ) +{ + return SequenceOutputStreamService_getSupportedServiceNames(); +} + +// ::com::sun::star::io::XOutputStream: +void SAL_CALL SequenceOutputStreamService::writeBytes( const uno::Sequence< ::sal_Int8 > & aData ) throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xOutputStream.is() ) + throw io::NotConnectedException(); + + m_xOutputStream->writeBytes( aData ); + m_aSequence = aData; +} + +void SAL_CALL SequenceOutputStreamService::flush() throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xOutputStream.is() ) + throw io::NotConnectedException(); + + m_xOutputStream->flush(); +}; + +void SAL_CALL SequenceOutputStreamService::closeOutput() throw ( uno::RuntimeException, io::NotConnectedException, io::BufferSizeExceededException, io::IOException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xOutputStream.is() ) + throw io::NotConnectedException(); + + m_xOutputStream->closeOutput(); + m_xOutputStream = uno::Reference< io::XOutputStream >(); +} + +// ::com::sun::star::io::XSequenceOutputStream: +uno::Sequence< ::sal_Int8 > SAL_CALL SequenceOutputStreamService::getWrittenBytes() throw ( io::NotConnectedException, io::IOException, uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xOutputStream.is() ) + throw io::NotConnectedException(); + + m_xOutputStream->flush(); + return m_aSequence; +} + +} // anonymous namespace + +::rtl::OUString SAL_CALL SequenceOutputStreamService_getImplementationName() { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.comp.SequenceOutputStreamService" ) ); +} + +uno::Sequence< ::rtl::OUString > SAL_CALL SequenceOutputStreamService_getSupportedServiceNames() +{ + uno::Sequence< ::rtl::OUString > s( 1 ); + s[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.io.SequenceOutputStream" ) ); + return s; +} + +uno::Reference< uno::XInterface > SAL_CALL SequenceOutputStreamService_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & xFactory ) + SAL_THROW( (uno::Exception ) ) +{ + return static_cast< ::cppu::OWeakObject * >( new SequenceOutputStreamService( xFactory ) ); +} + + + + + diff -urNpw @comphelper/source/streaming/seqstream.cxx comphelper/source/streaming/seqstream.cxx --- @comphelper/source/streaming/seqstream.cxx 2006-09-18 01:21:22.000000000 +0800 +++ comphelper/source/streaming/seqstream.cxx 2007-09-12 10:43:52.000000000 +0800 @@ -234,7 +234,8 @@ void SAL_CALL OSequenceOutputStream::flu if (!m_bConnected) throw NotConnectedException(); - // nothing to do here + // cut the sequence to the real size + m_rSequence.realloc(m_nSize); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]