summaryrefslogtreecommitdiffstats
path: root/chrome/tools/ipclist/ipclist.cc
blob: a2d37a8d86e569a241f70817a1753025c5c79166 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) 2012 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.

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

// Include once to get the type definitions
#include "chrome/common/all_messages.h"

struct msginfo {
  const char* name;
  int id;
  int in_count;
  int out_count;

  bool operator< (const msginfo other) const {
    return id < other.id;
  }
};

// Redefine macros to generate table
#include "ipc/ipc_message_null_macros.h"
#undef IPC_MESSAGE_DECL
#define IPC_MESSAGE_DECL(kind, type, name, in, out, ilist, olist) \
  { #name, IPC_MESSAGE_ID(), in, out },

static msginfo msgtable[] = {
#include "chrome/common/all_messages.h"
};
#define MSGTABLE_SIZE (sizeof(msgtable)/sizeof(msgtable[0]))

static bool check_msgtable() {
  bool result = true;
  int previous_class_id = 0;
  int highest_class_id = 0;
  std::vector<int> exemptions;

  // Exclude test and other non-browser files from consideration.  Do not
  // include message files used inside the actual chrome browser in this list.
  exemptions.push_back(TestMsgStart);
  exemptions.push_back(FirefoxImporterUnittestMsgStart);
  exemptions.push_back(ShellMsgStart);

  for (size_t i = 0; i < MSGTABLE_SIZE; ++i) {
    int class_id = IPC_MESSAGE_ID_CLASS(msgtable[i].id);
    if (class_id >= LastIPCMsgStart) {
      std::cout << "Invalid LastIPCMsgStart setting\n";
      result = false;
    }
    while (class_id > previous_class_id + 1) {
      std::vector<int>::iterator iter;
      iter = find(exemptions.begin(), exemptions.end(), previous_class_id+1);
      if (iter == exemptions.end()) {
        std::cout << "Missing message file: gap before " << class_id << "\n";
        result = false;
        break;
      }
      ++previous_class_id;
    }
    previous_class_id = class_id;
    if (class_id > highest_class_id)
      highest_class_id = class_id;
  }

  while (LastIPCMsgStart > highest_class_id + 1) {
    std::vector<int>::iterator iter;
    iter = find(exemptions.begin(), exemptions.end(), highest_class_id+1);
    if (iter == exemptions.end()) {
      std::cout << "Missing message file: gap before LastIPCMsgStart\n";
      result = false;
      break;
    }
    ++highest_class_id;
  }

  if (!result)
    std::cout << "Please check chrome/common/all_messages.h.\n";

  return result;
}

static void dump_msgtable(bool show_args, bool show_ids,
                          bool show_comma, const char *prefix) {
  bool first = true;
  for (size_t i = 0; i < MSGTABLE_SIZE; ++i) {
    if ((!prefix) || strstr(msgtable[i].name, prefix) == msgtable[i].name) {
      if (show_comma) {
        if (!first)
          std::cout << ",";
        first = false;
        std::cout << msgtable[i].id;
      } else {
        if (show_ids)
          std::cout << msgtable[i].id << " " <<
              IPC_MESSAGE_ID_CLASS(msgtable[i].id) << "," <<
              IPC_MESSAGE_ID_LINE(msgtable[i].id) << " ";
        std::cout << msgtable[i].name;
        if (show_args) {
          std::cout << "(" << msgtable[i].in_count << " IN, "  <<
              msgtable[i].out_count << " OUT)";
        }
        std::cout << "\n";
      }
    }
  }
  if (show_comma)
    std::cout << "\n";
}

int main(int argc, char **argv) {
  bool show_args = false;
  bool show_ids  = false;
  bool skip_check = false;
  bool show_comma = false;
  const char *filter = NULL;

  while (--argc > 0) {
    ++argv;
    if (std::string("--args") == *argv) {
      show_args = true;
    } else if (std::string("--comma") == *argv) {
      show_comma = true;
    } else if (std::string("--filter") == *argv) {
      filter = *(++argv);
      --argc;
    } else if (std::string("--ids") == *argv) {
      show_ids = true;
    } else if (std::string("--no-check") == *argv) {
      skip_check = true;
    } else {
      std::cout <<
          "usage: ipclist [--args] [--ids] [--no-check] [--filter prefix] "
          "[--comma]\n";
      return 1;
    }
  }

  std::sort(msgtable, msgtable + MSGTABLE_SIZE);

  if (!skip_check && check_msgtable() == false)
    return 1;

  dump_msgtable(show_args, show_ids, show_comma, filter);
  return 0;
}