//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/dom/PExternalHelperAppParent.h"

#include "mozilla/dom/PContentParent.h"
#include "mozilla/net/PChannelDiverterParent.h"

#include "nsIFile.h"
#include "GeckoProfiler.h"

namespace mozilla {
namespace dom {



MOZ_IMPLICIT PExternalHelperAppParent::PExternalHelperAppParent() :
    mozilla::ipc::IProtocol(mozilla::ipc::ParentSide),
    mState(PExternalHelperApp::__Dead)
{
    MOZ_COUNT_CTOR(PExternalHelperAppParent);
}

PExternalHelperAppParent::~PExternalHelperAppParent()
{
    MOZ_COUNT_DTOR(PExternalHelperAppParent);
}

auto PExternalHelperAppParent::Manager() const -> PContentParent*
{
    return static_cast<PContentParent*>(IProtocol::Manager());
}

auto PExternalHelperAppParent::state() -> PExternalHelperApp::State
{
    return mState;
}

auto PExternalHelperAppParent::SendCancel(const nsresult& aStatus) -> bool
{
    IPC::Message* msg__ = PExternalHelperApp::Msg_Cancel(Id());

    Write(aStatus, msg__);
    // Sentinel = 'aStatus'
    (msg__)->WriteSentinel(236002576);




    if (mozilla::ipc::LoggingEnabledFor("PExternalHelperAppParent")) {
        mozilla::ipc::LogMessageForProtocol("PExternalHelperAppParent", OtherPid(), "Sending ", (msg__)->type(), mozilla::ipc::MessageDirection::eSending);
    }
    PROFILER_LABEL("PExternalHelperApp", "Msg_Cancel", js::ProfileEntry::Category::OTHER);
    if ((!(PExternalHelperApp::Transition(Trigger(Trigger::Send, PExternalHelperApp::Msg_Cancel__ID), (&(mState)))))) {
        NS_WARNING("bad state transition!");
    }

    bool sendok__ = (GetIPCChannel())->Send(msg__);
    return sendok__;
}

auto PExternalHelperAppParent::Send__delete__(PExternalHelperAppParent* actor) -> bool
{
    if ((!(actor))) {
        return false;
    }

    IPC::Message* msg__ = PExternalHelperApp::Msg___delete__((actor)->Id());

    (actor)->Write(actor, msg__, false);
    // Sentinel = 'actor'
    (msg__)->WriteSentinel(875202478);



    if (mozilla::ipc::LoggingEnabledFor("PExternalHelperAppParent")) {
        mozilla::ipc::LogMessageForProtocol("PExternalHelperAppParent", (actor)->OtherPid(), "Sending ", (msg__)->type(), mozilla::ipc::MessageDirection::eSending);
    }
    PROFILER_LABEL("PExternalHelperApp", "Msg___delete__", js::ProfileEntry::Category::OTHER);
    if ((!(PExternalHelperApp::Transition(Trigger(Trigger::Send, PExternalHelperApp::Msg___delete____ID), (&((actor)->mState)))))) {
        NS_WARNING("bad state transition!");
    }

    bool sendok__ = ((actor)->GetIPCChannel())->Send(msg__);

    (actor)->DestroySubtree(Deletion);
    (actor)->DeallocSubtree();
    ((actor)->Manager())->RemoveManagee(PExternalHelperAppMsgStart, actor);
    return sendok__;
}

auto PExternalHelperAppParent::RemoveManagee(
        int32_t aProtocolId,
        ProtocolBase* aListener) -> void
{
    FatalError("unreached");
    return;
}

auto PExternalHelperAppParent::OnMessageReceived(const Message& msg__) -> PExternalHelperAppParent::Result
{
    switch ((msg__).type()) {
    case PExternalHelperApp::Msg_OnStartRequest__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PExternalHelperAppParent")) {
                mozilla::ipc::LogMessageForProtocol("PExternalHelperAppParent", OtherPid(), "Received ", ((&(msg__)))->type(), mozilla::ipc::MessageDirection::eReceiving);
            }
            PROFILER_LABEL("PExternalHelperApp", "Msg_OnStartRequest", js::ProfileEntry::Category::OTHER);

            PickleIterator iter__ = PickleIterator(msg__);
            nsCString entityID;

            if ((!(Read((&(entityID)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            // Sentinel = 'entityID'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 245743354)))) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PExternalHelperApp::Transition(Trigger(Trigger::Recv, PExternalHelperApp::Msg_OnStartRequest__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            if ((!(RecvOnStartRequest(mozilla::Move(entityID))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PExternalHelperApp::Msg_OnDataAvailable__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PExternalHelperAppParent")) {
                mozilla::ipc::LogMessageForProtocol("PExternalHelperAppParent", OtherPid(), "Received ", ((&(msg__)))->type(), mozilla::ipc::MessageDirection::eReceiving);
            }
            PROFILER_LABEL("PExternalHelperApp", "Msg_OnDataAvailable", js::ProfileEntry::Category::OTHER);

            PickleIterator iter__ = PickleIterator(msg__);
            nsCString data;
            uint64_t offset;
            uint32_t count;

            if ((!(Read((&(data)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            // Sentinel = 'data'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 843352540)))) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            if ((!(Read((&(offset)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'uint64_t'");
                return MsgValueError;
            }
            // Sentinel = 'offset'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 1369947863)))) {
                FatalError("Error deserializing 'uint64_t'");
                return MsgValueError;
            }
            if ((!(Read((&(count)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'uint32_t'");
                return MsgValueError;
            }
            // Sentinel = 'count'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 2126421856)))) {
                FatalError("Error deserializing 'uint32_t'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PExternalHelperApp::Transition(Trigger(Trigger::Recv, PExternalHelperApp::Msg_OnDataAvailable__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            if ((!(RecvOnDataAvailable(mozilla::Move(data), mozilla::Move(offset), mozilla::Move(count))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PExternalHelperApp::Msg_OnStopRequest__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PExternalHelperAppParent")) {
                mozilla::ipc::LogMessageForProtocol("PExternalHelperAppParent", OtherPid(), "Received ", ((&(msg__)))->type(), mozilla::ipc::MessageDirection::eReceiving);
            }
            PROFILER_LABEL("PExternalHelperApp", "Msg_OnStopRequest", js::ProfileEntry::Category::OTHER);

            PickleIterator iter__ = PickleIterator(msg__);
            nsresult code;

            if ((!(Read((&(code)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'nsresult'");
                return MsgValueError;
            }
            // Sentinel = 'code'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 3318913027)))) {
                FatalError("Error deserializing 'nsresult'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PExternalHelperApp::Transition(Trigger(Trigger::Recv, PExternalHelperApp::Msg_OnStopRequest__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            if ((!(RecvOnStopRequest(mozilla::Move(code))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PExternalHelperApp::Msg_DivertToParentUsing__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PExternalHelperAppParent")) {
                mozilla::ipc::LogMessageForProtocol("PExternalHelperAppParent", OtherPid(), "Received ", ((&(msg__)))->type(), mozilla::ipc::MessageDirection::eReceiving);
            }
            PROFILER_LABEL("PExternalHelperApp", "Msg_DivertToParentUsing", js::ProfileEntry::Category::OTHER);

            PickleIterator iter__ = PickleIterator(msg__);
            PChannelDiverterParent* diverter;

            if ((!(Read((&(diverter)), (&(msg__)), (&(iter__)), false)))) {
                FatalError("Error deserializing 'PChannelDiverterParent'");
                return MsgValueError;
            }
            // Sentinel = 'diverter'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 1783530825)))) {
                FatalError("Error deserializing 'PChannelDiverterParent'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PExternalHelperApp::Transition(Trigger(Trigger::Recv, PExternalHelperApp::Msg_DivertToParentUsing__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            if ((!(RecvDivertToParentUsing(mozilla::Move(diverter))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PExternalHelperApp::Reply___delete____ID:
        {
            return MsgProcessed;
        }
    default:
        {
            return MsgNotKnown;
        }
    }
}

auto PExternalHelperAppParent::OnMessageReceived(
        const Message& msg__,
        Message*& reply__) -> PExternalHelperAppParent::Result
{
    return MsgNotKnown;
}

auto PExternalHelperAppParent::OnCallReceived(
        const Message& msg__,
        Message*& reply__) -> PExternalHelperAppParent::Result
{
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}

auto PExternalHelperAppParent::GetProtocolTypeId() -> int32_t
{
    return PExternalHelperAppMsgStart;
}

auto PExternalHelperAppParent::ProtocolName() const -> const char*
{
    return "PExternalHelperAppParent";
}

auto PExternalHelperAppParent::DestroySubtree(ActorDestroyReason why) -> void
{
    // Unregister from our manager.
    Unregister(Id());
    SetId(1);

    // Finally, destroy "us".
    ActorDestroy(why);
}

auto PExternalHelperAppParent::DeallocSubtree() -> void
{
}

auto PExternalHelperAppParent::Write(
        const PExternalHelperAppParent* v__,
        Message* msg__,
        bool nullable__) -> void
{
    int32_t id;
    if ((!(v__))) {
        if ((!(nullable__))) {
            FatalError("NULL actor value passed to non-nullable param");
        }
        id = 0;
    }
    else {
        id = (v__)->Id();
        if ((1) == (id)) {
            FatalError("actor has been |delete|d");
        }
    }

    Write(id, msg__);
}

auto PExternalHelperAppParent::Read(
        PExternalHelperAppParent** v__,
        const Message* msg__,
        PickleIterator* iter__,
        bool nullable__) -> bool
{
    Maybe<mozilla::ipc::IProtocol*> actor = ReadActor(msg__, iter__, nullable__, "PExternalHelperApp", PExternalHelperAppMsgStart);
    if ((actor).isNothing()) {
        return false;
    }

    (*(v__)) = static_cast<PExternalHelperAppParent*>((actor).value());
    return true;
}

auto PExternalHelperAppParent::Write(
        const PChannelDiverterParent* v__,
        Message* msg__,
        bool nullable__) -> void
{
    int32_t id;
    if ((!(v__))) {
        if ((!(nullable__))) {
            FatalError("NULL actor value passed to non-nullable param");
        }
        id = 0;
    }
    else {
        id = (v__)->Id();
        if ((1) == (id)) {
            FatalError("actor has been |delete|d");
        }
    }

    Write(id, msg__);
}

auto PExternalHelperAppParent::Read(
        PChannelDiverterParent** v__,
        const Message* msg__,
        PickleIterator* iter__,
        bool nullable__) -> bool
{
    Maybe<mozilla::ipc::IProtocol*> actor = ReadActor(msg__, iter__, nullable__, "PChannelDiverter", PChannelDiverterMsgStart);
    if ((actor).isNothing()) {
        return false;
    }

    (*(v__)) = static_cast<PChannelDiverterParent*>((actor).value());
    return true;
}



} // namespace dom
} // namespace mozilla
