VLCException.cpp 2.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * VLCException.cpp: Binding for libvlc_exception
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * This program 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 program 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23 24 25 26 27
#include <QtDebug>
#include "VLCException.h"

using namespace LibVLCpp;

28 29
Exception::errorCallback        Exception::m_errorCallback = NULL;
void*                           Exception::m_datas = NULL;
30 31 32

Exception::Exception()
{
33 34
    m_internalPtr = new libvlc_exception_t;
    libvlc_exception_init( m_internalPtr );
35 36 37 38
}

Exception::~Exception()
{
39 40
    clear();
    delete m_internalPtr;
41 42
}

43
void        Exception::setErrorCallback( Exception::errorCallback handler, void* datas )
44
{
45 46
    Exception::m_datas = datas;
    Exception::m_errorCallback = handler;
47 48 49 50
}

const char* Exception::getErrorText() const
{
51
    return libvlc_exception_get_message( m_internalPtr );
52 53 54 55
}

void        Exception::clear()
{
56
    libvlc_exception_clear( m_internalPtr );
57 58 59 60
}

int         Exception::raised() const
{
61
    return libvlc_exception_raised( m_internalPtr );
62 63 64 65
}

void        Exception::checkThrow()
{
66
    if ( raised() == Exception::Raised )
67
    {
68 69
        if ( Exception::m_errorCallback != NULL )
            Exception::m_errorCallback( getErrorText(), Exception::m_datas );
70
        else
71 72
            qWarning() << "An exception was raised, but no error handler is set.\nError message is: " << getErrorText();
        clear();
73 74
    }
}