You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
983 B
Django/Jinja

#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 %}