class IAddRef

Brief

Manages the existence of an object. All objects created by ForexConnect API implement this interface.

Details

All objects created by ForexConnect API implement this interface. The ForexConnect listeners implemented by a client application and then passed to ForexConnect API must support the reference counter. This class is similar to the classic COM's IUnknown interface.
Every time an object is created or returned from the method, the reference counter is increased by using the addRef() method. The reference counter is increased by ForexConnect API. Every time an object is not required anymore, the reference counter must be decreased by using the release() method.
The reference counter should be decreased by a client application. The rules of using the reference counter are as follows:

  1. When you get an API object as a result of an API function call, API increases the reference counter of this object by 1. So you must call the release() method to decrease the value of its reference counter before the variable storing the object reference is out of the visibility scope. Or you can use the O2G2Ptr<IAddRef> helper template class . Then, when the function execution is finished, release() is called from the destructor of the O2G2Ptr<IAddRef> instance.
    For example:
    void myFunc()
    { IO2GSession* pSession = CO2GTransport::createSession();
    //...
    pSession->release();
    }
    or
    void myFunc()
    {
    {
    O2G2Ptr<IO2GSession> pSession = CO2GTransport::createSession();
    //...
    // release() is called here
    }
    }

  2. When you implement a virtual method (event handler) of your class which inherits the IO2GSessionStatus listener, or IO2GTableListener, or IO2GResponseListener interface, you must not call release() for objects that are taken as parameters of these methods. Such objects are created and released in the caller of your event handler.

  3. When you save an API object reference in a class-level variable for further usage, you must call addRef() immediately after the object reference has been assigned to this class-level variable. During the class destruction the release() method must be called for this object reference. The release() method must also be called if a new object reference is reassigned to the class-level variable.

Public Methods

addRef

Increments the reference count when the object is created or stored or returned from the method.

release

Decrements the reference count when the object is not required anymore.

back