1ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks// Use of this source code is governed by a BSD-style license that can be
3ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks// found in the LICENSE file.
4ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks
5ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#ifndef IPC_PARAM_TRAITS_LOG_MACROS_H_
6ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#define IPC_PARAM_TRAITS_LOG_MACROS_H_
7ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks
8ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#include <string>
9ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks
10ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks// Null out all the macros that need nulling.
11ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#include "ipc/ipc_message_null_macros.h"
12ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks
13ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks// STRUCT declarations cause corresponding STRUCT_TRAITS declarations to occur.
14ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#undef IPC_STRUCT_BEGIN_WITH_PARENT
15ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#undef IPC_STRUCT_MEMBER
16ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#undef IPC_STRUCT_END
17ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
18ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks  IPC_STRUCT_TRAITS_BEGIN(struct_name)
198dbcb888ec5c79b23c408ccbe800ca2264805dc2Andy Stadler#define IPC_STRUCT_MEMBER(type, name, ...) IPC_STRUCT_TRAITS_MEMBER(name)
208dbcb888ec5c79b23c408ccbe800ca2264805dc2Andy Stadler#define IPC_STRUCT_END() IPC_STRUCT_TRAITS_END()
21ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks
2239f1e04079976d3d10fdd8e5dd36c833bab8a371Jason parks// Set up so next include will generate log methods.
23ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#undef IPC_STRUCT_TRAITS_BEGIN
243da38a0771022615ecb568861e489761fe53a05aAndy Stadler#undef IPC_STRUCT_TRAITS_MEMBER
2539f1e04079976d3d10fdd8e5dd36c833bab8a371Jason parks#undef IPC_STRUCT_TRAITS_PARENT
2639f1e04079976d3d10fdd8e5dd36c833bab8a371Jason parks#undef IPC_STRUCT_TRAITS_END
27ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#define IPC_STRUCT_TRAITS_BEGIN(struct_name) \
2839f1e04079976d3d10fdd8e5dd36c833bab8a371Jason parks  void ParamTraits<struct_name>::Log(const param_type& p, std::string* l) { \
29ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks    bool needs_comma = false; \
3039f1e04079976d3d10fdd8e5dd36c833bab8a371Jason parks    l->append("(");
31ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#define IPC_STRUCT_TRAITS_MEMBER(name) \
32d71c31ef946b35f73a0dded0a32c6ad6afc12227Paul Lawrence    if (needs_comma) \
33ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks      l->append(", "); \
3495ef5575a2b70d8c018f99b218353c925a70d418Andy Stadler    LogParam(p.name, l); \
35ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks    needs_comma = true;
36ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#define IPC_STRUCT_TRAITS_PARENT(type) \
37ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks    if (needs_comma) \
38ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks      l->append(", "); \
39ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks      ParamTraits<type>::Log(p, l); \
40ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks      needs_comma = true;
41ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks#define IPC_STRUCT_TRAITS_END() \
42ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks    l->append(")"); \
43ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks  }
44ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks
458dbcb888ec5c79b23c408ccbe800ca2264805dc2Andy Stadler#undef IPC_ENUM_TRAITS_VALIDATE
468dbcb888ec5c79b23c408ccbe800ca2264805dc2Andy Stadler#define IPC_ENUM_TRAITS_VALIDATE(enum_name, validation_expression) \
478dbcb888ec5c79b23c408ccbe800ca2264805dc2Andy Stadler  void ParamTraits<enum_name>::Log(const param_type& p, std::string* l) { \
488dbcb888ec5c79b23c408ccbe800ca2264805dc2Andy Stadler    LogParam(static_cast<int>(p), l); \
49ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks  }
50ec5a45e79cb7161adfabf475342c1e1b25994276Jason parks
518dbcb888ec5c79b23c408ccbe800ca2264805dc2Andy Stadler#endif  // IPC_PARAM_TRAITS_LOG_MACROS_H_
528dbcb888ec5c79b23c408ccbe800ca2264805dc2Andy Stadler
5339f1e04079976d3d10fdd8e5dd36c833bab8a371Jason parks