interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/apps/tutorials/vostut1.cc

Go to the documentation of this file.
00001 /* First VOS tutorial.  The simplest possible program that uses VOS.
00002 
00003    This tutorial covers:
00004    - Creating a site for the application to use
00005    - Extending a site to communication over the network
00006 
00007    This file (vostut1.cc) is released into the public domain.  No
00008    restrictions are placed on its use, distribution or inclusion into
00009    other works.
00010 */
00011 
00012 /* This header brings in all the declarations needed to use the core
00013    VOS library. */
00014 
00015 #include <vos/vos/vos.hh>
00016 
00017 // All VOS stuff is located in the VOS namespace
00018 using namespace VUtil;
00019 using namespace VOS;
00020 
00021 // Windows has "_sleep" instead of "sleep" so fix that here
00022 #ifdef WIN32
00023 #define sleep _sleep
00024 #endif
00025 
00026 int main(int argc, char** argv)
00027 {
00028     std::cout << "VOS Tutorial 1\n\n";
00029 
00030     /* A "site" is a required part of any VOS application, and is
00031        usually the first thing you create.  The purpose of the site is
00032        to store your objects and act as the point of communication
00033        representing this application to other sites on the network.
00034     */
00035     std::cout << "Creating site\n";
00036     Site localsite;
00037 
00038     /* By adding various extensions to our site we can give it various
00039        useful capabilities.  One of the most common extensions is the
00040        socket extension; this provides the site with functionality to
00041        communicate with other sites, using the "VIP" protocol.
00042      */
00043     std::cout << "Adding site extension\n";
00044     localsite.addSiteExtension(new LocalVipSiteExtension());
00045 
00046     /* VOS is a multithreaded library.  When we extended the site to
00047        support sockets, background threads were created to handle
00048        incoming connections and messages.  Thus the main thread is
00049        free to do whatever it likes.  This ends the first tutorial, so
00050        we'll just leave it in an idle loop, humming quietly.
00051      */
00052     std::cout << "Going into idle loop...\n";
00053     while(true) sleep(1000);
00054 }