aboutsummaryrefslogtreecommitdiffstats
path: root/jrt_test/src/tests/mockup-invoke/mockup-server.cpp
blob: 46a1e2bc11a4c8eb73a8faa00739c2edaa7bf5bb (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/log/log.h>
LOG_SETUP("mockup_server");
#include <vespa/fastos/fastos.h>
#include <vespa/fnet/frt/frt.h>


class MockupServer : public FRT_Invokable
{
private:
    MockupServer(const MockupServer &);
    MockupServer &operator=(const MockupServer &);

public:
    MockupServer(FRT_Supervisor *s)
    {
        FRT_ReflectionBuilder rb(s);
        //-------------------------------------------------------------------
        rb.DefineMethod("concat", "ss", "s", true,
                        FRT_METHOD(MockupServer::RPC_concat), this);
        rb.MethodDesc("Concatenate two strings");
        rb.ParamDesc("string1", "a string");
        rb.ParamDesc("string2", "another string");
        rb.ReturnDesc("ret", "the concatenation of string1 and string2");
        //-------------------------------------------------------------------
    }

    void RPC_concat(FRT_RPCRequest *req)
    {
        FRT_Values &params = *req->GetParams();
        FRT_Values &ret    = *req->GetReturn();

        uint32_t len = (params[0]._string._len +
                        params[1]._string._len);
        char *tmp = ret.AddString(len);
        strcpy(tmp, params[0]._string._str);
        strcat(tmp, params[1]._string._str);
    }
};


class App : public FastOS_Application
{
public:
    int Main() override;
};


int
App::Main()
{
    if (_argc < 2) {
        printf("usage: %s <listenspec>\n", _argv[0]);
        return 1;
    }
    FRT_Supervisor orb;
    MockupServer server(&orb);
    orb.Listen(_argv[1]);
    orb.Main();
    return 0;
}


int
main(int argc, char **argv)
{
  App myapp;
  return myapp.Entry(argc, argv);
}