Click here to Skip to main content
15,886,518 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 - 2007. All rights reserved.
// Consult your license for conditions of use.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//******************************************************************************

#include <RCF/Tools.hpp>

#include <RCF/InitDeinit.hpp>

#include <RCF/util/Platform/OS/GetCurrentTime.hpp>

namespace RCF {

    util::TraceChannel *pTraceChannels[10];

    // current time in ms, modulo 65536 s (turns over every ~18.2 hrs)
    unsigned int getCurrentTimeMs()
    {
        return Platform::OS::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)
    {
        // 90% of the timer interval
        static const unsigned int maxTimeoutMs = (((unsigned int)-1)/10)*9;
        unsigned int currentTimeMs = getCurrentTimeMs();
        unsigned int timeoutMs = endTimeMs - currentTimeMs;
        return (timeoutMs < maxTimeoutMs) ? timeoutMs : 0;
    }

    void deinitRcfTraceChannels()
    {
        for (int i=0; i<10; ++i)
        {
            delete pTraceChannels[i];
            pTraceChannels[i] = NULL;
        }
    }

    void initRcfTraceChannels()
    {
        deinitRcfTraceChannels();
        for (int i=0; i<10; ++i)
        {
            std::string name = "RCF";
            if (i > 0)
            {
                name += '0' + static_cast<char>(i);
            }
            pTraceChannels[i] = new util::TraceChannel(name);
        }

#ifndef NDEBUG
        pTraceChannels[9]->setTraceTarget("ODS");
#endif

    }

    RCF_ON_INIT_DEINIT_NAMED(
        initRcfTraceChannels(),
        deinitRcfTraceChannels(),
        InitRcfTraceChannels);

    const int gRcfRuntimeVersion = 2;

} // namespace RCF

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