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

Consumer.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 <phNodeControllerClient.h>
00013 
00014 /* -------------------------------------------------------------------------- */
00015 /* usage: Print out all the usage switches available. */
00016 /* -------------------------------------------------------------------------- */
00017 void usage()
00018 {
00019     printf("\n\nUsage:\n\t./client <options>\n\toptions:\n");
00020     printf("\t--host <host> : Define the NC host\n");
00021     printf("\t--port <port> : Define the NC client port\n");
00022     printf("\n");
00023     fflush(stdout);
00024     exit(1);
00025 }
00026 
00027 /* -------------------------------------------------------------------------- *
00028  * main: The client's main processing block. 
00029  * -------------------------------------------------------------------------- */
00030 int main( int argc, char *argv[] )
00031 {
00032     phFUNCTION("main::client")
00033 
00034     int count = 0;
00035     int limit = 0;
00036 
00037     char    *host   = NULL;
00038     int     port    = 80;
00039     
00040     int verbose = 0;
00041 
00042     phNodeControllerClient *node_controller = NULL;
00043     
00044     phArgTable      *arg_parser = new phArgTable();
00045     
00046     /* Setup and parse all the arguments */
00047     /* phARG_CHAR, phARG_INT, phARG_UINT, phARG_LONG,
00048      * phARG_ULONG, phARG_BOOL, phARG_FUNC */
00049     rc = arg_parser->add("--host",&host,phARG_CHAR);
00050     phCHECK_RC(rc,NULL,"arg_parser->add");
00051     
00052     rc = arg_parser->add("--port",&port,phARG_INT);
00053     phCHECK_RC(rc,NULL,"arg_parser->add");
00054 
00055     rc = arg_parser->add("--help",(void*)&usage,phARG_FUNC);
00056     phCHECK_RC(rc,NULL,"arg_parser->add");
00057 
00058     rc = arg_parser->parse(argc,argv);
00059     phCHECK_RC(rc,NULL,"arg_parser->parse");
00060   
00061     /* Check the arguments */
00062     /* Check to make sure a host was specified */
00063     if (host == NULL)
00064     {
00065         printf("Error: Hostname must be specified\n");
00066         usage();
00067     }
00068 
00069     /* Check to make sure the port is valid */
00070     if ((port <= 0) || (port >= 65535))
00071     {
00072         printf("Error: Port value is invalid - valid values (1,65535)\n");
00073         usage();
00074     }
00075 
00076     /* Print out the progress of the client */
00077     if (verbose)
00078         printf("Attempting to connect to %s on port %d\n",
00079                 host, port );
00080    
00081     node_controller = new phNodeControllerClient(host,port);
00082     
00083     rc = node_controller->connect();
00084     phCHECK_RC(rc,NULL,"node_controller->connect failed.");
00085     
00086     if (verbose)
00087         printf("Connected...\n");
00088    
00089     while ((node_controller->isConnected()) && (limit < 10))
00090     {
00091         rc = node_controller->request(count % 4);
00092         phPRINT_RC(rc,NULL,"request(%d)",count % 4);
00093   
00094         /* phThread::mSleep(1000); */
00095         
00096         rc = node_controller->release(count % 4);
00097         phPRINT_RC(rc,NULL,"release(%d)",count % 4);
00098         
00099         //count++;
00100         limit++;
00101         /* main loop */
00102         phYield();
00103         phYield();
00104         phYield();
00105     }    
00106     
00107     phDelete(node_controller);
00108     phFree(host);
00109     
00110     phPROGRESS("Finished Successfully.\n");
00111     
00112     return phSUCCESS;    
00113 
00114     /* Error return path */
00115 error:
00116     phPROGRESS("Finished w/Failure.\n");
00117     phDelete(node_controller);
00118     phFree(host);
00119     
00120     phDelete(arg_parser);
00121 
00122     return phFAIL;
00123 }




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