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


#include "mozilla/dom/PHandlerServiceParent.h"

#include "mozilla/dom/PContentParent.h"

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

namespace mozilla {
namespace dom {


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


MOZ_IMPLICIT PHandlerServiceParent::PHandlerServiceParent() :
    mozilla::ipc::IProtocol(mozilla::ipc::ParentSide),
    mState(PHandlerService::__Dead)
{
    MOZ_COUNT_CTOR(PHandlerServiceParent);
}

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

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

auto PHandlerServiceParent::state() -> PHandlerService::State
{
    return mState;
}

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

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

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

            if ((!(Read((&(actor)), (&(msg__)), (&(iter__)), false)))) {
                FatalError("Error deserializing 'PHandlerServiceParent'");
                return MsgValueError;
            }
            // Sentinel = 'actor'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 875202478)))) {
                FatalError("Error deserializing 'PHandlerServiceParent'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PHandlerService::Transition(Trigger(Trigger::Recv, PHandlerService::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(PHandlerServiceMsgStart, actor);

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

auto PHandlerServiceParent::OnMessageReceived(
        const Message& msg__,
        Message*& reply__) -> PHandlerServiceParent::Result
{
    switch ((msg__).type()) {
    case PHandlerService::Msg_FillHandlerInfo__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PHandlerServiceParent")) {
                mozilla::ipc::LogMessageForProtocol("PHandlerServiceParent", OtherPid(), "Received ", ((&(msg__)))->type(), mozilla::ipc::MessageDirection::eReceiving);
            }
            PROFILER_LABEL("PHandlerService", "Msg_FillHandlerInfo", js::ProfileEntry::Category::OTHER);

            PickleIterator iter__ = PickleIterator(msg__);
            HandlerInfo aHandlerInfoData;
            nsCString aOverrideType;

            if ((!(Read((&(aHandlerInfoData)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'HandlerInfo'");
                return MsgValueError;
            }
            // Sentinel = 'aHandlerInfoData'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 818541303)))) {
                FatalError("Error deserializing 'HandlerInfo'");
                return MsgValueError;
            }
            if ((!(Read((&(aOverrideType)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            // Sentinel = 'aOverrideType'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 923193756)))) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PHandlerService::Transition(Trigger(Trigger::Recv, PHandlerService::Msg_FillHandlerInfo__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            HandlerInfo handlerInfoData;
            int32_t id__ = Id();
            if ((!(RecvFillHandlerInfo(mozilla::Move(aHandlerInfoData), mozilla::Move(aOverrideType), (&(handlerInfoData)))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                return MsgProcessingError;
            }

            reply__ = PHandlerService::Reply_FillHandlerInfo(id__);

            Write(handlerInfoData, reply__);
            // Sentinel = 'handlerInfoData'
            (reply__)->WriteSentinel(49315047);
            (reply__)->set_sync();
            (reply__)->set_reply();

            if (mozilla::ipc::LoggingEnabledFor("PHandlerServiceParent")) {
                mozilla::ipc::LogMessageForProtocol("PHandlerServiceParent", OtherPid(), "Sending reply ", (reply__)->type(), mozilla::ipc::MessageDirection::eSending);
            }
            return MsgProcessed;
        }
    case PHandlerService::Msg_Exists__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PHandlerServiceParent")) {
                mozilla::ipc::LogMessageForProtocol("PHandlerServiceParent", OtherPid(), "Received ", ((&(msg__)))->type(), mozilla::ipc::MessageDirection::eReceiving);
            }
            PROFILER_LABEL("PHandlerService", "Msg_Exists", js::ProfileEntry::Category::OTHER);

            PickleIterator iter__ = PickleIterator(msg__);
            HandlerInfo aHandlerInfo;

            if ((!(Read((&(aHandlerInfo)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'HandlerInfo'");
                return MsgValueError;
            }
            // Sentinel = 'aHandlerInfo'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 1227275979)))) {
                FatalError("Error deserializing 'HandlerInfo'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PHandlerService::Transition(Trigger(Trigger::Recv, PHandlerService::Msg_Exists__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            bool exists;
            int32_t id__ = Id();
            if ((!(RecvExists(mozilla::Move(aHandlerInfo), (&(exists)))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                return MsgProcessingError;
            }

            reply__ = PHandlerService::Reply_Exists(id__);

            Write(exists, reply__);
            // Sentinel = 'exists'
            (reply__)->WriteSentinel(351132806);
            (reply__)->set_sync();
            (reply__)->set_reply();

            if (mozilla::ipc::LoggingEnabledFor("PHandlerServiceParent")) {
                mozilla::ipc::LogMessageForProtocol("PHandlerServiceParent", OtherPid(), "Sending reply ", (reply__)->type(), mozilla::ipc::MessageDirection::eSending);
            }
            return MsgProcessed;
        }
    case PHandlerService::Msg_GetTypeFromExtension__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PHandlerServiceParent")) {
                mozilla::ipc::LogMessageForProtocol("PHandlerServiceParent", OtherPid(), "Received ", ((&(msg__)))->type(), mozilla::ipc::MessageDirection::eReceiving);
            }
            PROFILER_LABEL("PHandlerService", "Msg_GetTypeFromExtension", js::ProfileEntry::Category::OTHER);

            PickleIterator iter__ = PickleIterator(msg__);
            nsCString aFileExtension;

            if ((!(Read((&(aFileExtension)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            // Sentinel = 'aFileExtension'
            if ((!(((&(msg__)))->ReadSentinel((&(iter__)), 2406627352)))) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PHandlerService::Transition(Trigger(Trigger::Recv, PHandlerService::Msg_GetTypeFromExtension__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            nsCString type;
            int32_t id__ = Id();
            if ((!(RecvGetTypeFromExtension(mozilla::Move(aFileExtension), (&(type)))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                return MsgProcessingError;
            }

            reply__ = PHandlerService::Reply_GetTypeFromExtension(id__);

            Write(type, reply__);
            // Sentinel = 'type'
            (reply__)->WriteSentinel(2982068540);
            (reply__)->set_sync();
            (reply__)->set_reply();

            if (mozilla::ipc::LoggingEnabledFor("PHandlerServiceParent")) {
                mozilla::ipc::LogMessageForProtocol("PHandlerServiceParent", OtherPid(), "Sending reply ", (reply__)->type(), mozilla::ipc::MessageDirection::eSending);
            }
            return MsgProcessed;
        }
    default:
        {
            return MsgNotKnown;
        }
    }
}

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

auto PHandlerServiceParent::GetProtocolTypeId() -> int32_t
{
    return PHandlerServiceMsgStart;
}

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

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

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

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

auto PHandlerServiceParent::Write(
        const PHandlerServiceParent* 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 PHandlerServiceParent::Read(
        PHandlerServiceParent** v__,
        const Message* msg__,
        PickleIterator* iter__,
        bool nullable__) -> bool
{
    Maybe<mozilla::ipc::IProtocol*> actor = ReadActor(msg__, iter__, nullable__, "PHandlerService", PHandlerServiceMsgStart);
    if ((actor).isNothing()) {
        return false;
    }

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

auto PHandlerServiceParent::Write(
        const HandlerInfo& v__,
        Message* msg__) -> void
{
    Write((v__).type(), msg__);
    // Sentinel = 'type'
    (msg__)->WriteSentinel(2982068540);
    Write((v__).isMIMEInfo(), msg__);
    // Sentinel = 'isMIMEInfo'
    (msg__)->WriteSentinel(1069536950);
    Write((v__).description(), msg__);
    // Sentinel = 'description'
    (msg__)->WriteSentinel(962879941);
    Write((v__).alwaysAskBeforeHandling(), msg__);
    // Sentinel = 'alwaysAskBeforeHandling'
    (msg__)->WriteSentinel(1120635835);
    Write((v__).preferredApplicationHandler(), msg__);
    // Sentinel = 'preferredApplicationHandler'
    (msg__)->WriteSentinel(2543375802);
    Write((v__).possibleApplicationHandlers(), msg__);
    // Sentinel = 'possibleApplicationHandlers'
    (msg__)->WriteSentinel(608941865);
    Write((v__).preferredAction(), msg__);
    // Sentinel = 'preferredAction'
    (msg__)->WriteSentinel(3465546922);
}

auto PHandlerServiceParent::Read(
        HandlerInfo* v__,
        const Message* msg__,
        PickleIterator* iter__) -> bool
{
    if ((!(Read((&((v__)->type())), msg__, iter__)))) {
        FatalError("Error deserializing 'type' (nsCString) member of 'HandlerInfo'");
        return false;
    }
    // Sentinel = 'type'
    if ((!((msg__)->ReadSentinel(iter__, 2982068540)))) {
        FatalError("Error deserializing 'type' (nsCString) member of 'HandlerInfo'");
        return false;
    }
    if ((!(Read((&((v__)->isMIMEInfo())), msg__, iter__)))) {
        FatalError("Error deserializing 'isMIMEInfo' (bool) member of 'HandlerInfo'");
        return false;
    }
    // Sentinel = 'isMIMEInfo'
    if ((!((msg__)->ReadSentinel(iter__, 1069536950)))) {
        FatalError("Error deserializing 'isMIMEInfo' (bool) member of 'HandlerInfo'");
        return false;
    }
    if ((!(Read((&((v__)->description())), msg__, iter__)))) {
        FatalError("Error deserializing 'description' (nsString) member of 'HandlerInfo'");
        return false;
    }
    // Sentinel = 'description'
    if ((!((msg__)->ReadSentinel(iter__, 962879941)))) {
        FatalError("Error deserializing 'description' (nsString) member of 'HandlerInfo'");
        return false;
    }
    if ((!(Read((&((v__)->alwaysAskBeforeHandling())), msg__, iter__)))) {
        FatalError("Error deserializing 'alwaysAskBeforeHandling' (bool) member of 'HandlerInfo'");
        return false;
    }
    // Sentinel = 'alwaysAskBeforeHandling'
    if ((!((msg__)->ReadSentinel(iter__, 1120635835)))) {
        FatalError("Error deserializing 'alwaysAskBeforeHandling' (bool) member of 'HandlerInfo'");
        return false;
    }
    if ((!(Read((&((v__)->preferredApplicationHandler())), msg__, iter__)))) {
        FatalError("Error deserializing 'preferredApplicationHandler' (HandlerApp) member of 'HandlerInfo'");
        return false;
    }
    // Sentinel = 'preferredApplicationHandler'
    if ((!((msg__)->ReadSentinel(iter__, 2543375802)))) {
        FatalError("Error deserializing 'preferredApplicationHandler' (HandlerApp) member of 'HandlerInfo'");
        return false;
    }
    if ((!(Read((&((v__)->possibleApplicationHandlers())), msg__, iter__)))) {
        FatalError("Error deserializing 'possibleApplicationHandlers' (HandlerApp[]) member of 'HandlerInfo'");
        return false;
    }
    // Sentinel = 'possibleApplicationHandlers'
    if ((!((msg__)->ReadSentinel(iter__, 608941865)))) {
        FatalError("Error deserializing 'possibleApplicationHandlers' (HandlerApp[]) member of 'HandlerInfo'");
        return false;
    }
    if ((!(Read((&((v__)->preferredAction())), msg__, iter__)))) {
        FatalError("Error deserializing 'preferredAction' (long) member of 'HandlerInfo'");
        return false;
    }
    // Sentinel = 'preferredAction'
    if ((!((msg__)->ReadSentinel(iter__, 3465546922)))) {
        FatalError("Error deserializing 'preferredAction' (long) member of 'HandlerInfo'");
        return false;
    }
    return true;
}

auto PHandlerServiceParent::Write(
        const nsTArray<HandlerApp>& v__,
        Message* msg__) -> void
{
    uint32_t length = (v__).Length();
    Write(length, msg__);
    // Sentinel = ('length', 'HandlerApp[]')
    (msg__)->WriteSentinel(2475415906);

    for (auto& elem : v__) {
        Write(elem, msg__);
        // Sentinel = 'HandlerApp[]'
        (msg__)->WriteSentinel(3933538253);
    }
}

auto PHandlerServiceParent::Read(
        nsTArray<HandlerApp>* v__,
        const Message* msg__,
        PickleIterator* iter__) -> bool
{
    nsTArray<HandlerApp> fa;
    uint32_t length;
    if ((!(Read((&(length)), msg__, iter__)))) {
        mozilla::ipc::ArrayLengthReadError("HandlerApp[]");
        return false;
    }
    // Sentinel = ('length', 'HandlerApp[]')
    if ((!((msg__)->ReadSentinel(iter__, 2475415906)))) {
        mozilla::ipc::ArrayLengthReadError("HandlerApp[]");
        return false;
    }

    HandlerApp* elems = (fa).AppendElements(length);
    for (uint32_t i = 0; (i) < (length); (++(i))) {
        if ((!(Read((&(elems[i])), msg__, iter__)))) {
            FatalError("Error deserializing 'HandlerApp[i]'");
            return false;
        }
        // Sentinel = 'HandlerApp[]'
        if ((!((msg__)->ReadSentinel(iter__, 3933538253)))) {
            FatalError("Error deserializing 'HandlerApp[i]'");
            return false;
        }
    }
    (v__)->SwapElements(fa);
    return true;
}

auto PHandlerServiceParent::Write(
        const HandlerApp& v__,
        Message* msg__) -> void
{
    Write((v__).name(), msg__);
    // Sentinel = 'name'
    (msg__)->WriteSentinel(15034981);
    Write((v__).detailedDescription(), msg__);
    // Sentinel = 'detailedDescription'
    (msg__)->WriteSentinel(4289276469);
}

auto PHandlerServiceParent::Read(
        HandlerApp* v__,
        const Message* msg__,
        PickleIterator* iter__) -> bool
{
    if ((!(Read((&((v__)->name())), msg__, iter__)))) {
        FatalError("Error deserializing 'name' (nsString) member of 'HandlerApp'");
        return false;
    }
    // Sentinel = 'name'
    if ((!((msg__)->ReadSentinel(iter__, 15034981)))) {
        FatalError("Error deserializing 'name' (nsString) member of 'HandlerApp'");
        return false;
    }
    if ((!(Read((&((v__)->detailedDescription())), msg__, iter__)))) {
        FatalError("Error deserializing 'detailedDescription' (nsString) member of 'HandlerApp'");
        return false;
    }
    // Sentinel = 'detailedDescription'
    if ((!((msg__)->ReadSentinel(iter__, 4289276469)))) {
        FatalError("Error deserializing 'detailedDescription' (nsString) member of 'HandlerApp'");
        return false;
    }
    return true;
}



} // namespace dom
} // namespace mozilla
