Due to the difficulty of properly debugging real-time applications, as all those involving robotics sensors, it becomes more convenient to do development offline (on a dataset saved to disk) and, only when it seems all work fine, switch to the real thing.
The following example will show you how to do it in a way that doesn't affect your program structure: switching will be controlled by a simple bool variable.
Read here about the robotics dataset "rawlog" format and here about recording Kinect datasets.
See the entire example in: http://mrpt.googlecode.com/svn/trunk/samples/kinect_online_offline_demo/