#include "{{ cls.name }}.proxy.h" #include #include #include #include #include {{ 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 %}