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.

A good example of this is the capability and setup pattern used by the serial communications<br />

and other Symbian OS servers. Rather than providing many getter/setter functions to test<br />

and change the state of a communications port – speed, parity, data bits, stop bits,<br />

XON/XOFF, and the like – the communications server provides a single struct containing<br />

all the settings. You use a Config() call to get this struct; you can then change values<br />

in it, and use SetConfig() to send it back to the communications server.<br />

18.2.3 Data Caching<br />

Rather than read a data value from a server every time you need it, it's sometimes a good<br />

idea to cache the data value client side. When they need it, your client programs can use<br />

this value without a client-server transaction. However, you must ensure that the cached<br />

value is updated when necessary.<br />

For example, the Battleships status display shows the GDP protocol in use for the<br />

communication session. You can get this protocol from the GSDP server using a simple<br />

client API call, but that would require a client-server transaction every time the status view is<br />

drawn. It seemed simpler to cache the value in the status view and to update it whenever the<br />

client changes the settings.<br />

If the setting is updated by the server outside the client's control, then you need to use<br />

another method to update the client-side cache. For example, the system shell displays files<br />

in the current folder and highlights any files that are currently open. Files may be deleted and<br />

programs opened and closed, outside the shell's control. To keep the display up to date, the<br />

shell uses notification APIs in both the file server (which knows about all files) and the<br />

window server (which knows about all open GUI applications). The notification API<br />

generates an event when a relevant change occurs. The shell then responds to this event by<br />

asking the server for updated information. Thus, there is no need for the shell to poll (which<br />

would waste power and time), or to require the user to refresh the display (which would be<br />

confusing).<br />

Note<br />

On the emulator, you can alter a file visible to the shell by using the Windows<br />

shell rather than that of Symbian OS. If you want Symbian OS to pick up this<br />

change and notify its shell, press and release F5. This simulates opening<br />

and closing the door on a real machine for a removable media device. In<br />

turn, this causes the file server to notify the shell of general changes and the<br />

shell does a complete rescan.<br />

18.2.4 Related Servers in the Same Process<br />

Two key aspects of a client-server transaction are cheaper if the client and server are on<br />

different threads in the same process:<br />

� Context switching is much cheaper, because no changes to the MMU are required.<br />

� Interthread data transfer is cheaper, because there is no need to map the relevant<br />

client's data space into the server's address space.<br />

These effects are particularly relevant in the hardware implementations used by most current<br />

available Symbian OS phones. Like the Psion Series 5, they use a postcache MMU in order<br />

to save power. This means that the entire cache has to be flushed after a context switch,<br />

which slows things down.<br />

There are several ways to ensure that a client-server call avoids these overheads.

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

Saved successfully!

Ooh no, something went wrong!