00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
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