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.

GSDP clients can select the protocol that they want to use via the SetGdpProtocol()<br />

function, which ends up calling the CGdpSession::SetGdpProtocolL():<br />

void CGsdpSession::SetGdpProtocolL(TUid aProtocol)<br />

{<br />

iGdpProtocol = Server()->GetProtocolL(aProtocol);<br />

}<br />

As the protocols are shared between sessions, they are owned by the CGdpServer class.<br />

So the SetGdpProtocolL() function asks the CGdpServer for the right protocol adapter:<br />

CGsdpGdpAdapter* CGsdpServer::GetProtocolL(TUid aProtocol)<br />

{<br />

// Check if we already have an adaptor<br />

// TODO: Use Find()?<br />

TInt i;<br />

for(i=0; i < iAdapters.Count(); i++)<br />

{<br />

if(iAdapters[i]->ProtocolUid() == aProtocol)<br />

}<br />

{<br />

return iAdapters[i];<br />

}<br />

// if not, then create one<br />

CGsdpGdpAdapter* adapter = CGsdpGdpAdapter::NewL(*this);<br />

CleanupStack::PushL(adapter);<br />

CGdpSession* protocol = CGdpSession::NewL(aProtocol);<br />

adapter->SetProtocolL(protocol);<br />

User::LeaveIfError(iAdapters.Append(adapter));<br />

CleanupStack::Pop(adapter);<br />

return adapter;<br />

}<br />

First, GetProtocolL checks whether there is already a matching protocol loaded. If not,<br />

the GDP session is created, and then wrapped in a CGsdpGdpAdapter instance. This is<br />

stored in the server in case other sessions want to use the same protocol. Then the new<br />

adapter is returned to the session.<br />

Note<br />

This implementation ensures that protocols are only loaded when needed,<br />

but doesn't unload them when sessions are closed. A full server should<br />

implement a reference-counting scheme to unload the protocols when they<br />

are no longer needed.<br />

Creating a GDP implementation<br />

We've looked at using GDP implementations via the ECOM framework. Now we come on to<br />

creating an implementation. The simplest protocol, and one that is very useful in testing, is

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

Saved successfully!

Ooh no, something went wrong!