summaryrefslogtreecommitdiff
path: root/ipc/ipc_message_utils_impl.h
blob: 7e512a62c28bbf749748898a6ea6e45c7453d2bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file contains templates forward declared (but not defined) in
// ipc_message_utils.h so that they are only instantiated in certain files,
// notably a few IPC unit tests.

#ifndef IPC_IPC_MESSAGE_UTILS_IMPL_H_
#define IPC_IPC_MESSAGE_UTILS_IMPL_H_

namespace IPC {

template <class ParamType>
MessageWithTuple<ParamType>::MessageWithTuple(
    int32 routing_id, uint32 type, const RefParam& p)
    : Message(routing_id, type, PRIORITY_NORMAL) {
  WriteParam(this, p);
}

template <class ParamType>
bool MessageWithTuple<ParamType>::Read(const Message* msg, Param* p) {
  void* iter = NULL;
  if (ReadParam(msg, &iter, p))
    return true;
  NOTREACHED() << "Error deserializing message " << msg->type();
  return false;
}

// We can't migrate the template for Log() to MessageWithTuple, because each
// subclass needs to have Log() to call Read(), which instantiates the above
// template.

template <class SendParamType, class ReplyParamType>
MessageWithReply<SendParamType, ReplyParamType>::MessageWithReply(
    int32 routing_id, uint32 type,
    const RefSendParam& send,
    const ReplyParam& reply)
    : SyncMessage(routing_id, type, PRIORITY_NORMAL,
                  new ParamDeserializer<ReplyParam>(reply)) 
{
  WriteParam(this, send);
}

template <class SendParamType, class ReplyParamType>
bool MessageWithReply<SendParamType, ReplyParamType>::ReadSendParam(
    const Message* msg, SendParam* p) {
  void* iter = SyncMessage::GetDataIterator(msg);
  return ReadParam(msg, &iter, p);
}

template <class SendParamType, class ReplyParamType>
bool MessageWithReply<SendParamType, ReplyParamType>::ReadReplyParam(
    const Message* msg, typename TupleTypes<ReplyParam>::ValueTuple* p) {
  void* iter = SyncMessage::GetDataIterator(msg);
  return ReadParam(msg, &iter, p);
}

}  // namespace IPC

#endif  // IPC_IPC_MESSAGE_UTILS_IMPL_H_