auriemma    01/02/08 07:39:50

  Modified:    c/src/XalanTransformer XalanTransformerOutputStream.hpp
                        XalanTransformerOutputStream.cpp
                        XalanTransformer.hpp XalanTransformer.cpp
                        XalanCAPI.h XalanCAPI.cpp
  Log:
  Added (optional) flush callback.
  
  Revision  Changes    Path
  1.4       +13 -3     
xml-xalan/c/src/XalanTransformer/XalanTransformerOutputStream.hpp
  
  Index: XalanTransformerOutputStream.hpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/XalanTransformer/XalanTransformerOutputStream.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XalanTransformerOutputStream.hpp  2001/01/31 18:56:24     1.3
  +++ XalanTransformerOutputStream.hpp  2001/02/08 15:38:37     1.4
  @@ -73,6 +73,10 @@
   
   
   
  +typedef void (*XalanFlushHandlerType) (const void*);
  +
  +
  +
   // A class for output to a user define (callback) function.
   class XALAN_TRANSFORMER_EXPORT XalanTransformerOutputStream : public 
XalanOutputStream
   {
  @@ -82,12 +86,14 @@
         * Construct a XalanTransformerOutputStream instance for output to a
         * user define (callback) function.
         *
  -      * @param theOutputHandle       void data passed through to callback
  -      * @param theOutputHandler      address of callback
  +      * @param theOutputHandle       void pointer passed through to callback.
  +      * @param theOutputHandler      a user defined (callback) function.
  +      * @param theFlushHandler       a user defined (callback) function.
         */
       XalanTransformerOutputStream(
                const void*                                     
theOutputHandle, 
  -             XalanOutputHandlerType          theOutputHandler);
  +             XalanOutputHandlerType          theOutputHandler,
  +             XalanFlushHandlerType           theFlushHandler = 0);
   
   
       virtual
  @@ -113,8 +119,12 @@
        const void*                             m_outputHandle;
   
        XalanOutputHandlerType  m_outputHandler;
  +
  +     XalanFlushHandlerType   m_flushHandler;
   };
   
   
   
   #endif       // XALANTRANSFORMEROUTPUTSTREAM_HEADER_GUARD_1357924680
  +
  +
  
  
  
  1.4       +11 -6     
xml-xalan/c/src/XalanTransformer/XalanTransformerOutputStream.cpp
  
  Index: XalanTransformerOutputStream.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/XalanTransformer/XalanTransformerOutputStream.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XalanTransformerOutputStream.cpp  2001/01/31 18:56:26     1.3
  +++ XalanTransformerOutputStream.cpp  2001/02/08 15:38:45     1.4
  @@ -60,9 +60,11 @@
   
   XalanTransformerOutputStream::XalanTransformerOutputStream(
        const void*                                     theOutputHandle, 
  -     XalanOutputHandlerType          theOutputHandler):
  +     XalanOutputHandlerType          theOutputHandler,
  +     XalanFlushHandlerType           theFlushHandler):
        m_outputHandle(theOutputHandle),
  -     m_outputHandler(theOutputHandler)
  +     m_outputHandler(theOutputHandler),
  +     m_flushHandler(theFlushHandler)
   {
   }
   
  @@ -77,7 +79,10 @@
   void
   XalanTransformerOutputStream::doFlush()
   {
  -     // Not implemented
  +     if(m_flushHandler != 0)
  +     {
  +             m_flushHandler(m_outputHandle);
  +     }
   }
   
   
  @@ -89,9 +94,9 @@
   {
        const size_t theBytesWritten = m_outputHandler(theBuffer, 
theBufferLength, m_outputHandle);             
   
  -     // We validate that the number of bytes written equals the number of 
bytes sent to output handler.
  -     // Otherwise we will stop processing  and throw and exception thus 
allow the callback alert us of 
  -     // memory allocation issues or buffer overflows, all at the expense of 
confusing most people.
  +     // We validate that the number of bytes written equals the number of 
bytes sent to
  +     // the output handler. Otherwise we will stop processing  and throw and 
exception. 
  +     // Thus the callback can alert us of memory allocation issues or buffer 
overflows.
        if(theBytesWritten != theBufferLength)
        {
                throw XalanOutputStreamException(
  
  
  
  1.6       +20 -15    xml-xalan/c/src/XalanTransformer/XalanTransformer.hpp
  
  Index: XalanTransformer.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanTransformer/XalanTransformer.hpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XalanTransformer.hpp      2001/02/03 00:09:08     1.5
  +++ XalanTransformer.hpp      2001/02/08 15:38:47     1.6
  @@ -125,7 +125,7 @@
   
        /**
         * Initialize Xerces and Xalan.
  -      * Should be called only once before creating any
  +      * Should be called only once per process before creating any
         * instances of XalanTransformer. See class XSLTInit.
         */
        static void
  @@ -133,7 +133,7 @@
   
        /**
         * Terminate Xalan and Xerces.
  -      * Should be called only once after deleting all
  +      * Should be called only once per process after deleting all
         * instances of XalanTransformer. See class XSLTInit.
         */
        static void
  @@ -143,7 +143,7 @@
         * Returns the last error that occured as a 
         * result of callaing transform.        
         *
  -      * @return      error message int const c string 
  +      * @return      error message const character pointer.
         */
        const char*
        getLastError() const;
  @@ -157,7 +157,7 @@
         * @param inputSource           input source
         * @param stylesheetSource      stylesheet source
         * @param outputTarget          output source tree
  -      * @return      0 for success and 1 for failure 
  +      * @return      0 for success
         */
        int
        transform(
  @@ -173,7 +173,7 @@
         * @param theXMLFileName        filename of XML input source
         * @param theXSLFileName        filename of stylesheet source
         * @param theOutFileName        filename of output source
  -      * @return      0 for success and 1 for failure 
  +      * @return      0 for success
         */
        int
        transform(
  @@ -188,8 +188,8 @@
         *
         * @param theXMLFileName        filename of XML input source
         * @param theXSLFileName        filename of stylesheet source
  -      * @param theOutStream          a pointer to a std ostream for the 
output
  -      * @return      0 for success and 1 for failure 
  +      * @param theOutStream          a std ostream for the output
  +      * @return      0 for success
         */
        int
        transform(
  @@ -202,10 +202,10 @@
         * The processor will process the input stream, the stylesheet input 
         * stream, and transform to an output stream.
         *
  -      * @param theXMLInStream        a pointer to a std istream for the input
  -      * @param theXSLInStream        a pointer to a std istream for the input
  -      * @param theOutStream          a pointer to a std ostream for the 
output
  -      * @return      0 for success and 1 for failure 
  +      * @param theXMLInStream        a std istream for the input
  +      * @param theXSLInStream        a std istream for the input
  +      * @param theOutStream          a std ostream for the output
  +      * @return      0 for success
         */
        int
        transform(
  @@ -214,7 +214,7 @@
                        ostream&                                        
theOutStream);
   
        /**
  -      * Transform the XML source tree to the address of a callback.
  +      * Transform the XML source tree to a callback function.
         * The processor will process the input file, the stylesheet file,
         * and transform to output to a callback function in allocated 
         * blocks. Xalan will release any memory allocated upon 
  @@ -225,15 +225,17 @@
         * @param theXMLFileName        filename of XML input source
         * @param theXSLFileName        filename of stylesheet source    
         * @param theOutputHandle       void pointer passed through to callback.
  -      * @param theOutputHandler      address of a user defined (callback) 
function.
  -      * @return      0 for success and 1 for failure 
  +      * @param theOutputHandler      a user defined (callback) function.
  +      * @param theFlushHandler       (optional) a user defined (callback) 
function.
  +      * @return      0 for success 
         */
        int
        transform(
                        const char*                                     
theXMLFileName, 
                        const char*                                     
theXSLFileName,
                        const void*                                     
theOutputHandle, 
  -                     XalanOutputHandlerType          theOutputHandler);
  +                     XalanOutputHandlerType          theOutputHandler,
  +                     XalanFlushHandlerType           theFlushHandler = 0);
   
   protected:
   
  @@ -266,3 +268,6 @@
   
   
   #endif       // XALAN_TRANSFORMER_HEADER_GUARD
  +
  +
  +
  
  
  
  1.5       +4 -2      xml-xalan/c/src/XalanTransformer/XalanTransformer.cpp
  
  Index: XalanTransformer.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanTransformer/XalanTransformer.cpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XalanTransformer.cpp      2001/02/03 00:09:08     1.4
  +++ XalanTransformer.cpp      2001/02/08 15:38:50     1.5
  @@ -316,7 +316,8 @@
                const char*                             theXMLFileName, 
                const char*                             theXSLFileName,
                const void*                             theOutputHandle, 
  -             XalanOutputHandlerType  theOutputHandler)
  +             XalanOutputHandlerType  theOutputHandler,
  +             XalanFlushHandlerType   theFlushHandler)
   {
        // Set input sources
        const XalanDOMString    theDOMStringXMLFileName(theXMLFileName);
  @@ -326,7 +327,7 @@
        const XSLTInputSource   
theStylesheetSource(c_wstr(theDOMStringXSLFileName));
   
        // Set to output target to the callback 
  -     XalanTransformerOutputStream    theOutputStream(theOutputHandle, 
theOutputHandler);
  +     XalanTransformerOutputStream    theOutputStream(theOutputHandle, 
theOutputHandler, theFlushHandler);
        XalanOutputStreamPrintWriter    thePrintWriter(theOutputStream);
        XSLTResultTarget                                
theResultTarget(&thePrintWriter);
   
  @@ -336,6 +337,7 @@
                                        theStylesheetSource,
                                        theResultTarget);
   }
  +
   
   
   const char*
  
  
  
  1.6       +38 -20    xml-xalan/c/src/XalanTransformer/XalanCAPI.h
  
  Index: XalanCAPI.h
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanTransformer/XalanCAPI.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XalanCAPI.h       2001/02/03 00:09:09     1.5
  +++ XalanCAPI.h       2001/02/08 15:38:52     1.6
  @@ -82,7 +82,8 @@
   
        /**
         * Callback function passed to XalanTransformToHandler. 
  -      * Caller is responsible for streaming or coping data to a user  
  +      * Used to process transform output in blocks of data.
  +      * Caller is responsible for streaming or copying data to a user  
         * allocated buffer. Called should not attempt to write to or  
         * free this data. Xalan will reuse the same buffer and free it 
         * upon termination.
  @@ -99,10 +100,26 @@
         * @return number of bytes written
         */
        typedef unsigned long (*XalanOutputHandlerType) (const void*, unsigned 
long, const void*);
  +     
  +     /**
  +      * Callback function passed to XalanTransformToHandler. 
  +      * Used to flush the buffer once transform is completed.
  +      *
  +      * static void xalanFlushHandler(const void *handle);
  +      *
  +      * @param handle        handle of XalanTransformer instance.
  +      */
  +     typedef void (*XalanFlushHandlerType) (const void*);
  +
  +     /**
  +      * This is a typedef to workaround limitations with
  +      * the XALAN_TRANSFORMER_EXPORT_FUNCTION macro.
  +      */
  +     typedef const char*             XalanCCharPtr;
   
        /**
         * Initialize Xerces and Xalan.
  -      * Should be called only once before creating any
  +      * Should be called only once per process before creating any
         * instances of XalanTransformer.
         */
        XALAN_TRANSFORMER_EXPORT_FUNCTION(void)
  @@ -110,7 +127,7 @@
   
        /**
         * Terminate Xalan and Xerces.
  -      * Should be called only once after deleting all
  +      * Should be called only once per process after deleting all
         * instances of XalanTransformer.
         */
        XALAN_TRANSFORMER_EXPORT_FUNCTION(void)
  @@ -141,7 +158,7 @@
         * @param theXSLFileName        filename of stylesheet source
         * @param theOutFileName        filename of output source
         * @param theXalanHandle        handle of XalanTransformer instance.
  -      * @return      0 for success and 1 for failure 
  +      * @return      0 for success 
         */
        XALAN_TRANSFORMER_EXPORT_FUNCTION(int)
        XalanTransformToFile(
  @@ -161,7 +178,7 @@
         * @param theXSLFileName        filename of stylesheet source
         * @param theOutFileName        filename of output source
         * @param theXalanHandle        handle of XalanTransformer instance.
  -      * @return      0 for success and 1 for failure 
  +      * @return      0 for success 
         */
        XALAN_TRANSFORMER_EXPORT_FUNCTION(int) 
        XalanTransformToData(
  @@ -180,19 +197,25 @@
        XalanFreeData(char*             theStream);
   
        /**
  -      * Transform the XML source tree to the address of a callback.
  +      * Transform the XML source tree to a callback function.
         * The processor will process the input file, the stylesheet file,
  -      * and transform to output to a callback function in allocated 
  -      * blocks. Xalan will release any memory allocated upon 
  -      * termination. Data passed to the callback is not guaranteed to 
  -      * be null terminated. - See XalanOutputHandlerType for more details.
  +      * and transform to output to a callback function in pre-allocated 
  +      * blocks. Once the transform is completed a second callback, to
  +      * flush the buffer, will be called. You can pass in NULL if you 
  +      * do not wish to implement a flush callback. Xalan will release 
  +      * any memory allocated upon termination and data passed to the 
  +      * callback is not guaranteed to be null terminated. 
  +      * 
  +      * - See XalanOutputHandlerType and XalanFlushHandlerType for more 
  +      * details.
         * 
         * @param theXMLFileName        filename of XML input source
         * @param theXSLFileName        filename of stylesheet source
         * @param theXalanHandle        handle of XalanTransformer instance.
         * @param theOutputHandle       void pointer passed through to callback.
  -      * @param theOutputHandler      address of a user defined (callback) 
function.
  -      * @return      0 for success and 1 for failure 
  +      * @param theOutputHandler      a user defined (callback) function.
  +      * @param theFlushHandler       (can be NULL) a user defined (callback) 
function.
  +      * @return      0 for success 
         */
        XALAN_TRANSFORMER_EXPORT_FUNCTION(int) 
        XalanTransformToHandler(
  @@ -200,13 +223,8 @@
                                const char*                             
theXSLFileName,
                                XalanHandle                             
theXalanHandle,
                                const void*                             
theOutputHandle, 
  -                             XalanOutputHandlerType  theOutputHandler);
  -
  -     /**
  -      * This is a typedef to workaround limitations with
  -      * the XALAN_TRANSFORMER_EXPORT_FUNCTION macro.
  -      */
  -     typedef const char*             XalanCCharPtr;
  +                             XalanOutputHandlerType  theOutputHandler,
  +                             XalanFlushHandlerType   theFlushHandler);
   
        /**
         * Returns the last error that occured as a 
  @@ -216,7 +234,7 @@
         * const char*
         * XalanGetLastError(XalanHandle theXalanHandle) const;
         *
  -      * @return      error message int cons c string 
  +      * @return      error message const character pointer.
         */
        XALAN_TRANSFORMER_EXPORT_FUNCTION(XalanCCharPtr)
        XalanGetLastError(XalanHandle theXalanHandle);
  
  
  
  1.8       +4 -3      xml-xalan/c/src/XalanTransformer/XalanCAPI.cpp
  
  Index: XalanCAPI.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanTransformer/XalanCAPI.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XalanCAPI.cpp     2001/02/06 22:05:03     1.7
  +++ XalanCAPI.cpp     2001/02/08 15:38:54     1.8
  @@ -164,12 +164,13 @@
                        const char*                             theXSLFileName,
                        XalanHandle                             theXalanHandle,
                        const void*                             
theOutputHandle, 
  -                     XalanOutputHandlerType  theOutputHandler)
  +                     XalanOutputHandlerType  theOutputHandler,
  +                     XalanFlushHandlerType   theFlushHandler)
   {
   #if defined(XALAN_OLD_STYLE_CASTS)
  -     return ((XalanTransformer*)theXalanHandle)->transform(theXMLFileName, 
theXSLFileName, theOutputHandle, theOutputHandler);
  +     return ((XalanTransformer*)theXalanHandle)->transform(theXMLFileName, 
theXSLFileName, theOutputHandle, theOutputHandler, theFlushHandler);
   #else
  -     return  
static_cast<XalanTransformer*>(theXalanHandle)->transform(theXMLFileName, 
theXSLFileName, theOutputHandle, theOutputHandler);
  +     return  
static_cast<XalanTransformer*>(theXalanHandle)->transform(theXMLFileName, 
theXSLFileName, theOutputHandle, theOutputHandler, theFlushHandler);
   #endif       
   }
   
  
  
  

Reply via email to