Wrapper Design in C ++

I am developing a simulator to work in a test environment. In any case, the system under test represents the RCF API, which I use extensively. The problem is that I am allowed (to simulate a real system) to have a single "RCF client" for each connection. This means I will need to use secure client streams.

Usually, I would call an RCF method just by name:

client->methodA(param);

      

Now, instead, I have to (I think) wrap each method in the method that contains the call to the mutex:

virtual class RCFClientWrapper
{
protected:
    boost::mutex mtx;
public:
    virtual RCFClientWrapper();
}

class FunctionAClient:RCFClientWrapper
{
private:
    boost::shared_ptr<RcfClient<IRCFFunctionA_IDL> > client;
public:
    /*....Stuff....*/
    void methodA(param)
    {
        boost::lock_guard<boost::mutex> lock(mtx);
        client->methodA(param);
    }
}

      

First of all, is there a better way to do this? Secondly, is there a way to make all these little methods "automatically"? Instead of doing this for every any method? It seems like a lot of unnecessary copies / pasta.

+3


source to share


1 answer


Why not consider a proxy class that is used to implement a proxy pattern where an object is an interface or proxy for another object.



0


source







All Articles