In this section, we describe one way to start VR Juggler. We
will use the traditional main() function in C++,
but this is not the only way to do it. We have written Python
applications that start the VR Juggler kernel, and it is possible to
write a VR Juggler daemon that loads applications on
demand at runtime. In other words, the VR Juggler startup procedure is
quite flexible, and we choose to focus on the simplest method
here.
Previously, we explained how VR Juggler applications do not
have a main() function, but further explanation
is required. While it is true that user
applications do not have a
main() function because they are objects, there
must still be a main() somewhere that starts
the system. This is because the operating system uses
main() as the starting point for all
applications. In typical VR Juggler applications, there is a
main(), but it only starts the VR Juggler
kernel and gives the kernel the application to run. It then waits
for the kernel to shut down before exiting.
The following is a typical example of a
main() function that will start the VR Juggler
kernel and hand it an instance of a user application object. The
specifics of what is happening in this code are described
below.
1 #include <vrj/Kernel/Kernel.h>
#include <simpleApp.h>
int main(int argc, char* argv[])
5 {
vrj::Kernel* kernel = vrj::Kernel::instance(); // Get the kernel
simpleApp* app = new simpleApp(); // Create the app object
kernel->loadConfigFile(...); // Configure the kernel
10 kernel->start(); // Start the kernel thread
kernel->setApplication(app); // Give application to kernel
kernel->waitForKernelStop(); // Block until kernel stops
return 0;
15 }![]() | This line finds (and may create) the VR Juggler kernel. The kernel reference is stored in the handle so that we can use it later. |
![]() | We instantiate a copy of the user application object
( |
![]() | This statement represents the code that will be in the
|
![]() | As a result of this statement, the VR Juggler kernel begins running. It creates a new thread of execution for the kernel, and the kernel begins its internal processing. From this point on, any changes made reconfigure the kernel. These changes can come in the form of more configuration files or in the form of an application object to execute. At this point, it is important to notice that the kernel knows nothing about the application. Moreover, there is no need for it to know about configuration files yet. This demonstrates how the VR Juggler kernel executes independently from the user application. The kernel will simply work on its own controlling and configuring the system even without an application to run. |
![]() | This statement finally tells the kernel what application it should run. The method call reconfigures the kernel so that it will now start invoking the application object's member functions. It is at this time that the application is now running in the VR system. |