Click here to Skip to main content
15,884,709 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 815.3K   4.6K   153  
User-friendly remote method invocation in C++.
//*****************************************************************************
// RCF - Remote Call Framework
// Copyright (c) 2005, Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//
// Distributed under the so-called MIT license, see accompanying file license.txt.
//*****************************************************************************

#ifndef _RCF_SERVERSTUB_HPP_
#define _RCF_SERVERSTUB_HPP_

#include <RCF/Connection.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>

#include <RCF/Token.hpp>

namespace RCF {

    class Connection;

    class I_ServerStub
    {
    public:
        virtual ~I_ServerStub() {}
        virtual void invoke(int id, Connection &connection) = 0;
        virtual void setToken(Token token) = 0;
        virtual Token getToken() = 0;
    };
    
    template<typename StubT, typename ImplementationT>
    class ServerStub : public I_ServerStub, boost::noncopyable
    {
    public:
        ServerStub(ImplementationT &x);
        ServerStub(std::auto_ptr<ImplementationT> px);
        ServerStub(boost::shared_ptr<ImplementationT> px);

    private:
        void invoke(int id, RCF::Connection &connection);
        template<typename IdT> void invoke(StubT &stub, const IdT &id, Connection &connection, ImplementationT &t);
        Token getToken();
        void setToken(Token token);
    
        StubT stub;
        Token token;
        boost::shared_ptr<ImplementationT> px;
        ImplementationT &x;
    };

    class StubAccess
    {
    public:
        template<typename StubT, typename IdT, typename T>
        void invoke(StubT &stub, const IdT &id, Connection &connection, T &t);
    };

} // namespace RCF

#include <RCF/ServerStub.inl>

#endif // ! _RCF_SERVERSTUB_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