Click here to Skip to main content
15,881,559 members
Articles / Programming Languages / C++

RMI for C++

Rate me:
Please Sign up or sign in to vote.
4.87/5 (113 votes)
6 Aug 2009CPOL8 min read 812.3K   4.6K   153  
User-friendly remote method invocation in C++.
#ifndef _TEST_PERFORMANCE_HPP_
#define _TEST_PERFORMANCE_HPP_

#include <string>

#include <boost/lexical_cast.hpp>

#include <RCF/RCF.hpp>
#include <RCF/util/Profile.hpp>

class X 
{
public:
    void f0() {}
    int f1(int) { return 0; }
    std::string f2(const std::string &) { return ""; }
};

RCF_BEGIN( I_X, "I_X" )
    RCF_METHOD_V0(void, f0)
    RCF_METHOD_R1(int, f1, int)
    RCF_METHOD_R1(std::string, f2, const std::string &)
RCF_END( I_X )

void runClientTests(const std::string &ip, int port, int calls, int protocol)
{
    RcfClient<I_X> client(ip, port);
    client.f0();
    client.f1(1);
    client.f2("");

    for (int p=1; p<=10; p++)
    {
        if (protocol == p || (protocol == 0 && RCF::isProtocolSupported(p)))
        {
            client.setProtocol(p);
            std::string protocolName = RCF::getProtocolName(p);
            std::string titleHeader = 
                "Protocol: " + protocolName + 
                ", Calls: " + boost::lexical_cast<std::string>(calls);
            {
                std::string title = titleHeader + ", void f()";
                util::Profile profile(title);
                for (int i=0; i<calls; i++)
                {
                    client.f0();
                }
            }
            {
                std::string title = titleHeader + ", int f(int)";
                util::Profile profile(title);
                for (int i=0; i<calls; i++)
                {
                    client.f1(0);
                }
            }
            {
                std::string title = titleHeader + ", std::string f(std::string)";
                util::Profile profile(title);
                for (int i=0; i<calls; i++)
                {
                    client.f2("");
                }
            }
        }
    }
}

#endif // ! _TEST_PERFORMANCE_HPP_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
Software developer, from Sweden and now living in Canberra, Australia, working on distributed C++ applications. When he is not programming, Jarl enjoys skiing and playing table tennis. He derives immense satisfaction from referring to himself in third person.

Comments and Discussions