aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/storageserver/rpcrequestwrapper.cpp
blob: 59676c09e497a04de5a476de521f681a76f844af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "rpcrequestwrapper.h"
#include <vespa/fnet/frt/rpcrequest.h>
#include <cassert>

namespace storage {

RPCRequestWrapper::RPCRequestWrapper(FRT_RPCRequest *req)
    : _req(req)
{
}

RPCRequestWrapper::~RPCRequestWrapper()
{
    if (_req) {
        _req->SetError(ERR_REQUEST_DELETED, "Request deleted without having been replied to");
        _req->Return();
    }
}

const char *
RPCRequestWrapper::getParam() const
{
    assert(_req);
    return _req->GetParams()->GetValue(0)._data._buf;
}


uint32_t
RPCRequestWrapper::getParamLen() const
{
    assert(_req);
    return _req->GetParams()->GetValue(0)._data._len;
}


void
RPCRequestWrapper::returnData(const char *pt, uint32_t len)
{
    assert(_req);
    _req->GetReturn()->AddData(pt, len);
    _req->Return();
    _req = nullptr;
}


void
RPCRequestWrapper::returnError(uint32_t errorCode, const char *errorMessage)
{
    assert(_req);
    _req->SetError(errorCode, errorMessage);
    _req->Return();
    _req = nullptr;
}

void
RPCRequestWrapper::addReturnString(const char *str, uint32_t len)
{
    assert(_req);
    if (len !=0) {
        _req->GetReturn()->AddString(str, len);
    } else {
        _req->GetReturn()->AddString(str);
    }
}

void
RPCRequestWrapper::addReturnInt(uint32_t value)
{
    assert(_req);
    _req->GetReturn()->AddInt32(value);
}

void
RPCRequestWrapper::returnRequest()
{
    assert(_req);
    _req->Return();
    _req = nullptr;

}

const char *
RPCRequestWrapper::getMethodName() const {
    return _req->GetMethodName();
}

void
RPCRequestWrapper::discardBlobs()
{
    if (_req) {
        _req->DiscardBlobs();
    }
}

} // namespace storage