03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

virtual void OpenL(MGdpPacketHandler* aHandler)=0;<br />

// start up, and set handler for packets received<br />

virtual void SendL(const TDesC8& aToAddress, const TDesC8&<br />

aData)=0;<br />

// send packet<br />

virtual void ReceiveAllL()=0; // do a pull if necessary<br />

virtual TInt GetMaxPacketLength() const =0; // max packet<br />

length<br />

virtual TBool IsNetworked() const =0;<br />

// requires addresses, if networked<br />

inline TUid Uid() const {return iDtor_ID_Key;};<br />

protected:<br />

TUid iDtor_ID_Key;<br />

};<br />

The interface is defined in two classes, CgdpSession,and MGdpHandler. CGdpSession is<br />

the pure virtual base class from which I will derive the different implementations. It has<br />

methods for the basic functions supported by GDP. Two features make this class a little<br />

different from normal virtual base classes:<br />

� A static NewL() function. Clients call this function to acquire an implementation,<br />

specified using a UID.<br />

� The iDtor_ID member. This is used by the ECOM framework to identify<br />

implementations when creating and destroying them.<br />

Let's look at the NewL() function:<br />

EXPORT_C CGdpSession* CGdpSession::NewL(TUid aUid)<br />

{<br />

return<br />

static_cast(REComSession::CreateImplementationL<br />

}<br />

(aUid, _FOFF(CGdpSession, iDtor_ID_Key)));<br />

This is incredibly simple: the UID parameter is passed to the REcom-<br />

Session::CreateImplementation() function, which then returns the right instance.<br />

The offset of the iDtor_ID member is also passed to ECOM so that it can track<br />

instantiated classes. This is all that is required to create the right implementation – ECOM<br />

does all the hard work of finding and loading the right DLL for us.<br />

19.3.4 Using the Protocols<br />

Next, we'll look at how the server makes use of ECOM to find protocols and make them<br />

available to its clients. During server startup, ConstructL() is called:<br />

void CGsdpServer::ConstructL()<br />

{<br />

// construct receive queue<br />

iReceiveQueue=CGsdpReceiveQueue::NewL(*this);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!