TimeoutLinkage Class Reference

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.

A simple use example:
        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.
Instead of using the Timeout in the objects directly, the aPtr parameter of Expired could be an address of a manager type instance, which handles objects of this type. The object itself might not have any use of the Expired call and it should be passed to the manager. This can be realised by defining the linkage Expired as follows (for example)
        static void Expired(RTimeoutLink &aLink, const TTime &aNow, TAny *aPtr)
		{
		((CSomeManager *)aPtr)->Timeout(Object(aLink), aNow);
		}
       
Protected Member Functions
T * Object ( RTimeout &)

Member Functions Documentation

Object(RTimeout &)

T * Object ( RTimeout & aLink ) [protected, static, inline]

Gets the "parent object" of RTimeout member.

Based on the offset of the RTimeout member, typecast the adjusted pointer to the "parent type", and return the pointer.

Parameters

RTimeout & aLink The timeout handle.