real PoC of autocode
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#include "{{ cls.name }}.proxy.h"
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
{{ cls.name }}Proxy::{{ cls.name }}Proxy(const char* pipeIn, const char* pipeOut) {
|
||||
fdIn = open(pipeIn, O_WRONLY);
|
||||
if (fdIn < 0) {
|
||||
perror("open pipeIn");
|
||||
}
|
||||
fdOut = open(pipeOut, O_RDONLY);
|
||||
if (fdOut < 0) {
|
||||
perror("open pipeOut");
|
||||
}
|
||||
}
|
||||
|
||||
{% for m in cls.methods %}
|
||||
{{ m.return_type }} {{ cls.name }}Proxy::{{ m.name }}({% for a in m.args %}{{ a.type }} {{ a.name }}{% if not loop.last %}, {% endif %}{% endfor %}) {
|
||||
std::ostringstream out;
|
||||
out << "{{ m.name }}";
|
||||
{% for a in m.args %}
|
||||
out << " " << {{ a.name }};
|
||||
{% endfor %}
|
||||
out << "\n";
|
||||
std::string s = out.str();
|
||||
write(fdIn, s.c_str(), (ssize_t)s.size());
|
||||
|
||||
char buf[256];
|
||||
ssize_t n = read(fdOut, buf, sizeof(buf)-1);
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
buf[n] = '\0';
|
||||
return std::atoi(buf);
|
||||
}
|
||||
{% endfor %}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
|
||||
class {{ cls.name }}Proxy {
|
||||
public:
|
||||
{{ cls.name }}Proxy(const char* pipeIn, const char* pipeOut);
|
||||
{% for m in cls.methods %}
|
||||
{{ m.return_type }} {{ m.name }}({% for a in m.args %}{{ a.type }} {{ a.name }}{% if not loop.last %}, {% endif %}{% endfor %});
|
||||
{% endfor %}
|
||||
private:
|
||||
int fdIn;
|
||||
int fdOut;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "{{ cls.name }}.skeleton.h"
|
||||
#include <sstream>
|
||||
|
||||
{{ cls.name }}Skeleton::{{ cls.name }}Skeleton({{ cls.name }}& o) : obj(o) {}
|
||||
|
||||
std::string {{ cls.name }}Skeleton::handleRequest(const std::string& req) {
|
||||
std::istringstream in(req);
|
||||
std::string method;
|
||||
in >> method;
|
||||
{% for m in cls.methods %}
|
||||
if (method == "{{ m.name }}") {
|
||||
{% for a in m.args %}int {{ a.name }}; in >> {{ a.name }};
|
||||
{% endfor %}
|
||||
int res = obj.{{ m.name }}({% for a in m.args %}{{ a.name }}{% if not loop.last %}, {% endif %}{% endfor %});
|
||||
return std::to_string(res);
|
||||
}
|
||||
{% endfor %}
|
||||
return std::string("ERR");
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "{{ cls.name }}.h"
|
||||
#include <string>
|
||||
|
||||
class {{ cls.name }}Skeleton {
|
||||
public:
|
||||
{{ cls.name }}Skeleton({{ cls.name }}& obj);
|
||||
std::string handleRequest(const std::string& req);
|
||||
private:
|
||||
{{ cls.name }}& obj;
|
||||
};
|
||||
Reference in New Issue
Block a user