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
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"
22 namespace mozilla::ipc
{
24 template <class PFooSide
>
26 template <class PFooSide
>
27 class ManagedEndpoint
;
29 struct IPDLParamTraits
;
30 } // namespace mozilla::ipc
39 struct ParamTraits
<Channel::Mode
>
40 : ContiguousEnumSerializerInclusive
<Channel::Mode
, Channel::MODE_SERVER
,
41 Channel::MODE_CLIENT
> {};
44 struct ParamTraits
<IPCMessageStart
>
45 : ContiguousEnumSerializer
<IPCMessageStart
, IPCMessageStart(0),
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
) {
58 if (IPC::ReadParam(aReader
, &id
)) {
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
> {};
81 namespace mozilla::ipc
{
84 struct IPDLParamTraits
<UntypedManagedEndpoint
> {
85 using paramType
= UntypedManagedEndpoint
;
87 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
89 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
93 template <class PFooSide
>
94 struct IPDLParamTraits
<ManagedEndpoint
<PFooSide
>> {
95 using paramType
= ManagedEndpoint
<PFooSide
>;
97 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
99 IPDLParamTraits
<UntypedManagedEndpoint
>::Write(aWriter
, aActor
,
103 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
104 paramType
* aResult
) {
105 return IPDLParamTraits
<UntypedManagedEndpoint
>::Read(aReader
, aActor
,
111 struct IPDLParamTraits
<FileDescriptor
> {
112 typedef FileDescriptor paramType
;
114 static void Write(IPC::MessageWriter
* aWriter
, IProtocol
* aActor
,
115 const paramType
& aParam
);
116 static bool Read(IPC::MessageReader
* aReader
, IProtocol
* aActor
,
119 } // namespace mozilla::ipc
121 #endif // IPC_GLUE_PROTOCOLMESSAGEUTILS_H