diffapp.cc

Go to the documentation of this file.
00001 //
00002 // diffapp.cc     : Base Class for Diffusion Apps and Filters
00003 // author         : Fabio Silva and Padma Haldar
00004 //
00005 // Copyright (C) 2000-2002 by the University of Southern California
00006 // $Id: diffapp.cc,v 1.11 2005/09/13 04:53:49 tomh Exp $
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License,
00010 // version 2, as published by the Free Software Foundation.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License along
00018 // with this program; if not, write to the Free Software Foundation, Inc.,
00019 // 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020 //
00021 // Linking this file statically or dynamically with other modules is making
00022 // a combined work based on this file.  Thus, the terms and conditions of
00023 // the GNU General Public License cover the whole combination.
00024 //
00025 // In addition, as a special exception, the copyright holders of this file
00026 // give you permission to combine this file with free software programs or
00027 // libraries that are released under the GNU LGPL and with code included in
00028 // the standard release of ns-2 under the Apache 2.0 license or under
00029 // otherwise-compatible licenses with advertising requirements (or modified
00030 // versions of such code, with unchanged license).  You may copy and
00031 // distribute such a system following the terms of the GNU GPL for this
00032 // file and the licenses of the other code concerned, provided that you
00033 // include the source code of that other code when and as the GNU GPL
00034 // requires distribution of source code.
00035 //
00036 // Note that people who make modified versions of this file are not
00037 // obligated to grant this special exception for their modified versions;
00038 // it is their choice whether to do so.  The GNU General Public License
00039 // gives permission to release a modified version without this exception;
00040 // this exception also makes it possible to release a modified version
00041 // which carries forward this exception.
00042 //
00043 
00044 #include "diffapp.hh"
00045 
00046 #ifdef NS_DIFFUSION
00047 int DiffApp::command(int argc, const char*const* argv) {
00048   if (argc == 2) {
00049     if (strcmp(argv[1], "start") == 0) {
00050       start();
00051       return TCL_OK;
00052     }
00053   }
00054   if (argc == 3) {
00055     if (strcmp(argv[1], "dr") == 0) {
00056       DiffAppAgent *agent;
00057       agent = (DiffAppAgent *)TclObject::lookup(argv[2]);
00058       dr_ = agent->dr();
00059       return TCL_OK;
00060     }
00061   }
00062   return Application::command(argc, argv);
00063 }
00064 
00065 #else
00066 void DiffApp::usage(char *s){
00067   DiffPrint(DEBUG_ALWAYS, "Usage: %s [-d debug] [-p port] [-f file] [-h]\n\n", s);
00068   DiffPrint(DEBUG_ALWAYS, "\t-d - Sets debug level (0-10)\n");
00069   DiffPrint(DEBUG_ALWAYS, "\t-p - Uses port 'port' to talk to diffusion\n");
00070   DiffPrint(DEBUG_ALWAYS, "\t-f - Specifies a config file\n");
00071   DiffPrint(DEBUG_ALWAYS, "\t-h - Prints this information\n");
00072   DiffPrint(DEBUG_ALWAYS, "\n");
00073   exit(0);
00074 }
00075 
00076 void DiffApp::parseCommandLine(int argc, char **argv)
00077 {
00078   u_int16_t diff_port = DEFAULT_DIFFUSION_PORT;
00079   int debug_level;
00080   int opt;
00081 
00082   config_file_ = NULL;
00083   opterr = 0;
00084 
00085   while (1){
00086     opt = getopt(argc, argv, "f:hd:p:");
00087     switch (opt){
00088 
00089     case 'p':
00090 
00091       diff_port = (u_int16_t) atoi(optarg);
00092       if ((diff_port < 1024) || (diff_port >= 65535)){
00093     DiffPrint(DEBUG_ALWAYS, "Error: Diffusion port must be between 1024 and 65535 !\n");
00094     exit(-1);
00095       }
00096 
00097       break;
00098 
00099     case 'h':
00100 
00101       usage(argv[0]);
00102 
00103       break;
00104 
00105     case 'd':
00106 
00107       debug_level = atoi(optarg);
00108 
00109       if (debug_level < 1 || debug_level > 10){
00110     DiffPrint(DEBUG_ALWAYS, "Error: Debug level outside range or missing !\n");
00111     usage(argv[0]);
00112       }
00113 
00114       global_debug_level = debug_level;
00115 
00116       break;
00117 
00118     case 'f':
00119 
00120       if (!strncasecmp(optarg, "-", 1)){
00121     DiffPrint(DEBUG_ALWAYS, "Error: Parameter missing !\n");
00122     usage(argv[0]);
00123       }
00124 
00125       config_file_ = strdup(optarg);
00126 
00127       break;
00128 
00129     case '?':
00130 
00131       DiffPrint(DEBUG_ALWAYS,
00132         "Error: %c isn't a valid option or its parameter is missing !\n", optopt);
00133       usage(argv[0]);
00134 
00135       break;
00136 
00137     case ':':
00138 
00139       DiffPrint(DEBUG_ALWAYS, "Parameter missing !\n");
00140       usage(argv[0]);
00141 
00142       break;
00143 
00144     }
00145 
00146     if (opt == -1)
00147       break;
00148   }
00149 
00150   diffusion_port_ = diff_port;
00151 }
00152 
00153 #endif // NS_DIFFUSION

Generated on Tue Mar 6 16:47:44 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6