Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


Using CAsyncOneShot

An instance of a class derived from the CAsyncOneShot class can be used to perform one-off processing when no higher-priority active objects are ready to run.

While it has many uses, a common usage is to use it to unload a library. A typical CAsyncOneShot derived class is defined as:

class CLibUnloader : public CAsyncOneShot
    {
public:
    static CLibUnloader* NewL(RLibrary& aLibrary);
    inline void Unload();
protected:
    CLibUnloader();
    ~CLibUnloader();
    virtual void RunL();
private:
    RLibrary iLib;
    };

The static NewL() function takes a reference to an existing open RLibrary object and creates a new CLibUnloader object:

CLibUnloader* CLibUnloader::NewL(RLibrary& aLibrary)
    {
    CLibUnloader* u=new(ELeave)CLibUnloader;
    u->iLib=aLibrary;
    return u;
    }

The remaining functions are implemented as follows:

In other uses of CAsyncOneShot, RunL() could do more complex processing, and indeed could re-queue the active object with another call to CAsyncOneShot::Call().