const char* for command

This commit is contained in:
Erik Frojdh
2019-05-16 16:58:03 +02:00
parent 1943e77b24
commit fff79fbbb6
5 changed files with 243 additions and 232 deletions

View File

@ -29,14 +29,14 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
* @param action can be PUT_ACTION or GET_ACTION(from text client even READOUT_ACTION for acquisition)
* @param detPos -1 for all detectors in multi detector list or position of a specific detector in list
*/
std::string executeLine(int narg, char *args[], int action, int detPos = -1);
std::string executeLine(int narg, const char * const args[], int action, int detPos = -1);
/* /\** */
/* returns the help for the executeLine command */
/* \param os output stream to return the help to */
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
/* *\/ */
std::string helpLine(int narg, char *args[], int action=HELP_ACTION, int detPos = -1);
std::string helpLine(int narg, const char * const args[], int action=HELP_ACTION, int detPos = -1);
static std::string helpAcquire(int action);
static std::string helpData(int action);
static std::string helpStatus(int action);
@ -96,56 +96,56 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
multiSlsDetector *myDet;
std::string cmdUnderDevelopment(int narg, char *args[], int action, int detPos = -1);
std::string cmdUnknown(int narg, char *args[], int action, int detPos = -1);
std::string cmdAcquire(int narg, char *args[], int action, int detPos = -1);
std::string cmdData(int narg, char *args[], int action, int detPos = -1);
std::string cmdStatus(int narg, char *args[], int action, int detPos = -1);
std::string cmdDataStream(int narg, char *args[], int action, int detPos = -1);
std::string cmdFree(int narg, char *args[], int action, int detPos = -1);
std::string cmdHostname(int narg, char *args[], int action, int detPos = -1);
std::string cmdUser(int narg, char *args[], int action, int detPos = -1);
std::string cmdHelp(int narg, char *args[], int action, int detPos = -1);
std::string cmdExitServer(int narg, char *args[], int action, int detPos = -1);
std::string cmdSettingsDir(int narg, char *args[], int action, int detPos = -1);
std::string cmdTrimEn(int narg, char *args[], int action, int detPos = -1);
std::string cmdOutDir(int narg, char *args[], int action, int detPos = -1);
std::string cmdFileName(int narg, char *args[], int action, int detPos = -1);
std::string cmdFileIndex(int narg, char *args[], int action, int detPos = -1);
std::string cmdRateCorr(int narg, char *args[], int action, int detPos = -1);
std::string cmdNetworkParameter(int narg, char *args[], int action, int detPos = -1);
std::string cmdPort(int narg, char *args[], int action, int detPos = -1);
std::string cmdLock(int narg, char *args[], int action, int detPos = -1);
std::string cmdLastClient(int narg, char *args[], int action, int detPos = -1);
std::string cmdOnline(int narg, char *args[], int action, int detPos = -1);
std::string cmdConfigureMac(int narg, char *args[], int action, int detPos = -1);
std::string cmdDetectorSize(int narg, char *args[], int action, int detPos = -1);
std::string cmdSettings(int narg, char *args[], int action, int detPos = -1);
std::string cmdSN(int narg, char *args[], int action, int detPos = -1);
std::string cmdDigiTest(int narg, char *args[], int action, int detPos = -1);
std::string cmdRegister(int narg, char *args[], int action, int detPos = -1);
std::string cmdDAC(int narg, char *args[], int action, int detPos = -1);
std::string cmdTiming(int narg, char *args[], int action, int detPos = -1);
std::string cmdTimer(int narg, char *args[], int action, int detPos = -1);
std::string cmdTimeLeft(int narg, char *args[], int action, int detPos = -1);
std::string cmdSpeed(int narg, char *args[], int action, int detPos = -1);
std::string cmdAdvanced(int narg, char *args[], int action, int detPos = -1);
std::string cmdConfiguration(int narg, char *args[], int action, int detPos = -1);
std::string cmdImage(int narg, char *args[], int action, int detPos = -1);
std::string cmdCounter(int narg, char *args[], int action, int detPos = -1);
std::string cmdADC(int narg, char *args[], int action, int detPos = -1);
std::string cmdTempControl(int narg, char *args[], int action, int detPos = -1);
std::string cmdEnablefwrite(int narg, char *args[], int action, int detPos = -1);
std::string cmdOverwrite(int narg, char *args[], int action, int detPos = -1);
std::string cmdReceiver(int narg, char *args[], int action, int detPos = -1);
std::string cmdPattern(int narg, char *args[], int action, int detPos = -1);
std::string cmdPulse(int narg, char *args[], int action, int detPos = -1);
std::string cmdProcessor(int narg, char *args[], int action, int detPos = -1);
std::string cmdUnderDevelopment(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdUnknown(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdAcquire(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdData(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdStatus(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdDataStream(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdFree(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdHostname(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdUser(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdHelp(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdExitServer(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdSettingsDir(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTrimEn(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdOutDir(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdFileName(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdFileIndex(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdRateCorr(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdNetworkParameter(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdPort(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdLock(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdLastClient(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdOnline(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdConfigureMac(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdDetectorSize(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdSettings(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdSN(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdDigiTest(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdRegister(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdDAC(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTiming(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTimer(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTimeLeft(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdSpeed(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdAdvanced(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdConfiguration(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdImage(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdCounter(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdADC(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdTempControl(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdEnablefwrite(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdOverwrite(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdReceiver(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdPattern(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdPulse(int narg, const char * const args[], int action, int detPos = -1);
std::string cmdProcessor(int narg, const char * const args[], int action, int detPos = -1);
int numberOfCommands;
std::string cmd;
typedef std::string (slsDetectorCommand::*MemFuncGetter)(int narg, char *args[], int action, int detPos);
typedef std::string (slsDetectorCommand::*MemFuncGetter)(int narg, const char * const args[], int action, int detPos);
struct FuncTable

View File

@ -2130,7 +2130,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
//-----------------------------------------------------------
std::string slsDetectorCommand::executeLine(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::executeLine(int narg, const char * const args[], int action, int detPos) {
if (action == READOUT_ACTION)
return cmdAcquire(narg, args, action, detPos);
@ -2161,14 +2161,14 @@ std::string slsDetectorCommand::executeLine(int narg, char *args[], int action,
return cmdUnknown(narg, args, action, detPos);
}
std::string slsDetectorCommand::cmdUnknown(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdUnknown(int narg, const char * const args[], int action, int detPos) {
return std::string("Unknown command ") + std::string(args[0]) + std::string("\n") + helpLine(0, args, action, detPos);
}
std::string slsDetectorCommand::cmdUnderDevelopment(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdUnderDevelopment(int narg, const char * const args[], int action, int detPos) {
return std::string("Must still develop ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
}
std::string slsDetectorCommand::helpLine(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::helpLine(int narg, const char * const args[], int action, int detPos) {
std::ostringstream os;
@ -2187,7 +2187,7 @@ std::string slsDetectorCommand::helpLine(int narg, char *args[], int action, int
return executeLine(narg, args, HELP_ACTION, detPos);
}
std::string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdAcquire(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
#endif
@ -2232,7 +2232,7 @@ std::string slsDetectorCommand::helpAcquire(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdData(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdData(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
@ -2264,7 +2264,7 @@ std::string slsDetectorCommand::helpData(int action) {
return std::string("data \t gets all data from the detector (if any) processes them and writes them to file according to the preferences already setup\n");
}
std::string slsDetectorCommand::cmdStatus(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdStatus(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
@ -2317,7 +2317,7 @@ std::string slsDetectorCommand::helpStatus(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdDataStream(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdDataStream(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
@ -2351,7 +2351,7 @@ std::string slsDetectorCommand::helpDataStream(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdFree(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdFree(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
@ -2367,7 +2367,7 @@ std::string slsDetectorCommand::helpFree(int action) {
return std::string("free \t frees the shared memory\n");
}
std::string slsDetectorCommand::cmdHostname(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdHostname(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
#endif
@ -2429,7 +2429,7 @@ std::string slsDetectorCommand::helpHostname(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdUser(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdUser(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
#endif
@ -2459,7 +2459,7 @@ std::string slsDetectorCommand::helpUser(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdHelp(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdHelp(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
#endif
@ -2472,7 +2472,7 @@ std::string slsDetectorCommand::cmdHelp(int narg, char *args[], int action, int
return helpLine(0, args, action, detPos);
}
std::string slsDetectorCommand::cmdExitServer(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdExitServer(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
#endif
@ -2520,7 +2520,7 @@ std::string slsDetectorCommand::helpExitServer(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdSettingsDir(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdSettingsDir(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
#endif
@ -2548,7 +2548,7 @@ std::string slsDetectorCommand::helpSettingsDir(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdTrimEn(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdTrimEn(int narg, const char * const args[], int action, int detPos) {
std::vector<int> energies;
if (action == HELP_ACTION)
return helpTrimEn(action);
@ -2579,7 +2579,7 @@ std::string slsDetectorCommand::helpTrimEn(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdOutDir(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdOutDir(int narg, const char * const args[], int action, int detPos) {
myDet->setReceiverOnline(ONLINE_FLAG, detPos);
if (action == HELP_ACTION)
return helpOutDir(action);
@ -2599,7 +2599,7 @@ std::string slsDetectorCommand::helpOutDir(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdFileName(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdFileName(int narg, const char * const args[], int action, int detPos) {
myDet->setReceiverOnline(ONLINE_FLAG, detPos);
if (action == HELP_ACTION)
return helpFileName(action);
@ -2635,7 +2635,7 @@ std::string slsDetectorCommand::helpFileName(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdEnablefwrite(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdEnablefwrite(int narg, const char * const args[], int action, int detPos) {
int i;
char ans[100];
@ -2681,7 +2681,7 @@ std::string slsDetectorCommand::helpEnablefwrite(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdOverwrite(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdOverwrite(int narg, const char * const args[], int action, int detPos) {
int i;
char ans[100];
myDet->setReceiverOnline(ONLINE_FLAG, detPos);
@ -2707,7 +2707,7 @@ std::string slsDetectorCommand::helpOverwrite(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdFileIndex(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdFileIndex(int narg, const char * const args[], int action, int detPos) {
myDet->setReceiverOnline(ONLINE_FLAG, detPos);
if (action == HELP_ACTION) {
return helpFileName(action);
@ -2727,7 +2727,7 @@ std::string slsDetectorCommand::helpFileIndex(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdRateCorr(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION) {
return helpRateCorr(action);
@ -2754,7 +2754,7 @@ std::string slsDetectorCommand::helpRateCorr(int action) {
return os.str();
}
// std::string slsDetectorCommand::cmdThreaded(int narg, char *args[], int action, int detPos){
// std::string slsDetectorCommand::cmdThreaded(int narg, const char * const args[], int action, int detPos){
// int ival;
// char answer[1000];
@ -2780,7 +2780,7 @@ std::string slsDetectorCommand::helpThreaded(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdImage(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdImage(int narg, const char * const args[], int action, int detPos) {
std::string sval;
int retval = FAIL;
if (action == HELP_ACTION)
@ -2815,7 +2815,7 @@ std::string slsDetectorCommand::helpImage(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdCounter(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdCounter(int narg, const char * const args[], int action, int detPos) {
int ival;
char answer[100];
std::string sval;
@ -2876,7 +2876,7 @@ std::string slsDetectorCommand::helpCounter(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdNetworkParameter(int narg, const char * const args[], int action, int detPos) {
char ans[100] = {0};
int i;
@ -3127,7 +3127,7 @@ std::string slsDetectorCommand::helpNetworkParameter(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdPort(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdPort(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpPort(action);
@ -3175,7 +3175,7 @@ std::string slsDetectorCommand::helpPort(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdLock(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdLock(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpLock(action);
@ -3226,7 +3226,7 @@ std::string slsDetectorCommand::helpLock(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdLastClient(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdLastClient(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpLastClient(action);
@ -3257,7 +3257,7 @@ std::string slsDetectorCommand::helpLastClient(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdOnline(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdOnline(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION) {
return helpOnline(action);
@ -3341,7 +3341,7 @@ std::string slsDetectorCommand::helpOnline(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdConfigureMac(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdConfigureMac(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION) {
return helpConfigureMac(action);
@ -3372,7 +3372,7 @@ std::string slsDetectorCommand::helpConfigureMac(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdDetectorSize(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdDetectorSize(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpDetectorSize(action);
@ -3489,7 +3489,7 @@ std::string slsDetectorCommand::helpDetectorSize(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdSettings(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdSettings(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpSettings(action);
@ -3607,7 +3607,7 @@ std::string slsDetectorCommand::helpSettings(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdSN(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdSN(int narg, const char * const args[], int action, int detPos) {
char answer[1000];
@ -3700,7 +3700,7 @@ std::string slsDetectorCommand::helpSN(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdDigiTest(int narg, const char * const args[], int action, int detPos) {
char answer[1000];
@ -3751,7 +3751,7 @@ std::string slsDetectorCommand::helpDigiTest(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdRegister(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdRegister(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpRegister(action);
@ -3869,7 +3869,7 @@ std::string slsDetectorCommand::helpRegister(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdDAC(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdDAC(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpDAC(action);
@ -4215,7 +4215,7 @@ std::string slsDetectorCommand::helpDAC(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdADC(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdADC(int narg, const char * const args[], int action, int detPos) {
dacIndex adc;
int idac;
@ -4342,7 +4342,7 @@ std::string slsDetectorCommand::helpADC(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdTempControl(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdTempControl(int narg, const char * const args[], int action, int detPos) {
char answer[1000] = "";
int val = -1;
@ -4409,7 +4409,7 @@ std::string slsDetectorCommand::helpTempControl(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdTiming(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdTiming(int narg, const char * const args[], int action, int detPos) {
#ifdef VERBOSE
std::cout << std::string("Executing command ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
#endif
@ -4435,7 +4435,7 @@ std::string slsDetectorCommand::helpTiming(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdTimer(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdTimer(int narg, const char * const args[], int action, int detPos) {
timerIndex index;
int64_t t = -1, ret;
double val, rval;
@ -4565,7 +4565,7 @@ std::string slsDetectorCommand::helpTimer(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdTimeLeft(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdTimeLeft(int narg, const char * const args[], int action, int detPos) {
timerIndex index;
int64_t ret;
double rval;
@ -4635,7 +4635,7 @@ std::string slsDetectorCommand::helpTimeLeft(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdSpeed(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdSpeed(int narg, const char * const args[], int action, int detPos) {
speedVariable index;
int t = -1, ret = 0, mode = 0;
@ -4732,7 +4732,7 @@ std::string slsDetectorCommand::helpSpeed(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdAdvanced(int narg, const char * const args[], int action, int detPos) {
char answer[1000] = "";
@ -4970,7 +4970,7 @@ std::string slsDetectorCommand::helpAdvanced(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdConfiguration(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpConfiguration(action);
@ -5040,7 +5040,7 @@ std::string slsDetectorCommand::helpConfiguration(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdReceiver(int narg, const char * const args[], int action, int detPos) {
char answer[100];
int ival = -1;
@ -5288,7 +5288,7 @@ std::string slsDetectorCommand::helpPattern(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpPattern(action);
@ -5758,7 +5758,7 @@ std::string slsDetectorCommand::helpPulse(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdPulse(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdPulse(int narg, const char * const args[], int action, int detPos) {
int retval = FAIL;
if (action == HELP_ACTION)
@ -5820,7 +5820,7 @@ std::string slsDetectorCommand::helpProcessor(int action) {
return os.str();
}
std::string slsDetectorCommand::cmdProcessor(int narg, char *args[], int action, int detPos) {
std::string slsDetectorCommand::cmdProcessor(int narg, const char * const args[], int action, int detPos) {
if (action == HELP_ACTION)
return helpProcessor(action);

View File

@ -10,14 +10,13 @@ class CmdLineParser {
void Parse(const std::string &s);
void Print();
//getters
int multi_id() const { return multi_id_; };
int detector_id() const { return detector_id_; };
int n_arguments() const { return arguments_.size(); }
const std::string &command() const { return command_; }
const std::string &executable() const { return executable_; }
const std::vector<std::string> &arguments() const { return arguments_; };
std::vector<char *> argv();
std::vector<const char *> argv() const;
private:
void DecodeIdAndPosition(const char *c);

View File

@ -5,10 +5,11 @@
#include <iostream>
#include <iterator>
#include <sstream>
//printing function for debugging
void CmdLineParser::Print() {
std::cout << "\nCmdLineParser::Print()\n";
std::cout << "\tmulti_id: " << multi_id_ << ", detector_id: " << detector_id_ << std::endl;
std::cout << "\tmulti_id: " << multi_id_
<< ", detector_id: " << detector_id_ << std::endl;
std::cout << "\texecutable: " << executable_ << '\n';
std::cout << "\tcommand: " << command_ << '\n';
std::cout << "\tn_arguments: " << n_arguments() << '\n';
@ -20,26 +21,21 @@ void CmdLineParser::Print() {
};
void CmdLineParser::Parse(int argc, char *argv[]) {
//first element of argv is the command used to call the executable ->skipping
//and if this is the only command skip all
executable_ = argv[0];
executable_ = argv[0]; //first arg is calling binary
if (argc > 1) {
//second element is cmd string that needs to be decoded
DecodeIdAndPosition(argv[1]);
//The rest of the arguments goes into a vector for later processing
for (int i = 2; i < argc; ++i) {
arguments_.emplace_back(std::string(argv[i]));
arguments_.emplace_back(argv[i]);
}
}
};
}
void CmdLineParser::Parse(const std::string &s) {
std::istringstream iss(s);
auto it = std::istream_iterator<std::string>(iss);
//read the first element and increment
command_ = *it++;
arguments_ = std::vector<std::string>(it, std::istream_iterator<std::string>());
;
arguments_ =
std::vector<std::string>(it, std::istream_iterator<std::string>());
DecodeIdAndPosition(command_.c_str());
}
@ -51,19 +47,23 @@ void CmdLineParser::DecodeIdAndPosition(const char *c) {
if (contains_id && contains_pos) {
int r = sscanf(c, "%d-%d:%s", &multi_id_, &detector_id_, tmp);
if (r != 3) {
throw(std::invalid_argument("Cannot decode client or detector id from: \"" + std::string(c) + "\"\n"));
throw(std::invalid_argument(
"Cannot decode client or detector id from: \"" +
std::string(c) + "\"\n"));
}
command_ = tmp;
} else if (contains_id && !contains_pos) {
int r = sscanf(c, "%d-%s", &multi_id_, tmp);
if (r != 2) {
throw(std::invalid_argument("Cannot decode client id from: \"" + std::string(c) + "\"\n"));
throw(std::invalid_argument("Cannot decode client id from: \"" +
std::string(c) + "\"\n"));
}
command_ = tmp;
} else if (!contains_id && contains_pos) {
int r = sscanf(c, "%d:%s", &detector_id_, tmp);
if (r != 2) {
throw(std::invalid_argument("Cannot decode detector id from: \"" + std::string(c) + "\"\n"));
throw(std::invalid_argument("Cannot decode detector id from: \"" +
std::string(c) + "\"\n"));
}
command_ = tmp;
} else {
@ -71,12 +71,11 @@ void CmdLineParser::DecodeIdAndPosition(const char *c) {
}
}
std::vector<char *> CmdLineParser::argv() {
std::vector<char *> vec;
if (command_.empty()!=true){
std::vector<const char *> CmdLineParser::argv() const {
std::vector<const char *> vec;
if (command_.empty() != true) {
vec.push_back(&command_.front());
}
for (auto &arg : arguments_) {
vec.push_back(&arg.front());
}

View File

@ -2,13 +2,124 @@
#include "catch.hpp"
#include <exception>
#include <string>
//tests to add
//help for all docs
//command for all depreciated commands
// tests to add
// help for all docs
// command for all depreciated commands
TEST_CASE("Parse with no arguments results in no command and default id") {
//build up argc and argv
//first argument is the command used to call the binary
using vs = std::vector<std::string>;
SCENARIO("Construction", "[support]") {
GIVEN("A default constructed CmdLineParser") {
CmdLineParser p;
THEN("The state of the object is valid") {
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command().empty());
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().empty());
REQUIRE(p.argv().data() == nullptr);
}
}
}
SCENARIO("Parsing a string with the command line parser", "[support]") {
GIVEN("A CmdLineParser") {
CmdLineParser p;
WHEN("Parsing an empty string") {
std::string s;
p.Parse(s);
THEN("command and arguments are empty") {
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command().empty());
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().empty());
}
}
WHEN("Parsing a string with a single command") {
std::string s = "vrf";
p.Parse(s);
THEN("command is assigned and id's remain default") {
REQUIRE(p.command() == "vrf");
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().size() == 1);
}
}
WHEN("Parsing a string with command and value") {
std::string s = "vthreshold 1500";
p.Parse(s);
THEN("cmd and value are assigned and id's remain default") {
REQUIRE(p.command() == "vthreshold");
REQUIRE(p.arguments()[0] == "1500");
REQUIRE(p.arguments().size() == 1);
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
}
}
WHEN("Parsing a string with detector id and command") {
vs arg{"9:vcp", "53:vthreshold", "128:vtrim", "5:threshold"};
std::vector<int> det_id{9, 53, 128, 5};
vs res{"vcp", "vthreshold", "vtrim", "threshold"};
THEN("Values are correctly decoded") {
for (size_t i = 0; i != arg.size(); ++i) {
p.Parse(arg[i]);
REQUIRE(p.detector_id() == det_id[i]);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == res[i]);
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().size() == 1);
}
}
}
WHEN("Parsing a string with multi_id detector id and command") {
vs arg{"8-12:vrf", "0-52:vcmp", "19-10:vtrim", "31-127:threshold"};
std::vector<int> det_id{12, 52, 10, 127};
std::vector<int> multi_id{8, 0, 19, 31};
vs res{"vrf", "vcmp", "vtrim", "threshold"};
THEN("Values are correctly decoded") {
for (size_t i = 0; i != arg.size(); ++i) {
p.Parse(arg[i]);
REQUIRE(p.detector_id() == det_id[i]);
REQUIRE(p.multi_id() == multi_id[i]);
REQUIRE(p.command() == res[i]);
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().size() == 1);
}
}
}
WHEN("Parsing string with cmd and multiple arguments"){
std::string s = "trimen 5000 6000 7000";
p.Parse(s);
THEN("cmd and args are correct"){
REQUIRE(p.command() == "trimen");
REQUIRE(p.arguments().size() == 3);
REQUIRE(p.arguments()[0] == "5000");
REQUIRE(p.arguments()[1] == "6000");
REQUIRE(p.arguments()[2] == "7000");
}
}
WHEN("Cliend id and or detector id cannot be decoded") {
vs arg{"o:cmd", "-5:cmd", "aedpva:cmd",
"5-svc:vrf", "asv-5:cmd", "savc-asa:cmd"};
THEN("Parsing Throws") {
for (size_t i = 0; i != arg.size(); ++i) {
REQUIRE_THROWS(p.Parse(arg[i]));
}
}
}
}
}
TEST_CASE("Parse with no arguments results in no command and default id",
"[support]") {
// build up argc and argv
// first argument is the command used to call the binary
int argc = 1;
char *argv[argc];
char a0[] = "call";
@ -23,18 +134,9 @@ TEST_CASE("Parse with no arguments results in no command and default id") {
REQUIRE(p.arguments().empty());
}
TEST_CASE("Parse empty string") {
std::string s;
CmdLineParser p;
p.Parse(s);
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command().empty());
REQUIRE(p.arguments().empty());
}
TEST_CASE("Parse a command without client id and detector id results in default") {
TEST_CASE(
"Parse a command without client id and detector id results in default",
"[support]") {
int argc = 2;
char *argv[argc];
char a0[] = "call";
@ -51,18 +153,8 @@ TEST_CASE("Parse a command without client id and detector id results in default"
REQUIRE(p.arguments().empty());
}
TEST_CASE("Parse a string without client id and detector id results in default") {
std::string s = "vrf";
CmdLineParser p;
p.Parse(s);
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == "vrf");
REQUIRE(p.arguments().empty());
}
TEST_CASE("Parse a command with value but without client or detector id") {
TEST_CASE("Parse a command with value but without client or detector id",
"[support]") {
int argc = 3;
char *argv[argc];
char a0[] = "call";
@ -81,18 +173,6 @@ TEST_CASE("Parse a command with value but without client or detector id") {
REQUIRE(p.arguments().size() == 1);
REQUIRE(p.arguments()[0] == "3000");
}
TEST_CASE("Parse a string with value but without client or detector id") {
std::string s = "vrf 3000\n";
CmdLineParser p;
p.Parse(s);
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == "vrf");
REQUIRE(p.arguments().size() == 1);
REQUIRE(p.arguments()[0] == "3000");
}
TEST_CASE("Decodes position") {
int argc = 2;
@ -110,19 +190,8 @@ TEST_CASE("Decodes position") {
REQUIRE(p.command() == "vrf");
REQUIRE(p.arguments().empty());
}
TEST_CASE("Decodes position from string") {
std::string s = "7:vrf\n";
CmdLineParser p;
p.Parse(s);
REQUIRE(p.detector_id() == 7);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == "vrf");
REQUIRE(p.arguments().empty());
}
TEST_CASE("Decodes double digit position") {
TEST_CASE("Decodes double digit position", "[support]") {
int argc = 2;
char *argv[argc];
char a0[] = "call";
@ -139,19 +208,7 @@ TEST_CASE("Decodes double digit position") {
REQUIRE(p.arguments().empty());
}
TEST_CASE("Decodes double digit position from string") {
std::string s = "73:vcmp";
CmdLineParser p;
p.Parse(s);
REQUIRE(p.detector_id() == 73);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == "vcmp");
REQUIRE(p.arguments().empty());
}
TEST_CASE("Decodes position and id") {
TEST_CASE("Decodes position and id", "[support]") {
int argc = 2;
char *argv[argc];
char a0[] = "call";
@ -167,18 +224,8 @@ TEST_CASE("Decodes position and id") {
REQUIRE(p.command() == "vrf");
REQUIRE(p.arguments().empty());
}
TEST_CASE("Decodes position and id from string") {
std::string s = "5-8:vrf";
CmdLineParser p;
p.Parse(s);
REQUIRE(p.detector_id() == 8);
REQUIRE(p.multi_id() == 5);
REQUIRE(p.command() == "vrf");
REQUIRE(p.arguments().empty());
}
TEST_CASE("Double digit id") {
TEST_CASE("Double digit id", "[support]") {
int argc = 2;
char *argv[argc];
char a0[] = "call";
@ -195,18 +242,7 @@ TEST_CASE("Double digit id") {
REQUIRE(p.arguments().empty());
}
TEST_CASE("Double digit id from string") {
std::string s = "56-8:vrf";
CmdLineParser p;
p.Parse(s);
REQUIRE(p.detector_id() == 8);
REQUIRE(p.multi_id() == 56);
REQUIRE(p.command() == std::string("vrf"));
REQUIRE(p.arguments().empty());
}
TEST_CASE("Calling with wrong id throws invalid_argument") {
TEST_CASE("Calling with wrong id throws invalid_argument", "[support]") {
int argc = 2;
char *argv[argc];
@ -218,13 +254,8 @@ TEST_CASE("Calling with wrong id throws invalid_argument") {
CmdLineParser p;
CHECK_THROWS(p.Parse(argc, argv));
}
TEST_CASE("Calling with string with wrong id throws invalid_argument") {
std::string s = "asvldkn:vrf";
CmdLineParser p;
CHECK_THROWS(p.Parse(s));
}
TEST_CASE("Calling with wrong client throws invalid_argument") {
TEST_CASE("Calling with wrong client throws invalid_argument", "[support]") {
int argc = 2;
char *argv[argc];
char a0[] = "call";
@ -235,26 +266,9 @@ TEST_CASE("Calling with wrong client throws invalid_argument") {
CmdLineParser p;
CHECK_THROWS(p.Parse(argc, argv));
}
TEST_CASE("Calling with string with wrong client throws invalid_argument") {
std::string s = "lki-3:vrf";
CmdLineParser p;
CHECK_THROWS(p.Parse(s));
}
TEST_CASE("Parses string with two arguments") {
std::string s = "trimen 3000 4000\n";
TEST_CASE("Build up argv", "[support]") {
CmdLineParser p;
p.Parse(s);
REQUIRE("trimen" == p.command());
REQUIRE("3000" == p.arguments()[0]);
REQUIRE("4000" == p.arguments()[1]);
REQUIRE(p.arguments().size() == 2);
}
TEST_CASE("Build up argv"){
CmdLineParser p;
// p.argv();
REQUIRE(p.argv().empty());
REQUIRE(p.argv().data() == nullptr);
@ -262,5 +276,4 @@ TEST_CASE("Build up argv"){
p.Parse(s);
REQUIRE(p.argv().data() != nullptr);
REQUIRE(p.argv().size() == 3);
}