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

SDLDisplayTest.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 <SDLDisplayTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int usage()
00017 {
00018     printf("\n\n\tUsage:\n");
00019     printf("\t\t\t--help\t\t\tdisplay usage\n");
00020     printf("\t\t\t--test <value>\tsleep '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     SDLDisplay  display(320,240,"SDLDisplayTest");
00035     
00036     /* Utility class to ease the starting and stopping of displays, captures and
00037      * pipelines */
00038     phSystem    system;
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     /* startup */
00065     phPROGRESS("1.) Open & Close Test\n");
00066     
00067     rc = system.startup();
00068     phPRINT_RC(rc,NULL,"system.startup()");
00069     
00070     phMSleep(1000); /* 1 second */
00071     
00072     rc = system.shutdown();
00073     phPRINT_RC(rc,NULL,"system.shutdown()");
00074 
00075     
00076 
00077     /* 2.) Open and wait for user to close... test */
00078     phPROGRESS("2.) Open & Wait for user to close Test - try %d of %d\n",
00079              trycount, tries );
00080     
00081     /* Display startup */
00082     rc = system.startup();
00083     phPRINT_RC(rc,NULL,"system.startup()");
00084    
00085     while (displaysOpen)
00086     {
00087         /* Sleep a while, don't loop tightly */
00088 
00089         phMSleep(100);
00090         
00091         /* Yielding is optional. This gives up the thread's timeslice
00092          * to prevent slow response in other threads. It consumes more
00093          * CPU cycles than sleeping. Use it instead of sleeping if
00094          * this loop is processing anything */
00095         
00096         /* phYield(); */
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             /* test's value should be a time (in secs) value > 0*/
00122             phMSleep(test*1000);
00123         }
00124     }
00125 
00126     /* Display shutdown */
00127     rc = system.shutdown();
00128     phPRINT_RC(rc,NULL,"system.shutdown()");
00129 
00130 
00131 error:
00132     phDelete(arg_parser);
00133 
00134     return phSUCCESS;
00135 }




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:07 2007 for phission by  doxygen 1.4.4