blob: 100344023824d480826e7202add8001d937a7273 [file] [log] [blame]
[email protected]ce208f872012-03-07 20:42:561// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6476c72c2011-02-11 18:46:192// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef IPC_PARAM_TRAITS_MACROS_H_
6#define IPC_PARAM_TRAITS_MACROS_H_
7
8#include <string>
9
10// Traits generation for structs.
rockot502c94f2016-02-03 20:20:1611#define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
12 namespace IPC { \
13 template <> \
14 struct IPC_MESSAGE_EXPORT ParamTraits<struct_name> { \
15 typedef struct_name param_type; \
rockot0457af102016-02-05 02:12:3216 static void GetSize(base::PickleSizer* sizer, \
17 const param_type& p); \
rockot502c94f2016-02-03 20:20:1618 static void Write(base::Pickle* m, const param_type& p); \
19 static bool Read(const base::Pickle* m, \
20 base::PickleIterator* iter, \
21 param_type* p); \
22 static void Log(const param_type& p, std::string* l); \
23 }; \
[email protected]6476c72c2011-02-11 18:46:1924 }
25
26#define IPC_STRUCT_TRAITS_MEMBER(name)
[email protected]94dc971d2011-03-05 19:08:3227#define IPC_STRUCT_TRAITS_PARENT(type)
[email protected]6476c72c2011-02-11 18:46:1928#define IPC_STRUCT_TRAITS_END()
29
[email protected]dedd0a92013-06-04 07:20:3230// Convenience macro for defining enumerated type traits for types which are
31// not range-checked by the IPC system. The author of the message handlers
32// is responsible for all validation. This macro should not need to be
33// subsequently redefined.
34#define IPC_ENUM_TRAITS(type) \
35 IPC_ENUM_TRAITS_VALIDATE(type, true)
36
37// Convenience macro for defining enumerated type traits for types which are
38// range-checked by the IPC system to be in the range of 0..maxvalue inclusive.
39// This macro should not need to be subsequently redefined.
40#define IPC_ENUM_TRAITS_MAX_VALUE(type, maxvalue) \
41 IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, 0, maxvalue)
42
43// Convenience macro for defining enumerated type traits for types which are
44// range-checked by the IPC system to be in the range of minvalue..maxvalue
45// inclusive. This macro should not need to be subsequently redefined.
tsepez26d859a22014-10-23 02:39:2446// TODO(tsepez): Cast to std::underlying_type<>::type once that is permitted.
[email protected]dedd0a92013-06-04 07:20:3247#define IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, minvalue, maxvalue) \
tsepez26d859a22014-10-23 02:39:2448 IPC_ENUM_TRAITS_VALIDATE( \
49 type, (static_cast<int>(value) >= static_cast<int>(minvalue) && \
50 static_cast<int>(value) <= static_cast<int>(maxvalue)))
[email protected]dedd0a92013-06-04 07:20:3251
52// Traits generation for enums. This macro may be redefined later.
53#define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \
rockot502c94f2016-02-03 20:20:1654 namespace IPC { \
55 template <> \
56 struct IPC_MESSAGE_EXPORT ParamTraits<enum_name> { \
57 typedef enum_name param_type; \
rockot0457af102016-02-05 02:12:3258 static void GetSize(base::PickleSizer* sizer, \
59 const param_type& p); \
rockot502c94f2016-02-03 20:20:1660 static void Write(base::Pickle* m, const param_type& p); \
61 static bool Read(const base::Pickle* m, \
62 base::PickleIterator* iter, \
63 param_type* p); \
64 static void Log(const param_type& p, std::string* l); \
65 }; \
[email protected]6476c72c2011-02-11 18:46:1966 }
67
68#endif // IPC_PARAM_TRAITS_MACROS_H_
69