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


#include "mozilla/dom/PExternalHelperAppChild.h"

#include "mozilla/dom/PContentChild.h"
#include "mozilla/net/PChannelDiverterChild.h"

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

namespace mozilla {
namespace dom {


auto PExternalHelperAppChild::Recv__delete__() -> bool
{
    return true;
}

auto PExternalHelperAppChild::ActorDestroy(ActorDestroyReason aWhy) -> void
{
}

MOZ_IMPLICIT PExternalHelperAppChild::PExternalHelperAppChild() :
    mozilla::ipc::IProtocol(mozilla::ipc::ChildSide),
    mState(PExternalHelperApp::__Dead)
{
    MOZ_COUNT_CTOR(PExternalHelperAppChild);
}

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

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

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

auto PExternalHelperAppChild::SendOnStartRequest(const nsCString& entityID) -> bool
{
    IPC::Message* msg__ = PExternalHelperApp::Msg_OnStartRequest(Id());

    Write(entityID, msg__);
    // Sentinel = 'entityID'
    (msg__)->WriteSentinel(245743354);




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

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

auto PExternalHelperAppChild::SendOnDataAvailable(
        const nsCString& data,
        const uint64_t& offset,
        const uint32_t& count) -> bool
{
    IPC::Message* msg__ = PExternalHelperApp::Msg_OnDataAvailable(Id());

    Write(data, msg__);
    // Sentinel = 'data'
    (msg__)->WriteSentinel(843352540);
    Write(offset, msg__);
    // Sentinel = 'offset'
    (msg__)->WriteSentinel(1369947863);
    Write(count, msg__);
    // Sentinel = 'count'
    (msg__)->WriteSentinel(2126421856);




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

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

auto PExternalHelperAppChild::SendOnStopRequest(const nsresult& code) -> bool
{
    IPC::Message* msg__ = PExternalHelperApp::Msg_OnStopRequest(Id());

    Write(code, msg__);
    // Sentinel = 'code'
    (msg__)->WriteSentinel(3318913027);




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

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

auto PExternalHelperAppChild::SendDivertToParentUsing(PChannelDiverterChild* diverter) -> bool
{
    IPC::Message* msg__ = PExternalHelperApp::Msg_DivertToParentUsing(Id());

    Write(diverter, msg__, false);
    // Sentinel = 'diverter'
    (msg__)->WriteSentinel(1783530825);




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

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

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

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

            PickleIterator iter__ = PickleIterator(msg__);
            nsresult aStatus;

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

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

            PickleIterator iter__ = PickleIterator(msg__);
            PExternalHelperAppChild* actor;

            if ((!(Read((&(actor)), (&(msg__)), (&(iter__)), false)))) {
                FatalError("Error deserializing 'PExternalHelperAppChild'");
                return MsgValueError;
            }
            // Sentinel = 'actor'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 875202478)))) {
                FatalError("Error deserializing 'PExternalHelperAppChild'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PExternalHelperApp::Transition(Trigger(Trigger::Send, PExternalHelperApp::Msg___delete____ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            if ((!(Recv__delete__()))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                return MsgProcessingError;
            }


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

            return MsgProcessed;
        }
    default:
        {
            return MsgNotKnown;
        }
    }
}

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

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

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

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

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

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

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

auto PExternalHelperAppChild::Write(
        const PExternalHelperAppChild* 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 PExternalHelperAppChild::Read(
        PExternalHelperAppChild** 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<PExternalHelperAppChild*>((actor).value());
    return true;
}

auto PExternalHelperAppChild::Write(
        const PChannelDiverterChild* 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 PExternalHelperAppChild::Read(
        PChannelDiverterChild** 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<PChannelDiverterChild*>((actor).value());
    return true;
}



} // namespace dom
} // namespace mozilla
