/* This file is part of the KDE project
   Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
             (C) 1999 David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "envycardfactory.h"

#include <alsa/asoundlib.h>
#include <kdebug.h>

#include "envycard.h"

EnvyCardFactory::EnvyCardFactory()
{
}

QList< EnvyCard* > EnvyCardFactory::searchTheCards()
{
    QList< EnvyCard* > result;

    snd_ctl_card_info_t     *hw_info;
    snd_ctl_card_info_alloca(&hw_info);

    char        cardname[32];
    snd_ctl_t   *ctl;

    kDebug() << "searching for ICE1712 based cards";

    // FIXME hard coded number of cards
    for (int cardNumber = 0; cardNumber < 8; cardNumber++) {
        snprintf(cardname, sizeof(cardname)/sizeof(char), "hw:%d", cardNumber);
        if ((snd_ctl_open(&ctl, cardname, 0)) < 0)
            continue;
        if (snd_ctl_card_info(ctl, hw_info) < 0 ||
            strcmp(snd_ctl_card_info_get_driver(hw_info), "ICE1712")) {
            snd_ctl_close(ctl);
            continue;
        }
        /* found */
        kDebug() << "found a card named " << cardname;
        EnvyCard* card = new EnvyCard( ctl, cardname, cardNumber );
        result.append( card );
    }

    return result;
}

// kate: space-indent on; indent-width 4; replace-tabs on;
