/*
 * Emunation Plugin for MD-API 
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This code 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
 */
 
#include "dvbparser.h"
#include "sectionparser.h"
#include "dataparser.h"
#include "..\\main.h"
//#define WRITE(x){m_DLLInstance.x;}
#define WRITE(x){;}
cDVBParser::cDVBParser()
{
    m_buf=0;
    m_buflength=0;
    m_buftype=0;
    m_modeparsers[DVB_PACKETMODE_SECTION]=new cSectionParser();
}
cDVBParser::~cDVBParser()
{
     for(int i=0;i<MAX_MODEPARSER;i++)
     {
        delete m_modeparsers[i];
     }
     
}

void cDVBParser::SetBuffer(unsigned char* buffer,int length,int type)
{
     m_buf=buffer;
     m_buflength=length;
     m_buftype=type;
}
cDVBModeParser* cDVBParser::FindModeParser(int mode)
{
    if (mode<=MAX_MODEPARSER)
    {
        return m_modeparsers[mode];
    }
    else return 0;
}
bool cDVBParser::AnalyzePacket(int packetmode)
{
    m_curmodep=FindModeParser(packetmode);    
    WRITE(Log("AnalyzePacket:%p %p Mode:%d\n",m_curmodep,m_buf,packetmode))
     if(m_curmodep&&m_buf)
     {
        WRITE(Log("Parsing Mode detected%s \n","!"))
        m_curmodep->SetBuffer(m_buf,m_buflength);
        WRITE(Log("Buffer setted%s \n","!"))
        return m_curmodep->Parse();
     }
    return false;
}

cListBase*  cDVBParser::GetPacketData()
{
       return m_curmodep->GetDataParser()->GetData();
}

