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"
7 #include "otsdaq/NetworkUtilities/TransceiverSocket.h"
16 #include "otsdaq/TableCore/TableGroupKey.h"
18 #define MACROS_DB_PATH std::string(__ENV__("SERVICE_DATA_PATH")) + "/MacroData/"
19 #define MACROS_HIST_PATH std::string(__ENV__("SERVICE_DATA_PATH")) + "/MacroHistory/"
20 #define MACROS_SEQUENCE_PATH std::string(__ENV__("SERVICE_DATA_PATH")) + "/MacroSequence/"
21 #define MACROS_EXPORT_PATH std::string("/MacroExport/")
23 #define SEQUENCE_FILE_NAME \
24 std::string(__ENV__("SERVICE_DATA_PATH")) + "/OtsWizardData/sequence.dat"
25 #define SEQUENCE_OUT_FILE_NAME \
26 std::string(__ENV__("SERVICE_DATA_PATH")) + "/OtsWizardData/sequence.out"
31 #define __MF_SUBJECT__ "MacroMaker"
39 __SUP_COUT__ <<
"Constructing..." << __E__;
44 mkdir(((std::string)MACROS_DB_PATH).c_str(), 0755);
45 mkdir(((std::string)MACROS_HIST_PATH).c_str(), 0755);
46 mkdir(((std::string)MACROS_SEQUENCE_PATH).c_str(), 0755);
47 mkdir((__ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH).c_str(), 0755);
50 &MacroMakerSupervisor::frontEndCommunicationRequest,
55 if(CorePropertySupervisorBase::allSupervisorInfo_.isMacroMakerMode())
57 __SUP_COUT__ <<
"Starting constructor for Macro Maker mode." << __E__;
59 xgi::bind(
this, &MacroMakerSupervisor::requestIcons,
"requestIcons");
60 xgi::bind(
this, &MacroMakerSupervisor::verification,
"Verify");
61 xgi::bind(
this, &MacroMakerSupervisor::tooltipRequest,
"TooltipRequest");
62 xgi::bind(
this, &MacroMakerSupervisor::requestWrapper,
"Request");
64 &MacroMakerSupervisor::supervisorSequenceCheck,
65 "SupervisorSequenceCheck",
68 __SUP_COUT__ <<
"Completed constructor for Macro Maker mode." << __E__;
71 __SUP_COUT__ <<
"Not Macro Maker only mode." << __E__;
77 if(CorePropertySupervisorBase::allSupervisorInfo_.isMacroMakerMode())
83 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME);
88 FEPluginTypetoFEsMap_.clear();
89 FEtoSupervisorMap_.clear();
90 FEtoPluginTypeMap_.clear();
93 __SUP_COUT__ <<
"FEs for app MacroMakerFESupervisor"
99 .
getNode(
"MacroMakerFESupervisor")
100 .
getNode(
"LinkToSupervisorTable")
101 .
getNode(
"LinkToFEInterfaceTable")
104 for(
auto& fe : feChildren)
106 if(!fe.second.status())
109 __SUP_COUTV__(fe.first);
110 FEtoSupervisorMap_[fe.first] =
111 atoi(__ENV__(
"FE_SUPERVISOR_ID"));
113 std::string pluginType =
114 fe.second.getNode(
"FEInterfacePluginName").getValue();
115 FEPluginTypetoFEsMap_[pluginType].emplace(fe.first);
116 FEtoPluginTypeMap_[fe.first] = pluginType;
120 __SUP_COUTV__(StringMacros::mapToString(FEtoSupervisorMap_));
121 __SUP_COUTV__(StringMacros::mapToString(FEPluginTypetoFEsMap_));
122 __SUP_COUTV__(StringMacros::mapToString(FEtoPluginTypeMap_));
127 bool enableRemoteControl =
false;
130 __ENV__(
"OTS_MACROMAKER_UDP_PORT");
131 __ENV__(
"OTS_MACROMAKER_UDP_IP");
132 enableRemoteControl =
true;
139 if(enableRemoteControl)
141 __SUP_COUT__ <<
"Enabling remote control over UDP..." << __E__;
145 MacroMakerSupervisor::RemoteControlWorkLoop(s);
151 __SUP_COUT__ <<
"Remote control over UDP is disabled." << __E__;
154 __SUP_COUT__ <<
"Constructed." << __E__;
158 MacroMakerSupervisor::~MacroMakerSupervisor(
void) { destroy(); }
161 void MacroMakerSupervisor::init(
void)
166 allFESupervisorInfo_ =
167 SupervisorInfoMap(allSupervisorInfo_.getAllFETypeSupervisorInfo());
172 void MacroMakerSupervisor::destroy(
void)
184 void MacroMakerSupervisor::tooltipRequest(xgi::Input* in, xgi::Output* out)
186 cgicc::Cgicc cgi(in);
194 if(securityCode_.compare(submittedSequence) != 0)
196 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!"
208 if(Command ==
"check")
216 else if(Command ==
"setNeverShow")
219 WebUsers::DEFAULT_ADMIN_USERNAME,
228 __COUT__ <<
"Command Request, " << Command <<
", not recognized." << __E__;
234 void MacroMakerSupervisor::verification(xgi::Input* in, xgi::Output* out)
236 cgicc::Cgicc cgi(in);
238 __COUT__ <<
"submittedSequence=" << submittedSequence <<
" " << time(0) << __E__;
240 std::string securityWarning =
"";
242 if(securityCode_.compare(submittedSequence) != 0)
244 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!"
246 *out <<
"Invalid code.";
252 __COUT__ <<
"*** Successfully authenticated security sequence "
253 <<
"@ " << time(0) << __E__;
258 securityWarning =
"&secure=False";
262 *out <<
"<!DOCTYPE HTML><html lang='en'><head><title>ots MacroMaker mode</title>" <<
265 "<link rel='apple-touch-icon' sizes='57x57' href='/WebPath/images/otsdaqIcons/apple-icon-57x57.png'>\
266 <link rel='apple-touch-icon' sizes='60x60' href='/WebPath/images/otsdaqIcons/apple-icon-60x60.png'>\
267 <link rel='apple-touch-icon' sizes='72x72' href='/WebPath/images/otsdaqIcons/apple-icon-72x72.png'>\
268 <link rel='apple-touch-icon' sizes='76x76' href='/WebPath/images/otsdaqIcons/apple-icon-76x76.png'>\
269 <link rel='apple-touch-icon' sizes='114x114' href='/WebPath/images/otsdaqIcons/apple-icon-114x114.png'>\
270 <link rel='apple-touch-icon' sizes='120x120' href='/WebPath/images/otsdaqIcons/apple-icon-120x120.png'>\
271 <link rel='apple-touch-icon' sizes='144x144' href='/WebPath/images/otsdaqIcons/apple-icon-144x144.png'>\
272 <link rel='apple-touch-icon' sizes='152x152' href='/WebPath/images/otsdaqIcons/apple-icon-152x152.png'>\
273 <link rel='apple-touch-icon' sizes='180x180' href='/WebPath/images/otsdaqIcons/apple-icon-180x180.png'>\
274 <link rel='icon' type='image/png' sizes='192x192' href='/WebPath/images/otsdaqIcons/android-icon-192x192.png'>\
275 <link rel='icon' type='image/png' sizes='32x32' href='/WebPath/images/otsdaqIcons/favicon-32x32.png'>\
276 <link rel='icon' type='image/png' sizes='96x96' href='/WebPath/images/otsdaqIcons/favicon-96x96.png'>\
277 <link rel='icon' type='image/png' sizes='16x16' href='/WebPath/images/otsdaqIcons/favicon-16x16.png'>\
278 <link rel='manifest' href='/WebPath/images/otsdaqIcons/manifest.json'>\
279 <meta name='msapplication-TileColor' content='#ffffff'>\
280 <meta name='msapplication-TileImage' content='/ms-icon-144x144.png'>\
281 <meta name='theme-color' content='#ffffff'>"
285 <<
"<frameset col='100%' row='100%'><frame "
286 "src='/WebPath/html/MacroMakerSupervisor.html?urn="
287 << this->getApplicationDescriptor()->getLocalId() << securityWarning
288 <<
"'></frameset></html>";
292 void MacroMakerSupervisor::generateURL()
294 defaultSequence_ =
true;
297 FILE* fp = fopen((SEQUENCE_FILE_NAME).c_str(),
"r");
300 __SUP_COUT_INFO__ <<
"Sequence length file found: " << SEQUENCE_FILE_NAME
303 fgets(line, 100, fp);
304 sscanf(line,
"%d", &length);
309 defaultSequence_ =
false;
315 <<
"(Reverting to default wiz security) Sequence length file NOT found: "
316 << SEQUENCE_FILE_NAME << __E__;
320 __SUP_COUT__ <<
"Sequence length = " << length << __E__;
324 const char alphanum[] =
326 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
327 "abcdefghijklmnopqrstuvwxyz";
329 for(
int i = 0; i < length; ++i)
331 securityCode_ += alphanum[rand() % (
sizeof(alphanum) - 1)];
334 __SUP_COUT__ << __ENV__(
"HOSTNAME") <<
":" << __ENV__(
"PORT")
335 <<
"/urn:xdaq-application:lid="
336 << this->getApplicationDescriptor()->getLocalId()
337 <<
"/Verify?code=" << securityCode_ << __E__;
343 fp = fopen((SEQUENCE_OUT_FILE_NAME).c_str(),
"w");
346 fprintf(fp,
"%s", securityCode_.c_str());
350 __SUP_COUT_ERR__ <<
"Sequence output file NOT found: " << SEQUENCE_OUT_FILE_NAME
357 void MacroMakerSupervisor::requestIcons(xgi::Input* in, xgi::Output* out)
359 cgicc::Cgicc cgi(in);
364 if(securityCode_.compare(submittedSequence) != 0)
366 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match! "
372 __COUT__ <<
"***Successfully authenticated security sequence. " << time(0)
385 *out <<
"Macro Maker "
386 ",MM,0,1,icon-MacroMaker.png,/WebPath/html/"
387 "MacroMaker.html?urn=290,/"
389 ",CFG,0,1,icon-Configure.png,/WebPath/html/"
390 "FEMacroTest.html?urn=290,/"
392 <<
",Code Editor,CODE,0,1,icon-CodeEditor.png,/urn:xdaq-application:lid=240/,/"
396 std::string iconFile = std::string(__ENV__(
"USER_DATA")) +
"/MacroMakerModeIcons.dat";
397 __COUT__ <<
"Macro Maker mode user icons file: " << iconFile << __E__;
398 FILE* fp = fopen(iconFile.c_str(),
"r");
401 __COUT__ <<
"Macro Maker mode user icons loading from " << iconFile << __E__;
402 fseek(fp, 0, SEEK_END);
403 const unsigned long fileSize = ftell(fp);
404 std::string fileString(fileSize, 0);
406 if(fread(&fileString[0], 1, fileSize, fp) != fileSize)
408 __COUT_ERR__ <<
"Unable to read proper size string from icons file!" << __E__;
413 __COUTV__(fileString);
417 __COUT__ <<
"Macro Maker mode user icons file not found: " << iconFile << __E__;
424 xoap::MessageReference MacroMakerSupervisor::supervisorSequenceCheck(
425 xoap::MessageReference message)
430 SOAPUtilities::receive(message, parameters);
432 std::string submittedSequence = parameters.getValue(
"sequence");
436 std::map<std::string , WebUsers::permissionLevel_t> permissionMap;
438 if(securityCode_ == submittedSequence)
439 permissionMap.emplace(
440 std::pair<std::string /*groupName*/, WebUsers::permissionLevel_t>(
444 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!"
447 permissionMap.emplace(
448 std::pair<std::string /*groupName*/, WebUsers::permissionLevel_t>(
449 WebUsers::DEFAULT_USER_GROUP, WebUsers::PERMISSION_LEVEL_INACTIVE));
456 return SOAPUtilities::makeSOAPMessageReference(
"SequenceResponse", retParameters);
466 std::string ipAddressForRemoteControlOverUDP = __ENV__(
467 "OTS_MACROMAKER_UDP_IP");
468 int portForRemoteControlOverUDP = atoi(__ENV__(
469 "OTS_MACROMAKER_UDP_PORT"));
470 bool acknowledgementEnabled =
473 __COUTV__(ipAddressForRemoteControlOverUDP);
474 __COUTV__(portForRemoteControlOverUDP);
475 __COUTV__(acknowledgementEnabled);
478 portForRemoteControlOverUDP);
486 __SS__ <<
"FATAL Console error. Could not initialize socket at ip '"
487 << ipAddressForRemoteControlOverUDP <<
"' and port "
488 << portForRemoteControlOverUDP
489 <<
". Perhaps it is already in use? Exiting Remote Control "
490 "SOAPUtilities::receive loop."
497 __COUT__ <<
"UDP Remote Control workloop starting..." << __E__;
507 buffer, 0 , 1 ,
false ) !=
510 __COUT__ <<
"UDP Remote Control packet received of size = " << buffer.size()
516 if(buffer ==
"GetFrontendMacroInfo")
519 theSupervisor->getFEMacroList(xmldoc,
"NO-USER");
521 std::stringstream out;
525 __COUT__ <<
"out: " << out.str();
526 sock.acknowledge(out.str(),
true );
528 else if(buffer.find(
"RunFrontendMacro") == 0)
532 std::vector<std::string> bufferFields =
534 if(bufferFields.size() < 8)
536 __SS__ <<
"Missing input arguments for running FE Macro: "
537 << bufferFields.size() <<
" vs 8 expected" << __E__;
541 std::string feClassSelected = bufferFields[1];
542 std::string feUIDSelected =
544 std::string macroType = bufferFields[3];
545 std::string macroName =
549 std::string outputArgs =
551 bool saveOutputs = bufferFields[7] ==
"1";
552 std::string username =
"NO-USER";
553 std::string userGroupPermission =
"allUsers: 255";
555 theSupervisor->runFEMacro(xmldoc,
564 userGroupPermission);
566 std::stringstream out;
570 __COUT__ <<
"out: " << out.str();
571 sock.acknowledge(out.str(),
true );
575 __SS__ <<
"Unrecognized UDP command received: " << buffer << __E__;
579 catch(
const std::runtime_error& e)
581 __COUT_ERR__ <<
"Error during UDP command handling: " << e.what()
583 sock.acknowledge(std::string(
"Error: ") + e.what(),
true );
587 __COUT_ERR__ <<
"Unknown error caught during UDP command handling - "
590 sock.acknowledge(std::string(
"Error: ") +
"unknown error caught",
594 __COUT__ <<
"Done handling command '" << buffer <<
"'" << __E__;
604 void MacroMakerSupervisor::requestWrapper(xgi::Input* in, xgi::Output* out)
607 if(!CorePropertySupervisorBase::allSupervisorInfo_.isMacroMakerMode())
609 __SUP_COUTT__ <<
"Default request wrapper" << __E__;
610 return CoreSupervisorBase::requestWrapper(in, out);
614 __SUP_COUTT__ <<
"MacroMaker mode request handler!" << __E__;
618 cgicc::Cgicc cgiIn(in);
623 if(securityCode_.compare(submittedSequence) != 0)
625 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match! "
631 __COUT__ <<
"***Successfully authenticated security sequence. " << time(0)
638 __SUP_COUT_TYPE__(TLVL_DEBUG + 10) << __COUT_HDR__ <<
"requestType " << requestType
639 <<
" files: " << cgiIn.getFiles().size() << __E__;
642 WebUsers::RequestUserInfo userInfo(
648 userInfo.username_ =
"admin";
649 userInfo.displayName_ =
"Admin";
650 userInfo.usernameWithLock_ =
"admin";
651 userInfo.userSessionIndex_ = 0;
652 std::map<std::string , WebUsers::permissionLevel_t> initPermissions = {
656 if(1 || !userInfo.automatedCommand_)
657 __SUP_COUT__ <<
"requestType: " << requestType << __E__;
659 if(userInfo.NonXMLRequestType_)
665 catch(
const std::runtime_error& e)
667 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
668 <<
"':" << e.what() << __E__;
669 __SUP_COUT_ERR__ <<
"\n" << ss.str();
673 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
674 << requestType <<
".' "
675 <<
"Please check the printouts to debug." << __E__;
680 catch(
const std::exception& e)
682 ss <<
"Exception message: " << e.what();
687 __SUP_COUT_ERR__ <<
"\n" << ss.str();
696 request(requestType, cgiIn, xmlOut, userInfo);
697 __SUP_COUTT__ <<
"Request '" << requestType <<
"' complete." << __E__;
699 catch(
const std::runtime_error& e)
701 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
702 <<
"':" << e.what() << __E__;
703 __SUP_COUT_ERR__ <<
"\n" << ss.str();
704 xmlOut.addTextElementToData(
"Error", ss.str());
708 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
709 << requestType <<
".' "
710 <<
"Please check the printouts to debug." << __E__;
715 catch(
const std::exception& e)
717 ss <<
"Exception message: " << e.what();
722 __SUP_COUT_ERR__ <<
"\n" << ss.str();
723 xmlOut.addTextElementToData(
"Error", ss.str());
728 unsigned int occurance = 0;
732 __SUP_COUT_ERR__ <<
"'" << requestType <<
"' ERROR encountered: " << err
738 __SUP_COUTVS__(10, userInfo.NoXmlWhiteSpace_);
743 !userInfo.NoXmlWhiteSpace_ );
747 void MacroMakerSupervisor::request(
const std::string& requestType,
750 const WebUsers::RequestUserInfo& userInfo)
753 std::chrono::steady_clock::time_point requestStart = std::chrono::steady_clock::now();
754 time_t requestStartTime = time(0);
757 std::string username =
"";
758 for(
unsigned int i = 0; i < userInfo.username_.size(); ++i)
759 if((userInfo.username_[i] >=
'a' && userInfo.username_[i] <=
'z') ||
760 (userInfo.username_[i] >=
'A' && userInfo.username_[i] <=
'Z') ||
761 (userInfo.username_[i] >=
'0' && userInfo.username_[i] <=
'9') ||
762 userInfo.username_[i] >=
'-' || userInfo.username_[i] <=
'_')
763 username += userInfo.username_[i];
765 if(username.size() < 2)
767 __SUP_SS__ <<
"Illegal username '" << userInfo.username_ <<
"' received."
772 __SUP_COUT__ <<
"User name is " << userInfo.username_ <<
"." << __E__;
773 __SUP_COUT__ <<
"User permission level for request '" << requestType <<
"' is "
774 << unsigned(userInfo.permissionLevel_) <<
"." << __E__;
778 if(requestType ==
"loadFEHistory")
780 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
781 mkdir(histPath.c_str(), 0755);
784 if(requestType ==
"loadFEMacroSequences")
786 std::string seqPath =
787 (std::string)MACROS_SEQUENCE_PATH + userInfo.username_ +
"/";
788 mkdir(seqPath.c_str(), 0755);
791 if(requestType ==
"getPermission")
793 xmlOut.addTextElementToData(
"Permission",
794 std::to_string(
unsigned(userInfo.permissionLevel_)));
797 std::string publicPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
798 mkdir(publicPath.c_str(), 0755);
799 std::string exportPath =
800 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + userInfo.username_ +
"/";
801 mkdir(exportPath.c_str(), 0755);
804 handleRequest(requestType, xmlOut, cgiIn, userInfo);
806 __SUP_COUTT__ <<
"Total MacroMaker request time: "
807 << artdaq::TimeUtils::GetElapsedTime(requestStart) <<
" = "
808 << time(0) - requestStartTime <<
" seconds" << __E__;
810 catch(
const std::runtime_error& e)
812 __SS__ <<
"Error occurred handling request '" << requestType <<
"': " << e.what()
814 __SUP_COUT__ << ss.str();
815 xmlOut.addTextElementToData(
"Error", ss.str());
819 __SS__ <<
"Unknown error occurred handling request '" << requestType <<
"!'" << __E__;
824 catch(
const std::exception& e)
826 ss <<
"Exception message: " << e.what();
831 __SUP_COUT__ << ss.str();
832 xmlOut.addTextElementToData(
"Error", ss.str());
837 void MacroMakerSupervisor::handleRequest(
const std::string Command,
840 const WebUsers::RequestUserInfo& userInfo)
842 if(Command ==
"FElist")
845 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
846 mkdir(macroPath.c_str(), 0755);
847 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
848 mkdir(histPath.c_str(), 0755);
852 else if(Command ==
"writeData")
853 writeData(xmldoc, cgi, userInfo.username_);
854 else if(Command ==
"readData")
855 readData(xmldoc, cgi, userInfo.username_);
856 else if(Command ==
"createMacro")
857 createMacro(xmldoc, cgi, userInfo.username_);
858 else if(Command ==
"loadMacros")
859 loadMacros(xmldoc, userInfo.username_);
860 else if(Command ==
"loadHistory")
861 loadHistory(xmldoc, userInfo.username_);
862 else if(Command ==
"deleteMacro")
863 deleteMacro(xmldoc, cgi, userInfo.username_);
864 else if(Command ==
"editMacro")
865 editMacro(xmldoc, cgi, userInfo.username_);
866 else if(Command ==
"clearHistory")
867 clearHistory(userInfo.username_);
868 else if(Command ==
"exportMacro")
869 exportMacro(xmldoc, cgi, userInfo.username_);
870 else if(Command ==
"exportFEMacro")
871 exportFEMacro(xmldoc, cgi, userInfo.username_);
872 else if(Command ==
"getFEMacroList")
876 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
877 mkdir(macroPath.c_str(), 0755);
878 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
879 mkdir(histPath.c_str(), 0755);
881 getFEMacroList(xmldoc, userInfo.username_);
883 else if(Command ==
"runFEMacro")
885 runFEMacro(xmldoc, cgi, userInfo);
886 else if(Command ==
"loadFEHistory")
888 loadFEHistory(xmldoc, userInfo.username_);
889 else if(Command ==
"clearFEHistory")
891 clearFEHistory(userInfo.username_);
892 else if(Command ==
"loadFEMacroSequences")
893 loadFEMacroSequences(xmldoc, userInfo.username_);
894 else if(Command ==
"saveFEMacroSequence")
895 saveFEMacroSequence(cgi, userInfo.username_);
896 else if(Command ==
"getFEMacroSequence")
897 getFEMacroSequence(xmldoc, cgi, userInfo.username_);
898 else if(Command ==
"deleteFEMacroSequence")
899 deleteFEMacroSequence(cgi, userInfo.username_);
900 else if(Command ==
"makeSequencePublic")
901 makeSequencePublic(cgi, userInfo.username_);
903 xmldoc.addTextElementToData(
"Error",
904 "Command '" + Command +
905 "' not recognized by the Macro Maker Supervisor "
906 "(was it intended for another Supervisor?).");
910 xoap::MessageReference MacroMakerSupervisor::frontEndCommunicationRequest(
911 xoap::MessageReference message)
915 __SUP_COUT__ <<
"FE Request received: " << SOAPUtilities::translate(message) << __E__;
919 SOAPUtilities::receive(message, typeParameter);
921 std::string type = typeParameter.getValue(
"type");
923 std::string error =
"";
925 if(type ==
"initFElist")
931 SOAPUtilities::receive(message, rxParameters);
933 std::string groupName = rxParameters.getValue(
"groupName");
934 std::string groupKey = rxParameters.getValue(
"groupKey");
936 __SUP_COUTV__(groupName);
937 __SUP_COUTV__(groupKey);
945 const SupervisorInfoMap& feTypeSupervisors =
946 CorePropertySupervisorBase::allSupervisorInfo_.getAllFETypeSupervisorInfo();
949 cfgMgr.
getNode(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME);
951 __SUP_COUT__ <<
"Number of FE Supervisors found = " << feTypeSupervisors.size()
954 FEPluginTypetoFEsMap_.clear();
955 FEtoSupervisorMap_.clear();
956 FEtoPluginTypeMap_.clear();
957 for(
auto& feApp : feTypeSupervisors)
959 __SUP_COUT__ <<
"FEs for app " << feApp.first <<
":" << feApp.second.getName()
962 auto feChildren = appsNode.
getNode(feApp.second.getName())
963 .
getNode(
"LinkToSupervisorTable")
964 .
getNode(
"LinkToFEInterfaceTable")
967 for(
auto& fe : feChildren)
969 if(!fe.second.status())
972 __SUP_COUTV__(fe.first);
973 FEtoSupervisorMap_[fe.first] = feApp.first;
975 std::string pluginType =
976 fe.second.getNode(
"FEInterfacePluginName").getValue();
977 FEPluginTypetoFEsMap_[pluginType].emplace(fe.first);
978 FEtoPluginTypeMap_[fe.first] = pluginType;
986 else if(type ==
"feSend" ||
988 type ==
"feMacroMultiDimensionalStart" ||
989 type ==
"feMacroMultiDimensionalCheck" ||
990 type ==
"macroMultiDimensionalStart" ||
991 type ==
"macroMultiDimensionalCheck")
996 SOAPUtilities::receive(message, rxParameters);
998 std::string targetInterfaceID = rxParameters.getValue(
"targetInterfaceID");
1000 __SUP_COUTV__(targetInterfaceID);
1002 auto feIt = FEtoSupervisorMap_.find(targetInterfaceID);
1003 if(feIt == FEtoSupervisorMap_.end())
1005 __SUP_SS__ <<
"Destination front end interface ID '" << targetInterfaceID
1006 <<
"' was not found in the list of front ends." << __E__;
1010 unsigned int FESupervisorIndex = feIt->second;
1011 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
1013 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1014 if(it == allFESupervisorInfo_.end())
1016 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1017 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' \n\n"
1018 <<
"The FE Supervisor Index does not exist. Have you configured "
1019 "the state machine properly?"
1024 if(type ==
"macroMultiDimensionalStart")
1030 SOAPUtilities::receive(message, rxParameters);
1031 std::string macroName = rxParameters.getValue(
"macroName");
1032 __SUP_COUTV__(macroName);
1034 std::string macroString;
1035 loadMacro(macroName, macroString);
1039 SOAPUtilities::addParameters(message, parameters);
1044 __SUP_COUT__ <<
"Forwarding request: " << SOAPUtilities::translate(message)
1047 xoap::MessageReference replyMessage =
1048 SOAPMessenger::sendWithSOAPReply(it->second.getDescriptor(), message);
1050 if(type !=
"feSend")
1052 __SUP_COUT__ <<
"Forwarding FE Macro response: "
1053 << SOAPUtilities::translate(replyMessage) << __E__;
1055 return replyMessage;
1058 catch(
const xdaq::exception::Exception& e)
1060 __SUP_SS__ <<
"Error forwarding FE Communication request to FE Supervisor '"
1061 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' "
1062 <<
"Have you configured the state machine properly?\n\n"
1063 << e.what() << __E__;
1069 __SUP_SS__ <<
"Unrecognized FE Communication type: " << type << __E__;
1073 return SOAPUtilities::makeSOAPMessageReference(
"Received");
1075 catch(
const std::runtime_error& e)
1077 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
1078 __SUP_COUT_ERR__ << ss.str();
1080 xoap::MessageReference returnMessage =
1081 SOAPUtilities::makeSOAPMessageReference(
"Error");
1085 SOAPUtilities::addParameters(returnMessage, parameters);
1086 return returnMessage;
1090 xoap::MessageReference returnMessage =
1091 SOAPUtilities::makeSOAPMessageReference(
"Error");
1093 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
1098 catch(
const std::exception& e)
1100 ss <<
"Exception message: " << e.what();
1105 __SUP_COUT_ERR__ << ss.str();
1109 SOAPUtilities::addParameters(returnMessage, parameters);
1110 return returnMessage;
1116 __SUP_COUT__ <<
"Getting FE list!!!!!!!!!" << __E__;
1128 SupervisorInfoMap::const_iterator it;
1129 std::string oneInterface;
1130 std::string rxFEList;
1131 std::string rxFrontEndError;
1133 size_t lastColonIndex;
1137 for(
auto& appInfo : allFESupervisorInfo_)
1145 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
1146 <<
" name = " << appInfo.second.getName() << __E__;
1150 xoap::MessageReference retMsg =
1151 SOAPMessenger::sendWithSOAPReply(appInfo.second.getDescriptor(),
1152 "MacroMakerSupervisorRequest",
1154 SOAPUtilities::receive(retMsg, rxParameters);
1156 __SUP_COUT__ <<
"Received MacroMaker response: "
1157 << SOAPUtilities::translate(retMsg).getCommand() <<
"==>"
1158 << SOAPUtilities::translate(retMsg) << __E__;
1160 if(SOAPUtilities::translate(retMsg).getCommand() ==
"Fault")
1162 __SUP_SS__ <<
"Unrecognized command received!" << __E__;
1166 catch(
const xdaq::exception::Exception& e)
1168 __SUP_SS__ <<
"Error transmitting request to FE Supervisor LID = "
1169 << appInfo.second.getId() <<
" name = " << appInfo.second.getName()
1171 << e.what() << __E__;
1175 rxFEList = rxParameters.getValue(
"FEList");
1176 rxFrontEndError = rxParameters.getValue(
"frontEndError");
1178 __SUP_COUT__ <<
"FE List received: \n" << rxFEList << __E__;
1180 if(rxFrontEndError !=
"")
1182 __SUP_SS__ <<
"FE Errors received: \n" << rxFrontEndError << __E__;
1186 std::istringstream allInterfaces(rxFEList);
1187 while(std::getline(allInterfaces, oneInterface))
1189 __SUP_COUTV__(oneInterface);
1190 xmldoc.addTextElementToData(
"FE", oneInterface);
1192 lastColonIndex = oneInterface.rfind(
':');
1193 if(lastColonIndex == std::string::npos)
1195 __SUP_SS__ <<
"Last colon could not be found in " << oneInterface
1199 oneInterface = oneInterface.substr(lastColonIndex);
1201 __SUP_COUTV__(oneInterface);
1211 const std::string& username)
1213 __SUP_COUT__ <<
"MacroMaker writing..." << __E__;
1226 __SUP_COUT__ <<
"Write Address: " << Address <<
" Data: " << Data << __E__;
1227 __SUP_COUTV__(interfaces);
1229 std::string command =
"w:" + Address +
":" + Data;
1230 std::string format = addressFormatStr +
":" + dataFormatStr;
1231 appendCommandToHistory(command, format, time, interfaces, username);
1234 txParameters.
addParameter(
"Request",
"UniversalWrite");
1238 __SUP_COUT__ <<
"Here comes the array from multiselect box for WRITE, behold: \n"
1239 << supervisorIndexArray <<
"\n"
1240 << interfaceIndexArray << __E__;
1244 std::vector<std::string> interfaceIndices;
1245 std::istringstream f(interfaceIndexArray);
1247 while(getline(f, s,
','))
1248 interfaceIndices.push_back(s);
1249 std::vector<int> supervisorIndices;
1250 std::istringstream g(supervisorIndexArray);
1252 while(getline(g, t,
','))
1253 supervisorIndices.push_back(std::stoi(t));
1255 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
1257 unsigned int FESupervisorIndex = supervisorIndices[i];
1258 std::string interfaceIndex = interfaceIndices[i];
1260 txParameters.
addParameter(
"InterfaceID", interfaceIndex);
1262 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
1264 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
1266 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1267 if(it == allFESupervisorInfo_.end())
1269 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1270 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
1271 <<
"The FE Index doesn't exist. Have you configured the state "
1279 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1280 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1282 __SUP_COUT__ <<
"Response received: "
1283 << SOAPUtilities::translate(replyMessage) << __E__;
1287 SOAPUtilities::receive(replyMessage, rxParameters);
1289 std::string error = rxParameters.getValue(
"Error");
1290 __SUP_COUTV__(error);
1295 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1296 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1297 <<
"Have you configured the state machine properly?\n\n"
1302 catch(
const xdaq::exception::Exception& e)
1304 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1305 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1306 <<
"Have you configured the state machine properly?\n\n"
1307 << e.what() << __E__;
1317 const std::string& username)
1319 __SUP_COUT__ <<
"@@@@@@@ MacroMaker wants to read data @@@@@@@@" << __E__;
1330 __SUP_COUT__ <<
"Read Address: " << Address << __E__;
1331 __SUP_COUTV__(interfaces);
1340 __SUP_COUT__ <<
"Here comes the array from multiselect box for READ, behold: "
1341 << supervisorIndexArray <<
"," << interfaceIndexArray << __E__;
1345 std::vector<std::string> interfaceIndices;
1346 std::istringstream f(interfaceIndexArray);
1348 while(getline(f, s,
','))
1349 interfaceIndices.push_back(s);
1350 std::vector<int> supervisorIndices;
1351 std::istringstream g(supervisorIndexArray);
1353 while(getline(g, t,
','))
1354 supervisorIndices.push_back(std::stoi(t));
1356 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
1358 unsigned int FESupervisorIndex = supervisorIndices[i];
1359 std::string interfaceIndex = interfaceIndices[i];
1361 txParameters.
addParameter(
"InterfaceID", interfaceIndex);
1363 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
1365 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
1367 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1368 if(it == allFESupervisorInfo_.end())
1370 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1371 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
1372 <<
"The FE Index doesn't exist. Have you configured the state "
1380 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
1381 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1383 __SUP_COUT__ <<
"Response received: " << SOAPUtilities::translate(retMsg)
1388 SOAPUtilities::receive(retMsg, rxParameters);
1390 std::string error = rxParameters.getValue(
"Error");
1391 __SUP_COUTV__(error);
1396 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1397 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1398 <<
"Have you configured the state machine properly?\n\n"
1403 catch(
const xdaq::exception::Exception& e)
1405 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1406 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1407 <<
"Have you configured the state machine properly?\n\n"
1408 << e.what() << __E__;
1412 std::string dataReadResult = rxParameters.getValue(
"dataResult");
1413 __SUP_COUT__ <<
"Data reading result received: " << dataReadResult << __E__;
1414 xmldoc.addTextElementToData(
"readData", dataReadResult);
1415 std::string command =
"r:" + Address +
":" + dataReadResult;
1416 std::string format = addressFormatStr +
":" + dataFormatStr;
1417 appendCommandToHistory(command, format, time, interfaces, username);
1424 const std::string& username)
1426 __SUP_COUT__ <<
"MacroMaker wants to create a macro!!!!!!!!!" << __E__;
1435 __SUP_COUTV__(Name);
1436 __SUP_COUTV__(Sequence);
1437 __SUP_COUTV__(Notes);
1438 __SUP_COUTV__(Time);
1439 __SUP_COUTV__(isMacroPublic);
1440 __SUP_COUTV__(isMacroLSBF);
1442 __SUP_COUTV__(MACROS_DB_PATH);
1444 std::string fileName = Name +
".dat";
1445 std::string fullPath;
1446 if(isMacroPublic ==
"true")
1447 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
1449 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
1451 __SUP_COUTV__(fullPath);
1453 std::ofstream macrofile(fullPath.c_str());
1454 if(macrofile.is_open())
1457 macrofile <<
"\"name\":\"" << Name <<
"\",\n";
1458 macrofile <<
"\"sequence\":\"" << Sequence <<
"\",\n";
1459 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
1460 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
1461 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
1462 macrofile <<
"}@" << __E__;
1467 __SUP_SS__ <<
"Unable to open file" << __E__;
1480 void MacroMakerSupervisor::loadMacro(
const std::string& macroName,
1481 std::string& macroString,
1482 const std::string& username )
1484 __SUP_COUTV__(macroName);
1487 std::string fullPath, line;
1489 for(
unsigned int i = 0; i < 2; ++i)
1492 fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1494 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1496 fullPath += macroName;
1497 if(macroName.find(
".dat") != macroName.size() - 4)
1499 __SUP_COUTV__(fullPath);
1501 std::ifstream read(fullPath.c_str());
1506 getline(read, line);
1507 macroString += line;
1514 __SUP_COUT__ <<
"Unable to open file: " << fullPath << __E__;
1518 if(macroString !=
"")
1522 if(macroString ==
"")
1524 __SUP_SS__ <<
"Unable to locate file for macro '" << macroName
1525 <<
"'... does it exist?" << __E__;
1527 ss <<
" Attempted username was '" << username <<
".'" << __E__;
1531 __SUP_COUTV__(macroString);
1535 void MacroMakerSupervisor::loadMacroNames(
1536 const std::string& username,
1537 std::pair<std::vector<std::string> ,
1538 std::vector<std::string> >& returnMacroNames)
1542 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1543 if((dir = opendir(fullPath.c_str())) != NULL)
1546 while((ent = readdir(dir)) != NULL)
1549 if((
unsigned)strlen(ent->d_name) > 4)
1553 ((fullPath + (std::string)ent->d_name)).c_str());
1558 returnMacroNames.second.push_back(ent->d_name);
1561 __SUP_COUT__ <<
"Unable to open file" << __E__;
1568 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1571 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1572 if((dir = opendir(fullPath.c_str())) != NULL)
1575 while((ent = readdir(dir)) != NULL)
1578 if((
unsigned)strlen(ent->d_name) > 4)
1582 ((fullPath + (std::string)ent->d_name)).c_str());
1586 returnMacroNames.first.push_back(ent->d_name);
1590 __SUP_COUT__ <<
"Unable to open file" << __E__;
1597 __SUP_COUT__ << fullPath << __E__;
1598 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1606 const std::string& username)
1610 std::string returnStr =
"";
1611 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1612 if((dir = opendir(fullPath.c_str())) != NULL)
1615 while((ent = readdir(dir)) != NULL)
1618 if((
unsigned)strlen(ent->d_name) > 4)
1622 ((fullPath + (std::string)ent->d_name)).c_str());
1625 std::stringstream buffer;
1628 getline(read, line);
1632 returnStr += buffer.str();
1637 __SUP_COUT__ <<
"Unable to open file" << __E__;
1640 std::string returnMacroStr = returnStr.substr(0, returnStr.size() - 1);
1642 __SUP_COUT__ <<
"Loading existing macros! " << returnMacroStr << __E__;
1645 xmldoc.addTextElementToData(
"returnMacroStr", returnMacroStr);
1649 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1652 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1654 if((dir = opendir(fullPath.c_str())) != NULL)
1657 while((ent = readdir(dir)) != NULL)
1660 if((
unsigned)strlen(ent->d_name) > 4)
1664 ((fullPath + (std::string)ent->d_name)).c_str());
1667 std::stringstream buffer;
1670 getline(read, line);
1674 returnStr += buffer.str();
1678 __SUP_COUT__ <<
"Unable to open file" << __E__;
1681 std::string returnPublicStr = returnStr.substr(0, returnStr.size() - 1);
1682 __SUP_COUT__ <<
"Loading existing public macros: " << returnPublicStr << __E__;
1684 xmldoc.addTextElementToData(
"returnPublicStr", returnPublicStr);
1688 __SUP_COUT__ << fullPath << __E__;
1689 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1695 void MacroMakerSupervisor::appendCommandToHistory(std::string Command,
1698 std::string Interfaces,
1699 const std::string& username)
1701 std::string fileName =
"history.hist";
1702 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1703 __SUP_COUT__ << fullPath << __E__;
1704 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1705 if(histfile.is_open())
1708 histfile <<
"\"Command\":\"" << Command <<
"\",\n";
1709 histfile <<
"\"Format\":\"" << Format <<
"\",\n";
1710 histfile <<
"\"Time\":\"" << Time <<
"\",\n";
1711 histfile <<
"\"Interfaces\":\"" << Interfaces <<
"\"\n";
1712 histfile <<
"}#" << __E__;
1717 __SUP_SS__ <<
"Unable to open history.hist at " << fullPath << __E__;
1723 void MacroMakerSupervisor::appendCommandToHistory(std::string feClass,
1725 std::string macroType,
1726 std::string macroName,
1727 std::string inputArgs,
1728 std::string outputArgs,
1730 const std::string& username)
1733 auto feHistoryIt = lastFeCommandToHistory_.find(username);
1734 if(feHistoryIt != lastFeCommandToHistory_.end() && feHistoryIt->second.size() == 7 &&
1735 feHistoryIt->second[0] == feClass && feHistoryIt->second[1] == feUID &&
1736 feHistoryIt->second[2] == macroType && feHistoryIt->second[3] == macroName &&
1737 feHistoryIt->second[4] == inputArgs && feHistoryIt->second[5] == outputArgs &&
1738 feHistoryIt->second[6] == (saveOutputs ?
"1" :
"0"))
1740 __SUP_COUTT__ <<
"Not saving repeat command to history from user " << username
1745 std::string fileName =
"FEhistory.hist";
1746 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1747 __SUP_COUT__ << fullPath << __E__;
1748 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1749 if(histfile.is_open())
1752 histfile <<
"\"feClass\":\"" << feClass <<
"\",\n";
1753 histfile <<
"\"feUID\":\"" << feUID <<
"\",\n";
1754 histfile <<
"\"macroType\":\"" << macroType <<
"\",\n";
1755 histfile <<
"\"macroName\":\"" << macroName <<
"\",\n";
1756 histfile <<
"\"inputArgs\":\"" << inputArgs <<
"\",\n";
1757 histfile <<
"\"outputArgs\":\"" << outputArgs <<
"\",\n";
1759 histfile <<
"\"saveOutputs\":\"" << 1 <<
"\"\n";
1761 histfile <<
"\"saveOutputs\":\"" << 0 <<
"\"\n";
1762 histfile <<
"}#" << __E__;
1765 lastFeCommandToHistory_[username].clear();
1766 feHistoryIt = lastFeCommandToHistory_.find(username);
1767 feHistoryIt->second.push_back(feClass);
1768 feHistoryIt->second.push_back(feUID);
1769 feHistoryIt->second.push_back(macroType);
1770 feHistoryIt->second.push_back(macroName);
1771 feHistoryIt->second.push_back(inputArgs);
1772 feHistoryIt->second.push_back(outputArgs);
1773 feHistoryIt->second.push_back((saveOutputs ?
"1" :
"0"));
1777 __SUP_SS__ <<
"Unable to open FEhistory.hist at " << fullPath << __E__;
1784 void MacroMakerSupervisor::loadFEMacroSequences(
HttpXmlDocument& xmldoc,
1785 const std::string& username)
1787 __SUP_COUT__ <<
"loadFEMacroSequences for " << username << __E__;
1790 std::string fullPath = (std::string)MACROS_SEQUENCE_PATH + username +
"/";
1791 std::string sequences =
"";
1792 __SUP_COUTV__(fullPath);
1793 if((dir = opendir(fullPath.c_str())) != NULL)
1796 while((ent = readdir(dir)) != NULL)
1800 ((fullPath + (std::string)ent->d_name)).c_str());
1804 sequences += ent->d_name + std::string(
";");
1807 __SUP_COUT__ <<
"Unable to open file" << __E__;
1813 __SUP_COUT__ <<
"Looping through MacroSequence/" + username +
1814 " folder failed! Invalid directory."
1818 if(username == WebUsers::DEFAULT_ADMIN_USERNAME)
1821 xmldoc.addTextElementToData(
"FEsequences", sequences);
1826 fullPath = (std::string)MACROS_SEQUENCE_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
"/";
1828 if((dir = opendir(fullPath.c_str())) != NULL)
1831 while((ent = readdir(dir)) != NULL)
1835 ((fullPath + (std::string)ent->d_name)).c_str());
1839 sequences += std::string(
"public/") + ent->d_name + std::string(
";");
1842 __SUP_COUT__ <<
"Unable to open file" << __E__;
1848 __SUP_COUT__ <<
"Looping through MacroSequence/" +
1849 WebUsers::DEFAULT_ADMIN_USERNAME +
1850 " folder failed! Invalid directory."
1855 xmldoc.addTextElementToData(
"FEsequences", sequences);
1859 void MacroMakerSupervisor::saveFEMacroSequence(cgicc::Cgicc& cgi,
1860 const std::string& username)
1865 std::string FEsequence =
1867 bool overwrite = CgiDataUtilities::getDataAsInt(cgi,
"overwrite");
1869 __SUP_COUTV__(overwrite);
1870 __SUP_COUTV__(name);
1871 __SUP_COUTV__(FEsequence);
1874 std::string fixedName =
"";
1875 for(
size_t i = 0; i < name.size(); ++i)
1876 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
1877 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
1878 (name[i] >=
'a' && name[i] <=
'z')))
1881 <<
"Illegal character in Sequence name (position " << i
1882 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
1887 fixedName += name[i];
1888 __SUP_COUTV__(fixedName);
1890 std::string fullPath =
1891 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
1892 __SUP_COUTV__(fullPath);
1895 if(!overwrite && std::filesystem::exists(fullPath))
1897 __SUP_SS__ <<
"Please choose another Sequence name! A sequence with the same "
1898 "resulting filename already exists at "
1899 << fullPath << __E__;
1903 std::ofstream seqfile(fullPath.c_str());
1904 if(seqfile.is_open())
1906 seqfile << FEsequence << __E__;
1911 __SUP_SS__ <<
"Unable to open file to save FE Macro Sequence at " << fullPath
1918 void MacroMakerSupervisor::getFEMacroSequence(
HttpXmlDocument& xmldoc,
1920 const std::string& username)
1924 __SUP_COUTV__(name);
1926 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
1927 __SUP_COUTV__(isPublic);
1930 std::string fixedName =
"";
1931 for(
size_t i = (isPublic ? std::string(
"public/").size() : 0); i < name.size(); ++i)
1932 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
1933 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
1934 (name[i] >=
'a' && name[i] <=
'z')))
1936 __COUT__ <<
"Illegal character in Sequence name (position " << i
1937 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
1941 fixedName += name[i];
1942 __SUP_COUTV__(fixedName);
1945 std::string fullPath =
1946 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
1947 __SUP_COUT__ << fullPath << __E__;
1949 std::ifstream read(fullPath.c_str());
1951 unsigned long long fileSize;
1953 if(!isPublic && read.is_open())
1955 read.seekg(0, std::ios::end);
1956 fileSize = read.tellg();
1957 response =
new char[fileSize + 1];
1958 response[fileSize] =
'\0';
1959 read.seekg(0, std::ios::beg);
1962 read.read(response, fileSize);
1965 xmldoc.addTextElementToData(
"FEsequence", &response[0]);
1972 __SUP_COUT__ <<
"Unable to open " << fullPath <<
"! Trying public area..."
1976 std::string publicFullPath = (std::string)MACROS_SEQUENCE_PATH +
1977 WebUsers::DEFAULT_ADMIN_USERNAME +
"/" + fixedName +
1979 __SUP_COUT__ << publicFullPath << __E__;
1981 std::ifstream read(publicFullPath.c_str());
1983 unsigned long long fileSize;
1987 read.seekg(0, std::ios::end);
1988 fileSize = read.tellg();
1989 response =
new char[fileSize + 1];
1990 response[fileSize] =
'\0';
1991 read.seekg(0, std::ios::beg);
1994 read.read(response, fileSize);
1997 xmldoc.addTextElementToData(
"FEsequence", &response[0]);
2003 __SUP_SS__ <<
"Unable to open FE Macro Sequence at " << fullPath <<
" or "
2004 << publicFullPath << __E__;
2011 void MacroMakerSupervisor::deleteFEMacroSequence(cgicc::Cgicc& cgi,
2012 const std::string& username)
2016 __SUP_COUTV__(name);
2018 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
2019 __SUP_COUTV__(isPublic);
2022 std::string fixedName =
"";
2023 for(
size_t i = (isPublic ? std::string(
"public/").size() : 0); i < name.size(); ++i)
2024 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
2025 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
2026 (name[i] >=
'a' && name[i] <=
'z')))
2028 __COUT__ <<
"Illegal character in Sequence name (position " << i
2029 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2033 fixedName += name[i];
2034 __SUP_COUTV__(fixedName);
2037 std::string fullPath =
2038 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2040 fullPath = (std::string)MACROS_SEQUENCE_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
2041 "/" + fixedName +
".dat";
2042 __SUP_COUT__ << fullPath << __E__;
2045 if(!std::filesystem::exists(fullPath))
2048 <<
"The specified Sequence name does not exist! Looking for sequence file at "
2049 << fullPath << __E__;
2053 std::remove(fullPath.c_str());
2054 __SUP_COUT__ <<
"Successfully deleted " << fullPath << __E__;
2058 void MacroMakerSupervisor::makeSequencePublic(cgicc::Cgicc& cgi,
2059 const std::string& username)
2063 __SUP_COUTV__(name);
2065 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
2066 __SUP_COUTV__(isPublic);
2069 __SUP_SS__ <<
"The specified Sequence name is already designated as public."
2075 std::string fixedName =
"";
2076 for(
size_t i = 0; i < name.size(); ++i)
2077 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
2078 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
2079 (name[i] >=
'a' && name[i] <=
'z')))
2081 __COUT__ <<
"Illegal character in Sequence name (position " << i
2082 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2086 fixedName += name[i];
2087 __SUP_COUTV__(fixedName);
2090 std::string source =
2091 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2092 __SUP_COUT__ << source << __E__;
2093 std::string destination = (std::string)MACROS_SEQUENCE_PATH +
2094 WebUsers::DEFAULT_ADMIN_USERNAME +
"/" + fixedName +
".dat";
2095 __SUP_COUT__ << destination << __E__;
2097 if(std::filesystem::exists(destination))
2099 __SUP_SS__ <<
"The sequence name '" << fixedName
2100 <<
"' already exists in the admin/public location: " << destination
2106 std::filesystem::copy_file(
2107 source, destination, std::filesystem::copy_options::skip_existing);
2108 __SUP_COUT__ <<
"Successfully made " << fixedName
2109 <<
" public at path: " << destination << __E__;
2114 const std::string& username)
2116 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"history.hist";
2118 std::ifstream read(fileName.c_str());
2119 __SUP_COUT__ << fileName << __E__;
2125 unsigned long long fileSz, i = 0, MAX_HISTORY_SIZE = 100000;
2129 read.seekg(0, std::ios::end);
2130 fileSz = read.tellg();
2131 returnStr =
new char[fileSz + 1];
2132 returnStr[fileSz] =
'\0';
2133 read.seekg(0, std::ios::beg);
2136 read.read(returnStr, fileSz);
2140 if(fileSz > MAX_HISTORY_SIZE)
2142 i = fileSz - MAX_HISTORY_SIZE;
2143 for(; i < fileSz; ++i)
2144 if(returnStr[i] ==
'#')
2153 FILE* fp = fopen(fileName.c_str(),
"w");
2157 __SS__ <<
"Big problem with macromaker history file: " << fileName
2161 fwrite(&returnStr[i], fileSz - i, 1, fp);
2165 __SUP_COUT__ <<
"Loading user history! " << __E__;
2168 returnStr[fileSz - 2] =
'\0';
2170 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
2175 __SUP_COUT__ <<
"Unable to open history.hist" << __E__;
2181 const std::string& username)
2183 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"FEhistory.hist";
2185 std::ifstream read(fileName.c_str());
2186 __SUP_COUT__ << fileName << __E__;
2188 if(!read.is_open() && username != WebUsers::DEFAULT_ADMIN_USERNAME)
2190 __SUP_COUT__ <<
"Unable to open FE history.hist.. Defaulting to admin's FE "
2191 "history as starting point."
2195 MACROS_HIST_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
"/" +
"FEhistory.hist";
2196 read.open(fileName.c_str());
2203 unsigned long long fileSize;
2204 unsigned long long i = 0;
2205 unsigned long long MAX_HISTORY_SIZE = 100000;
2208 read.seekg(0, std::ios::end);
2209 fileSize = read.tellg();
2210 returnStr =
new char[fileSize + 1];
2211 returnStr[fileSize] =
'\0';
2212 read.seekg(0, std::ios::beg);
2215 read.read(returnStr, fileSize);
2219 if(fileSize > MAX_HISTORY_SIZE)
2221 i = fileSize - MAX_HISTORY_SIZE;
2222 for(; i < fileSize; ++i)
2224 if(returnStr[i] ==
'#')
2234 FILE* fp = fopen(fileName.c_str(),
"w");
2238 __SS__ <<
"Big problem with FE history file: " << fileName << __E__;
2241 fwrite(&returnStr[i], fileSize - i, 1, fp);
2245 __SUP_COUT__ <<
"Loading user history! " << __E__;
2248 returnStr[fileSize - 2] =
'\0';
2250 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
2255 __SUP_COUT__ <<
"Unable to open FE history.hist" << __E__;
2262 const std::string& username)
2267 std::string fileName = MacroName +
".dat";
2268 std::string fullPath;
2269 if(isMacroPublic ==
"true")
2270 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
2272 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
2274 __SUP_COUT__ << fullPath << __E__;
2276 std::remove(fullPath.c_str());
2277 __SUP_COUT__ <<
"Successfully deleted " << MacroName;
2278 xmldoc.addTextElementToData(
"deletedMacroName", MacroName);
2284 const std::string& username)
2296 __SUP_COUTV__(oldMacroName);
2297 __SUP_COUTV__(newMacroName);
2298 __SUP_COUTV__(FESequence);
2299 __SUP_COUTV__(Notes);
2300 __SUP_COUTV__(Time);
2301 __SUP_COUTV__(isMacroPublic);
2302 __SUP_COUTV__(isMacroLSBF);
2304 __SUP_COUTV__(MACROS_DB_PATH);
2306 std::string fileName = oldMacroName +
".dat";
2307 std::string fullPath;
2308 if(isMacroPublic ==
"true")
2309 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
2311 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
2313 __SUP_COUTV__(fullPath);
2315 std::ofstream macrofile(fullPath.c_str());
2316 if(macrofile.is_open())
2319 macrofile <<
"\"name\":\"" << newMacroName <<
"\",\n";
2320 macrofile <<
"\"FEsequence\":\"" << FESequence <<
"\",\n";
2321 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
2322 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
2323 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
2324 macrofile <<
"}@" << __E__;
2328 __SUP_COUT__ <<
"Unable to open file" << __E__;
2330 if(oldMacroName != newMacroName)
2334 rename((MACROS_DB_PATH + username +
"/" + oldMacroName +
".dat").c_str(),
2335 (MACROS_DB_PATH + username +
"/" + newMacroName +
".dat").c_str());
2337 xmldoc.addTextElementToData(
"newMacroName", newMacroName);
2339 xmldoc.addTextElementToData(
"newMacroName",
"ERROR");
2344 void MacroMakerSupervisor::clearHistory(
const std::string& username)
2346 std::string fileName =
"history.hist";
2347 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
2349 std::remove(fullPath.c_str());
2350 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
2354 void MacroMakerSupervisor::clearFEHistory(
const std::string& username)
2356 std::string fileName =
"FEhistory.hist";
2357 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
2359 std::remove(fullPath.c_str());
2360 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
2366 const std::string& username)
2371 std::string macroNotes =
2374 __SUP_COUTV__(pluginName);
2375 __SUP_COUTV__(macroName);
2376 __SUP_COUTV__(macroSequence);
2379 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
2380 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
2381 macroNotes[i] =
' ';
2382 __SUP_COUTV__(macroNotes);
2384 std::stringstream ss(macroSequence);
2385 std::string command;
2386 std::vector<std::string> commands;
2388 while(getline(ss, command,
','))
2389 commands.push_back(command);
2393 std::map<std::string , std::set<std::string> >
2394 specialsCodeMap = CodeEditor::getSpecialsMap();
2397 auto specialsCodeMapIt = specialsCodeMap.find(CodeEditor::SPECIAL_TYPE_FEInterface);
2398 if(specialsCodeMapIt == specialsCodeMap.end())
2401 <<
"Could not find any FE Interface plugins in source code. Does MacroMaker "
2402 <<
"have access to the source code? Check that the Supervisor context places "
2404 <<
"location with access to the source code." << __E__;
2409 std::string headerFile = pluginName +
".h";
2410 std::string sourceFile = pluginName +
"_interface.cc";
2411 bool foundHeaderFile =
false;
2412 bool foundSourceFile =
false;
2413 for(
const auto& filePath : specialsCodeMapIt->second)
2415 if(!foundHeaderFile && filePath.find(headerFile) != std::string::npos)
2417 foundHeaderFile =
true;
2418 headerFile = filePath;
2419 __SUP_COUT__ <<
"found headerFile=" << filePath << __E__;
2421 if(!foundSourceFile && filePath.find(sourceFile) != std::string::npos)
2423 foundSourceFile =
true;
2424 sourceFile = filePath;
2425 __SUP_COUT__ <<
"found sourceFile=" << filePath << __E__;
2428 if(foundSourceFile && foundHeaderFile)
2432 if(!foundHeaderFile)
2434 __SS__ <<
"Could not find the header file for the FE Interface plugins at '"
2435 << headerFile <<
".' Does MacroMaker "
2436 <<
"have access to the source code? Check that the Supervisor context "
2437 "places MacroMaker in a "
2438 <<
"location with access to the source code." << __E__;
2441 if(!foundSourceFile)
2443 __SS__ <<
"Could not find the source file for the FE Interface plugins at '"
2444 << sourceFile <<
".' Does MacroMaker "
2445 <<
"have access to the source code? Check that the Supervisor context "
2446 "places MacroMaker in a "
2447 <<
"location with access to the source code." << __E__;
2460 char timeBuffer[100];
2463 struct tm* timeinfo;
2466 timeinfo = localtime(&rawtime);
2468 strftime(timeBuffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
2471 std::string contents;
2476 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, sourceFile, contents);
2480 xmldoc.addTextElementToData(
"sourceFile", sourceFile);
2481 xmldoc.addTextElementToData(
"headerFile", headerFile);
2484 if(contents.find(pluginName +
"::" + macroName) != std::string::npos)
2486 __SS__ <<
"The function definition '" << (pluginName +
"::" + macroName)
2487 <<
"(...)' already exists in the source file '" << sourceFile
2488 <<
".' Duplicate functions are not allowed - please rename the macro or "
2489 "modify the source file."
2494 std::stringstream codess;
2495 std::set<std::string> inArgNames, outArgNames;
2507 auto insertPos = contents.find(pluginName +
"::" + pluginName);
2508 if(insertPos == std::string::npos)
2510 __SS__ <<
"Could not find the code insert position in the source file '"
2511 << sourceFile <<
".' The FE plugin class constructor must be '"
2512 << pluginName <<
":" << pluginName <<
"' - is this the case?" << __E__;
2515 __SUP_COUTV__(insertPos);
2517 insertPos = contents.find(
"{", insertPos);
2518 if(insertPos == std::string::npos)
2520 __SS__ <<
"Could not find the code insert position in the source file '"
2522 <<
".' The FE plugin class constructor must begin with '{"
2523 <<
"' - is this the case?" << __E__;
2527 __SUP_COUTV__(insertPos);
2529 insert =
"\n\t//registration of FEMacro '" + macroName +
"' generated, " +
2530 timeBuffer +
", by '" + username +
"' using MacroMaker.\n\t" +
2531 "FEVInterface::registerFEMacroFunction(\"" + macroName +
2532 "\",//feMacroName \n\t\t" +
2533 "static_cast<FEVInterface::frontEndMacroFunction_t>(&" + pluginName +
2534 "::" + macroName +
"), //feMacroFunction \n\t\t" +
2535 "std::vector<std::string>{";
2538 for(
const auto& inArg : inArgNames)
2544 insert +=
"\"" + inArg +
"\"";
2547 insert +=
"}, //namesOfInputArgs \n\t\t";
2548 insert +=
"std::vector<std::string>{";
2551 for(
const auto& outArg : outArgNames)
2557 insert +=
"\"" + outArg +
"\"";
2560 insert +=
"}, //namesOfOutputArgs \n\t\t";
2561 insert +=
"1); //requiredUserPermissions \n\n";
2563 __SUP_COUTV__(insert);
2564 contents = contents.substr(0, insertPos) + insert + contents.substr(insertPos);
2569 auto insertPos = contents.rfind(
"DEFINE_OTS_INTERFACE");
2570 if(insertPos == std::string::npos)
2572 __SS__ <<
"Could not find the code insert position in the source file '"
2574 <<
".' The FE plugin class must end with a 'DEFINE_OTS_INTERFACE("
2575 << pluginName <<
")' - is this the case?" << __E__;
2578 __SUP_COUTV__(insertPos);
2582 "============================================================================"
2583 "============================================\n//" +
2584 macroName +
"\n" +
"//\tFEMacro '" + macroName +
"' generated, " +
2585 timeBuffer +
", by '" + username +
"' using MacroMaker.\n" +
2586 "//\tMacro Notes: " + macroNotes +
"\n" +
"void " + pluginName +
2587 "::" + macroName +
"(__ARGS__)\n{\n\t" +
2588 "__CFG_COUT__ << \"# of input args = \" << argsIn.size() << __E__; \n\t" +
2589 "__CFG_COUT__ << \"# of output args = \" << argsOut.size() << __E__; \n\t" +
2590 "for(auto &argIn:argsIn) \n\t\t" +
2591 "__CFG_COUT__ << argIn.first << \": \" << argIn.second << __E__; \n\n\t" +
2592 "//macro commands section \n" + codess.str() +
"\n\n\t" +
2593 "for(auto &argOut:argsOut) \n\t\t" +
2594 "__CFG_COUT__ << argOut.first << \": \" << argOut.second << __E__; \n\n" +
2595 "} //end " + macroName +
"()\n\n";
2598 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
2601 "MacroMaker-" + username,
2608 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, headerFile, contents);
2613 auto insertPos = contents.rfind(
"};");
2614 if(insertPos == std::string::npos)
2616 __SS__ <<
"Could not find the code insert position in the header file '"
2618 <<
".' The FE plugin class must end with a '};' - is this the case?"
2623 __SUP_COUTV__(insertPos);
2625 insert =
"\npublic: // FEMacro '" + macroName +
"' generated, " + timeBuffer +
2626 ", by '" + username +
"' using MacroMaker.\n\t" +
"void " + macroName +
2629 __SUP_COUTV__(insert);
2630 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
2633 "MacroMaker-" + username,
2643 const std::string& username)
2647 std::string macroNotes =
2650 __SUP_COUTV__(macroName);
2651 __SUP_COUTV__(macroSequence);
2654 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
2655 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
2656 macroNotes[i] =
' ';
2657 __SUP_COUTV__(macroNotes);
2659 std::stringstream ss(macroSequence);
2660 std::string command;
2661 std::vector<std::string> commands;
2663 while(getline(ss, command,
','))
2664 commands.push_back(command);
2666 std::string fileName = macroName +
".cc";
2668 std::string fullPath =
2669 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + username +
"/" + fileName;
2670 __SUP_COUT__ << fullPath << __E__;
2671 std::ofstream exportFile(fullPath.c_str(), std::ios::trunc);
2672 if(exportFile.is_open())
2674 exportFile <<
"//Generated Macro Name:\t" << macroName <<
"\n";
2675 exportFile <<
"//Macro Notes: " << macroNotes <<
"\n";
2679 struct tm* timeinfo;
2683 timeinfo = localtime(&rawtime);
2685 strftime(buffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
2686 exportFile <<
"//Generated Time: \t\t" << buffer <<
"\n";
2689 exportFile <<
"//Paste this whole file into an interface to transfer Macro "
2692 createCode(exportFile, commands);
2696 xmldoc.addTextElementToData(
2698 "$USER_DATA/ServiceData/" + MACROS_EXPORT_PATH + username +
"/" + fileName);
2701 __SUP_COUT__ <<
"Unable to open file" << __E__;
2706 void MacroMakerSupervisor::createCode(std::ostream& out,
2707 const std::vector<std::string>& commands,
2708 const std::string& tabOffset,
2710 std::set<std::string>* inArgNames,
2711 std::set<std::string>* outArgNames)
2714 std::set<std::string > argInHasBeenInitializedSet;
2715 bool addressIsVariable, dataIsVariable;
2717 out << tabOffset <<
"{";
2720 << tabOffset <<
"\t"
2721 <<
"char *address \t= new char[universalAddressSize_]{0}; //create address "
2722 "buffer of interface size and init to all 0";
2724 << tabOffset <<
"\t"
2725 <<
"char *data \t\t= new char[universalDataSize_]{0}; //create data buffer "
2726 "of interface size and init to all 0";
2729 << tabOffset <<
"\t"
2730 <<
"uint64_t macroAddress; //create macro address buffer (size 8 bytes)";
2732 << tabOffset <<
"\t"
2733 <<
"uint64_t macroData; //create macro address buffer (size 8 bytes)";
2736 << tabOffset <<
"\t"
2737 <<
"std::map<std::string /*arg name*/,uint64_t /*arg val*/> macroArgs; //create "
2738 "map from arg name to 64-bit number";
2741 for(
unsigned int i = 0; i < commands.size(); i++)
2743 std::stringstream sst(commands[i]);
2745 std::vector<std::string>
2747 while(getline(sst, tokens,
':'))
2748 oneCommand.push_back(tokens);
2749 while(oneCommand.size() < 4)
2750 oneCommand.push_back(
"");
2778 addressIsVariable = isArgumentVariable(oneCommand[2]);
2779 dataIsVariable = isArgumentVariable(oneCommand[3]);
2781 __SUP_COUTV__(addressIsVariable);
2782 __SUP_COUTV__(dataIsVariable);
2784 out <<
"\n\n" << tabOffset <<
"\t// command-#" << i <<
": ";
2786 if(oneCommand[1][0] ==
'w' || oneCommand[1][0] ==
'r')
2788 if(oneCommand[1][0] ==
'w')
2790 else if(oneCommand[1][0] ==
'r')
2793 if(addressIsVariable)
2794 out << oneCommand[2];
2796 out <<
"0x" << oneCommand[2];
2797 out <<
" /*address*/,";
2801 out << oneCommand[3] <<
" /*data*/";
2802 else if(oneCommand[1][0] ==
'w')
2803 out <<
"0x" << oneCommand[3] <<
" /*data*/";
2804 else if(oneCommand[1][0] ==
'r')
2808 else if(oneCommand[1][0] ==
'd')
2810 out <<
"delay(" << oneCommand[2] <<
");\n";
2811 out << tabOffset <<
"\t"
2812 <<
"__CFG_COUT__ << \"Sleeping for... \" << " << oneCommand[2]
2813 <<
" << \" milliseconds \" << __E__;\n";
2814 out << tabOffset <<
"\t"
2815 <<
"usleep(" << oneCommand[2] <<
"*1000 /* microseconds */);\n";
2820 __SS__ <<
"FATAL ERROR: Unknown command '" << oneCommand[1]
2821 <<
"'... command is not w, r or d" << __E__;
2827 if(addressIsVariable)
2829 if(argInHasBeenInitializedSet.find(oneCommand[2]) ==
2830 argInHasBeenInitializedSet.end())
2832 argInHasBeenInitializedSet.emplace(oneCommand[2]);
2837 out << tabOffset <<
"\t"
2838 <<
"macroArgs[\"" << oneCommand[2]
2840 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2843 << tabOffset <<
"\t\t\"" << oneCommand[2]
2844 <<
"\").getValue<uint64_t>();";
2849 inArgNames->emplace(oneCommand[2]);
2852 out << tabOffset <<
"\t"
2853 <<
"macroArgs[\"" << oneCommand[2] <<
"\"] = __GET_ARG_IN__(\""
2854 << oneCommand[2] <<
"\", uint64_t);";
2857 out <<
"\t//get macro address argument";
2859 << tabOffset <<
"\tmemcpy(address,¯oArgs[\"" << oneCommand[2]
2860 <<
"\"],8); //copy macro address argument to buffer";
2864 out << tabOffset <<
"\t"
2865 <<
"macroAddress = 0x" << oneCommand[2]
2866 <<
"; memcpy(address,¯oAddress,8);"
2867 <<
"\t//copy macro address to buffer";
2872 if(oneCommand[1] ==
"w")
2876 if(argInHasBeenInitializedSet.find(oneCommand[3]) ==
2877 argInHasBeenInitializedSet
2880 argInHasBeenInitializedSet.emplace(oneCommand[3]);
2885 inArgNames->emplace(oneCommand[3]);
2889 << tabOffset <<
"\t"
2890 <<
"macroArgs[\"" << oneCommand[3]
2891 <<
"\"] = __GET_ARG_IN__(\"" << oneCommand[3]
2892 <<
"\", uint64_t); //initialize from input arguments";
2898 << tabOffset <<
"\t"
2899 <<
"macroArgs[\"" << oneCommand[3]
2901 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2904 << tabOffset <<
"\t\t\"" << oneCommand[3]
2905 <<
"\").getValue<uint64_t>(); //initialize from "
2906 "configuration tree";
2909 out <<
"\t//get macro data argument";
2911 << tabOffset <<
"\tmemcpy(data,¯oArgs[\"" << oneCommand[3]
2912 <<
"\"],8); //copy macro data argument to buffer";
2917 << tabOffset <<
"\t"
2918 <<
"macroData = 0x" << oneCommand[3] <<
"; memcpy(data,¯oData,8);"
2919 <<
"\t//copy macro data to buffer";
2922 << tabOffset <<
"\t"
2923 <<
"universalWrite(address,data);";
2928 << tabOffset <<
"\t"
2929 <<
"universalRead(address,data);";
2931 std::string outputArgName;
2934 outputArgName = oneCommand[3];
2938 sprintf(str,
"outArg%d", i);
2939 outputArgName = str;
2941 __SUP_COUTV__(outputArgName);
2943 out << tabOffset <<
"\t"
2944 <<
"memcpy(¯oArgs[\"" << outputArgName
2945 <<
"\"],data,8); //copy buffer to argument map";
2950 << tabOffset <<
"\t"
2951 <<
"__SET_ARG_OUT__(\"" << outputArgName <<
"\",macroArgs[\""
2952 << outputArgName <<
"\"]); //update output argument result";
2955 outArgNames->emplace(outputArgName);
2956 argInHasBeenInitializedSet.emplace(
2961 out <<
"\n\n" << tabOffset <<
"\tdelete[] address; //free the memory";
2962 out <<
"\n" << tabOffset <<
"\tdelete[] data; //free the memory";
2963 out <<
"\n" << tabOffset <<
"}";
2965 __SUP_COUT__ <<
"Done with code generation." << __E__;
2971 bool MacroMakerSupervisor::isArgumentVariable(
const std::string& argumentString)
2973 for(
unsigned int i = 0; i < argumentString.length(); ++i)
2976 if(!((argumentString[i] >=
'0' && argumentString[i] <=
'9') ||
2977 (argumentString[i] >=
'a' && argumentString[i] <=
'f') ||
2978 (argumentString[i] >=
'A' && argumentString[i] <=
'F')))
2993 std::string MacroMakerSupervisor::generateHexArray(
const std::string& sourceHexString,
2996 std::stringstream retSs;
2998 std::string srcHexStr = sourceHexString;
2999 __SUP_COUT__ <<
"Translating: \n";
3000 __SUP_COUT__ << srcHexStr << __E__;
3002 if(srcHexStr.size() % 2)
3003 srcHexStr =
"0" + srcHexStr;
3005 numOfBytes = srcHexStr.size() / 2;
3006 retSs <<
"[" << numOfBytes <<
"] = {";
3008 for(
int i = 0; i < numOfBytes * 2; i += 2)
3011 if(!((srcHexStr[i] >=
'0' && srcHexStr[i] <=
'9') ||
3012 (srcHexStr[i] >=
'a' && srcHexStr[i] <=
'f') ||
3013 (srcHexStr[i] >=
'A' && srcHexStr[i] <=
'F')) ||
3014 !((srcHexStr[i + 1] >=
'0' && srcHexStr[i + 1] <=
'9') ||
3015 (srcHexStr[i + 1] >=
'a' && srcHexStr[i + 1] <=
'f') ||
3016 (srcHexStr[i + 1] >=
'A' && srcHexStr[i + 1] <=
'F')))
3024 retSs <<
"0x" << srcHexStr[srcHexStr.size() - 1 - i - 1]
3025 << srcHexStr[srcHexStr.size() - 1 - i];
3029 __SUP_COUT__ << retSs.str() << __E__;
3037 const WebUsers::RequestUserInfo& userInfo)
3040 __SUP_COUTT__ << __E__;
3042 uint64_t NotDoneID = CgiDataUtilities::getDataAsUint64_t(cgi,
"NotDoneID");
3045 __SUP_COUT__ <<
"Checking if recent FE macro run has completed for NotDoneID = "
3046 << NotDoneID << __E__;
3048 for(
const auto& feMacroRunThreadStruct : feMacroRunThreadStruct_)
3049 __SUP_COUTT__ <<
"[] threadID_ = "
3050 << feMacroRunThreadStruct.parameters_.threadID_ << __E__;
3052 time_t now = time(0);
3053 size_t target_i = -1;
3054 for(
size_t i = 0; i < feMacroRunThreadStruct_.size(); ++i)
3056 if(feMacroRunThreadStruct_[i].parameters_.threadID_ == NotDoneID)
3059 __SUP_COUTT__ <<
"Found NotDoneID = " << NotDoneID << __E__;
3062 else if(feMacroRunThreadStruct_[i].feMacroRunDone_ &&
3063 now - feMacroRunThreadStruct_[i].parameters_.doneTime_ >
3066 __SUP_COUTT__ <<
"Cleaning up completed NotDoneID = " << NotDoneID
3069 feMacroRunThreadStruct_.erase(feMacroRunThreadStruct_.begin() + i);
3072 else if(now - feMacroRunThreadStruct_[i].parameters_.startTime_ >
3076 <<
"Found old FE Macro exectution of '"
3077 << feMacroRunThreadStruct_[i].parameters_.macroName_ <<
"' at '"
3078 << feMacroRunThreadStruct_[i].parameters_.feUIDSelected_ <<
".'"
3083 if(target_i >= feMacroRunThreadStruct_.size())
3086 <<
"Attempted to check recent FE Macro run completion with invalid ID="
3088 <<
". Perhaps this FE Macro completed more than 5 minutes ago?" << __E__;
3092 if(feMacroRunThreadStruct_[target_i].feMacroRunDone_)
3094 __SUP_COUT__ <<
"Found done for NotDoneID = " << NotDoneID << __E__;
3096 if(feMacroRunThreadStruct_[target_i].parameters_.feMacroRunError_ !=
"")
3099 << feMacroRunThreadStruct_[target_i].parameters_.feMacroRunError_;
3105 std::ostringstream oss;
3106 feMacroRunThreadStruct_.back().parameters_.xmldoc_.outputXmlDocument(
3108 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3111 feMacroRunThreadStruct_[target_i].parameters_.xmldoc_);
3112 __SUP_COUT__ <<
"FE macro complete." << __E__;
3116 __SUP_COUT__ <<
"Found still going for NotDoneID = " << NotDoneID << __E__;
3118 xmldoc.addNumberElementToData(
"NotDoneID", NotDoneID);
3125 std::string feUIDSelected =
3128 std::string macroName =
3132 bool saveOutputs = CgiDataUtilities::getDataAsInt(cgi,
"saveOutputs") == 1;
3134 __SUP_COUTTV__(feClassSelected);
3135 __SUP_COUTTV__(feUIDSelected);
3136 __SUP_COUTTV__(macroType);
3137 __SUP_COUTTV__(macroName);
3138 __SUP_COUTTV__(inputArgs);
3139 __SUP_COUTTV__(outputArgs);
3140 __SUP_COUTTV__(saveOutputs);
3141 __SUP_COUTTV__(userInfo.username_);
3144 feMacroRunThreadStruct_.emplace_back(
3171 MacroMakerSupervisor::runFEMacroThread(s, mm);
3173 &feMacroRunThreadStruct_.back(),
3176 size_t sleepTime = 10 * 1000;
3179 for(
int i = 0; i < 6; ++i)
3181 if(feMacroRunThreadStruct_.back().feMacroRunDone_)
3183 __SUP_COUTT__ <<
"FE macro marked done" << __E__;
3188 __SUP_COUTT__ <<
"FE macro not done, sleeping..." << __E__;
3190 if(sleepTime > 1000 * 1000 )
3191 sleepTime = 1000 * 1000;
3196 if(!feMacroRunThreadStruct_.back().feMacroRunDone_)
3198 if(t.get_id() == std::thread::id())
3200 __SUP_SS__ <<
"Invalid thread ID. Contact system admins!" << __E__;
3203 feMacroRunThreadStruct_.back().parameters_.threadID_ =
3204 std::hash<std::thread::id>{}(t.get_id());
3206 if(feMacroRunThreadStruct_.back().parameters_.threadID_ == 0)
3208 __SUP_SS__ <<
"Invalid thread ID hash. Contact system admins!" << __E__;
3212 __SUP_COUT__ <<
"FE macro not done, detaching thread="
3213 << feMacroRunThreadStruct_.back().parameters_.threadID_ << __E__;
3215 xmldoc.addNumberElementToData(
3216 "NotDoneID", feMacroRunThreadStruct_.back().parameters_.threadID_);
3220 std::ostringstream oss;
3222 &oss,
false ,
true );
3223 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3228 __SUP_COUTT__ <<
"FE macro marked done - joining threads." << __E__;
3230 if(feMacroRunThreadStruct_.back().parameters_.feMacroRunError_ !=
"")
3232 __SUP_SS__ << feMacroRunThreadStruct_.back().parameters_.feMacroRunError_;
3238 std::ostringstream oss;
3239 feMacroRunThreadStruct_.back().parameters_.xmldoc_.outputXmlDocument(
3240 &oss,
false ,
true );
3241 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3243 xmldoc.
copyDataChildren(feMacroRunThreadStruct_.back().parameters_.xmldoc_);
3247 std::ostringstream oss;
3249 &oss,
false ,
true );
3250 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3253 feMacroRunThreadStruct_.pop_back();
3254 __SUP_COUT__ <<
"FE macro complete." << __E__;
3256 for(
const auto& feMacroRunThreadStruct : feMacroRunThreadStruct_)
3257 __SUP_COUTT__ <<
"[] threadID_ = " << feMacroRunThreadStruct.parameters_.threadID_
3261 catch(
const std::runtime_error& e)
3263 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
3264 __SUP_COUT_ERR__ << ss.str();
3265 xmldoc.addTextElementToData(
"Error", ss.str());
3269 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
3274 catch(
const std::exception& e)
3276 ss <<
"Exception message: " << e.what();
3281 __SUP_COUT_ERR__ << ss.str();
3283 xmldoc.addTextElementToData(
"Error", ss.str());
3288 void MacroMakerSupervisor::runFEMacroThread(runFEMacroStruct* feMacroRunThreadStruct,
3292 __COUT__ <<
"runFEMacro thread started... threadid = " << std::this_thread::get_id()
3293 <<
" " << mmSupervisor <<
" getpid()=" << getpid()
3294 <<
" gettid()=" << gettid() << __E__;
3296 mmSupervisor->runFEMacro(feMacroRunThreadStruct->parameters_.xmldoc_,
3297 feMacroRunThreadStruct->parameters_.feClassSelected_,
3298 feMacroRunThreadStruct->parameters_.feUIDSelected_,
3299 feMacroRunThreadStruct->parameters_.macroType_,
3300 feMacroRunThreadStruct->parameters_.macroName_,
3301 feMacroRunThreadStruct->parameters_.inputArgs_,
3302 feMacroRunThreadStruct->parameters_.outputArgs_,
3303 feMacroRunThreadStruct->parameters_.saveOutputs_,
3304 feMacroRunThreadStruct->parameters_.runningUsername_,
3305 feMacroRunThreadStruct->parameters_.userGroupPermissions_);
3307 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3308 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3309 __COUT__ <<
"runFEMacro thread done. threadid = " << std::this_thread::get_id()
3313 catch(
const std::runtime_error& e)
3315 __SS__ <<
"Error during runFEMacro thread: " << e.what() << __E__;
3316 __COUT_ERR__ << ss.str();
3317 feMacroRunThreadStruct->parameters_.feMacroRunError_ = ss.str();
3318 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3319 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3323 __SS__ <<
"Unknown error during runFEMacro thread." << __E__;
3328 catch(
const std::exception& e)
3330 ss <<
"Exception message: " << e.what();
3335 __COUT_ERR__ << ss.str();
3336 feMacroRunThreadStruct->parameters_.feMacroRunError_ = ss.str();
3337 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3338 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3343 std::string feClassSelected,
3344 std::string feUIDSelected,
3345 const std::string& macroType,
3346 const std::string& macroName,
3347 const std::string& inputArgs,
3348 const std::string outputArgs,
3350 const std::string& username,
3351 const std::string& userGroupPermissions)
3353 __SUP_COUTV__(feClassSelected);
3354 __SUP_COUTV__(feUIDSelected);
3355 __SUP_COUTV__(macroType);
3356 __SUP_COUTV__(macroName);
3357 __SUP_COUTV__(inputArgs);
3358 __SUP_COUTV__(outputArgs);
3359 __SUP_COUTV__(saveOutputs);
3360 __SUP_COUTV__(username);
3361 __SUP_COUTV__(userGroupPermissions);
3363 appendCommandToHistory(feClassSelected,
3372 std::set<std::string > feUIDs;
3374 if(feUIDSelected ==
"")
3375 feUIDSelected =
"*";
3376 if(feClassSelected ==
"")
3377 feClassSelected =
"*";
3379 if(feClassSelected ==
"" || feUIDSelected ==
"" || macroType ==
"" || macroName ==
"")
3381 __SUP_SS__ <<
"Illegal empty front-end parameter." << __E__;
3384 else if(feUIDSelected !=
"*")
3391 if(feClassSelected ==
"*")
3393 for(
auto& feTypePair : FEPluginTypetoFEsMap_)
3394 for(
auto& feUID : feTypePair.second)
3395 feUIDs.emplace(feUID);
3399 auto typeIt = FEPluginTypetoFEsMap_.find(feClassSelected);
3400 if(typeIt == FEPluginTypetoFEsMap_.end())
3402 __SUP_SS__ <<
"Illegal front-end type parameter '" << feClassSelected
3403 <<
"' not in list of types." << __E__;
3407 for(
auto& feUID : typeIt->second)
3408 feUIDs.emplace(feUID);
3414 std::string macroString;
3415 if(macroType ==
"public")
3416 loadMacro(macroName, macroString);
3417 else if(macroType ==
"private")
3418 loadMacro(macroName, macroString, username);
3420 __SUP_COUTV__(macroString);
3427 std::string filename =
"/macroOutput_" + std::to_string(time(0)) +
"_" +
3428 std::to_string(clock()) +
".txt";
3430 __SUP_COUTV__(filename);
3431 fp = fopen((CodeEditor::OTSDAQ_DATA_PATH + filename).c_str(),
"w");
3434 __SUP_SS__ <<
"Failed to open file to save macro output '"
3435 << CodeEditor::OTSDAQ_DATA_PATH << filename <<
"'..." << __E__;
3439 fprintf(fp,
"############################\n");
3441 "### Running '%s' at time %s\n",
3445 "### \t Target front-ends (count=%lu): %s\n",
3448 fprintf(fp,
"### \t\t Inputs: %s\n", inputArgs.c_str());
3449 fprintf(fp,
"############################\n\n\n");
3451 xmldoc.addTextElementToData(
"feMacroRunArgs_name",
"Filename");
3452 xmldoc.addTextElementToData(
"feMacroRunArgs_value",
3453 "$OTSDAQ_DATA/" + filename);
3457 for(
auto& feUID : feUIDs)
3459 auto feIt = FEtoSupervisorMap_.find(feUID);
3460 if(feIt == FEtoSupervisorMap_.end())
3462 __SUP_SS__ <<
"Destination front end interface ID '" << feUID
3463 <<
"' was not found in the list of front ends." << __E__;
3464 ss <<
"\n\nHere is the map:\n\n"
3469 unsigned int FESupervisorIndex = feIt->second;
3470 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
3472 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
3473 if(it == allFESupervisorInfo_.end())
3476 <<
"Error transmitting request to FE Supervisor '" << feUID <<
":"
3477 << FESupervisorIndex <<
".' \n\n"
3478 <<
"The FE Supervisor Index does not exist. Have you configured "
3479 "the state machine properly?"
3486 if(macroType ==
"fe")
3487 txParameters.
addParameter(
"Request",
"RunInterfaceMacro");
3489 txParameters.
addParameter(
"Request",
"RunMacroMakerMacro");
3491 if(macroType ==
"fe")
3500 txParameters.
addParameter(
"userPermissions", userGroupPermissions);
3510 "Running '%s' at time %s\n",
3514 "\t Target front-end: '%s::%s'\n",
3515 FEtoPluginTypeMap_[feUID].c_str(),
3518 "\t\t Inputs: %s\n",
3523 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
3524 it->second.getDescriptor(),
3525 "MacroMakerSupervisorRequest",
3528 __SUP_COUT__ <<
"Received response message: "
3529 << SOAPUtilities::translate(retMsg) << __E__;
3531 SOAPUtilities::receive(retMsg, rxParameters);
3533 __SUP_COUT__ <<
"Received it " << __E__;
3536 std::string outputResults = rxParameters.getValue(
"outputArgs");
3537 std::string error = rxParameters.getValue(
"Error");
3540 __SUP_COUT__ <<
"outputArgs = " << outputResults << __E__;
3544 __SS__ <<
"Attempted FE Macro Failed. Attempted target "
3545 <<
"was UID=" << feUID
3546 <<
" at feSupervisorID=" << FESupervisorIndex <<
"." << __E__;
3547 ss <<
"\n\n The error was:\n\n" << error << __E__;
3548 __SUP_COUT_ERR__ <<
"\n" << ss.str();
3549 xmldoc.addTextElementToData(
"Error", ss.str());
3556 DOMElement* feMacroExecParent =
3557 xmldoc.addTextElementToData(
"feMacroExec", macroName);
3563 "fe_type", FEtoPluginTypeMap_[feUID], feMacroExecParent);
3565 "fe_context", it->second.getContextName(), feMacroExecParent);
3567 "fe_supervisor", it->second.getName(), feMacroExecParent);
3569 "fe_hostname", it->second.getHostname(), feMacroExecParent);
3571 std::istringstream inputStream(outputResults);
3572 std::string splitVal, argName, argValue;
3573 while(getline(inputStream, splitVal,
';'))
3575 std::istringstream pairInputStream(splitVal);
3576 getline(pairInputStream, argName,
',');
3577 getline(pairInputStream, argValue,
',');
3582 "\t\t Output '%s' = %s\n",
3589 "outputArgs_name", argName, feMacroExecParent);
3591 "outputArgs_value", argValue, feMacroExecParent);
3593 __SUP_COUT__ << argName <<
": " << argValue << __E__;
3612 const std::string& username)
3614 __SUP_COUT__ <<
"Getting FE Macro list" << __E__;
3617 txParameters.
addParameter(
"Request",
"GetInterfaceMacros");
3622 std::string oneInterface;
3623 std::string rxFEMacros;
3627 for(
auto& appInfo : allFESupervisorInfo_)
3629 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
3630 <<
" name = " << appInfo.second.getName() << __E__;
3632 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
3633 appInfo.second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
3634 SOAPUtilities::receive(retMsg, rxParameters);
3636 rxFEMacros = rxParameters.getValue(
"FEMacros");
3638 __SUP_COUT__ <<
"FE Macros received: \n" << rxFEMacros << __E__;
3640 std::istringstream allInterfaces(rxFEMacros);
3641 while(std::getline(allInterfaces, oneInterface))
3645 xmldoc.addTextElementToData(
"FEMacros", oneInterface);
3651 std::pair<std::vector<std::string> ,
3652 std::vector<std::string> >
3654 loadMacroNames(username, macroNames);
3656 __SUP_COUT__ <<
"Public macro count: " << macroNames.first.size() << __E__;
3657 __SUP_COUT__ <<
"Private macro count: " << macroNames.second.size() << __E__;
3659 std::string macroString;
3668 for(
int i = 0; i < 2; ++i)
3669 for(
auto& macroName : (i ? macroNames.second : macroNames.first))
3672 loadMacro(macroName, macroString, username);
3677 std::stringstream xmlMacroStream;
3678 xmlMacroStream << macro.macroName_;
3679 xmlMacroStream <<
":"
3681 xmlMacroStream <<
":" << macro.namesOfInputArguments_.size();
3682 for(
auto& inputArg : macro.namesOfInputArguments_)
3683 xmlMacroStream <<
":" << inputArg;
3684 xmlMacroStream <<
":" << macro.namesOfOutputArguments_.size();
3685 for(
auto& inputArg : macro.namesOfOutputArguments_)
3686 xmlMacroStream <<
":" << inputArg;
3688 xmldoc.addTextElementToData(i ?
"PrivateMacro" :
"PublicMacro",
3689 xmlMacroStream.str());
static std::string postData(cgicc::Cgicc &cgi, const std::string &needle)
static std::string getOrPostData(cgicc::Cgicc &cgi, const std::string &needle)
static std::string getData(cgicc::Cgicc &cgi, const std::string &needle)
void loadTableGroup(const std::string &tableGroupName, const TableGroupKey &tableGroupKey, bool doActivate=false, std::map< std::string, TableVersion > *groupMembers=0, ProgressBar *progressBar=0, std::string *accumulateWarnings=0, std::string *groupComment=0, std::string *groupAuthor=0, std::string *groupCreateTime=0, bool doNotLoadMember=false, std::string *groupTypeString=0, std::map< std::string, std::string > *groupAliases=0, ConfigurationManager::LoadGroupType groupTypeToLoad=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false)
ConfigurationTree getNode(const std::string &nodeString, bool doNotThrowOnBrokenUIDLinks=false) const
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
std::vector< std::pair< std::string, ConfigurationTree > > getChildren(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool byPriority=false, bool onlyStatusTrue=false) const
void getRequestUserInfo(WebUsers::RequestUserInfo &requestUserInfo)
friend friend class MacroMakerSupervisor
virtual void nonXmlRequest(const std::string &requestType, cgicc::Cgicc &cgiIn, std::ostream &out, const WebUsers::RequestUserInfo &userInfo)
void copyDataChildren(HttpXmlDocument &document)
std::string getMatchingValue(const std::string &field, const unsigned int occurance=0)
void outputXmlDocument(std::ostringstream *out, bool dispStdOut=false, bool allowWhiteSpace=false, bool printErrors=false)
virtual void forceSupervisorPropertyValues(void) override
override to force supervisor property values (and ignore user settings)
void addParameter(const std::string name, const std::string value)
static void tooltipSetNeverShowForUsername(const std::string &username, HttpXmlDocument *xmldoc, const std::string &srcFile, const std::string &srcFunc, const std::string &srcId, bool doNeverShow, bool temporarySilence)
static void tooltipCheckForUsername(const std::string &username, HttpXmlDocument *xmldoc, const std::string &srcFile, const std::string &srcFunc, const std::string &srcId)
xercesc::DOMElement * addTextElementToParent(const std::string &childName, const std::string &childText, xercesc::DOMElement *parent)
void INIT_MF(const char *name)
static std::string getTimestampString(const std::string &linuxTimeInSeconds)
static void getVectorFromString(const std::string &inputString, std::vector< std::string > &listToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'}, std::vector< char > *listOfDelimiters=0, bool decodeURIComponents=false)
static void getSetFromString(const std::string &inputString, std::set< std::string > &setToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
static std::string setToString(const std::set< T > &setToReturn, const std::string &delimeter=", ")
static std::string vectorToString(const std::vector< T > &setToReturn, const std::string &delimeter=", ")
static std::string mapToString(const std::map< std::string, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
static std::string decodeURIComponent(const std::string &data)