Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

zipstreamer.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //-----------------------------------------------------------------------------
00006 //  ZipStreamer.CPP
00007 //-----------------------------------------------------------------------------
00013 //_____________________________________________________________________________
00014 //
00015 //  Copyright (C) 2003 Guillaume Baurand. All Rights Reserved.
00016 //
00017 //  This file is part of the XDFLengine project.
00018 //
00019 //  The XDFLengine is free software; you can redistribute it and/or modify
00020 //  it under the terms of the GNU General Public License as published by
00021 //  the Free Software Foundation; either version 2 of the License, or
00022 //  (at your option) any later version.
00023 //
00024 //  This program is distributed in the hope that it will be useful,
00025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027 //  GNU General Public License for more details.
00028 //
00029 //  You should have received a copy of the GNU General Public License
00030 //  along with this program; if not, write to the Free Software
00031 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
00032 //  USA.
00033 //
00034 //  For more information, 
00035 //      contact  : guillaume@baurand.net 
00036 //      or visit : http://xdflengine.sourceforge.net
00037 //
00038 //============================================================================= 
00039 
00040 #   include "zipstreamer.hpp"
00041 #   include "flow/buffers/filebuffer.hpp"
00042 #   include "processor/xmlprocessor.hpp"
00043 #   include "processor/xmlflowcontext.hpp"
00044 
00045 BEGIN_XDFLENGINE_NS
00046 
00047 //=============================================================================
00048 //  CLASS ZipStreamer
00049 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00050 
00051 // CONSTRUCTOR & DESTRUCTOR
00052 
00053     //_____________________________________________________________________
00054     //  ZipStreamer
00055     //---------------------------------------------------------------------
00056     ZipStreamer::ZipStreamer( const XMLStreamerFactory* p_pParent, StreamerParams* p_pParameters, XMLFlowContext* p_pContext, XMLStreamConsumer* p_pOutput)
00057     :XMLStreamer( p_pParent, p_pParameters, p_pContext, p_pOutput)
00058     {
00059         m_pBufOut = 0;
00060         DEBUG_CREATE(ZipStreamer)
00061     }
00062     
00063     //_____________________________________________________________________
00064     //  ~ZipStreamer
00065     //---------------------------------------------------------------------     
00066     ZipStreamer::~ZipStreamer()
00067     {
00068         DEBUG_DEL(ZipStreamer)
00069         if(m_pBufOut) delete m_pBufOut;
00070     }
00071     
00072 // STREAM   
00073 
00074     //_____________________________________________________________________
00075     //  INITSTREAM
00076     //---------------------------------------------------------------------
00077     bool ZipStreamer::initStream()
00078     {
00079         //---------------------------------------------------------------------
00080         const char*     l_pszFilePath;
00081         const char*     l_pszHeader;
00082         const char*     l_pszAction;
00083         //---------------------------------------------------------------------
00084 
00085         DEBUG_IN(ZipStreamer::initStream)
00086 
00087         // Get parameters
00088         l_pszFilePath = getParamValue(m_pParameters, ZIPSTREAMER_TARGET);
00089 
00090         if( strlen(l_pszFilePath)>0 )
00091         {
00092 
00093             l_pszHeader = getParamValue(m_pParameters, ZIPSTREAMER_HEADER,ZIPSTREAMER_HEADER_DEF);
00094             l_pszAction = getParamValue(m_pParameters, ZIPSTREAMER_ACTION, ZIPSTREAMER_ACTION_DEF);
00095 
00096             if ( strcmp( l_pszAction, ZIPSTREAMER_ACTION_DELETE) != 0 )
00097             {
00098                 m_pBufOut = new ZipBuffer( l_pszFilePath, false);
00099 
00100                 if ( strcmp( l_pszAction, ZIPSTREAMER_ACTION_FLUSH) == 0 ) m_pBufOut->flush();
00101                 if( strlen(l_pszHeader)>0) (*m_pBufOut) << l_pszHeader << "\n";         
00102             }
00103             else
00104             {
00105                 remove( l_pszFilePath);
00106             }
00107         }
00108         else
00109         {
00110             m_pBufOut = 0;
00111         }
00112 
00113 
00114         DEBUG_OUT(ZipStreamer::initStream)  
00115 
00116         return true;
00117     }
00118 
00119     //_____________________________________________________________________
00120     //  WRITEDATA
00121     //---------------------------------------------------------------------
00122     void ZipStreamer::writeData( const char*    p_pszData, unsigned int p_uiDataLen)
00123     {
00124         DEBUG_IN(ZipStreamer::writeData)
00125 
00126         if(m_pBufOut) m_pBufOut -> writeData( p_pszData, p_uiDataLen);
00127         if(m_pOutput) m_pOutput -> writeData( p_pszData, p_uiDataLen);
00128 
00129         DEBUG_OUT(ZipStreamer::writeData)
00130     }
00131 
00132     //_____________________________________________________________________
00133     //  COMMITSTREAM
00134     //---------------------------------------------------------------------
00135     bool ZipStreamer::commitStream(bool p_fFinal)
00136     {
00137         DEBUG_IN(ZipStreamer::commitStream)
00138 
00139         bool m_fOK;
00140         bool m_fOK2;
00141         
00142         if(m_pBufOut) m_fOK = m_pBufOut->commitStream(false);
00143         if(m_pOutput) m_fOK2 = m_pOutput->commitStream(false);
00144 
00145         DEBUG_OUT(ZipStreamer::commitStream)
00146 
00147         return m_fOK;
00148 
00149         
00150     }
00151 
00152 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00153 //=============================================================================
00154 
00155 
00156 //=============================================================================
00157 //  CLASS ZipStreamerFactory
00158 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00159     ZipStreamerFactory::ZipStreamerFactory()
00160     {
00161         logout.display_version( "ZLIB", "'zlib' general purpose compression library", ZLIB_VERSION, "Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler"); 
00162     }
00163 
00164     XMLStreamer* ZipStreamerFactory::getStreamer(
00165         StreamerParams*         p_pParameters, 
00166         XMLFlowContext* p_pStreamContext, 
00167         XMLStreamConsumer*      p_pStreamConsumer) const
00168     {
00169         DEBUG_FUNC(ZipStreamerFactory::getStreamer)
00170     
00171         
00172         return (XMLStreamer*) new ZipStreamer( this, p_pParameters, p_pStreamContext, p_pStreamConsumer);
00173     }
00174 
00175 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00176 //=============================================================================
00177 
00178 
00179 END_XDFLENGINE_NS
00180 
00181 

Generated on Sat Oct 4 13:20:05 2003 for XDFLengine by doxygen1.3-rc2