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
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 - 2007. All rights reserved.
// Consult your license for conditions of use.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//******************************************************************************

#ifndef INCLUDE_RCF_CLIENTSTUB_HPP
#define INCLUDE_RCF_CLIENTSTUB_HPP

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

#include <boost/shared_ptr.hpp>

#include <RCF/AsyncFilter.hpp>
#include <RCF/Endpoint.hpp>
#include <RCF/GetInterfaceName.hpp>
#include <RCF/MethodInvocation.hpp>
#include <RCF/Protocol/Protocol.hpp>
#include <RCF/SerializationProtocol.hpp>
#include <RCF/Token.hpp>

#ifdef RCF_USE_SF_SERIALIZATION
#include <SF/shared_ptr.hpp>
#include <SF/SerializeEnum.hpp>
#endif

#ifdef RCF_USE_BOOST_SERIALIZATION
#include <boost/serialization/shared_ptr.hpp>
#endif

namespace RCF {

    class ConnectionResetGuard;

    namespace IDL {

        class DoRequest;

    } // namespace IDL

    /// Indicates whether a client should use one-way or two-way semantics for remote calls.
    enum RemoteCallSemantics
    {
        Oneway,
        Twoway
    };

    void setDefaultConnectTimeoutMs(unsigned int connectTimeoutMs);
    unsigned int getDefaultConnectTimeoutMs();

    void setDefaultRemoteCallTimeoutMs(unsigned int remoteCallTimeoutMs);
    unsigned int getDefaultRemoteCallTimeoutMs();

    class ClientStub;

    typedef boost::shared_ptr<ClientStub> ClientStubPtr;

    class ClientProgress;
    typedef boost::shared_ptr<ClientProgress> ClientProgressPtr;

    class I_ClientTransport;
    typedef std::auto_ptr<I_ClientTransport> ClientTransportAutoPtr;

    /// Manages the client side of communications between server and client.
    class ClientStub
    {
    public:
        /// Constructor.
        ClientStub(const std::string &interfaceName);

        /// Constructor.
        /// \param objectName Name of the binding on the server which the client wants to invoke.
        ClientStub(const std::string &interfaceName, const std::string &objectName);

        /// Copy constructor. NB - transfers ownership of the client transport!
        ClientStub(const ClientStub &rhs);

        /// Assignment operator. NB - transfers ownership of the client transport!
        ClientStub &operator=(const ClientStub &rhs);

        /// Sets the server endpoint to which the client will call.
        /// \param endpoint Server endpoint.
        void setEndpoint(const I_Endpoint &endpoint);

        /// Sets the server endpoint to which the client will call.
        /// \param endpoint Server endpoint.
        void setEndpoint(EndpointPtr endpointPtr);

        /// Returns a copy of the currently set server endpoint.
        /// \return Shared pointer to an endpoint.
        EndpointPtr getEndpoint() const;

        // TODO: a lot of these get/set functions should not be publicly available
        /// Gets the token, if any, that the client is using.
        /// \return Returns a copy of the token the client is using. If none, then it returns a default constructed Token.
        Token getTargetToken() const;

        /// Sets the token that the client should use in its calls to the server.
        /// \param token Token that the client should pass in subsequent calls to the server.
        void setTargetToken(Token token);

        /// Gets the binding name on the server that the client is accessing.
        /// \return Name of the server binding.
        std::string getTargetName() const;

        /// Sets the binding name on the server that the client should access on subsequent calls.
        /// \param serverBindingName Name of the server binding.
        //void setServerBindingName(const std::string &serverBindingName);
        void setTargetName(const std::string &targetName);

        /// Gets the calling semantics that the client is currently using (oneway or twoway).
        /// \return Current calling semantics.
        RemoteCallSemantics getDefaultCallingSemantics() const;

        /// Sets the calling semantics that the client should use in subsequent calls (oneway or twoway).
        /// \param defaultCallingSemantics Calling semantics to be used.
        void setDefaultCallingSemantics(RemoteCallSemantics defaultCallingSemantics);

        /// Sets the serialization protocol.
        /// \param protocol Integer identifier of the desired serialization protocol.
        void setSerializationProtocol(int protocol);

        /// Gets the serialization protocol.
        /// \return Integer identifier of the currently set serialization protocol.
        int getSerializationProtocol() const;

        /// Enables pointer tracking for outbound SF serialization.
        /// \parameter Whether to enable or not.
        void enableSfSerializationPointerTracking(bool enable);

        /// Sets the client transport, releasing the currently configured transport.
        /// \param transport Client transport.
        void setTransport(ClientTransportAutoPtr transport);

        /// Returns a reference to currently configured client transport.
        /// \return Current client transport.
        I_ClientTransport& getTransport();

        /// Releases and returns the currently configured client transport.
        /// \return Auto pointer to client transport.
        ClientTransportAutoPtr releaseTransport();

        // /// Deletes the current client transport, and replaces it with a cloned copy.
        /// Calls reset() on the client transport.
        //void resetTransport();

        /// Attempts to connect the underlying client transport.
        void createTransport(); // TODO: private?
        void verifyTransport();
        void connect();
        void disconnect();

        /// Attempts to determine if the underlying client transport is connected.
        /// \return True if the transport is connected, false otherwise.
        bool isConnected();

        /// Sets the payload filtering sequence.
        /// \param filters Vector of filters, enumerated in the order in which they should be applied to unfiltered data
        void setMessageFilters(const std::vector<FilterPtr> &filters);

        /// Sets the payload filtering sequence.
        /// \param filterPtr Single filter.
        void setMessageFilters(FilterPtr filterPtr);

        /// Sets the transport filtering sequence.
        /// \param filters Vector of filters, enumerated in the order in which they should be applied to unfiltered data
        //void setTransportFilters(const std::vector<FilterPtr> &filters);

        /// Sets the transport filtering sequence.
        /// \param filterPtr Single filter.
        //void setTransportFilters(FilterPtr filterPtr = FilterPtr());

        void requestTransportFilters(const std::vector<FilterPtr> &filters);
        void requestTransportFilters(FilterPtr filterPtr);
        bool queryForTransportFilters(const std::vector<FilterPtr> &filters);
        bool queryForTransportFilters(FilterPtr filterPtr);
        void clearTransportFilters();

        const std::vector<FilterPtr> &getMessageFilters();

        /// Sets the remote call timeout value. By default, the timeout is set to 10 seconds.
        /// \param remoteCallTimeoutMs Timeout value, in milliseconds.
        void setRemoteCallTimeoutMs(unsigned int remoteCallTimeoutMs);

        /// Gets the remote call timeout value.
        /// \return Timeout value, in milliseconds.
        unsigned int getRemoteCallTimeoutMs() const;

        /// Sets the connect timeout value. By default, the timeout is set to xx seconds.
        /// \param connectTimeoutMs Timeout value, in milliseconds.
        void setConnectTimeoutMs(unsigned int connectTimeoutMs);

        /// Gets the connect timeout value.
        /// \return Timeout value, in milliseconds.
        unsigned int getConnectTimeoutMs() const;

        void setAutoReconnect(bool autoReconnect);
        bool getAutoReconnect() const;

        void setAutoVersioning(bool autoVersioning);
        bool getAutoVersioning() const;

        void setRcfRuntimeVersion(int version);
        int getRcfRuntimeVersion() const;

        void setClientProgressPtr(ClientProgressPtr ClientProgressPtr);
        ClientProgressPtr getClientProgressPtr() const;

        void setTries(std::size_t tries);
        std::size_t getTries() const;

        template<typename Archive> void serialize(Archive &ar, const unsigned int)
        {
            ar  & mToken
                & mDefaultCallingSemantics
                & mProtocol
                & mEndpointName
                & mObjectName
                & mInterfaceName
                & mRemoteCallTimeoutMs
                & mAutoReconnect
                & mEndpoint;
        }

        void createRemoteObject(const std::string &objectName = "");
        void deleteRemoteObject();

        void createRemoteSessionObject(const std::string &objectName = "");
        void deleteRemoteSessionObject();

    private:

        Token                   mToken;
        RemoteCallSemantics     mDefaultCallingSemantics;
        int                     mProtocol;
        std::string             mEndpointName;
        std::string             mObjectName;
        std::string             mInterfaceName;

        unsigned int            mRemoteCallTimeoutMs;
        unsigned int            mConnectTimeoutMs;
        bool                    mAutoReconnect;
        bool                    mConnected;
        std::size_t                mTries;

        EndpointPtr             mEndpoint;
        ClientTransportAutoPtr  mTransport;

        //VectorFilter            mTransportFilters;
        VectorFilter            mMessageFilters;

        ClientProgressPtr       mClientProgressPtr;

        bool                    mAutoVersioning;
        int                        mRcfRuntimeVersion;

        friend class IDL::DoRequest;

        // TODO: make these private
    public:
        MethodInvocationRequest mRequest;
        SerializationProtocolIn mIn;
        SerializationProtocolOut mOut;
    };

    // thread specific client stub
    void setCurrentClientStubPtr(ClientStubPtr clientStubPtr);
    ClientStubPtr getCurrentClientStubPtr();


    class CurrentClientStubPtrSentry
    {
    public:
        CurrentClientStubPtrSentry(ClientStubPtr clientStubPtr)
        {
            setCurrentClientStubPtr(clientStubPtr);
        }

        ~CurrentClientStubPtrSentry()
        {
            setCurrentClientStubPtr(ClientStubPtr());
        }
    };

} // namespace RCF

#ifdef RCF_USE_SF_SERIALIZATION

namespace SF {

    SF_CTOR(RCF::ClientStub, RCF::ClientStub("", ""))

} // namespace SF

#endif

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

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
Web02 | 2.8.140721.1 | Last Updated 25 Oct 2011
Article Copyright 2005 by Jarl Lindrud
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid