Chapter 9. Base Code

Most VOCAL components execute state machines, which share a common base code: a common framework that we wrote to help ensure some design consistency between several different server types including the Marshal, Redirect, and CPL Feature servers. This chapter looks at how we implemented the base state machine and the different types of classes found within the base code. As this code is widely used within VOCAL, it is important for you to understand how it has been written if you intend to modify any of the other processes.

State Machine

The general model of this state machine provides a class for each state. The constructor for each of these classes lists a series of operators that are instantiated at the same time the state class is instantiated. Each of these operators has been written as a separate class, and the events are defined in a general event class. For example, all the events that drive the state machine for the SIP User Agent are defined within vocal-1.3.0/sip/ua/DeviceEvent.hxx.

When a thread sends an event to a state machine, it passes the event to the current state and then to each operator that is listed within the constructor for that state. Each operator contains code that enables it to work with some events and to ignore all others. If the event is one that it is designed to handle, the operator executes and returns a definition of the next state for the state machine to transform itself into. This makes the state machine move to its next ...

Get Practical VoIP Using VOCAL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.