/*
 * 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 "sectionparser.h"
#include "patparser.h"
#include "pmtparser.h"
#include "..\\main.h"
#define WRITE(x){m_DLLInstance.x;}
cSectionParser::cSectionParser()
{
#ifdef PAT_PARSER
    m_table_parsers[0].table_id=SECTIONTYPE_PAT;
    m_table_parsers[0].table_parser=new cPATParser();
#endif
    m_table_parsers[1].table_id=SECTIONTYPE_PMT;
    m_table_parsers[1].table_parser=new cPMTParser();
}

cSectionParser::~cSectionParser()
{
//    delete m_curdatap;
}
cDataParser* cSectionParser::FindTableParser(int table_id)
{

    for(int i=0;i<sizeof(m_table_parsers)/sizeof(SECTIONDATAPARSER);i++)
        if (m_table_parsers[i].table_id==table_id) return m_table_parsers[i].table_parser;
    return 0;
}
bool cSectionParser::Parse()
{
    int table_id;
    if(m_buf)
    {
        table_id=m_buf[0];
        //WRITE(Log("table_id:%d\n",table_id))
        m_curdatap=FindTableParser(table_id);

        if(m_curdatap)
        {
            m_curdatap->SetBuffer(m_buf,m_buflength);
            return m_curdatap->Parse();
        }
        return false;

    }//if(m_buf)
}

