Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / ipc / glue / ProtocolMessageUtils.h
blob74089d96af9662c6bb8716e13fe97aed78716946
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #ifndef IPC_GLUE_PROTOCOLMESSAGEUTILS_H
8 #define IPC_GLUE_PROTOCOLMESSAGEUTILS_H
10 #include <stdint.h>
11 #include <string>
12 #include "base/string_util.h"
13 #include "chrome/common/ipc_channel.h"
14 #include "chrome/common/ipc_message_utils.h"
15 #include "ipc/EnumSerializer.h"
16 #include "mozilla/Assertions.h"
17 #include "mozilla/ipc/Endpoint.h"
18 #include "mozilla/ipc/ProtocolUtils.h"
20 class PickleIterator;
22 namespace mozilla::ipc {
23 class FileDescriptor;
24 template <class PFooSide>
25 class Endpoint;
26 template <class PFooSide>
27 class ManagedEndpoint;
28 template <typename P>
29 struct IPDLParamTraits;
30 } // namespace mozilla::ipc
32 namespace IPC {
34 class Message;
35 class MessageReader;
36 class MessageWriter;
38 template <>
39 struct ParamTraits<Channel::Mode>
40 : ContiguousEnumSerializerInclusive<Channel::Mode, Channel::MODE_SERVER,
41 Channel::MODE_CLIENT> {};
43 template <>
44 struct ParamTraits<IPCMessageStart>
45 : ContiguousEnumSerializer<IPCMessageStart, IPCMessageStart(0),
46 LastMsgIndex> {};
48 template <>
49 struct ParamTraits<mozilla::ipc::ActorHandle> {
50 typedef mozilla::ipc::ActorHandle paramType;
52 static void Write(MessageWriter* aWriter, const paramType& aParam) {
53 IPC::WriteParam(aWriter, aParam.mId);
56 static bool Read(MessageReader* aReader, paramType* aResult) {
57 int id;
58 if (IPC::ReadParam(aReader, &id)) {
59 aResult->mId = id;
60 return true;
62 return false;
66 template <>
67 struct ParamTraits<mozilla::ipc::UntypedEndpoint> {
68 using paramType = mozilla::ipc::UntypedEndpoint;
70 static void Write(MessageWriter* aWriter, paramType&& aParam);
72 static bool Read(MessageReader* aReader, paramType* aResult);
75 template <class PFooSide>
76 struct ParamTraits<mozilla::ipc::Endpoint<PFooSide>>
77 : ParamTraits<mozilla::ipc::UntypedEndpoint> {};
79 template <>
80 struct ParamTraits<mozilla::ipc::EndpointProcInfo> {
81 using paramType = mozilla::ipc::EndpointProcInfo;
83 static void Write(MessageWriter* aWriter, const paramType& aParam) {
84 IPC::WriteParam(aWriter, aParam.mPid);
85 IPC::WriteParam(aWriter, aParam.mChildID);
88 static bool Read(MessageReader* aReader, paramType* aResult) {
89 return IPC::ReadParam(aReader, &aResult->mPid) &&
90 IPC::ReadParam(aReader, &aResult->mChildID);
94 } // namespace IPC
96 namespace mozilla::ipc {
98 template <>
99 struct IPDLParamTraits<UntypedManagedEndpoint> {
100 using paramType = UntypedManagedEndpoint;
102 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
103 paramType&& aParam);
104 static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
105 paramType* aResult);
108 template <class PFooSide>
109 struct IPDLParamTraits<ManagedEndpoint<PFooSide>> {
110 using paramType = ManagedEndpoint<PFooSide>;
112 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
113 paramType&& aParam) {
114 IPDLParamTraits<UntypedManagedEndpoint>::Write(aWriter, aActor,
115 std::move(aParam));
118 static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
119 paramType* aResult) {
120 return IPDLParamTraits<UntypedManagedEndpoint>::Read(aReader, aActor,
121 aResult);
125 template <>
126 struct IPDLParamTraits<FileDescriptor> {
127 typedef FileDescriptor paramType;
129 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
130 const paramType& aParam);
131 static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
132 paramType* aResult);
134 } // namespace mozilla::ipc
136 #endif // IPC_GLUE_PROTOCOLMESSAGEUTILS_H