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.

CGsdpScheduler::TServerStart start;<br />

TInt r=start.GetCommand();<br />

if (r==KErrNone)<br />

return r;<br />

}<br />

r=CGsdpScheduler::ThreadStart(start);<br />

The CGsdpScheduler::TServerStart class is designed solely to allow the client thread<br />

to pass a TRequestStatus in such a way that it survives either the thread launch or the<br />

process launch above. This allows the server to signal success or failure back to the client.<br />

CGsdpScheduler::TServerStart wraps up a pointer to a TRequestStatus and a<br />

thread ID. This can then be passed on the command line to the new process using the<br />

AsCommand() method. Once in the new process, the TServerStart object can be<br />

reconstituted from the command line using the GetCommand() method. Here's the code for<br />

this:<br />

inline CGsdpScheduler::TServerStart::TServerStart() {};<br />

inline CGsdpScheduler::TServerStart::TServerStart(TRequestStatus&<br />

aStatus)<br />

:iId(RThread().Id()),iStatus(&aStatus)<br />

{aStatus=KRequestPending;}<br />

inline TPtrC CGsdpScheduler::TServerStart::AsCommand() const<br />

{return TPtrC(reinterpret_cast (this),<br />

sizeof(TServerStart)/sizeof(TText));}<br />

TInt CGsdpScheduler::TServerStart::GetCommand()<br />

{<br />

RProcess p;<br />

if (p.CommandLineLength()!=sizeof(TServerStart)/sizeof(TText))<br />

return KErrGeneral;<br />

TPtr ptr(reinterpret_cast(this),0,sizeof(TServerStart)/<br />

sizeof(TText));<br />

p.CommandLine(ptr);<br />

return KErrNone;<br />

}<br />

It's unusual for Symbian OS code to differ between the emulator and real Symbian OS<br />

phones. Server launch is one of the areas where the differences cut in. The design of the<br />

GSDP server minimizes those differences down to a couple of carefully controlled hotspots,<br />

which we've now dealt with.<br />

Server bootstrap<br />

Whether on the emulator or a real Symbian OS machine, execution in the newly launched<br />

server thread now begins in earnest with CGsdp-Scheduler::ThreadStart():<br />

EXPORT_C TInt CGsdpScheduler::ThreadStart(TServerStart& aStart)

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

Saved successfully!

Ooh no, something went wrong!