mirror of
https://github.com/RGBCube/serenity
synced 2025-07-15 15:17:37 +00:00
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:
parent
fae3091999
commit
05e08afcd8
3 changed files with 25 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include <AK/BufferStream.h>
|
#include <AK/BufferStream.h>
|
||||||
|
#include <AK/HashMap.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/CFile.h>
|
#include <LibCore/CFile.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -182,12 +183,32 @@ int main(int argc, char** argv)
|
||||||
dbg() << "namespace " << endpoint.name << " {";
|
dbg() << "namespace " << endpoint.name << " {";
|
||||||
dbg();
|
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 = {}) {
|
auto do_message = [&](const String& name, const Vector<Parameter>& parameters, String response_type = {}) {
|
||||||
dbg() << "class " << name << " final : public IMessage {";
|
dbg() << "class " << name << " final : public IMessage {";
|
||||||
dbg() << "public:";
|
dbg() << "public:";
|
||||||
if (!response_type.is_null())
|
if (!response_type.is_null())
|
||||||
dbg() << " typedef " << response_type << " ResponseType;";
|
dbg() << " typedef class " << response_type << " ResponseType;";
|
||||||
dbg() << " virtual ~" << name << "() override {}";
|
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() << " virtual ByteBuffer encode() override";
|
||||||
dbg() << " {";
|
dbg() << " {";
|
||||||
if (parameters.is_empty()) {
|
if (parameters.is_empty()) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ class IEndpoint {
|
||||||
public:
|
public:
|
||||||
virtual ~IEndpoint();
|
virtual ~IEndpoint();
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
virtual String name() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IEndpoint();
|
IEndpoint();
|
||||||
|
|
|
@ -7,12 +7,10 @@ class IMessage {
|
||||||
public:
|
public:
|
||||||
virtual ~IMessage();
|
virtual ~IMessage();
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
virtual int id() const = 0;
|
||||||
|
virtual String name() const = 0;
|
||||||
virtual ByteBuffer encode() = 0;
|
virtual ByteBuffer encode() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IMessage();
|
IMessage();
|
||||||
|
|
||||||
private:
|
|
||||||
String m_name;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue