From a97b725f43eb13b18e63997f32f436f3e420b72a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 25 Jun 2018 19:14:41 +0200 Subject: [PATCH] sharedmem: command line done, fixing to do --- .../multiSlsDetector/multiSlsDetectorClient.h | 178 +++++++++++------- .../multiSlsDetectorCommand.h | 8 +- 2 files changed, 109 insertions(+), 77 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h index 57ea92638..0e5382b58 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h @@ -16,82 +16,114 @@ int dummyCallback(detectorData* d, int p,void*) { class multiSlsDetectorClient { - public: - multiSlsDetectorClient(int argc, char *argv[], int action, multiSlsDetector *myDetector=NULL) { \ - string answer; \ - multiSlsDetectorCommand *myCmd; \ - int id=-1, iv=0, pos=-1; \ - int del=0; \ - char cmd[100]; \ - if (action==slsDetectorDefs::READOUT_ACTION) { \ +public: + multiSlsDetectorClient(int argc, char *argv[], int action, multiSlsDetector *myDetector=NULL) { \ + string answer; \ + multiSlsDetectorCommand *myCmd; \ + int id = -1, pos = -1, iv = 0; \ + bool verify = true, update = true; \ + int del = 0; \ + char cmd[100] = ""; \ - if (argc!=0) { - iv=sscanf(argv[0],"%d-%s",&id,cmd); \ - if (iv>0 && id>=0 && strchr(argv[0],'-')) { - cout << "id " << id << endl; \ - if (iv>1) - argv[0]=cmd; - } - iv=sscanf(argv[0],"%d:",&pos); \ - if (iv>0 && pos>=0 && strchr(argv[0],':')) - cout << "pos " << pos << "is not allowed!" << endl; \ - } - if (id<0) - id=0; + // multi id scanned + iv=sscanf(argv[0],"%d-%s",&id, cmd); \ + if (iv != 2 || id < 0) \ + id = 0; \ + if (iv == 2 && id >= 0) { \ + argv[0] = cmd; \ + cout << id << "-" ; \ + } \ - if (myDetector==NULL) { \ - myDetector=new multiSlsDetector(id); \ - //myDetector->registerDataCallback(&dummyCallback, NULL); - del=1; \ - }; - // cout << "noid" <executeLine(argc, argv, action); \ - cout << answer<< endl; \ - delete myCmd; \ - if (del) delete myDetector; \ - return; \ - }; \ - if (action==slsDetectorDefs::PUT_ACTION && argc<2) { \ - cout << "Wrong usage - should be: "<< argv[0] << \ - "[id-][pos:]channel arg" << endl; \ - cout << endl; \ - return; \ - if (del) delete myDetector; \ - }; - if (action==slsDetectorDefs::GET_ACTION && argc<1) { \ - cout << "Wrong usage - should be: "<< argv[0] << \ - "[id-][pos:]channel arg" << endl; \ - cout << endl; \ - if (del) delete myDetector; \ - return; \ - }; \ - if (myDetector==NULL) { \ - iv=sscanf(argv[0],"%d-%s",&id, cmd); \ - if (iv==2 && id>=0) { \ - myDetector=new multiSlsDetector(id); \ - argv[0]=cmd; \ - cout << id << "-" ; \ - } else { \ - myDetector=new multiSlsDetector(); \ - }; \ - del=1; \ - } \ - iv=sscanf(argv[0],"%d:%s",&pos, cmd); \ - if (iv==2 && pos>=0) { \ - argv[0]=cmd; \ - cout << pos << ":" ; \ - } ; \ - myCmd=new multiSlsDetectorCommand(myDetector); \ - answer=myCmd->executeLine(argc, argv, action, pos); \ - cout << argv[0] << " " ; \ - cout << answer<< endl; \ - delete myCmd; \ - if (del) delete myDetector; \ - }; - - + // sls pos scanned + iv=sscanf(argv[0],"%d:%s", &pos, cmd); \ + if (iv != 2 ) \ + pos = 0; \ + if (iv == 2 && pos >= 0) { \ + argv[0] = cmd; \ + cout << pos << ":" ; \ + } \ + // readout + if (action==slsDetectorDefs::READOUT_ACTION) { \ + if (pos != -1) { \ + cout << "pos " << pos << "is not allowed for readout!" << endl; \ + } \ + // create multiSlsDetector class if required + if (myDetector==NULL) { \ + try { \ + myDetector = new multiSlsDetector(id, verify, update); \ + } catch (const SharedMemoryException & e) { \ + cout << e.GetMessage() << endl; \ + return; \ + } catch (...) { \ + cout << " caught exception" << endl; \ + return; \ + } \ + //myDetector->registerDataCallback(&dummyCallback, NULL); + del=1; \ + } \ + myCmd=new multiSlsDetectorCommand(myDetector); \ + answer=myCmd->executeLine(argc, argv, action); \ + cout << answer<< endl; \ + delete myCmd; \ + if (del) delete myDetector; \ + return; \ + }; \ + + if (action==slsDetectorDefs::PUT_ACTION && argc<2) { \ + cout << "Wrong usage - should be: "<< argv[0] << \ + "[id-][pos:]channel arg" << endl; \ + cout << endl; \ + return; \ + if (del) delete myDetector; \ + }; + if (action==slsDetectorDefs::GET_ACTION && argc<1) { \ + cout << "Wrong usage - should be: "<< argv[0] << \ + "[id-][pos:]channel arg" << endl; \ + cout << endl; \ + if (del) delete myDetector; \ + return; \ + }; \ + + // special commands + string scmd = cmd; \ + // free without calling multiSlsDetector constructor + if (scmd == "free") { \ + if (pos != -1) \ + slsDetector::freeSharedMemory(id, pos); \ + else \ + multiSlsDetector::freeSharedMemory(id); \ + return; \ + } \ + // get user details without verify sharedMultiSlsDetector version + else if ((scmd == "userdetails") && (action==slsDetectorDefs::GET_ACTION)) {\ + verify = false; \ + update = false; \ + myDetector=NULL; \ + } \ + + // create multiSlsDetector class if required + if (myDetector==NULL) { \ + try { \ + myDetector = new multiSlsDetector(id, verify, update); \ + } catch (const SharedMemoryException & e) { \ + cout << e.GetMessage() << endl; \ + return; \ + } catch (...) { \ + cout << " caught exception" << endl; \ + return; \ + } \ + del=1; \ + } \ + + // call multi detector command line + myCmd=new multiSlsDetectorCommand(myDetector); \ + answer=myCmd->executeLine(argc, argv, action, pos); \ + cout << argv[0] << " " ; \ + cout << answer<< endl; \ + delete myCmd; \ + if (del) delete myDetector; \ + }; }; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorCommand.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorCommand.h index e3cc7a247..6e5c68e93 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorCommand.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorCommand.h @@ -27,7 +27,7 @@ class multiSlsDetectorCommand : public slsDetectorCommand { /* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */ /* \returns answer string */ /* *\/ */ - + string executeLine(int narg, char *args[], int action, int id=-1) { \ string s; \ if (id>=0) { @@ -37,14 +37,14 @@ class multiSlsDetectorCommand : public slsDetectorCommand { s=cmd->executeLine(narg, args, action); \ if(d->getErrorMask()) \ myDet->setErrorMask((myDet->getErrorMask())|(1<