/** @file MOMOutputCollection.cpp
 *
 * Copyright (C) Espial Limited 2014 - Company confidential - All rights reserved.
 *
 */

#include "config.h"

#if ENABLE(RMAI)

#include "MOMOutputCollection.h"
#include "MOMOutput.h"

#include "UtilsMOM.h"

extern "C" {
#include "layers.h"
#include "cdf/mom_output.h"
#include "cdf/mom_output_collection.h"
}

namespace WebCore {

PassRefPtr<MOMOutputCollection> MOMOutputCollection::create()
{
    return adoptRef(new MOMOutputCollection());
}

MOMOutputCollection::MOMOutputCollection()
{
}

int MOMOutputCollection::length() const
{
    return mom_output_collection_get_length();
}

PassRefPtr<MOMOutput> MOMOutputCollection::item( int index )
{
    return MOMOutput::create(index);
}

bool MOMOutputCollection::canGetItemsForName( const String & name )
{
    layers_string lname = UtilsMOM::LayersStringFromString(name);
    int count = mom_output_collection_get_length();

    bool canGet = false;
    for (int i = 0; i < count; i++)
    {
        if (layers_string_equal(mom_output_get_name(i), lname))
        {
            canGet = true;
            break;
        }
    }
    layers_string_dispose(lname);

    return canGet;
}

RefPtr<MOMOutput> MOMOutputCollection::namedItem( const String & name )
{
    layers_string lname = UtilsMOM::LayersStringFromString(name);
    int count = mom_output_collection_get_length();

    RefPtr<MOMOutput> output;
    for (int i = 0; i < count; i++)
    {
        if (layers_string_equal(mom_output_get_name(i), lname))
        {
            output = MOMOutput::create(i);
            break;
        }
    }
    layers_string_dispose(lname);

    return output;
}

} // namespace WebCore

#endif // ENABLE(RMAI)
