File: disttest_cpp.cpp

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (43 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download
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
// Simple test to read the RobotRaconteurNode version

#include <RobotRaconteur.h>
#include <iostream>
#include "robotraconteur_generated.h"

using namespace RobotRaconteur;
using namespace experimental::distfiles_test;

class DistfilesTest_impl : public virtual DistfilesTest
{
    // NOLINTBEGIN
  public:
    virtual double get_c() { return c; }
    virtual void set_c(double value) { c = value; }

    virtual double add(double a, int32_t b) { return a + b + c; }

  private:
    double c;
};

int main(int argc, char* argv[])
{
    RR_SHARED_PTR<DistfilesTest_impl> impl = RR_MAKE_SHARED<DistfilesTest_impl>();

    ServerNodeSetup node_setup(ROBOTRACONTEUR_SERVICE_TYPES, "experimental.distfiles_test", 0, argc, argv);
    int32_t port = node_setup.GetTcpTransport()->GetListenPort();
    RobotRaconteurNode::s()->RegisterService("DistfilesTest", "experimental.distfiles_test", impl);

    RR_SHARED_PTR<DistfilesTest> c = rr_cast<DistfilesTest>(RobotRaconteurNode::s()->ConnectService(
        "rr+tcp://localhost:" + boost::lexical_cast<std::string>(port) + "?service=DistfilesTest"));

    c->set_c(5.0);
    if (c->add(1.0, 2) != 8.0)
    {
        throw std::runtime_error("Unexpected result");
    }

    std::cout << "Test completed successfully" << std::endl;

    return 0;
}