1 #include "otsdaq-utilities/MacroMaker/MacroMakerSupervisor.h"
9 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
10 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
14 #include "otsdaq-core/FECore/FEVInterface.h"
17 #include "otsdaq-core/CodeEditor/CodeEditor.h"
31 #define MACROS_DB_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/MacroData/"
32 #define MACROS_HIST_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/MacroHistory/"
33 #define MACROS_EXPORT_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/MacroExport/"
38 #define __MF_SUBJECT__ "MacroMaker"
44 : CoreSupervisorBase(stub)
46 INIT_MF(
"MacroMaker");
49 mkdir(((std::string)MACROS_DB_PATH).c_str(), 0755);
50 mkdir(((std::string)MACROS_HIST_PATH).c_str(), 0755);
51 mkdir(((std::string)MACROS_EXPORT_PATH).c_str(), 0755);
53 xoap::bind(
this, &MacroMakerSupervisor::frontEndCommunicationRequest,
54 "FECommunication", XDAQ_NS_URI );
60 MacroMakerSupervisor::~MacroMakerSupervisor(
void)
66 void MacroMakerSupervisor::init(
void)
71 allFESupervisorInfo_ = allSupervisorInfo_.getAllFETypeSupervisorInfo();
75 void MacroMakerSupervisor::destroy(
void)
83 void MacroMakerSupervisor::forceSupervisorPropertyValues()
90 void MacroMakerSupervisor::request(
const std::string& requestType, cgicc::Cgicc& cgiIn,
91 HttpXmlDocument& xmlOut,
const WebUsers::RequestUserInfo& userInfo)
94 __SUP_COUT__ <<
"User name is " << userInfo.username_ <<
"." << __E__;
95 __SUP_COUT__ <<
"User permission level for request '" << requestType <<
"' is " <<
96 unsigned(userInfo.permissionLevel_) <<
"." << __E__;
100 if(requestType ==
"getPermission")
102 xmlOut.addTextElementToData(
"Permission", std::to_string(
unsigned(userInfo.permissionLevel_)));
105 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
106 mkdir(macroPath.c_str(), 0755);
107 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
108 mkdir(histPath.c_str(), 0755);
109 std::string publicPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
110 mkdir(publicPath.c_str(), 0755);
111 std::string exportPath = (std::string)MACROS_EXPORT_PATH + userInfo.username_ +
"/";
112 mkdir(exportPath.c_str(), 0755);
115 handleRequest(requestType,xmlOut,cgiIn,userInfo.username_);
117 catch(
const std::runtime_error& e)
119 __SS__ <<
"Error occurred handling request '" << requestType <<
120 "': " << e.what() << __E__;
121 __SUP_COUT__ << ss.str();
122 xmlOut.addTextElementToData(
"Error",ss.str());
126 __SS__ <<
"Unknown error occurred handling request '" << requestType <<
128 __SUP_COUT__ << ss.str();
129 xmlOut.addTextElementToData(
"Error",ss.str());
133 void MacroMakerSupervisor::handleRequest(
const std::string Command,
134 HttpXmlDocument& xmldoc, cgicc::Cgicc& cgi,
135 const std::string &username)
137 if(Command ==
"FElist")
139 else if(Command ==
"writeData")
140 writeData(xmldoc,cgi,username);
141 else if(Command ==
"readData")
142 readData(xmldoc,cgi,username);
143 else if(Command ==
"createMacro")
144 createMacro(xmldoc,cgi,username);
145 else if(Command ==
"loadMacros")
146 loadMacros(xmldoc,username);
147 else if(Command ==
"loadHistory")
148 loadHistory(xmldoc,username);
149 else if(Command ==
"deleteMacro")
150 deleteMacro(xmldoc,cgi,username);
151 else if(Command ==
"editMacro")
152 editMacro(xmldoc,cgi,username);
153 else if(Command ==
"clearHistory")
154 clearHistory(username);
155 else if(Command ==
"exportMacro")
156 exportMacro(xmldoc,cgi,username);
157 else if(Command ==
"exportFEMacro")
158 exportFEMacro(xmldoc,cgi,username);
159 else if(Command ==
"getFEMacroList")
160 getFEMacroList(xmldoc,username);
161 else if(Command ==
"runFEMacro")
162 runFEMacro(xmldoc,cgi);
164 xmldoc.addTextElementToData(
"Error",
"Unrecognized command '" + Command +
"'");
169 xoap::MessageReference MacroMakerSupervisor::frontEndCommunicationRequest(xoap::MessageReference message)
172 __SUP_COUT__<<
"FE Request received: " << SOAPUtilities::translate(message) << __E__;
174 SOAPParameters typeParameter, rxParameters;
175 typeParameter.addParameter(
"type");
176 SOAPUtilities::receive(message, typeParameter);
178 std::string type = typeParameter.getValue(
"type");
180 std::string error =
"";
183 if(type ==
"initFElist")
187 rxParameters.addParameter(
"groupName");
188 rxParameters.addParameter(
"groupKey");
189 SOAPUtilities::receive(message, rxParameters);
191 std::string groupName = rxParameters.getValue(
"groupName");
192 std::string groupKey = rxParameters.getValue(
"groupKey");
194 __SUP_COUTV__(groupName);
195 __SUP_COUTV__(groupKey);
197 ConfigurationManager cfgMgr;
198 cfgMgr.loadConfigurationGroup(
199 groupName, ConfigurationGroupKey(groupKey),
true);
204 const SupervisorInfoMap& feTypeSupervisors =
205 CorePropertySupervisorBase::allSupervisorInfo_.getAllFETypeSupervisorInfo();
207 ConfigurationTree appsNode =
208 cfgMgr.getNode(
"XDAQApplicationConfiguration");
210 for(
auto& feApp:feTypeSupervisors)
212 __SUP_COUT__ <<
"FEs for app " << feApp.first <<
":" <<
213 feApp.second.getName() << __E__;
215 std::vector<std::string> feChildren =
216 appsNode.getNode(feApp.second.getName()).
217 getNode(
"LinkToSupervisorTable").
218 getNode(
"LinkToFEInterfaceTable").getChildrenNames();
220 for(
auto& fe:feChildren)
223 FEtoSupervisorMap_[fe] = feApp.first;
227 __SUP_COUTV__(StringMacros::mapToString(FEtoSupervisorMap_));
229 else if(type ==
"feSend" ||
231 type ==
"feMacroMultiDimensionalStart" ||
232 type ==
"feMacroMultiDimensionalCheck" ||
233 type ==
"macroMultiDimensionalStart" ||
234 type ==
"macroMultiDimensionalCheck")
238 rxParameters.addParameter(
"targetInterfaceID");
239 SOAPUtilities::receive(message, rxParameters);
241 std::string targetInterfaceID = rxParameters.getValue(
"targetInterfaceID");
243 __SUP_COUTV__(targetInterfaceID);
245 auto feIt = FEtoSupervisorMap_.find(targetInterfaceID);
246 if(feIt == FEtoSupervisorMap_.end())
248 __SUP_SS__ <<
"Destination front end interface ID '" <<
249 targetInterfaceID <<
"' was not found in the list of front ends." << __E__;
253 unsigned int FESupervisorIndex = feIt->second;
254 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
256 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
257 if (it == allFESupervisorInfo_.end())
259 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '" <<
260 targetInterfaceID <<
":" << FESupervisorIndex <<
".' \n\n" <<
261 "The FE Supervisor Index does not exist. Have you configured the state machine properly?" << __E__;
265 if(type ==
"macroMultiDimensionalStart")
270 SOAPParameters rxParameters;
271 rxParameters.addParameter(
"macroName");
272 SOAPUtilities::receive(message, rxParameters);
273 std::string macroName = rxParameters.getValue(
"macroName");
274 __SUP_COUTV__(macroName);
277 std::string macroString;
278 loadMacro(macroName,macroString);
280 SOAPParameters parameters;
281 parameters.addParameter(
"macroString", macroString);
282 SOAPUtilities::addParameters(message, parameters);
288 __SUP_COUT__ <<
"Forwarding request: " <<
289 SOAPUtilities::translate(message) << __E__;
291 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
292 it->second.getDescriptor(),
297 __SUP_COUT__ <<
"Forwarding FE Macro response: " <<
298 SOAPUtilities::translate(replyMessage) << __E__;
303 catch(
const xdaq::exception::Exception& e)
305 __SUP_SS__ <<
"Error forwarding FE Communication request to FE Supervisor '" <<
306 targetInterfaceID <<
":" << FESupervisorIndex <<
".' " <<
307 "Have you configured the state machine properly?\n\n" <<
314 __SUP_SS__ <<
"Unrecognized FE Communication type: " << type << __E__;
318 return SOAPUtilities::makeSOAPMessageReference(
"Received");
320 catch(
const std::runtime_error& e)
322 xoap::MessageReference returnMessage =
323 SOAPUtilities::makeSOAPMessageReference(
"Error");
325 SOAPParameters parameters;
326 parameters.addParameter(
"Error", e.what());
327 SOAPUtilities::addParameters(returnMessage, parameters);
328 return returnMessage;
332 xoap::MessageReference returnMessage =
333 SOAPUtilities::makeSOAPMessageReference(
"Error");
335 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
336 __SUP_COUT_ERR__ << ss.str();
338 SOAPParameters parameters;
339 parameters.addParameter(
"Error", ss.str());
340 SOAPUtilities::addParameters(returnMessage, parameters);
341 return returnMessage;
345 void MacroMakerSupervisor::getFElist(HttpXmlDocument& xmldoc)
347 __SUP_COUT__<<
"Getting FE list!!!!!!!!!" << __E__;
348 FEtoSupervisorMap_.clear();
350 SOAPParameters txParameters;
351 txParameters.addParameter(
"Request",
"GetInterfaces");
353 SOAPParameters rxParameters;
354 rxParameters.addParameter(
"FEList");
356 SupervisorInfoMap::const_iterator it;
357 std::string oneInterface;
358 std::string rxFEList;
360 size_t lastColonIndex;
364 for(
auto &appInfo:allFESupervisorInfo_)
372 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId() <<
373 " name = " << appInfo.second.getName() << __E__;
377 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
378 appInfo.second.getDescriptor(),
379 "MacroMakerSupervisorRequest",
381 SOAPUtilities::receive(retMsg, rxParameters);
383 catch(
const xdaq::exception::Exception& e)
385 __SS__ <<
"Error transmitting request to FE Supervisor LID = " << appInfo.second.getId() <<
386 " name = " << appInfo.second.getName() <<
". \n\n" << e.what() << __E__;
387 __SUP_COUT_ERR__ << ss.str();
391 rxFEList = rxParameters.getValue(
"FEList");
393 __SUP_COUT__ <<
"FE List received: \n" << rxFEList << __E__;
395 std::istringstream allInterfaces(rxFEList);
396 while (std::getline(allInterfaces, oneInterface))
398 __SUP_COUTV__(oneInterface);
399 xmldoc.addTextElementToData(
"FE",oneInterface);
401 lastColonIndex = oneInterface.rfind(
':');
402 if(lastColonIndex == std::string::npos)
404 __SUP_SS__ <<
"Last colon could not be found in " << oneInterface << __E__;
407 oneInterface = oneInterface.substr(lastColonIndex);
409 __SUP_COUTV__(oneInterface);
411 FEtoSupervisorMap_[oneInterface] = appInfo.second.getId();
420 void MacroMakerSupervisor::writeData(
421 HttpXmlDocument& xmldoc,
423 const std::string &username)
425 __SUP_COUT__<<
"MacroMaker writing..." << __E__;
427 std::string Address = CgiDataUtilities::getData(cgi,
"Address");
428 std::string Data = CgiDataUtilities::getData(cgi,
"Data");
429 std::string interfaceIndexArray = CgiDataUtilities::getData(cgi,
"interfaceIndex");
430 std::string supervisorIndexArray = CgiDataUtilities::getData(cgi,
"supervisorIndex");
431 std::string time = CgiDataUtilities::decodeURIComponent(
432 CgiDataUtilities::getData(cgi,
"time"));
433 std::string addressFormatStr = CgiDataUtilities::getData(cgi,
"addressFormatStr");
434 std::string dataFormatStr = CgiDataUtilities::getData(cgi,
"dataFormatStr");
436 std::string interfaces = CgiDataUtilities::postData(cgi,
"interfaces");
438 __SUP_COUT__<<
"Write Address: " << Address <<
" Data: " << Data << __E__;
439 __SUP_COUTV__(interfaces);
441 std::string command =
"w:" + Address +
":" + Data;
442 std::string format = addressFormatStr +
":" + dataFormatStr;
443 appendCommandToHistory(command,format,time,interfaces,username);
445 SOAPParameters txParameters;
446 txParameters.addParameter(
"Request",
"UniversalWrite");
447 txParameters.addParameter(
"Address",Address);
448 txParameters.addParameter(
"Data",Data);
451 __SUP_COUT__<<
"Here comes the array from multiselect box for WRITE, behold: \n"
452 << supervisorIndexArray <<
"\n" << interfaceIndexArray << __E__;
455 std::vector<std::string> interfaceIndices;
456 std::istringstream f(interfaceIndexArray);
458 while (getline(f, s,
',')) interfaceIndices.push_back(s);
459 std::vector<int> supervisorIndices;
460 std::istringstream g(supervisorIndexArray);
462 while (getline(g, t,
',')) supervisorIndices.push_back(std::stoi(t));
465 for(
unsigned int i=0; i < supervisorIndices.size(); i++)
467 unsigned int FESupervisorIndex = supervisorIndices[i];
468 std::string interfaceIndex = interfaceIndices[i];
470 txParameters.addParameter(
"InterfaceID",interfaceIndex);
472 __SUP_COUT__<<
"The index of the supervisor instance is: " << FESupervisorIndex << __E__;
473 __SUP_COUT__<<
"...and the interface ID is: " << interfaceIndex << __E__;
475 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
476 if (it == allFESupervisorInfo_.end())
478 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '" <<
479 interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n" <<
480 "The FE Index doesn't exist. Have you configured the state machine properly?" << __E__;
486 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
487 it->second.getDescriptor(),
488 "MacroMakerSupervisorRequest",
491 __SUP_COUT__ <<
"Response received: " <<
492 SOAPUtilities::translate(replyMessage) << __E__;
494 SOAPParameters rxParameters;
495 rxParameters.addParameter(
"Error");
496 SOAPUtilities::receive(replyMessage,rxParameters);
498 std::string error = rxParameters.getValue(
"Error");
499 __SUP_COUTV__(error);
504 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '" <<
505 interfaceIndex <<
":" << FESupervisorIndex <<
".' " <<
506 "Have you configured the state machine properly?\n\n" <<
511 catch(
const xdaq::exception::Exception& e)
513 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '" <<
514 interfaceIndex <<
":" << FESupervisorIndex <<
".' " <<
515 "Have you configured the state machine properly?\n\n" <<
525 void MacroMakerSupervisor::readData(HttpXmlDocument& xmldoc, cgicc::Cgicc& cgi,
const std::string &username)
527 __SUP_COUT__<<
"@@@@@@@ MacroMaker wants to read data @@@@@@@@" << __E__;
528 std::string Address = CgiDataUtilities::getData(cgi,
"Address");
529 std::string interfaceIndexArray = CgiDataUtilities::getData(cgi,
"interfaceIndex");
530 std::string supervisorIndexArray = CgiDataUtilities::getData(cgi,
"supervisorIndex");
531 std::string time = CgiDataUtilities::decodeURIComponent(
532 CgiDataUtilities::getData(cgi,
"time"));
533 std::string addressFormatStr = CgiDataUtilities::getData(cgi,
"addressFormatStr");
534 std::string dataFormatStr = CgiDataUtilities::getData(cgi,
"dataFormatStr");
536 std::string interfaces = CgiDataUtilities::postData(cgi,
"interfaces");
539 __SUP_COUT__<<
"Read Address: " << Address << __E__;
540 __SUP_COUTV__(interfaces);
542 SOAPParameters txParameters;
543 txParameters.addParameter(
"Request",
"UniversalRead");
544 txParameters.addParameter(
"Address",Address);
546 SOAPParameters rxParameters;
547 rxParameters.addParameter(
"dataResult");
548 rxParameters.addParameter(
"Error");
549 __SUP_COUT__<<
"Here comes the array from multiselect box for READ, behold: "
550 << supervisorIndexArray <<
"," << interfaceIndexArray << __E__;
554 std::vector<std::string> interfaceIndices;
555 std::istringstream f(interfaceIndexArray);
557 while (getline(f, s,
',')) interfaceIndices.push_back(s);
558 std::vector<int> supervisorIndices;
559 std::istringstream g(supervisorIndexArray);
561 while (getline(g, t,
',')) supervisorIndices.push_back(std::stoi(t));
563 for(
unsigned int i=0; i < supervisorIndices.size(); i++)
565 unsigned int FESupervisorIndex = supervisorIndices[i];
566 std::string interfaceIndex = interfaceIndices[i];
568 txParameters.addParameter(
"InterfaceID",interfaceIndex);
571 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex << __E__;
572 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
574 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
575 if (it == allFESupervisorInfo_.end())
577 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '" <<
578 interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n" <<
579 "The FE Index doesn't exist. Have you configured the state machine properly?" << __E__;
585 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
586 it->second.getDescriptor(),
587 "MacroMakerSupervisorRequest",
590 __SUP_COUT__ <<
"Response received: " <<
591 SOAPUtilities::translate(retMsg) << __E__;
595 SOAPUtilities::receive(retMsg,rxParameters);
597 std::string error = rxParameters.getValue(
"Error");
598 __SUP_COUTV__(error);
603 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '" <<
604 interfaceIndex <<
":" << FESupervisorIndex <<
".' " <<
605 "Have you configured the state machine properly?\n\n" <<
610 catch(
const xdaq::exception::Exception& e)
612 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '" <<
613 interfaceIndex <<
":" << FESupervisorIndex <<
".' " <<
614 "Have you configured the state machine properly?\n\n" <<
619 std::string dataReadResult = rxParameters.getValue(
"dataResult");
620 __SUP_COUT__<<
"Data reading result received: " << dataReadResult << __E__;
621 xmldoc.addTextElementToData(
"readData",dataReadResult);
622 std::string command =
"r:" + Address +
":" + dataReadResult;
623 std::string format = addressFormatStr +
":" + dataFormatStr;
624 appendCommandToHistory(command,format,time,interfaces,username);
629 void MacroMakerSupervisor::createMacro(HttpXmlDocument& xmldoc, cgicc::Cgicc& cgi,
const std::string &username)
631 __SUP_COUT__<<
"MacroMaker wants to create a macro!!!!!!!!!" << __E__;
632 std::string Name = CgiDataUtilities::postData(cgi,
"Name");
633 std::string Sequence = CgiDataUtilities::postData(cgi,
"Sequence");
634 std::string Time = CgiDataUtilities::postData(cgi,
"Time");
635 std::string Notes = CgiDataUtilities::decodeURIComponent(
636 CgiDataUtilities::postData(cgi,
"Notes"));
637 std::string isMacroPublic = CgiDataUtilities::getData(cgi,
"isPublic");
638 std::string isMacroLSBF = CgiDataUtilities::getData(cgi,
"isLSBF");
641 __SUP_COUTV__(Sequence);
642 __SUP_COUTV__(Notes);
644 __SUP_COUTV__(isMacroPublic);
645 __SUP_COUTV__(isMacroLSBF);
647 __SUP_COUTV__(MACROS_DB_PATH);
649 std::string fileName = Name +
".dat";
650 std::string fullPath;
651 if (isMacroPublic ==
"true") fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
652 else fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
654 __SUP_COUTV__(fullPath);
656 std::ofstream macrofile (fullPath.c_str());
657 if (macrofile.is_open())
660 macrofile <<
"\"name\":\"" << Name <<
"\",\n";
661 macrofile <<
"\"sequence\":\"" << Sequence <<
"\",\n";
662 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
663 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
664 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
665 macrofile <<
"}@" << __E__;
669 __SUP_COUT__<<
"Unable to open file" << __E__;
680 void MacroMakerSupervisor::loadMacro(
681 const std::string& macroName,
682 std::string& macroString,
683 const std::string &username )
685 __SUP_COUTV__(macroName);
688 std::string fullPath, line;
690 for(
unsigned int i=0;i<2;++i)
693 fullPath = (std::string)MACROS_DB_PATH + username +
"/";
695 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
697 fullPath += macroName +
".dat";
698 __SUP_COUTV__(fullPath);
700 std::ifstream read (fullPath.c_str());
703 while (! read.eof() )
713 __SUP_COUT__<<
"Unable to open file: " << fullPath << __E__;
717 if(macroString !=
"")
break;
720 if(macroString ==
"")
722 __SUP_SS__<<
"Unable to locate file for macro '" << macroName <<
723 "'... does it exist?" << __E__;
725 ss <<
" Attempted username was '" << username <<
".'" << __E__;
729 __SUP_COUTV__(macroString);
733 void MacroMakerSupervisor::loadMacros(HttpXmlDocument& xmldoc,
const std::string &username)
737 std::string returnStr =
"";
738 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
739 if ((dir = opendir (fullPath.c_str())) != NULL)
742 while ((ent = readdir (dir)) != NULL)
745 if ((
unsigned)strlen(ent->d_name) > 4)
748 std::ifstream read (((fullPath + (std::string)ent->d_name)).c_str());
751 std::stringstream buffer;
752 while (! read.eof() )
758 returnStr += buffer.str();
763 __SUP_COUT__<<
"Unable to open file" << __E__;
766 std::string returnMacroStr = returnStr.substr(0, returnStr.size()-1);
768 __SUP_COUT__<<
"Loading existing macros! " << returnMacroStr << __E__;
771 xmldoc.addTextElementToData(
"returnMacroStr",returnMacroStr);
775 __SUP_COUT__<<
"Looping through privateMacros folder failed! Wrong directory" << __E__;
777 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
779 if ((dir = opendir (fullPath.c_str())) != NULL)
782 while ((ent = readdir (dir)) != NULL)
785 if ((
unsigned)strlen(ent->d_name) > 4)
788 std::ifstream read (((fullPath + (std::string)ent->d_name)).c_str());
791 std::stringstream buffer;
792 while (! read.eof() )
798 returnStr += buffer.str();
802 __SUP_COUT__<<
"Unable to open file" << __E__;
805 std::string returnPublicStr = returnStr.substr(0, returnStr.size()-1);
806 __SUP_COUT__<<
"Loading existing public macros: " << returnPublicStr << __E__;
808 xmldoc.addTextElementToData(
"returnPublicStr",returnPublicStr);
812 __SUP_COUT__ << fullPath << __E__;
813 __SUP_COUT__<<
"Looping through MacroData folder failed! Wrong directory" << __E__;
819 void MacroMakerSupervisor::appendCommandToHistory(std::string Command,
820 std::string Format, std::string Time, std::string Interfaces,
const std::string &username)
822 std::string fileName =
"history.hist";
823 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
824 __SUP_COUT__ << fullPath << __E__;
825 std::ofstream histfile (fullPath.c_str(),std::ios::app);
826 if (histfile.is_open())
829 histfile <<
"\"Command\":\"" << Command <<
"\",\n";
830 histfile <<
"\"Format\":\"" << Format <<
"\",\n";
831 histfile <<
"\"Time\":\"" << Time <<
"\",\n";
832 histfile <<
"\"Interfaces\":\"" << Interfaces <<
"\"\n";
833 histfile <<
"}#" << __E__;
837 __SUP_COUT__<<
"Unable to open history.hist" << __E__;
841 void MacroMakerSupervisor::loadHistory(HttpXmlDocument& xmldoc,
const std::string &username)
843 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"history.hist";
845 std::ifstream read (fileName.c_str());
846 __SUP_COUT__<< fileName << __E__;
852 unsigned long long fileSz, i = 0, MAX_HISTORY_SIZE = 100000;
857 read.seekg(0, std::ios::end);
858 fileSz = read.tellg();
859 returnStr =
new char[fileSz+1];
860 returnStr[fileSz] =
'\0';
861 read.seekg(0, std::ios::beg);
865 read.read(returnStr,fileSz);
870 if(fileSz > MAX_HISTORY_SIZE)
872 i = fileSz - MAX_HISTORY_SIZE;
874 if(returnStr[i] ==
'#')
878 if(i > fileSz) i = fileSz;
881 FILE *fp = fopen(fileName.c_str(),
"w");
884 __SS__ <<
"Big problem with macromaker history file: " << fileName << __E__;
887 fwrite(&returnStr[i],fileSz-i,1,fp);
891 __SUP_COUT__<<
"Loading user history! " << __E__;
894 returnStr[fileSz-2] =
'\0';
896 xmldoc.addTextElementToData(
"returnHistStr",&returnStr[i]);
903 __SUP_COUT__<<
"Unable to open history.hist" << __E__;
908 void MacroMakerSupervisor::deleteMacro(HttpXmlDocument& xmldoc,cgicc::Cgicc& cgi,
const std::string &username)
910 std::string MacroName = CgiDataUtilities::getData(cgi,
"MacroName");
911 std::string isMacroPublic = CgiDataUtilities::getData(cgi,
"isPublic");
914 std::string fileName = MacroName +
".dat";
915 std::string fullPath;
916 if (isMacroPublic ==
"true") fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
917 else fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
919 __SUP_COUT__<< fullPath << __E__;
921 std::remove(fullPath.c_str());
922 __SUP_COUT__ <<
"Successfully deleted " << MacroName;
923 xmldoc.addTextElementToData(
"deletedMacroName",MacroName);
927 void MacroMakerSupervisor::editMacro(HttpXmlDocument& xmldoc, cgicc::Cgicc& cgi,
const std::string &username)
929 std::string oldMacroName = CgiDataUtilities::postData(cgi,
"oldMacroName");
930 std::string newMacroName = CgiDataUtilities::postData(cgi,
"newMacroName");
931 std::string Sequence = CgiDataUtilities::postData(cgi,
"Sequence");
932 std::string Time = CgiDataUtilities::postData(cgi,
"Time");
933 std::string Notes = CgiDataUtilities::decodeURIComponent(
934 CgiDataUtilities::postData(cgi,
"Notes"));
936 std::string isMacroPublic = CgiDataUtilities::getData(cgi,
"isPublic");
937 std::string isMacroLSBF = CgiDataUtilities::getData(cgi,
"isLSBF");
939 __SUP_COUTV__(oldMacroName);
940 __SUP_COUTV__(newMacroName);
941 __SUP_COUTV__(Sequence);
942 __SUP_COUTV__(Notes);
944 __SUP_COUTV__(isMacroPublic);
945 __SUP_COUTV__(isMacroLSBF);
947 __SUP_COUTV__(MACROS_DB_PATH);
949 std::string fileName = oldMacroName +
".dat";
950 std::string fullPath;
951 if (isMacroPublic ==
"true") fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
952 else fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
954 __SUP_COUTV__(fullPath);
956 std::ofstream macrofile (fullPath.c_str());
957 if (macrofile.is_open())
960 macrofile <<
"\"name\":\"" << newMacroName <<
"\",\n";
961 macrofile <<
"\"sequence\":\"" << Sequence <<
"\",\n";
962 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
963 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
964 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
965 macrofile <<
"}@" << __E__;
969 __SUP_COUT__<<
"Unable to open file" << __E__;
971 if(oldMacroName != newMacroName)
974 result = rename((MACROS_DB_PATH + username +
"/" + oldMacroName +
".dat").c_str(), (MACROS_DB_PATH + username +
"/" + newMacroName +
".dat").c_str());
976 xmldoc.addTextElementToData(
"newMacroName",newMacroName);
978 xmldoc.addTextElementToData(
"newMacroName",
"ERROR");
983 void MacroMakerSupervisor::clearHistory(
const std::string &username)
985 std::string fileName =
"history.hist";
986 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
988 std::remove(fullPath.c_str());
989 __SUP_COUT__<<
"Successfully deleted " << fullPath;
993 void MacroMakerSupervisor::exportFEMacro(HttpXmlDocument& xmldoc, cgicc::Cgicc& cgi,
994 const std::string &username)
996 std::string macroName = CgiDataUtilities::getData(cgi,
"MacroName");
997 std::string pluginName = CgiDataUtilities::getData(cgi,
"PluginName");
998 std::string macroSequence = CgiDataUtilities::postData(cgi,
"MacroSequence");
999 std::string macroNotes = CgiDataUtilities::decodeURIComponent(
1000 CgiDataUtilities::postData(cgi,
"MacroNotes"));
1002 __SUP_COUTV__(pluginName);
1003 __SUP_COUTV__(macroName);
1004 __SUP_COUTV__(macroSequence);
1007 for(
unsigned int i=0;i<macroNotes.length();++i)
1008 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
1009 macroNotes[i] =
' ';
1010 __SUP_COUTV__(macroNotes);
1012 std::stringstream ss(macroSequence);
1013 std::string command;
1014 std::vector<std::string> commands;
1016 while (getline(ss, command,
',')) commands.push_back(command);
1018 __SUP_COUTV__(StringMacros::vectorToString(commands));
1020 std::map<std::string ,std::set<std::string> >
1021 specialsCodeMap = CodeEditor::getSpecialsMap();
1024 auto specialsCodeMapIt = specialsCodeMap.find(CodeEditor::SPECIAL_TYPE_FEInterface);
1025 if(specialsCodeMapIt == specialsCodeMap.end())
1027 __SS__ <<
"Could not find any FE Interface plugins in source code. Does MacroMaker " <<
1028 "have access to the source code? Check that the Supervisor context places MacroMaker in a " <<
1029 "location with access to the source code." << __E__;
1034 std::string headerFile = pluginName +
".h";
1035 std::string sourceFile = pluginName +
"_interface.cc";
1036 bool foundHeaderFile =
false;
1037 bool foundSourceFile =
false;
1038 for(
const auto& filePath : specialsCodeMapIt->second)
1040 if(!foundHeaderFile &&
1041 filePath.find(headerFile) != std::string::npos)
1043 foundHeaderFile =
true;
1044 headerFile = filePath;
1045 __SUP_COUT__ <<
"found headerFile=" << filePath << __E__;
1047 if(!foundSourceFile &&
1048 filePath.find(sourceFile) != std::string::npos)
1050 foundSourceFile =
true;
1051 sourceFile = filePath;
1052 __SUP_COUT__ <<
"found sourceFile=" << filePath << __E__;
1055 if(foundSourceFile && foundHeaderFile)
break;
1058 if(!foundHeaderFile)
1060 __SS__ <<
"Could not find the header file for the FE Interface plugins at '" <<
1061 headerFile <<
".' Does MacroMaker " <<
1062 "have access to the source code? Check that the Supervisor context places MacroMaker in a " <<
1063 "location with access to the source code." << __E__;
1066 if(!foundSourceFile)
1068 __SS__ <<
"Could not find the source file for the FE Interface plugins at '" <<
1069 sourceFile <<
".' Does MacroMaker " <<
1070 "have access to the source code? Check that the Supervisor context places MacroMaker in a " <<
1071 "location with access to the source code." << __E__;
1084 char timeBuffer[100];
1087 struct tm * timeinfo;
1090 timeinfo = localtime(&rawtime);
1092 strftime(timeBuffer,100,
"%b-%d-%Y %I:%M:%S",timeinfo);
1095 std::string contents;
1100 CodeEditor::readFile(sourceFile,contents);
1104 xmldoc.addTextElementToData(
"sourceFile",sourceFile);
1105 xmldoc.addTextElementToData(
"headerFile",headerFile);
1108 if(contents.find(pluginName +
"::" + macroName) !=
1111 __SS__ <<
"The function definition '" << (pluginName +
"::" + macroName) <<
1112 "(...)' already exists in the source file '" << sourceFile <<
1113 ".' Duplicate functions are not allowed - please rename the macro or modify the source file." << __E__;
1119 std::stringstream codess;
1120 std::set<std::string> inArgNames, outArgNames;
1121 createCode(codess,commands,
"\t" ,
true ,
1122 &inArgNames,&outArgNames);
1123 __SUP_COUTV__(StringMacros::setToString(inArgNames));
1124 __SUP_COUTV__(StringMacros::setToString(outArgNames));
1128 auto insertPos = contents.find(pluginName +
"::" + pluginName);
1129 if(insertPos == std::string::npos)
1131 __SS__ <<
"Could not find the code insert position in the source file '" <<
1132 sourceFile <<
".' The FE plugin class constructor must be '" <<
1133 pluginName <<
":" << pluginName <<
"' - is this the case?" << __E__;
1136 __SUP_COUTV__(insertPos);
1138 insertPos = contents.find(
"{",insertPos);
1139 if(insertPos == std::string::npos)
1141 __SS__ <<
"Could not find the code insert position in the source file '" <<
1142 sourceFile <<
".' The FE plugin class constructor must begin with '{" <<
1143 "' - is this the case?" << __E__;
1147 __SUP_COUTV__(insertPos);
1149 insert =
"\n\t//registration of FEMacro '" + macroName +
"' generated, " +
1150 timeBuffer +
", by '" + username +
"' using MacroMaker.\n\t" +
1151 "FEVInterface::registerFEMacroFunction(\"" + macroName +
"\",//feMacroName \n\t\t" +
1152 "static_cast<FEVInterface::frontEndMacroFunction_t>(&" +
1153 pluginName +
"::" + macroName +
"), //feMacroFunction \n\t\t" +
1154 "std::vector<std::string>{";
1157 for(
const auto& inArg:inArgNames)
1163 insert +=
"\"" + inArg +
"\"";
1166 insert +=
"}, //namesOfInputArgs \n\t\t";
1167 insert +=
"std::vector<std::string>{";
1170 for(
const auto& outArg:outArgNames)
1176 insert +=
"\"" + outArg +
"\"";
1179 insert +=
"}, //namesOfOutputArgs \n\t\t";
1180 insert +=
"1); //requiredUserPermissions \n\n";
1182 __SUP_COUTV__(insert);
1183 contents = contents.substr(0,insertPos) + insert + contents.substr(insertPos);
1188 auto insertPos = contents.rfind(
"DEFINE_OTS_INTERFACE");
1189 if(insertPos == std::string::npos)
1191 __SS__ <<
"Could not find the code insert position in the source file '" <<
1192 sourceFile <<
".' The FE plugin class must end with a 'DEFINE_OTS_INTERFACE(" <<
1193 pluginName <<
")' - is this the case?" << __E__;
1196 __SUP_COUTV__(insertPos);
1198 insert =
"\n//========================================================================================================================\n//" +
1200 "//\tFEMacro '" + macroName +
"' generated, " +
1201 timeBuffer +
", by '" + username +
"' using MacroMaker.\n" +
1202 "//\tMacro Notes: " + macroNotes +
"\n" +
1203 "void " + pluginName +
"::" + macroName +
"(__ARGS__)\n{\n\t" +
1204 "__CFG_COUT__ << \"# of input args = \" << argsIn.size() << __E__; \n\t" +
1205 "__CFG_COUT__ << \"# of output args = \" << argsOut.size() << __E__; \n\t" +
1206 "for(auto &argIn:argsIn) \n\t\t" +
1207 "__CFG_COUT__ << argIn.first << \": \" << argIn.second << __E__; \n\n\t" +
1208 "//macro commands section \n" +
1211 "for(auto &argOut:argsOut) \n\t\t" +
1212 "__CFG_COUT__ << argOut.first << \": \" << argOut.second << __E__; \n\n" +
1213 "} //end " + macroName +
"()\n\n";
1216 CodeEditor::writeFile(sourceFile,contents,insertPos,insert);
1223 CodeEditor::readFile(headerFile,contents);
1229 auto insertPos = contents.rfind(
"};");
1230 if(insertPos == std::string::npos)
1232 __SS__ <<
"Could not find the code insert position in the header file '" <<
1233 headerFile <<
".' The FE plugin class must end with a '};' - is this the case?" << __E__;
1237 __SUP_COUTV__(insertPos);
1239 insert =
"\npublic: // FEMacro '" + macroName +
"' generated, " +
1240 timeBuffer +
", by '" + username +
"' using MacroMaker.\n\t" +
1241 "void " + macroName +
1244 __SUP_COUTV__(insert);
1245 CodeEditor::writeFile(headerFile,contents,insertPos,insert);
1252 void MacroMakerSupervisor::exportMacro(HttpXmlDocument& xmldoc, cgicc::Cgicc& cgi,
const std::string &username)
1254 std::string macroName = CgiDataUtilities::getData(cgi,
"MacroName");
1255 std::string macroSequence = CgiDataUtilities::postData(cgi,
"MacroSequence");
1256 std::string macroNotes = CgiDataUtilities::decodeURIComponent(
1257 CgiDataUtilities::postData(cgi,
"MacroNotes"));
1259 __SUP_COUTV__(macroName);
1260 __SUP_COUTV__(macroSequence);
1263 for(
unsigned int i=0;i<macroNotes.length();++i)
1264 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
1265 macroNotes[i] =
' ';
1266 __SUP_COUTV__(macroNotes);
1268 std::stringstream ss(macroSequence);
1269 std::string command;
1270 std::vector<std::string> commands;
1272 while (getline(ss, command,
',')) commands.push_back(command);
1274 std::string fileName = macroName +
".cc";
1277 std::string fullPath = (std::string)MACROS_EXPORT_PATH + username +
"/" + fileName;
1278 __SUP_COUT__ << fullPath << __E__;
1279 std::ofstream exportFile (fullPath.c_str(),std::ios::trunc);
1280 if (exportFile.is_open())
1282 exportFile <<
"//Generated Macro Name:\t" << macroName <<
"\n";
1283 exportFile <<
"//Macro Notes: " << macroNotes <<
"\n";
1287 struct tm * timeinfo;
1291 timeinfo = localtime(&rawtime);
1293 strftime(buffer,100,
"%b-%d-%Y %I:%M:%S",timeinfo);
1294 exportFile <<
"//Generated Time: \t\t" << buffer <<
"\n";
1297 exportFile <<
"//Paste this whole file into an interface to transfer Macro functionality.\n";
1299 createCode(exportFile,commands);
1303 xmldoc.addTextElementToData(
"ExportFile",fullPath);
1306 __SUP_COUT__ <<
"Unable to open file" << __E__;
1312 void MacroMakerSupervisor::createCode(std::ostream& out,
1313 const std::vector<std::string>& commands,
1314 const std::string& tabOffset,
1316 std::set<std::string>* inArgNames,
1317 std::set<std::string>* outArgNames)
1320 std::set<std::string > argInHasBeenInitializedSet;
1321 bool addressIsVariable, dataIsVariable;
1323 out << tabOffset <<
"{";
1325 out <<
"\n" << tabOffset <<
"\t" <<
"char *address \t= new char[universalAddressSize_]{0}; //create address buffer of interface size and init to all 0";
1326 out <<
"\n" << tabOffset <<
"\t" <<
"char *data \t\t= new char[universalDataSize_]{0}; //create data buffer of interface size and init to all 0";
1328 out <<
"\n" << tabOffset <<
"\t" <<
"uint64_t macroAddress; //create macro address buffer (size 8 bytes)";
1329 out <<
"\n" << tabOffset <<
"\t" <<
"uint64_t macroData; //create macro address buffer (size 8 bytes)";
1331 out <<
"\n" << tabOffset <<
"\t" <<
"std::map<std::string /*arg name*/,uint64_t /*arg val*/> macroArgs; //create map from arg name to 64-bit number";
1334 for(
unsigned int i = 0; i < commands.size(); i++)
1336 std::stringstream sst(commands[i]);
1338 std::vector<std::string> oneCommand;
1339 while (getline(sst, tokens,
':')) oneCommand.push_back(tokens);
1340 while(oneCommand.size() < 4) oneCommand.push_back(
"");
1342 __SUP_COUTV__(StringMacros::vectorToString(oneCommand));
1367 addressIsVariable = isArgumentVariable(oneCommand[2]);
1368 dataIsVariable = isArgumentVariable(oneCommand[3]);
1370 __SUP_COUTV__(addressIsVariable);
1371 __SUP_COUTV__(dataIsVariable);
1373 out <<
"\n\n" << tabOffset <<
"\t// command-#" << i <<
": ";
1375 if(oneCommand[1][0] ==
'w' || oneCommand[1][0] ==
'r')
1377 if (oneCommand[1][0] ==
'w')
1379 else if (oneCommand[1][0] ==
'r')
1382 if(addressIsVariable)
1383 out << oneCommand[2];
1385 out <<
"0x" << oneCommand[2];
1386 out <<
" /*address*/,";
1389 out << oneCommand[3] <<
" /*data*/";
1390 else if (oneCommand[1][0] ==
'w')
1391 out <<
"0x" << oneCommand[3] <<
" /*data*/";
1392 else if (oneCommand[1][0] ==
'r')
1396 else if (oneCommand[1][0] ==
'd')
1398 out <<
"delay(" << oneCommand[2] <<
");\n";
1399 out << tabOffset <<
"\t" <<
"__CFG_COUT__ << \"Sleeping for... \" << " << oneCommand[2] <<
1400 " << \" milliseconds \" << __E__;\n";
1401 out << tabOffset <<
"\t" <<
"usleep(" << oneCommand[2] <<
"*1000 /* microseconds */);\n";
1406 __SS__ <<
"FATAL ERROR: Unknown command '" << oneCommand[1] <<
1407 "'... command is not w, r or d" << __E__;
1413 if(addressIsVariable)
1415 if(argInHasBeenInitializedSet.find(oneCommand[2]) ==
1416 argInHasBeenInitializedSet.end())
1418 argInHasBeenInitializedSet.emplace(oneCommand[2]);
1423 out << tabOffset <<
"\t" <<
1425 oneCommand[2] <<
"\"] = theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode(" <<
1426 "\n" << tabOffset <<
"\t\t\"" <<
1427 oneCommand[2] <<
"\").getValue<uint64_t>();";
1431 if(inArgNames) inArgNames->emplace(oneCommand[2]);
1434 out << tabOffset <<
"\t" <<
1436 oneCommand[2] <<
"\"] = __GET_ARG_IN__(\"" <<
1437 oneCommand[2] <<
"\", uint64_t);";
1440 out <<
"\t//get macro address argument";
1441 out <<
"\n" << tabOffset <<
"\tmemcpy(address,¯oArgs[\"" <<
1442 oneCommand[2] <<
"\"],8); //copy macro address argument to buffer";
1447 out << tabOffset <<
"\t" <<
1448 "macroAddress = 0x" << oneCommand[2] <<
"; memcpy(address,¯oAddress,8);" <<
1449 "\t//copy macro address to buffer";
1454 if (oneCommand[1] ==
"w")
1458 if(argInHasBeenInitializedSet.find(oneCommand[3]) ==
1459 argInHasBeenInitializedSet.end())
1461 argInHasBeenInitializedSet.emplace(oneCommand[3]);
1466 if(inArgNames) inArgNames->emplace(oneCommand[3]);
1469 out <<
"\n" << tabOffset <<
"\t" <<
1471 oneCommand[3] <<
"\"] = __GET_ARG_IN__(\"" <<
1472 oneCommand[3] <<
"\", uint64_t); //initialize from input arguments";
1479 out <<
"\n" << tabOffset <<
"\t" <<
1481 oneCommand[3] <<
"\"] = theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode(" <<
1482 "\n" << tabOffset <<
"\t\t\"" <<
1483 oneCommand[3] <<
"\").getValue<uint64_t>(); //initialize from configuration tree";
1486 out <<
"\t//get macro data argument";
1487 out <<
"\n" << tabOffset <<
"\tmemcpy(data,¯oArgs[\"" <<
1488 oneCommand[3] <<
"\"],8); //copy macro data argument to buffer";
1492 out <<
"\n" << tabOffset <<
"\t" <<
1493 "macroData = 0x" << oneCommand[3] <<
"; memcpy(data,¯oData,8);" <<
1494 "\t//copy macro data to buffer";
1496 out <<
"\n" << tabOffset <<
"\t" <<
1497 "universalWrite(address,data);";
1501 out <<
"\n" << tabOffset <<
"\t" <<
1502 "universalRead(address,data);";
1505 std::string outputArgName;
1508 outputArgName = oneCommand[3];
1512 sprintf(str,
"outArg%d",i);
1513 outputArgName = str;
1515 __SUP_COUTV__(outputArgName);
1517 out << tabOffset <<
"\t" <<
1518 "memcpy(¯oArgs[\"" <<
1519 outputArgName <<
"\"],data,8); //copy buffer to argument map";
1523 out <<
"\n" << tabOffset <<
"\t" <<
1524 "__SET_ARG_OUT__(\"" <<
1525 outputArgName <<
"\",macroArgs[\"" <<
1526 outputArgName <<
"\"]); //update output argument result";
1528 if(outArgNames) outArgNames->emplace(outputArgName);
1529 argInHasBeenInitializedSet.emplace(outputArgName);
1533 out <<
"\n\n" << tabOffset <<
"\tdelete[] address; //free the memory";
1534 out <<
"\n" << tabOffset <<
"\tdelete[] data; //free the memory";
1535 out <<
"\n" << tabOffset <<
"}";
1537 __SUP_COUT__ <<
"Done with code generation." << __E__;
1543 bool MacroMakerSupervisor::isArgumentVariable(
const std::string &argumentString)
1545 for(
unsigned int i=0; i<argumentString.length(); ++i)
1548 if(!((argumentString[i] >=
'0' && argumentString[i] <=
'9') ||
1549 (argumentString[i] >=
'a' && argumentString[i] <=
'f')||
1550 (argumentString[i] >=
'A' && argumentString[i] <=
'F')))
1565 std::string MacroMakerSupervisor::generateHexArray(
const std::string &sourceHexString,
1568 std::stringstream retSs;
1570 std::string srcHexStr = sourceHexString;
1571 __SUP_COUT__<<
"Translating: \n";
1572 __SUP_COUT__ << srcHexStr << __E__;
1574 if(srcHexStr.size()%2)
1575 srcHexStr =
"0" + srcHexStr;
1577 numOfBytes = srcHexStr.size()/2;
1578 retSs <<
"[" << numOfBytes <<
"] = {";
1580 for(
int i=0; i<numOfBytes*2; i+=2)
1583 if(!((srcHexStr[i] >=
'0' && srcHexStr[i] <=
'9') ||
1584 (srcHexStr[i] >=
'a' && srcHexStr[i] <=
'f')||
1585 (srcHexStr[i] >=
'A' && srcHexStr[i] <=
'F')) ||
1586 !((srcHexStr[i+1] >=
'0' && srcHexStr[i+1] <=
'9') ||
1587 (srcHexStr[i+1] >=
'a' && srcHexStr[i+1] <=
'f')||
1588 (srcHexStr[i+1] >=
'A' && srcHexStr[i+1] <=
'F'))
1595 if(i != 0) retSs <<
", ";
1597 srcHexStr[srcHexStr.size()-1-i-1] <<
1598 srcHexStr[srcHexStr.size()-1-i];
1602 __SUP_COUT__ << retSs.str() << __E__;
1608 void MacroMakerSupervisor::runFEMacro(HttpXmlDocument& xmldoc, cgicc::Cgicc& cgi)
1610 __SUP_COUT__<< __E__;
1612 unsigned int feSupervisorID = CgiDataUtilities::getDataAsInt(cgi,
"feSupervisorID");
1613 std::string feUID = CgiDataUtilities::getData(cgi,
"feUID");
1614 std::string macroName = CgiDataUtilities::getData(cgi,
"macroName");
1615 std::string inputArgs = CgiDataUtilities::postData(cgi,
"inputArgs");
1616 std::string outputArgs = CgiDataUtilities::postData(cgi,
"outputArgs");
1618 __SUP_COUTV__(feSupervisorID);
1619 __SUP_COUTV__(feUID);
1620 __SUP_COUTV__(macroName);
1621 __SUP_COUTV__(inputArgs);
1622 __SUP_COUTV__(outputArgs);
1625 SOAPParameters txParameters;
1626 txParameters.addParameter(
"Request",
"RunInterfaceMacro");
1627 txParameters.addParameter(
"InterfaceID", feUID);
1628 txParameters.addParameter(
"feMacroName", macroName);
1629 txParameters.addParameter(
"inputArgs", inputArgs);
1630 txParameters.addParameter(
"outputArgs", outputArgs);
1632 SOAPParameters rxParameters;
1633 rxParameters.addParameter(
"success");
1634 rxParameters.addParameter(
"outputArgs");
1639 auto supervisorDescriptorPairIt = allFESupervisorInfo_.find(feSupervisorID);
1640 if(supervisorDescriptorPairIt == allFESupervisorInfo_.end())
1642 __SS__ <<
"Targeted Supervisor Descriptor was not found. Attempted target " <<
1643 "was UID=" << feUID <<
" at feSupervisorID=" << feSupervisorID <<
"." << __E__;
1644 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1645 xmldoc.addTextElementToData(
"Error",ss.str());
1650 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
1651 supervisorDescriptorPairIt->second.getDescriptor(),
1652 "MacroMakerSupervisorRequest",
1654 SOAPUtilities::receive(retMsg, rxParameters);
1656 __SUP_COUT__ <<
"Received it " << __E__;
1658 bool success = rxParameters.getValue(
"success") ==
"1";
1659 outputArgs = rxParameters.getValue(
"outputArgs");
1661 __SUP_COUT__ <<
"rx success = " << success << __E__;
1662 __SUP_COUT__ <<
"outputArgs = " << outputArgs << __E__;
1666 __SS__ <<
"Attempted FE Macro Failed. Attempted target " <<
1667 "was UID=" << feUID <<
" at feSupervisorID=" << feSupervisorID <<
"." << __E__;
1668 ss <<
"\n\n The error was:\n\n" << outputArgs << __E__;
1669 __SUP_COUT_ERR__ <<
"\n" << ss.str();
1670 xmldoc.addTextElementToData(
"Error",ss.str());
1678 std::istringstream inputStream(outputArgs);
1679 std::string splitVal, argName, argValue;
1680 while (getline(inputStream, splitVal,
';'))
1682 std::istringstream pairInputStream(splitVal);
1683 getline(pairInputStream, argName,
',');
1684 getline(pairInputStream, argValue,
',');
1685 xmldoc.addTextElementToData(
"outputArgs_name",argName);
1686 xmldoc.addTextElementToData(
"outputArgs_value",argValue);
1687 __SUP_COUT__ << argName <<
": " << argValue << __E__;
1694 void MacroMakerSupervisor::getFEMacroList(HttpXmlDocument& xmldoc,
const std::string &username)
1696 __SUP_COUT__<<
"Getting FE Macro list" << __E__;
1698 SOAPParameters txParameters;
1699 txParameters.addParameter(
"Request",
"GetInterfaceMacros");
1701 SOAPParameters rxParameters;
1702 rxParameters.addParameter(
"FEMacros");
1704 std::string oneInterface;
1705 std::string rxFEMacros;
1710 for(
auto &appInfo:allFESupervisorInfo_)
1712 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId() <<
1713 " name = " << appInfo.second.getName() << __E__;
1715 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
1716 appInfo.second.getDescriptor(),
1717 "MacroMakerSupervisorRequest",
1719 SOAPUtilities::receive(retMsg, rxParameters);
1721 rxFEMacros = rxParameters.getValue(
"FEMacros");
1723 __SUP_COUT__ <<
"FE Macros received: \n" << rxFEMacros << __E__;
1725 std::istringstream allInterfaces(rxFEMacros);
1726 while (std::getline(allInterfaces, oneInterface))
1730 xmldoc.addTextElementToData(
"FEMacros",oneInterface);
1736 loadMacros(xmldoc, username);