03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In this version, if ListImplementationsL() succeeds, we update the iProtocolInfo<br />

list with the new information, but if it fails then the old iProtocolInfo is retained.<br />

This means that protocol info returned to the client may not be up-to-date, and this in turn<br />

has some subtle implications:<br />

� It may not be possible to use a protocol that appears in the list because it is no longer<br />

installed.<br />

� There may be other protocols that exist but that don't appear in the list.<br />

Neither of these two problems seem as bad as returning an empty protocol list, so this is the<br />

version that I chose. You can see here how the error handling of a relatively simple update<br />

function ended up changing the guarantees that the server was able to make to its clients.<br />

Tempting though it may be to ignore errors, handling them is much, much better than hoping<br />

they will never come up. It's my experience that in production code, every possible error<br />

condition will occur, and unhandled ones will eventually sneak up and bite you.<br />

Thanks to the combination of initializing iProtocolInfo at startup and the updates<br />

provided by UpdateProtocolInfo(), CountProtocols() and<br />

GetGdpProtocolInfo() are both simple:<br />

TInt CGsdpServer::CountProtocols()<br />

{<br />

return iProtocolInfo.Count();<br />

}<br />

void CGsdpServer::GetProtocolInfoL(TInt aProto, TGdpProtocolInfo&<br />

aInfo)<br />

{<br />

if(aProto < 0 || aProto >= iProtocolInfo.Count())<br />

User::Leave(KErrArgument);<br />

aInfo.iUid = iProtocolInfo[aProto]->ImplementationUid();<br />

aInfo.iDisplayName = iProtocolInfo[aProto]->DisplayName();<br />

TLex8 lexer(iProtocolInfo[aProto]->OpaqueData());<br />

User::LeaveIfError(lexer.Val(aInfo.iNetworked));<br />

}<br />

CountProtocols() just return the length of the iProtocolInfo array.<br />

GetGdpProtocolInfo() returns the information on a protocol. The protocol to inquire<br />

about is selected by an integer parameter, and the function simply copies the information out<br />

of the iProtocolInfo array and copies it back to the client. Any ECOM implementation<br />

can supply some additional information, called opaque data, in its definition. Here, I use this<br />

to indicate whether the protocol is networked or not. Since it is a blob of binary data, I use<br />

TLex8 to parse it into an integer. If the format isn't right, we leave.<br />

The way I've written the interface requires a client/server call to retrieve the information for<br />

each protocol. I've selected this for ease of programming, but it is inefficient and it would be<br />

better to return all the information in one go. One way to do this would be to use the<br />

MPublicRegistry ECOM interface.

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

Saved successfully!

Ooh no, something went wrong!