1 #include "otsdaq-utilities/MacroMaker/MacroMakerSupervisor.h"
3 #include "otsdaq/CodeEditor/CodeEditor.h"
4 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
5 #include "otsdaq/FECore/FEVInterface.h"
13 #include "otsdaq/TableCore/TableGroupKey.h"
15 #define MACROS_DB_PATH std::string(__ENV__("SERVICE_DATA_PATH")) + "/MacroData/"
16 #define MACROS_HIST_PATH std::string(__ENV__("SERVICE_DATA_PATH")) + "/MacroHistory/"
17 #define MACROS_EXPORT_PATH std::string("/MacroExport/")
19 #define SEQUENCE_FILE_NAME \
20 std::string(__ENV__("SERVICE_DATA_PATH")) + "/OtsWizardData/sequence.dat"
21 #define SEQUENCE_OUT_FILE_NAME \
22 std::string(__ENV__("SERVICE_DATA_PATH")) + "/OtsWizardData/sequence.out"
27 #define __MF_SUBJECT__ "MacroMaker"
33 : CoreSupervisorBase(stub)
35 __SUP_COUT__ <<
"Constructing..." << __E__;
40 mkdir(((std::string)MACROS_DB_PATH).c_str(), 0755);
41 mkdir(((std::string)MACROS_HIST_PATH).c_str(), 0755);
42 mkdir((__ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH).c_str(), 0755);
45 &MacroMakerSupervisor::frontEndCommunicationRequest,
50 if(CorePropertySupervisorBase::allSupervisorInfo_.isMacroMakerMode())
52 __SUP_COUT__ <<
"Starting constructor for Macro Maker mode." << __E__;
54 xgi::bind(
this, &MacroMakerSupervisor::requestIcons,
"requestIcons");
55 xgi::bind(
this, &MacroMakerSupervisor::verification,
"Verify");
56 xgi::bind(
this, &MacroMakerSupervisor::tooltipRequest,
"TooltipRequest");
57 xgi::bind(
this, &MacroMakerSupervisor::requestWrapper,
"Request");
59 __SUP_COUT__ <<
"Completed constructor for Macro Maker mode." << __E__;
62 __SUP_COUT__ <<
"Not Macro Maker only mode." << __E__;
67 __SUP_COUT__ <<
"Constructed." << __E__;
71 MacroMakerSupervisor::~MacroMakerSupervisor(
void) { destroy(); }
74 void MacroMakerSupervisor::init(
void)
79 allFESupervisorInfo_ = SupervisorInfoMap( allSupervisorInfo_.getAllFETypeSupervisorInfo() );
84 void MacroMakerSupervisor::destroy(
void)
92 void MacroMakerSupervisor::forceSupervisorPropertyValues()
99 void MacroMakerSupervisor::tooltipRequest(xgi::Input* in, xgi::Output* out)
101 cgicc::Cgicc cgi(in);
103 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
106 std::string submittedSequence = CgiDataUtilities::postData(cgi,
"sequence");
109 if(securityCode_.compare(submittedSequence) != 0)
111 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!"
121 HttpXmlDocument xmldoc;
123 if(Command ==
"check")
125 WebUsers::tooltipCheckForUsername(WebUsers::DEFAULT_ADMIN_USERNAME,
127 CgiDataUtilities::getData(cgi,
"srcFile"),
128 CgiDataUtilities::getData(cgi,
"srcFunc"),
129 CgiDataUtilities::getData(cgi,
"srcId"));
131 else if(Command ==
"setNeverShow")
133 WebUsers::tooltipSetNeverShowForUsername(
134 WebUsers::DEFAULT_ADMIN_USERNAME,
136 CgiDataUtilities::getData(cgi,
"srcFile"),
137 CgiDataUtilities::getData(cgi,
"srcFunc"),
138 CgiDataUtilities::getData(cgi,
"srcId"),
139 CgiDataUtilities::getData(cgi,
"doNeverShow") ==
"1" ?
true :
false,
140 CgiDataUtilities::getData(cgi,
"temporarySilence") ==
"1" ?
true :
false);
143 __COUT__ <<
"Command Request, " << Command <<
", not recognized." << __E__;
145 xmldoc.outputXmlDocument((std::ostringstream*)out,
false,
true);
149 void MacroMakerSupervisor::verification(xgi::Input* in, xgi::Output* out)
151 cgicc::Cgicc cgi(in);
152 std::string submittedSequence = CgiDataUtilities::getData(cgi,
"code");
153 __COUT__ <<
"submittedSequence=" << submittedSequence <<
" " << time(0) << __E__;
155 std::string securityWarning =
"";
157 if(securityCode_.compare(submittedSequence) != 0)
159 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!"
161 *out <<
"Invalid code.";
167 __COUT__ <<
"*** Successfully authenticated security sequence "
168 <<
"@ " << time(0) << __E__;
173 securityWarning =
"&secure=False";
177 *out <<
"<!DOCTYPE HTML><html lang='en'><head><title>ots wiz</title>" <<
180 "<link rel='apple-touch-icon' sizes='57x57' href='/WebPath/images/otsdaqIcons/apple-icon-57x57.png'>\
181 <link rel='apple-touch-icon' sizes='60x60' href='/WebPath/images/otsdaqIcons/apple-icon-60x60.png'>\
182 <link rel='apple-touch-icon' sizes='72x72' href='/WebPath/images/otsdaqIcons/apple-icon-72x72.png'>\
183 <link rel='apple-touch-icon' sizes='76x76' href='/WebPath/images/otsdaqIcons/apple-icon-76x76.png'>\
184 <link rel='apple-touch-icon' sizes='114x114' href='/WebPath/images/otsdaqIcons/apple-icon-114x114.png'>\
185 <link rel='apple-touch-icon' sizes='120x120' href='/WebPath/images/otsdaqIcons/apple-icon-120x120.png'>\
186 <link rel='apple-touch-icon' sizes='144x144' href='/WebPath/images/otsdaqIcons/apple-icon-144x144.png'>\
187 <link rel='apple-touch-icon' sizes='152x152' href='/WebPath/images/otsdaqIcons/apple-icon-152x152.png'>\
188 <link rel='apple-touch-icon' sizes='180x180' href='/WebPath/images/otsdaqIcons/apple-icon-180x180.png'>\
189 <link rel='icon' type='image/png' sizes='192x192' href='/WebPath/images/otsdaqIcons/android-icon-192x192.png'>\
190 <link rel='icon' type='image/png' sizes='32x32' href='/WebPath/images/otsdaqIcons/favicon-32x32.png'>\
191 <link rel='icon' type='image/png' sizes='96x96' href='/WebPath/images/otsdaqIcons/favicon-96x96.png'>\
192 <link rel='icon' type='image/png' sizes='16x16' href='/WebPath/images/otsdaqIcons/favicon-16x16.png'>\
193 <link rel='manifest' href='/WebPath/images/otsdaqIcons/manifest.json'>\
194 <meta name='msapplication-TileColor' content='#ffffff'>\
195 <meta name='msapplication-TileImage' content='/ms-icon-144x144.png'>\
196 <meta name='theme-color' content='#ffffff'>"
200 <<
"<frameset col='100%' row='100%'><frame "
201 "src='/WebPath/html/MacroMakerSupervisor.html?urn="
202 << this->getApplicationDescriptor()->getLocalId() << securityWarning
203 <<
"'></frameset></html>";
207 void MacroMakerSupervisor::generateURL()
209 defaultSequence_ =
true;
212 FILE* fp = fopen((SEQUENCE_FILE_NAME).c_str(),
"r");
215 __SUP_COUT_INFO__ <<
"Sequence length file found: " << SEQUENCE_FILE_NAME
218 fgets(line, 100, fp);
219 sscanf(line,
"%d", &length);
224 defaultSequence_ =
false;
230 <<
"(Reverting to default wiz security) Sequence length file NOT found: "
231 << SEQUENCE_FILE_NAME << __E__;
235 __SUP_COUT__ <<
"Sequence length = " << length << __E__;
239 const char alphanum[] =
241 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
242 "abcdefghijklmnopqrstuvwxyz";
244 for(
int i = 0; i < length; ++i)
246 securityCode_ += alphanum[rand() % (
sizeof(alphanum) - 1)];
249 __SUP_COUT__ << __ENV__(
"HOSTNAME") <<
":" << __ENV__(
"PORT")
250 <<
"/urn:xdaq-application:lid="
251 << this->getApplicationDescriptor()->getLocalId()
252 <<
"/Verify?code=" << securityCode_ << __E__;
258 fp = fopen((SEQUENCE_OUT_FILE_NAME).c_str(),
"w");
261 fprintf(fp,
"%s", securityCode_.c_str());
265 __SUP_COUT_ERR__ <<
"Sequence output file NOT found: " << SEQUENCE_OUT_FILE_NAME
271 void MacroMakerSupervisor::requestIcons(xgi::Input* in, xgi::Output* out)
273 cgicc::Cgicc cgi(in);
275 std::string submittedSequence = CgiDataUtilities::postData(cgi,
"sequence");
278 if(securityCode_.compare(submittedSequence) != 0)
280 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match! "
286 __COUT__ <<
"***Successfully authenticated security sequence. " << time(0)
299 *out <<
"Macro Maker "
300 ",MM,0,1,icon-MacroMaker.png,/WebPath/html/"
301 "MacroMaker.html?urn=290,/"
303 ",CFG,0,1,icon-Configure.png,/WebPath/html/"
304 "FEMacroTest.html?urn=290,/"
308 std::string iconFile = std::string(__ENV__(
"USER_DATA")) +
"/MacroMakerModeIcons.dat";
309 __COUT__ <<
"Macro Maker mode user icons file: " << iconFile << __E__;
310 FILE* fp = fopen(iconFile.c_str(),
"r");
313 __COUT__ <<
"Macro Maker mode user icons loading from " << iconFile << __E__;
314 fseek(fp, 0, SEEK_END);
315 const unsigned long fileSize = ftell(fp);
316 std::string fileString(fileSize, 0);
318 if(fread(&fileString[0], 1, fileSize, fp) != fileSize)
320 __COUT_ERR__ <<
"Unable to read proper size string from icons file!" << __E__;
325 __COUTV__(fileString);
329 __COUT__ <<
"Macro Maker mode user icons file not found: " << iconFile << __E__;
336 void MacroMakerSupervisor::requestWrapper(xgi::Input* in, xgi::Output* out)
339 if(!CorePropertySupervisorBase::allSupervisorInfo_.isMacroMakerMode())
342 return CoreSupervisorBase::requestWrapper(in, out);
350 cgicc::Cgicc cgiIn(in);
352 std::string submittedSequence = CgiDataUtilities::postData(cgiIn,
"sequence");
355 if(securityCode_.compare(submittedSequence) != 0)
357 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match! "
363 __COUT__ <<
"***Successfully authenticated security sequence. " << time(0)
368 std::string requestType = CgiDataUtilities::getData(cgiIn,
"RequestType");
373 HttpXmlDocument xmlOut;
374 WebUsers::RequestUserInfo userInfo(
375 requestType, CgiDataUtilities::getOrPostData(cgiIn,
"CookieCode"));
377 CorePropertySupervisorBase::getRequestUserInfo(userInfo);
380 userInfo.username_ =
"admin";
381 userInfo.displayName_ =
"Admin";
382 userInfo.usernameWithLock_ =
"admin";
383 userInfo.activeUserSessionIndex_ = 0;
385 if(1 || !userInfo.automatedCommand_)
386 __SUP_COUT__ <<
"requestType: " << requestType << __E__;
388 if(userInfo.NonXMLRequestType_)
392 nonXmlRequest(requestType, cgiIn, *out, userInfo);
394 catch(
const std::runtime_error& e)
396 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
397 <<
"':" << e.what() << __E__;
398 __SUP_COUT_ERR__ <<
"\n" << ss.str();
399 __SUP_MOUT_ERR__ <<
"\n" << ss.str();
403 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
404 << requestType <<
".' "
405 <<
"Please check the printouts to debug." << __E__;
406 __SUP_COUT_ERR__ <<
"\n" << ss.str();
407 __SUP_MOUT_ERR__ <<
"\n" << ss.str();
416 request(requestType, cgiIn, xmlOut, userInfo);
418 catch(
const std::runtime_error& e)
420 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
421 <<
"':" << e.what() << __E__;
422 __SUP_COUT_ERR__ <<
"\n" << ss.str();
423 xmlOut.addTextElementToData(
"Error", ss.str());
427 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
428 << requestType <<
".' "
429 <<
"Please check the printouts to debug." << __E__;
430 __SUP_COUT_ERR__ <<
"\n" << ss.str();
431 xmlOut.addTextElementToData(
"Error", ss.str());
436 unsigned int occurance = 0;
437 std::string err = xmlOut.getMatchingValue(
"Error", occurance++);
440 __SUP_COUT_ERR__ <<
"'" << requestType <<
"' ERROR encountered: " << err
442 __SUP_MOUT_ERR__ <<
"'" << requestType <<
"' ERROR encountered: " << err
444 err = xmlOut.getMatchingValue(
"Error", occurance++);
449 xmlOut.outputXmlDocument((std::ostringstream*)out,
451 !userInfo.NoXmlWhiteSpace_ );
455 void MacroMakerSupervisor::request(
const std::string& requestType,
457 HttpXmlDocument& xmlOut,
458 const WebUsers::RequestUserInfo& userInfo)
try
461 std::string username =
"";
462 for(
unsigned int i = 0; i < userInfo.username_.size(); ++i)
463 if((userInfo.username_[i] >=
'a' && userInfo.username_[i] <=
'z') ||
464 (userInfo.username_[i] >=
'A' && userInfo.username_[i] <=
'Z') ||
465 (userInfo.username_[i] >=
'0' && userInfo.username_[i] <=
'9') ||
466 userInfo.username_[i] >=
'-' || userInfo.username_[i] <=
'_')
467 username += userInfo.username_[i];
469 if(username.size() < 2)
471 __SUP_SS__ <<
"Illegal username '" << userInfo.username_ <<
"' received."
476 __SUP_COUT__ <<
"User name is " << userInfo.username_ <<
"." << __E__;
477 __SUP_COUT__ <<
"User permission level for request '" << requestType <<
"' is "
478 << unsigned(userInfo.permissionLevel_) <<
"." << __E__;
481 if(requestType ==
"getPermission")
483 xmlOut.addTextElementToData(
"Permission",
484 std::to_string(
unsigned(userInfo.permissionLevel_)));
488 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
489 mkdir(macroPath.c_str(), 0755);
490 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
491 mkdir(histPath.c_str(), 0755);
492 std::string publicPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
493 mkdir(publicPath.c_str(), 0755);
494 std::string exportPath =
495 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + userInfo.username_ +
"/";
496 mkdir(exportPath.c_str(), 0755);
499 handleRequest(requestType, xmlOut, cgiIn, userInfo.username_);
501 catch(
const std::runtime_error& e)
503 __SS__ <<
"Error occurred handling request '" << requestType <<
"': " << e.what()
505 __SUP_COUT__ << ss.str();
506 xmlOut.addTextElementToData(
"Error", ss.str());
510 __SS__ <<
"Unknown error occurred handling request '" << requestType <<
"!'" << __E__;
511 __SUP_COUT__ << ss.str();
512 xmlOut.addTextElementToData(
"Error", ss.str());
516 void MacroMakerSupervisor::handleRequest(
const std::string Command,
517 HttpXmlDocument& xmldoc,
519 const std::string& username)
521 if(Command ==
"FElist")
523 else if(Command ==
"writeData")
524 writeData(xmldoc, cgi, username);
525 else if(Command ==
"readData")
526 readData(xmldoc, cgi, username);
527 else if(Command ==
"createMacro")
528 createMacro(xmldoc, cgi, username);
529 else if(Command ==
"loadMacros")
530 loadMacros(xmldoc, username);
531 else if(Command ==
"loadHistory")
532 loadHistory(xmldoc, username);
533 else if(Command ==
"deleteMacro")
534 deleteMacro(xmldoc, cgi, username);
535 else if(Command ==
"editMacro")
536 editMacro(xmldoc, cgi, username);
537 else if(Command ==
"clearHistory")
538 clearHistory(username);
539 else if(Command ==
"exportMacro")
540 exportMacro(xmldoc, cgi, username);
541 else if(Command ==
"exportFEMacro")
542 exportFEMacro(xmldoc, cgi, username);
543 else if(Command ==
"getFEMacroList")
545 getFEMacroList(xmldoc, username);
546 else if(Command ==
"runFEMacro")
548 runFEMacro(xmldoc, cgi, username);
550 xmldoc.addTextElementToData(
"Error",
"Unrecognized command '" + Command +
"'");
554 xoap::MessageReference MacroMakerSupervisor::frontEndCommunicationRequest(
555 xoap::MessageReference message)
try
557 __SUP_COUT__ <<
"FE Request received: " << SOAPUtilities::translate(message) << __E__;
559 SOAPParameters typeParameter, rxParameters;
560 typeParameter.addParameter(
"type");
561 SOAPUtilities::receive(message, typeParameter);
563 std::string type = typeParameter.getValue(
"type");
565 std::string error =
"";
567 if(type ==
"initFElist")
571 rxParameters.addParameter(
"groupName");
572 rxParameters.addParameter(
"groupKey");
573 SOAPUtilities::receive(message, rxParameters);
575 std::string groupName = rxParameters.getValue(
"groupName");
576 std::string groupKey = rxParameters.getValue(
"groupKey");
578 __SUP_COUTV__(groupName);
579 __SUP_COUTV__(groupKey);
581 ConfigurationManager cfgMgr;
582 cfgMgr.loadTableGroup(groupName, TableGroupKey(groupKey),
true);
587 const SupervisorInfoMap& feTypeSupervisors =
588 CorePropertySupervisorBase::allSupervisorInfo_.getAllFETypeSupervisorInfo();
590 ConfigurationTree appsNode =
591 cfgMgr.getNode(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME);
593 __SUP_COUT__ <<
"Number of FE Supervisors found = " << feTypeSupervisors.size()
596 FEPluginTypetoFEsMap_.clear();
597 FEtoSupervisorMap_.clear();
598 FEtoPluginTypeMap_.clear();
599 for(
auto& feApp : feTypeSupervisors)
601 __SUP_COUT__ <<
"FEs for app " << feApp.first <<
":" << feApp.second.getName()
604 auto feChildren = appsNode.getNode(feApp.second.getName())
605 .getNode(
"LinkToSupervisorTable")
606 .getNode(
"LinkToFEInterfaceTable")
609 for(
auto& fe : feChildren)
611 __SUP_COUTV__(fe.first);
612 FEtoSupervisorMap_[fe.first] = feApp.first;
614 std::string pluginType =
615 fe.second.getNode(
"FEInterfacePluginName").getValue();
616 FEPluginTypetoFEsMap_[pluginType].emplace(fe.first);
617 FEtoPluginTypeMap_[fe.first] = pluginType;
621 __SUP_COUTV__(StringMacros::mapToString(FEtoSupervisorMap_));
622 __SUP_COUTV__(StringMacros::mapToString(FEPluginTypetoFEsMap_));
623 __SUP_COUTV__(StringMacros::mapToString(FEtoPluginTypeMap_));
625 else if(type ==
"feSend" ||
627 type ==
"feMacroMultiDimensionalStart" ||
628 type ==
"feMacroMultiDimensionalCheck" ||
629 type ==
"macroMultiDimensionalStart" ||
630 type ==
"macroMultiDimensionalCheck")
634 rxParameters.addParameter(
"targetInterfaceID");
635 SOAPUtilities::receive(message, rxParameters);
637 std::string targetInterfaceID = rxParameters.getValue(
"targetInterfaceID");
639 __SUP_COUTV__(targetInterfaceID);
641 auto feIt = FEtoSupervisorMap_.find(targetInterfaceID);
642 if(feIt == FEtoSupervisorMap_.end())
644 __SUP_SS__ <<
"Destination front end interface ID '" << targetInterfaceID
645 <<
"' was not found in the list of front ends." << __E__;
649 unsigned int FESupervisorIndex = feIt->second;
650 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
652 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
653 if(it == allFESupervisorInfo_.end())
655 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
656 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' \n\n"
657 <<
"The FE Supervisor Index does not exist. Have you configured "
658 "the state machine properly?"
663 if(type ==
"macroMultiDimensionalStart")
667 SOAPParameters rxParameters;
668 rxParameters.addParameter(
"macroName");
669 SOAPUtilities::receive(message, rxParameters);
670 std::string macroName = rxParameters.getValue(
"macroName");
671 __SUP_COUTV__(macroName);
673 std::string macroString;
674 loadMacro(macroName, macroString);
676 SOAPParameters parameters;
677 parameters.addParameter(
"macroString", macroString);
678 SOAPUtilities::addParameters(message, parameters);
683 __SUP_COUT__ <<
"Forwarding request: " << SOAPUtilities::translate(message)
686 xoap::MessageReference replyMessage =
687 SOAPMessenger::sendWithSOAPReply(it->second.getDescriptor(), message);
691 __SUP_COUT__ <<
"Forwarding FE Macro response: "
692 << SOAPUtilities::translate(replyMessage) << __E__;
697 catch(
const xdaq::exception::Exception& e)
699 __SUP_SS__ <<
"Error forwarding FE Communication request to FE Supervisor '"
700 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' "
701 <<
"Have you configured the state machine properly?\n\n"
702 << e.what() << __E__;
708 __SUP_SS__ <<
"Unrecognized FE Communication type: " << type << __E__;
712 return SOAPUtilities::makeSOAPMessageReference(
"Received");
714 catch(
const std::runtime_error& e)
716 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
717 __SUP_COUT_ERR__ << ss.str();
719 xoap::MessageReference returnMessage =
720 SOAPUtilities::makeSOAPMessageReference(
"Error");
722 SOAPParameters parameters;
723 parameters.addParameter(
"Error", ss.str());
724 SOAPUtilities::addParameters(returnMessage, parameters);
725 return returnMessage;
729 xoap::MessageReference returnMessage =
730 SOAPUtilities::makeSOAPMessageReference(
"Error");
732 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
733 __SUP_COUT_ERR__ << ss.str();
735 SOAPParameters parameters;
736 parameters.addParameter(
"Error", ss.str());
737 SOAPUtilities::addParameters(returnMessage, parameters);
738 return returnMessage;
742 void MacroMakerSupervisor::getFElist(HttpXmlDocument& xmldoc)
744 __SUP_COUT__ <<
"Getting FE list!!!!!!!!!" << __E__;
746 SOAPParameters txParameters;
747 txParameters.addParameter(
"Request",
"GetInterfaces");
749 SOAPParameters rxParameters;
750 rxParameters.addParameter(
"FEList");
751 rxParameters.addParameter(
756 SupervisorInfoMap::const_iterator it;
757 std::string oneInterface;
758 std::string rxFEList;
759 std::string rxFrontEndError;
761 size_t lastColonIndex;
765 for(
auto& appInfo : allFESupervisorInfo_)
773 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
774 <<
" name = " << appInfo.second.getName() << __E__;
778 xoap::MessageReference retMsg =
779 SOAPMessenger::sendWithSOAPReply(appInfo.second.getDescriptor(),
780 "MacroMakerSupervisorRequest",
782 SOAPUtilities::receive(retMsg, rxParameters);
784 catch(
const xdaq::exception::Exception& e)
786 __SUP_SS__ <<
"Error transmitting request to FE Supervisor LID = "
787 << appInfo.second.getId() <<
" name = " << appInfo.second.getName()
789 << e.what() << __E__;
793 rxFEList = rxParameters.getValue(
"FEList");
794 rxFrontEndError = rxParameters.getValue(
"frontEndError");
796 __SUP_COUT__ <<
"FE List received: \n" << rxFEList << __E__;
798 if(rxFrontEndError !=
"")
800 __SUP_SS__ <<
"FE Errors received: \n" << rxFrontEndError << __E__;
804 std::istringstream allInterfaces(rxFEList);
805 while(std::getline(allInterfaces, oneInterface))
807 __SUP_COUTV__(oneInterface);
808 xmldoc.addTextElementToData(
"FE", oneInterface);
810 lastColonIndex = oneInterface.rfind(
':');
811 if(lastColonIndex == std::string::npos)
813 __SUP_SS__ <<
"Last colon could not be found in " << oneInterface
817 oneInterface = oneInterface.substr(lastColonIndex);
819 __SUP_COUTV__(oneInterface);
827 void MacroMakerSupervisor::writeData(HttpXmlDocument& ,
829 const std::string& username)
831 __SUP_COUT__ <<
"MacroMaker writing..." << __E__;
833 std::string Address = CgiDataUtilities::getData(cgi,
"Address");
834 std::string Data = CgiDataUtilities::getData(cgi,
"Data");
835 std::string interfaceIndexArray = CgiDataUtilities::getData(cgi,
"interfaceIndex");
836 std::string supervisorIndexArray = CgiDataUtilities::getData(cgi,
"supervisorIndex");
838 StringMacros::decodeURIComponent(CgiDataUtilities::getData(cgi,
"time"));
839 std::string addressFormatStr = CgiDataUtilities::getData(cgi,
"addressFormatStr");
840 std::string dataFormatStr = CgiDataUtilities::getData(cgi,
"dataFormatStr");
842 std::string interfaces = CgiDataUtilities::postData(cgi,
"interfaces");
844 __SUP_COUT__ <<
"Write Address: " << Address <<
" Data: " << Data << __E__;
845 __SUP_COUTV__(interfaces);
847 std::string command =
"w:" + Address +
":" + Data;
848 std::string format = addressFormatStr +
":" + dataFormatStr;
849 appendCommandToHistory(command, format, time, interfaces, username);
851 SOAPParameters txParameters;
852 txParameters.addParameter(
"Request",
"UniversalWrite");
853 txParameters.addParameter(
"Address", Address);
854 txParameters.addParameter(
"Data", Data);
856 __SUP_COUT__ <<
"Here comes the array from multiselect box for WRITE, behold: \n"
857 << supervisorIndexArray <<
"\n"
858 << interfaceIndexArray << __E__;
862 std::vector<std::string> interfaceIndices;
863 std::istringstream f(interfaceIndexArray);
865 while(getline(f, s,
','))
866 interfaceIndices.push_back(s);
867 std::vector<int> supervisorIndices;
868 std::istringstream g(supervisorIndexArray);
870 while(getline(g, t,
','))
871 supervisorIndices.push_back(std::stoi(t));
873 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
875 unsigned int FESupervisorIndex = supervisorIndices[i];
876 std::string interfaceIndex = interfaceIndices[i];
878 txParameters.addParameter(
"InterfaceID", interfaceIndex);
880 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
882 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
884 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
885 if(it == allFESupervisorInfo_.end())
887 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
888 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
889 <<
"The FE Index doesn't exist. Have you configured the state "
897 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
898 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
900 __SUP_COUT__ <<
"Response received: "
901 << SOAPUtilities::translate(replyMessage) << __E__;
903 SOAPParameters rxParameters;
904 rxParameters.addParameter(
"Error");
905 SOAPUtilities::receive(replyMessage, rxParameters);
907 std::string error = rxParameters.getValue(
"Error");
908 __SUP_COUTV__(error);
913 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
914 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
915 <<
"Have you configured the state machine properly?\n\n"
920 catch(
const xdaq::exception::Exception& e)
922 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
923 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
924 <<
"Have you configured the state machine properly?\n\n"
925 << e.what() << __E__;
933 void MacroMakerSupervisor::readData(HttpXmlDocument& xmldoc,
935 const std::string& username)
937 __SUP_COUT__ <<
"@@@@@@@ MacroMaker wants to read data @@@@@@@@" << __E__;
938 std::string Address = CgiDataUtilities::getData(cgi,
"Address");
939 std::string interfaceIndexArray = CgiDataUtilities::getData(cgi,
"interfaceIndex");
940 std::string supervisorIndexArray = CgiDataUtilities::getData(cgi,
"supervisorIndex");
942 StringMacros::decodeURIComponent(CgiDataUtilities::getData(cgi,
"time"));
943 std::string addressFormatStr = CgiDataUtilities::getData(cgi,
"addressFormatStr");
944 std::string dataFormatStr = CgiDataUtilities::getData(cgi,
"dataFormatStr");
946 std::string interfaces = CgiDataUtilities::postData(cgi,
"interfaces");
948 __SUP_COUT__ <<
"Read Address: " << Address << __E__;
949 __SUP_COUTV__(interfaces);
951 SOAPParameters txParameters;
952 txParameters.addParameter(
"Request",
"UniversalRead");
953 txParameters.addParameter(
"Address", Address);
955 SOAPParameters rxParameters;
956 rxParameters.addParameter(
"dataResult");
957 rxParameters.addParameter(
"Error");
958 __SUP_COUT__ <<
"Here comes the array from multiselect box for READ, behold: "
959 << supervisorIndexArray <<
"," << interfaceIndexArray << __E__;
963 std::vector<std::string> interfaceIndices;
964 std::istringstream f(interfaceIndexArray);
966 while(getline(f, s,
','))
967 interfaceIndices.push_back(s);
968 std::vector<int> supervisorIndices;
969 std::istringstream g(supervisorIndexArray);
971 while(getline(g, t,
','))
972 supervisorIndices.push_back(std::stoi(t));
974 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
976 unsigned int FESupervisorIndex = supervisorIndices[i];
977 std::string interfaceIndex = interfaceIndices[i];
979 txParameters.addParameter(
"InterfaceID", interfaceIndex);
981 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
983 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
985 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
986 if(it == allFESupervisorInfo_.end())
988 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
989 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
990 <<
"The FE Index doesn't exist. Have you configured the state "
998 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
999 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1001 __SUP_COUT__ <<
"Response received: " << SOAPUtilities::translate(retMsg)
1006 SOAPUtilities::receive(retMsg, rxParameters);
1008 std::string error = rxParameters.getValue(
"Error");
1009 __SUP_COUTV__(error);
1014 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1015 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1016 <<
"Have you configured the state machine properly?\n\n"
1021 catch(
const xdaq::exception::Exception& e)
1023 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1024 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1025 <<
"Have you configured the state machine properly?\n\n"
1026 << e.what() << __E__;
1030 std::string dataReadResult = rxParameters.getValue(
"dataResult");
1031 __SUP_COUT__ <<
"Data reading result received: " << dataReadResult << __E__;
1032 xmldoc.addTextElementToData(
"readData", dataReadResult);
1033 std::string command =
"r:" + Address +
":" + dataReadResult;
1034 std::string format = addressFormatStr +
":" + dataFormatStr;
1035 appendCommandToHistory(command, format, time, interfaces, username);
1040 void MacroMakerSupervisor::createMacro(HttpXmlDocument& ,
1042 const std::string& username)
1044 __SUP_COUT__ <<
"MacroMaker wants to create a macro!!!!!!!!!" << __E__;
1045 std::string Name = CgiDataUtilities::postData(cgi,
"Name");
1046 std::string Sequence = CgiDataUtilities::postData(cgi,
"Sequence");
1047 std::string Time = CgiDataUtilities::postData(cgi,
"Time");
1049 StringMacros::decodeURIComponent(CgiDataUtilities::postData(cgi,
"Notes"));
1050 std::string isMacroPublic = CgiDataUtilities::getData(cgi,
"isPublic");
1051 std::string isMacroLSBF = CgiDataUtilities::getData(cgi,
"isLSBF");
1053 __SUP_COUTV__(Name);
1054 __SUP_COUTV__(Sequence);
1055 __SUP_COUTV__(Notes);
1056 __SUP_COUTV__(Time);
1057 __SUP_COUTV__(isMacroPublic);
1058 __SUP_COUTV__(isMacroLSBF);
1060 __SUP_COUTV__(MACROS_DB_PATH);
1062 std::string fileName = Name +
".dat";
1063 std::string fullPath;
1064 if(isMacroPublic ==
"true")
1065 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
1067 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
1069 __SUP_COUTV__(fullPath);
1071 std::ofstream macrofile(fullPath.c_str());
1072 if(macrofile.is_open())
1075 macrofile <<
"\"name\":\"" << Name <<
"\",\n";
1076 macrofile <<
"\"sequence\":\"" << Sequence <<
"\",\n";
1077 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
1078 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
1079 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
1080 macrofile <<
"}@" << __E__;
1084 __SUP_COUT__ <<
"Unable to open file" << __E__;
1095 void MacroMakerSupervisor::loadMacro(
const std::string& macroName,
1096 std::string& macroString,
1097 const std::string& username )
1099 __SUP_COUTV__(macroName);
1102 std::string fullPath, line;
1104 for(
unsigned int i = 0; i < 2; ++i)
1107 fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1109 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1111 fullPath += macroName;
1112 if(macroName.find(
".dat") != macroName.size() - 4)
1114 __SUP_COUTV__(fullPath);
1116 std::ifstream read(fullPath.c_str());
1121 getline(read, line);
1122 macroString += line;
1129 __SUP_COUT__ <<
"Unable to open file: " << fullPath << __E__;
1133 if(macroString !=
"")
1137 if(macroString ==
"")
1139 __SUP_SS__ <<
"Unable to locate file for macro '" << macroName
1140 <<
"'... does it exist?" << __E__;
1142 ss <<
" Attempted username was '" << username <<
".'" << __E__;
1146 __SUP_COUTV__(macroString);
1150 void MacroMakerSupervisor::loadMacroNames(
1151 const std::string& username,
1152 std::pair<std::vector<std::string> ,
1153 std::vector<std::string> >& returnMacroNames)
1157 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1158 if((dir = opendir(fullPath.c_str())) != NULL)
1161 while((ent = readdir(dir)) != NULL)
1164 if((
unsigned)strlen(ent->d_name) > 4)
1168 ((fullPath + (std::string)ent->d_name)).c_str());
1173 returnMacroNames.second.push_back(ent->d_name);
1176 __SUP_COUT__ <<
"Unable to open file" << __E__;
1183 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1186 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1187 if((dir = opendir(fullPath.c_str())) != NULL)
1190 while((ent = readdir(dir)) != NULL)
1193 if((
unsigned)strlen(ent->d_name) > 4)
1197 ((fullPath + (std::string)ent->d_name)).c_str());
1201 returnMacroNames.first.push_back(ent->d_name);
1205 __SUP_COUT__ <<
"Unable to open file" << __E__;
1212 __SUP_COUT__ << fullPath << __E__;
1213 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1220 void MacroMakerSupervisor::loadMacros(HttpXmlDocument& xmldoc,
1221 const std::string& username)
1225 std::string returnStr =
"";
1226 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1227 if((dir = opendir(fullPath.c_str())) != NULL)
1230 while((ent = readdir(dir)) != NULL)
1233 if((
unsigned)strlen(ent->d_name) > 4)
1237 ((fullPath + (std::string)ent->d_name)).c_str());
1240 std::stringstream buffer;
1243 getline(read, line);
1247 returnStr += buffer.str();
1252 __SUP_COUT__ <<
"Unable to open file" << __E__;
1255 std::string returnMacroStr = returnStr.substr(0, returnStr.size() - 1);
1257 __SUP_COUT__ <<
"Loading existing macros! " << returnMacroStr << __E__;
1260 xmldoc.addTextElementToData(
"returnMacroStr", returnMacroStr);
1264 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1267 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1269 if((dir = opendir(fullPath.c_str())) != NULL)
1272 while((ent = readdir(dir)) != NULL)
1275 if((
unsigned)strlen(ent->d_name) > 4)
1279 ((fullPath + (std::string)ent->d_name)).c_str());
1282 std::stringstream buffer;
1285 getline(read, line);
1289 returnStr += buffer.str();
1293 __SUP_COUT__ <<
"Unable to open file" << __E__;
1296 std::string returnPublicStr = returnStr.substr(0, returnStr.size() - 1);
1297 __SUP_COUT__ <<
"Loading existing public macros: " << returnPublicStr << __E__;
1299 xmldoc.addTextElementToData(
"returnPublicStr", returnPublicStr);
1303 __SUP_COUT__ << fullPath << __E__;
1304 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1310 void MacroMakerSupervisor::appendCommandToHistory(std::string Command,
1313 std::string Interfaces,
1314 const std::string& username)
1316 std::string fileName =
"history.hist";
1317 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1318 __SUP_COUT__ << fullPath << __E__;
1319 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1320 if(histfile.is_open())
1323 histfile <<
"\"Command\":\"" << Command <<
"\",\n";
1324 histfile <<
"\"Format\":\"" << Format <<
"\",\n";
1325 histfile <<
"\"Time\":\"" << Time <<
"\",\n";
1326 histfile <<
"\"Interfaces\":\"" << Interfaces <<
"\"\n";
1327 histfile <<
"}#" << __E__;
1331 __SUP_COUT__ <<
"Unable to open history.hist" << __E__;
1335 void MacroMakerSupervisor::loadHistory(HttpXmlDocument& xmldoc,
1336 const std::string& username)
1338 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"history.hist";
1340 std::ifstream read(fileName.c_str());
1341 __SUP_COUT__ << fileName << __E__;
1347 unsigned long long fileSz, i = 0, MAX_HISTORY_SIZE = 100000;
1351 read.seekg(0, std::ios::end);
1352 fileSz = read.tellg();
1353 returnStr =
new char[fileSz + 1];
1354 returnStr[fileSz] =
'\0';
1355 read.seekg(0, std::ios::beg);
1358 read.read(returnStr, fileSz);
1362 if(fileSz > MAX_HISTORY_SIZE)
1364 i = fileSz - MAX_HISTORY_SIZE;
1365 for(; i < fileSz; ++i)
1366 if(returnStr[i] ==
'#')
1375 FILE* fp = fopen(fileName.c_str(),
"w");
1378 __SS__ <<
"Big problem with macromaker history file: " << fileName
1382 fwrite(&returnStr[i], fileSz - i, 1, fp);
1386 __SUP_COUT__ <<
"Loading user history! " << __E__;
1389 returnStr[fileSz - 2] =
'\0';
1391 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
1397 __SUP_COUT__ <<
"Unable to open history.hist" << __E__;
1401 void MacroMakerSupervisor::deleteMacro(HttpXmlDocument& xmldoc,
1403 const std::string& username)
1405 std::string MacroName = CgiDataUtilities::getData(cgi,
"MacroName");
1406 std::string isMacroPublic = CgiDataUtilities::getData(cgi,
"isPublic");
1408 std::string fileName = MacroName +
".dat";
1409 std::string fullPath;
1410 if(isMacroPublic ==
"true")
1411 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
1413 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
1415 __SUP_COUT__ << fullPath << __E__;
1417 std::remove(fullPath.c_str());
1418 __SUP_COUT__ <<
"Successfully deleted " << MacroName;
1419 xmldoc.addTextElementToData(
"deletedMacroName", MacroName);
1423 void MacroMakerSupervisor::editMacro(HttpXmlDocument& xmldoc,
1425 const std::string& username)
1427 std::string oldMacroName = CgiDataUtilities::postData(cgi,
"oldMacroName");
1428 std::string newMacroName = CgiDataUtilities::postData(cgi,
"newMacroName");
1429 std::string Sequence = CgiDataUtilities::postData(cgi,
"Sequence");
1430 std::string Time = CgiDataUtilities::postData(cgi,
"Time");
1432 StringMacros::decodeURIComponent(CgiDataUtilities::postData(cgi,
"Notes"));
1434 std::string isMacroPublic = CgiDataUtilities::getData(cgi,
"isPublic");
1435 std::string isMacroLSBF = CgiDataUtilities::getData(cgi,
"isLSBF");
1437 __SUP_COUTV__(oldMacroName);
1438 __SUP_COUTV__(newMacroName);
1439 __SUP_COUTV__(Sequence);
1440 __SUP_COUTV__(Notes);
1441 __SUP_COUTV__(Time);
1442 __SUP_COUTV__(isMacroPublic);
1443 __SUP_COUTV__(isMacroLSBF);
1445 __SUP_COUTV__(MACROS_DB_PATH);
1447 std::string fileName = oldMacroName +
".dat";
1448 std::string fullPath;
1449 if(isMacroPublic ==
"true")
1450 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
1452 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
1454 __SUP_COUTV__(fullPath);
1456 std::ofstream macrofile(fullPath.c_str());
1457 if(macrofile.is_open())
1460 macrofile <<
"\"name\":\"" << newMacroName <<
"\",\n";
1461 macrofile <<
"\"sequence\":\"" << Sequence <<
"\",\n";
1462 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
1463 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
1464 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
1465 macrofile <<
"}@" << __E__;
1469 __SUP_COUT__ <<
"Unable to open file" << __E__;
1471 if(oldMacroName != newMacroName)
1475 rename((MACROS_DB_PATH + username +
"/" + oldMacroName +
".dat").c_str(),
1476 (MACROS_DB_PATH + username +
"/" + newMacroName +
".dat").c_str());
1478 xmldoc.addTextElementToData(
"newMacroName", newMacroName);
1480 xmldoc.addTextElementToData(
"newMacroName",
"ERROR");
1485 void MacroMakerSupervisor::clearHistory(
const std::string& username)
1487 std::string fileName =
"history.hist";
1488 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1490 std::remove(fullPath.c_str());
1491 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
1495 void MacroMakerSupervisor::exportFEMacro(HttpXmlDocument& xmldoc,
1497 const std::string& username)
1499 std::string macroName = CgiDataUtilities::getData(cgi,
"MacroName");
1500 std::string pluginName = CgiDataUtilities::getData(cgi,
"PluginName");
1501 std::string macroSequence = CgiDataUtilities::postData(cgi,
"MacroSequence");
1502 std::string macroNotes =
1503 StringMacros::decodeURIComponent(CgiDataUtilities::postData(cgi,
"MacroNotes"));
1505 __SUP_COUTV__(pluginName);
1506 __SUP_COUTV__(macroName);
1507 __SUP_COUTV__(macroSequence);
1510 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
1511 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
1512 macroNotes[i] =
' ';
1513 __SUP_COUTV__(macroNotes);
1515 std::stringstream ss(macroSequence);
1516 std::string command;
1517 std::vector<std::string> commands;
1519 while(getline(ss, command,
','))
1520 commands.push_back(command);
1522 __SUP_COUTV__(StringMacros::vectorToString(commands));
1524 std::map<std::string , std::set<std::string> >
1525 specialsCodeMap = CodeEditor::getSpecialsMap();
1528 auto specialsCodeMapIt = specialsCodeMap.find(CodeEditor::SPECIAL_TYPE_FEInterface);
1529 if(specialsCodeMapIt == specialsCodeMap.end())
1532 <<
"Could not find any FE Interface plugins in source code. Does MacroMaker "
1533 <<
"have access to the source code? Check that the Supervisor context places "
1535 <<
"location with access to the source code." << __E__;
1540 std::string headerFile = pluginName +
".h";
1541 std::string sourceFile = pluginName +
"_interface.cc";
1542 bool foundHeaderFile =
false;
1543 bool foundSourceFile =
false;
1544 for(
const auto& filePath : specialsCodeMapIt->second)
1546 if(!foundHeaderFile && filePath.find(headerFile) != std::string::npos)
1548 foundHeaderFile =
true;
1549 headerFile = filePath;
1550 __SUP_COUT__ <<
"found headerFile=" << filePath << __E__;
1552 if(!foundSourceFile && filePath.find(sourceFile) != std::string::npos)
1554 foundSourceFile =
true;
1555 sourceFile = filePath;
1556 __SUP_COUT__ <<
"found sourceFile=" << filePath << __E__;
1559 if(foundSourceFile && foundHeaderFile)
1563 if(!foundHeaderFile)
1565 __SS__ <<
"Could not find the header file for the FE Interface plugins at '"
1566 << headerFile <<
".' Does MacroMaker "
1567 <<
"have access to the source code? Check that the Supervisor context "
1568 "places MacroMaker in a "
1569 <<
"location with access to the source code." << __E__;
1572 if(!foundSourceFile)
1574 __SS__ <<
"Could not find the source file for the FE Interface plugins at '"
1575 << sourceFile <<
".' Does MacroMaker "
1576 <<
"have access to the source code? Check that the Supervisor context "
1577 "places MacroMaker in a "
1578 <<
"location with access to the source code." << __E__;
1591 char timeBuffer[100];
1594 struct tm* timeinfo;
1597 timeinfo = localtime(&rawtime);
1599 strftime(timeBuffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
1602 std::string contents;
1607 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, sourceFile, contents);
1611 xmldoc.addTextElementToData(
"sourceFile", sourceFile);
1612 xmldoc.addTextElementToData(
"headerFile", headerFile);
1615 if(contents.find(pluginName +
"::" + macroName) != std::string::npos)
1617 __SS__ <<
"The function definition '" << (pluginName +
"::" + macroName)
1618 <<
"(...)' already exists in the source file '" << sourceFile
1619 <<
".' Duplicate functions are not allowed - please rename the macro or "
1620 "modify the source file."
1625 std::stringstream codess;
1626 std::set<std::string> inArgNames, outArgNames;
1633 __SUP_COUTV__(StringMacros::setToString(inArgNames));
1634 __SUP_COUTV__(StringMacros::setToString(outArgNames));
1638 auto insertPos = contents.find(pluginName +
"::" + pluginName);
1639 if(insertPos == std::string::npos)
1641 __SS__ <<
"Could not find the code insert position in the source file '"
1642 << sourceFile <<
".' The FE plugin class constructor must be '"
1643 << pluginName <<
":" << pluginName <<
"' - is this the case?" << __E__;
1646 __SUP_COUTV__(insertPos);
1648 insertPos = contents.find(
"{", insertPos);
1649 if(insertPos == std::string::npos)
1651 __SS__ <<
"Could not find the code insert position in the source file '"
1653 <<
".' The FE plugin class constructor must begin with '{"
1654 <<
"' - is this the case?" << __E__;
1658 __SUP_COUTV__(insertPos);
1660 insert =
"\n\t//registration of FEMacro '" + macroName +
"' generated, " +
1661 timeBuffer +
", by '" + username +
"' using MacroMaker.\n\t" +
1662 "FEVInterface::registerFEMacroFunction(\"" + macroName +
1663 "\",//feMacroName \n\t\t" +
1664 "static_cast<FEVInterface::frontEndMacroFunction_t>(&" + pluginName +
1665 "::" + macroName +
"), //feMacroFunction \n\t\t" +
1666 "std::vector<std::string>{";
1669 for(
const auto& inArg : inArgNames)
1675 insert +=
"\"" + inArg +
"\"";
1678 insert +=
"}, //namesOfInputArgs \n\t\t";
1679 insert +=
"std::vector<std::string>{";
1682 for(
const auto& outArg : outArgNames)
1688 insert +=
"\"" + outArg +
"\"";
1691 insert +=
"}, //namesOfOutputArgs \n\t\t";
1692 insert +=
"1); //requiredUserPermissions \n\n";
1694 __SUP_COUTV__(insert);
1695 contents = contents.substr(0, insertPos) + insert + contents.substr(insertPos);
1700 auto insertPos = contents.rfind(
"DEFINE_OTS_INTERFACE");
1701 if(insertPos == std::string::npos)
1703 __SS__ <<
"Could not find the code insert position in the source file '"
1705 <<
".' The FE plugin class must end with a 'DEFINE_OTS_INTERFACE("
1706 << pluginName <<
")' - is this the case?" << __E__;
1709 __SUP_COUTV__(insertPos);
1713 "============================================================================"
1714 "============================================\n//" +
1715 macroName +
"\n" +
"//\tFEMacro '" + macroName +
"' generated, " +
1716 timeBuffer +
", by '" + username +
"' using MacroMaker.\n" +
1717 "//\tMacro Notes: " + macroNotes +
"\n" +
"void " + pluginName +
1718 "::" + macroName +
"(__ARGS__)\n{\n\t" +
1719 "__CFG_COUT__ << \"# of input args = \" << argsIn.size() << __E__; \n\t" +
1720 "__CFG_COUT__ << \"# of output args = \" << argsOut.size() << __E__; \n\t" +
1721 "for(auto &argIn:argsIn) \n\t\t" +
1722 "__CFG_COUT__ << argIn.first << \": \" << argIn.second << __E__; \n\n\t" +
1723 "//macro commands section \n" + codess.str() +
"\n\n\t" +
1724 "for(auto &argOut:argsOut) \n\t\t" +
1725 "__CFG_COUT__ << argOut.first << \": \" << argOut.second << __E__; \n\n" +
1726 "} //end " + macroName +
"()\n\n";
1729 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
1732 "MacroMaker-" + username,
1739 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, headerFile, contents);
1744 auto insertPos = contents.rfind(
"};");
1745 if(insertPos == std::string::npos)
1747 __SS__ <<
"Could not find the code insert position in the header file '"
1749 <<
".' The FE plugin class must end with a '};' - is this the case?"
1754 __SUP_COUTV__(insertPos);
1756 insert =
"\npublic: // FEMacro '" + macroName +
"' generated, " + timeBuffer +
1757 ", by '" + username +
"' using MacroMaker.\n\t" +
"void " + macroName +
1760 __SUP_COUTV__(insert);
1761 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
1764 "MacroMaker-" + username,
1772 void MacroMakerSupervisor::exportMacro(HttpXmlDocument& xmldoc,
1774 const std::string& username)
1776 std::string macroName = CgiDataUtilities::getData(cgi,
"MacroName");
1777 std::string macroSequence = CgiDataUtilities::postData(cgi,
"MacroSequence");
1778 std::string macroNotes =
1779 StringMacros::decodeURIComponent(CgiDataUtilities::postData(cgi,
"MacroNotes"));
1781 __SUP_COUTV__(macroName);
1782 __SUP_COUTV__(macroSequence);
1785 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
1786 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
1787 macroNotes[i] =
' ';
1788 __SUP_COUTV__(macroNotes);
1790 std::stringstream ss(macroSequence);
1791 std::string command;
1792 std::vector<std::string> commands;
1794 while(getline(ss, command,
','))
1795 commands.push_back(command);
1797 std::string fileName = macroName +
".cc";
1799 std::string fullPath =
1800 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + username +
"/" + fileName;
1801 __SUP_COUT__ << fullPath << __E__;
1802 std::ofstream exportFile(fullPath.c_str(), std::ios::trunc);
1803 if(exportFile.is_open())
1805 exportFile <<
"//Generated Macro Name:\t" << macroName <<
"\n";
1806 exportFile <<
"//Macro Notes: " << macroNotes <<
"\n";
1810 struct tm* timeinfo;
1814 timeinfo = localtime(&rawtime);
1816 strftime(buffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
1817 exportFile <<
"//Generated Time: \t\t" << buffer <<
"\n";
1820 exportFile <<
"//Paste this whole file into an interface to transfer Macro "
1823 createCode(exportFile, commands);
1827 xmldoc.addTextElementToData(
1829 "$USER_DATA/ServiceData/" + MACROS_EXPORT_PATH + username +
"/" + fileName);
1832 __SUP_COUT__ <<
"Unable to open file" << __E__;
1837 void MacroMakerSupervisor::createCode(std::ostream& out,
1838 const std::vector<std::string>& commands,
1839 const std::string& tabOffset,
1841 std::set<std::string>* inArgNames,
1842 std::set<std::string>* outArgNames)
1845 std::set<std::string > argInHasBeenInitializedSet;
1846 bool addressIsVariable, dataIsVariable;
1848 out << tabOffset <<
"{";
1851 << tabOffset <<
"\t"
1852 <<
"char *address \t= new char[universalAddressSize_]{0}; //create address "
1853 "buffer of interface size and init to all 0";
1855 << tabOffset <<
"\t"
1856 <<
"char *data \t\t= new char[universalDataSize_]{0}; //create data buffer "
1857 "of interface size and init to all 0";
1860 << tabOffset <<
"\t"
1861 <<
"uint64_t macroAddress; //create macro address buffer (size 8 bytes)";
1863 << tabOffset <<
"\t"
1864 <<
"uint64_t macroData; //create macro address buffer (size 8 bytes)";
1867 << tabOffset <<
"\t"
1868 <<
"std::map<std::string /*arg name*/,uint64_t /*arg val*/> macroArgs; //create "
1869 "map from arg name to 64-bit number";
1872 for(
unsigned int i = 0; i < commands.size(); i++)
1874 std::stringstream sst(commands[i]);
1876 std::vector<std::string>
1878 while(getline(sst, tokens,
':'))
1879 oneCommand.push_back(tokens);
1880 while(oneCommand.size() < 4)
1881 oneCommand.push_back(
"");
1883 __SUP_COUTV__(StringMacros::vectorToString(oneCommand));
1909 addressIsVariable = isArgumentVariable(oneCommand[2]);
1910 dataIsVariable = isArgumentVariable(oneCommand[3]);
1912 __SUP_COUTV__(addressIsVariable);
1913 __SUP_COUTV__(dataIsVariable);
1915 out <<
"\n\n" << tabOffset <<
"\t// command-#" << i <<
": ";
1917 if(oneCommand[1][0] ==
'w' || oneCommand[1][0] ==
'r')
1919 if(oneCommand[1][0] ==
'w')
1921 else if(oneCommand[1][0] ==
'r')
1924 if(addressIsVariable)
1925 out << oneCommand[2];
1927 out <<
"0x" << oneCommand[2];
1928 out <<
" /*address*/,";
1932 out << oneCommand[3] <<
" /*data*/";
1933 else if(oneCommand[1][0] ==
'w')
1934 out <<
"0x" << oneCommand[3] <<
" /*data*/";
1935 else if(oneCommand[1][0] ==
'r')
1939 else if(oneCommand[1][0] ==
'd')
1941 out <<
"delay(" << oneCommand[2] <<
");\n";
1942 out << tabOffset <<
"\t"
1943 <<
"__CFG_COUT__ << \"Sleeping for... \" << " << oneCommand[2]
1944 <<
" << \" milliseconds \" << __E__;\n";
1945 out << tabOffset <<
"\t"
1946 <<
"usleep(" << oneCommand[2] <<
"*1000 /* microseconds */);\n";
1951 __SS__ <<
"FATAL ERROR: Unknown command '" << oneCommand[1]
1952 <<
"'... command is not w, r or d" << __E__;
1958 if(addressIsVariable)
1960 if(argInHasBeenInitializedSet.find(oneCommand[2]) ==
1961 argInHasBeenInitializedSet.end())
1963 argInHasBeenInitializedSet.emplace(oneCommand[2]);
1968 out << tabOffset <<
"\t"
1969 <<
"macroArgs[\"" << oneCommand[2]
1971 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
1974 << tabOffset <<
"\t\t\"" << oneCommand[2]
1975 <<
"\").getValue<uint64_t>();";
1980 inArgNames->emplace(oneCommand[2]);
1983 out << tabOffset <<
"\t"
1984 <<
"macroArgs[\"" << oneCommand[2] <<
"\"] = __GET_ARG_IN__(\""
1985 << oneCommand[2] <<
"\", uint64_t);";
1988 out <<
"\t//get macro address argument";
1990 << tabOffset <<
"\tmemcpy(address,¯oArgs[\"" << oneCommand[2]
1991 <<
"\"],8); //copy macro address argument to buffer";
1995 out << tabOffset <<
"\t"
1996 <<
"macroAddress = 0x" << oneCommand[2]
1997 <<
"; memcpy(address,¯oAddress,8);"
1998 <<
"\t//copy macro address to buffer";
2003 if(oneCommand[1] ==
"w")
2007 if(argInHasBeenInitializedSet.find(oneCommand[3]) ==
2008 argInHasBeenInitializedSet
2011 argInHasBeenInitializedSet.emplace(oneCommand[3]);
2016 inArgNames->emplace(oneCommand[3]);
2020 << tabOffset <<
"\t"
2021 <<
"macroArgs[\"" << oneCommand[3]
2022 <<
"\"] = __GET_ARG_IN__(\"" << oneCommand[3]
2023 <<
"\", uint64_t); //initialize from input arguments";
2029 << tabOffset <<
"\t"
2030 <<
"macroArgs[\"" << oneCommand[3]
2032 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2035 << tabOffset <<
"\t\t\"" << oneCommand[3]
2036 <<
"\").getValue<uint64_t>(); //initialize from "
2037 "configuration tree";
2040 out <<
"\t//get macro data argument";
2042 << tabOffset <<
"\tmemcpy(data,¯oArgs[\"" << oneCommand[3]
2043 <<
"\"],8); //copy macro data argument to buffer";
2048 << tabOffset <<
"\t"
2049 <<
"macroData = 0x" << oneCommand[3] <<
"; memcpy(data,¯oData,8);"
2050 <<
"\t//copy macro data to buffer";
2053 << tabOffset <<
"\t"
2054 <<
"universalWrite(address,data);";
2059 << tabOffset <<
"\t"
2060 <<
"universalRead(address,data);";
2062 std::string outputArgName;
2065 outputArgName = oneCommand[3];
2069 sprintf(str,
"outArg%d", i);
2070 outputArgName = str;
2072 __SUP_COUTV__(outputArgName);
2074 out << tabOffset <<
"\t"
2075 <<
"memcpy(¯oArgs[\"" << outputArgName
2076 <<
"\"],data,8); //copy buffer to argument map";
2081 << tabOffset <<
"\t"
2082 <<
"__SET_ARG_OUT__(\"" << outputArgName <<
"\",macroArgs[\""
2083 << outputArgName <<
"\"]); //update output argument result";
2086 outArgNames->emplace(outputArgName);
2087 argInHasBeenInitializedSet.emplace(
2092 out <<
"\n\n" << tabOffset <<
"\tdelete[] address; //free the memory";
2093 out <<
"\n" << tabOffset <<
"\tdelete[] data; //free the memory";
2094 out <<
"\n" << tabOffset <<
"}";
2096 __SUP_COUT__ <<
"Done with code generation." << __E__;
2102 bool MacroMakerSupervisor::isArgumentVariable(
const std::string& argumentString)
2104 for(
unsigned int i = 0; i < argumentString.length(); ++i)
2107 if(!((argumentString[i] >=
'0' && argumentString[i] <=
'9') ||
2108 (argumentString[i] >=
'a' && argumentString[i] <=
'f') ||
2109 (argumentString[i] >=
'A' && argumentString[i] <=
'F')))
2124 std::string MacroMakerSupervisor::generateHexArray(
const std::string& sourceHexString,
2127 std::stringstream retSs;
2129 std::string srcHexStr = sourceHexString;
2130 __SUP_COUT__ <<
"Translating: \n";
2131 __SUP_COUT__ << srcHexStr << __E__;
2133 if(srcHexStr.size() % 2)
2134 srcHexStr =
"0" + srcHexStr;
2136 numOfBytes = srcHexStr.size() / 2;
2137 retSs <<
"[" << numOfBytes <<
"] = {";
2139 for(
int i = 0; i < numOfBytes * 2; i += 2)
2142 if(!((srcHexStr[i] >=
'0' && srcHexStr[i] <=
'9') ||
2143 (srcHexStr[i] >=
'a' && srcHexStr[i] <=
'f') ||
2144 (srcHexStr[i] >=
'A' && srcHexStr[i] <=
'F')) ||
2145 !((srcHexStr[i + 1] >=
'0' && srcHexStr[i + 1] <=
'9') ||
2146 (srcHexStr[i + 1] >=
'a' && srcHexStr[i + 1] <=
'f') ||
2147 (srcHexStr[i + 1] >=
'A' && srcHexStr[i + 1] <=
'F')))
2155 retSs <<
"0x" << srcHexStr[srcHexStr.size() - 1 - i - 1]
2156 << srcHexStr[srcHexStr.size() - 1 - i];
2160 __SUP_COUT__ << retSs.str() << __E__;
2166 void MacroMakerSupervisor::runFEMacro(HttpXmlDocument& xmldoc,
2168 const std::string& username)
try
2170 __SUP_COUT__ << __E__;
2174 std::string feClassSelected = CgiDataUtilities::getData(cgi,
"feClassSelected");
2175 std::string feUIDSelected = CgiDataUtilities::getData(cgi,
"feUIDSelected");
2176 std::string macroType = CgiDataUtilities::getData(cgi,
"macroType");
2177 std::string macroName = CgiDataUtilities::getData(cgi,
"macroName");
2178 std::string inputArgs = CgiDataUtilities::postData(cgi,
"inputArgs");
2179 std::string outputArgs = CgiDataUtilities::postData(cgi,
"outputArgs");
2180 bool saveOutputs = CgiDataUtilities::getDataAsInt(cgi,
"saveOutputs") == 1;
2183 __SUP_COUTV__(feClassSelected);
2184 __SUP_COUTV__(feUIDSelected);
2185 __SUP_COUTV__(macroType);
2186 __SUP_COUTV__(macroName);
2187 __SUP_COUTV__(inputArgs);
2188 __SUP_COUTV__(outputArgs);
2189 __SUP_COUTV__(saveOutputs);
2191 std::set<std::string > feUIDs;
2193 if(feUIDSelected ==
"")
2194 feUIDSelected =
"*";
2195 if(feClassSelected ==
"")
2196 feClassSelected =
"*";
2198 if(feClassSelected ==
"" || feUIDSelected ==
"" || macroType ==
"" || macroName ==
"")
2200 __SUP_SS__ <<
"Illegal empty front-end parameter." << __E__;
2203 else if(feUIDSelected !=
"*")
2204 feUIDs.emplace(feUIDSelected);
2208 if(feClassSelected ==
"*")
2210 for(
auto& feTypePair : FEPluginTypetoFEsMap_)
2211 for(
auto& feUID : feTypePair.second)
2212 feUIDs.emplace(feUID);
2216 auto typeIt = FEPluginTypetoFEsMap_.find(feClassSelected);
2217 if(typeIt == FEPluginTypetoFEsMap_.end())
2219 __SUP_SS__ <<
"Illegal front-end type parameter '" << feClassSelected
2220 <<
"' not in list of types." << __E__;
2224 for(
auto& feUID : typeIt->second)
2225 feUIDs.emplace(feUID);
2229 __SUP_COUTV__(StringMacros::setToString(feUIDs));
2231 std::string macroString;
2232 if(macroType ==
"public")
2233 loadMacro(macroName, macroString);
2234 else if(macroType ==
"private")
2235 loadMacro(macroName, macroString, username);
2237 __SUP_COUTV__(macroString);
2244 std::string filename =
"/macroOutput_" + std::to_string(time(0)) +
"_" +
2245 std::to_string(clock()) +
".txt";
2247 __SUP_COUTV__(filename);
2248 fp = fopen((CodeEditor::OTSDAQ_DATA_PATH + filename).c_str(),
"w");
2251 __SUP_SS__ <<
"Failed to open file to save macro output '"
2252 << CodeEditor::OTSDAQ_DATA_PATH << filename <<
"'..." << __E__;
2256 fprintf(fp,
"############################\n");
2258 "### Running '%s' at time %s\n",
2260 StringMacros::getTimestampString().c_str());
2262 "### \t Target front-ends (count=%lu): %s\n",
2264 StringMacros::setToString(feUIDs).c_str());
2265 fprintf(fp,
"### \t\t Inputs: %s\n", inputArgs.c_str());
2266 fprintf(fp,
"############################\n\n\n");
2268 xmldoc.addTextElementToData(
"outputArgs_name",
"Filename");
2269 xmldoc.addTextElementToData(
"outputArgs_value",
"$OTSDAQ_DATA/" + filename);
2273 for(
auto& feUID : feUIDs)
2275 auto feIt = FEtoSupervisorMap_.find(feUID);
2276 if(feIt == FEtoSupervisorMap_.end())
2278 __SUP_SS__ <<
"Destination front end interface ID '" << feUID
2279 <<
"' was not found in the list of front ends." << __E__;
2280 ss <<
"\n\nHere is the map:\n\n"
2281 << StringMacros::mapToString(FEtoSupervisorMap_) << __E__;
2285 unsigned int FESupervisorIndex = feIt->second;
2286 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
2288 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
2289 if(it == allFESupervisorInfo_.end())
2292 <<
"Error transmitting request to FE Supervisor '" << feUID <<
":"
2293 << FESupervisorIndex <<
".' \n\n"
2294 <<
"The FE Supervisor Index does not exist. Have you configured "
2295 "the state machine properly?"
2301 SOAPParameters txParameters;
2302 if(macroType ==
"fe")
2303 txParameters.addParameter(
"Request",
"RunInterfaceMacro");
2305 txParameters.addParameter(
"Request",
"RunMacroMakerMacro");
2306 txParameters.addParameter(
"InterfaceID", feUID);
2307 if(macroType ==
"fe")
2308 txParameters.addParameter(
"feMacroName", macroName);
2311 txParameters.addParameter(
"macroName", macroName);
2312 txParameters.addParameter(
"macroString", macroString);
2314 txParameters.addParameter(
"inputArgs", inputArgs);
2315 txParameters.addParameter(
"outputArgs", outputArgs);
2317 SOAPParameters rxParameters;
2319 rxParameters.addParameter(
"outputArgs");
2320 rxParameters.addParameter(
"Error");
2325 "Running '%s' at time %s\n",
2327 StringMacros::getTimestampString().c_str());
2329 "\t Target front-end: '%s::%s'\n",
2330 FEtoPluginTypeMap_[feUID].c_str(),
2333 "\t\t Inputs: %s\n",
2334 StringMacros::decodeURIComponent(inputArgs).c_str());
2338 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
2339 it->second.getDescriptor(),
2340 "MacroMakerSupervisorRequest",
2343 __SUP_COUT__ <<
"Received response message: "
2344 << SOAPUtilities::translate(retMsg) << __E__;
2346 SOAPUtilities::receive(retMsg, rxParameters);
2348 __SUP_COUT__ <<
"Received it " << __E__;
2351 std::string outputResults = rxParameters.getValue(
"outputArgs");
2352 std::string error = rxParameters.getValue(
"Error");
2355 __SUP_COUT__ <<
"outputArgs = " << outputResults << __E__;
2359 __SS__ <<
"Attempted FE Macro Failed. Attempted target "
2360 <<
"was UID=" << feUID
2361 <<
" at feSupervisorID=" << FESupervisorIndex <<
"." << __E__;
2362 ss <<
"\n\n The error was:\n\n" << error << __E__;
2363 __SUP_COUT_ERR__ <<
"\n" << ss.str();
2364 xmldoc.addTextElementToData(
"Error", ss.str());
2372 std::istringstream inputStream(outputResults);
2373 std::string splitVal, argName, argValue;
2374 while(getline(inputStream, splitVal,
';'))
2376 std::istringstream pairInputStream(splitVal);
2377 getline(pairInputStream, argName,
',');
2378 getline(pairInputStream, argValue,
',');
2383 "\t\t Output '%s' = %s\n",
2385 StringMacros::decodeURIComponent(argValue).c_str());
2389 xmldoc.addTextElementToData(
"outputArgs_name", argName);
2390 xmldoc.addTextElementToData(
"outputArgs_value", argValue);
2392 __SUP_COUT__ << argName <<
": " << argValue << __E__;
2408 catch(
const std::runtime_error& e)
2410 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
2411 __SUP_COUT_ERR__ << ss.str();
2412 xmldoc.addTextElementToData(
"Error", ss.str());
2416 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
2417 __SUP_COUT_ERR__ << ss.str();
2419 xmldoc.addTextElementToData(
"Error", ss.str());
2423 void MacroMakerSupervisor::getFEMacroList(HttpXmlDocument& xmldoc,
2424 const std::string& username)
2426 __SUP_COUT__ <<
"Getting FE Macro list" << __E__;
2428 SOAPParameters txParameters;
2429 txParameters.addParameter(
"Request",
"GetInterfaceMacros");
2431 SOAPParameters rxParameters;
2432 rxParameters.addParameter(
"FEMacros");
2434 std::string oneInterface;
2435 std::string rxFEMacros;
2439 for(
auto& appInfo : allFESupervisorInfo_)
2441 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
2442 <<
" name = " << appInfo.second.getName() << __E__;
2444 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
2445 appInfo.second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
2446 SOAPUtilities::receive(retMsg, rxParameters);
2448 rxFEMacros = rxParameters.getValue(
"FEMacros");
2450 __SUP_COUT__ <<
"FE Macros received: \n" << rxFEMacros << __E__;
2452 std::istringstream allInterfaces(rxFEMacros);
2453 while(std::getline(allInterfaces, oneInterface))
2457 xmldoc.addTextElementToData(
"FEMacros", oneInterface);
2463 std::pair<std::vector<std::string> ,
2464 std::vector<std::string> >
2466 loadMacroNames(username, macroNames);
2468 __SUP_COUT__ <<
"Public macro count: " << macroNames.first.size() << __E__;
2469 __SUP_COUT__ <<
"Private macro count: " << macroNames.second.size() << __E__;
2471 std::string macroString;
2480 for(
int i = 0; i < 2; ++i)
2481 for(
auto& macroName : (i ? macroNames.second : macroNames.first))
2484 loadMacro(macroName, macroString, username);
2487 FEVInterface::macroStruct_t macro(macroString);
2489 std::stringstream xmlMacroStream;
2490 xmlMacroStream << macro.macroName_;
2491 xmlMacroStream <<
":"
2493 xmlMacroStream <<
":" << macro.namesOfInputArguments_.size();
2494 for(
auto& inputArg : macro.namesOfInputArguments_)
2495 xmlMacroStream <<
":" << inputArg;
2496 xmlMacroStream <<
":" << macro.namesOfOutputArguments_.size();
2497 for(
auto& inputArg : macro.namesOfOutputArguments_)
2498 xmlMacroStream <<
":" << inputArg;
2500 xmldoc.addTextElementToData(i ?
"PrivateMacro" :
"PublicMacro",
2501 xmlMacroStream.str());