Click here to Skip to main content
11,501,513 members (75,912 online)
Click here to Skip to main content
Add your own
alternative version

RCF - Interprocess Communication for C++

, 25 Oct 2011 CPOL 1.5M 7K 321
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_TOOLS_HPP
#define INCLUDE_RCF_TOOLS_HPP

// Various utilities

#include <time.h>

#include <deque>
#include <iostream>
#include <iterator>
#include <memory>
#include <stdexcept>
#include <typeinfo>
#include <vector>

#include <boost/bind.hpp>
#include <boost/current_function.hpp>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>

#include <RCF/Exception.hpp>
#include <RCF/ScopeGuard.h>
#include <RCF/ThreadLibrary.hpp>
#include <RCF/util/Meta.hpp>
#include <RCF/util/UnusedVariable.hpp>

// Assertion mechanism
#include <RCF/util/Assert.hpp>
#define RCF_ASSERT(x) UTIL_ASSERT(x, RCF::AssertionFailureException)

// Verification mechanism
#include <RCF/util/Throw.hpp>
#define RCF_VERIFY(x, msg) UTIL_VERIFY(x, RCF::VerificationFailureException, msg)

// Trace mechanism
#include <RCF/util/Trace.hpp>
//#define RCF_TRACE(x) DUMMY_VARIABLE_ARG_MACRO()
#define RCF_TRACE(x)  UTIL_TRACE(x, (*::RCF::pTraceChannels[0]))
#define RCF1_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[1]))
#define RCF2_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[2]))
#define RCF3_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[3]))
#define RCF4_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[4]))
#define RCF5_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[5]))
#define RCF6_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[6]))
#define RCF7_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[7]))
#define RCF8_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[8]))
#define RCF9_TRACE(x) UTIL_TRACE(x, (*::RCF::pTraceChannels[9]))

namespace RCF {
    extern util::TraceChannel *pTraceChannels[10];
}

// Throw mechanism
#include <RCF/util/Throw.hpp>
#define RCF_THROW UTIL_THROW

// Scope guard mechanism
namespace RCF {

    class SharedPtrScopeGuard : boost::noncopyable
    {
    public:
        template<typename T>
        SharedPtrScopeGuard(T &t) : 
            spv(static_cast<void*>(NULL), t)
        {}

        template<typename T, typename R>
        SharedPtrScopeGuard(T &t, R (T::*pfn)() ) : 
            spv(static_cast<void*>(NULL), boost::bind(pfn, &t))
        {}

        template<typename T, typename R, typename A>
        SharedPtrScopeGuard(T &t, R (T::*pfn)(A), A a) : 
            spv(static_cast<void*>(NULL), boost::bind(pfn, &t, a))
        {}

        void dismiss()
        {
            spv.reset();
        }

    private:
        boost::shared_ptr<void> spv;
    };
/*
    template<typename PFN>
    void trigger0(void *pv)
    {
        ((PFN) pv)();
    }

    template<typename T, typename PMFN>
    void trigger1(void *pvt, void *pvmfn)
    {
        PMFN pmfn = (PMFN) pvmfn;
        T *pt = (T *) pvt;
        pt->*pmfn();
    }
  
    class AlexandrescuScopeGuard
    {
    public:

        template<typename PFN>
        AlexandrescuScopeGuard(PFN pfn) :
            mTrigger0( trigger0<PFN> ),
            mTrigger1(),
            mpv0(pfn),
            mpv1(),
            mDismissed()
        {}

        template<typename T, typename PMFN>
        AlexandrescuScopeGuard(T &t, PMFN pmfn) :
            mTrigger1( trigger1<T, PMFN> ),
            mpv0(&t),
            mpv1( (void *) pmfn)
        {}

        ~AlexandrescuScopeGuard()
        {
            if (!mDismissed)
            {
                try
                {
                    if (mTrigger0)
                    {
                        mTrigger0(mpv0);
                    }
                    else if (mTrigger1)
                    {
                        mTrigger1(mpv0, mpv1);
                    }
                }
                catch(...)
                {}
            }
        }

        void dismiss()
        {
            mDismissed = true;
        }

    private:
        bool mDismissed;
        void (*mTrigger0)(void *pv0);
        void (*mTrigger1)(void *pv0, void *pv1);
        void *mpv0;
        void *mpv1;
    };

//#ifdef __BORLANDC__
//    typedef SharedPtrScopeGuard         ScopeGuard;
//#else
    typedef AlexandrescuScopeGuard      ScopeGuard;
//#endif
*/
}

#ifndef __BORLANDC__
namespace std {
#endif

    // Trace std::vector
    template<typename T>
    std::ostream &operator<<(std::ostream &os, const std::vector<T> &v)
    {
        os << "(";
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(os, ", "));
        os << ")";
        return os;
    }

    // Trace std::deque
    template<typename T>
    std::ostream &operator<<(std::ostream &os, const std::deque<T> &d)
    {
        os << "(";
        std::copy(d.begin(), d.end(), std::ostream_iterator<T>(os, ", "));
        os << ")";
        return os;
    }


    // Trace type_info
    inline std::ostream &operator<<(std::ostream &os, const std::type_info &ti) 
    { 
        return os << ti.name(); 
    }
    
    // Trace exception
    inline std::ostream &operator<<(std::ostream &os, const std::exception &e) 
    { 
        return os << "Type: " << typeid(e).name() << ", What: " << e.what(); 
    }

#ifndef __BORLANDC__
} // namespace std
#endif

namespace RCF {

    // Time in ms since ca 1970, modulo 65536 s (turns over every ~18.2 hrs).
    unsigned int getCurrentTimeMs();
    
    // Generate a timeout value for the given ending time.
    // Returns zero if endTime <= current time <= endTime+10%of timer resolution, otherwise returns a nonzero duration in ms.
    // Timer resolution as above (18.2 hrs).
    unsigned int generateTimeoutMs(unsigned int endTimeMs);

} // namespace RCF

#endif // ! INCLUDE_RCF_TOOLS_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 | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 25 Oct 2011
Article Copyright 2005 by Jarl Lindrud
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid