<filename>projects/node-pylon/src/pylon/PylonDevice.cc
// MIT License
// 
// Copyright (c) 2017 - 2018 <NAME> <<EMAIL>>
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// 
// ----------------------------------------------------------------------------
// This is auto generated code by pylon-node-gen.
// Do not edit this file or all your changes will be lost after re-generation.
// ----------------------------------------------------------------------------

#include "pylondevice.h"
#include "../pylon_v8.h"

using namespace v8;
using namespace Pylon;

Nan::Persistent<FunctionTemplate> PylonDeviceWrap::prototype;
Nan::Persistent<Function> PylonDeviceWrap::constructor;

// Supported implementations
// IPylonDevice()
// IPylonDevice(IPylonDevice& const arg0)
PylonDeviceWrap::PylonDeviceWrap(Nan::NAN_METHOD_ARGS_TYPE info)
  : m_PylonDevice(NULL)
{
    // Check constructor arguments
    if (info.Length() == 0)
    {
        // IPylonDevice()
        m_PylonDevice = new IPylonDevice();
    }
    else if ((info.Length() == 1) && (info[0]->IsObject() && (pylon_v8::ToGCString(info[0]->ToObject()->GetConstructorName()) == "IPylonDevice")))
    {
        // Unwrap object
        PylonDeviceWrap* arg0_wrap = ObjectWrap::Unwrap<PylonDeviceWrap>(info[0]->ToObject());
        IPylonDevice* arg0 = arg0_wrap->GetWrapped();

        // IPylonDevice(IPylonDevice& const arg0)
        m_PylonDevice = new IPylonDevice(*arg0);
    }
}

PylonDeviceWrap::~PylonDeviceWrap()
{
    delete m_PylonDevice;
}

NAN_MODULE_INIT(PylonDeviceWrap::Initialize)
{
    // Prepare constructor template
    Local <FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
    tpl->SetClassName(Nan::New("PylonDeviceWrap").ToLocalChecked());
    tpl->InstanceTemplate()->SetInternalFieldCount(1);

    // Register prototypes to template
    Nan::SetPrototypeMethod(tpl, "getNumStreamGrabberChannels", GetNumStreamGrabberChannels);
    Nan::SetPrototypeMethod(tpl, "getStreamGrabber", GetStreamGrabber);
    Nan::SetPrototypeMethod(tpl, "getEventGrabber", GetEventGrabber);
    Nan::SetPrototypeMethod(tpl, "getNodeMap", GetNodeMap);
    Nan::SetPrototypeMethod(tpl, "getTLNodeMap", GetTLNodeMap);
    Nan::SetPrototypeMethod(tpl, "createChunkParser", CreateChunkParser);
    Nan::SetPrototypeMethod(tpl, "destroyChunkParser", DestroyChunkParser);
    Nan::SetPrototypeMethod(tpl, "createEventAdapter", CreateEventAdapter);
    Nan::SetPrototypeMethod(tpl, "destroyEventAdapter", DestroyEventAdapter);
    Nan::SetPrototypeMethod(tpl, "createSelfReliantChunkParser", CreateSelfReliantChunkParser);
    Nan::SetPrototypeMethod(tpl, "destroySelfReliantChunkParser", DestroySelfReliantChunkParser);
    Nan::SetPrototypeMethod(tpl, "registerRemovalCallback", RegisterRemovalCallback);
    Nan::SetPrototypeMethod(tpl, "deregisterRemovalCallback", DeregisterRemovalCallback);

    // Register template in Node JS
    prototype.Reset(tpl);
    Local<Function> function = Nan::GetFunction(tpl).ToLocalChecked();
    constructor.Reset(function);
    Nan::Set(target, Nan::New("IPylonDevice").ToLocalChecked(), function);
}

NAN_METHOD(PylonDeviceWrap::CreateChunkParser)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if (info.Length() == 0)
    {
        // Call wrapped method
        pylonDevice->CreateChunkParser();
    }
}

NAN_METHOD(PylonDeviceWrap::CreateEventAdapter)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if (info.Length() == 0)
    {
        // Call wrapped method
        pylonDevice->CreateEventAdapter();
    }
}

NAN_METHOD(PylonDeviceWrap::CreateSelfReliantChunkParser)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if (info.Length() == 0)
    {
        // Call wrapped method
        pylonDevice->CreateSelfReliantChunkParser();
    }
}

NAN_METHOD(PylonDeviceWrap::DeregisterRemovalCallback)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if ((info.Length() == 1) && info[0]->IsObject())
    {
        // TODO: Implement wrapper for void

        // Call wrapped method
        bool result = pylonDevice->DeregisterRemovalCallback(arg0);

        // Set return value
        info.GetReturnValue().Set(Nan::New<Boolean>(result));
    }
}

NAN_METHOD(PylonDeviceWrap::DestroyChunkParser)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if ((info.Length() == 1) && (info[0]->IsObject() && (pylon_v8::ToGCString(info[0]->ToObject()->GetConstructorName()) == "IChunkParser")))
    {
        // Unwrap object
        ChunkParserWrap* arg0_wrap = ObjectWrap::Unwrap<ChunkParserWrap>(info[0]->ToObject());
        IChunkParser* arg0 = arg0_wrap->GetWrapped();

        // Call wrapped method
        pylonDevice->DestroyChunkParser(arg0);

        // Set return value to undefined
        info.GetReturnValue().SetUndefined();
    }
}

NAN_METHOD(PylonDeviceWrap::DestroyEventAdapter)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if ((info.Length() == 1) && (info[0]->IsObject() && (pylon_v8::ToGCString(info[0]->ToObject()->GetConstructorName()) == "IEventAdapter")))
    {
        // Unwrap object
        EventAdapterWrap* arg0_wrap = ObjectWrap::Unwrap<EventAdapterWrap>(info[0]->ToObject());
        IEventAdapter* arg0 = arg0_wrap->GetWrapped();

        // Call wrapped method
        pylonDevice->DestroyEventAdapter(arg0);

        // Set return value to undefined
        info.GetReturnValue().SetUndefined();
    }
}

NAN_METHOD(PylonDeviceWrap::DestroySelfReliantChunkParser)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if ((info.Length() == 1) && (info[0]->IsObject() && (pylon_v8::ToGCString(info[0]->ToObject()->GetConstructorName()) == "ISelfReliantChunkParser")))
    {
        // Unwrap object
        SelfReliantChunkParserWrap* arg0_wrap = ObjectWrap::Unwrap<SelfReliantChunkParserWrap>(info[0]->ToObject());
        ISelfReliantChunkParser* arg0 = arg0_wrap->GetWrapped();

        // Call wrapped method
        pylonDevice->DestroySelfReliantChunkParser(arg0);

        // Set return value to undefined
        info.GetReturnValue().SetUndefined();
    }
}

NAN_METHOD(PylonDeviceWrap::GetEventGrabber)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if (info.Length() == 0)
    {
        // Call wrapped method
        // TODO: Implement return value wrapper for pylonDevice->GetEventGrabber()
    }
}

NAN_METHOD(PylonDeviceWrap::GetNodeMap)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if (info.Length() == 0)
    {
        // Call wrapped method
        pylonDevice->GetNodeMap();
    }
}

NAN_METHOD(PylonDeviceWrap::GetNumStreamGrabberChannels)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if (info.Length() == 0)
    {
        // Call wrapped method
        unsigned int result = pylonDevice->GetNumStreamGrabberChannels();

        // Set return value
        info.GetReturnValue().Set(Nan::New<Number>(result));
    }
}

NAN_METHOD(PylonDeviceWrap::GetStreamGrabber)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if ((info.Length() == 1) && info[0]->IsNumber())
    {
        // Convert from number value
        unsigned int arg0 = static_cast<unsigned int>(info[0]->NumberValue());

        // Call wrapped method
        pylonDevice->GetStreamGrabber(arg0);
    }
}

NAN_METHOD(PylonDeviceWrap::GetTLNodeMap)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if (info.Length() == 0)
    {
        // Call wrapped method
        pylonDevice->GetTLNodeMap();
    }
}

NAN_METHOD(PylonDeviceWrap::RegisterRemovalCallback)
{
    PylonDeviceWrap* wrappedPylonDevice = ObjectWrap::Unwrap<PylonDeviceWrap>(info.This());
    IPylonDevice* pylonDevice = wrappedPylonDevice->GetWrapped();

    if ((info.Length() == 1) && info[0]->IsObject())
    {
        // TODO: Implement wrapper for Callback1<Pylon::IPylonDevice *>

        // Call wrapped method
        // TODO: Implement return value wrapper for pylonDevice->RegisterRemovalCallback(*arg0)
    }
}
