Symbian OS<br />Client-Server Framework<br />v2.0a – 29 April 2008<br />1<br />Andreas Jakl, 2008<br />
Disclaimer<br />These slides are provided free of charge at http://www.symbianresources.com and are used during Symbian OS...
Contents<br />Client-Server Framework<br />Architecture<br />Message Passing<br />Servers and Sessions<br />Andreas Jakl, ...
Client-Server Framework<br />Theory of the …<br />Andreas Jakl, 2008<br />4<br />
Client-Server Pattern<br />Client makes use of services provided by a server<br />Server:<br />Receives request messages f...
Client-Server Architecture<br />Most of the system services in Symbian OS are client-server-based<br />Examples:<br />Wind...
Advantages: Plugins<br />Extensibility: Plug-in modules for globally available new object types (e.g. new multimedia codec...
Advantages<br />Efficiency<br />Multiple clients use a single server<br />Security<br />Server/Client in different threads...
Structure – Example<br />Andreas Jakl, 2008<br />9<br />myApp.exe<br />Client<br />Links efsrv.lib, uses API-methods like:...
R-type Classes<br />For client-side implementation<br />R: Owns external Resource handle (e.g. handle to a server session)...
Examplecode<br />Andreas Jakl, 2008<br />11<br />// Establishconnectiontofile-server<br />RFsfs;<br />User::LeaveIfError(f...
Session<br />Session = Communication channel between client and server<br />Initiated by a client<br />Kernel creates serv...
Client-side Representation<br />Server is usually accessible through a public client class<br />Handles details of establi...
Communication<br />Andreas Jakl, 2008<br />14<br />Calls functions from the base class<br />Establishsession<br />Own, pri...
Communication<br />Send data between processes:<br />Message Passing: Used in all cases<br />Inter-process communication (...
Messages [1]<br />Clients send messages to servers<br />Each message is a request for a service<br />Server processes requ...
Messages [2]<br />Request message: Consists of five 32-bit numbers<br />Function number<br />Four 32-bit parameters<br />E...
MessagePassing<br />Andreas Jakl, 2008<br />18<br />Server<br />Client<br />four 32-bit parameters<br />x=RXxxSession::Foo...
Inter-ProcessCommunication<br />Andreas Jakl, 2008<br />19<br />Server<br />Client<br />y=RXxxSession::Bar(a,b,c)<br />bar...
Request-Handling<br />Andreas Jakl, 2008<br />20<br />“2” – Symbian OS 9: Capability-Support<br />Client<br />Server<br />...
Server Lifetime<br />Three options:<br />System Server: Started with the mobile phone, essential for the OS (e.g. File Ser...
Server Lifetime<br />Andreas Jakl, 2008<br />22<br />System<br />System server<br />connect<br />disconnect<br />Applicati...
Processes & Servers<br />23<br />Same-processservers<br />Privilegedcode<br />Fixedprocesses<br />ekern.exe(privileged)Ker...
Sessions<br />Andreas Jakl, 2008<br />24<br />Server thread<br />Server can serve multiple clients<br />A client can have ...
Subsessions<br />Solution: SubSessions<br />e.g. File Server: One Session per Client (RFs), multiple files represent SubSe...
API Example<br />Andreas Jakl, 2008<br />26<br />class RFs : public RSessionBase {...}<br />class RFsBase : public RSubSes...
Examplecode (Revisited)<br />Andreas Jakl, 2008<br />27<br />// Establishconnectiontofile-server<br />RFsfs;<br />User::Le...
Performance<br />Communication:<br />Overhead through thread / process context switches<br />Inter-process data transfer r...
Is a Server Required?<br />Need to share functionality or resources across a number of threads or processes?<br />Require ...
ASD-like Question – Easy <br />Which of the following statements correctly describe the client-server model in Symbian OS?...
Solution<br />A.	Correct. <br />B.	Incorrect. Most servers are executed in an own process, but it is not required. <br />C...
ASD-like Question – Medium<br />For which of the following scenarios would a developer choose to implement a client and se...
Solution<br />A.	Incorrect. The performance overhead would be too high. <br />B.	Correct. <br />C.Correct.<br />D.	Incorre...
Thanks for your attention<br />That’s it!<br />Andreas Jakl, 2008<br />34<br />
Upcoming SlideShare
Loading in...5
×

Symbian OS - Client Server Framework

2,959

Published on

Many system APIs communicate with applications through the client-server framework. This tutorial gives you a theoretical explanation of the concepts behind it.

Contents

* Client-Server Framework
* Architecture
* Message Passing
* Servers and Sessions

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,959
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Symbian OS - Client Server Framework

  1. 1. Symbian OS<br />Client-Server Framework<br />v2.0a – 29 April 2008<br />1<br />Andreas Jakl, 2008<br />
  2. 2. Disclaimer<br />These slides are provided free of charge at http://www.symbianresources.com and are used during Symbian OS courses at the University of Applied Sciences in Hagenberg, Austria ( http://www.fh-hagenberg.at/ )<br />Respecting the copyright laws, you are allowed to use them:<br />for your own, personal, non-commercial use<br />in the academic environment<br />In all other cases (e.g. for commercial training), please contact andreas.jakl@fh-hagenberg.at<br />The correctness of the contents of these materials cannot be guaranteed. Andreas Jakl is not liable for incorrect information or damage that may arise from using the materials.<br />Parts of these materials are based on information from Symbian Press-books published by John Wiley & Sons, Ltd. This document contains copyright materials which are proprietary to Symbian, UIQ, Nokia and SonyEricsson. “S60™” is a trademark of Nokia. “UIQ™” is a trademark of UIQ Technology. Pictures of mobile phones or applications are copyright their respective manufacturers / developers. “Symbian ™”, “Symbian OS ™” and all other Symbian-based marks and logos are trademarks of Symbian Software Limited and are used under license. © Symbian Software Limited 2006. <br />Andreas Jakl, 2008<br />2<br />
  3. 3. Contents<br />Client-Server Framework<br />Architecture<br />Message Passing<br />Servers and Sessions<br />Andreas Jakl, 2008<br />3<br />Colour coding used in these slides:<br />Client<br />Server<br />Kernel<br />
  4. 4. Client-Server Framework<br />Theory of the …<br />Andreas Jakl, 2008<br />4<br />
  5. 5. Client-Server Pattern<br />Client makes use of services provided by a server<br />Server:<br />Receives request messages from its clients<br />Handles requests (synchronously or asynchronously)<br />Andreas Jakl, 2008<br />5<br />Client<br />Server<br />Messages<br />
  6. 6. Client-Server Architecture<br />Most of the system services in Symbian OS are client-server-based<br />Examples:<br />Window Server (UI, keypad)<br />File Server<br />Socket Server<br />Telephony Server<br />Andreas Jakl, 2008<br />6<br />
  7. 7. Advantages: Plugins<br />Extensibility: Plug-in modules for globally available new object types (e.g. new multimedia codecs, …)<br />Andreas Jakl, 2008<br />7<br />File Server<br />Local file system<br />Flash filing system<br />Sockets Server<br />Infrared protocols<br />TCP/IP<br />SMS<br />
  8. 8. Advantages<br />Efficiency<br />Multiple clients use a single server<br />Security<br />Server/Client in different threads (usually also different processes).<br />Communication through messages client can not “crash” server<br />Asynchronous<br />Server uses Active Objects for return messages. No polling needed  good for our battery!<br />Andreas Jakl, 2008<br />8<br />
  9. 9. Structure – Example<br />Andreas Jakl, 2008<br />9<br />myApp.exe<br />Client<br />Links efsrv.lib, uses API-methods like:RFs::Connect()<br />Client-sideFile Server implementation<br />efsrv.dll<br />Client-Servercommunication (via Kernel)<br />Process Boundary<br />efile.exe<br />File Server<br />
  10. 10. R-type Classes<br />For client-side implementation<br />R: Owns external Resource handle (e.g. handle to a server session)<br />Resource allocation: usually Open(), Create() or Initialize()<br />Deallocation: usually Close() or Reset()<br />The destructor doesn’t do it – most of the times, there is no destructor<br />App. should release the resource as soon as possible<br />Can be instantiated on the stack (automatic variable) or on the heap (instance variable)<br />Andreas Jakl, 2008<br />10<br />
  11. 11. Examplecode<br />Andreas Jakl, 2008<br />11<br />// Establishconnectiontofile-server<br />RFsfs;<br />User::LeaveIfError(fs.Connect());CleanupClosePushL(fs);<br />// Submit a requesttotheserver<br />_LIT(KIniFile, „c:yini.ini“);<br />User::LeaveIfError(fs.Delete(KIniFile));<br />// Create a subsession<br />RFilefile;<br />User::LeaveIfError(file.Create(fs, KIniFile, EFileRead | EFileWrite |EFileShareExclusive));<br />CleanupClosePushL(file);<br />// Submit a requestusingthesubsession<br />TBuf8&lt;32&gt; buf;<br />User::LeaveIfError(file.Read(buf));<br />// Cleanup<br />CleanupStack::PopAndDestroy(2, &fs); // file, fs<br />Whendeleting: closeconnection to theserver (call Close())<br />WrapperforRSubSessionBase::SendReceive()<br />
  12. 12. Session<br />Session = Communication channel between client and server<br />Initiated by a client<br />Kernel creates server-side representation<br />Messages between client / server mediated by kernel<br />Only onesynchronous request may be submitted at a time<br />... but multipleasynchronous requests may be outstanding<br />Andreas Jakl, 2008<br />12<br />
  13. 13. Client-side Representation<br />Server is usually accessible through a public client class<br />Handles details of establishing a session with its server<br />Sends commands to the server<br />Handles receiving responses<br />Derives from RSessionBase<br /> Hides implementation details of the private client-server communication protocol<br />Example:<br />Simple functions RFs::Delete() or RFs::GetDir() communicate with the file server and hide the more complex client-server communication protocol<br />Andreas Jakl, 2008<br />13<br />
  14. 14. Communication<br />Andreas Jakl, 2008<br />14<br />Calls functions from the base class<br />Establishsession<br />Own, privateprotocol<br />Disconnect<br />
  15. 15. Communication<br />Send data between processes:<br />Message Passing: Used in all cases<br />Inter-process communication (IPC): For large data packets, if needed<br />Andreas Jakl, 2008<br />15<br />Kernel<br />Client<br />Server<br />Process Boundary<br />
  16. 16. Messages [1]<br />Clients send messages to servers<br />Each message is a request for a service<br />Server processes request<br />Performs work on behalf of the client<br />Optionally sends a reply to the client<br />Messages can be sent:<br />synchronously, or<br />asynchronously<br />Andreas Jakl, 2008<br />16<br />
  17. 17. Messages [2]<br />Request message: Consists of five 32-bit numbers<br />Function number<br />Four 32-bit parameters<br />Each of the four parameters can be:<br />An integer (TInt)<br />A pointer to a flat data structure, wrapped as a Symbian OS descriptor ( read using IPC)<br />Andreas Jakl, 2008<br />17<br />
  18. 18. MessagePassing<br />Andreas Jakl, 2008<br />18<br />Server<br />Client<br />four 32-bit parameters<br />x=RXxxSession::Foo(a,b,c)<br />foo<br />a<br />b<br />c<br />-<br />ServiceL(RMessage2 aMessage)<br />Server processes the request...<br />aMessage.Complete(x)<br />x<br />
  19. 19. Inter-ProcessCommunication<br />Andreas Jakl, 2008<br />19<br />Server<br />Client<br />y=RXxxSession::Bar(a,b,c)<br />bar<br />p<br />&q<br />&r<br />-<br />ServiceL(RMessage1 aMessage)<br />q<br />aMessage.ReadL()<br />r<br />aMessage.WriteL()<br />aMessage.Complete(y)<br />y<br />
  20. 20. Request-Handling<br />Andreas Jakl, 2008<br />20<br />“2” – Symbian OS 9: Capability-Support<br />Client<br />Server<br />RSessionBaseSendReceive()<br />Functions for the client, converts requests to parameters<br />CSession2ServiceL()<br />Handling of requests, represents session server-side<br />CServer2 (Active Obj)RunL()<br />Receives requests, forward to corresponding session<br />RMessage2Complete()<br />For client/server data transfer<br />DSessionLinks Client/Server, Cleanup<br />Kernel<br />
  21. 21. Server Lifetime<br />Three options:<br />System Server: Started with the mobile phone, essential for the OS (e.g. File Server, Window Server). Unexpected termination usually forces phone reboot.<br />Application / Transient Server: Started on request of an application, closed when last client disconnects.If a second client starts a new server, no error is produced, existing server instance is used.<br />Other Servers: Started and closed with an individual application. If used by multiple applications: each app. has its own private instance; e.g. POSIX server.<br />Andreas Jakl, 2008<br />21<br />
  22. 22. Server Lifetime<br />Andreas Jakl, 2008<br />22<br />System<br />System server<br />connect<br />disconnect<br />Application 1<br />connect<br />disconnect<br />App. server<br />connect<br />disconnect<br />Application 2<br />Other server<br />
  23. 23. Processes & Servers<br />23<br />Same-processservers<br />Privilegedcode<br />Fixedprocesses<br />ekern.exe(privileged)Kernelserver<br />efsrv.exe(fixed)File server<br />ewsrv.exe(fixed)Windowserver<br />fbsrv.exe(fixed)Font & bitmapserver<br />c32exe.exe(fixed)Comms, Sockets, Telephonyservers<br />app1.exe<br />Application<br />xxx.exe…server<br />edbsrv.exeDBMS server<br />app2.exe<br />Application<br />app3.exe<br />Application<br />Private server<br />Ordinaryapplications<br />Ordinaryservers<br />Private server<br />Andreas Jakl, 2008<br />
  24. 24. Sessions<br />Andreas Jakl, 2008<br />24<br />Server thread<br />Server can serve multiple clients<br />A client can have multiple sessions with a server<br />Each session requires resources <br />Server<br />CServer2<br />Server side session<br />CSession2<br />Server side session<br />CSession2<br />Server side session<br />CSession2<br />Client side session<br />RSessionBase<br />Client side session<br />RSessionBase<br />Client side session<br />RSessionBase<br />Client 1 (thread)<br />Client 2 (thread)<br />
  25. 25. Subsessions<br />Solution: SubSessions<br />e.g. File Server: One Session per Client (RFs), multiple files represent SubSessions (RFile)<br /> no new session for every single file!<br />Andreas Jakl, 2008<br />25<br />Server thread<br />Server<br />CServer2<br />Server side session<br />CSession2<br />Client side session<br />RSessionBase<br />Subsession<br />RSubSessionBase<br />Subsession<br />RSubSessionBase<br />Client (thread)<br />
  26. 26. API Example<br />Andreas Jakl, 2008<br />26<br />class RFs : public RSessionBase {...}<br />class RFsBase : public RSubSessionBase {...}<br />class RFile : public RFsBase<br />{<br />public:<br />IMPORT_C TInt Open(RFs& aFs, const TDesC& aName, TUintaFileMode);<br />IMPORT_C TInt Read(TDes8& aDes) const;<br />IMPORT_C void Read(TDes8& aDes, TRequestStatus& aStatus) const;<br />IMPORT_C TInt Write(const TDesC8& aDes);<br />IMPORT_C void Write(const TDesC8& aDes, TRequestStatus& aStatus);<br />[...]<br />};<br />
  27. 27. Examplecode (Revisited)<br />Andreas Jakl, 2008<br />27<br />// Establishconnectiontofile-server<br />RFsfs;<br />User::LeaveIfError(fs.Connect());CleanupClosePushL(fs);<br />// Submit a requesttotheserver<br />_LIT(KIniFile, „c:yini.ini“);<br />User::LeaveIfError(fs.Delete(KIniFile));<br />// Create a subsession<br />RFilefile;<br />User::LeaveIfError(file.Create(fs, KIniFile, EFileRead | EFileWrite |EFileShareExclusive));<br />CleanupClosePushL(file);<br />// Submit a requestusingthesubsession<br />TBuf8&lt;32&gt; buf;<br />User::LeaveIfError(file.Read(buf));<br />// Cleanup<br />CleanupStack::PopAndDestroy(2, &fs); // file, fs<br />Whendeleting: closeconnection to theserver (call Close())<br />WrapperforRSubSessionBase::SendReceive()<br />
  28. 28. Performance<br />Communication:<br />Overhead through thread / process context switches<br />Inter-process data transfer requires mapping client data area to server’s virtual address space<br />Best practice:<br />Transfer a large amount of data in a single transaction instead of performing a number of server accesses<br />Example: Most Symbian OS components don’t use RFile::Read() / Write() directly, but instead use buffered streams (RReadStream() / RWriteStream())<br />Andreas Jakl, 2008<br />28<br />
  29. 29. Is a Server Required?<br />Need to share functionality or resources across a number of threads or processes?<br />Require isolation between service provider and service user?<br />Pre-emptive asynchronous processing desirable?<br />Gains outweigh costs?<br />Andreas Jakl, 2008<br />29<br />
  30. 30. ASD-like Question – Easy <br />Which of the following statements correctly describe the client-server model in Symbian OS?<br />A. A client and server always execute in separate threads.<br />B. A client and server always execute in separate processes.<br />C. A client initiates a server request by passing an integer to identify the request. It then sends any “payload” data separately.<br />D. To return data to a client, the server writes directly into the client’s address space.<br />E. At any time, there can only be one outstanding synchronous client request to a server.<br />Andreas Jakl, 2008<br />30<br />Copyright Meme Education, 2006<br />http://www.meme-education.com/<br />
  31. 31. Solution<br />A. Correct. <br />B. Incorrect. Most servers are executed in an own process, but it is not required. <br />C.Incorrect. The data is sent together with the function request as a parameter.<br />D. Incorrect. The return values are sent using a message object.<br />E. Correct. <br />Andreas Jakl, 2008<br />31<br />
  32. 32. ASD-like Question – Medium<br />For which of the following scenarios would a developer choose to implement a client and server on Symbian OS?<br />A. To provide utility code, such as a 3D graphics library.<br />B. To implement a system-wide “broadcast” notification system.<br />C. To manage access to a hardware resource, such as the camera.<br />D. To implement a Bluetooth game where the host player runs as a server and all other players are clients.<br />E. To implement a user interface application for displaying weather information.<br />Andreas Jakl, 2008<br />32<br />Copyright Meme Education, 2006<br />http://www.meme-education.com/<br />
  33. 33. Solution<br />A. Incorrect. The performance overhead would be too high. <br />B. Correct. <br />C.Correct.<br />D. Incorrect. This has nothing to do with the client/server communication within Symbian OS.<br />E. Incorrect. UI and application logic should be separated, but rather by using DLLs instead of implementing client/server communication.<br />Andreas Jakl, 2008<br />33<br />
  34. 34. Thanks for your attention<br />That’s it!<br />Andreas Jakl, 2008<br />34<br />

×