jbates@chromium.org | 0fc8736 | 2012-03-08 05:42:56 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 2 | // 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. |
| 11 | #define IPC_STRUCT_TRAITS_BEGIN(struct_name) \ |
| 12 | namespace IPC { \ |
| 13 | template <> \ |
dpranke@chromium.org | 5a4c53c | 2011-09-30 09:28:14 +0900 | [diff] [blame] | 14 | struct IPC_MESSAGE_EXPORT ParamTraits<struct_name> { \ |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 15 | typedef struct_name param_type; \ |
| 16 | static void Write(Message* m, const param_type& p); \ |
jbates@chromium.org | 0fc8736 | 2012-03-08 05:42:56 +0900 | [diff] [blame] | 17 | static bool Read(const Message* m, PickleIterator* iter, param_type* p); \ |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 18 | static void Log(const param_type& p, std::string* l); \ |
| 19 | }; \ |
| 20 | } |
| 21 | |
| 22 | #define IPC_STRUCT_TRAITS_MEMBER(name) |
jam@chromium.org | 4ae3f56 | 2011-03-06 04:08:32 +0900 | [diff] [blame] | 23 | #define IPC_STRUCT_TRAITS_PARENT(type) |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 24 | #define IPC_STRUCT_TRAITS_END() |
| 25 | |
tsepez@chromium.org | 384d976 | 2013-06-04 16:20:32 +0900 | [diff] [blame] | 26 | // Convenience macro for defining enumerated type traits for types which are |
| 27 | // not range-checked by the IPC system. The author of the message handlers |
| 28 | // is responsible for all validation. This macro should not need to be |
| 29 | // subsequently redefined. |
| 30 | #define IPC_ENUM_TRAITS(type) \ |
| 31 | IPC_ENUM_TRAITS_VALIDATE(type, true) |
| 32 | |
| 33 | // Convenience macro for defining enumerated type traits for types which are |
| 34 | // range-checked by the IPC system to be in the range of 0..maxvalue inclusive. |
| 35 | // This macro should not need to be subsequently redefined. |
| 36 | #define IPC_ENUM_TRAITS_MAX_VALUE(type, maxvalue) \ |
| 37 | IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, 0, maxvalue) |
| 38 | |
| 39 | // Convenience macro for defining enumerated type traits for types which are |
| 40 | // range-checked by the IPC system to be in the range of minvalue..maxvalue |
| 41 | // inclusive. This macro should not need to be subsequently redefined. |
| 42 | #define IPC_ENUM_TRAITS_MIN_MAX_VALUE(type, minvalue, maxvalue) \ |
| 43 | IPC_ENUM_TRAITS_VALIDATE(type, (value >= (minvalue) && value <= (maxvalue))) |
| 44 | |
| 45 | // Traits generation for enums. This macro may be redefined later. |
| 46 | #define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \ |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 47 | namespace IPC { \ |
| 48 | template <> \ |
tfarina@chromium.org | c14d448 | 2011-12-07 11:43:47 +0900 | [diff] [blame] | 49 | struct IPC_MESSAGE_EXPORT ParamTraits<enum_name> { \ |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 50 | typedef enum_name param_type; \ |
| 51 | static void Write(Message* m, const param_type& p); \ |
jbates@chromium.org | 0fc8736 | 2012-03-08 05:42:56 +0900 | [diff] [blame] | 52 | static bool Read(const Message* m, PickleIterator* iter, param_type* p); \ |
tsepez@chromium.org | 1ac4613 | 2011-02-12 03:46:19 +0900 | [diff] [blame] | 53 | static void Log(const param_type& p, std::string* l); \ |
| 54 | }; \ |
| 55 | } |
| 56 | |
| 57 | #endif // IPC_PARAM_TRAITS_MACROS_H_ |
| 58 | |