RA - Client/Server Request-Action

From LinuxMCE
Revision as of 17:43, 5 June 2006 by Wikiadmin (Talk | contribs) (Imported document)

(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search
This page was written by Pluto and imported with their permission when LinuxMCE branched off in February, 2007. In general any information should apply to LinuxMCE. However, this page should be edited to reflect changes to LinuxMCE and remove old references to Pluto.

How does it work?

The client creates "Requests" which it sends to the server. The server will process the request, set some return variables, and can optionally add "Actions" it wants the client to execute in response. An example is a cashier's computer (the client) sends the central credit card processing server a request to "process a credit card", the server responds with the authorization code and also includes an action "give customer a message" which causes a message to appear on the cashier's computer.

Both the client and server use the same library. Both create an instance of RA_Processor. The only difference is the server calls "ReceiveRequest" and the client creates the actual requests, and calls RA_Processor's "SendRequest".

To create a request, just create a class derived from RA_Request. Add some member variables for the request and variables for the response. Your request must be derived from SerializeClass--a base class that facilitates taking an object (a request in this case), serializing the variables into a binary block, and then on the other end reconstructing the class with all the data. The framework handles everything. You just add the data members.

In the above example, the request variables would probably be the credit card information and maybe the customer ID, and the response variables would be the authorization code. RA_Request has a pure virtual function "ProcessRequest" which will be called on the server to handle the request. Both the client and the server have the same Request/Action classes. When the client side passes a request to the RequestProcessor, the framework handles serializing all the request member variables, making the socket connection to the server and sending the request to the server. On the server, the framework will create an instance of the request class and deserialize all the data and call the "ProcessRequest" member function. That is the only function the server needs to implement. From within ProcessRequest, the server needs to set the response variables. When ProcessRequest returns, the framework will serialize the response variables, send them back to the client, update the client's original request with the response, and execution will continue. Less than 10 lines of code are required to make it work, and the project includes a sample client/server application you can extend. See the Programmer's Guide for details.