diff --git a/DevTools/IPCCompiler/main.cpp b/DevTools/IPCCompiler/main.cpp index 2637dac5f81..966551a9bb0 100644 --- a/DevTools/IPCCompiler/main.cpp +++ b/DevTools/IPCCompiler/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -182,12 +183,32 @@ int main(int argc, char** argv) dbg() << "namespace " << endpoint.name << " {"; dbg(); + HashMap 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& 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()) { diff --git a/Libraries/LibIPC/IEndpoint.h b/Libraries/LibIPC/IEndpoint.h index 6481c902799..9693b12dee6 100644 --- a/Libraries/LibIPC/IEndpoint.h +++ b/Libraries/LibIPC/IEndpoint.h @@ -6,7 +6,7 @@ class IEndpoint { public: virtual ~IEndpoint(); - const String& name() const { return m_name; } + virtual String name() const = 0; protected: IEndpoint(); diff --git a/Libraries/LibIPC/IMessage.h b/Libraries/LibIPC/IMessage.h index 4be554852b1..ca561039300 100644 --- a/Libraries/LibIPC/IMessage.h +++ b/Libraries/LibIPC/IMessage.h @@ -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; };