IPCCompiler: Generate getters for message ID's and message names

Each endpoint namespace will have an enum class MessageID where you can
find all of its messages.
This commit is contained in:
Andreas Kling 2019-08-03 16:18:37 +02:00
parent fae3091999
commit 05e08afcd8
Notes: sideshowbarker 2024-07-19 12:55:22 +09:00
3 changed files with 25 additions and 6 deletions

View file

@ -1,4 +1,5 @@
#include <AK/BufferStream.h>
#include <AK/HashMap.h>
#include <AK/StringBuilder.h>
#include <LibCore/CFile.h>
#include <ctype.h>
@ -182,12 +183,32 @@ int main(int argc, char** argv)
dbg() << "namespace " << endpoint.name << " {";
dbg();
HashMap<String, int> message_ids;
dbg() << "enum class MessageID : int {";
for (auto& message : endpoint.messages) {
message_ids.set(message.name, message_ids.size() + 1);
dbg() << " " << message.name << " = " << message_ids.size() << ",";
if (message.is_synchronous) {
StringBuilder builder;
builder.append(message.name);
builder.append("Response");
auto response_name = builder.to_string();
message_ids.set(response_name, message_ids.size() + 1);
dbg() << " " << response_name << " = " << message_ids.size() << ",";
}
}
dbg() << "};";
dbg();
auto do_message = [&](const String& name, const Vector<Parameter>& parameters, String response_type = {}) {
dbg() << "class " << name << " final : public IMessage {";
dbg() << "public:";
if (!response_type.is_null())
dbg() << " typedef " << response_type << " ResponseType;";
dbg() << " typedef class " << response_type << " ResponseType;";
dbg() << " virtual ~" << name << "() override {}";
dbg() << " virtual int id() const override { return (int)MessageID::" << name << "; }";
dbg() << " virtual String name() const override { return \"" << endpoint.name << "::" << name << "\"; }";
dbg() << " virtual ByteBuffer encode() override";
dbg() << " {";
if (parameters.is_empty()) {

View file

@ -6,7 +6,7 @@ class IEndpoint {
public:
virtual ~IEndpoint();
const String& name() const { return m_name; }
virtual String name() const = 0;
protected:
IEndpoint();

View file

@ -7,12 +7,10 @@ class IMessage {
public:
virtual ~IMessage();
const String& name() const { return m_name; }
virtual int id() const = 0;
virtual String name() const = 0;
virtual ByteBuffer encode() = 0;
protected:
IMessage();
private:
String m_name;
};