Click here to Skip to main content
15,881,620 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++.
//*****************************************************************************
// 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_CLIENTSTUB_HPP_
#define _RCF_CLIENTSTUB_HPP_

#include <string>
#include <memory>

#include <RCF/Token.hpp>
#include <RCF/Protocol/Protocol.hpp>

namespace RCF {

    class Connection;

    extern const int DefaultClientRecvTimeoutMs;

    class ClientStub
    {
    public:
        ClientStub();
        ClientStub(
            const std::string &ip, 
            int port, 
            int fd, 
            bool oneway,
            bool service,
            unsigned int recvTimeoutMs,
            const std::string &endpointName, 
            const std::string &objectName, 
            const std::string &interfaceName);
        ClientStub(const ClientStub &rhs);
        ClientStub &operator=(const ClientStub &rhs);
        virtual ~ClientStub();
        
        // TODO: a lot of these get/set functions should not be publicly available
        Token getToken() const;
        void setToken(Token token);

        std::string getObjectName() const { return objectName; }
        void setObjectName(const std::string &objectName) { this->objectName = objectName; }
        
        bool getOneway() const { return oneway; }
        void setOneway(bool oneway) { this->oneway = oneway; } // TODO: oneway should be immutable
        
        bool getService() const { return service; }
        void setService(bool service) { this->service = service; }

        unsigned int getRecvTimeoutMs() const { return recvTimeoutMs; }
        void setRecvTimeoutMs(unsigned int recvTimeoutMs) { this->recvTimeoutMs = recvTimeoutMs; }
        
        std::string getIp() const { return ip; }
        void setIp(const std::string &ip) { this->ip = ip; }

        int getPort() const { return port; }
        void setPort(int port) { this->port = port; }

        void setFd(int fd) { this->fd = fd; }
        int getFd() const { return fd; }

        void setProtocol(int protocol) { this->protocol = protocol; }
        int getProtocol() { return protocol; }

        Connection& getConnection();
        void setConnection( std::auto_ptr<Connection> connection );
        std::auto_ptr<Connection> releaseConnection();
        bool isConnected();

        template<typename Archive> void serialize(Archive &ar, const unsigned int)
        {
            ar & token
               & ip
               & port
               & oneway 
               & service 
               & recvTimeoutMs 
               & protocol
               & endpointName 
               & objectName 
               & interfaceName;
        }

    private:
        Token token;
        std::string ip;
        int port;
        int fd;
        bool oneway;
        bool service;
        unsigned int recvTimeoutMs;
        int protocol;
        std::string endpointName;
        std::string objectName;
        std::string interfaceName;
        std::auto_ptr<Connection> connection;
    };

} // namespace RCF

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