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")
518 std::string macroPath = (std::string)MACROS_DB_PATH +
"NO-USER" +
"/";
519 mkdir(macroPath.c_str(), 0755);
520 std::string histPath =
521 (std::string)MACROS_HIST_PATH +
"NO-USER" +
"/";
522 mkdir(histPath.c_str(), 0755);
525 theSupervisor->getFEMacroList(xmldoc,
"NO-USER");
527 std::stringstream out;
531 __COUT__ <<
"out: " << out.str();
532 sock.acknowledge(out.str(),
true );
534 else if(buffer.find(
"RunFrontendMacro") == 0)
538 std::vector<std::string> bufferFields =
540 if(bufferFields.size() < 8)
542 __SS__ <<
"Missing input arguments for running FE Macro: "
543 << bufferFields.size() <<
" vs 8 expected" << __E__;
547 std::string feClassSelected = bufferFields[1];
548 std::string feUIDSelected =
550 std::string macroType = bufferFields[3];
551 std::string macroName =
555 std::string outputArgs =
557 bool saveOutputs = bufferFields[7] ==
"1";
558 std::string username =
"NO-USER";
559 std::string userGroupPermission =
"allUsers: 255";
561 theSupervisor->runFEMacro(xmldoc,
570 userGroupPermission);
572 std::stringstream out;
576 __COUT__ <<
"out: " << out.str();
577 sock.acknowledge(out.str(),
true );
581 __SS__ <<
"Unrecognized UDP command received: " << buffer << __E__;
585 catch(
const std::runtime_error& e)
587 __COUT_ERR__ <<
"Error during UDP command handling: " << e.what()
589 sock.acknowledge(std::string(
"Error: ") + e.what(),
true );
593 __COUT_ERR__ <<
"Unknown error caught during UDP command handling - "
596 sock.acknowledge(std::string(
"Error: ") +
"unknown error caught",
600 __COUT__ <<
"Done handling command '" << buffer <<
"'" << __E__;
610 void MacroMakerSupervisor::requestWrapper(xgi::Input* in, xgi::Output* out)
613 if(!CorePropertySupervisorBase::allSupervisorInfo_.isMacroMakerMode())
615 __SUP_COUTT__ <<
"Default request wrapper" << __E__;
616 return CoreSupervisorBase::requestWrapper(in, out);
620 __SUP_COUTT__ <<
"MacroMaker mode request handler!" << __E__;
624 cgicc::Cgicc cgiIn(in);
629 if(securityCode_.compare(submittedSequence) != 0)
631 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match! "
637 __SUP_COUTT__ <<
"***Successfully authenticated security sequence. " << time(0)
644 __SUP_COUT_TYPE__(TLVL_DEBUG + 10) << __COUT_HDR__ <<
"requestType " << requestType
645 <<
" files: " << cgiIn.getFiles().size() << __E__;
648 WebUsers::RequestUserInfo userInfo(
654 userInfo.username_ =
"admin";
655 userInfo.displayName_ =
"Admin";
656 userInfo.usernameWithLock_ =
"admin";
657 userInfo.userSessionIndex_ = 0;
658 std::map<std::string , WebUsers::permissionLevel_t> initPermissions = {
663 __SUP_COUTT__ <<
"requestType: " << requestType << __E__;
664 else if(!userInfo.automatedCommand_)
665 __SUP_COUT__ <<
"requestType: " << requestType << __E__;
667 if(userInfo.NonXMLRequestType_)
673 catch(
const std::runtime_error& e)
675 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
676 <<
"':" << e.what() << __E__;
677 __SUP_COUT_ERR__ <<
"\n" << ss.str();
681 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
682 << requestType <<
".' "
683 <<
"Please check the printouts to debug." << __E__;
688 catch(
const std::exception& e)
690 ss <<
"Exception message: " << e.what();
695 __SUP_COUT_ERR__ <<
"\n" << ss.str();
704 request(requestType, cgiIn, xmlOut, userInfo);
705 __SUP_COUTT__ <<
"Request '" << requestType <<
"' complete." << __E__;
707 catch(
const std::runtime_error& e)
709 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
710 <<
"':" << e.what() << __E__;
711 __SUP_COUT_ERR__ <<
"\n" << ss.str();
712 xmlOut.addTextElementToData(
"Error", ss.str());
716 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
717 << requestType <<
".' "
718 <<
"Please check the printouts to debug." << __E__;
723 catch(
const std::exception& e)
725 ss <<
"Exception message: " << e.what();
730 __SUP_COUT_ERR__ <<
"\n" << ss.str();
731 xmlOut.addTextElementToData(
"Error", ss.str());
736 unsigned int occurance = 0;
740 __SUP_COUT_ERR__ <<
"'" << requestType <<
"' ERROR encountered: " << err
746 __SUP_COUTVS__(10, userInfo.NoXmlWhiteSpace_);
751 !userInfo.NoXmlWhiteSpace_ );
755 void MacroMakerSupervisor::request(
const std::string& requestType,
758 const WebUsers::RequestUserInfo& userInfo)
761 std::chrono::steady_clock::time_point requestStart = std::chrono::steady_clock::now();
762 time_t requestStartTime = time(0);
765 std::string username =
"";
766 for(
unsigned int i = 0; i < userInfo.username_.size(); ++i)
767 if((userInfo.username_[i] >=
'a' && userInfo.username_[i] <=
'z') ||
768 (userInfo.username_[i] >=
'A' && userInfo.username_[i] <=
'Z') ||
769 (userInfo.username_[i] >=
'0' && userInfo.username_[i] <=
'9') ||
770 userInfo.username_[i] >=
'-' || userInfo.username_[i] <=
'_')
771 username += userInfo.username_[i];
773 if(username.size() < 2)
775 __SUP_SS__ <<
"Illegal username '" << userInfo.username_ <<
"' received."
780 __SUP_COUT__ <<
"User name is " << userInfo.username_ <<
"." << __E__;
781 __SUP_COUT__ <<
"User permission level for request '" << requestType <<
"' is "
782 << unsigned(userInfo.permissionLevel_) <<
"." << __E__;
786 if(requestType ==
"loadFEHistory")
788 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
789 mkdir(histPath.c_str(), 0755);
792 if(requestType ==
"loadFEMacroSequences")
794 std::string seqPath =
795 (std::string)MACROS_SEQUENCE_PATH + userInfo.username_ +
"/";
796 mkdir(seqPath.c_str(), 0755);
799 if(requestType ==
"getPermission")
801 xmlOut.addTextElementToData(
"Permission",
802 std::to_string(
unsigned(userInfo.permissionLevel_)));
805 std::string publicPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
806 mkdir(publicPath.c_str(), 0755);
807 std::string exportPath =
808 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + userInfo.username_ +
"/";
809 mkdir(exportPath.c_str(), 0755);
812 handleRequest(requestType, xmlOut, cgiIn, userInfo);
814 __SUP_COUTT__ <<
"Total MacroMaker request time: "
815 << artdaq::TimeUtils::GetElapsedTime(requestStart) <<
" = "
816 << time(0) - requestStartTime <<
" seconds" << __E__;
818 catch(
const std::runtime_error& e)
820 __SS__ <<
"Error occurred handling request '" << requestType <<
"': " << e.what()
822 __SUP_COUT__ << ss.str();
823 xmlOut.addTextElementToData(
"Error", ss.str());
827 __SS__ <<
"Unknown error occurred handling request '" << requestType <<
"!'" << __E__;
832 catch(
const std::exception& e)
834 ss <<
"Exception message: " << e.what();
839 __SUP_COUT__ << ss.str();
840 xmlOut.addTextElementToData(
"Error", ss.str());
845 void MacroMakerSupervisor::handleRequest(
const std::string Command,
848 const WebUsers::RequestUserInfo& userInfo)
850 if(Command ==
"FElist")
853 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
854 mkdir(macroPath.c_str(), 0755);
855 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
856 mkdir(histPath.c_str(), 0755);
860 else if(Command ==
"writeData")
861 writeData(xmldoc, cgi, userInfo.username_);
862 else if(Command ==
"readData")
863 readData(xmldoc, cgi, userInfo.username_);
864 else if(Command ==
"createMacro")
865 createMacro(xmldoc, cgi, userInfo.username_);
866 else if(Command ==
"loadMacros")
867 loadMacros(xmldoc, userInfo.username_);
868 else if(Command ==
"loadHistory")
869 loadHistory(xmldoc, userInfo.username_);
870 else if(Command ==
"deleteMacro")
871 deleteMacro(xmldoc, cgi, userInfo.username_);
872 else if(Command ==
"editMacro")
873 editMacro(xmldoc, cgi, userInfo.username_);
874 else if(Command ==
"clearHistory")
875 clearHistory(userInfo.username_);
876 else if(Command ==
"exportMacro")
877 exportMacro(xmldoc, cgi, userInfo.username_);
878 else if(Command ==
"exportFEMacro")
879 exportFEMacro(xmldoc, cgi, userInfo.username_);
880 else if(Command ==
"getFEMacroList")
884 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
885 mkdir(macroPath.c_str(), 0755);
886 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
887 mkdir(histPath.c_str(), 0755);
889 getFEMacroList(xmldoc, userInfo.username_);
891 else if(Command ==
"runFEMacro")
893 runFEMacro(xmldoc, cgi, userInfo);
894 else if(Command ==
"loadFEHistory")
896 loadFEHistory(xmldoc, userInfo.username_);
897 else if(Command ==
"clearFEHistory")
899 clearFEHistory(userInfo.username_);
900 else if(Command ==
"loadFEMacroSequences")
901 loadFEMacroSequences(xmldoc, userInfo.username_);
902 else if(Command ==
"saveFEMacroSequence")
903 saveFEMacroSequence(cgi, userInfo.username_);
904 else if(Command ==
"getFEMacroSequence")
905 getFEMacroSequence(xmldoc, cgi, userInfo.username_);
906 else if(Command ==
"deleteFEMacroSequence")
907 deleteFEMacroSequence(cgi, userInfo.username_);
908 else if(Command ==
"makeSequencePublic")
909 makeSequencePublic(cgi, userInfo.username_);
911 xmldoc.addTextElementToData(
"Error",
912 "Command '" + Command +
913 "' not recognized by the Macro Maker Supervisor "
914 "(was it intended for another Supervisor?).");
918 xoap::MessageReference MacroMakerSupervisor::frontEndCommunicationRequest(
919 xoap::MessageReference message)
923 __SUP_COUT__ <<
"FE Request received: " << SOAPUtilities::translate(message) << __E__;
927 SOAPUtilities::receive(message, typeParameter);
929 std::string type = typeParameter.getValue(
"type");
931 std::string error =
"";
933 if(type ==
"initFElist")
939 SOAPUtilities::receive(message, rxParameters);
941 std::string groupName = rxParameters.getValue(
"groupName");
942 std::string groupKey = rxParameters.getValue(
"groupKey");
944 __SUP_COUTV__(groupName);
945 __SUP_COUTV__(groupKey);
953 const SupervisorInfoMap& feTypeSupervisors =
954 CorePropertySupervisorBase::allSupervisorInfo_.getAllFETypeSupervisorInfo();
957 cfgMgr.
getNode(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME);
959 __SUP_COUT__ <<
"Number of FE Supervisors found = " << feTypeSupervisors.size()
962 FEPluginTypetoFEsMap_.clear();
963 FEtoSupervisorMap_.clear();
964 FEtoPluginTypeMap_.clear();
965 for(
auto& feApp : feTypeSupervisors)
967 __SUP_COUT__ <<
"FEs for app " << feApp.first <<
":" << feApp.second.getName()
970 auto feChildren = appsNode.
getNode(feApp.second.getName())
971 .
getNode(
"LinkToSupervisorTable")
972 .
getNode(
"LinkToFEInterfaceTable")
975 for(
auto& fe : feChildren)
977 if(!fe.second.status())
980 __SUP_COUTV__(fe.first);
981 FEtoSupervisorMap_[fe.first] = feApp.first;
983 std::string pluginType =
984 fe.second.getNode(
"FEInterfacePluginName").getValue();
985 FEPluginTypetoFEsMap_[pluginType].emplace(fe.first);
986 FEtoPluginTypeMap_[fe.first] = pluginType;
994 else if(type ==
"feSend" ||
996 type ==
"feMacroMultiDimensionalStart" ||
997 type ==
"feMacroMultiDimensionalCheck" ||
998 type ==
"macroMultiDimensionalStart" ||
999 type ==
"macroMultiDimensionalCheck")
1001 __SUP_COUTV__(type);
1004 SOAPUtilities::receive(message, rxParameters);
1006 std::string targetInterfaceID = rxParameters.getValue(
"targetInterfaceID");
1008 __SUP_COUTV__(targetInterfaceID);
1010 auto feIt = FEtoSupervisorMap_.find(targetInterfaceID);
1011 if(feIt == FEtoSupervisorMap_.end())
1013 __SUP_SS__ <<
"Destination front end interface ID '" << targetInterfaceID
1014 <<
"' was not found in the list of front ends." << __E__;
1018 unsigned int FESupervisorIndex = feIt->second;
1019 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
1021 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1022 if(it == allFESupervisorInfo_.end())
1024 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1025 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' \n\n"
1026 <<
"The FE Supervisor Index does not exist. Have you configured "
1027 "the state machine properly?"
1032 if(type ==
"macroMultiDimensionalStart")
1038 SOAPUtilities::receive(message, rxParameters);
1039 std::string macroName = rxParameters.getValue(
"macroName");
1040 __SUP_COUTV__(macroName);
1042 std::string macroString;
1043 loadMacro(macroName, macroString);
1047 SOAPUtilities::addParameters(message, parameters);
1052 __SUP_COUT__ <<
"Forwarding request: " << SOAPUtilities::translate(message)
1055 xoap::MessageReference replyMessage =
1056 SOAPMessenger::sendWithSOAPReply(it->second.getDescriptor(), message);
1058 if(type !=
"feSend")
1060 __SUP_COUT__ <<
"Forwarding FE Macro response: "
1061 << SOAPUtilities::translate(replyMessage) << __E__;
1063 return replyMessage;
1066 catch(
const xdaq::exception::Exception& e)
1068 __SUP_SS__ <<
"Error forwarding FE Communication request to FE Supervisor '"
1069 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' "
1070 <<
"Have you configured the state machine properly?\n\n"
1071 << e.what() << __E__;
1077 __SUP_SS__ <<
"Unrecognized FE Communication type: " << type << __E__;
1081 return SOAPUtilities::makeSOAPMessageReference(
"Received");
1083 catch(
const std::runtime_error& e)
1085 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
1086 __SUP_COUT_ERR__ << ss.str();
1088 xoap::MessageReference returnMessage =
1089 SOAPUtilities::makeSOAPMessageReference(
"Error");
1093 SOAPUtilities::addParameters(returnMessage, parameters);
1094 return returnMessage;
1098 xoap::MessageReference returnMessage =
1099 SOAPUtilities::makeSOAPMessageReference(
"Error");
1101 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
1106 catch(
const std::exception& e)
1108 ss <<
"Exception message: " << e.what();
1113 __SUP_COUT_ERR__ << ss.str();
1117 SOAPUtilities::addParameters(returnMessage, parameters);
1118 return returnMessage;
1124 __SUP_COUT__ <<
"Getting FE list!!!!!!!!!" << __E__;
1136 SupervisorInfoMap::const_iterator it;
1137 std::string oneInterface;
1138 std::string rxFEList;
1139 std::string rxFrontEndError;
1141 size_t lastColonIndex;
1145 for(
auto& appInfo : allFESupervisorInfo_)
1153 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
1154 <<
" name = " << appInfo.second.getName() << __E__;
1158 xoap::MessageReference retMsg =
1159 SOAPMessenger::sendWithSOAPReply(appInfo.second.getDescriptor(),
1160 "MacroMakerSupervisorRequest",
1162 SOAPUtilities::receive(retMsg, rxParameters);
1164 __SUP_COUT__ <<
"Received MacroMaker response: "
1165 << SOAPUtilities::translate(retMsg).getCommand() <<
"==>"
1166 << SOAPUtilities::translate(retMsg) << __E__;
1168 if(SOAPUtilities::translate(retMsg).getCommand() ==
"Fault")
1170 __SUP_SS__ <<
"Unrecognized command received!" << __E__;
1174 catch(
const xdaq::exception::Exception& e)
1176 __SUP_SS__ <<
"Error transmitting request to FE Supervisor LID = "
1177 << appInfo.second.getId() <<
" name = " << appInfo.second.getName()
1179 << e.what() << __E__;
1183 rxFEList = rxParameters.getValue(
"FEList");
1184 rxFrontEndError = rxParameters.getValue(
"frontEndError");
1186 __SUP_COUT__ <<
"FE List received: \n" << rxFEList << __E__;
1188 if(rxFrontEndError !=
"")
1190 __SUP_SS__ <<
"FE Errors received: \n" << rxFrontEndError << __E__;
1194 std::istringstream allInterfaces(rxFEList);
1195 while(std::getline(allInterfaces, oneInterface))
1197 __SUP_COUTV__(oneInterface);
1198 xmldoc.addTextElementToData(
"FE", oneInterface);
1200 lastColonIndex = oneInterface.rfind(
':');
1201 if(lastColonIndex == std::string::npos)
1203 __SUP_SS__ <<
"Last colon could not be found in " << oneInterface
1207 oneInterface = oneInterface.substr(lastColonIndex);
1209 __SUP_COUTV__(oneInterface);
1219 const std::string& username)
1221 __SUP_COUT__ <<
"MacroMaker writing..." << __E__;
1234 __SUP_COUT__ <<
"Write Address: " << Address <<
" Data: " << Data << __E__;
1235 __SUP_COUTV__(interfaces);
1237 std::string command =
"w:" + Address +
":" + Data;
1238 std::string format = addressFormatStr +
":" + dataFormatStr;
1239 appendCommandToHistory(command, format, time, interfaces, username);
1242 txParameters.
addParameter(
"Request",
"UniversalWrite");
1246 __SUP_COUT__ <<
"Here comes the array from multiselect box for WRITE, behold: \n"
1247 << supervisorIndexArray <<
"\n"
1248 << interfaceIndexArray << __E__;
1252 std::vector<std::string> interfaceIndices;
1253 std::istringstream f(interfaceIndexArray);
1255 while(getline(f, s,
','))
1256 interfaceIndices.push_back(s);
1257 std::vector<int> supervisorIndices;
1258 std::istringstream g(supervisorIndexArray);
1260 while(getline(g, t,
','))
1261 supervisorIndices.push_back(std::stoi(t));
1263 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
1265 unsigned int FESupervisorIndex = supervisorIndices[i];
1266 std::string interfaceIndex = interfaceIndices[i];
1268 txParameters.
addParameter(
"InterfaceID", interfaceIndex);
1270 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
1272 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
1274 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1275 if(it == allFESupervisorInfo_.end())
1277 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1278 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
1279 <<
"The FE Index doesn't exist. Have you configured the state "
1287 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1288 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1290 __SUP_COUT__ <<
"Response received: "
1291 << SOAPUtilities::translate(replyMessage) << __E__;
1295 SOAPUtilities::receive(replyMessage, rxParameters);
1297 std::string error = rxParameters.getValue(
"Error");
1298 __SUP_COUTV__(error);
1303 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1304 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1305 <<
"Have you configured the state machine properly?\n\n"
1310 catch(
const xdaq::exception::Exception& e)
1312 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1313 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1314 <<
"Have you configured the state machine properly?\n\n"
1315 << e.what() << __E__;
1325 const std::string& username)
1327 __SUP_COUT__ <<
"@@@@@@@ MacroMaker wants to read data @@@@@@@@" << __E__;
1338 __SUP_COUT__ <<
"Read Address: " << Address << __E__;
1339 __SUP_COUTV__(interfaces);
1348 __SUP_COUT__ <<
"Here comes the array from multiselect box for READ, behold: "
1349 << supervisorIndexArray <<
"," << interfaceIndexArray << __E__;
1353 std::vector<std::string> interfaceIndices;
1354 std::istringstream f(interfaceIndexArray);
1356 while(getline(f, s,
','))
1357 interfaceIndices.push_back(s);
1358 std::vector<int> supervisorIndices;
1359 std::istringstream g(supervisorIndexArray);
1361 while(getline(g, t,
','))
1362 supervisorIndices.push_back(std::stoi(t));
1364 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
1366 unsigned int FESupervisorIndex = supervisorIndices[i];
1367 std::string interfaceIndex = interfaceIndices[i];
1369 txParameters.
addParameter(
"InterfaceID", interfaceIndex);
1371 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
1373 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
1375 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1376 if(it == allFESupervisorInfo_.end())
1378 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1379 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
1380 <<
"The FE Index doesn't exist. Have you configured the state "
1388 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
1389 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1391 __SUP_COUT__ <<
"Response received: " << SOAPUtilities::translate(retMsg)
1396 SOAPUtilities::receive(retMsg, rxParameters);
1398 std::string error = rxParameters.getValue(
"Error");
1399 __SUP_COUTV__(error);
1404 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1405 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1406 <<
"Have you configured the state machine properly?\n\n"
1411 catch(
const xdaq::exception::Exception& e)
1413 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1414 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1415 <<
"Have you configured the state machine properly?\n\n"
1416 << e.what() << __E__;
1420 std::string dataReadResult = rxParameters.getValue(
"dataResult");
1421 __SUP_COUT__ <<
"Data reading result received: " << dataReadResult << __E__;
1422 xmldoc.addTextElementToData(
"readData", dataReadResult);
1423 std::string command =
"r:" + Address +
":" + dataReadResult;
1424 std::string format = addressFormatStr +
":" + dataFormatStr;
1425 appendCommandToHistory(command, format, time, interfaces, username);
1432 const std::string& username)
1434 __SUP_COUT__ <<
"MacroMaker wants to create a macro!!!!!!!!!" << __E__;
1443 __SUP_COUTV__(Name);
1444 __SUP_COUTV__(Sequence);
1445 __SUP_COUTV__(Notes);
1446 __SUP_COUTV__(Time);
1447 __SUP_COUTV__(isMacroPublic);
1448 __SUP_COUTV__(isMacroLSBF);
1450 __SUP_COUTV__(MACROS_DB_PATH);
1452 std::string fileName = Name +
".dat";
1453 std::string fullPath;
1454 if(isMacroPublic ==
"true")
1455 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
1457 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
1459 __SUP_COUTV__(fullPath);
1461 std::ofstream macrofile(fullPath.c_str());
1462 if(macrofile.is_open())
1465 macrofile <<
"\"name\":\"" << Name <<
"\",\n";
1466 macrofile <<
"\"sequence\":\"" << Sequence <<
"\",\n";
1467 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
1468 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
1469 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
1470 macrofile <<
"}@" << __E__;
1475 __SUP_SS__ <<
"Unable to open file" << __E__;
1488 void MacroMakerSupervisor::loadMacro(
const std::string& macroName,
1489 std::string& macroString,
1490 const std::string& username )
1492 __SUP_COUTV__(macroName);
1495 std::string fullPath, line;
1497 for(
unsigned int i = 0; i < 2; ++i)
1500 fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1502 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1504 fullPath += macroName;
1505 if(macroName.find(
".dat") != macroName.size() - 4)
1507 __SUP_COUTV__(fullPath);
1509 std::ifstream read(fullPath.c_str());
1514 getline(read, line);
1515 macroString += line;
1522 __SUP_COUT__ <<
"Unable to open file: " << fullPath << __E__;
1526 if(macroString !=
"")
1530 if(macroString ==
"")
1532 __SUP_SS__ <<
"Unable to locate file for macro '" << macroName
1533 <<
"'... does it exist?" << __E__;
1535 ss <<
" Attempted username was '" << username <<
".'" << __E__;
1539 __SUP_COUTV__(macroString);
1543 void MacroMakerSupervisor::loadMacroNames(
1544 const std::string& username,
1545 std::pair<std::vector<std::string> ,
1546 std::vector<std::string> >& returnMacroNames)
1550 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1551 if((dir = opendir(fullPath.c_str())) != NULL)
1554 while((ent = readdir(dir)) != NULL)
1557 if((
unsigned)strlen(ent->d_name) > 4)
1561 ((fullPath + (std::string)ent->d_name)).c_str());
1566 returnMacroNames.second.push_back(ent->d_name);
1569 __SUP_COUT__ <<
"Unable to open file" << __E__;
1576 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1579 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1580 if((dir = opendir(fullPath.c_str())) != NULL)
1583 while((ent = readdir(dir)) != NULL)
1586 if((
unsigned)strlen(ent->d_name) > 4)
1590 ((fullPath + (std::string)ent->d_name)).c_str());
1594 returnMacroNames.first.push_back(ent->d_name);
1598 __SUP_COUT__ <<
"Unable to open file" << __E__;
1605 __SUP_COUT__ << fullPath << __E__;
1606 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1614 const std::string& username)
1618 std::string returnStr =
"";
1619 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1620 if((dir = opendir(fullPath.c_str())) != NULL)
1623 while((ent = readdir(dir)) != NULL)
1626 if((
unsigned)strlen(ent->d_name) > 4)
1630 ((fullPath + (std::string)ent->d_name)).c_str());
1633 std::stringstream buffer;
1636 getline(read, line);
1640 returnStr += buffer.str();
1645 __SUP_COUT__ <<
"Unable to open file" << __E__;
1648 std::string returnMacroStr = returnStr.substr(0, returnStr.size() - 1);
1650 __SUP_COUT__ <<
"Loading existing macros! " << returnMacroStr << __E__;
1653 xmldoc.addTextElementToData(
"returnMacroStr", returnMacroStr);
1657 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1660 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1662 if((dir = opendir(fullPath.c_str())) != NULL)
1665 while((ent = readdir(dir)) != NULL)
1668 if((
unsigned)strlen(ent->d_name) > 4)
1672 ((fullPath + (std::string)ent->d_name)).c_str());
1675 std::stringstream buffer;
1678 getline(read, line);
1682 returnStr += buffer.str();
1686 __SUP_COUT__ <<
"Unable to open file" << __E__;
1689 std::string returnPublicStr = returnStr.substr(0, returnStr.size() - 1);
1690 __SUP_COUT__ <<
"Loading existing public macros: " << returnPublicStr << __E__;
1692 xmldoc.addTextElementToData(
"returnPublicStr", returnPublicStr);
1696 __SUP_COUT__ << fullPath << __E__;
1697 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1703 void MacroMakerSupervisor::appendCommandToHistory(std::string Command,
1706 std::string Interfaces,
1707 const std::string& username)
1709 std::string fileName =
"history.hist";
1710 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1711 __SUP_COUT__ << fullPath << __E__;
1712 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1713 if(histfile.is_open())
1716 histfile <<
"\"Command\":\"" << Command <<
"\",\n";
1717 histfile <<
"\"Format\":\"" << Format <<
"\",\n";
1718 histfile <<
"\"Time\":\"" << Time <<
"\",\n";
1719 histfile <<
"\"Interfaces\":\"" << Interfaces <<
"\"\n";
1720 histfile <<
"}#" << __E__;
1725 __SUP_SS__ <<
"Unable to open history.hist at " << fullPath << __E__;
1731 void MacroMakerSupervisor::appendCommandToHistory(std::string feClass,
1733 std::string macroType,
1734 std::string macroName,
1735 std::string inputArgs,
1736 std::string outputArgs,
1738 const std::string& username)
1741 auto feHistoryIt = lastFeCommandToHistory_.find(username);
1742 if(feHistoryIt != lastFeCommandToHistory_.end() && feHistoryIt->second.size() == 7 &&
1743 feHistoryIt->second[0] == feClass && feHistoryIt->second[1] == feUID &&
1744 feHistoryIt->second[2] == macroType && feHistoryIt->second[3] == macroName &&
1745 feHistoryIt->second[4] == inputArgs && feHistoryIt->second[5] == outputArgs &&
1746 feHistoryIt->second[6] == (saveOutputs ?
"1" :
"0"))
1748 __SUP_COUTT__ <<
"Not saving repeat command to history from user " << username
1753 std::string fileName =
"FEhistory.hist";
1754 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1755 __SUP_COUT__ << fullPath << __E__;
1756 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1757 if(histfile.is_open())
1760 histfile <<
"\"feClass\":\"" << feClass <<
"\",\n";
1761 histfile <<
"\"feUID\":\"" << feUID <<
"\",\n";
1762 histfile <<
"\"macroType\":\"" << macroType <<
"\",\n";
1763 histfile <<
"\"macroName\":\"" << macroName <<
"\",\n";
1764 histfile <<
"\"inputArgs\":\"" << inputArgs <<
"\",\n";
1765 histfile <<
"\"outputArgs\":\"" << outputArgs <<
"\",\n";
1767 histfile <<
"\"saveOutputs\":\"" << 1 <<
"\"\n";
1769 histfile <<
"\"saveOutputs\":\"" << 0 <<
"\"\n";
1770 histfile <<
"}#" << __E__;
1773 lastFeCommandToHistory_[username].clear();
1774 feHistoryIt = lastFeCommandToHistory_.find(username);
1775 feHistoryIt->second.push_back(feClass);
1776 feHistoryIt->second.push_back(feUID);
1777 feHistoryIt->second.push_back(macroType);
1778 feHistoryIt->second.push_back(macroName);
1779 feHistoryIt->second.push_back(inputArgs);
1780 feHistoryIt->second.push_back(outputArgs);
1781 feHistoryIt->second.push_back((saveOutputs ?
"1" :
"0"));
1785 __SUP_SS__ <<
"Unable to open FEhistory.hist at " << fullPath << __E__;
1792 void MacroMakerSupervisor::loadFEMacroSequences(
HttpXmlDocument& xmldoc,
1793 const std::string& username)
1795 __SUP_COUT__ <<
"loadFEMacroSequences for " << username << __E__;
1798 std::string fullPath = (std::string)MACROS_SEQUENCE_PATH + username +
"/";
1799 std::string sequences =
"";
1800 __SUP_COUTV__(fullPath);
1801 if((dir = opendir(fullPath.c_str())) != NULL)
1804 while((ent = readdir(dir)) != NULL)
1808 ((fullPath + (std::string)ent->d_name)).c_str());
1812 sequences += ent->d_name + std::string(
";");
1815 __SUP_COUT__ <<
"Unable to open file" << __E__;
1821 __SUP_COUT__ <<
"Looping through MacroSequence/" + username +
1822 " folder failed! Invalid directory."
1826 if(username == WebUsers::DEFAULT_ADMIN_USERNAME)
1829 xmldoc.addTextElementToData(
"FEsequences", sequences);
1834 fullPath = (std::string)MACROS_SEQUENCE_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
"/";
1836 if((dir = opendir(fullPath.c_str())) != NULL)
1839 while((ent = readdir(dir)) != NULL)
1843 ((fullPath + (std::string)ent->d_name)).c_str());
1847 sequences += std::string(
"public/") + ent->d_name + std::string(
";");
1850 __SUP_COUT__ <<
"Unable to open file" << __E__;
1856 __SUP_COUT__ <<
"Looping through MacroSequence/" +
1857 WebUsers::DEFAULT_ADMIN_USERNAME +
1858 " folder failed! Invalid directory."
1863 xmldoc.addTextElementToData(
"FEsequences", sequences);
1867 void MacroMakerSupervisor::saveFEMacroSequence(cgicc::Cgicc& cgi,
1868 const std::string& username)
1873 std::string FEsequence =
1875 bool overwrite = CgiDataUtilities::getDataAsInt(cgi,
"overwrite");
1877 __SUP_COUTV__(overwrite);
1878 __SUP_COUTV__(name);
1879 __SUP_COUTV__(FEsequence);
1882 std::string fixedName =
"";
1883 for(
size_t i = 0; i < name.size(); ++i)
1884 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
1885 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
1886 (name[i] >=
'a' && name[i] <=
'z')))
1889 <<
"Illegal character in Sequence name (position " << i
1890 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
1895 fixedName += name[i];
1896 __SUP_COUTV__(fixedName);
1898 std::string fullPath =
1899 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
1900 __SUP_COUTV__(fullPath);
1903 if(!overwrite && std::filesystem::exists(fullPath))
1905 __SUP_SS__ <<
"Please choose another Sequence name! A sequence with the same "
1906 "resulting filename already exists at "
1907 << fullPath << __E__;
1911 std::ofstream seqfile(fullPath.c_str());
1912 if(seqfile.is_open())
1914 seqfile << FEsequence << __E__;
1919 __SUP_SS__ <<
"Unable to open file to save FE Macro Sequence at " << fullPath
1926 void MacroMakerSupervisor::getFEMacroSequence(
HttpXmlDocument& xmldoc,
1928 const std::string& username)
1932 __SUP_COUTV__(name);
1934 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
1935 __SUP_COUTV__(isPublic);
1938 std::string fixedName =
"";
1939 for(
size_t i = (isPublic ? std::string(
"public/").size() : 0); i < name.size(); ++i)
1940 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
1941 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
1942 (name[i] >=
'a' && name[i] <=
'z')))
1944 __COUT__ <<
"Illegal character in Sequence name (position " << i
1945 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
1949 fixedName += name[i];
1950 __SUP_COUTV__(fixedName);
1953 std::string fullPath =
1954 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
1955 __SUP_COUT__ << fullPath << __E__;
1957 std::ifstream read(fullPath.c_str());
1959 unsigned long long fileSize;
1961 if(!isPublic && read.is_open())
1963 read.seekg(0, std::ios::end);
1964 fileSize = read.tellg();
1965 response =
new char[fileSize + 1];
1966 response[fileSize] =
'\0';
1967 read.seekg(0, std::ios::beg);
1970 read.read(response, fileSize);
1973 xmldoc.addTextElementToData(
"FEsequence", &response[0]);
1980 __SUP_COUT__ <<
"Unable to open " << fullPath <<
"! Trying public area..."
1984 std::string publicFullPath = (std::string)MACROS_SEQUENCE_PATH +
1985 WebUsers::DEFAULT_ADMIN_USERNAME +
"/" + fixedName +
1987 __SUP_COUT__ << publicFullPath << __E__;
1989 std::ifstream read(publicFullPath.c_str());
1991 unsigned long long fileSize;
1995 read.seekg(0, std::ios::end);
1996 fileSize = read.tellg();
1997 response =
new char[fileSize + 1];
1998 response[fileSize] =
'\0';
1999 read.seekg(0, std::ios::beg);
2002 read.read(response, fileSize);
2005 xmldoc.addTextElementToData(
"FEsequence", &response[0]);
2011 __SUP_SS__ <<
"Unable to open FE Macro Sequence at " << fullPath <<
" or "
2012 << publicFullPath << __E__;
2019 void MacroMakerSupervisor::deleteFEMacroSequence(cgicc::Cgicc& cgi,
2020 const std::string& username)
2024 __SUP_COUTV__(name);
2026 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
2027 __SUP_COUTV__(isPublic);
2030 std::string fixedName =
"";
2031 for(
size_t i = (isPublic ? std::string(
"public/").size() : 0); i < name.size(); ++i)
2032 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
2033 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
2034 (name[i] >=
'a' && name[i] <=
'z')))
2036 __COUT__ <<
"Illegal character in Sequence name (position " << i
2037 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2041 fixedName += name[i];
2042 __SUP_COUTV__(fixedName);
2045 std::string fullPath =
2046 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2048 fullPath = (std::string)MACROS_SEQUENCE_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
2049 "/" + fixedName +
".dat";
2050 __SUP_COUT__ << fullPath << __E__;
2053 if(!std::filesystem::exists(fullPath))
2056 <<
"The specified Sequence name does not exist! Looking for sequence file at "
2057 << fullPath << __E__;
2061 std::remove(fullPath.c_str());
2062 __SUP_COUT__ <<
"Successfully deleted " << fullPath << __E__;
2066 void MacroMakerSupervisor::makeSequencePublic(cgicc::Cgicc& cgi,
2067 const std::string& username)
2071 __SUP_COUTV__(name);
2073 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
2074 __SUP_COUTV__(isPublic);
2077 __SUP_SS__ <<
"The specified Sequence name is already designated as public."
2083 std::string fixedName =
"";
2084 for(
size_t i = 0; i < name.size(); ++i)
2085 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
2086 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
2087 (name[i] >=
'a' && name[i] <=
'z')))
2089 __COUT__ <<
"Illegal character in Sequence name (position " << i
2090 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2094 fixedName += name[i];
2095 __SUP_COUTV__(fixedName);
2098 std::string source =
2099 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2100 __SUP_COUT__ << source << __E__;
2101 std::string destination = (std::string)MACROS_SEQUENCE_PATH +
2102 WebUsers::DEFAULT_ADMIN_USERNAME +
"/" + fixedName +
".dat";
2103 __SUP_COUT__ << destination << __E__;
2105 if(std::filesystem::exists(destination))
2107 __SUP_SS__ <<
"The sequence name '" << fixedName
2108 <<
"' already exists in the admin/public location: " << destination
2114 std::filesystem::copy_file(
2115 source, destination, std::filesystem::copy_options::skip_existing);
2116 __SUP_COUT__ <<
"Successfully made " << fixedName
2117 <<
" public at path: " << destination << __E__;
2122 const std::string& username)
2124 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"history.hist";
2126 std::ifstream read(fileName.c_str());
2127 __SUP_COUT__ << fileName << __E__;
2133 unsigned long long fileSz, i = 0, MAX_HISTORY_SIZE = 100000;
2137 read.seekg(0, std::ios::end);
2138 fileSz = read.tellg();
2139 returnStr =
new char[fileSz + 1];
2140 returnStr[fileSz] =
'\0';
2141 read.seekg(0, std::ios::beg);
2144 read.read(returnStr, fileSz);
2148 if(fileSz > MAX_HISTORY_SIZE)
2150 i = fileSz - MAX_HISTORY_SIZE;
2151 for(; i < fileSz; ++i)
2152 if(returnStr[i] ==
'#')
2161 FILE* fp = fopen(fileName.c_str(),
"w");
2165 __SS__ <<
"Big problem with macromaker history file: " << fileName
2169 fwrite(&returnStr[i], fileSz - i, 1, fp);
2173 __SUP_COUT__ <<
"Loading user history! " << __E__;
2176 returnStr[fileSz - 2] =
'\0';
2178 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
2183 __SUP_COUT__ <<
"Unable to open history.hist" << __E__;
2189 const std::string& username)
2191 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"FEhistory.hist";
2193 std::ifstream read(fileName.c_str());
2194 __SUP_COUT__ << fileName << __E__;
2196 if(!read.is_open() && username != WebUsers::DEFAULT_ADMIN_USERNAME)
2198 __SUP_COUT__ <<
"Unable to open FE history.hist.. Defaulting to admin's FE "
2199 "history as starting point."
2203 MACROS_HIST_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
"/" +
"FEhistory.hist";
2204 read.open(fileName.c_str());
2211 unsigned long long fileSize;
2212 unsigned long long i = 0;
2213 unsigned long long MAX_HISTORY_SIZE = 100000;
2216 read.seekg(0, std::ios::end);
2217 fileSize = read.tellg();
2218 returnStr =
new char[fileSize + 1];
2219 returnStr[fileSize] =
'\0';
2220 read.seekg(0, std::ios::beg);
2223 read.read(returnStr, fileSize);
2227 if(fileSize > MAX_HISTORY_SIZE)
2229 i = fileSize - MAX_HISTORY_SIZE;
2230 for(; i < fileSize; ++i)
2232 if(returnStr[i] ==
'#')
2242 FILE* fp = fopen(fileName.c_str(),
"w");
2246 __SS__ <<
"Big problem with FE history file: " << fileName << __E__;
2249 fwrite(&returnStr[i], fileSize - i, 1, fp);
2253 __SUP_COUT__ <<
"Loading user history! " << __E__;
2256 returnStr[fileSize - 2] =
'\0';
2258 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
2263 __SUP_COUT__ <<
"Unable to open FE history.hist" << __E__;
2270 const std::string& username)
2275 std::string fileName = MacroName +
".dat";
2276 std::string fullPath;
2277 if(isMacroPublic ==
"true")
2278 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
2280 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
2282 __SUP_COUT__ << fullPath << __E__;
2284 std::remove(fullPath.c_str());
2285 __SUP_COUT__ <<
"Successfully deleted " << MacroName;
2286 xmldoc.addTextElementToData(
"deletedMacroName", MacroName);
2292 const std::string& username)
2304 __SUP_COUTV__(oldMacroName);
2305 __SUP_COUTV__(newMacroName);
2306 __SUP_COUTV__(FESequence);
2307 __SUP_COUTV__(Notes);
2308 __SUP_COUTV__(Time);
2309 __SUP_COUTV__(isMacroPublic);
2310 __SUP_COUTV__(isMacroLSBF);
2312 __SUP_COUTV__(MACROS_DB_PATH);
2314 std::string fileName = oldMacroName +
".dat";
2315 std::string fullPath;
2316 if(isMacroPublic ==
"true")
2317 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
2319 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
2321 __SUP_COUTV__(fullPath);
2323 std::ofstream macrofile(fullPath.c_str());
2324 if(macrofile.is_open())
2327 macrofile <<
"\"name\":\"" << newMacroName <<
"\",\n";
2328 macrofile <<
"\"FEsequence\":\"" << FESequence <<
"\",\n";
2329 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
2330 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
2331 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
2332 macrofile <<
"}@" << __E__;
2336 __SUP_COUT__ <<
"Unable to open file" << __E__;
2338 if(oldMacroName != newMacroName)
2342 rename((MACROS_DB_PATH + username +
"/" + oldMacroName +
".dat").c_str(),
2343 (MACROS_DB_PATH + username +
"/" + newMacroName +
".dat").c_str());
2345 xmldoc.addTextElementToData(
"newMacroName", newMacroName);
2347 xmldoc.addTextElementToData(
"newMacroName",
"ERROR");
2352 void MacroMakerSupervisor::clearHistory(
const std::string& username)
2354 std::string fileName =
"history.hist";
2355 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
2357 std::remove(fullPath.c_str());
2358 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
2362 void MacroMakerSupervisor::clearFEHistory(
const std::string& username)
2364 std::string fileName =
"FEhistory.hist";
2365 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
2367 std::remove(fullPath.c_str());
2368 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
2374 const std::string& username)
2379 std::string macroNotes =
2382 __SUP_COUTV__(pluginName);
2383 __SUP_COUTV__(macroName);
2384 __SUP_COUTV__(macroSequence);
2387 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
2388 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
2389 macroNotes[i] =
' ';
2390 __SUP_COUTV__(macroNotes);
2392 std::stringstream ss(macroSequence);
2393 std::string command;
2394 std::vector<std::string> commands;
2396 while(getline(ss, command,
','))
2397 commands.push_back(command);
2401 std::map<std::string , std::set<std::string> >
2402 specialsCodeMap = CodeEditor::getSpecialsMap();
2405 auto specialsCodeMapIt = specialsCodeMap.find(CodeEditor::SPECIAL_TYPE_FEInterface);
2406 if(specialsCodeMapIt == specialsCodeMap.end())
2409 <<
"Could not find any FE Interface plugins in source code. Does MacroMaker "
2410 <<
"have access to the source code? Check that the Supervisor context places "
2412 <<
"location with access to the source code." << __E__;
2417 std::string headerFile = pluginName +
".h";
2418 std::string sourceFile = pluginName +
"_interface.cc";
2419 bool foundHeaderFile =
false;
2420 bool foundSourceFile =
false;
2421 for(
const auto& filePath : specialsCodeMapIt->second)
2423 if(!foundHeaderFile && filePath.find(headerFile) != std::string::npos)
2425 foundHeaderFile =
true;
2426 headerFile = filePath;
2427 __SUP_COUT__ <<
"found headerFile=" << filePath << __E__;
2429 if(!foundSourceFile && filePath.find(sourceFile) != std::string::npos)
2431 foundSourceFile =
true;
2432 sourceFile = filePath;
2433 __SUP_COUT__ <<
"found sourceFile=" << filePath << __E__;
2436 if(foundSourceFile && foundHeaderFile)
2440 if(!foundHeaderFile)
2442 __SS__ <<
"Could not find the header file for the FE Interface plugins at '"
2443 << headerFile <<
".' Does MacroMaker "
2444 <<
"have access to the source code? Check that the Supervisor context "
2445 "places MacroMaker in a "
2446 <<
"location with access to the source code." << __E__;
2449 if(!foundSourceFile)
2451 __SS__ <<
"Could not find the source file for the FE Interface plugins at '"
2452 << sourceFile <<
".' Does MacroMaker "
2453 <<
"have access to the source code? Check that the Supervisor context "
2454 "places MacroMaker in a "
2455 <<
"location with access to the source code." << __E__;
2468 char timeBuffer[100];
2471 struct tm* timeinfo;
2474 timeinfo = localtime(&rawtime);
2476 strftime(timeBuffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
2479 std::string contents;
2484 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, sourceFile, contents);
2488 xmldoc.addTextElementToData(
"sourceFile", sourceFile);
2489 xmldoc.addTextElementToData(
"headerFile", headerFile);
2492 if(contents.find(pluginName +
"::" + macroName) != std::string::npos)
2494 __SS__ <<
"The function definition '" << (pluginName +
"::" + macroName)
2495 <<
"(...)' already exists in the source file '" << sourceFile
2496 <<
".' Duplicate functions are not allowed - please rename the macro or "
2497 "modify the source file."
2502 std::stringstream codess;
2503 std::set<std::string> inArgNames, outArgNames;
2515 auto insertPos = contents.find(pluginName +
"::" + pluginName);
2516 if(insertPos == std::string::npos)
2518 __SS__ <<
"Could not find the code insert position in the source file '"
2519 << sourceFile <<
".' The FE plugin class constructor must be '"
2520 << pluginName <<
":" << pluginName <<
"' - is this the case?" << __E__;
2523 __SUP_COUTV__(insertPos);
2525 insertPos = contents.find(
"{", insertPos);
2526 if(insertPos == std::string::npos)
2528 __SS__ <<
"Could not find the code insert position in the source file '"
2530 <<
".' The FE plugin class constructor must begin with '{"
2531 <<
"' - is this the case?" << __E__;
2535 __SUP_COUTV__(insertPos);
2537 insert =
"\n\t//registration of FEMacro '" + macroName +
"' generated, " +
2538 timeBuffer +
", by '" + username +
"' using MacroMaker.\n\t" +
2539 "FEVInterface::registerFEMacroFunction(\"" + macroName +
2540 "\",//feMacroName \n\t\t" +
2541 "static_cast<FEVInterface::frontEndMacroFunction_t>(&" + pluginName +
2542 "::" + macroName +
"), //feMacroFunction \n\t\t" +
2543 "std::vector<std::string>{";
2546 for(
const auto& inArg : inArgNames)
2552 insert +=
"\"" + inArg +
"\"";
2555 insert +=
"}, //namesOfInputArgs \n\t\t";
2556 insert +=
"std::vector<std::string>{";
2559 for(
const auto& outArg : outArgNames)
2565 insert +=
"\"" + outArg +
"\"";
2568 insert +=
"}, //namesOfOutputArgs \n\t\t";
2569 insert +=
"1); //requiredUserPermissions \n\n";
2571 __SUP_COUTV__(insert);
2572 contents = contents.substr(0, insertPos) + insert + contents.substr(insertPos);
2577 auto insertPos = contents.rfind(
"DEFINE_OTS_INTERFACE");
2578 if(insertPos == std::string::npos)
2580 __SS__ <<
"Could not find the code insert position in the source file '"
2582 <<
".' The FE plugin class must end with a 'DEFINE_OTS_INTERFACE("
2583 << pluginName <<
")' - is this the case?" << __E__;
2586 __SUP_COUTV__(insertPos);
2590 "============================================================================"
2591 "============================================\n//" +
2592 macroName +
"\n" +
"//\tFEMacro '" + macroName +
"' generated, " +
2593 timeBuffer +
", by '" + username +
"' using MacroMaker.\n" +
2594 "//\tMacro Notes: " + macroNotes +
"\n" +
"void " + pluginName +
2595 "::" + macroName +
"(__ARGS__)\n{\n\t" +
2596 "__CFG_COUT__ << \"# of input args = \" << argsIn.size() << __E__; \n\t" +
2597 "__CFG_COUT__ << \"# of output args = \" << argsOut.size() << __E__; \n\t" +
2598 "for(auto &argIn:argsIn) \n\t\t" +
2599 "__CFG_COUT__ << argIn.first << \": \" << argIn.second << __E__; \n\n\t" +
2600 "//macro commands section \n" + codess.str() +
"\n\n\t" +
2601 "for(auto &argOut:argsOut) \n\t\t" +
2602 "__CFG_COUT__ << argOut.first << \": \" << argOut.second << __E__; \n\n" +
2603 "} //end " + macroName +
"()\n\n";
2606 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
2609 "MacroMaker-" + username,
2616 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, headerFile, contents);
2621 auto insertPos = contents.rfind(
"};");
2622 if(insertPos == std::string::npos)
2624 __SS__ <<
"Could not find the code insert position in the header file '"
2626 <<
".' The FE plugin class must end with a '};' - is this the case?"
2631 __SUP_COUTV__(insertPos);
2633 insert =
"\npublic: // FEMacro '" + macroName +
"' generated, " + timeBuffer +
2634 ", by '" + username +
"' using MacroMaker.\n\t" +
"void " + macroName +
2637 __SUP_COUTV__(insert);
2638 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
2641 "MacroMaker-" + username,
2651 const std::string& username)
2655 std::string macroNotes =
2658 __SUP_COUTV__(macroName);
2659 __SUP_COUTV__(macroSequence);
2662 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
2663 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
2664 macroNotes[i] =
' ';
2665 __SUP_COUTV__(macroNotes);
2667 std::stringstream ss(macroSequence);
2668 std::string command;
2669 std::vector<std::string> commands;
2671 while(getline(ss, command,
','))
2672 commands.push_back(command);
2674 std::string fileName = macroName +
".cc";
2676 std::string fullPath =
2677 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + username +
"/" + fileName;
2678 __SUP_COUT__ << fullPath << __E__;
2679 std::ofstream exportFile(fullPath.c_str(), std::ios::trunc);
2680 if(exportFile.is_open())
2682 exportFile <<
"//Generated Macro Name:\t" << macroName <<
"\n";
2683 exportFile <<
"//Macro Notes: " << macroNotes <<
"\n";
2687 struct tm* timeinfo;
2691 timeinfo = localtime(&rawtime);
2693 strftime(buffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
2694 exportFile <<
"//Generated Time: \t\t" << buffer <<
"\n";
2697 exportFile <<
"//Paste this whole file into an interface to transfer Macro "
2700 createCode(exportFile, commands);
2704 xmldoc.addTextElementToData(
2706 "$USER_DATA/ServiceData/" + MACROS_EXPORT_PATH + username +
"/" + fileName);
2709 __SUP_COUT__ <<
"Unable to open file" << __E__;
2714 void MacroMakerSupervisor::createCode(std::ostream& out,
2715 const std::vector<std::string>& commands,
2716 const std::string& tabOffset,
2718 std::set<std::string>* inArgNames,
2719 std::set<std::string>* outArgNames)
2722 std::set<std::string > argInHasBeenInitializedSet;
2723 bool addressIsVariable, dataIsVariable;
2725 out << tabOffset <<
"{";
2728 << tabOffset <<
"\t"
2729 <<
"char *address \t= new char[universalAddressSize_]{0}; //create address "
2730 "buffer of interface size and init to all 0";
2732 << tabOffset <<
"\t"
2733 <<
"char *data \t\t= new char[universalDataSize_]{0}; //create data buffer "
2734 "of interface size and init to all 0";
2737 << tabOffset <<
"\t"
2738 <<
"uint64_t macroAddress; //create macro address buffer (size 8 bytes)";
2740 << tabOffset <<
"\t"
2741 <<
"uint64_t macroData; //create macro address buffer (size 8 bytes)";
2744 << tabOffset <<
"\t"
2745 <<
"std::map<std::string /*arg name*/,uint64_t /*arg val*/> macroArgs; //create "
2746 "map from arg name to 64-bit number";
2749 for(
unsigned int i = 0; i < commands.size(); i++)
2751 std::stringstream sst(commands[i]);
2753 std::vector<std::string>
2755 while(getline(sst, tokens,
':'))
2756 oneCommand.push_back(tokens);
2757 while(oneCommand.size() < 4)
2758 oneCommand.push_back(
"");
2786 addressIsVariable = isArgumentVariable(oneCommand[2]);
2787 dataIsVariable = isArgumentVariable(oneCommand[3]);
2789 __SUP_COUTV__(addressIsVariable);
2790 __SUP_COUTV__(dataIsVariable);
2792 out <<
"\n\n" << tabOffset <<
"\t// command-#" << i <<
": ";
2794 if(oneCommand[1][0] ==
'w' || oneCommand[1][0] ==
'r')
2796 if(oneCommand[1][0] ==
'w')
2798 else if(oneCommand[1][0] ==
'r')
2801 if(addressIsVariable)
2802 out << oneCommand[2];
2804 out <<
"0x" << oneCommand[2];
2805 out <<
" /*address*/,";
2809 out << oneCommand[3] <<
" /*data*/";
2810 else if(oneCommand[1][0] ==
'w')
2811 out <<
"0x" << oneCommand[3] <<
" /*data*/";
2812 else if(oneCommand[1][0] ==
'r')
2816 else if(oneCommand[1][0] ==
'd')
2818 out <<
"delay(" << oneCommand[2] <<
");\n";
2819 out << tabOffset <<
"\t"
2820 <<
"__CFG_COUT__ << \"Sleeping for... \" << " << oneCommand[2]
2821 <<
" << \" milliseconds \" << __E__;\n";
2822 out << tabOffset <<
"\t"
2823 <<
"usleep(" << oneCommand[2] <<
"*1000 /* microseconds */);\n";
2828 __SS__ <<
"FATAL ERROR: Unknown command '" << oneCommand[1]
2829 <<
"'... command is not w, r or d" << __E__;
2835 if(addressIsVariable)
2837 if(argInHasBeenInitializedSet.find(oneCommand[2]) ==
2838 argInHasBeenInitializedSet.end())
2840 argInHasBeenInitializedSet.emplace(oneCommand[2]);
2845 out << tabOffset <<
"\t"
2846 <<
"macroArgs[\"" << oneCommand[2]
2848 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2851 << tabOffset <<
"\t\t\"" << oneCommand[2]
2852 <<
"\").getValue<uint64_t>();";
2857 inArgNames->emplace(oneCommand[2]);
2860 out << tabOffset <<
"\t"
2861 <<
"macroArgs[\"" << oneCommand[2] <<
"\"] = __GET_ARG_IN__(\""
2862 << oneCommand[2] <<
"\", uint64_t);";
2865 out <<
"\t//get macro address argument";
2867 << tabOffset <<
"\tmemcpy(address,¯oArgs[\"" << oneCommand[2]
2868 <<
"\"],8); //copy macro address argument to buffer";
2872 out << tabOffset <<
"\t"
2873 <<
"macroAddress = 0x" << oneCommand[2]
2874 <<
"; memcpy(address,¯oAddress,8);"
2875 <<
"\t//copy macro address to buffer";
2880 if(oneCommand[1] ==
"w")
2884 if(argInHasBeenInitializedSet.find(oneCommand[3]) ==
2885 argInHasBeenInitializedSet
2888 argInHasBeenInitializedSet.emplace(oneCommand[3]);
2893 inArgNames->emplace(oneCommand[3]);
2897 << tabOffset <<
"\t"
2898 <<
"macroArgs[\"" << oneCommand[3]
2899 <<
"\"] = __GET_ARG_IN__(\"" << oneCommand[3]
2900 <<
"\", uint64_t); //initialize from input arguments";
2906 << tabOffset <<
"\t"
2907 <<
"macroArgs[\"" << oneCommand[3]
2909 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2912 << tabOffset <<
"\t\t\"" << oneCommand[3]
2913 <<
"\").getValue<uint64_t>(); //initialize from "
2914 "configuration tree";
2917 out <<
"\t//get macro data argument";
2919 << tabOffset <<
"\tmemcpy(data,¯oArgs[\"" << oneCommand[3]
2920 <<
"\"],8); //copy macro data argument to buffer";
2925 << tabOffset <<
"\t"
2926 <<
"macroData = 0x" << oneCommand[3] <<
"; memcpy(data,¯oData,8);"
2927 <<
"\t//copy macro data to buffer";
2930 << tabOffset <<
"\t"
2931 <<
"universalWrite(address,data);";
2936 << tabOffset <<
"\t"
2937 <<
"universalRead(address,data);";
2939 std::string outputArgName;
2942 outputArgName = oneCommand[3];
2946 sprintf(str,
"outArg%d", i);
2947 outputArgName = str;
2949 __SUP_COUTV__(outputArgName);
2951 out << tabOffset <<
"\t"
2952 <<
"memcpy(¯oArgs[\"" << outputArgName
2953 <<
"\"],data,8); //copy buffer to argument map";
2958 << tabOffset <<
"\t"
2959 <<
"__SET_ARG_OUT__(\"" << outputArgName <<
"\",macroArgs[\""
2960 << outputArgName <<
"\"]); //update output argument result";
2963 outArgNames->emplace(outputArgName);
2964 argInHasBeenInitializedSet.emplace(
2969 out <<
"\n\n" << tabOffset <<
"\tdelete[] address; //free the memory";
2970 out <<
"\n" << tabOffset <<
"\tdelete[] data; //free the memory";
2971 out <<
"\n" << tabOffset <<
"}";
2973 __SUP_COUT__ <<
"Done with code generation." << __E__;
2979 bool MacroMakerSupervisor::isArgumentVariable(
const std::string& argumentString)
2981 for(
unsigned int i = 0; i < argumentString.length(); ++i)
2984 if(!((argumentString[i] >=
'0' && argumentString[i] <=
'9') ||
2985 (argumentString[i] >=
'a' && argumentString[i] <=
'f') ||
2986 (argumentString[i] >=
'A' && argumentString[i] <=
'F')))
3001 std::string MacroMakerSupervisor::generateHexArray(
const std::string& sourceHexString,
3004 std::stringstream retSs;
3006 std::string srcHexStr = sourceHexString;
3007 __SUP_COUT__ <<
"Translating: \n";
3008 __SUP_COUT__ << srcHexStr << __E__;
3010 if(srcHexStr.size() % 2)
3011 srcHexStr =
"0" + srcHexStr;
3013 numOfBytes = srcHexStr.size() / 2;
3014 retSs <<
"[" << numOfBytes <<
"] = {";
3016 for(
int i = 0; i < numOfBytes * 2; i += 2)
3019 if(!((srcHexStr[i] >=
'0' && srcHexStr[i] <=
'9') ||
3020 (srcHexStr[i] >=
'a' && srcHexStr[i] <=
'f') ||
3021 (srcHexStr[i] >=
'A' && srcHexStr[i] <=
'F')) ||
3022 !((srcHexStr[i + 1] >=
'0' && srcHexStr[i + 1] <=
'9') ||
3023 (srcHexStr[i + 1] >=
'a' && srcHexStr[i + 1] <=
'f') ||
3024 (srcHexStr[i + 1] >=
'A' && srcHexStr[i + 1] <=
'F')))
3032 retSs <<
"0x" << srcHexStr[srcHexStr.size() - 1 - i - 1]
3033 << srcHexStr[srcHexStr.size() - 1 - i];
3037 __SUP_COUT__ << retSs.str() << __E__;
3045 const WebUsers::RequestUserInfo& userInfo)
3048 __SUP_COUTT__ << __E__;
3050 uint64_t NotDoneID = CgiDataUtilities::getDataAsUint64_t(cgi,
"NotDoneID");
3053 __SUP_COUT__ <<
"Checking if recent FE macro run has completed for NotDoneID = "
3054 << NotDoneID << __E__;
3056 for(
const auto& feMacroRunThreadStruct : feMacroRunThreadStruct_)
3057 __SUP_COUTT__ <<
"[] threadID_ = "
3058 << feMacroRunThreadStruct.parameters_.threadID_ << __E__;
3060 time_t now = time(0);
3061 size_t target_i = -1;
3062 for(
size_t i = 0; i < feMacroRunThreadStruct_.size(); ++i)
3064 if(feMacroRunThreadStruct_[i].parameters_.threadID_ == NotDoneID)
3067 __SUP_COUTT__ <<
"Found NotDoneID = " << NotDoneID << __E__;
3070 else if(feMacroRunThreadStruct_[i].feMacroRunDone_ &&
3071 now - feMacroRunThreadStruct_[i].parameters_.doneTime_ >
3074 __SUP_COUTT__ <<
"Cleaning up completed NotDoneID = " << NotDoneID
3077 feMacroRunThreadStruct_.erase(feMacroRunThreadStruct_.begin() + i);
3080 else if(now - feMacroRunThreadStruct_[i].parameters_.startTime_ >
3084 <<
"Found old FE Macro exectution of '"
3085 << feMacroRunThreadStruct_[i].parameters_.macroName_ <<
"' at '"
3086 << feMacroRunThreadStruct_[i].parameters_.feUIDSelected_ <<
".'"
3092 if(target_i >= feMacroRunThreadStruct_.size())
3095 <<
"Attempted to check recent FE Macro run completion with invalid ID="
3097 <<
". Perhaps this FE Macro completed more than 5 minutes ago?" << __E__;
3101 if(feMacroRunThreadStruct_[target_i].feMacroRunDone_)
3103 __SUP_COUT__ <<
"Found done for NotDoneID = " << NotDoneID << __E__;
3104 bars_[target_i]->complete();
3106 if(feMacroRunThreadStruct_[target_i].parameters_.feMacroRunError_ !=
"")
3109 << feMacroRunThreadStruct_[target_i].parameters_.feMacroRunError_;
3115 std::ostringstream oss;
3116 feMacroRunThreadStruct_.back().parameters_.xmldoc_.outputXmlDocument(
3118 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3121 feMacroRunThreadStruct_[target_i].parameters_.xmldoc_);
3122 __SUP_COUT__ <<
"FE macro complete." << __E__;
3126 __SUP_COUT__ <<
"Found still going for NotDoneID = " << NotDoneID << __E__;
3128 xmldoc.addNumberElementToData(
"NotDoneID", NotDoneID);
3131 bars_[target_i]->step();
3132 xmldoc.addNumberElementToData(
"Progress", bars_[target_i]->read());
3139 std::string feUIDSelected =
3142 std::string macroName =
3146 bool saveOutputs = CgiDataUtilities::getDataAsInt(cgi,
"saveOutputs") == 1;
3148 __SUP_COUTTV__(feClassSelected);
3149 __SUP_COUTTV__(feUIDSelected);
3150 __SUP_COUTTV__(macroType);
3151 __SUP_COUTTV__(macroName);
3152 __SUP_COUTTV__(inputArgs);
3153 __SUP_COUTTV__(outputArgs);
3154 __SUP_COUTTV__(saveOutputs);
3155 __SUP_COUTTV__(userInfo.username_);
3158 feMacroRunThreadStruct_.emplace_back(
3185 MacroMakerSupervisor::runFEMacroThread(s, mm);
3187 &feMacroRunThreadStruct_.back(),
3190 size_t sleepTime = 10 * 1000;
3193 for(
int i = 0; i < 6; ++i)
3195 if(feMacroRunThreadStruct_.back().feMacroRunDone_)
3197 __SUP_COUTT__ <<
"FE macro marked done" << __E__;
3202 __SUP_COUTT__ <<
"FE macro not done, sleeping..." << __E__;
3204 if(sleepTime > 1000 * 1000 )
3205 sleepTime = 1000 * 1000;
3210 if(!feMacroRunThreadStruct_.back().feMacroRunDone_)
3212 if(t.get_id() == std::thread::id())
3214 __SUP_SS__ <<
"Invalid thread ID. Contact system admins!" << __E__;
3217 feMacroRunThreadStruct_.back().parameters_.threadID_ =
3218 std::hash<std::thread::id>{}(t.get_id());
3220 if(feMacroRunThreadStruct_.back().parameters_.threadID_ == 0)
3222 __SUP_SS__ <<
"Invalid thread ID hash. Contact system admins!" << __E__;
3226 __SUP_COUT__ <<
"FE macro not done, detaching thread="
3227 << feMacroRunThreadStruct_.back().parameters_.threadID_ << __E__;
3231 auto bar = std::make_unique<ProgressBar>();
3232 bar->reset(macroName, feUIDSelected);
3233 bars_.push_back(std::move(bar));
3235 xmldoc.addNumberElementToData(
3236 "NotDoneID", feMacroRunThreadStruct_.back().parameters_.threadID_);
3240 std::ostringstream oss;
3242 &oss,
false ,
true );
3243 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3248 __SUP_COUTT__ <<
"FE macro marked done - joining threads." << __E__;
3250 if(feMacroRunThreadStruct_.back().parameters_.feMacroRunError_ !=
"")
3252 __SUP_SS__ << feMacroRunThreadStruct_.back().parameters_.feMacroRunError_;
3258 std::ostringstream oss;
3259 feMacroRunThreadStruct_.back().parameters_.xmldoc_.outputXmlDocument(
3260 &oss,
false ,
true );
3261 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3263 xmldoc.
copyDataChildren(feMacroRunThreadStruct_.back().parameters_.xmldoc_);
3267 std::ostringstream oss;
3269 &oss,
false ,
true );
3270 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3273 feMacroRunThreadStruct_.pop_back();
3274 __SUP_COUT__ <<
"FE macro complete." << __E__;
3276 for(
const auto& feMacroRunThreadStruct : feMacroRunThreadStruct_)
3277 __SUP_COUTT__ <<
"[] threadID_ = " << feMacroRunThreadStruct.parameters_.threadID_
3281 catch(
const std::runtime_error& e)
3283 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
3284 __SUP_COUT_ERR__ << ss.str();
3285 xmldoc.addTextElementToData(
"Error", ss.str());
3289 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
3294 catch(
const std::exception& e)
3296 ss <<
"Exception message: " << e.what();
3301 __SUP_COUT_ERR__ << ss.str();
3303 xmldoc.addTextElementToData(
"Error", ss.str());
3308 void MacroMakerSupervisor::runFEMacroThread(runFEMacroStruct* feMacroRunThreadStruct,
3312 __COUT__ <<
"runFEMacro thread started... threadid = " << std::this_thread::get_id()
3313 <<
" " << mmSupervisor <<
" getpid()=" << getpid()
3314 <<
" gettid()=" << gettid() << __E__;
3316 mmSupervisor->runFEMacro(feMacroRunThreadStruct->parameters_.xmldoc_,
3317 feMacroRunThreadStruct->parameters_.feClassSelected_,
3318 feMacroRunThreadStruct->parameters_.feUIDSelected_,
3319 feMacroRunThreadStruct->parameters_.macroType_,
3320 feMacroRunThreadStruct->parameters_.macroName_,
3321 feMacroRunThreadStruct->parameters_.inputArgs_,
3322 feMacroRunThreadStruct->parameters_.outputArgs_,
3323 feMacroRunThreadStruct->parameters_.saveOutputs_,
3324 feMacroRunThreadStruct->parameters_.runningUsername_,
3325 feMacroRunThreadStruct->parameters_.userGroupPermissions_);
3327 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3328 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3329 __COUT__ <<
"runFEMacro thread done. threadid = " << std::this_thread::get_id()
3333 catch(
const std::runtime_error& e)
3335 __SS__ <<
"Error during runFEMacro thread: " << e.what() << __E__;
3336 __COUT_ERR__ << ss.str();
3337 feMacroRunThreadStruct->parameters_.feMacroRunError_ = ss.str();
3338 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3339 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3343 __SS__ <<
"Unknown error during runFEMacro thread." << __E__;
3348 catch(
const std::exception& e)
3350 ss <<
"Exception message: " << e.what();
3355 __COUT_ERR__ << ss.str();
3356 feMacroRunThreadStruct->parameters_.feMacroRunError_ = ss.str();
3357 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3358 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3363 std::string feClassSelected,
3364 std::string feUIDSelected,
3365 const std::string& macroType,
3366 const std::string& macroName,
3367 const std::string& inputArgs,
3368 const std::string outputArgs,
3370 const std::string& username,
3371 const std::string& userGroupPermissions)
3373 __SUP_COUTV__(feClassSelected);
3374 __SUP_COUTV__(feUIDSelected);
3375 __SUP_COUTV__(macroType);
3376 __SUP_COUTV__(macroName);
3377 __SUP_COUTV__(inputArgs);
3378 __SUP_COUTV__(outputArgs);
3379 __SUP_COUTV__(saveOutputs);
3380 __SUP_COUTV__(username);
3381 __SUP_COUTV__(userGroupPermissions);
3383 appendCommandToHistory(feClassSelected,
3392 std::set<std::string > feUIDs;
3394 if(feUIDSelected ==
"")
3395 feUIDSelected =
"*";
3396 if(feClassSelected ==
"")
3397 feClassSelected =
"*";
3399 if(feClassSelected ==
"" || feUIDSelected ==
"" || macroType ==
"" || macroName ==
"")
3401 __SUP_SS__ <<
"Illegal empty front-end parameter." << __E__;
3404 else if(feUIDSelected !=
"*")
3411 if(feClassSelected ==
"*")
3413 for(
auto& feTypePair : FEPluginTypetoFEsMap_)
3414 for(
auto& feUID : feTypePair.second)
3415 feUIDs.emplace(feUID);
3419 auto typeIt = FEPluginTypetoFEsMap_.find(feClassSelected);
3420 if(typeIt == FEPluginTypetoFEsMap_.end())
3422 __SUP_SS__ <<
"Illegal front-end type parameter '" << feClassSelected
3423 <<
"' not in list of types." << __E__;
3427 for(
auto& feUID : typeIt->second)
3428 feUIDs.emplace(feUID);
3434 std::string macroString;
3435 if(macroType ==
"public")
3436 loadMacro(macroName, macroString);
3437 else if(macroType ==
"private")
3438 loadMacro(macroName, macroString, username);
3440 __SUP_COUTV__(macroString);
3447 std::string filename =
"/macroOutput_" + std::to_string(time(0)) +
"_" +
3448 std::to_string(clock()) +
".txt";
3450 __SUP_COUTV__(filename);
3451 fp = fopen((CodeEditor::OTSDAQ_DATA_PATH + filename).c_str(),
"w");
3454 __SUP_SS__ <<
"Failed to open file to save macro output '"
3455 << CodeEditor::OTSDAQ_DATA_PATH << filename <<
"'..." << __E__;
3459 fprintf(fp,
"############################\n");
3461 "### Running '%s' at time %s\n",
3465 "### \t Target front-ends (count=%lu): %s\n",
3468 fprintf(fp,
"### \t\t Inputs: %s\n", inputArgs.c_str());
3469 fprintf(fp,
"############################\n\n\n");
3471 xmldoc.addTextElementToData(
"feMacroRunArgs_name",
"Filename");
3472 xmldoc.addTextElementToData(
"feMacroRunArgs_value",
3473 "$OTSDAQ_DATA/" + filename);
3477 for(
auto& feUID : feUIDs)
3479 auto feIt = FEtoSupervisorMap_.find(feUID);
3480 if(feIt == FEtoSupervisorMap_.end())
3482 __SUP_SS__ <<
"Destination front end interface ID '" << feUID
3483 <<
"' was not found in the list of front ends." << __E__;
3484 ss <<
"\n\nHere is the map:\n\n"
3489 unsigned int FESupervisorIndex = feIt->second;
3490 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
3492 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
3493 if(it == allFESupervisorInfo_.end())
3496 <<
"Error transmitting request to FE Supervisor '" << feUID <<
":"
3497 << FESupervisorIndex <<
".' \n\n"
3498 <<
"The FE Supervisor Index does not exist. Have you configured "
3499 "the state machine properly?"
3506 if(macroType ==
"fe")
3507 txParameters.
addParameter(
"Request",
"RunInterfaceMacro");
3509 txParameters.
addParameter(
"Request",
"RunMacroMakerMacro");
3511 if(macroType ==
"fe")
3520 txParameters.
addParameter(
"userPermissions", userGroupPermissions);
3530 "Running '%s' at time %s\n",
3534 "\t Target front-end: '%s::%s'\n",
3535 FEtoPluginTypeMap_[feUID].c_str(),
3538 "\t\t Inputs: %s\n",
3543 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
3544 it->second.getDescriptor(),
3545 "MacroMakerSupervisorRequest",
3548 __SUP_COUT__ <<
"Received response message: "
3549 << SOAPUtilities::translate(retMsg) << __E__;
3551 SOAPUtilities::receive(retMsg, rxParameters);
3553 __SUP_COUT__ <<
"Received it " << __E__;
3556 std::string outputResults = rxParameters.getValue(
"outputArgs");
3557 std::string error = rxParameters.getValue(
"Error");
3560 __SUP_COUT__ <<
"outputArgs = " << outputResults << __E__;
3564 __SS__ <<
"Attempted FE Macro Failed. Attempted target "
3565 <<
"was UID=" << feUID
3566 <<
" at feSupervisorID=" << FESupervisorIndex <<
"." << __E__;
3567 ss <<
"\n\n The error was:\n\n" << error << __E__;
3568 __SUP_COUT_ERR__ <<
"\n" << ss.str();
3569 xmldoc.addTextElementToData(
"Error", ss.str());
3576 DOMElement* feMacroExecParent =
3577 xmldoc.addTextElementToData(
"feMacroExec", macroName);
3583 "fe_type", FEtoPluginTypeMap_[feUID], feMacroExecParent);
3585 "fe_context", it->second.getContextName(), feMacroExecParent);
3587 "fe_supervisor", it->second.getName(), feMacroExecParent);
3589 "fe_hostname", it->second.getHostname(), feMacroExecParent);
3591 std::istringstream inputStream(outputResults);
3592 std::string splitVal, argName, argValue;
3593 while(getline(inputStream, splitVal,
';'))
3595 std::istringstream pairInputStream(splitVal);
3596 getline(pairInputStream, argName,
',');
3597 getline(pairInputStream, argValue,
',');
3602 "\t\t Output '%s' = %s\n",
3609 "outputArgs_name", argName, feMacroExecParent);
3611 "outputArgs_value", argValue, feMacroExecParent);
3613 __SUP_COUT__ << argName <<
": " << argValue << __E__;
3634 const std::string& username)
3636 __SUP_COUT__ <<
"Getting FE Macro list" << __E__;
3639 txParameters.
addParameter(
"Request",
"GetInterfaceMacros");
3644 std::string oneInterface;
3645 std::string rxFEMacros;
3649 for(
auto& appInfo : allFESupervisorInfo_)
3651 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
3652 <<
" name = " << appInfo.second.getName() << __E__;
3654 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
3655 appInfo.second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
3656 SOAPUtilities::receive(retMsg, rxParameters);
3658 rxFEMacros = rxParameters.getValue(
"FEMacros");
3660 __SUP_COUT__ <<
"FE Macros received: \n" << rxFEMacros << __E__;
3662 std::istringstream allInterfaces(rxFEMacros);
3663 while(std::getline(allInterfaces, oneInterface))
3667 xmldoc.addTextElementToData(
"FEMacros", oneInterface);
3673 std::pair<std::vector<std::string> ,
3674 std::vector<std::string> >
3676 loadMacroNames(username, macroNames);
3678 __SUP_COUT__ <<
"Public macro count: " << macroNames.first.size() << __E__;
3679 __SUP_COUT__ <<
"Private macro count: " << macroNames.second.size() << __E__;
3681 std::string macroString;
3690 for(
int i = 0; i < 2; ++i)
3691 for(
auto& macroName : (i ? macroNames.second : macroNames.first))
3694 loadMacro(macroName, macroString, username);
3699 std::stringstream xmlMacroStream;
3700 xmlMacroStream << macro.macroName_;
3701 xmlMacroStream <<
":"
3703 xmlMacroStream <<
":" << macro.namesOfInputArguments_.size();
3704 for(
auto& inputArg : macro.namesOfInputArguments_)
3705 xmlMacroStream <<
":" << inputArg;
3706 xmlMacroStream <<
":" << macro.namesOfOutputArguments_.size();
3707 for(
auto& inputArg : macro.namesOfOutputArguments_)
3708 xmlMacroStream <<
":" << inputArg;
3710 xmldoc.addTextElementToData(i ?
"PrivateMacro" :
"PublicMacro",
3711 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)