KIM introduction There are four main parts of the KIM backend interface. The Protocol classes, The Network classes, the Contact class and the XML classes.
- The Protocol classes - Decodes and encodes the protocol stream. It's tasks are:
- Take the raw input from the server and parse it. Then pass the the data to the frontend GUI.
- Encode requests made by the frontend into the format the server understand.
- The Network classes - The protocols does not deal directly with the system network interface it's is the job of the network classes. Each client needs a network class that implements the interface in class Network.
- The Contact class - Keeps track of ``contacts''. Each contact has a protocol and a state associated with it.
- XML - The KIM backend uses XML as a flexible way of storing data.XMLNode keeps all the info stored by an XML tag (everything between <tag> ... </tag> )
1. Writing a client
The normal way of using a protocol is by subclassing the protocol implementations. For example, if you wish to write a kit client, you would declare a class like this:
class myKitProtocol: public KitProtocol { myKitProtocol(XMLNode &configuration,Network *net): KitProtocol(n,net); void c_loggedIn(string proto); // any other c_ functions you are interested in (c_ is short for callback_) }the inheritance diagram for subclassing KitProtocol will be Protocol -> KitProtocol -> myKitProtocol. The parameters to the constructor are first an XMLNode where all the configuration information is stored (server ip, port, username and password) are specified here.
1.1. Network interfacing
Since the protocol code is completely network agnostic you need to create a class to do the acctual network interfacing. Network is another interface class that you need to subclass and implement for your client. This gives you full control over how to do event handling in your client. Also see the documentation for the Network class.
2. Writing a new protocol
Writing a new protocol is pretty simple, subclass Protocol and implement the action functions to perform the actions needed.
handleData() is called when there is data available, so once that function is called, parse it in a convenient way.
All network interfacing should be done through the m_network member - please be careful to keep the protocol code free of system dependancies.
When you want to send an event to the client, call the event* functions defined in Protocol.h. If you call them they'll automatically make sure the protocol can be used both with the protocol manager and with the callback functions (c_*) directly.
Alphabetic index Hierarchy of classes