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

execstreamer.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //-----------------------------------------------------------------------------
00006 //  EXECSTREAMER.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 "execstreamer.hpp"
00041 #   include "processor/xmlprocessor.hpp"
00042 #   include "processor/xmlflowcontext.hpp"
00043 
00044 
00045 BEGIN_XDFLENGINE_NS
00046 
00047 //=============================================================================
00048 //  CLASS EXECSTREAMER
00049 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00050 
00051 // CONSTRUCTOR & DESTRUCTOR
00052 
00053     //_____________________________________________________________________
00054     //  EXECSTREAMER
00055     //---------------------------------------------------------------------
00056     ExecStreamer::ExecStreamer( 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         DEBUG_CREATE(ExecStreamer)
00060         m_pScriptBuffer = 0;
00061     }
00062     
00063     //_____________________________________________________________________
00064     //  ~EXECSTREAMER
00065     //---------------------------------------------------------------------     
00066     ExecStreamer::~ExecStreamer()
00067     {
00068         DEBUG_DEL(ExecStreamer)
00069     }
00070     
00071 // STREAM   
00072 
00073     //_____________________________________________________________________
00074     //  INITSTREAM
00075     //---------------------------------------------------------------------
00076     bool ExecStreamer::initStream()
00077     {
00078         //-----------------------------------------------------------------
00079         const char* l_pszFileName;
00080         //-----------------------------------------------------------------
00081 
00082         DEBUG_IN(ExecStreamer::initStream)
00083 
00084         m_pszBufferName = getParamValue( m_pParameters, EXECSTREAMER_NAME,"");
00085         l_pszFileName = getParamValue( m_pParameters, EXECSTREAMER_FILENAME,"");
00086         m_fIsolateContext=true;
00087         if( strcmp( getParamValue( m_pParameters, EXECSTREAMER_ISOLATE, EXECSTREAMER_ISOLATE_DEF), REQ_FALSE)==0) m_fIsolateContext=false;
00088 
00089         if(strlen(m_pszBufferName)==0)
00090         {
00091             // create new buffer of given type
00092             if( strlen(l_pszFileName)==0)
00093             {
00094                 m_pScriptBuffer = m_pContext->getProcessor() -> getNewBuffer();
00095             }
00096             else
00097             {
00098                 m_pScriptBuffer = m_pContext->getProcessor() -> getNewBuffer( XMLPROCESSOR_FILE, l_pszFileName, false);
00099             }
00100 
00101             m_fOwnBuffer = true;
00102             m_pszBufferName = 0;
00103         }
00104         else
00105         {
00106             m_pScriptBuffer = m_pContext -> getNamedBuffer( m_pszBufferName);
00107             m_fOwnBuffer = false;
00108         }
00109 
00110         if( !m_pScriptBuffer) THROW_XMLFLOW_EXCEPTION ( ERRCODE_LOC_EXECSTREAMER + ERRCODE_CAUSE_MISSINGREF , "Script buffer not found.", "",  "ExecStreamer::initStream", "", false );
00111 
00112         DEBUG_OUT(ExecStreamer::initStream)
00113 
00114         return true;
00115     }
00116 
00117     //_____________________________________________________________________
00118     //  WRITEDATA
00119     //---------------------------------------------------------------------
00120     void ExecStreamer::writeData( const char*   p_pszData, unsigned int p_uiDataLen)
00121     {
00122         DEBUG_IN(ExecStreamer::writeData)
00123 
00124         m_pScriptBuffer -> writeData( p_pszData, p_uiDataLen);
00125 
00126         DEBUG_OUT(ExecStreamer::writeData)
00127     }
00128 
00129     //_____________________________________________________________________
00130     //  COMMITSTREAM
00131     //---------------------------------------------------------------------
00132     bool ExecStreamer::commitStream(bool p_fFinal)
00133     {
00134         XMLFlowContext* l_pScriptContext=0;
00135         PREP_CATCH_XML_FLOW_ERROR;
00136 
00137         if(p_fFinal)
00138         {
00139             if(m_fIsolateContext) l_pScriptContext = new XMLFlowContext( m_pContext->getProcessor(), m_pContext, m_pContext->getThreadId(), m_pContext->getEncoding());
00140             else l_pScriptContext = m_pContext;
00141 
00142             WATCH_XML_FLOW_ERROR
00143             {
00144 
00145                 m_pContext->getProcessor()->process( m_pScriptBuffer , m_pOutput, l_pScriptContext);
00146             }
00147             CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN
00148         }
00149 
00150     RELEASE_AND_RETURN:
00151         if(p_fFinal )
00152         {
00153             if(m_fOwnBuffer) delete m_pScriptBuffer;
00154             if(m_fIsolateContext) delete l_pScriptContext;
00155         }
00156         ON_XML_FLOW_ERROR_THROW;
00157         return false;
00158     }
00159 
00160 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00161 //=============================================================================
00162 
00163 
00164 //=============================================================================
00165 //  CLASS ExecStreamerFactory
00166 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00167 
00168     XMLStreamer* ExecStreamerFactory::getStreamer(
00169         StreamerParams*         p_pParameters, 
00170         XMLFlowContext* p_pStreamContext, 
00171         XMLStreamConsumer*      p_pStreamConsumer) const
00172     {
00173         return (XMLStreamer*) new ExecStreamer( this, p_pParameters, p_pStreamContext, p_pStreamConsumer);
00174     }
00175 
00176 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00177 //=============================================================================
00178 
00179 
00180 END_XDFLENGINE_NS
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 

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