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")
844 else if(Command ==
"writeData")
845 writeData(xmldoc, cgi, userInfo.username_);
846 else if(Command ==
"readData")
847 readData(xmldoc, cgi, userInfo.username_);
848 else if(Command ==
"createMacro")
849 createMacro(xmldoc, cgi, userInfo.username_);
850 else if(Command ==
"loadMacros")
851 loadMacros(xmldoc, userInfo.username_);
852 else if(Command ==
"loadHistory")
853 loadHistory(xmldoc, userInfo.username_);
854 else if(Command ==
"deleteMacro")
855 deleteMacro(xmldoc, cgi, userInfo.username_);
856 else if(Command ==
"editMacro")
857 editMacro(xmldoc, cgi, userInfo.username_);
858 else if(Command ==
"clearHistory")
859 clearHistory(userInfo.username_);
860 else if(Command ==
"exportMacro")
861 exportMacro(xmldoc, cgi, userInfo.username_);
862 else if(Command ==
"exportFEMacro")
863 exportFEMacro(xmldoc, cgi, userInfo.username_);
864 else if(Command ==
"getFEMacroList")
867 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
868 mkdir(macroPath.c_str(), 0755);
869 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
870 mkdir(histPath.c_str(), 0755);
872 getFEMacroList(xmldoc, userInfo.username_);
874 else if(Command ==
"runFEMacro")
876 runFEMacro(xmldoc, cgi, userInfo);
877 else if(Command ==
"loadFEHistory")
879 loadFEHistory(xmldoc, userInfo.username_);
880 else if(Command ==
"clearFEHistory")
882 clearFEHistory(userInfo.username_);
883 else if(Command ==
"loadFEMacroSequences")
884 loadFEMacroSequences(xmldoc, userInfo.username_);
885 else if(Command ==
"saveFEMacroSequence")
886 saveFEMacroSequence(cgi, userInfo.username_);
887 else if(Command ==
"getFEMacroSequence")
888 getFEMacroSequence(xmldoc, cgi, userInfo.username_);
889 else if(Command ==
"deleteFEMacroSequence")
890 deleteFEMacroSequence(cgi, userInfo.username_);
891 else if(Command ==
"makeSequencePublic")
892 makeSequencePublic(cgi, userInfo.username_);
894 xmldoc.addTextElementToData(
"Error",
"Unrecognized command '" + Command +
"'");
898 xoap::MessageReference MacroMakerSupervisor::frontEndCommunicationRequest(
899 xoap::MessageReference message)
903 __SUP_COUT__ <<
"FE Request received: " << SOAPUtilities::translate(message) << __E__;
907 SOAPUtilities::receive(message, typeParameter);
909 std::string type = typeParameter.getValue(
"type");
911 std::string error =
"";
913 if(type ==
"initFElist")
919 SOAPUtilities::receive(message, rxParameters);
921 std::string groupName = rxParameters.getValue(
"groupName");
922 std::string groupKey = rxParameters.getValue(
"groupKey");
924 __SUP_COUTV__(groupName);
925 __SUP_COUTV__(groupKey);
933 const SupervisorInfoMap& feTypeSupervisors =
934 CorePropertySupervisorBase::allSupervisorInfo_.getAllFETypeSupervisorInfo();
937 cfgMgr.
getNode(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME);
939 __SUP_COUT__ <<
"Number of FE Supervisors found = " << feTypeSupervisors.size()
942 FEPluginTypetoFEsMap_.clear();
943 FEtoSupervisorMap_.clear();
944 FEtoPluginTypeMap_.clear();
945 for(
auto& feApp : feTypeSupervisors)
947 __SUP_COUT__ <<
"FEs for app " << feApp.first <<
":" << feApp.second.getName()
950 auto feChildren = appsNode.
getNode(feApp.second.getName())
951 .
getNode(
"LinkToSupervisorTable")
952 .
getNode(
"LinkToFEInterfaceTable")
955 for(
auto& fe : feChildren)
957 if(!fe.second.status())
960 __SUP_COUTV__(fe.first);
961 FEtoSupervisorMap_[fe.first] = feApp.first;
963 std::string pluginType =
964 fe.second.getNode(
"FEInterfacePluginName").getValue();
965 FEPluginTypetoFEsMap_[pluginType].emplace(fe.first);
966 FEtoPluginTypeMap_[fe.first] = pluginType;
974 else if(type ==
"feSend" ||
976 type ==
"feMacroMultiDimensionalStart" ||
977 type ==
"feMacroMultiDimensionalCheck" ||
978 type ==
"macroMultiDimensionalStart" ||
979 type ==
"macroMultiDimensionalCheck")
984 SOAPUtilities::receive(message, rxParameters);
986 std::string targetInterfaceID = rxParameters.getValue(
"targetInterfaceID");
988 __SUP_COUTV__(targetInterfaceID);
990 auto feIt = FEtoSupervisorMap_.find(targetInterfaceID);
991 if(feIt == FEtoSupervisorMap_.end())
993 __SUP_SS__ <<
"Destination front end interface ID '" << targetInterfaceID
994 <<
"' was not found in the list of front ends." << __E__;
998 unsigned int FESupervisorIndex = feIt->second;
999 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
1001 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1002 if(it == allFESupervisorInfo_.end())
1004 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1005 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' \n\n"
1006 <<
"The FE Supervisor Index does not exist. Have you configured "
1007 "the state machine properly?"
1012 if(type ==
"macroMultiDimensionalStart")
1018 SOAPUtilities::receive(message, rxParameters);
1019 std::string macroName = rxParameters.getValue(
"macroName");
1020 __SUP_COUTV__(macroName);
1022 std::string macroString;
1023 loadMacro(macroName, macroString);
1027 SOAPUtilities::addParameters(message, parameters);
1032 __SUP_COUT__ <<
"Forwarding request: " << SOAPUtilities::translate(message)
1035 xoap::MessageReference replyMessage =
1036 SOAPMessenger::sendWithSOAPReply(it->second.getDescriptor(), message);
1038 if(type !=
"feSend")
1040 __SUP_COUT__ <<
"Forwarding FE Macro response: "
1041 << SOAPUtilities::translate(replyMessage) << __E__;
1043 return replyMessage;
1046 catch(
const xdaq::exception::Exception& e)
1048 __SUP_SS__ <<
"Error forwarding FE Communication request to FE Supervisor '"
1049 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' "
1050 <<
"Have you configured the state machine properly?\n\n"
1051 << e.what() << __E__;
1057 __SUP_SS__ <<
"Unrecognized FE Communication type: " << type << __E__;
1061 return SOAPUtilities::makeSOAPMessageReference(
"Received");
1063 catch(
const std::runtime_error& e)
1065 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
1066 __SUP_COUT_ERR__ << ss.str();
1068 xoap::MessageReference returnMessage =
1069 SOAPUtilities::makeSOAPMessageReference(
"Error");
1073 SOAPUtilities::addParameters(returnMessage, parameters);
1074 return returnMessage;
1078 xoap::MessageReference returnMessage =
1079 SOAPUtilities::makeSOAPMessageReference(
"Error");
1081 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
1086 catch(
const std::exception& e)
1088 ss <<
"Exception message: " << e.what();
1093 __SUP_COUT_ERR__ << ss.str();
1097 SOAPUtilities::addParameters(returnMessage, parameters);
1098 return returnMessage;
1104 __SUP_COUT__ <<
"Getting FE list!!!!!!!!!" << __E__;
1116 SupervisorInfoMap::const_iterator it;
1117 std::string oneInterface;
1118 std::string rxFEList;
1119 std::string rxFrontEndError;
1121 size_t lastColonIndex;
1125 for(
auto& appInfo : allFESupervisorInfo_)
1133 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
1134 <<
" name = " << appInfo.second.getName() << __E__;
1138 xoap::MessageReference retMsg =
1139 SOAPMessenger::sendWithSOAPReply(appInfo.second.getDescriptor(),
1140 "MacroMakerSupervisorRequest",
1142 SOAPUtilities::receive(retMsg, rxParameters);
1144 __SUP_COUT__ <<
"Received MacroMaker response: "
1145 << SOAPUtilities::translate(retMsg).getCommand() <<
"==>"
1146 << SOAPUtilities::translate(retMsg) << __E__;
1148 if(SOAPUtilities::translate(retMsg).getCommand() ==
"Fault")
1150 __SUP_SS__ <<
"Unrecognized command received!" << __E__;
1154 catch(
const xdaq::exception::Exception& e)
1156 __SUP_SS__ <<
"Error transmitting request to FE Supervisor LID = "
1157 << appInfo.second.getId() <<
" name = " << appInfo.second.getName()
1159 << e.what() << __E__;
1163 rxFEList = rxParameters.getValue(
"FEList");
1164 rxFrontEndError = rxParameters.getValue(
"frontEndError");
1166 __SUP_COUT__ <<
"FE List received: \n" << rxFEList << __E__;
1168 if(rxFrontEndError !=
"")
1170 __SUP_SS__ <<
"FE Errors received: \n" << rxFrontEndError << __E__;
1174 std::istringstream allInterfaces(rxFEList);
1175 while(std::getline(allInterfaces, oneInterface))
1177 __SUP_COUTV__(oneInterface);
1178 xmldoc.addTextElementToData(
"FE", oneInterface);
1180 lastColonIndex = oneInterface.rfind(
':');
1181 if(lastColonIndex == std::string::npos)
1183 __SUP_SS__ <<
"Last colon could not be found in " << oneInterface
1187 oneInterface = oneInterface.substr(lastColonIndex);
1189 __SUP_COUTV__(oneInterface);
1199 const std::string& username)
1201 __SUP_COUT__ <<
"MacroMaker writing..." << __E__;
1214 __SUP_COUT__ <<
"Write Address: " << Address <<
" Data: " << Data << __E__;
1215 __SUP_COUTV__(interfaces);
1217 std::string command =
"w:" + Address +
":" + Data;
1218 std::string format = addressFormatStr +
":" + dataFormatStr;
1219 appendCommandToHistory(command, format, time, interfaces, username);
1222 txParameters.
addParameter(
"Request",
"UniversalWrite");
1226 __SUP_COUT__ <<
"Here comes the array from multiselect box for WRITE, behold: \n"
1227 << supervisorIndexArray <<
"\n"
1228 << interfaceIndexArray << __E__;
1232 std::vector<std::string> interfaceIndices;
1233 std::istringstream f(interfaceIndexArray);
1235 while(getline(f, s,
','))
1236 interfaceIndices.push_back(s);
1237 std::vector<int> supervisorIndices;
1238 std::istringstream g(supervisorIndexArray);
1240 while(getline(g, t,
','))
1241 supervisorIndices.push_back(std::stoi(t));
1243 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
1245 unsigned int FESupervisorIndex = supervisorIndices[i];
1246 std::string interfaceIndex = interfaceIndices[i];
1248 txParameters.
addParameter(
"InterfaceID", interfaceIndex);
1250 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
1252 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
1254 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1255 if(it == allFESupervisorInfo_.end())
1257 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1258 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
1259 <<
"The FE Index doesn't exist. Have you configured the state "
1267 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1268 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1270 __SUP_COUT__ <<
"Response received: "
1271 << SOAPUtilities::translate(replyMessage) << __E__;
1275 SOAPUtilities::receive(replyMessage, rxParameters);
1277 std::string error = rxParameters.getValue(
"Error");
1278 __SUP_COUTV__(error);
1283 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1284 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1285 <<
"Have you configured the state machine properly?\n\n"
1290 catch(
const xdaq::exception::Exception& e)
1292 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1293 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1294 <<
"Have you configured the state machine properly?\n\n"
1295 << e.what() << __E__;
1305 const std::string& username)
1307 __SUP_COUT__ <<
"@@@@@@@ MacroMaker wants to read data @@@@@@@@" << __E__;
1318 __SUP_COUT__ <<
"Read Address: " << Address << __E__;
1319 __SUP_COUTV__(interfaces);
1328 __SUP_COUT__ <<
"Here comes the array from multiselect box for READ, behold: "
1329 << supervisorIndexArray <<
"," << interfaceIndexArray << __E__;
1333 std::vector<std::string> interfaceIndices;
1334 std::istringstream f(interfaceIndexArray);
1336 while(getline(f, s,
','))
1337 interfaceIndices.push_back(s);
1338 std::vector<int> supervisorIndices;
1339 std::istringstream g(supervisorIndexArray);
1341 while(getline(g, t,
','))
1342 supervisorIndices.push_back(std::stoi(t));
1344 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
1346 unsigned int FESupervisorIndex = supervisorIndices[i];
1347 std::string interfaceIndex = interfaceIndices[i];
1349 txParameters.
addParameter(
"InterfaceID", interfaceIndex);
1351 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
1353 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
1355 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1356 if(it == allFESupervisorInfo_.end())
1358 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1359 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
1360 <<
"The FE Index doesn't exist. Have you configured the state "
1368 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
1369 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1371 __SUP_COUT__ <<
"Response received: " << SOAPUtilities::translate(retMsg)
1376 SOAPUtilities::receive(retMsg, rxParameters);
1378 std::string error = rxParameters.getValue(
"Error");
1379 __SUP_COUTV__(error);
1384 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1385 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1386 <<
"Have you configured the state machine properly?\n\n"
1391 catch(
const xdaq::exception::Exception& e)
1393 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1394 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1395 <<
"Have you configured the state machine properly?\n\n"
1396 << e.what() << __E__;
1400 std::string dataReadResult = rxParameters.getValue(
"dataResult");
1401 __SUP_COUT__ <<
"Data reading result received: " << dataReadResult << __E__;
1402 xmldoc.addTextElementToData(
"readData", dataReadResult);
1403 std::string command =
"r:" + Address +
":" + dataReadResult;
1404 std::string format = addressFormatStr +
":" + dataFormatStr;
1405 appendCommandToHistory(command, format, time, interfaces, username);
1412 const std::string& username)
1414 __SUP_COUT__ <<
"MacroMaker wants to create a macro!!!!!!!!!" << __E__;
1423 __SUP_COUTV__(Name);
1424 __SUP_COUTV__(Sequence);
1425 __SUP_COUTV__(Notes);
1426 __SUP_COUTV__(Time);
1427 __SUP_COUTV__(isMacroPublic);
1428 __SUP_COUTV__(isMacroLSBF);
1430 __SUP_COUTV__(MACROS_DB_PATH);
1432 std::string fileName = Name +
".dat";
1433 std::string fullPath;
1434 if(isMacroPublic ==
"true")
1435 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
1437 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
1439 __SUP_COUTV__(fullPath);
1441 std::ofstream macrofile(fullPath.c_str());
1442 if(macrofile.is_open())
1445 macrofile <<
"\"name\":\"" << Name <<
"\",\n";
1446 macrofile <<
"\"sequence\":\"" << Sequence <<
"\",\n";
1447 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
1448 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
1449 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
1450 macrofile <<
"}@" << __E__;
1454 __SUP_COUT__ <<
"Unable to open file" << __E__;
1465 void MacroMakerSupervisor::loadMacro(
const std::string& macroName,
1466 std::string& macroString,
1467 const std::string& username )
1469 __SUP_COUTV__(macroName);
1472 std::string fullPath, line;
1474 for(
unsigned int i = 0; i < 2; ++i)
1477 fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1479 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1481 fullPath += macroName;
1482 if(macroName.find(
".dat") != macroName.size() - 4)
1484 __SUP_COUTV__(fullPath);
1486 std::ifstream read(fullPath.c_str());
1491 getline(read, line);
1492 macroString += line;
1499 __SUP_COUT__ <<
"Unable to open file: " << fullPath << __E__;
1503 if(macroString !=
"")
1507 if(macroString ==
"")
1509 __SUP_SS__ <<
"Unable to locate file for macro '" << macroName
1510 <<
"'... does it exist?" << __E__;
1512 ss <<
" Attempted username was '" << username <<
".'" << __E__;
1516 __SUP_COUTV__(macroString);
1520 void MacroMakerSupervisor::loadMacroNames(
1521 const std::string& username,
1522 std::pair<std::vector<std::string> ,
1523 std::vector<std::string> >& returnMacroNames)
1527 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1528 if((dir = opendir(fullPath.c_str())) != NULL)
1531 while((ent = readdir(dir)) != NULL)
1534 if((
unsigned)strlen(ent->d_name) > 4)
1538 ((fullPath + (std::string)ent->d_name)).c_str());
1543 returnMacroNames.second.push_back(ent->d_name);
1546 __SUP_COUT__ <<
"Unable to open file" << __E__;
1553 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1556 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1557 if((dir = opendir(fullPath.c_str())) != NULL)
1560 while((ent = readdir(dir)) != NULL)
1563 if((
unsigned)strlen(ent->d_name) > 4)
1567 ((fullPath + (std::string)ent->d_name)).c_str());
1571 returnMacroNames.first.push_back(ent->d_name);
1575 __SUP_COUT__ <<
"Unable to open file" << __E__;
1582 __SUP_COUT__ << fullPath << __E__;
1583 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1591 const std::string& username)
1595 std::string returnStr =
"";
1596 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1597 if((dir = opendir(fullPath.c_str())) != NULL)
1600 while((ent = readdir(dir)) != NULL)
1603 if((
unsigned)strlen(ent->d_name) > 4)
1607 ((fullPath + (std::string)ent->d_name)).c_str());
1610 std::stringstream buffer;
1613 getline(read, line);
1617 returnStr += buffer.str();
1622 __SUP_COUT__ <<
"Unable to open file" << __E__;
1625 std::string returnMacroStr = returnStr.substr(0, returnStr.size() - 1);
1627 __SUP_COUT__ <<
"Loading existing macros! " << returnMacroStr << __E__;
1630 xmldoc.addTextElementToData(
"returnMacroStr", returnMacroStr);
1634 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1637 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1639 if((dir = opendir(fullPath.c_str())) != NULL)
1642 while((ent = readdir(dir)) != NULL)
1645 if((
unsigned)strlen(ent->d_name) > 4)
1649 ((fullPath + (std::string)ent->d_name)).c_str());
1652 std::stringstream buffer;
1655 getline(read, line);
1659 returnStr += buffer.str();
1663 __SUP_COUT__ <<
"Unable to open file" << __E__;
1666 std::string returnPublicStr = returnStr.substr(0, returnStr.size() - 1);
1667 __SUP_COUT__ <<
"Loading existing public macros: " << returnPublicStr << __E__;
1669 xmldoc.addTextElementToData(
"returnPublicStr", returnPublicStr);
1673 __SUP_COUT__ << fullPath << __E__;
1674 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1680 void MacroMakerSupervisor::appendCommandToHistory(std::string Command,
1683 std::string Interfaces,
1684 const std::string& username)
1686 std::string fileName =
"history.hist";
1687 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1688 __SUP_COUT__ << fullPath << __E__;
1689 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1690 if(histfile.is_open())
1693 histfile <<
"\"Command\":\"" << Command <<
"\",\n";
1694 histfile <<
"\"Format\":\"" << Format <<
"\",\n";
1695 histfile <<
"\"Time\":\"" << Time <<
"\",\n";
1696 histfile <<
"\"Interfaces\":\"" << Interfaces <<
"\"\n";
1697 histfile <<
"}#" << __E__;
1701 __SUP_COUT__ <<
"Unable to open history.hist" << __E__;
1705 void MacroMakerSupervisor::appendCommandToHistory(std::string feClass,
1707 std::string macroType,
1708 std::string macroName,
1709 std::string inputArgs,
1710 std::string outputArgs,
1712 const std::string& username)
1715 auto feHistoryIt = lastFeCommandToHistory_.find(username);
1716 if(feHistoryIt != lastFeCommandToHistory_.end() && feHistoryIt->second.size() == 7 &&
1717 feHistoryIt->second[0] == feClass && feHistoryIt->second[1] == feUID &&
1718 feHistoryIt->second[2] == macroType && feHistoryIt->second[3] == macroName &&
1719 feHistoryIt->second[4] == inputArgs && feHistoryIt->second[5] == outputArgs &&
1720 feHistoryIt->second[6] == (saveOutputs ?
"1" :
"0"))
1722 __SUP_COUTT__ <<
"Not saving repeat command to history from user " << username
1727 std::string fileName =
"FEhistory.hist";
1728 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1729 __SUP_COUT__ << fullPath << __E__;
1730 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1731 if(histfile.is_open())
1734 histfile <<
"\"feClass\":\"" << feClass <<
"\",\n";
1735 histfile <<
"\"feUID\":\"" << feUID <<
"\",\n";
1736 histfile <<
"\"macroType\":\"" << macroType <<
"\",\n";
1737 histfile <<
"\"macroName\":\"" << macroName <<
"\",\n";
1738 histfile <<
"\"inputArgs\":\"" << inputArgs <<
"\",\n";
1739 histfile <<
"\"outputArgs\":\"" << outputArgs <<
"\",\n";
1741 histfile <<
"\"saveOutputs\":\"" << 1 <<
"\"\n";
1743 histfile <<
"\"saveOutputs\":\"" << 0 <<
"\"\n";
1744 histfile <<
"}#" << __E__;
1747 lastFeCommandToHistory_[username].clear();
1748 feHistoryIt = lastFeCommandToHistory_.find(username);
1749 feHistoryIt->second.push_back(feClass);
1750 feHistoryIt->second.push_back(feUID);
1751 feHistoryIt->second.push_back(macroType);
1752 feHistoryIt->second.push_back(macroName);
1753 feHistoryIt->second.push_back(inputArgs);
1754 feHistoryIt->second.push_back(outputArgs);
1755 feHistoryIt->second.push_back((saveOutputs ?
"1" :
"0"));
1758 __SUP_COUT__ <<
"Unable to open FEhistory.hist" << __E__;
1763 void MacroMakerSupervisor::loadFEMacroSequences(
HttpXmlDocument& xmldoc,
1764 const std::string& username)
1766 __SUP_COUT__ <<
"loadFEMacroSequences for " << username << __E__;
1769 std::string fullPath = (std::string)MACROS_SEQUENCE_PATH + username +
"/";
1770 std::string sequences =
"";
1771 __SUP_COUTV__(fullPath);
1772 if((dir = opendir(fullPath.c_str())) != NULL)
1775 while((ent = readdir(dir)) != NULL)
1779 ((fullPath + (std::string)ent->d_name)).c_str());
1783 sequences += ent->d_name + std::string(
";");
1786 __SUP_COUT__ <<
"Unable to open file" << __E__;
1792 __SUP_COUT__ <<
"Looping through MacroSequence/" + username +
1793 " folder failed! Invalid directory."
1797 if(username == WebUsers::DEFAULT_ADMIN_USERNAME)
1800 xmldoc.addTextElementToData(
"FEsequences", sequences);
1805 fullPath = (std::string)MACROS_SEQUENCE_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
"/";
1807 if((dir = opendir(fullPath.c_str())) != NULL)
1810 while((ent = readdir(dir)) != NULL)
1814 ((fullPath + (std::string)ent->d_name)).c_str());
1818 sequences += std::string(
"public/") + ent->d_name + std::string(
";");
1821 __SUP_COUT__ <<
"Unable to open file" << __E__;
1827 __SUP_COUT__ <<
"Looping through MacroSequence/" +
1828 WebUsers::DEFAULT_ADMIN_USERNAME +
1829 " folder failed! Invalid directory."
1834 xmldoc.addTextElementToData(
"FEsequences", sequences);
1839 void MacroMakerSupervisor::saveFEMacroSequence(cgicc::Cgicc& cgi,
1840 const std::string& username)
1845 std::string FEsequence =
1847 bool overwrite = CgiDataUtilities::getDataAsInt(cgi,
"overwrite");
1849 __SUP_COUTV__(overwrite);
1850 __SUP_COUTV__(name);
1851 __SUP_COUTV__(FEsequence);
1854 std::string fixedName =
"";
1855 for(
size_t i = 0; i < name.size(); ++i)
1856 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
1857 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
1858 (name[i] >=
'a' && name[i] <=
'z')))
1861 <<
"Illegal character in Sequence name (position " << i
1862 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
1867 fixedName += name[i];
1868 __SUP_COUTV__(fixedName);
1870 std::string fullPath =
1871 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
1872 __SUP_COUTV__(fullPath);
1875 if(!overwrite && std::filesystem::exists(fullPath))
1877 __SUP_SS__ <<
"Please choose another Sequence name! A sequence with the same "
1878 "resulting filename already exists at "
1879 << fullPath << __E__;
1883 std::ofstream seqfile(fullPath.c_str());
1884 if(seqfile.is_open())
1886 seqfile << FEsequence << __E__;
1891 __SUP_SS__ <<
"Unable to open file to save FE Macro Sequence at " << fullPath
1898 void MacroMakerSupervisor::getFEMacroSequence(
HttpXmlDocument& xmldoc,
1900 const std::string& username)
1904 __SUP_COUTV__(name);
1906 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
1907 __SUP_COUTV__(isPublic);
1910 std::string fixedName =
"";
1911 for(
size_t i = (isPublic ? std::string(
"public/").size() : 0); i < name.size(); ++i)
1912 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
1913 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
1914 (name[i] >=
'a' && name[i] <=
'z')))
1916 __COUT__ <<
"Illegal character in Sequence name (position " << i
1917 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
1921 fixedName += name[i];
1922 __SUP_COUTV__(fixedName);
1925 std::string fullPath =
1926 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
1927 __SUP_COUT__ << fullPath << __E__;
1929 std::ifstream read(fullPath.c_str());
1931 unsigned long long fileSize;
1933 if(!isPublic && read.is_open())
1935 read.seekg(0, std::ios::end);
1936 fileSize = read.tellg();
1937 response =
new char[fileSize + 1];
1938 response[fileSize] =
'\0';
1939 read.seekg(0, std::ios::beg);
1942 read.read(response, fileSize);
1945 xmldoc.addTextElementToData(
"FEsequence", &response[0]);
1952 __SUP_COUT__ <<
"Unable to open " << fullPath <<
"! Trying public area..."
1956 std::string publicFullPath = (std::string)MACROS_SEQUENCE_PATH +
1957 WebUsers::DEFAULT_ADMIN_USERNAME +
"/" + fixedName +
1959 __SUP_COUT__ << publicFullPath << __E__;
1961 std::ifstream read(publicFullPath.c_str());
1963 unsigned long long fileSize;
1967 read.seekg(0, std::ios::end);
1968 fileSize = read.tellg();
1969 response =
new char[fileSize + 1];
1970 response[fileSize] =
'\0';
1971 read.seekg(0, std::ios::beg);
1974 read.read(response, fileSize);
1977 xmldoc.addTextElementToData(
"FEsequence", &response[0]);
1983 __SUP_SS__ <<
"Unable to open FE Macro Sequence at " << fullPath <<
" or "
1984 << publicFullPath << __E__;
1991 void MacroMakerSupervisor::deleteFEMacroSequence(cgicc::Cgicc& cgi,
1992 const std::string& username)
1996 __SUP_COUTV__(name);
1998 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
1999 __SUP_COUTV__(isPublic);
2002 std::string fixedName =
"";
2003 for(
size_t i = (isPublic ? std::string(
"public/").size() : 0); i < name.size(); ++i)
2004 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
2005 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
2006 (name[i] >=
'a' && name[i] <=
'z')))
2008 __COUT__ <<
"Illegal character in Sequence name (position " << i
2009 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2013 fixedName += name[i];
2014 __SUP_COUTV__(fixedName);
2017 std::string fullPath =
2018 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2020 fullPath = (std::string)MACROS_SEQUENCE_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
2021 "/" + fixedName +
".dat";
2022 __SUP_COUT__ << fullPath << __E__;
2025 if(!std::filesystem::exists(fullPath))
2028 <<
"The specified Sequence name does not exist! Looking for sequence file at "
2029 << fullPath << __E__;
2033 std::remove(fullPath.c_str());
2034 __SUP_COUT__ <<
"Successfully deleted " << fullPath << __E__;
2038 void MacroMakerSupervisor::makeSequencePublic(cgicc::Cgicc& cgi,
2039 const std::string& username)
2043 __SUP_COUTV__(name);
2045 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
2046 __SUP_COUTV__(isPublic);
2049 __SUP_SS__ <<
"The specified Sequence name is already designated as public."
2055 std::string fixedName =
"";
2056 for(
size_t i = 0; i < name.size(); ++i)
2057 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
2058 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
2059 (name[i] >=
'a' && name[i] <=
'z')))
2061 __COUT__ <<
"Illegal character in Sequence name (position " << i
2062 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2066 fixedName += name[i];
2067 __SUP_COUTV__(fixedName);
2070 std::string source =
2071 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2072 __SUP_COUT__ << source << __E__;
2073 std::string destination = (std::string)MACROS_SEQUENCE_PATH +
2074 WebUsers::DEFAULT_ADMIN_USERNAME +
"/" + fixedName +
".dat";
2075 __SUP_COUT__ << destination << __E__;
2077 if(std::filesystem::exists(destination))
2079 __SUP_SS__ <<
"The sequence name '" << fixedName
2080 <<
"' already exists in the admin/public location: " << destination
2086 std::filesystem::copy_file(
2087 source, destination, std::filesystem::copy_options::skip_existing);
2088 __SUP_COUT__ <<
"Successfully made " << fixedName
2089 <<
" public at path: " << destination << __E__;
2094 const std::string& username)
2096 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"history.hist";
2098 std::ifstream read(fileName.c_str());
2099 __SUP_COUT__ << fileName << __E__;
2105 unsigned long long fileSz, i = 0, MAX_HISTORY_SIZE = 100000;
2109 read.seekg(0, std::ios::end);
2110 fileSz = read.tellg();
2111 returnStr =
new char[fileSz + 1];
2112 returnStr[fileSz] =
'\0';
2113 read.seekg(0, std::ios::beg);
2116 read.read(returnStr, fileSz);
2120 if(fileSz > MAX_HISTORY_SIZE)
2122 i = fileSz - MAX_HISTORY_SIZE;
2123 for(; i < fileSz; ++i)
2124 if(returnStr[i] ==
'#')
2133 FILE* fp = fopen(fileName.c_str(),
"w");
2137 __SS__ <<
"Big problem with macromaker history file: " << fileName
2141 fwrite(&returnStr[i], fileSz - i, 1, fp);
2145 __SUP_COUT__ <<
"Loading user history! " << __E__;
2148 returnStr[fileSz - 2] =
'\0';
2150 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
2155 __SUP_COUT__ <<
"Unable to open history.hist" << __E__;
2161 const std::string& username)
2163 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"FEhistory.hist";
2165 std::ifstream read(fileName.c_str());
2166 __SUP_COUT__ << fileName << __E__;
2168 if(!read.is_open() && username != WebUsers::DEFAULT_ADMIN_USERNAME)
2170 __SUP_COUT__ <<
"Unable to open FE history.hist.. Defaulting to admin's FE "
2171 "history as starting point."
2175 MACROS_HIST_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
"/" +
"FEhistory.hist";
2176 read.open(fileName.c_str());
2183 unsigned long long fileSize;
2184 unsigned long long i = 0;
2185 unsigned long long MAX_HISTORY_SIZE = 100000;
2188 read.seekg(0, std::ios::end);
2189 fileSize = read.tellg();
2190 returnStr =
new char[fileSize + 1];
2191 returnStr[fileSize] =
'\0';
2192 read.seekg(0, std::ios::beg);
2195 read.read(returnStr, fileSize);
2199 if(fileSize > MAX_HISTORY_SIZE)
2201 i = fileSize - MAX_HISTORY_SIZE;
2202 for(; i < fileSize; ++i)
2204 if(returnStr[i] ==
'#')
2214 FILE* fp = fopen(fileName.c_str(),
"w");
2218 __SS__ <<
"Big problem with FE history file: " << fileName << __E__;
2221 fwrite(&returnStr[i], fileSize - i, 1, fp);
2225 __SUP_COUT__ <<
"Loading user history! " << __E__;
2228 returnStr[fileSize - 2] =
'\0';
2230 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
2235 __SUP_COUT__ <<
"Unable to open FE history.hist" << __E__;
2242 const std::string& username)
2247 std::string fileName = MacroName +
".dat";
2248 std::string fullPath;
2249 if(isMacroPublic ==
"true")
2250 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
2252 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
2254 __SUP_COUT__ << fullPath << __E__;
2256 std::remove(fullPath.c_str());
2257 __SUP_COUT__ <<
"Successfully deleted " << MacroName;
2258 xmldoc.addTextElementToData(
"deletedMacroName", MacroName);
2264 const std::string& username)
2276 __SUP_COUTV__(oldMacroName);
2277 __SUP_COUTV__(newMacroName);
2278 __SUP_COUTV__(FESequence);
2279 __SUP_COUTV__(Notes);
2280 __SUP_COUTV__(Time);
2281 __SUP_COUTV__(isMacroPublic);
2282 __SUP_COUTV__(isMacroLSBF);
2284 __SUP_COUTV__(MACROS_DB_PATH);
2286 std::string fileName = oldMacroName +
".dat";
2287 std::string fullPath;
2288 if(isMacroPublic ==
"true")
2289 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
2291 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
2293 __SUP_COUTV__(fullPath);
2295 std::ofstream macrofile(fullPath.c_str());
2296 if(macrofile.is_open())
2299 macrofile <<
"\"name\":\"" << newMacroName <<
"\",\n";
2300 macrofile <<
"\"FEsequence\":\"" << FESequence <<
"\",\n";
2301 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
2302 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
2303 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
2304 macrofile <<
"}@" << __E__;
2308 __SUP_COUT__ <<
"Unable to open file" << __E__;
2310 if(oldMacroName != newMacroName)
2314 rename((MACROS_DB_PATH + username +
"/" + oldMacroName +
".dat").c_str(),
2315 (MACROS_DB_PATH + username +
"/" + newMacroName +
".dat").c_str());
2317 xmldoc.addTextElementToData(
"newMacroName", newMacroName);
2319 xmldoc.addTextElementToData(
"newMacroName",
"ERROR");
2324 void MacroMakerSupervisor::clearHistory(
const std::string& username)
2326 std::string fileName =
"history.hist";
2327 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
2329 std::remove(fullPath.c_str());
2330 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
2334 void MacroMakerSupervisor::clearFEHistory(
const std::string& username)
2336 std::string fileName =
"FEhistory.hist";
2337 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
2339 std::remove(fullPath.c_str());
2340 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
2346 const std::string& username)
2351 std::string macroNotes =
2354 __SUP_COUTV__(pluginName);
2355 __SUP_COUTV__(macroName);
2356 __SUP_COUTV__(macroSequence);
2359 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
2360 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
2361 macroNotes[i] =
' ';
2362 __SUP_COUTV__(macroNotes);
2364 std::stringstream ss(macroSequence);
2365 std::string command;
2366 std::vector<std::string> commands;
2368 while(getline(ss, command,
','))
2369 commands.push_back(command);
2373 std::map<std::string , std::set<std::string> >
2374 specialsCodeMap = CodeEditor::getSpecialsMap();
2377 auto specialsCodeMapIt = specialsCodeMap.find(CodeEditor::SPECIAL_TYPE_FEInterface);
2378 if(specialsCodeMapIt == specialsCodeMap.end())
2381 <<
"Could not find any FE Interface plugins in source code. Does MacroMaker "
2382 <<
"have access to the source code? Check that the Supervisor context places "
2384 <<
"location with access to the source code." << __E__;
2389 std::string headerFile = pluginName +
".h";
2390 std::string sourceFile = pluginName +
"_interface.cc";
2391 bool foundHeaderFile =
false;
2392 bool foundSourceFile =
false;
2393 for(
const auto& filePath : specialsCodeMapIt->second)
2395 if(!foundHeaderFile && filePath.find(headerFile) != std::string::npos)
2397 foundHeaderFile =
true;
2398 headerFile = filePath;
2399 __SUP_COUT__ <<
"found headerFile=" << filePath << __E__;
2401 if(!foundSourceFile && filePath.find(sourceFile) != std::string::npos)
2403 foundSourceFile =
true;
2404 sourceFile = filePath;
2405 __SUP_COUT__ <<
"found sourceFile=" << filePath << __E__;
2408 if(foundSourceFile && foundHeaderFile)
2412 if(!foundHeaderFile)
2414 __SS__ <<
"Could not find the header file for the FE Interface plugins at '"
2415 << headerFile <<
".' Does MacroMaker "
2416 <<
"have access to the source code? Check that the Supervisor context "
2417 "places MacroMaker in a "
2418 <<
"location with access to the source code." << __E__;
2421 if(!foundSourceFile)
2423 __SS__ <<
"Could not find the source file for the FE Interface plugins at '"
2424 << sourceFile <<
".' Does MacroMaker "
2425 <<
"have access to the source code? Check that the Supervisor context "
2426 "places MacroMaker in a "
2427 <<
"location with access to the source code." << __E__;
2440 char timeBuffer[100];
2443 struct tm* timeinfo;
2446 timeinfo = localtime(&rawtime);
2448 strftime(timeBuffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
2451 std::string contents;
2456 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, sourceFile, contents);
2460 xmldoc.addTextElementToData(
"sourceFile", sourceFile);
2461 xmldoc.addTextElementToData(
"headerFile", headerFile);
2464 if(contents.find(pluginName +
"::" + macroName) != std::string::npos)
2466 __SS__ <<
"The function definition '" << (pluginName +
"::" + macroName)
2467 <<
"(...)' already exists in the source file '" << sourceFile
2468 <<
".' Duplicate functions are not allowed - please rename the macro or "
2469 "modify the source file."
2474 std::stringstream codess;
2475 std::set<std::string> inArgNames, outArgNames;
2487 auto insertPos = contents.find(pluginName +
"::" + pluginName);
2488 if(insertPos == std::string::npos)
2490 __SS__ <<
"Could not find the code insert position in the source file '"
2491 << sourceFile <<
".' The FE plugin class constructor must be '"
2492 << pluginName <<
":" << pluginName <<
"' - is this the case?" << __E__;
2495 __SUP_COUTV__(insertPos);
2497 insertPos = contents.find(
"{", insertPos);
2498 if(insertPos == std::string::npos)
2500 __SS__ <<
"Could not find the code insert position in the source file '"
2502 <<
".' The FE plugin class constructor must begin with '{"
2503 <<
"' - is this the case?" << __E__;
2507 __SUP_COUTV__(insertPos);
2509 insert =
"\n\t//registration of FEMacro '" + macroName +
"' generated, " +
2510 timeBuffer +
", by '" + username +
"' using MacroMaker.\n\t" +
2511 "FEVInterface::registerFEMacroFunction(\"" + macroName +
2512 "\",//feMacroName \n\t\t" +
2513 "static_cast<FEVInterface::frontEndMacroFunction_t>(&" + pluginName +
2514 "::" + macroName +
"), //feMacroFunction \n\t\t" +
2515 "std::vector<std::string>{";
2518 for(
const auto& inArg : inArgNames)
2524 insert +=
"\"" + inArg +
"\"";
2527 insert +=
"}, //namesOfInputArgs \n\t\t";
2528 insert +=
"std::vector<std::string>{";
2531 for(
const auto& outArg : outArgNames)
2537 insert +=
"\"" + outArg +
"\"";
2540 insert +=
"}, //namesOfOutputArgs \n\t\t";
2541 insert +=
"1); //requiredUserPermissions \n\n";
2543 __SUP_COUTV__(insert);
2544 contents = contents.substr(0, insertPos) + insert + contents.substr(insertPos);
2549 auto insertPos = contents.rfind(
"DEFINE_OTS_INTERFACE");
2550 if(insertPos == std::string::npos)
2552 __SS__ <<
"Could not find the code insert position in the source file '"
2554 <<
".' The FE plugin class must end with a 'DEFINE_OTS_INTERFACE("
2555 << pluginName <<
")' - is this the case?" << __E__;
2558 __SUP_COUTV__(insertPos);
2562 "============================================================================"
2563 "============================================\n//" +
2564 macroName +
"\n" +
"//\tFEMacro '" + macroName +
"' generated, " +
2565 timeBuffer +
", by '" + username +
"' using MacroMaker.\n" +
2566 "//\tMacro Notes: " + macroNotes +
"\n" +
"void " + pluginName +
2567 "::" + macroName +
"(__ARGS__)\n{\n\t" +
2568 "__CFG_COUT__ << \"# of input args = \" << argsIn.size() << __E__; \n\t" +
2569 "__CFG_COUT__ << \"# of output args = \" << argsOut.size() << __E__; \n\t" +
2570 "for(auto &argIn:argsIn) \n\t\t" +
2571 "__CFG_COUT__ << argIn.first << \": \" << argIn.second << __E__; \n\n\t" +
2572 "//macro commands section \n" + codess.str() +
"\n\n\t" +
2573 "for(auto &argOut:argsOut) \n\t\t" +
2574 "__CFG_COUT__ << argOut.first << \": \" << argOut.second << __E__; \n\n" +
2575 "} //end " + macroName +
"()\n\n";
2578 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
2581 "MacroMaker-" + username,
2588 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, headerFile, contents);
2593 auto insertPos = contents.rfind(
"};");
2594 if(insertPos == std::string::npos)
2596 __SS__ <<
"Could not find the code insert position in the header file '"
2598 <<
".' The FE plugin class must end with a '};' - is this the case?"
2603 __SUP_COUTV__(insertPos);
2605 insert =
"\npublic: // FEMacro '" + macroName +
"' generated, " + timeBuffer +
2606 ", by '" + username +
"' using MacroMaker.\n\t" +
"void " + macroName +
2609 __SUP_COUTV__(insert);
2610 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
2613 "MacroMaker-" + username,
2623 const std::string& username)
2627 std::string macroNotes =
2630 __SUP_COUTV__(macroName);
2631 __SUP_COUTV__(macroSequence);
2634 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
2635 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
2636 macroNotes[i] =
' ';
2637 __SUP_COUTV__(macroNotes);
2639 std::stringstream ss(macroSequence);
2640 std::string command;
2641 std::vector<std::string> commands;
2643 while(getline(ss, command,
','))
2644 commands.push_back(command);
2646 std::string fileName = macroName +
".cc";
2648 std::string fullPath =
2649 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + username +
"/" + fileName;
2650 __SUP_COUT__ << fullPath << __E__;
2651 std::ofstream exportFile(fullPath.c_str(), std::ios::trunc);
2652 if(exportFile.is_open())
2654 exportFile <<
"//Generated Macro Name:\t" << macroName <<
"\n";
2655 exportFile <<
"//Macro Notes: " << macroNotes <<
"\n";
2659 struct tm* timeinfo;
2663 timeinfo = localtime(&rawtime);
2665 strftime(buffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
2666 exportFile <<
"//Generated Time: \t\t" << buffer <<
"\n";
2669 exportFile <<
"//Paste this whole file into an interface to transfer Macro "
2672 createCode(exportFile, commands);
2676 xmldoc.addTextElementToData(
2678 "$USER_DATA/ServiceData/" + MACROS_EXPORT_PATH + username +
"/" + fileName);
2681 __SUP_COUT__ <<
"Unable to open file" << __E__;
2686 void MacroMakerSupervisor::createCode(std::ostream& out,
2687 const std::vector<std::string>& commands,
2688 const std::string& tabOffset,
2690 std::set<std::string>* inArgNames,
2691 std::set<std::string>* outArgNames)
2694 std::set<std::string > argInHasBeenInitializedSet;
2695 bool addressIsVariable, dataIsVariable;
2697 out << tabOffset <<
"{";
2700 << tabOffset <<
"\t"
2701 <<
"char *address \t= new char[universalAddressSize_]{0}; //create address "
2702 "buffer of interface size and init to all 0";
2704 << tabOffset <<
"\t"
2705 <<
"char *data \t\t= new char[universalDataSize_]{0}; //create data buffer "
2706 "of interface size and init to all 0";
2709 << tabOffset <<
"\t"
2710 <<
"uint64_t macroAddress; //create macro address buffer (size 8 bytes)";
2712 << tabOffset <<
"\t"
2713 <<
"uint64_t macroData; //create macro address buffer (size 8 bytes)";
2716 << tabOffset <<
"\t"
2717 <<
"std::map<std::string /*arg name*/,uint64_t /*arg val*/> macroArgs; //create "
2718 "map from arg name to 64-bit number";
2721 for(
unsigned int i = 0; i < commands.size(); i++)
2723 std::stringstream sst(commands[i]);
2725 std::vector<std::string>
2727 while(getline(sst, tokens,
':'))
2728 oneCommand.push_back(tokens);
2729 while(oneCommand.size() < 4)
2730 oneCommand.push_back(
"");
2758 addressIsVariable = isArgumentVariable(oneCommand[2]);
2759 dataIsVariable = isArgumentVariable(oneCommand[3]);
2761 __SUP_COUTV__(addressIsVariable);
2762 __SUP_COUTV__(dataIsVariable);
2764 out <<
"\n\n" << tabOffset <<
"\t// command-#" << i <<
": ";
2766 if(oneCommand[1][0] ==
'w' || oneCommand[1][0] ==
'r')
2768 if(oneCommand[1][0] ==
'w')
2770 else if(oneCommand[1][0] ==
'r')
2773 if(addressIsVariable)
2774 out << oneCommand[2];
2776 out <<
"0x" << oneCommand[2];
2777 out <<
" /*address*/,";
2781 out << oneCommand[3] <<
" /*data*/";
2782 else if(oneCommand[1][0] ==
'w')
2783 out <<
"0x" << oneCommand[3] <<
" /*data*/";
2784 else if(oneCommand[1][0] ==
'r')
2788 else if(oneCommand[1][0] ==
'd')
2790 out <<
"delay(" << oneCommand[2] <<
");\n";
2791 out << tabOffset <<
"\t"
2792 <<
"__CFG_COUT__ << \"Sleeping for... \" << " << oneCommand[2]
2793 <<
" << \" milliseconds \" << __E__;\n";
2794 out << tabOffset <<
"\t"
2795 <<
"usleep(" << oneCommand[2] <<
"*1000 /* microseconds */);\n";
2800 __SS__ <<
"FATAL ERROR: Unknown command '" << oneCommand[1]
2801 <<
"'... command is not w, r or d" << __E__;
2807 if(addressIsVariable)
2809 if(argInHasBeenInitializedSet.find(oneCommand[2]) ==
2810 argInHasBeenInitializedSet.end())
2812 argInHasBeenInitializedSet.emplace(oneCommand[2]);
2817 out << tabOffset <<
"\t"
2818 <<
"macroArgs[\"" << oneCommand[2]
2820 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2823 << tabOffset <<
"\t\t\"" << oneCommand[2]
2824 <<
"\").getValue<uint64_t>();";
2829 inArgNames->emplace(oneCommand[2]);
2832 out << tabOffset <<
"\t"
2833 <<
"macroArgs[\"" << oneCommand[2] <<
"\"] = __GET_ARG_IN__(\""
2834 << oneCommand[2] <<
"\", uint64_t);";
2837 out <<
"\t//get macro address argument";
2839 << tabOffset <<
"\tmemcpy(address,¯oArgs[\"" << oneCommand[2]
2840 <<
"\"],8); //copy macro address argument to buffer";
2844 out << tabOffset <<
"\t"
2845 <<
"macroAddress = 0x" << oneCommand[2]
2846 <<
"; memcpy(address,¯oAddress,8);"
2847 <<
"\t//copy macro address to buffer";
2852 if(oneCommand[1] ==
"w")
2856 if(argInHasBeenInitializedSet.find(oneCommand[3]) ==
2857 argInHasBeenInitializedSet
2860 argInHasBeenInitializedSet.emplace(oneCommand[3]);
2865 inArgNames->emplace(oneCommand[3]);
2869 << tabOffset <<
"\t"
2870 <<
"macroArgs[\"" << oneCommand[3]
2871 <<
"\"] = __GET_ARG_IN__(\"" << oneCommand[3]
2872 <<
"\", uint64_t); //initialize from input arguments";
2878 << tabOffset <<
"\t"
2879 <<
"macroArgs[\"" << oneCommand[3]
2881 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2884 << tabOffset <<
"\t\t\"" << oneCommand[3]
2885 <<
"\").getValue<uint64_t>(); //initialize from "
2886 "configuration tree";
2889 out <<
"\t//get macro data argument";
2891 << tabOffset <<
"\tmemcpy(data,¯oArgs[\"" << oneCommand[3]
2892 <<
"\"],8); //copy macro data argument to buffer";
2897 << tabOffset <<
"\t"
2898 <<
"macroData = 0x" << oneCommand[3] <<
"; memcpy(data,¯oData,8);"
2899 <<
"\t//copy macro data to buffer";
2902 << tabOffset <<
"\t"
2903 <<
"universalWrite(address,data);";
2908 << tabOffset <<
"\t"
2909 <<
"universalRead(address,data);";
2911 std::string outputArgName;
2914 outputArgName = oneCommand[3];
2918 sprintf(str,
"outArg%d", i);
2919 outputArgName = str;
2921 __SUP_COUTV__(outputArgName);
2923 out << tabOffset <<
"\t"
2924 <<
"memcpy(¯oArgs[\"" << outputArgName
2925 <<
"\"],data,8); //copy buffer to argument map";
2930 << tabOffset <<
"\t"
2931 <<
"__SET_ARG_OUT__(\"" << outputArgName <<
"\",macroArgs[\""
2932 << outputArgName <<
"\"]); //update output argument result";
2935 outArgNames->emplace(outputArgName);
2936 argInHasBeenInitializedSet.emplace(
2941 out <<
"\n\n" << tabOffset <<
"\tdelete[] address; //free the memory";
2942 out <<
"\n" << tabOffset <<
"\tdelete[] data; //free the memory";
2943 out <<
"\n" << tabOffset <<
"}";
2945 __SUP_COUT__ <<
"Done with code generation." << __E__;
2951 bool MacroMakerSupervisor::isArgumentVariable(
const std::string& argumentString)
2953 for(
unsigned int i = 0; i < argumentString.length(); ++i)
2956 if(!((argumentString[i] >=
'0' && argumentString[i] <=
'9') ||
2957 (argumentString[i] >=
'a' && argumentString[i] <=
'f') ||
2958 (argumentString[i] >=
'A' && argumentString[i] <=
'F')))
2973 std::string MacroMakerSupervisor::generateHexArray(
const std::string& sourceHexString,
2976 std::stringstream retSs;
2978 std::string srcHexStr = sourceHexString;
2979 __SUP_COUT__ <<
"Translating: \n";
2980 __SUP_COUT__ << srcHexStr << __E__;
2982 if(srcHexStr.size() % 2)
2983 srcHexStr =
"0" + srcHexStr;
2985 numOfBytes = srcHexStr.size() / 2;
2986 retSs <<
"[" << numOfBytes <<
"] = {";
2988 for(
int i = 0; i < numOfBytes * 2; i += 2)
2991 if(!((srcHexStr[i] >=
'0' && srcHexStr[i] <=
'9') ||
2992 (srcHexStr[i] >=
'a' && srcHexStr[i] <=
'f') ||
2993 (srcHexStr[i] >=
'A' && srcHexStr[i] <=
'F')) ||
2994 !((srcHexStr[i + 1] >=
'0' && srcHexStr[i + 1] <=
'9') ||
2995 (srcHexStr[i + 1] >=
'a' && srcHexStr[i + 1] <=
'f') ||
2996 (srcHexStr[i + 1] >=
'A' && srcHexStr[i + 1] <=
'F')))
3004 retSs <<
"0x" << srcHexStr[srcHexStr.size() - 1 - i - 1]
3005 << srcHexStr[srcHexStr.size() - 1 - i];
3009 __SUP_COUT__ << retSs.str() << __E__;
3017 const WebUsers::RequestUserInfo& userInfo)
3020 __SUP_COUTT__ << __E__;
3022 uint64_t NotDoneID = CgiDataUtilities::getDataAsUint64_t(cgi,
"NotDoneID");
3025 __SUP_COUT__ <<
"Checking if recent FE macro run has completed for NotDoneID = "
3026 << NotDoneID << __E__;
3028 for(
const auto& feMacroRunThreadStruct : feMacroRunThreadStruct_)
3029 __SUP_COUTT__ <<
"[] threadID_ = "
3030 << feMacroRunThreadStruct.parameters_.threadID_ << __E__;
3032 time_t now = time(0);
3033 size_t target_i = -1;
3034 for(
size_t i = 0; i < feMacroRunThreadStruct_.size(); ++i)
3036 if(feMacroRunThreadStruct_[i].parameters_.threadID_ == NotDoneID)
3039 __SUP_COUTT__ <<
"Found NotDoneID = " << NotDoneID << __E__;
3042 else if(feMacroRunThreadStruct_[i].feMacroRunDone_ &&
3043 now - feMacroRunThreadStruct_[i].parameters_.doneTime_ >
3046 __SUP_COUTT__ <<
"Cleaning up completed NotDoneID = " << NotDoneID
3049 feMacroRunThreadStruct_.erase(feMacroRunThreadStruct_.begin() + i);
3052 else if(now - feMacroRunThreadStruct_[i].parameters_.startTime_ >
3056 <<
"Found old FE Macro exectution of '"
3057 << feMacroRunThreadStruct_[i].parameters_.macroName_ <<
"' at '"
3058 << feMacroRunThreadStruct_[i].parameters_.feUIDSelected_ <<
".'"
3063 if(target_i >= feMacroRunThreadStruct_.size())
3066 <<
"Attempted to check recent FE Macro run completion with invalid ID="
3068 <<
". Perhaps this FE Macro completed more than 5 minutes ago?" << __E__;
3072 if(feMacroRunThreadStruct_[target_i].feMacroRunDone_)
3074 __SUP_COUT__ <<
"Found done for NotDoneID = " << NotDoneID << __E__;
3076 if(feMacroRunThreadStruct_[target_i].parameters_.feMacroRunError_ !=
"")
3079 << feMacroRunThreadStruct_[target_i].parameters_.feMacroRunError_;
3085 std::ostringstream oss;
3086 feMacroRunThreadStruct_.back().parameters_.xmldoc_.outputXmlDocument(
3088 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3091 feMacroRunThreadStruct_[target_i].parameters_.xmldoc_);
3092 __SUP_COUT__ <<
"FE macro complete." << __E__;
3096 __SUP_COUT__ <<
"Found still going for NotDoneID = " << NotDoneID << __E__;
3098 xmldoc.addNumberElementToData(
"NotDoneID", NotDoneID);
3105 std::string feUIDSelected =
3108 std::string macroName =
3112 bool saveOutputs = CgiDataUtilities::getDataAsInt(cgi,
"saveOutputs") == 1;
3114 __SUP_COUTTV__(feClassSelected);
3115 __SUP_COUTTV__(feUIDSelected);
3116 __SUP_COUTTV__(macroType);
3117 __SUP_COUTTV__(macroName);
3118 __SUP_COUTTV__(inputArgs);
3119 __SUP_COUTTV__(outputArgs);
3120 __SUP_COUTTV__(saveOutputs);
3121 __SUP_COUTTV__(userInfo.username_);
3124 feMacroRunThreadStruct_.emplace_back(
3151 MacroMakerSupervisor::runFEMacroThread(s, mm);
3153 &feMacroRunThreadStruct_.back(),
3156 size_t sleepTime = 10 * 1000;
3159 for(
int i = 0; i < 6; ++i)
3161 if(feMacroRunThreadStruct_.back().feMacroRunDone_)
3163 __SUP_COUTT__ <<
"FE macro marked done" << __E__;
3168 __SUP_COUTT__ <<
"FE macro not done, sleeping..." << __E__;
3170 if(sleepTime > 1000 * 1000 )
3171 sleepTime = 1000 * 1000;
3176 if(!feMacroRunThreadStruct_.back().feMacroRunDone_)
3178 if(t.get_id() == std::thread::id())
3180 __SUP_SS__ <<
"Invalid thread ID. Contact system admins!" << __E__;
3183 feMacroRunThreadStruct_.back().parameters_.threadID_ =
3184 std::hash<std::thread::id>{}(t.get_id());
3186 if(feMacroRunThreadStruct_.back().parameters_.threadID_ == 0)
3188 __SUP_SS__ <<
"Invalid thread ID hash. Contact system admins!" << __E__;
3192 __SUP_COUT__ <<
"FE macro not done, detaching thread="
3193 << feMacroRunThreadStruct_.back().parameters_.threadID_ << __E__;
3195 xmldoc.addNumberElementToData(
3196 "NotDoneID", feMacroRunThreadStruct_.back().parameters_.threadID_);
3200 std::ostringstream oss;
3202 &oss,
false ,
true );
3203 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3208 __SUP_COUTT__ <<
"FE macro marked done - joining threads." << __E__;
3210 if(feMacroRunThreadStruct_.back().parameters_.feMacroRunError_ !=
"")
3212 __SUP_SS__ << feMacroRunThreadStruct_.back().parameters_.feMacroRunError_;
3218 std::ostringstream oss;
3219 feMacroRunThreadStruct_.back().parameters_.xmldoc_.outputXmlDocument(
3220 &oss,
false ,
true );
3221 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3223 xmldoc.
copyDataChildren(feMacroRunThreadStruct_.back().parameters_.xmldoc_);
3227 std::ostringstream oss;
3229 &oss,
false ,
true );
3230 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3233 feMacroRunThreadStruct_.pop_back();
3234 __SUP_COUT__ <<
"FE macro complete." << __E__;
3236 for(
const auto& feMacroRunThreadStruct : feMacroRunThreadStruct_)
3237 __SUP_COUTT__ <<
"[] threadID_ = " << feMacroRunThreadStruct.parameters_.threadID_
3241 catch(
const std::runtime_error& e)
3243 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
3244 __SUP_COUT_ERR__ << ss.str();
3245 xmldoc.addTextElementToData(
"Error", ss.str());
3249 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
3254 catch(
const std::exception& e)
3256 ss <<
"Exception message: " << e.what();
3261 __SUP_COUT_ERR__ << ss.str();
3263 xmldoc.addTextElementToData(
"Error", ss.str());
3268 void MacroMakerSupervisor::runFEMacroThread(runFEMacroStruct* feMacroRunThreadStruct,
3272 __COUT__ <<
"runFEMacro thread started... threadid = " << std::this_thread::get_id()
3273 <<
" " << mmSupervisor <<
" getpid()=" << getpid()
3274 <<
" gettid()=" << gettid() << __E__;
3276 mmSupervisor->runFEMacro(feMacroRunThreadStruct->parameters_.xmldoc_,
3277 feMacroRunThreadStruct->parameters_.feClassSelected_,
3278 feMacroRunThreadStruct->parameters_.feUIDSelected_,
3279 feMacroRunThreadStruct->parameters_.macroType_,
3280 feMacroRunThreadStruct->parameters_.macroName_,
3281 feMacroRunThreadStruct->parameters_.inputArgs_,
3282 feMacroRunThreadStruct->parameters_.outputArgs_,
3283 feMacroRunThreadStruct->parameters_.saveOutputs_,
3284 feMacroRunThreadStruct->parameters_.runningUsername_,
3285 feMacroRunThreadStruct->parameters_.userGroupPermissions_);
3287 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3288 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3289 __COUT__ <<
"runFEMacro thread done. threadid = " << std::this_thread::get_id()
3293 catch(
const std::runtime_error& e)
3295 __SS__ <<
"Error during runFEMacro thread: " << e.what() << __E__;
3296 __COUT_ERR__ << ss.str();
3297 feMacroRunThreadStruct->parameters_.feMacroRunError_ = ss.str();
3298 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3299 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3303 __SS__ <<
"Unknown error during runFEMacro thread." << __E__;
3308 catch(
const std::exception& e)
3310 ss <<
"Exception message: " << e.what();
3315 __COUT_ERR__ << ss.str();
3316 feMacroRunThreadStruct->parameters_.feMacroRunError_ = ss.str();
3317 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3318 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3323 std::string feClassSelected,
3324 std::string feUIDSelected,
3325 const std::string& macroType,
3326 const std::string& macroName,
3327 const std::string& inputArgs,
3328 const std::string outputArgs,
3330 const std::string& username,
3331 const std::string& userGroupPermissions)
3333 __SUP_COUTV__(feClassSelected);
3334 __SUP_COUTV__(feUIDSelected);
3335 __SUP_COUTV__(macroType);
3336 __SUP_COUTV__(macroName);
3337 __SUP_COUTV__(inputArgs);
3338 __SUP_COUTV__(outputArgs);
3339 __SUP_COUTV__(saveOutputs);
3340 __SUP_COUTV__(username);
3341 __SUP_COUTV__(userGroupPermissions);
3343 appendCommandToHistory(feClassSelected,
3352 std::set<std::string > feUIDs;
3354 if(feUIDSelected ==
"")
3355 feUIDSelected =
"*";
3356 if(feClassSelected ==
"")
3357 feClassSelected =
"*";
3359 if(feClassSelected ==
"" || feUIDSelected ==
"" || macroType ==
"" || macroName ==
"")
3361 __SUP_SS__ <<
"Illegal empty front-end parameter." << __E__;
3364 else if(feUIDSelected !=
"*")
3371 if(feClassSelected ==
"*")
3373 for(
auto& feTypePair : FEPluginTypetoFEsMap_)
3374 for(
auto& feUID : feTypePair.second)
3375 feUIDs.emplace(feUID);
3379 auto typeIt = FEPluginTypetoFEsMap_.find(feClassSelected);
3380 if(typeIt == FEPluginTypetoFEsMap_.end())
3382 __SUP_SS__ <<
"Illegal front-end type parameter '" << feClassSelected
3383 <<
"' not in list of types." << __E__;
3387 for(
auto& feUID : typeIt->second)
3388 feUIDs.emplace(feUID);
3394 std::string macroString;
3395 if(macroType ==
"public")
3396 loadMacro(macroName, macroString);
3397 else if(macroType ==
"private")
3398 loadMacro(macroName, macroString, username);
3400 __SUP_COUTV__(macroString);
3407 std::string filename =
"/macroOutput_" + std::to_string(time(0)) +
"_" +
3408 std::to_string(clock()) +
".txt";
3410 __SUP_COUTV__(filename);
3411 fp = fopen((CodeEditor::OTSDAQ_DATA_PATH + filename).c_str(),
"w");
3414 __SUP_SS__ <<
"Failed to open file to save macro output '"
3415 << CodeEditor::OTSDAQ_DATA_PATH << filename <<
"'..." << __E__;
3419 fprintf(fp,
"############################\n");
3421 "### Running '%s' at time %s\n",
3425 "### \t Target front-ends (count=%lu): %s\n",
3428 fprintf(fp,
"### \t\t Inputs: %s\n", inputArgs.c_str());
3429 fprintf(fp,
"############################\n\n\n");
3431 xmldoc.addTextElementToData(
"feMacroRunArgs_name",
"Filename");
3432 xmldoc.addTextElementToData(
"feMacroRunArgs_value",
3433 "$OTSDAQ_DATA/" + filename);
3437 for(
auto& feUID : feUIDs)
3439 auto feIt = FEtoSupervisorMap_.find(feUID);
3440 if(feIt == FEtoSupervisorMap_.end())
3442 __SUP_SS__ <<
"Destination front end interface ID '" << feUID
3443 <<
"' was not found in the list of front ends." << __E__;
3444 ss <<
"\n\nHere is the map:\n\n"
3449 unsigned int FESupervisorIndex = feIt->second;
3450 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
3452 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
3453 if(it == allFESupervisorInfo_.end())
3456 <<
"Error transmitting request to FE Supervisor '" << feUID <<
":"
3457 << FESupervisorIndex <<
".' \n\n"
3458 <<
"The FE Supervisor Index does not exist. Have you configured "
3459 "the state machine properly?"
3466 if(macroType ==
"fe")
3467 txParameters.
addParameter(
"Request",
"RunInterfaceMacro");
3469 txParameters.
addParameter(
"Request",
"RunMacroMakerMacro");
3471 if(macroType ==
"fe")
3480 txParameters.
addParameter(
"userPermissions", userGroupPermissions);
3490 "Running '%s' at time %s\n",
3494 "\t Target front-end: '%s::%s'\n",
3495 FEtoPluginTypeMap_[feUID].c_str(),
3498 "\t\t Inputs: %s\n",
3503 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
3504 it->second.getDescriptor(),
3505 "MacroMakerSupervisorRequest",
3508 __SUP_COUT__ <<
"Received response message: "
3509 << SOAPUtilities::translate(retMsg) << __E__;
3511 SOAPUtilities::receive(retMsg, rxParameters);
3513 __SUP_COUT__ <<
"Received it " << __E__;
3516 std::string outputResults = rxParameters.getValue(
"outputArgs");
3517 std::string error = rxParameters.getValue(
"Error");
3520 __SUP_COUT__ <<
"outputArgs = " << outputResults << __E__;
3524 __SS__ <<
"Attempted FE Macro Failed. Attempted target "
3525 <<
"was UID=" << feUID
3526 <<
" at feSupervisorID=" << FESupervisorIndex <<
"." << __E__;
3527 ss <<
"\n\n The error was:\n\n" << error << __E__;
3528 __SUP_COUT_ERR__ <<
"\n" << ss.str();
3529 xmldoc.addTextElementToData(
"Error", ss.str());
3536 DOMElement* feMacroExecParent =
3537 xmldoc.addTextElementToData(
"feMacroExec", macroName);
3543 "fe_type", FEtoPluginTypeMap_[feUID], feMacroExecParent);
3545 "fe_context", it->second.getContextName(), feMacroExecParent);
3547 "fe_supervisor", it->second.getName(), feMacroExecParent);
3549 "fe_hostname", it->second.getHostname(), feMacroExecParent);
3551 std::istringstream inputStream(outputResults);
3552 std::string splitVal, argName, argValue;
3553 while(getline(inputStream, splitVal,
';'))
3555 std::istringstream pairInputStream(splitVal);
3556 getline(pairInputStream, argName,
',');
3557 getline(pairInputStream, argValue,
',');
3562 "\t\t Output '%s' = %s\n",
3569 "outputArgs_name", argName, feMacroExecParent);
3571 "outputArgs_value", argValue, feMacroExecParent);
3573 __SUP_COUT__ << argName <<
": " << argValue << __E__;
3592 const std::string& username)
3594 __SUP_COUT__ <<
"Getting FE Macro list" << __E__;
3597 txParameters.
addParameter(
"Request",
"GetInterfaceMacros");
3602 std::string oneInterface;
3603 std::string rxFEMacros;
3607 for(
auto& appInfo : allFESupervisorInfo_)
3609 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
3610 <<
" name = " << appInfo.second.getName() << __E__;
3612 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
3613 appInfo.second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
3614 SOAPUtilities::receive(retMsg, rxParameters);
3616 rxFEMacros = rxParameters.getValue(
"FEMacros");
3618 __SUP_COUT__ <<
"FE Macros received: \n" << rxFEMacros << __E__;
3620 std::istringstream allInterfaces(rxFEMacros);
3621 while(std::getline(allInterfaces, oneInterface))
3625 xmldoc.addTextElementToData(
"FEMacros", oneInterface);
3631 std::pair<std::vector<std::string> ,
3632 std::vector<std::string> >
3634 loadMacroNames(username, macroNames);
3636 __SUP_COUT__ <<
"Public macro count: " << macroNames.first.size() << __E__;
3637 __SUP_COUT__ <<
"Private macro count: " << macroNames.second.size() << __E__;
3639 std::string macroString;
3648 for(
int i = 0; i < 2; ++i)
3649 for(
auto& macroName : (i ? macroNames.second : macroNames.first))
3652 loadMacro(macroName, macroString, username);
3657 std::stringstream xmlMacroStream;
3658 xmlMacroStream << macro.macroName_;
3659 xmlMacroStream <<
":"
3661 xmlMacroStream <<
":" << macro.namesOfInputArguments_.size();
3662 for(
auto& inputArg : macro.namesOfInputArguments_)
3663 xmlMacroStream <<
":" << inputArg;
3664 xmlMacroStream <<
":" << macro.namesOfOutputArguments_.size();
3665 for(
auto& inputArg : macro.namesOfOutputArguments_)
3666 xmlMacroStream <<
":" << inputArg;
3668 xmldoc.addTextElementToData(i ?
"PrivateMacro" :
"PublicMacro",
3669 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 onlyLoadIfBackboneOrContext=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)