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.

42 lines
1.3 KiB
Django/Jinja

#include "{{ cls.name }}.skeleton.h"
{{ cls.name }}Skeleton::{{ cls.name }}Skeleton({{ cls.name }}& obj)
: obj_(obj) {
}
RpcValue {{ cls.name }}Skeleton::invoke(const std::string& method,
const RpcArgs& args) {
const auto& table = handlers();
auto it = table.find(method);
if (it == table.end()) {
// Неизвестный метод — PoC: возвращаем 0.
return RpcValue::fromInt(0);
}
Handler fn = it->second;
return (this->*fn)(args);
}
const std::unordered_map<std::string, {{ cls.name }}Skeleton::Handler>&
{{ cls.name }}Skeleton::handlers() {
static const std::unordered_map<std::string, Handler> kHandlers = {
{% for m in cls.methods %}
{ "{{ cls.name }}.{{ m.name }}", &{{ cls.name }}Skeleton::call_{{ m.name }} }{% if not loop.last %},{% endif %}
{% endfor %}
};
return kHandlers;
}
{% for m in cls.methods %}
RpcValue {{ cls.name }}Skeleton::call_{{ m.name }}(const RpcArgs& args) {
// PoC: единственный тип аргументов и результата — int.
int idx = 0;
{% for a in m.args %}
int {{ a.name }} = args[idx++].asInt();
{% endfor %}
int result = obj_.{{ m.name }}({% for a in m.args %}{{ a.name }}{% if not loop.last %}, {% endif %}{% endfor %});
return RpcValue::fromInt(result);
}
{% endfor %}