The two modules that I have to implement for the pjsip project are almost done. They are in this state since last month, but I did not have time to post an entry about them.
Presence Server (implemented by Cătălina) knows how to communicate using pjsip library. The manager does not use this library and is platform dependent. Thus, for modularization, it was necessary to implement a Presence Client that links the two modules.
The Presence Client has two threads running simultaneously: one to communicate with the manager and one to communicate with the Presence Server. Synchronization between the two threads is achieved using a semaphore.
The Presence Server and Presence Client use pjsip architecture for communication.
The following diagram shows how SIP messages are passed back and forth among pjsip components:

At the heart of the SIP stack is the SIP endpoint, which is represented by opaque data type pjsip_endpoint. The endpoint responsibilities are:
- a pool factory, to allocate pools for all SIP components (this is pretty cool, actually you don’t have to worry about memory allocation)
- the transport manager instance which has SIP transports and controls message printing and parsing
- to manage pjsip modules
- to receive incoming SIP messages from transport manager and to distribute the message to modules.
Here, the endpoint manages only one module responsible for the communication between the Presence Server and the Presence Client.
The client does not need to check when receiving a message if the type is SIP because the transport manager handles it.
The Manager is a server.
Thus, the Presence Client connects to the Manager and sends an XML message like:
<xml>
<type> PC </type>
…
</xml>
Modules communicate with each other only through XML formatted messages. Thus, it is much easier to extract the necessary information from the message.
The connection with the manager is one of the two threads that runs within the Presence Client. As I said before, the second thread is used for the connection with the Presence Server.
When the Presence Client receives a message from the Manager, it puts it in a circular buffer. As long as the buffer is not empty, it takes the messages and sends a PUBLISH message to the Presence Server.
In the next post I will discuss about how I have decided to implement the Manager module. Sources are kept in a private svn, but I will post them when the whole project will be ready.