71 lines
2.0 KiB
Django/Jinja
71 lines
2.0 KiB
Django/Jinja
// Generated file - DO NOT MODIFY
|
|
#include "{{file}}.client.h"
|
|
|
|
#include <glacier/buffer/byte_buffer.h>
|
|
#include <glacier/buffer/cap_buffer.h>
|
|
#include <mammoth/util/debug.h>
|
|
#include <zcall.h>
|
|
|
|
{% if package != None %}
|
|
namespace {{package.cpp_namespace()}} {
|
|
{% endif %}
|
|
{% for interface in interfaces %}
|
|
|
|
{{interface.name}}Client::~{{interface.name}}Client() {
|
|
if (endpoint_ != 0) {
|
|
check(ZCapRelease(endpoint_));
|
|
}
|
|
}
|
|
|
|
{% for method in interface.methods %}
|
|
|
|
{% if method.request == None %}
|
|
glcr::Status {{interface.name}}Client::{{method.name}}({{method.response}}& response) {
|
|
{% elif method.response == None %}
|
|
glcr::Status {{interface.name}}Client::{{method.name}}(const {{method.request}}& request) {
|
|
{% else %}
|
|
glcr::Status {{interface.name}}Client::{{method.name}}(const {{method.request}}& request, {{method.response}}& response) {
|
|
{% endif %}
|
|
uint64_t buffer_size = kBufferSize;
|
|
uint64_t cap_size = kCapBufferSize;
|
|
|
|
const uint32_t kSentinel = 0xBEEFDEAD;
|
|
buffer_.WriteAt<uint32_t>(0, kSentinel);
|
|
buffer_.WriteAt<uint64_t>(8, {{loop.index0}});
|
|
|
|
cap_buffer_.Reset();
|
|
{% if method.request == None %}
|
|
uint64_t length = 0;
|
|
{% else %}
|
|
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
|
{% endif %}
|
|
|
|
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
|
|
|
z_cap_t reply_port_cap;
|
|
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap));
|
|
|
|
// FIXME: Add a way to zero out the first buffer.
|
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
|
|
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
|
}
|
|
|
|
// Check Response Code.
|
|
RET_ERR(buffer_.At<uint64_t>(8));
|
|
|
|
{% if method.response != None %}
|
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
|
{% endif %}
|
|
|
|
return glcr::OK;
|
|
}
|
|
|
|
{% endfor %}
|
|
{% endfor %}
|
|
|
|
{% if package != None %}
|
|
} // namepace {{package.cpp_namespace()}}
|
|
{% endif %}
|