no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / ipc / glue / ProtocolMessageUtils.h
blob48485596ea34e9fa93e5d5ab56d63878a547edcc
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 } // namespace IPC
81 namespace mozilla::ipc {
83 template <>
84 struct IPDLParamTraits<UntypedManagedEndpoint> {
85 using paramType = UntypedManagedEndpoint;
87 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
88 paramType&& aParam);
89 static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
90 paramType* aResult);
93 template <class PFooSide>
94 struct IPDLParamTraits<ManagedEndpoint<PFooSide>> {
95 using paramType = ManagedEndpoint<PFooSide>;
97 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
98 paramType&& aParam) {
99 IPDLParamTraits<UntypedManagedEndpoint>::Write(aWriter, aActor,
100 std::move(aParam));
103 static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
104 paramType* aResult) {
105 return IPDLParamTraits<UntypedManagedEndpoint>::Read(aReader, aActor,
106 aResult);
110 template <>
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,
117 paramType* aResult);
119 } // namespace mozilla::ipc
121 #endif // IPC_GLUE_PROTOCOLMESSAGEUTILS_H