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

#include "config.h"

#if ENABLE(RMAI)

#include "MOMSatellite.h"
#include "MOMTransportStream.h"
#include "MOMChannelScanOptions.h"
#include "MOMContentItem.h"
#include "MOMException.h"
#include "MOMTransportStream.h"

namespace WebCore {

PassRefPtr<MOMSatellite> MOMSatellite::createAdopt(ScriptExecutionContext *context, mom_satellite satellite)
{
    return static_pointer_cast<MOMSatellite>(MOMContentItem::createAdopt(context, (mom_content_item)satellite));
}

MOMSatellite::MOMSatellite(ScriptExecutionContext* context, mom_content_item item)
    : MOMContentItem(context, item)
{
}

bool MOMSatellite::enabled() const
{
    return mom_satellite_enabled(itemAsSatellite());
}

void MOMSatellite::setEnabled(bool enabled)
{
    mom_satellite_enabled_set(itemAsSatellite(), enabled);
}

bool MOMSatellite::userCreated() const
{
    return mom_satellite_userCreated(itemAsSatellite());
}

bool MOMSatellite::useTone() const
{
    return mom_satellite_useTone(itemAsSatellite());
}

void MOMSatellite::setUseTone(bool useTone)
{
    mom_satellite_useTone_set(itemAsSatellite(), useTone);
}

bool MOMSatellite::lNBPower() const
{
    return mom_satellite_LNBPower(itemAsSatellite());
}

void MOMSatellite::setLNBPower(bool LNBPower)
{
    mom_satellite_LNBPower_set(itemAsSatellite(), LNBPower);
}

int MOMSatellite::lNBType() const
{
    return mom_satellite_LNBType(itemAsSatellite());
}

void MOMSatellite::setLNBType(int LNBType)
{
    mom_satellite_LNBType_set(itemAsSatellite(), LNBType);
}

int MOMSatellite::lNBFrequencyLowMHz() const
{
    return mom_satellite_LNBFrequencyLow(itemAsSatellite());
}

void MOMSatellite::setLNBFrequencyLowMHz(int LNBFrequencyLowMHz)
{
    mom_satellite_LNBFrequencyLow_set(itemAsSatellite(), LNBFrequencyLowMHz);
}

int MOMSatellite::lNBFrequencyHighMHz() const
{
    return mom_satellite_LNBFrequencyHigh(itemAsSatellite());
}

void MOMSatellite::setLNBFrequencyHighMHz(int LNBFrequencyHighMHz)
{
    mom_satellite_LNBFrequencyHigh_set(itemAsSatellite(), LNBFrequencyHighMHz);
}

int MOMSatellite::diSEqCPort() const
{
    return mom_satellite_DiSEqCPort(itemAsSatellite());
}

void MOMSatellite::setDiSEqCPort(int DiSEqCPort)
{
    mom_satellite_DiSEqCPort_set(itemAsSatellite(), DiSEqCPort);
}

MOMContentList* MOMSatellite::transportStreams() const
{
    if (!m_transportStreams)
        m_transportStreams = MOMContentList::create(scriptExecutionContext(), mom_satellite_transportstreams_get(itemAsSatellite()));
    return m_transportStreams.get();
}

MOMTransportStream* MOMSatellite::homeTransponder() const
{
    if (!m_homeTransponder)
        m_homeTransponder = MOMTransportStream::create(scriptExecutionContext(), mom_satellite_hometransponder_get(itemAsSatellite()));
    return m_homeTransponder.get();
}

PassRefPtr<MOMTransportStream> MOMSatellite::createTransportStream(ExceptionCode& ec)
{
    mom_transportstream stream;
    mom_error err = mom_satellite_transportstream_create(itemAsSatellite(), &stream);
    if (err != ERR_NONE)
    {
        MOMException::setFromMOMError(err, ec);
        return nullptr;
    }
    return MOMTransportStream::createAdopt(scriptExecutionContext(), stream);
}

void MOMSatellite::remove( MOMTransportStream* transportStream )
{
    mom_satellite_transportstream_object_destroy(itemAsSatellite(), transportStream->itemAsTransportStream());
}

void MOMSatellite::startScan( MOMChannelScanOptions* options )
{
    // not implemented
}

void MOMSatellite::startScan()
{
	startScan(0);
}

} // namespace WebCore

#endif // ENABLE(RMAI)
