00001
00002
00003
00004
00005
00006
00008 #include <cstring>
00009
00010 #include "JobControl/JobCPathHandler.h"
00011 #include "MessageService/MsgService.h"
00012 #include "JobControl/JobCommand.h"
00013 #include "JobControl/JobCPath.h"
00014 #include "JobControl/JobCNode.h"
00015
00016 CVSID("$Id: JobCPathHandler.cxx,v 1.4 2009/02/28 21:46:13 gmieg Exp $");
00017
00018
00019
00020 static void sorry(const char* method)
00021 {
00022 MSG("JobC",Msg::kWarning) <<
00023 "Sorry, method " << method << " not implemented." << endl;
00024 }
00025
00026
00027
00028 JobCPathHandler::JobCPathHandler() : fPath(0) { }
00029
00030
00031
00032 JobCPathHandler::JobCPathHandler(JobCPath* p) : fPath(p) { }
00033
00034
00035
00036 JobCPathHandler::~JobCPathHandler() { }
00037
00038
00039
00040 void JobCPathHandler::HandleCommand(JobCommand *cmd)
00041 {
00042
00043
00044
00045
00046
00047
00048
00049 const char *c = cmd->PopCmd();
00050 if (c) {
00051 if (strcmp(c,"Run")==0) {this->PathRunCommand (fPath, cmd); return;}
00052 if (strcmp(c,"Filter")==0) {this->PathFilterCommand(fPath, cmd); return;}
00053 if (strcmp(c,"Report")==0) {this->PathReportCommand(fPath, cmd); return;}
00054 if (strcmp(c,"Reset")==0) {this->PathResetCommand (fPath, cmd); return;}
00055 MSG("JobC", Msg::kWarning) <<
00056 "Unknown command '" << c << "'." <<
00057 " Try one of the following:\n" <<
00058 " Run,Filter,Report,Reset\n";
00059 }
00060 }
00061
00062
00063
00064 void JobCPathHandler::PathRunCommand(JobCPath *p, JobCommand *cmd)
00065 {
00066
00067
00068
00069
00070
00071
00072
00073 const char* c[2];
00074 int nopt = 0;
00075 while (cmd->HaveOpt() && nopt<2) {
00076 c[nopt] = cmd->PopOpt();
00077 ++nopt;
00078 }
00079
00080
00081 if (nopt == 0) {
00082 p->Run();
00083 return;
00084 }
00085
00086
00087 if (nopt == 1) {
00088 int n = atoi(c[0]);
00089 p->RunNin(n);
00090 return;
00091 }
00092
00093
00094 if (nopt == 2) {
00095 int n = atoi(c[1]);
00096 if (strcmp(c[0],"Nin")==0) { p->RunNin(n); return; }
00097 if (strcmp(c[0],"Npass")==0) { p->RunNpass(n); return; }
00098 if (strcmp(c[0],"Nfail")==0) { p->RunNfail(n); return; }
00099 }
00100
00101
00102 const char* nm = p->GetName();
00103 MSG("JobC", Msg::kWarning) <<
00104 "usage: \n"
00105 " " << nm << "/Run Nin [n] - run until n records have been input\n" <<
00106 " " << nm << "/Run Npass [n] - run until n records pass\n"
00107 " " << nm << "/Run Nfail [n] - run until n records fail\n"
00108 " " << nm << "/Run [n] - same as /Run Nin [n]\n";
00109 }
00110
00111
00112
00113 void JobCPathHandler::PathFilterCommand(JobCPath* p, JobCommand* cmd)
00114 {
00115
00116
00117
00118 while (cmd->HaveOpt()) {
00119 const char* node = cmd->PopOpt();
00120 const char* onOff = cmd->PopOpt();
00121 if (node == 0 || onOff == 0) {
00122 MSG("JobC",Msg::kWarning) <<
00123 "Usage: Filter <module>::<method> [on,reverse,off] ...\n" <<
00124 " Filter all [on,off]\n";
00125 return;
00126 }
00127
00128 string onOffs(onOff);
00129 string nodes(node);
00130 if (nodes == "ALL" || nodes == "all") {
00131 if (onOffs == "on" || onOffs == "ON") {
00132 p->SetAllFilters(true);
00133 return;
00134 }
00135 else if (onOffs == "reverse" || onOffs == "REVERSE") {
00136 p->ReverseAllFilters();
00137 return;
00138 }
00139 }
00140
00141
00142 string mod;
00143 string method;
00144 JobCommand::SplitLine(node,':',mod,method);
00145 JobCNode* nodep = p->FindNode(mod.c_str(), method.c_str());
00146 if (nodep == 0) {
00147 MSG("JobC",Msg::kWarning) <<
00148 "Can't find node " << mod << "::" << method << ". Skipped.\n";
00149 }
00150 else {
00151 if (onOffs == "on" || onOffs == "ON") {
00152 nodep->FilterOn();
00153 }
00154 else if (onOffs == "reverse" || onOffs == "REVERSE") {
00155 nodep->ReverseFilter();
00156 }
00157 else {
00158 nodep->FilterOff();
00159 }
00160 }
00161 }
00162 }
00163
00164
00165
00166 void JobCPathHandler::PathReportCommand(JobCPath* p, JobCommand* )
00167 {
00168
00169
00170
00171 MSG("JobC",Msg::kInfo) << (*p) << endl;
00172 }
00173
00174
00175
00176 void JobCPathHandler::PathResetCommand(JobCPath* ,
00177 JobCommand* )
00178 {
00179 sorry("PathResetCommand");
00180 }
00181