Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

X11DisplayTest.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008     
00009     This file is part of Phission.
00010 
00011  ---------------------------------------------------------------------------*/
00012 #include <X11DisplayTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int usage()
00017 {
00018     printf("\n\nUsage:\n");
00019     printf("\t--help            Display usage\n");
00020     printf("\t--test <value>    Sleep <value> seconds and then close test\n");
00021     printf("\n\n");
00022 
00023     exit(1);
00024 }
00025 
00026 /* ------------------------------------------------------------------------ */
00027 int main(int argc, char *argv[] )
00028 {
00029     phFUNCTION("main")
00030 
00031     int         displaysOpen= 1;
00032     int         trycount = 1;
00033     int         tries = 4;
00034     /* Utility class to ease the starting and stopping of displays, captures and
00035      * pipelines */
00036     phSystem    system;
00037     
00038     X11Display  display(320,240,"X11DisplayTest");
00039    
00040     /* Remove the code below when using this code as an example.
00041      * 
00042      * This just checks whether "--test" has been specified with
00043      * a time value argument. It's for testing all the examples
00044      * without the need for human intervention. */
00045     int             test = 0;
00046 
00047     phArgTable      *arg_parser = new phArgTable();
00048 
00049     /* Setup and parse all the arguments */
00050     rc = arg_parser->add("--test",&test,phARG_INT);
00051     phCHECK_RC(rc,NULL,"arg_parser->add");
00052     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00053     phCHECK_RC(rc,NULL,"arg_parser->add");
00054     
00055     rc = arg_parser->parse(argc,argv);
00056     phCHECK_RC(rc,NULL,"arg_parser->parse");
00057 
00058 
00059     rc = system.addDisplay(&display);
00060     phPRINT_RC(rc,NULL,"system.addDisplay(&display)");
00061     
00062 
00063     /* 1.) Open and close test */
00064     phPROGRESS("1.) Open & Close Test\n");
00065     
00066     rc = system.startup();
00067     phPRINT_RC(rc,NULL,"system.startup()");
00068 
00069     phMSleep(1000);  /* 1 second */
00070     
00071     rc = system.shutdown();
00072     phPRINT_RC(rc,NULL,"system.shutdown()");
00073 
00074    
00075 
00076     /* 2.) Open and wait for user to close... test */
00077     phPROGRESS("2.) Open & Wait for user to close Test - try %d of %d\n",
00078              trycount, tries );
00079     
00080     /* Display startup */
00081     rc = system.startup();
00082     phPRINT_RC(rc,NULL,"system.startup()");
00083    
00084     while (displaysOpen)
00085     {
00086         /* Sleep a while, don't loop tightly */
00087 
00088         phMSleep(100);
00089         
00090         /* Yielding is optional. This gives up the thread's timeslice
00091          * to prevent slow response in other threads. It consumes more
00092          * CPU cycles than sleeping. Use it instead of sleeping if
00093          * this loop is processing anything */
00094         
00095         /* phYield(); */
00096         
00097         displaysOpen = 0;
00098         if (display.isOpen())
00099         {
00100             displaysOpen = 1;
00101         }
00102         
00103         /* Reopen the window X times */
00104         if ((displaysOpen == 0) && (trycount < tries))
00105         {
00106             rc = display.open();
00107             phPRINT_RC(rc,NULL,"display.open");
00108 
00109             displaysOpen = 1;
00110             trycount++;
00111             
00112             phPROGRESS("2.) Open & Wait for user to close Test - try %d of %d\n",
00113                      trycount, tries );
00114         }
00115         
00116         /* Remove this if block when using this code as an example */
00117         /* Set the loop control value to end the loop when testing */
00118         if (test > 0)
00119         { 
00120             displaysOpen = 0;
00121             phSleep(test); /* test's value should be a time (in secs) value > 0*/
00122         }
00123     }
00124 
00125     /* Display shutdown */
00126     rc = system.shutdown();
00127     phPRINT_RC(rc,NULL,"system.shutdown()");
00128 
00129 
00130 error:
00131     phDelete(arg_parser);
00132 
00133     return phSUCCESS;
00134 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:08 2007 for phission by  doxygen 1.4.4