O'Reilly logo

Practical VoIP Using VOCAL by Luan Dang, Cullen Jennings, David Kelly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required