Click here to Skip to main content
15,893,663 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_RCFCLIENT_HPP
#define INCLUDE_RCF_RCFCLIENT_HPP

#include <boost/mpl/bool_fwd.hpp>
#include <boost/shared_ptr.hpp>

#include <RCF/ServerStub.hpp>

#include <SF/SfNew.hpp>

#include <RCF/CheckRtti.hpp>

namespace RCF {

    class ClientStub;
    class ServerStub;

    /// Base class of all RcfClient<> templates.
    class I_RcfClient
    {
    public:
        /// Virtual destructor.
        virtual ~I_RcfClient() {}

        /// Returns a reference to the contained client stub, if one is available, i.e. if the RcfClient<> template is configured as a client stub.
        virtual ClientStub &getClientStub() = 0;

        /// Returns a reference to the contained server stub, if one is available, i.e. if the RcfClient<> template is configured as a server stub.
        virtual ServerStub &getServerStub() = 0;
    };

    typedef boost::shared_ptr<I_RcfClient> RcfClientPtr;

    //SF_NO_CTOR(I_RcfClient)

    //template<typename Archive>
    //void serialize(Archive &archive, I_RcfClient &rcfClient, const unsigned int)
    //{
        //archive & rcfClient.getClientStub();
    //}

    // some meta-programming functionality needed by the macros in IDL.hpp

#ifndef __BORLANDC__

    typedef char (&yes_type)[1];
    typedef char (&no_type)[2];
    template<typename U> static yes_type HasRcfClient_helper(typename U::RcfClient *);
    template<typename U> static no_type HasRcfClient_helper(...);

    template<typename T>
    struct HasRcfClient
    {
        typedef typename boost::mpl::bool_<sizeof(yes_type) == sizeof(HasRcfClient_helper<T>(0))> type;
    };

    template<typename T, typename U>
    struct GetRcfClient;

    template<typename U>
    struct GetRcfClient<boost::mpl::true_, U>
    {
        typedef typename U::RcfClient type;
    };

    template<typename U>
    struct GetRcfClient<boost::mpl::false_, U>
    {
        typedef U type;
    };

    template<typename T>
    struct ToDeriveFrom
    {
        typedef typename GetRcfClient< typename HasRcfClient<T>::type, T >::type type;
    };

#endif

    template<typename T, typename U>
    class RegisterInvokeFunctors;

    template<typename U>
    class RegisterInvokeFunctors<boost::mpl::true_, U>
    {
    public:
        template<typename V, typename DerefPtrT>
        void operator()(V &v, InvokeFunctorMap &invokeFunctorMap, DerefPtrT derefPtr)
        {
            typedef typename U::RcfClient Parent;
            //v.RcfClient::registerInvokeFunctors(invokeFunctorMap, derefPtr);

            StubAccess().registerParentInvokeFunctors<Parent>(v, invokeFunctorMap, derefPtr);
        }
    };

    template<typename U>
    class RegisterInvokeFunctors<boost::mpl::false_, U>
    {
    public:
        template<typename V, typename DerefPtrT>
            void operator()(V &v, InvokeFunctorMap &invokeFunctorMap, DerefPtrT derefPtr)
        {}
    };

    template<typename T>
    class Dummy
    {};

} // namespace RCF

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