Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

RCF - Interprocess Communication for C++

, 25 Oct 2011 CPOL
A server/client IPC framework, using the C++ preprocessor as an IDL compiler.
rcf-04.zip
RCF-0.4
demo
vs2003
RCF
Client
Server
doc
html
class_r_c_f_1_1_exception.png
class_r_c_f_1_1_filter.png
class_r_c_f_1_1_filter_factory.png
class_r_c_f_1_1_filter_service.png
class_r_c_f_1_1_identity_filter.png
class_r_c_f_1_1_identity_filter_factory.png
class_r_c_f_1_1_i___client_transport.png
class_r_c_f_1_1_i___endpoint.png
class_r_c_f_1_1_i___service.png
class_r_c_f_1_1_i___session_manager.png
class_r_c_f_1_1_multicast_client_transport.png
class_r_c_f_1_1_object_factory_service.png
class_r_c_f_1_1_open_ssl_encryption_filter.png
class_r_c_f_1_1_open_ssl_encryption_filter_factory.png
class_r_c_f_1_1_publishing_service.png
class_r_c_f_1_1_rcf_server.png
class_r_c_f_1_1_remote_exception.png
class_r_c_f_1_1_subscription_service.png
class_r_c_f_1_1_tcp_endpoint.png
class_r_c_f_1_1_udp_endpoint.png
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.png
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.png
doxygen.png
ftv2blank.png
ftv2doc.png
ftv2folderclosed.png
ftv2folderopen.png
ftv2lastnode.png
ftv2link.png
ftv2mlastnode.png
ftv2mnode.png
ftv2node.png
ftv2plastnode.png
ftv2pnode.png
ftv2vertline.png
tab_b.gif
tab_l.gif
tab_r.gif
latex
annotated.tex
class_r_c_f_1_1_client_stub.tex
class_r_c_f_1_1_exception.eps
class_r_c_f_1_1_exception.tex
class_r_c_f_1_1_filter.eps
class_r_c_f_1_1_filter.tex
class_r_c_f_1_1_filter_description.tex
class_r_c_f_1_1_filter_factory.eps
class_r_c_f_1_1_filter_factory.tex
class_r_c_f_1_1_filter_service.eps
class_r_c_f_1_1_filter_service.tex
class_r_c_f_1_1_identity_filter.eps
class_r_c_f_1_1_identity_filter.tex
class_r_c_f_1_1_identity_filter_factory.eps
class_r_c_f_1_1_identity_filter_factory.tex
class_r_c_f_1_1_i___client_transport.eps
class_r_c_f_1_1_i___client_transport.tex
class_r_c_f_1_1_i___endpoint.eps
class_r_c_f_1_1_i___endpoint.tex
class_r_c_f_1_1_i___proactor.tex
class_r_c_f_1_1_i___rcf_client.tex
class_r_c_f_1_1_i___server_transport.tex
class_r_c_f_1_1_i___server_transport_ex.tex
class_r_c_f_1_1_i___service.eps
class_r_c_f_1_1_i___service.tex
class_r_c_f_1_1_i___session.tex
class_r_c_f_1_1_i___session_manager.eps
class_r_c_f_1_1_i___session_manager.tex
class_r_c_f_1_1_multicast_client_transport.eps
class_r_c_f_1_1_multicast_client_transport.tex
class_r_c_f_1_1_object_factory_service.eps
class_r_c_f_1_1_object_factory_service.tex
class_r_c_f_1_1_open_ssl_encryption_filter.eps
class_r_c_f_1_1_open_ssl_encryption_filter.tex
class_r_c_f_1_1_open_ssl_encryption_filter_factory.eps
class_r_c_f_1_1_open_ssl_encryption_filter_factory.tex
class_r_c_f_1_1_publishing_service.eps
class_r_c_f_1_1_publishing_service.tex
class_r_c_f_1_1_rcf_server.eps
class_r_c_f_1_1_rcf_server.tex
class_r_c_f_1_1_remote_exception.eps
class_r_c_f_1_1_remote_exception.tex
class_r_c_f_1_1_subscription_service.eps
class_r_c_f_1_1_subscription_service.tex
class_r_c_f_1_1_tcp_endpoint.eps
class_r_c_f_1_1_tcp_endpoint.tex
class_r_c_f_1_1_udp_endpoint.eps
class_r_c_f_1_1_udp_endpoint.tex
class_r_c_f_1_1_zlib_stateful_compression_filter.tex
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.eps
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.tex
class_r_c_f_1_1_zlib_stateless_compression_filter.tex
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.eps
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.tex
dirs.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2F.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2FRCF_2F.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2FRCF_2FProtocol_2F.tex
doxygen.sty
Helvetica.ttf
hierarchy.tex
Makefile
refman.tex
struct_r_c_f_1_1_filter_id_comparison.tex
include
RCF
Marshal.inl
Protocol
RcfServer.inl
ServerStub.inl
test
util
Platform
Machine
SPARC
x86
OS
Unix
Windows
Threads
SF
src
RCF
Protocol
SF
test
borland
Jamfile
Jamrules
Jamfile
Jamrules
vs2003
RCF
RCF
RCFTest
client.pem
server.pem
rcf-09c.zip
RCF-0.9c
demo
vs2003
RCF
Client
Server
include
RCF
Marshal.inl
Protocol
RcfServer.inl
ServerStub.inl
test
util
Platform
Machine
SPARC
x86
OS
Unix
Windows
Threads
SF
src
RCF
Protocol
util
SF
test
bcc
Jamfile
Jamrules
data
caCertA.pem
caCertB.pem
certA.pem
certB.pem
ssCert1.pem
ssCert2.pem
Jamfile
Jamrules
vc6
Jamfile
Jamrules
//*****************************************************************************
// RCF - Remote Call Framework
// Copyright (c) 2005. All rights reserved.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//*****************************************************************************

#ifndef INCLUDE_RCF_SERVERTRANSPORT_HPP
#define INCLUDE_RCF_SERVERTRANSPORT_HPP

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

#include <boost/shared_ptr.hpp>

namespace RCF {

    class Filter;
    class I_Endpoint;
    class I_ClientTransport;
    class I_Proactor;
    class I_Session;

    typedef boost::shared_ptr<Filter> FilterPtr;
    typedef boost::shared_ptr<I_Proactor> ProactorPtr;
    typedef std::auto_ptr<I_ClientTransport> ClientTransportAutoPtr;

    class I_ServerTransport;
    typedef boost::shared_ptr<I_ServerTransport> ServerTransportPtr;

    class I_RemoteAddress
    {
    public:
        virtual ~I_RemoteAddress()
        {}
    };
    
    /// Interface by which the session manager reads/writes data on a given session.
    /// Each session has a polymorphic I_Proactor object.
    class I_Proactor
    {
    public:
        /// Virtual destructor.
        virtual ~I_Proactor() {}

        /// Posts a read request to the server transport.
        virtual void postRead() = 0;

        /// Posts a write request to the server transport
        virtual void postWrite() = 0;

        // TODO
        /// Posts a close request to the server transport. Not implemented.
        virtual void postClose() = 0;

        /// Returns a reference to the write buffer of the session. The user may resize the buffer, but not to a size below write offset.
        /// \return Reference to the internal write buffer of the session.
        virtual std::vector<char> &getWriteBuffer() = 0;

        /// Returns a value indicating where in the write buffer the user may commence writing.
        /// \return Offset into the write buffer.
        virtual std::size_t getWriteOffset() = 0;

        /// Returns a reference to the internal read buffer of the session. The user should not, and should have no need to, resize this buffer.
        /// \return Reference to the internal write buffer of the session.
        virtual std::vector<char> &getReadBuffer() = 0;

        /// Returns a value indicating where in the read buffer the user should commence reading.
        /// \return Offset into the read buffer.
        virtual std::size_t getReadOffset() = 0;

        /// Returns a reference to the server transport.
        /// \return Reference to the server transport.
        virtual I_ServerTransport &getServerTransport() = 0;

        /// Returns a I_RemoteAddress interface containing information on the remote address of the client of this session.
        /// \return I_RemoteAddress reference.
        virtual const I_RemoteAddress &getRemoteAddress() = 0;

        /// Sets the transport filter sequence of this session, which will become active on the next read or write operation.
        /// \param filters Sequence of filters to be used as transport filters on the session.
        virtual void setTransportFilters(const std::vector<FilterPtr> &filters) = 0;
    };

    typedef boost::shared_ptr<I_Proactor> ProactorPtr;

    /// Interface for a generic server session.
    class I_Session
    {
    public:
        /// Virtual destructor.
        virtual ~I_Session() {}

        /// Returns a pointer to the I_Proactor instance of the session.
        /// \return Pointer to I_Proactor instance.
        ProactorPtr getProactorPtr()
        {
            return mProactorPtr;
        }

        /// Sets the I_Proactor instance of the session.
        /// \param proactorPtr Pointer to I_Proactor instance.
        void setProactorPtr(ProactorPtr proactorPtr)
        {
            mProactorPtr = proactorPtr;
        }

    private:
        ProactorPtr mProactorPtr;
    };

    /// Base class of all server transport services.
    class I_ServerTransport
    {
    public:
        /// Constructor.
        I_ServerTransport();

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

        /// Clones the server transport
        /// \return A cloned copy of this transport.
        virtual ServerTransportPtr clone() = 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;
    };

    /// Additional base class for server transport services with extended stream-oriented functionality.
    ///
    /// Twoway, stream-oriented server transport services that are to be used with publish/subscribe need to implement I_ServerTransportEx.
    /// The functions in I_ServerTransportEx are all synchronized and can safely be called from any thread.
    class I_ServerTransportEx
    {
    public:

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

        /// Creates a client transport to the given endpoint.
        /// \param endpoint Endpoint describing a remote server.
        /// \return Auto pointer to client transport accessing the remote server described by the endpoint.
        virtual ClientTransportAutoPtr createClientTransport(const I_Endpoint &endpoint) = 0;
        
        /// Creates a server session dual to the given client transport.
        /// \param clientTransportAutoPtr Auto pointer to client transport, from which the server session should be generated.
        /// \return Server session.
        virtual boost::shared_ptr<I_Session> createServerSession(ClientTransportAutoPtr clientTransportAutoPtr) = 0;

        /// Creates a client transport dual to the given server session.
        /// \param sessionPtr Server session from which to generate the client transport.
        /// \return Auto pointer to client transport.
        virtual ClientTransportAutoPtr createClientTransport(boost::shared_ptr<I_Session> sessionPtr) = 0;
        
        /// Requests the server transport to start reflecting data between the two given sessions. All data subsequently read on the first session will
        /// be sent out on the second session, and vice versa.
        /// \param sessionPtr1 First server session
        /// \param sessionPtr2 Second server session.
        /// \return true if server transport acquiesces, false otherwise.
        virtual bool reflect(boost::shared_ptr<I_Session> sessionPtr1, boost::shared_ptr<I_Session> sessionPtr2) = 0;
        
        /// Attempts to determine whether a server session is still connected. Returns true, unless it can be determined that the 
        /// physical transport instance is no longer valid. For a TCP server session, this amounts to checking if the underlying socket is ready
        /// to receive and has no errors queued, in other words that the TCP connection is still open.
        /// \param sessionPtr Session to check.
        /// \return Boolean value indicating the server transports best-effort knowledge of the state of the session.
        virtual bool isConnected(boost::shared_ptr<I_Session> sessionPtr) = 0;
    };
    
    /// Base class for session managers, in particular RcfServer.
    ///
    /// Server transports use I_SessionManager to communicate with the RcfServer class.
    class I_SessionManager
    {
    public:
        /// Virtual destructor.
        virtual ~I_SessionManager() {}

        /// Requests the session manager to create a new session.
        /// \return Pointer to newly created session.
        virtual boost::shared_ptr<I_Session> createSession() = 0;

        /// Callback, by which the server transport indicates that a read operation has completed on the session.
        /// \param sessionPtr Session for which the read operation has completed.
        virtual void onReadCompleted(boost::shared_ptr<I_Session> sessionPtr) = 0;

        /// Callback, by which the server transport indicates that a write operation has completed on the session.
        /// \param sessionPtr Session for which the write operation has completed.
        virtual void onWriteCompleted(boost::shared_ptr<I_Session> sessionPtr) = 0;
    };

} // namespace RCF

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

Share

About the Author

Jarl Lindrud

Australia Australia
Software developer, ex-resident of Sweden and now living in Canberra, Australia, working on distributed C++ applications. Jarl enjoys programming, but prefers skiing and playing table tennis. He derives immense satisfaction from referring to himself in third person.

| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 25 Oct 2011
Article Copyright 2005 by Jarl Lindrud
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid