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


#include "mozilla/glean/PFOGTransportChild.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/glean/FOGTransportChild.h"
#include "mozilla/ipc/ByteBufUtils.h"


#include "ipc/IPCMessageUtils.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "nsIFile.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/ShmemMessageUtils.h"
#include "mozilla/ipc/TaintingIPCUtils.h"

namespace mozilla {
namespace glean {


auto PFOGTransportChild::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

auto PFOGTransportChild::ShouldContinueFromReplyTimeout() -> bool
{
    return true;
}

MOZ_IMPLICIT PFOGTransportChild::PFOGTransportChild() :
    mozilla::ipc::IToplevelProtocol("PFOGTransportChild", kProtocolId, mozilla::ipc::ChildSide)
{
    MOZ_COUNT_CTOR(PFOGTransportChild);
}

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

auto PFOGTransportChild::ActorAlloc() -> void
{
    MOZ_RELEASE_ASSERT(XRE_IsContentProcess(), "Invalid process for `PFOGTransportChild'");
    AddRef();
}

auto PFOGTransportChild::ActorDealloc() -> void
{
    Release();
}

auto PFOGTransportChild::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    return {};
}

auto PFOGTransportChild::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    default:
        return nullptr;
    }
}

auto PFOGTransportChild::RejectPendingResponses(ResponseRejectReason aReason) -> void
{
    mAsyncCallbacks.RejectPendingResponses(aReason);
}

auto PFOGTransportChild::SendFOGData(ByteBuf&& buf) -> bool
{
    UniquePtr<IPC::Message> msg__ = PFOGTransport::Msg_FOGData(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), std::move(buf));
    // Sentinel = 'buf'
    ((&(writer__)))->WriteSentinel(41484606);


    if (mozilla::ipc::LoggingEnabledFor("PFOGTransport", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PFOGTransportChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PFOGTransport::Msg_FOGData", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PFOGTransportChild::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    FatalError("unreached");
    return;
}

auto PFOGTransportChild::OnMessageReceived(const Message& msg__) -> PFOGTransportChild::Result
{
    if (!CanSend()) {
        if (mozilla::ipc::LoggingEnabledFor("PFOGTransport", mozilla::ipc::ChildSide)) {
            mozilla::ipc::LogMessageForProtocol(
                "PFOGTransportChild",
                this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                "Ignored message for dead actor",
                (&(msg__))->type(),
                mozilla::ipc::MessageDirection::eSending);
        }
        return MsgProcessed;

    }
    switch (msg__.type()) {
    case PFOGTransport::Msg_FlushFOGData__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PFOGTransport", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PFOGTransportChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PFOGTransport::Msg_FlushFOGData", OTHER);

            mozilla::ipc::ActorId id__ = MSG_ROUTING_CONTROL;
            UniquePtr<IPC::Message> reply__(PFOGTransport::Reply_FlushFOGData(id__));
            reply__->set_seqno(msg__.seqno());

            RefPtr<mozilla::ipc::IPDLResolverInner> resolver__ =
                new mozilla::ipc::IPDLResolverInner(std::move(reply__), this);

            FlushFOGDataResolver resolver = [resolver__ = std::move(resolver__)](ByteBuf&& aParam) {
                resolver__->Resolve([&] (IPC::Message* reply__, IProtocol* self__) {
                    IPC::MessageWriter writer__(*reply__, self__);
                    IPC::WriteParam((&(writer__)), std::move(aParam));
                    // Sentinel = 'buf'
                    ((&(writer__)))->WriteSentinel(41484606);

                    if (mozilla::ipc::LoggingEnabledFor("PFOGTransport", mozilla::ipc::ChildSide)) {
                        mozilla::ipc::LogMessageForProtocol(
                            "PFOGTransportChild",
                            self__->ToplevelProtocol()->OtherPidMaybeInvalid(),
                            "Sending reply ",
                            reply__->type(),
                            mozilla::ipc::MessageDirection::eSending);
                    }

                });
            };
            mozilla::ipc::IPCResult __ok = (static_cast<::mozilla::glean::FOGTransportChild*>(this))->RecvFlushFOGData(std::move(resolver));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    case SHMEM_CREATED_MESSAGE_TYPE:
        {
            if (!ShmemCreated(msg__)) {
                return MsgPayloadError;
            }
            return MsgProcessed;
        }
    case SHMEM_DESTROYED_MESSAGE_TYPE:
        {
            if (!ShmemDestroyed(msg__)) {
                return MsgPayloadError;
            }
            return MsgProcessed;
        }
    }
}

auto PFOGTransportChild::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PFOGTransportChild::Result
{
    if (!CanSend()) {
        return MsgDropped;

    }
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}



} // namespace glean
} // namespace mozilla
