class TimeoutLinkage |
Access "parent" class based on the RTimeout member offset.
This is a base template class to convert the link reference into "parent" class refeference. This is just a convenience template and other solutions for defining the the "expired" callback for RTimeout can also be used.
class CSome { CSome(aCallback) : iTimeout(aCallback) {}; ~CSome() { iTimeout.Cancel(); } Timeout(); // A method to handle the timeout of CSome public: RTimeout iTimeout; }; class SomeLinkage : public TimeoutLinkage<CSome, _FOFF(CSome, iTimeout)> { public: static void Expired(RTimeout &aLink, const TTime & aNow, TAny *aPtr) { Object(aLink)->Timeout(); } };All of the above can be in the CSome header file, and instances of CSome can now just be created as
MTimeoutManager *tMgr = TimeoutFactory::NewL(1); // unit = 1s ... CSome x = new CSome(SomeLinkage:Expired); ... x->iTimeout.Set(tMgr, 10); // request timeout after 10s. ... // when not needed, just delete delete x; delete tMgr;and the CSome Timeout() method will be called after 10s, unless cancelled.
static void Expired(RTimeoutLink &aLink, const TTime &aNow, TAny *aPtr) { ((CSomeManager *)aPtr)->Timeout(Object(aLink), aNow); }
T * | Object | ( | RTimeout & | aLink | ) | [protected, static, inline] |
RTimeout & aLink | The timeout handle. |
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.