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

funccallstreamer.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //-----------------------------------------------------------------------------
00006 //  FUNCCALLSTREAMER.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 "funccallstreamer.hpp"
00041 #   include "processor/xmlprocessor.hpp"
00042 #   include "processor/xmlflowcontext.hpp"
00043 
00044 
00045 BEGIN_XDFLENGINE_NS
00046 
00047 //=============================================================================
00048 //  CLASS FUNCCALLSTREAMER
00049 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00050 
00051 // CONSTRUCTOR & DESTRUCTOR
00052 
00053     //_____________________________________________________________________
00054     //  FUNCCALLSTREAMER
00055     //---------------------------------------------------------------------
00056     FuncCallStreamer::FuncCallStreamer( 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(FuncCallStreamer)
00060         m_pScriptParamBuffer = 0;
00061     }
00062     
00063     //_____________________________________________________________________
00064     //  ~FUNCCALLSTREAMER
00065     //---------------------------------------------------------------------     
00066     FuncCallStreamer::~FuncCallStreamer()
00067     {
00068         DEBUG_DEL(FuncCallStreamer)
00069     }
00070     
00071 // STREAM   
00072 
00073     //_____________________________________________________________________
00074     //  INITSTREAM
00075     //---------------------------------------------------------------------
00076     bool FuncCallStreamer::initStream()
00077     {
00078         
00079         DEBUG_IN(FuncCallStreamer::initStream)
00080 
00081         m_pScriptParamBuffer = m_pContext->getProcessor() -> getNewBuffer();
00082 
00083         DEBUG_OUT(FuncCallStreamer::initStream)
00084 
00085         return true;
00086     }
00087 
00088     //_____________________________________________________________________
00089     //  WRITEDATA
00090     //---------------------------------------------------------------------
00091     void FuncCallStreamer::writeData( const char*   p_pszData, unsigned int p_uiDataLen)
00092     {
00093         DEBUG_IN(FuncCallStreamer::writeData)
00094 
00095         m_pScriptParamBuffer -> writeData( p_pszData, p_uiDataLen);
00096 
00097         DEBUG_OUT(FuncCallStreamer::writeData)
00098     }
00099 
00100     //_____________________________________________________________________
00101     //  COMMITSTREAM
00102     //---------------------------------------------------------------------
00103     bool FuncCallStreamer::commitStream(bool p_fFinal)
00104     {
00105         //-----------------------------------------------------------------
00106         XMLFlowContext* l_pScriptContext=0;
00107         const RootStreamNode* l_pScriptRoot;
00108         unsigned int i;
00109         const char* l_pszScriptName;
00110         //-----------------------------------------------------------------
00111 
00112         PREP_CATCH_XML_FLOW_ERROR;
00113 
00114         l_pszScriptName = getParamValue( m_pParameters, FUNCCALLSTREAMER_NAME,"");
00115         if(p_fFinal )
00116         {
00117             // get compiles script
00118             l_pScriptRoot = ((FuncCallStreamerFactory*) m_pParent)->getCachedScript(l_pszScriptName);
00119             if(!l_pScriptRoot) THROW_XMLFLOW_EXCEPTION( ERRCODE_LOC_FUNCCALLSTREAMER + ERRCODE_CAUSE_MISSINGREF , "Function not found." , l_pszScriptName, "FuncCallStreamer::commitStream", "", false );
00120 
00121             l_pScriptContext = new XMLFlowContext( m_pContext->getProcessor(), m_pContext, m_pContext->getThreadId(), m_pContext->getEncoding());
00122             
00123             // copy parameters to child context
00124             for( i=0; i<m_pParameters->size(); i++) l_pScriptContext->addParameter( m_pParameters->getKey(i), m_pParameters->get(i));
00125 
00126             WATCH_XML_FLOW_ERROR
00127             {
00128                 logout << "\t" << FUNCCALLSTREAMER_TAGNAME<< "   :   " << "Call function " << l_pszScriptName << "...\n";
00129                 l_pScriptContext->addNamedBuffer( FUNCCALLSTREAMER_BUFINPUT, m_pScriptParamBuffer);
00130                 m_pContext->getProcessor()->execute( l_pScriptRoot , m_pOutput, l_pScriptContext);
00131             }
00132             CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN
00133 
00134         }
00135 
00136     RELEASE_AND_RETURN:
00137         if(p_fFinal )
00138         {
00139             l_pScriptContext->removeNamedBuffer(FUNCCALLSTREAMER_BUFINPUT);
00140             delete m_pScriptParamBuffer;
00141             delete l_pScriptContext;
00142         }
00143         ON_XML_FLOW_ERROR_THROW;
00144         return false;
00145     }
00146 
00147 
00148 
00149 
00150 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00151 //=============================================================================
00152 
00153 
00154 //=============================================================================
00155 //  CLASS FuncCallStreamerFactory
00156 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00157 
00158 
00159     //_____________________________________________________________________
00160     //  ~FuncCallStreamerFactory
00161     //---------------------------------------------------------------------
00162     FuncCallStreamerFactory::~FuncCallStreamerFactory()
00163     {
00164         while(!m_pvaScriptCache.empty()) delete m_pvaScriptCache.pop();
00165     }
00166 
00167     //_____________________________________________________________________
00168     //  getStreamer
00169     //---------------------------------------------------------------------
00170     XMLStreamer* FuncCallStreamerFactory::getStreamer(
00171         StreamerParams*         p_pParameters, 
00172         XMLFlowContext* p_pStreamContext, 
00173         XMLStreamConsumer*      p_pStreamConsumer) const
00174     {
00175         return (XMLStreamer*) new FuncCallStreamer( this, p_pParameters, p_pStreamContext, p_pStreamConsumer);
00176     }
00177 
00178 
00179     //_____________________________________________________________________
00180     //  CACHESCRIPT
00181     //---------------------------------------------------------------------
00182     void FuncCallStreamerFactory::cacheScript( RootStreamNode* p_pRootNode, const char* p_pszCacheName)
00183     {
00184         m_pvaScriptCache.add( p_pRootNode, p_pszCacheName);
00185     }
00186 
00187     //_____________________________________________________________________
00188     //  GETCACHEDSCRIPT
00189     //---------------------------------------------------------------------
00190     const RootStreamNode* FuncCallStreamerFactory::getCachedScript( const char* p_pszCacheName)
00191     {
00192         return m_pvaScriptCache.get( p_pszCacheName);
00193     }
00194 
00195 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00196 //=============================================================================
00197 
00198 
00199 END_XDFLENGINE_NS
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 

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