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

#include "config.h"

#if ENABLE(RMAI)

#include "MOMEvent.h"
#include "JSMOMEvent.h"
#include "JSDOMBinding.h"

#include "MOMPlayEvent.h"
#include "JSMOMPlayEvent.h"
#include "MOMRecordEvent.h"
#include "JSMOMRecordEvent.h"
#include "MOMGuideSearchEvent.h"
#include "JSMOMGuideSearchEvent.h"
#include "MOMUpdateEvent.h"
#include "JSMOMUpdateEvent.h"
#include "MOMAccessEvent.h"
#include "JSMOMAccessEvent.h"
#include "MOMContentEvent.h"
#include "JSMOMContentEvent.h"
#include "MOMContentCatalogueEvent.h"
#include "JSMOMContentCatalogueEvent.h"
#include "MOMDVREvent.h"
#include "JSMOMDVREvent.h"
#include "MOMChannelScanEvent.h"
#include "JSMOMChannelScanEvent.h"
#include "MOMEASEvent.h"
#include "JSMOMEASEvent.h"
#include "MOMResourceConflictEvent.h"
#include "JSMOMResourceConflictEvent.h"
#include "MOMMessageEvent.h"
#include "JSMOMMessageEvent.h"
#include "MOMRequestEvent.h"
#include "JSMOMRequestEvent.h"
#include "MOMDeviceEvent.h"
#include "JSMOMDeviceEvent.h"
#include "MOMPackageEvent.h"
#include "JSMOMPackageEvent.h"
#include "MOMPurchasableEvent.h"
#include "JSMOMPurchasableEvent.h"
#include "MOMPurchaseEvent.h"
#include "JSMOMPurchaseEvent.h"
#include "MOMDiscEvent.h"
#include "JSMOMDiscEvent.h"
#include "MOMNetworkTestEvent.h"
#include "JSMOMNetworkTestEvent.h"
#include "MOMComponentEvent.h"
#include "JSMOMComponentEvent.h"
#include "MOMDRMMessageResultEvent.h"
#include "JSMOMDRMMessageResultEvent.h"

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

using namespace JSC;

namespace WebCore {

JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, MOMEvent* event)
{
    if (!event)
        return jsNull();

    JSObject* wrapper = getCachedWrapper(globalObject->world(), event);
    if (wrapper)
        return wrapper;

    // keep this list in sync with the one in MOMEvent.cpp
    switch (event->momEventType())
    {
    case mom_event_PLAY:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMPlayEvent, event);
        break;
    case mom_event_RECORD:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMRecordEvent, event);
        break;
    case mom_event_GUIDESEARCH:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMGuideSearchEvent, event);
        break;
    case mom_event_UPDATE:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMUpdateEvent, event);
        break;
    case mom_event_ACCESS:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMAccessEvent, event);
        break;
    case mom_event_CONTENTACTION:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMContentEvent, event);
        break;
    case mom_event_CONTENTCATALOGUE:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMContentCatalogueEvent, event);
        break;
    case mom_event_DVR:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMDVREvent, event);
        break;
    case mom_event_CHANNELSCAN:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMChannelScanEvent, event);
        break;
    case mom_event_EAS:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMEASEvent, event);
        break;
    case mom_event_RESOURCECONFLICT:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMResourceConflictEvent, event);
        break;
    case mom_event_MESSAGE:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMMessageEvent, event);
        break;
    case mom_event_REQUEST:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMRequestEvent, event);
        break;
    case mom_event_DEVICE:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMDeviceEvent, event);
        break;
    case mom_event_PACKAGE:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMPackageEvent, event);
        break;
    case mom_event_PURCHASABLE:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMPurchasableEvent, event);
        break;
    case mom_event_PURCHASE:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMPurchaseEvent, event);
        break;
    case mom_event_DISC:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMDiscEvent, event);
        break;
    case mom_event_NETWORKTEST_RESULT:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMNetworkTestEvent, event);
        break;
    case mom_event_COMPONENT:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMComponentEvent, event);
        break;
    case mom_event_DRMMESSAGERESULT:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMDRMMessageResultEvent, event);
        break;

    // OIPF only events
    case mom_event_STREAM:
    case mom_event_CHANNELCHANGESUCCEEDED:
    case mom_event_CHANNELCHANGEERROR:
    case mom_event_FULLSCREENCHANGE:
    case mom_event_PLAYSTATECHANGED:
    case mom_event_PROGRAMMESCHANGED:
    case mom_event_PARENTALRATINGCHANGE:
    case mom_event_PARENTALRATINGERROR:
    case mom_event_OIPFPLAYSPEEDCHANGED:
    case mom_event_OIPFPLAYPOSITIONCHANGED:
    case mom_event_OIPFRECORDINGEVENT:
    case mom_event_MAX:
    default:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMEvent, event);
        break;
    }

    return wrapper;
}

} // namespace WebCore

#endif // ENABLE(RMAI)
