Click here to Skip to main content
15,891,033 members
Articles / Programming Languages / C++

RCF - Interprocess Communication for C++

Rate me:
Please Sign up or sign in to vote.
4.94/5 (147 votes)
25 Oct 2011CPOL20 min read 4.6M   8.4K   331  
A server/client IPC framework, using the C++ preprocessor as an IDL compiler.
//*****************************************************************************
// RCF - Remote Call Framework
// Copyright (c) 2005. All rights reserved.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//*****************************************************************************

#ifndef INCLUDE_RCF_CLIENTTRANSPORT_HPP
#define INCLUDE_RCF_CLIENTTRANSPORT_HPP

#include <memory>
#include <string>
#include <vector>

#include <RCF/AsyncFilter.hpp>

namespace RCF {

    class I_Endpoint;
    typedef boost::shared_ptr<I_Endpoint> EndpointPtr;

    /// Base class for client transports.
    class I_ClientTransport
    {
    public:
        /// Constructor.
        I_ClientTransport();

        /// Virtual destructor.
        virtual ~I_ClientTransport() {}

        /// Clones this transport (deep copy).
        /// \return Auto pointer to a new client transport, cloned from this one.
        virtual std::auto_ptr<I_ClientTransport> clone() const = 0;

        /// Obtains the remote endpoint of the client transport.
        /// \return Pointer to endpoint.
        virtual EndpointPtr getEndpointPtr() const = 0;
        
        /// Sends data over the client transport, under the given timeout.
        /// \param data Data to send.
        /// \param timeoutMs Timeout value, specified in milliseconds.
        /// \return -2 for timeout, -1 for error, 0 for peer closure, 1 for ok.
        virtual int send(const std::string &data, unsigned int timeoutMs) = 0;

        /// Attempts to receive data over the client transport, under the given timeout.
        /// \param data Buffer in which to receive data.
        /// \param timeoutMs Timeout value, specified in milliseconds.
        /// \return -2 for timeout, -1 for error, 0 for peer closure, 1 for ok.
        virtual int receive(std::string &data, unsigned int timeoutMs) = 0;

        /// Attempts to determine if the transport is connected, i.e. if send() or receive() can proceed without errors.
        /// \return By default, the return value is true. If it can be determined that the transport is not connected, the return val�e is false.
        virtual bool isConnected();

        /// Sets the transport filter sequence of the transport.
        /// \param filters Sequence of filters to install.
        virtual void setTransportFilters(const std::vector<FilterPtr> &filters) = 0;

        /// Sets the maximum message length.
        /// \param maxMessageLength Maximum allowed message length.
        void setMaxMessageLength(std::size_t maxMessageLength);

        /// Gets the maximum message length.
        /// \return Maximum allowed message length.
        std::size_t getMaxMessageLength();

    private:
        std::size_t mMaxMessageLength;

    };

    typedef boost::shared_ptr<I_ClientTransport> ClientTransportPtr;

    typedef std::auto_ptr<I_ClientTransport> ClientTransportAutoPtr;

} // namespace RCF

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