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_INFO__ <<
"Enabling remote control over UDP..." << __E__;
145 MacroMakerSupervisor::RemoteControlWorkLoop(s);
151 __SUP_COUT_INFO__ <<
"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! "
633 *out << WebUsers::REQ_NO_PERMISSION_RESPONSE.c_str();
638 __SUP_COUTT__ <<
"***Successfully authenticated security sequence. " << time(0)
645 __SUP_COUT_TYPE__(TLVL_DEBUG + 10) << __COUT_HDR__ <<
"requestType " << requestType
646 <<
" files: " << cgiIn.getFiles().size() << __E__;
649 WebUsers::RequestUserInfo userInfo(
655 userInfo.username_ =
"admin";
656 userInfo.displayName_ =
"Admin";
657 userInfo.usernameWithLock_ =
"admin";
658 userInfo.userSessionIndex_ = 0;
659 std::map<std::string , WebUsers::permissionLevel_t> initPermissions = {
664 __SUP_COUTT__ <<
"requestType: " << requestType << __E__;
665 else if(!userInfo.automatedCommand_)
666 __SUP_COUT__ <<
"requestType: " << requestType << __E__;
668 if(userInfo.NonXMLRequestType_)
674 catch(
const std::runtime_error& e)
676 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
677 <<
"':" << e.what() << __E__;
678 __SUP_COUT_ERR__ <<
"\n" << ss.str();
682 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
683 << requestType <<
".' "
684 <<
"Please check the printouts to debug." << __E__;
689 catch(
const std::exception& e)
691 ss <<
"Exception message: " << e.what();
696 __SUP_COUT_ERR__ <<
"\n" << ss.str();
705 request(requestType, cgiIn, xmlOut, userInfo);
706 __SUP_COUTT__ <<
"Request '" << requestType <<
"' complete." << __E__;
708 catch(
const std::runtime_error& e)
710 __SUP_SS__ <<
"An error was encountered handling requestType '" << requestType
711 <<
"':" << e.what() << __E__;
712 __SUP_COUT_ERR__ <<
"\n" << ss.str();
713 xmlOut.addTextElementToData(
"Error", ss.str());
717 __SUP_SS__ <<
"An unknown error was encountered handling requestType '"
718 << requestType <<
".' "
719 <<
"Please check the printouts to debug." << __E__;
724 catch(
const std::exception& e)
726 ss <<
"Exception message: " << e.what();
731 __SUP_COUT_ERR__ <<
"\n" << ss.str();
732 xmlOut.addTextElementToData(
"Error", ss.str());
737 unsigned int occurance = 0;
741 __SUP_COUT_ERR__ <<
"'" << requestType <<
"' ERROR encountered: " << err
747 __SUP_COUTVS__(10, userInfo.NoXmlWhiteSpace_);
752 !userInfo.NoXmlWhiteSpace_ );
756 void MacroMakerSupervisor::request(
const std::string& requestType,
759 const WebUsers::RequestUserInfo& userInfo)
762 std::chrono::steady_clock::time_point requestStart = std::chrono::steady_clock::now();
763 time_t requestStartTime = time(0);
766 std::string username =
"";
767 for(
unsigned int i = 0; i < userInfo.username_.size(); ++i)
768 if((userInfo.username_[i] >=
'a' && userInfo.username_[i] <=
'z') ||
769 (userInfo.username_[i] >=
'A' && userInfo.username_[i] <=
'Z') ||
770 (userInfo.username_[i] >=
'0' && userInfo.username_[i] <=
'9') ||
771 userInfo.username_[i] >=
'-' || userInfo.username_[i] <=
'_')
772 username += userInfo.username_[i];
774 if(username.size() < 2)
776 __SUP_SS__ <<
"Illegal username '" << userInfo.username_ <<
"' received."
781 __SUP_COUT__ <<
"User name is " << userInfo.username_ <<
"." << __E__;
782 __SUP_COUT__ <<
"User permission level for request '" << requestType <<
"' is "
783 << unsigned(userInfo.permissionLevel_) <<
"." << __E__;
787 if(requestType ==
"loadFEHistory")
789 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
790 mkdir(histPath.c_str(), 0755);
793 if(requestType ==
"loadFEMacroSequences")
795 std::string seqPath =
796 (std::string)MACROS_SEQUENCE_PATH + userInfo.username_ +
"/";
797 mkdir(seqPath.c_str(), 0755);
800 if(requestType ==
"getPermission")
802 xmlOut.addTextElementToData(
"Permission",
803 std::to_string(
unsigned(userInfo.permissionLevel_)));
806 std::string publicPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
807 mkdir(publicPath.c_str(), 0755);
808 std::string exportPath =
809 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + userInfo.username_ +
"/";
810 mkdir(exportPath.c_str(), 0755);
813 handleRequest(requestType, xmlOut, cgiIn, userInfo);
815 __SUP_COUTT__ <<
"Total MacroMaker request time: "
816 << artdaq::TimeUtils::GetElapsedTime(requestStart) <<
" = "
817 << time(0) - requestStartTime <<
" seconds" << __E__;
819 catch(
const std::runtime_error& e)
821 __SS__ <<
"Error occurred handling request '" << requestType <<
"': " << e.what()
823 __SUP_COUT__ << ss.str();
824 xmlOut.addTextElementToData(
"Error", ss.str());
828 __SS__ <<
"Unknown error occurred handling request '" << requestType <<
"!'" << __E__;
833 catch(
const std::exception& e)
835 ss <<
"Exception message: " << e.what();
840 __SUP_COUT__ << ss.str();
841 xmlOut.addTextElementToData(
"Error", ss.str());
846 void MacroMakerSupervisor::handleRequest(
const std::string Command,
849 const WebUsers::RequestUserInfo& userInfo)
851 if(Command ==
"FElist")
854 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
855 mkdir(macroPath.c_str(), 0755);
856 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
857 mkdir(histPath.c_str(), 0755);
861 else if(Command ==
"writeData")
862 writeData(xmldoc, cgi, userInfo.username_);
863 else if(Command ==
"readData")
864 readData(xmldoc, cgi, userInfo.username_);
865 else if(Command ==
"createMacro")
866 createMacro(xmldoc, cgi, userInfo.username_);
867 else if(Command ==
"loadMacros")
868 loadMacros(xmldoc, userInfo.username_);
869 else if(Command ==
"loadHistory")
870 loadHistory(xmldoc, userInfo.username_);
871 else if(Command ==
"deleteMacro")
872 deleteMacro(xmldoc, cgi, userInfo.username_);
873 else if(Command ==
"editMacro")
874 editMacro(xmldoc, cgi, userInfo.username_);
875 else if(Command ==
"clearHistory")
876 clearHistory(userInfo.username_);
877 else if(Command ==
"exportMacro")
878 exportMacro(xmldoc, cgi, userInfo.username_);
879 else if(Command ==
"exportFEMacro")
880 exportFEMacro(xmldoc, cgi, userInfo.username_);
881 else if(Command ==
"getFEMacroList")
885 std::string macroPath = (std::string)MACROS_DB_PATH + userInfo.username_ +
"/";
886 mkdir(macroPath.c_str(), 0755);
887 std::string histPath = (std::string)MACROS_HIST_PATH + userInfo.username_ +
"/";
888 mkdir(histPath.c_str(), 0755);
890 getFEMacroList(xmldoc, userInfo.username_);
892 else if(Command ==
"runFEMacro")
894 runFEMacro(xmldoc, cgi, userInfo);
895 else if(Command ==
"loadFEHistory")
897 loadFEHistory(xmldoc, userInfo.username_);
898 else if(Command ==
"clearFEHistory")
900 clearFEHistory(userInfo.username_);
901 else if(Command ==
"loadFEMacroSequences")
902 loadFEMacroSequences(xmldoc, userInfo.username_);
903 else if(Command ==
"saveFEMacroSequence")
904 saveFEMacroSequence(cgi, userInfo.username_);
905 else if(Command ==
"getFEMacroSequence")
906 getFEMacroSequence(xmldoc, cgi, userInfo.username_);
907 else if(Command ==
"deleteFEMacroSequence")
908 deleteFEMacroSequence(cgi, userInfo.username_);
909 else if(Command ==
"makeSequencePublic")
910 makeSequencePublic(cgi, userInfo.username_);
912 xmldoc.addTextElementToData(
"Error",
913 "Command '" + Command +
914 "' not recognized by the Macro Maker Supervisor "
915 "(was it intended for another Supervisor?).");
919 xoap::MessageReference MacroMakerSupervisor::frontEndCommunicationRequest(
920 xoap::MessageReference message)
924 __SUP_COUT__ <<
"FE Request received: " << SOAPUtilities::translate(message) << __E__;
928 SOAPUtilities::receive(message, typeParameter);
930 std::string type = typeParameter.getValue(
"type");
932 std::string error =
"";
934 if(type ==
"initFElist")
941 rxParameters.
addParameter(
"SubsystemCommonOverrideList");
942 SOAPUtilities::receive(message, rxParameters);
944 std::string groupName = rxParameters.getValue(
"groupName");
945 std::string groupKey = rxParameters.getValue(
"groupKey");
946 std::string subsystemCommonList = rxParameters.getValue(
"SubsystemCommonList");
947 std::string subsystemCommonOverrideList =
948 rxParameters.getValue(
"SubsystemCommonOverrideList");
950 __SUP_COUTV__(groupName);
951 __SUP_COUTV__(groupKey);
952 __SUP_COUTV__(subsystemCommonList);
953 __SUP_COUTV__(subsystemCommonOverrideList);
956 std::map<std::string ,
TableVersion> mergeInTables, overrideTables;
959 if(!subsystemCommonList.empty())
961 subsystemCommonList =
963 __COUT__ <<
"Transition parameter SubsystemCommonList: "
964 << subsystemCommonList << __E__;
971 if(!subsystemCommonOverrideList.empty())
973 subsystemCommonOverrideList =
975 __COUT__ <<
"Transition parameter SubsystemCommonOverrideList: "
976 << subsystemCommonOverrideList << __E__;
998 ConfigurationManager::LoadGroupType::ALL_TYPES,
1007 const SupervisorInfoMap& feTypeSupervisors =
1008 CorePropertySupervisorBase::allSupervisorInfo_.getAllFETypeSupervisorInfo();
1011 cfgMgr.
getNode(ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME);
1013 __SUP_COUT__ <<
"Number of FE Supervisors found = " << feTypeSupervisors.size()
1016 FEPluginTypetoFEsMap_.clear();
1017 FEtoSupervisorMap_.clear();
1018 FEtoPluginTypeMap_.clear();
1019 for(
auto& feApp : feTypeSupervisors)
1021 __SUP_COUT__ <<
"FEs for app " << feApp.first <<
":" << feApp.second.getName()
1024 auto feChildren = appsNode.
getNode(feApp.second.getName())
1025 .
getNode(
"LinkToSupervisorTable")
1026 .
getNode(
"LinkToFEInterfaceTable")
1029 for(
auto& fe : feChildren)
1031 if(!fe.second.status())
1034 __SUP_COUTV__(fe.first);
1035 FEtoSupervisorMap_[fe.first] = feApp.first;
1037 std::string pluginType =
1038 fe.second.getNode(
"FEInterfacePluginName").getValue();
1039 FEPluginTypetoFEsMap_[pluginType].emplace(fe.first);
1040 FEtoPluginTypeMap_[fe.first] = pluginType;
1048 else if(type ==
"feSend" ||
1049 type ==
"feMacro" ||
1050 type ==
"feMacroMultiDimensionalStart" ||
1051 type ==
"feMacroMultiDimensionalCheck" ||
1052 type ==
"macroMultiDimensionalStart" ||
1053 type ==
"macroMultiDimensionalCheck")
1055 __SUP_COUTV__(type);
1058 SOAPUtilities::receive(message, rxParameters);
1060 std::string targetInterfaceID = rxParameters.getValue(
"targetInterfaceID");
1062 __SUP_COUTV__(targetInterfaceID);
1064 auto feIt = FEtoSupervisorMap_.find(targetInterfaceID);
1065 if(feIt == FEtoSupervisorMap_.end())
1067 __SUP_SS__ <<
"Destination front end interface ID '" << targetInterfaceID
1068 <<
"' was not found in the list of front ends." << __E__;
1072 unsigned int FESupervisorIndex = feIt->second;
1073 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
1075 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1076 if(it == allFESupervisorInfo_.end())
1078 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1079 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' \n\n"
1080 <<
"The FE Supervisor Index does not exist. Have you configured "
1081 "the state machine properly?"
1086 if(type ==
"macroMultiDimensionalStart")
1092 SOAPUtilities::receive(message, rxParameters);
1093 std::string macroName = rxParameters.getValue(
"macroName");
1094 __SUP_COUTV__(macroName);
1096 std::string macroString;
1097 loadMacro(macroName, macroString);
1101 SOAPUtilities::addParameters(message, parameters);
1106 __SUP_COUT__ <<
"Forwarding request: " << SOAPUtilities::translate(message)
1109 xoap::MessageReference replyMessage =
1110 SOAPMessenger::sendWithSOAPReply(it->second.getDescriptor(), message);
1112 if(type !=
"feSend")
1114 __SUP_COUT__ <<
"Forwarding FE Macro response: "
1115 << SOAPUtilities::translate(replyMessage) << __E__;
1117 return replyMessage;
1120 catch(
const xdaq::exception::Exception& e)
1122 __SUP_SS__ <<
"Error forwarding FE Communication request to FE Supervisor '"
1123 << targetInterfaceID <<
":" << FESupervisorIndex <<
".' "
1124 <<
"Have you configured the state machine properly?\n\n"
1125 << e.what() << __E__;
1131 __SUP_SS__ <<
"Unrecognized FE Communication type: " << type << __E__;
1135 return SOAPUtilities::makeSOAPMessageReference(
"Received");
1137 catch(
const std::runtime_error& e)
1139 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
1140 __SUP_COUT_ERR__ << ss.str();
1142 xoap::MessageReference returnMessage =
1143 SOAPUtilities::makeSOAPMessageReference(
"Error");
1147 SOAPUtilities::addParameters(returnMessage, parameters);
1148 return returnMessage;
1152 xoap::MessageReference returnMessage =
1153 SOAPUtilities::makeSOAPMessageReference(
"Error");
1155 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
1160 catch(
const std::exception& e)
1162 ss <<
"Exception message: " << e.what();
1167 __SUP_COUT_ERR__ << ss.str();
1171 SOAPUtilities::addParameters(returnMessage, parameters);
1172 return returnMessage;
1178 __SUP_COUT__ <<
"Getting FE list!!!!!!!!!" << __E__;
1190 SupervisorInfoMap::const_iterator it;
1191 std::string oneInterface;
1192 std::string rxFEList;
1193 std::string rxFrontEndError;
1195 size_t lastColonIndex;
1199 for(
auto& appInfo : allFESupervisorInfo_)
1207 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
1208 <<
" name = " << appInfo.second.getName() << __E__;
1212 xoap::MessageReference retMsg =
1213 SOAPMessenger::sendWithSOAPReply(appInfo.second.getDescriptor(),
1214 "MacroMakerSupervisorRequest",
1216 SOAPUtilities::receive(retMsg, rxParameters);
1218 __SUP_COUT__ <<
"Received MacroMaker response: "
1219 << SOAPUtilities::translate(retMsg).getCommand() <<
"==>"
1220 << SOAPUtilities::translate(retMsg) << __E__;
1222 if(SOAPUtilities::translate(retMsg).getCommand() ==
"Fault")
1224 __SUP_SS__ <<
"Unrecognized command received!" << __E__;
1228 catch(
const xdaq::exception::Exception& e)
1230 __SUP_SS__ <<
"Error transmitting request to FE Supervisor LID = "
1231 << appInfo.second.getId() <<
" name = " << appInfo.second.getName()
1233 << e.what() << __E__;
1237 rxFEList = rxParameters.getValue(
"FEList");
1238 rxFrontEndError = rxParameters.getValue(
"frontEndError");
1240 __SUP_COUT__ <<
"FE List received: \n" << rxFEList << __E__;
1242 if(rxFrontEndError !=
"")
1244 __SUP_SS__ <<
"FE Errors received: \n" << rxFrontEndError << __E__;
1248 std::istringstream allInterfaces(rxFEList);
1249 while(std::getline(allInterfaces, oneInterface))
1251 __SUP_COUTV__(oneInterface);
1252 xmldoc.addTextElementToData(
"FE", oneInterface);
1254 lastColonIndex = oneInterface.rfind(
':');
1255 if(lastColonIndex == std::string::npos)
1257 __SUP_SS__ <<
"Last colon could not be found in " << oneInterface
1261 oneInterface = oneInterface.substr(lastColonIndex);
1263 __SUP_COUTV__(oneInterface);
1273 const std::string& username)
1275 __SUP_COUT__ <<
"MacroMaker writing..." << __E__;
1288 __SUP_COUT__ <<
"Write Address: " << Address <<
" Data: " << Data << __E__;
1289 __SUP_COUTV__(interfaces);
1291 std::string command =
"w:" + Address +
":" + Data;
1292 std::string format = addressFormatStr +
":" + dataFormatStr;
1293 appendCommandToHistory(command, format, time, interfaces, username);
1296 txParameters.
addParameter(
"Request",
"UniversalWrite");
1300 __SUP_COUT__ <<
"Here comes the array from multiselect box for WRITE, behold: \n"
1301 << supervisorIndexArray <<
"\n"
1302 << interfaceIndexArray << __E__;
1306 std::vector<std::string> interfaceIndices;
1307 std::istringstream f(interfaceIndexArray);
1309 while(getline(f, s,
','))
1310 interfaceIndices.push_back(s);
1311 std::vector<int> supervisorIndices;
1312 std::istringstream g(supervisorIndexArray);
1314 while(getline(g, t,
','))
1315 supervisorIndices.push_back(std::stoi(t));
1317 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
1319 unsigned int FESupervisorIndex = supervisorIndices[i];
1320 std::string interfaceIndex = interfaceIndices[i];
1322 txParameters.
addParameter(
"InterfaceID", interfaceIndex);
1324 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
1326 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
1328 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1329 if(it == allFESupervisorInfo_.end())
1331 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1332 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
1333 <<
"The FE Index doesn't exist. Have you configured the state "
1341 xoap::MessageReference replyMessage = SOAPMessenger::sendWithSOAPReply(
1342 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1344 __SUP_COUT__ <<
"Response received: "
1345 << SOAPUtilities::translate(replyMessage) << __E__;
1349 SOAPUtilities::receive(replyMessage, rxParameters);
1351 std::string error = rxParameters.getValue(
"Error");
1352 __SUP_COUTV__(error);
1357 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1358 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1359 <<
"Have you configured the state machine properly?\n\n"
1364 catch(
const xdaq::exception::Exception& e)
1366 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1367 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1368 <<
"Have you configured the state machine properly?\n\n"
1369 << e.what() << __E__;
1379 const std::string& username)
1381 __SUP_COUT__ <<
"@@@@@@@ MacroMaker wants to read data @@@@@@@@" << __E__;
1392 __SUP_COUT__ <<
"Read Address: " << Address << __E__;
1393 __SUP_COUTV__(interfaces);
1402 __SUP_COUT__ <<
"Here comes the array from multiselect box for READ, behold: "
1403 << supervisorIndexArray <<
"," << interfaceIndexArray << __E__;
1407 std::vector<std::string> interfaceIndices;
1408 std::istringstream f(interfaceIndexArray);
1410 while(getline(f, s,
','))
1411 interfaceIndices.push_back(s);
1412 std::vector<int> supervisorIndices;
1413 std::istringstream g(supervisorIndexArray);
1415 while(getline(g, t,
','))
1416 supervisorIndices.push_back(std::stoi(t));
1418 for(
unsigned int i = 0; i < supervisorIndices.size(); i++)
1420 unsigned int FESupervisorIndex = supervisorIndices[i];
1421 std::string interfaceIndex = interfaceIndices[i];
1423 txParameters.
addParameter(
"InterfaceID", interfaceIndex);
1425 __SUP_COUT__ <<
"The index of the supervisor instance is: " << FESupervisorIndex
1427 __SUP_COUT__ <<
"...and the interface ID is: " << interfaceIndex << __E__;
1429 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
1430 if(it == allFESupervisorInfo_.end())
1432 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1433 << interfaceIndex <<
":" << FESupervisorIndex <<
".' \n\n"
1434 <<
"The FE Index doesn't exist. Have you configured the state "
1442 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
1443 it->second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
1445 __SUP_COUT__ <<
"Response received: " << SOAPUtilities::translate(retMsg)
1450 SOAPUtilities::receive(retMsg, rxParameters);
1452 std::string error = rxParameters.getValue(
"Error");
1453 __SUP_COUTV__(error);
1458 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1459 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1460 <<
"Have you configured the state machine properly?\n\n"
1465 catch(
const xdaq::exception::Exception& e)
1467 __SUP_SS__ <<
"Error transmitting request to FE Supervisor '"
1468 << interfaceIndex <<
":" << FESupervisorIndex <<
".' "
1469 <<
"Have you configured the state machine properly?\n\n"
1470 << e.what() << __E__;
1474 std::string dataReadResult = rxParameters.getValue(
"dataResult");
1475 __SUP_COUT__ <<
"Data reading result received: " << dataReadResult << __E__;
1476 xmldoc.addTextElementToData(
"readData", dataReadResult);
1477 std::string command =
"r:" + Address +
":" + dataReadResult;
1478 std::string format = addressFormatStr +
":" + dataFormatStr;
1479 appendCommandToHistory(command, format, time, interfaces, username);
1486 const std::string& username)
1488 __SUP_COUT__ <<
"MacroMaker wants to create a macro!!!!!!!!!" << __E__;
1497 __SUP_COUTV__(Name);
1498 __SUP_COUTV__(Sequence);
1499 __SUP_COUTV__(Notes);
1500 __SUP_COUTV__(Time);
1501 __SUP_COUTV__(isMacroPublic);
1502 __SUP_COUTV__(isMacroLSBF);
1504 __SUP_COUTV__(MACROS_DB_PATH);
1506 std::string fileName = Name +
".dat";
1507 std::string fullPath;
1508 if(isMacroPublic ==
"true")
1509 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
1511 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
1513 __SUP_COUTV__(fullPath);
1515 std::ofstream macrofile(fullPath.c_str());
1516 if(macrofile.is_open())
1519 macrofile <<
"\"name\":\"" << Name <<
"\",\n";
1520 macrofile <<
"\"sequence\":\"" << Sequence <<
"\",\n";
1521 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
1522 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
1523 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
1524 macrofile <<
"}@" << __E__;
1529 __SUP_SS__ <<
"Unable to open file" << __E__;
1542 void MacroMakerSupervisor::loadMacro(
const std::string& macroName,
1543 std::string& macroString,
1544 const std::string& username )
1546 __SUP_COUTV__(macroName);
1549 std::string fullPath, line;
1551 for(
unsigned int i = 0; i < 2; ++i)
1554 fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1556 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1558 fullPath += macroName;
1559 if(macroName.find(
".dat") != macroName.size() - 4)
1561 __SUP_COUTV__(fullPath);
1563 std::ifstream read(fullPath.c_str());
1568 getline(read, line);
1569 macroString += line;
1576 __SUP_COUT__ <<
"Unable to open file: " << fullPath << __E__;
1580 if(macroString !=
"")
1584 if(macroString ==
"")
1586 __SUP_SS__ <<
"Unable to locate file for macro '" << macroName
1587 <<
"'... does it exist?" << __E__;
1589 ss <<
" Attempted username was '" << username <<
".'" << __E__;
1593 __SUP_COUTV__(macroString);
1597 void MacroMakerSupervisor::loadMacroNames(
1598 const std::string& username,
1599 std::pair<std::vector<std::string> ,
1600 std::vector<std::string> >& returnMacroNames)
1604 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1605 if((dir = opendir(fullPath.c_str())) != NULL)
1608 while((ent = readdir(dir)) != NULL)
1611 if((
unsigned)strlen(ent->d_name) > 4)
1615 ((fullPath + (std::string)ent->d_name)).c_str());
1620 returnMacroNames.second.push_back(ent->d_name);
1623 __SUP_COUT__ <<
"Unable to open file" << __E__;
1630 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1633 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1634 if((dir = opendir(fullPath.c_str())) != NULL)
1637 while((ent = readdir(dir)) != NULL)
1640 if((
unsigned)strlen(ent->d_name) > 4)
1644 ((fullPath + (std::string)ent->d_name)).c_str());
1648 returnMacroNames.first.push_back(ent->d_name);
1652 __SUP_COUT__ <<
"Unable to open file" << __E__;
1659 __SUP_COUT__ << fullPath << __E__;
1660 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1668 const std::string& username)
1672 std::string returnStr =
"";
1673 std::string fullPath = (std::string)MACROS_DB_PATH + username +
"/";
1674 if((dir = opendir(fullPath.c_str())) != NULL)
1677 while((ent = readdir(dir)) != NULL)
1680 if((
unsigned)strlen(ent->d_name) > 4)
1684 ((fullPath + (std::string)ent->d_name)).c_str());
1687 std::stringstream buffer;
1690 getline(read, line);
1694 returnStr += buffer.str();
1699 __SUP_COUT__ <<
"Unable to open file" << __E__;
1702 std::string returnMacroStr = returnStr.substr(0, returnStr.size() - 1);
1704 __SUP_COUT__ <<
"Loading existing macros! " << returnMacroStr << __E__;
1707 xmldoc.addTextElementToData(
"returnMacroStr", returnMacroStr);
1711 __SUP_COUT__ <<
"Looping through privateMacros folder failed! Wrong directory"
1714 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/";
1716 if((dir = opendir(fullPath.c_str())) != NULL)
1719 while((ent = readdir(dir)) != NULL)
1722 if((
unsigned)strlen(ent->d_name) > 4)
1726 ((fullPath + (std::string)ent->d_name)).c_str());
1729 std::stringstream buffer;
1732 getline(read, line);
1736 returnStr += buffer.str();
1740 __SUP_COUT__ <<
"Unable to open file" << __E__;
1743 std::string returnPublicStr = returnStr.substr(0, returnStr.size() - 1);
1744 __SUP_COUT__ <<
"Loading existing public macros: " << returnPublicStr << __E__;
1746 xmldoc.addTextElementToData(
"returnPublicStr", returnPublicStr);
1750 __SUP_COUT__ << fullPath << __E__;
1751 __SUP_COUT__ <<
"Looping through MacroData folder failed! Wrong directory"
1757 void MacroMakerSupervisor::appendCommandToHistory(std::string Command,
1760 std::string Interfaces,
1761 const std::string& username)
1763 std::string fileName =
"history.hist";
1764 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1765 __SUP_COUT__ << fullPath << __E__;
1766 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1767 if(histfile.is_open())
1770 histfile <<
"\"Command\":\"" << Command <<
"\",\n";
1771 histfile <<
"\"Format\":\"" << Format <<
"\",\n";
1772 histfile <<
"\"Time\":\"" << Time <<
"\",\n";
1773 histfile <<
"\"Interfaces\":\"" << Interfaces <<
"\"\n";
1774 histfile <<
"}#" << __E__;
1779 __SUP_SS__ <<
"Unable to open history.hist at " << fullPath << __E__;
1785 void MacroMakerSupervisor::appendCommandToHistory(std::string feClass,
1787 std::string macroType,
1788 std::string macroName,
1789 std::string inputArgs,
1790 std::string outputArgs,
1792 const std::string& username)
1795 auto feHistoryIt = lastFeCommandToHistory_.find(username);
1796 if(feHistoryIt != lastFeCommandToHistory_.end() && feHistoryIt->second.size() == 7 &&
1797 feHistoryIt->second[0] == feClass && feHistoryIt->second[1] == feUID &&
1798 feHistoryIt->second[2] == macroType && feHistoryIt->second[3] == macroName &&
1799 feHistoryIt->second[4] == inputArgs && feHistoryIt->second[5] == outputArgs &&
1800 feHistoryIt->second[6] == (saveOutputs ?
"1" :
"0"))
1802 __SUP_COUTT__ <<
"Not saving repeat command to history from user " << username
1807 std::string fileName =
"FEhistory.hist";
1808 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
1809 __SUP_COUT__ << fullPath << __E__;
1810 std::ofstream histfile(fullPath.c_str(), std::ios::app);
1811 if(histfile.is_open())
1814 histfile <<
"\"feClass\":\"" << feClass <<
"\",\n";
1815 histfile <<
"\"feUID\":\"" << feUID <<
"\",\n";
1816 histfile <<
"\"macroType\":\"" << macroType <<
"\",\n";
1817 histfile <<
"\"macroName\":\"" << macroName <<
"\",\n";
1818 histfile <<
"\"inputArgs\":\"" << inputArgs <<
"\",\n";
1819 histfile <<
"\"outputArgs\":\"" << outputArgs <<
"\",\n";
1821 histfile <<
"\"saveOutputs\":\"" << 1 <<
"\"\n";
1823 histfile <<
"\"saveOutputs\":\"" << 0 <<
"\"\n";
1824 histfile <<
"}#" << __E__;
1827 lastFeCommandToHistory_[username].clear();
1828 feHistoryIt = lastFeCommandToHistory_.find(username);
1829 feHistoryIt->second.push_back(feClass);
1830 feHistoryIt->second.push_back(feUID);
1831 feHistoryIt->second.push_back(macroType);
1832 feHistoryIt->second.push_back(macroName);
1833 feHistoryIt->second.push_back(inputArgs);
1834 feHistoryIt->second.push_back(outputArgs);
1835 feHistoryIt->second.push_back((saveOutputs ?
"1" :
"0"));
1839 __SUP_SS__ <<
"Unable to open FEhistory.hist at " << fullPath << __E__;
1846 void MacroMakerSupervisor::loadFEMacroSequences(
HttpXmlDocument& xmldoc,
1847 const std::string& username)
1849 __SUP_COUT__ <<
"loadFEMacroSequences for " << username << __E__;
1852 std::string fullPath = (std::string)MACROS_SEQUENCE_PATH + username +
"/";
1853 std::string sequences =
"";
1854 __SUP_COUTV__(fullPath);
1855 if((dir = opendir(fullPath.c_str())) != NULL)
1858 while((ent = readdir(dir)) != NULL)
1862 ((fullPath + (std::string)ent->d_name)).c_str());
1866 sequences += ent->d_name + std::string(
";");
1869 __SUP_COUT__ <<
"Unable to open file" << __E__;
1875 __SUP_COUT__ <<
"Looping through MacroSequence/" + username +
1876 " folder failed! Invalid directory."
1880 if(username == WebUsers::DEFAULT_ADMIN_USERNAME)
1883 xmldoc.addTextElementToData(
"FEsequences", sequences);
1888 fullPath = (std::string)MACROS_SEQUENCE_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
"/";
1890 if((dir = opendir(fullPath.c_str())) != NULL)
1893 while((ent = readdir(dir)) != NULL)
1897 ((fullPath + (std::string)ent->d_name)).c_str());
1901 sequences += std::string(
"public/") + ent->d_name + std::string(
";");
1904 __SUP_COUT__ <<
"Unable to open file" << __E__;
1910 __SUP_COUT__ <<
"Looping through MacroSequence/" +
1911 WebUsers::DEFAULT_ADMIN_USERNAME +
1912 " folder failed! Invalid directory."
1917 xmldoc.addTextElementToData(
"FEsequences", sequences);
1921 void MacroMakerSupervisor::saveFEMacroSequence(cgicc::Cgicc& cgi,
1922 const std::string& username)
1927 std::string FEsequence =
1929 bool overwrite = CgiDataUtilities::getDataAsInt(cgi,
"overwrite");
1931 __SUP_COUTV__(overwrite);
1932 __SUP_COUTV__(name);
1933 __SUP_COUTV__(FEsequence);
1936 std::string fixedName =
"";
1937 for(
size_t i = 0; i < name.size(); ++i)
1938 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
1939 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
1940 (name[i] >=
'a' && name[i] <=
'z')))
1943 <<
"Illegal character in Sequence name (position " << i
1944 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
1949 fixedName += name[i];
1950 __SUP_COUTV__(fixedName);
1952 std::string fullPath =
1953 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
1954 __SUP_COUTV__(fullPath);
1957 if(!overwrite && std::filesystem::exists(fullPath))
1959 __SUP_SS__ <<
"Please choose another Sequence name! A sequence with the same "
1960 "resulting filename already exists at "
1961 << fullPath << __E__;
1965 std::ofstream seqfile(fullPath.c_str());
1966 if(seqfile.is_open())
1968 seqfile << FEsequence << __E__;
1973 __SUP_SS__ <<
"Unable to open file to save FE Macro Sequence at " << fullPath
1980 void MacroMakerSupervisor::getFEMacroSequence(
HttpXmlDocument& xmldoc,
1982 const std::string& username)
1986 __SUP_COUTV__(name);
1988 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
1989 __SUP_COUTV__(isPublic);
1992 std::string fixedName =
"";
1993 for(
size_t i = (isPublic ? std::string(
"public/").size() : 0); i < name.size(); ++i)
1994 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
1995 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
1996 (name[i] >=
'a' && name[i] <=
'z')))
1998 __COUT__ <<
"Illegal character in Sequence name (position " << i
1999 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2003 fixedName += name[i];
2004 __SUP_COUTV__(fixedName);
2007 std::string fullPath =
2008 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2009 __SUP_COUT__ << fullPath << __E__;
2011 std::ifstream read(fullPath.c_str());
2013 unsigned long long fileSize;
2015 if(!isPublic && read.is_open())
2017 read.seekg(0, std::ios::end);
2018 fileSize = read.tellg();
2019 response =
new char[fileSize + 1];
2020 response[fileSize] =
'\0';
2021 read.seekg(0, std::ios::beg);
2024 read.read(response, fileSize);
2027 xmldoc.addTextElementToData(
"FEsequence", &response[0]);
2034 __SUP_COUT__ <<
"Unable to open " << fullPath <<
"! Trying public area..."
2038 std::string publicFullPath = (std::string)MACROS_SEQUENCE_PATH +
2039 WebUsers::DEFAULT_ADMIN_USERNAME +
"/" + fixedName +
2041 __SUP_COUT__ << publicFullPath << __E__;
2043 std::ifstream read(publicFullPath.c_str());
2045 unsigned long long fileSize;
2049 read.seekg(0, std::ios::end);
2050 fileSize = read.tellg();
2051 response =
new char[fileSize + 1];
2052 response[fileSize] =
'\0';
2053 read.seekg(0, std::ios::beg);
2056 read.read(response, fileSize);
2059 xmldoc.addTextElementToData(
"FEsequence", &response[0]);
2065 __SUP_SS__ <<
"Unable to open FE Macro Sequence at " << fullPath <<
" or "
2066 << publicFullPath << __E__;
2073 void MacroMakerSupervisor::deleteFEMacroSequence(cgicc::Cgicc& cgi,
2074 const std::string& username)
2078 __SUP_COUTV__(name);
2080 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
2081 __SUP_COUTV__(isPublic);
2084 std::string fixedName =
"";
2085 for(
size_t i = (isPublic ? std::string(
"public/").size() : 0); i < name.size(); ++i)
2086 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
2087 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
2088 (name[i] >=
'a' && name[i] <=
'z')))
2090 __COUT__ <<
"Illegal character in Sequence name (position " << i
2091 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2095 fixedName += name[i];
2096 __SUP_COUTV__(fixedName);
2099 std::string fullPath =
2100 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2102 fullPath = (std::string)MACROS_SEQUENCE_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
2103 "/" + fixedName +
".dat";
2104 __SUP_COUT__ << fullPath << __E__;
2107 if(!std::filesystem::exists(fullPath))
2110 <<
"The specified Sequence name does not exist! Looking for sequence file at "
2111 << fullPath << __E__;
2115 std::remove(fullPath.c_str());
2116 __SUP_COUT__ <<
"Successfully deleted " << fullPath << __E__;
2120 void MacroMakerSupervisor::makeSequencePublic(cgicc::Cgicc& cgi,
2121 const std::string& username)
2125 __SUP_COUTV__(name);
2127 bool isPublic = (name.find(
"public/") == 0 ? true :
false);
2128 __SUP_COUTV__(isPublic);
2131 __SUP_SS__ <<
"The specified Sequence name is already designated as public."
2137 std::string fixedName =
"";
2138 for(
size_t i = 0; i < name.size(); ++i)
2139 if(!(name[i] ==
' ' || name[i] ==
'-' || name[i] ==
'_' ||
2140 (name[i] >=
'0' && name[i] <=
'9') || (name[i] >=
'A' && name[i] <=
'Z') ||
2141 (name[i] >=
'a' && name[i] <=
'z')))
2143 __COUT__ <<
"Illegal character in Sequence name (position " << i
2144 <<
") - only alphanumeric, spaces, dashes, and underscores allowed!"
2148 fixedName += name[i];
2149 __SUP_COUTV__(fixedName);
2152 std::string source =
2153 (std::string)MACROS_SEQUENCE_PATH + username +
"/" + fixedName +
".dat";
2154 __SUP_COUT__ << source << __E__;
2155 std::string destination = (std::string)MACROS_SEQUENCE_PATH +
2156 WebUsers::DEFAULT_ADMIN_USERNAME +
"/" + fixedName +
".dat";
2157 __SUP_COUT__ << destination << __E__;
2159 if(std::filesystem::exists(destination))
2161 __SUP_SS__ <<
"The sequence name '" << fixedName
2162 <<
"' already exists in the admin/public location: " << destination
2168 std::filesystem::copy_file(
2169 source, destination, std::filesystem::copy_options::skip_existing);
2170 __SUP_COUT__ <<
"Successfully made " << fixedName
2171 <<
" public at path: " << destination << __E__;
2176 const std::string& username)
2178 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"history.hist";
2180 std::ifstream read(fileName.c_str());
2181 __SUP_COUT__ << fileName << __E__;
2187 unsigned long long fileSz, i = 0, MAX_HISTORY_SIZE = 100000;
2191 read.seekg(0, std::ios::end);
2192 fileSz = read.tellg();
2193 returnStr =
new char[fileSz + 1];
2194 returnStr[fileSz] =
'\0';
2195 read.seekg(0, std::ios::beg);
2198 read.read(returnStr, fileSz);
2202 if(fileSz > MAX_HISTORY_SIZE)
2204 i = fileSz - MAX_HISTORY_SIZE;
2205 for(; i < fileSz; ++i)
2206 if(returnStr[i] ==
'#')
2215 FILE* fp = fopen(fileName.c_str(),
"w");
2219 __SS__ <<
"Big problem with macromaker history file: " << fileName
2223 fwrite(&returnStr[i], fileSz - i, 1, fp);
2227 __SUP_COUT__ <<
"Loading user history! " << __E__;
2230 returnStr[fileSz - 2] =
'\0';
2232 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
2237 __SUP_COUT__ <<
"Unable to open history.hist" << __E__;
2243 const std::string& username)
2245 std::string fileName = MACROS_HIST_PATH + username +
"/" +
"FEhistory.hist";
2247 std::ifstream read(fileName.c_str());
2248 __SUP_COUT__ << fileName << __E__;
2250 if(!read.is_open() && username != WebUsers::DEFAULT_ADMIN_USERNAME)
2252 __SUP_COUT__ <<
"Unable to open FE history.hist.. Defaulting to admin's FE "
2253 "history as starting point."
2257 MACROS_HIST_PATH + WebUsers::DEFAULT_ADMIN_USERNAME +
"/" +
"FEhistory.hist";
2258 read.open(fileName.c_str());
2265 unsigned long long fileSize;
2266 unsigned long long i = 0;
2267 unsigned long long MAX_HISTORY_SIZE = 100000;
2270 read.seekg(0, std::ios::end);
2271 fileSize = read.tellg();
2272 returnStr =
new char[fileSize + 1];
2273 returnStr[fileSize] =
'\0';
2274 read.seekg(0, std::ios::beg);
2277 read.read(returnStr, fileSize);
2281 if(fileSize > MAX_HISTORY_SIZE)
2283 i = fileSize - MAX_HISTORY_SIZE;
2284 for(; i < fileSize; ++i)
2286 if(returnStr[i] ==
'#')
2296 FILE* fp = fopen(fileName.c_str(),
"w");
2300 __SS__ <<
"Big problem with FE history file: " << fileName << __E__;
2303 fwrite(&returnStr[i], fileSize - i, 1, fp);
2307 __SUP_COUT__ <<
"Loading user history! " << __E__;
2310 returnStr[fileSize - 2] =
'\0';
2312 xmldoc.addTextElementToData(
"returnHistStr", &returnStr[i]);
2317 __SUP_COUT__ <<
"Unable to open FE history.hist" << __E__;
2324 const std::string& username)
2329 std::string fileName = MacroName +
".dat";
2330 std::string fullPath;
2331 if(isMacroPublic ==
"true")
2332 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
2334 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
2336 __SUP_COUT__ << fullPath << __E__;
2338 std::remove(fullPath.c_str());
2339 __SUP_COUT__ <<
"Successfully deleted " << MacroName;
2340 xmldoc.addTextElementToData(
"deletedMacroName", MacroName);
2346 const std::string& username)
2358 __SUP_COUTV__(oldMacroName);
2359 __SUP_COUTV__(newMacroName);
2360 __SUP_COUTV__(FESequence);
2361 __SUP_COUTV__(Notes);
2362 __SUP_COUTV__(Time);
2363 __SUP_COUTV__(isMacroPublic);
2364 __SUP_COUTV__(isMacroLSBF);
2366 __SUP_COUTV__(MACROS_DB_PATH);
2368 std::string fileName = oldMacroName +
".dat";
2369 std::string fullPath;
2370 if(isMacroPublic ==
"true")
2371 fullPath = (std::string)MACROS_DB_PATH +
"publicMacros/" + fileName;
2373 fullPath = (std::string)MACROS_DB_PATH + username +
"/" + fileName;
2375 __SUP_COUTV__(fullPath);
2377 std::ofstream macrofile(fullPath.c_str());
2378 if(macrofile.is_open())
2381 macrofile <<
"\"name\":\"" << newMacroName <<
"\",\n";
2382 macrofile <<
"\"FEsequence\":\"" << FESequence <<
"\",\n";
2383 macrofile <<
"\"time\":\"" << Time <<
"\",\n";
2384 macrofile <<
"\"notes\":\"" << Notes <<
"\",\n";
2385 macrofile <<
"\"LSBF\":\"" << isMacroLSBF <<
"\"\n";
2386 macrofile <<
"}@" << __E__;
2390 __SUP_COUT__ <<
"Unable to open file" << __E__;
2392 if(oldMacroName != newMacroName)
2396 rename((MACROS_DB_PATH + username +
"/" + oldMacroName +
".dat").c_str(),
2397 (MACROS_DB_PATH + username +
"/" + newMacroName +
".dat").c_str());
2399 xmldoc.addTextElementToData(
"newMacroName", newMacroName);
2401 xmldoc.addTextElementToData(
"newMacroName",
"ERROR");
2406 void MacroMakerSupervisor::clearHistory(
const std::string& username)
2408 std::string fileName =
"history.hist";
2409 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
2411 std::remove(fullPath.c_str());
2412 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
2416 void MacroMakerSupervisor::clearFEHistory(
const std::string& username)
2418 std::string fileName =
"FEhistory.hist";
2419 std::string fullPath = (std::string)MACROS_HIST_PATH + username +
"/" + fileName;
2421 std::remove(fullPath.c_str());
2422 __SUP_COUT__ <<
"Successfully deleted " << fullPath;
2428 const std::string& username)
2433 std::string macroNotes =
2436 __SUP_COUTV__(pluginName);
2437 __SUP_COUTV__(macroName);
2438 __SUP_COUTV__(macroSequence);
2441 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
2442 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
2443 macroNotes[i] =
' ';
2444 __SUP_COUTV__(macroNotes);
2446 std::stringstream ss(macroSequence);
2447 std::string command;
2448 std::vector<std::string> commands;
2450 while(getline(ss, command,
','))
2451 commands.push_back(command);
2455 std::map<std::string , std::set<std::string> >
2456 specialsCodeMap = CodeEditor::getSpecialsMap();
2459 auto specialsCodeMapIt = specialsCodeMap.find(CodeEditor::SPECIAL_TYPE_FEInterface);
2460 if(specialsCodeMapIt == specialsCodeMap.end())
2463 <<
"Could not find any FE Interface plugins in source code. Does MacroMaker "
2464 <<
"have access to the source code? Check that the Supervisor context places "
2466 <<
"location with access to the source code." << __E__;
2471 std::string headerFile = pluginName +
".h";
2472 std::string sourceFile = pluginName +
"_interface.cc";
2473 bool foundHeaderFile =
false;
2474 bool foundSourceFile =
false;
2475 for(
const auto& filePath : specialsCodeMapIt->second)
2477 if(!foundHeaderFile && filePath.find(headerFile) != std::string::npos)
2479 foundHeaderFile =
true;
2480 headerFile = filePath;
2481 __SUP_COUT__ <<
"found headerFile=" << filePath << __E__;
2483 if(!foundSourceFile && filePath.find(sourceFile) != std::string::npos)
2485 foundSourceFile =
true;
2486 sourceFile = filePath;
2487 __SUP_COUT__ <<
"found sourceFile=" << filePath << __E__;
2490 if(foundSourceFile && foundHeaderFile)
2494 if(!foundHeaderFile)
2496 __SS__ <<
"Could not find the header file for the FE Interface plugins at '"
2497 << headerFile <<
".' Does MacroMaker "
2498 <<
"have access to the source code? Check that the Supervisor context "
2499 "places MacroMaker in a "
2500 <<
"location with access to the source code." << __E__;
2503 if(!foundSourceFile)
2505 __SS__ <<
"Could not find the source file for the FE Interface plugins at '"
2506 << sourceFile <<
".' Does MacroMaker "
2507 <<
"have access to the source code? Check that the Supervisor context "
2508 "places MacroMaker in a "
2509 <<
"location with access to the source code." << __E__;
2522 char timeBuffer[100];
2525 struct tm* timeinfo;
2528 timeinfo = localtime(&rawtime);
2530 strftime(timeBuffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
2533 std::string contents;
2538 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, sourceFile, contents);
2542 xmldoc.addTextElementToData(
"sourceFile", sourceFile);
2543 xmldoc.addTextElementToData(
"headerFile", headerFile);
2546 if(contents.find(pluginName +
"::" + macroName) != std::string::npos)
2548 __SS__ <<
"The function definition '" << (pluginName +
"::" + macroName)
2549 <<
"(...)' already exists in the source file '" << sourceFile
2550 <<
".' Duplicate functions are not allowed - please rename the macro or "
2551 "modify the source file."
2556 std::stringstream codess;
2557 std::set<std::string> inArgNames, outArgNames;
2569 auto insertPos = contents.find(pluginName +
"::" + pluginName);
2570 if(insertPos == std::string::npos)
2572 __SS__ <<
"Could not find the code insert position in the source file '"
2573 << sourceFile <<
".' The FE plugin class constructor must be '"
2574 << pluginName <<
":" << pluginName <<
"' - is this the case?" << __E__;
2577 __SUP_COUTV__(insertPos);
2579 insertPos = contents.find(
"{", insertPos);
2580 if(insertPos == std::string::npos)
2582 __SS__ <<
"Could not find the code insert position in the source file '"
2584 <<
".' The FE plugin class constructor must begin with '{"
2585 <<
"' - is this the case?" << __E__;
2589 __SUP_COUTV__(insertPos);
2591 insert =
"\n\t//registration of FEMacro '" + macroName +
"' generated, " +
2592 timeBuffer +
", by '" + username +
"' using MacroMaker.\n\t" +
2593 "FEVInterface::registerFEMacroFunction(\"" + macroName +
2594 "\",//feMacroName \n\t\t" +
2595 "static_cast<FEVInterface::frontEndMacroFunction_t>(&" + pluginName +
2596 "::" + macroName +
"), //feMacroFunction \n\t\t" +
2597 "std::vector<std::string>{";
2600 for(
const auto& inArg : inArgNames)
2606 insert +=
"\"" + inArg +
"\"";
2609 insert +=
"}, //namesOfInputArgs \n\t\t";
2610 insert +=
"std::vector<std::string>{";
2613 for(
const auto& outArg : outArgNames)
2619 insert +=
"\"" + outArg +
"\"";
2622 insert +=
"}, //namesOfOutputArgs \n\t\t";
2623 insert +=
"1); //requiredUserPermissions \n\n";
2625 __SUP_COUTV__(insert);
2626 contents = contents.substr(0, insertPos) + insert + contents.substr(insertPos);
2631 auto insertPos = contents.rfind(
"DEFINE_OTS_INTERFACE");
2632 if(insertPos == std::string::npos)
2634 __SS__ <<
"Could not find the code insert position in the source file '"
2636 <<
".' The FE plugin class must end with a 'DEFINE_OTS_INTERFACE("
2637 << pluginName <<
")' - is this the case?" << __E__;
2640 __SUP_COUTV__(insertPos);
2644 "============================================================================"
2645 "============================================\n//" +
2646 macroName +
"\n" +
"//\tFEMacro '" + macroName +
"' generated, " +
2647 timeBuffer +
", by '" + username +
"' using MacroMaker.\n" +
2648 "//\tMacro Notes: " + macroNotes +
"\n" +
"void " + pluginName +
2649 "::" + macroName +
"(__ARGS__)\n{\n\t" +
2650 "__CFG_COUT__ << \"# of input args = \" << argsIn.size() << __E__; \n\t" +
2651 "__CFG_COUT__ << \"# of output args = \" << argsOut.size() << __E__; \n\t" +
2652 "for(auto &argIn:argsIn) \n\t\t" +
2653 "__CFG_COUT__ << argIn.first << \": \" << argIn.second << __E__; \n\n\t" +
2654 "//macro commands section \n" + codess.str() +
"\n\n\t" +
2655 "for(auto &argOut:argsOut) \n\t\t" +
2656 "__CFG_COUT__ << argOut.first << \": \" << argOut.second << __E__; \n\n" +
2657 "} //end " + macroName +
"()\n\n";
2660 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
2663 "MacroMaker-" + username,
2670 CodeEditor::readFile(CodeEditor::SOURCE_BASE_PATH, headerFile, contents);
2675 auto insertPos = contents.rfind(
"};");
2676 if(insertPos == std::string::npos)
2678 __SS__ <<
"Could not find the code insert position in the header file '"
2680 <<
".' The FE plugin class must end with a '};' - is this the case?"
2685 __SUP_COUTV__(insertPos);
2687 insert =
"\npublic: // FEMacro '" + macroName +
"' generated, " + timeBuffer +
2688 ", by '" + username +
"' using MacroMaker.\n\t" +
"void " + macroName +
2691 __SUP_COUTV__(insert);
2692 CodeEditor::writeFile(CodeEditor::SOURCE_BASE_PATH,
2695 "MacroMaker-" + username,
2705 const std::string& username)
2709 std::string macroNotes =
2712 __SUP_COUTV__(macroName);
2713 __SUP_COUTV__(macroSequence);
2716 for(
unsigned int i = 0; i < macroNotes.length(); ++i)
2717 if(macroNotes[i] ==
'\r' || macroNotes[i] ==
'\n')
2718 macroNotes[i] =
' ';
2719 __SUP_COUTV__(macroNotes);
2721 std::stringstream ss(macroSequence);
2722 std::string command;
2723 std::vector<std::string> commands;
2725 while(getline(ss, command,
','))
2726 commands.push_back(command);
2728 std::string fileName = macroName +
".cc";
2730 std::string fullPath =
2731 __ENV__(
"SERVICE_DATA_PATH") + MACROS_EXPORT_PATH + username +
"/" + fileName;
2732 __SUP_COUT__ << fullPath << __E__;
2733 std::ofstream exportFile(fullPath.c_str(), std::ios::trunc);
2734 if(exportFile.is_open())
2736 exportFile <<
"//Generated Macro Name:\t" << macroName <<
"\n";
2737 exportFile <<
"//Macro Notes: " << macroNotes <<
"\n";
2741 struct tm* timeinfo;
2745 timeinfo = localtime(&rawtime);
2747 strftime(buffer, 100,
"%b-%d-%Y %I:%M:%S", timeinfo);
2748 exportFile <<
"//Generated Time: \t\t" << buffer <<
"\n";
2751 exportFile <<
"//Paste this whole file into an interface to transfer Macro "
2754 createCode(exportFile, commands);
2758 xmldoc.addTextElementToData(
2760 "$USER_DATA/ServiceData/" + MACROS_EXPORT_PATH + username +
"/" + fileName);
2763 __SUP_COUT__ <<
"Unable to open file" << __E__;
2768 void MacroMakerSupervisor::createCode(std::ostream& out,
2769 const std::vector<std::string>& commands,
2770 const std::string& tabOffset,
2772 std::set<std::string>* inArgNames,
2773 std::set<std::string>* outArgNames)
2776 std::set<std::string > argInHasBeenInitializedSet;
2777 bool addressIsVariable, dataIsVariable;
2779 out << tabOffset <<
"{";
2782 << tabOffset <<
"\t"
2783 <<
"char *address \t= new char[universalAddressSize_]{0}; //create address "
2784 "buffer of interface size and init to all 0";
2786 << tabOffset <<
"\t"
2787 <<
"char *data \t\t= new char[universalDataSize_]{0}; //create data buffer "
2788 "of interface size and init to all 0";
2791 << tabOffset <<
"\t"
2792 <<
"uint64_t macroAddress; //create macro address buffer (size 8 bytes)";
2794 << tabOffset <<
"\t"
2795 <<
"uint64_t macroData; //create macro address buffer (size 8 bytes)";
2798 << tabOffset <<
"\t"
2799 <<
"std::map<std::string /*arg name*/,uint64_t /*arg val*/> macroArgs; //create "
2800 "map from arg name to 64-bit number";
2803 for(
unsigned int i = 0; i < commands.size(); i++)
2805 std::stringstream sst(commands[i]);
2807 std::vector<std::string>
2809 while(getline(sst, tokens,
':'))
2810 oneCommand.push_back(tokens);
2811 while(oneCommand.size() < 4)
2812 oneCommand.push_back(
"");
2840 addressIsVariable = isArgumentVariable(oneCommand[2]);
2841 dataIsVariable = isArgumentVariable(oneCommand[3]);
2843 __SUP_COUTV__(addressIsVariable);
2844 __SUP_COUTV__(dataIsVariable);
2846 out <<
"\n\n" << tabOffset <<
"\t// command-#" << i <<
": ";
2848 if(oneCommand[1][0] ==
'w' || oneCommand[1][0] ==
'r')
2850 if(oneCommand[1][0] ==
'w')
2852 else if(oneCommand[1][0] ==
'r')
2855 if(addressIsVariable)
2856 out << oneCommand[2];
2858 out <<
"0x" << oneCommand[2];
2859 out <<
" /*address*/,";
2863 out << oneCommand[3] <<
" /*data*/";
2864 else if(oneCommand[1][0] ==
'w')
2865 out <<
"0x" << oneCommand[3] <<
" /*data*/";
2866 else if(oneCommand[1][0] ==
'r')
2870 else if(oneCommand[1][0] ==
'd')
2872 out <<
"delay(" << oneCommand[2] <<
");\n";
2873 out << tabOffset <<
"\t"
2874 <<
"__CFG_COUT__ << \"Sleeping for... \" << " << oneCommand[2]
2875 <<
" << \" milliseconds \" << __E__;\n";
2876 out << tabOffset <<
"\t"
2877 <<
"usleep(" << oneCommand[2] <<
"*1000 /* microseconds */);\n";
2882 __SS__ <<
"FATAL ERROR: Unknown command '" << oneCommand[1]
2883 <<
"'... command is not w, r or d" << __E__;
2889 if(addressIsVariable)
2891 if(argInHasBeenInitializedSet.find(oneCommand[2]) ==
2892 argInHasBeenInitializedSet.end())
2894 argInHasBeenInitializedSet.emplace(oneCommand[2]);
2899 out << tabOffset <<
"\t"
2900 <<
"macroArgs[\"" << oneCommand[2]
2902 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2905 << tabOffset <<
"\t\t\"" << oneCommand[2]
2906 <<
"\").getValue<uint64_t>();";
2911 inArgNames->emplace(oneCommand[2]);
2914 out << tabOffset <<
"\t"
2915 <<
"macroArgs[\"" << oneCommand[2] <<
"\"] = __GET_ARG_IN__(\""
2916 << oneCommand[2] <<
"\", uint64_t);";
2919 out <<
"\t//get macro address argument";
2921 << tabOffset <<
"\tmemcpy(address,¯oArgs[\"" << oneCommand[2]
2922 <<
"\"],8); //copy macro address argument to buffer";
2926 out << tabOffset <<
"\t"
2927 <<
"macroAddress = 0x" << oneCommand[2]
2928 <<
"; memcpy(address,¯oAddress,8);"
2929 <<
"\t//copy macro address to buffer";
2934 if(oneCommand[1] ==
"w")
2938 if(argInHasBeenInitializedSet.find(oneCommand[3]) ==
2939 argInHasBeenInitializedSet
2942 argInHasBeenInitializedSet.emplace(oneCommand[3]);
2947 inArgNames->emplace(oneCommand[3]);
2951 << tabOffset <<
"\t"
2952 <<
"macroArgs[\"" << oneCommand[3]
2953 <<
"\"] = __GET_ARG_IN__(\"" << oneCommand[3]
2954 <<
"\", uint64_t); //initialize from input arguments";
2960 << tabOffset <<
"\t"
2961 <<
"macroArgs[\"" << oneCommand[3]
2963 "theXDAQContextConfigTree_.getNode(theConfigurationPath_)."
2966 << tabOffset <<
"\t\t\"" << oneCommand[3]
2967 <<
"\").getValue<uint64_t>(); //initialize from "
2968 "configuration tree";
2971 out <<
"\t//get macro data argument";
2973 << tabOffset <<
"\tmemcpy(data,¯oArgs[\"" << oneCommand[3]
2974 <<
"\"],8); //copy macro data argument to buffer";
2979 << tabOffset <<
"\t"
2980 <<
"macroData = 0x" << oneCommand[3] <<
"; memcpy(data,¯oData,8);"
2981 <<
"\t//copy macro data to buffer";
2984 << tabOffset <<
"\t"
2985 <<
"universalWrite(address,data);";
2990 << tabOffset <<
"\t"
2991 <<
"universalRead(address,data);";
2993 std::string outputArgName;
2996 outputArgName = oneCommand[3];
3000 sprintf(str,
"outArg%d", i);
3001 outputArgName = str;
3003 __SUP_COUTV__(outputArgName);
3005 out << tabOffset <<
"\t"
3006 <<
"memcpy(¯oArgs[\"" << outputArgName
3007 <<
"\"],data,8); //copy buffer to argument map";
3012 << tabOffset <<
"\t"
3013 <<
"__SET_ARG_OUT__(\"" << outputArgName <<
"\",macroArgs[\""
3014 << outputArgName <<
"\"]); //update output argument result";
3017 outArgNames->emplace(outputArgName);
3018 argInHasBeenInitializedSet.emplace(
3023 out <<
"\n\n" << tabOffset <<
"\tdelete[] address; //free the memory";
3024 out <<
"\n" << tabOffset <<
"\tdelete[] data; //free the memory";
3025 out <<
"\n" << tabOffset <<
"}";
3027 __SUP_COUT__ <<
"Done with code generation." << __E__;
3033 bool MacroMakerSupervisor::isArgumentVariable(
const std::string& argumentString)
3035 for(
unsigned int i = 0; i < argumentString.length(); ++i)
3038 if(!((argumentString[i] >=
'0' && argumentString[i] <=
'9') ||
3039 (argumentString[i] >=
'a' && argumentString[i] <=
'f') ||
3040 (argumentString[i] >=
'A' && argumentString[i] <=
'F')))
3055 std::string MacroMakerSupervisor::generateHexArray(
const std::string& sourceHexString,
3058 std::stringstream retSs;
3060 std::string srcHexStr = sourceHexString;
3061 __SUP_COUT__ <<
"Translating: \n";
3062 __SUP_COUT__ << srcHexStr << __E__;
3064 if(srcHexStr.size() % 2)
3065 srcHexStr =
"0" + srcHexStr;
3067 numOfBytes = srcHexStr.size() / 2;
3068 retSs <<
"[" << numOfBytes <<
"] = {";
3070 for(
int i = 0; i < numOfBytes * 2; i += 2)
3073 if(!((srcHexStr[i] >=
'0' && srcHexStr[i] <=
'9') ||
3074 (srcHexStr[i] >=
'a' && srcHexStr[i] <=
'f') ||
3075 (srcHexStr[i] >=
'A' && srcHexStr[i] <=
'F')) ||
3076 !((srcHexStr[i + 1] >=
'0' && srcHexStr[i + 1] <=
'9') ||
3077 (srcHexStr[i + 1] >=
'a' && srcHexStr[i + 1] <=
'f') ||
3078 (srcHexStr[i + 1] >=
'A' && srcHexStr[i + 1] <=
'F')))
3086 retSs <<
"0x" << srcHexStr[srcHexStr.size() - 1 - i - 1]
3087 << srcHexStr[srcHexStr.size() - 1 - i];
3091 __SUP_COUT__ << retSs.str() << __E__;
3099 const WebUsers::RequestUserInfo& userInfo)
3102 __SUP_COUTT__ << __E__;
3104 uint64_t NotDoneID = CgiDataUtilities::getDataAsUint64_t(cgi,
"NotDoneID");
3107 __SUP_COUT__ <<
"Checking if recent FE macro run has completed for NotDoneID = "
3108 << NotDoneID << __E__;
3110 for(
const auto& feMacroRunThreadStruct : feMacroRunThreadStruct_)
3111 __SUP_COUTT__ <<
"[] threadID_ = "
3112 << feMacroRunThreadStruct.parameters_.threadID_ << __E__;
3114 time_t now = time(0);
3115 size_t target_i = -1;
3116 for(
size_t i = 0; i < feMacroRunThreadStruct_.size(); ++i)
3118 if(feMacroRunThreadStruct_[i].parameters_.threadID_ == NotDoneID)
3121 __SUP_COUTT__ <<
"Found NotDoneID = " << NotDoneID << __E__;
3124 else if(feMacroRunThreadStruct_[i].feMacroRunDone_ &&
3125 now - feMacroRunThreadStruct_[i].parameters_.doneTime_ >
3128 __SUP_COUTT__ <<
"Cleaning up completed NotDoneID = " << NotDoneID
3131 feMacroRunThreadStruct_.erase(feMacroRunThreadStruct_.begin() + i);
3134 else if(now - feMacroRunThreadStruct_[i].parameters_.startTime_ >
3138 <<
"Found old FE Macro exectution of '"
3139 << feMacroRunThreadStruct_[i].parameters_.macroName_ <<
"' at '"
3140 << feMacroRunThreadStruct_[i].parameters_.feUIDSelected_ <<
".'"
3146 if(target_i >= feMacroRunThreadStruct_.size())
3149 <<
"Attempted to check recent FE Macro run completion with invalid ID="
3151 <<
". Perhaps this FE Macro completed more than 5 minutes ago?" << __E__;
3155 if(feMacroRunThreadStruct_[target_i].feMacroRunDone_)
3157 __SUP_COUT__ <<
"Found done for NotDoneID = " << NotDoneID << __E__;
3158 bars_[target_i]->complete();
3160 if(feMacroRunThreadStruct_[target_i].parameters_.feMacroRunError_ !=
"")
3163 << feMacroRunThreadStruct_[target_i].parameters_.feMacroRunError_;
3169 std::ostringstream oss;
3170 feMacroRunThreadStruct_.back().parameters_.xmldoc_.outputXmlDocument(
3172 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3175 feMacroRunThreadStruct_[target_i].parameters_.xmldoc_);
3176 __SUP_COUT__ <<
"FE macro complete." << __E__;
3180 __SUP_COUT__ <<
"Found still going for NotDoneID = " << NotDoneID << __E__;
3182 xmldoc.addNumberElementToData(
"NotDoneID", NotDoneID);
3185 bars_[target_i]->step();
3186 xmldoc.addNumberElementToData(
"Progress", bars_[target_i]->read());
3193 std::string feUIDSelected =
3196 std::string macroName =
3200 bool saveOutputs = CgiDataUtilities::getDataAsInt(cgi,
"saveOutputs") == 1;
3202 __SUP_COUTTV__(feClassSelected);
3203 __SUP_COUTTV__(feUIDSelected);
3204 __SUP_COUTTV__(macroType);
3205 __SUP_COUTTV__(macroName);
3206 __SUP_COUTTV__(inputArgs);
3207 __SUP_COUTTV__(outputArgs);
3208 __SUP_COUTTV__(saveOutputs);
3209 __SUP_COUTTV__(userInfo.username_);
3212 feMacroRunThreadStruct_.emplace_back(
3239 MacroMakerSupervisor::runFEMacroThread(s, mm);
3241 &feMacroRunThreadStruct_.back(),
3244 size_t sleepTime = 10 * 1000;
3247 for(
int i = 0; i < 6; ++i)
3249 if(feMacroRunThreadStruct_.back().feMacroRunDone_)
3251 __SUP_COUTT__ <<
"FE macro marked done" << __E__;
3256 __SUP_COUTT__ <<
"FE macro not done, sleeping..." << __E__;
3258 if(sleepTime > 1000 * 1000 )
3259 sleepTime = 1000 * 1000;
3264 if(!feMacroRunThreadStruct_.back().feMacroRunDone_)
3266 if(t.get_id() == std::thread::id())
3268 __SUP_SS__ <<
"Invalid thread ID. Contact system admins!" << __E__;
3271 feMacroRunThreadStruct_.back().parameters_.threadID_ =
3272 std::hash<std::thread::id>{}(t.get_id());
3274 if(feMacroRunThreadStruct_.back().parameters_.threadID_ == 0)
3276 __SUP_SS__ <<
"Invalid thread ID hash. Contact system admins!" << __E__;
3280 __SUP_COUT__ <<
"FE macro not done, detaching thread="
3281 << feMacroRunThreadStruct_.back().parameters_.threadID_ << __E__;
3285 auto bar = std::make_unique<ProgressBar>();
3286 bar->reset(macroName, feUIDSelected);
3287 bars_.push_back(std::move(bar));
3289 xmldoc.addNumberElementToData(
3290 "NotDoneID", feMacroRunThreadStruct_.back().parameters_.threadID_);
3294 std::ostringstream oss;
3296 &oss,
false ,
true );
3297 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3302 __SUP_COUTT__ <<
"FE macro marked done - joining threads." << __E__;
3304 if(feMacroRunThreadStruct_.back().parameters_.feMacroRunError_ !=
"")
3306 __SUP_SS__ << feMacroRunThreadStruct_.back().parameters_.feMacroRunError_;
3312 std::ostringstream oss;
3313 feMacroRunThreadStruct_.back().parameters_.xmldoc_.outputXmlDocument(
3314 &oss,
false ,
true );
3315 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3317 xmldoc.
copyDataChildren(feMacroRunThreadStruct_.back().parameters_.xmldoc_);
3321 std::ostringstream oss;
3323 &oss,
false ,
true );
3324 __SUP_COUTT__ <<
"xmldoc: " << oss.str() << __E__;
3327 feMacroRunThreadStruct_.pop_back();
3328 __SUP_COUT__ <<
"FE macro complete." << __E__;
3330 for(
const auto& feMacroRunThreadStruct : feMacroRunThreadStruct_)
3331 __SUP_COUTT__ <<
"[] threadID_ = " << feMacroRunThreadStruct.parameters_.threadID_
3335 catch(
const std::runtime_error& e)
3337 __SUP_SS__ <<
"Error processing FE communication request: " << e.what() << __E__;
3338 __SUP_COUT_ERR__ << ss.str();
3339 xmldoc.addTextElementToData(
"Error", ss.str());
3343 __SUP_SS__ <<
"Unknown error processing FE communication request." << __E__;
3348 catch(
const std::exception& e)
3350 ss <<
"Exception message: " << e.what();
3355 __SUP_COUT_ERR__ << ss.str();
3357 xmldoc.addTextElementToData(
"Error", ss.str());
3362 void MacroMakerSupervisor::runFEMacroThread(runFEMacroStruct* feMacroRunThreadStruct,
3366 __COUT__ <<
"runFEMacro thread started... threadid = " << std::this_thread::get_id()
3367 <<
" " << mmSupervisor <<
" getpid()=" << getpid()
3368 <<
" gettid()=" << gettid() << __E__;
3370 mmSupervisor->runFEMacro(feMacroRunThreadStruct->parameters_.xmldoc_,
3371 feMacroRunThreadStruct->parameters_.feClassSelected_,
3372 feMacroRunThreadStruct->parameters_.feUIDSelected_,
3373 feMacroRunThreadStruct->parameters_.macroType_,
3374 feMacroRunThreadStruct->parameters_.macroName_,
3375 feMacroRunThreadStruct->parameters_.inputArgs_,
3376 feMacroRunThreadStruct->parameters_.outputArgs_,
3377 feMacroRunThreadStruct->parameters_.saveOutputs_,
3378 feMacroRunThreadStruct->parameters_.runningUsername_,
3379 feMacroRunThreadStruct->parameters_.userGroupPermissions_);
3381 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3382 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3383 __COUT__ <<
"runFEMacro thread done. threadid = " << std::this_thread::get_id()
3387 catch(
const std::runtime_error& e)
3389 __SS__ <<
"Error during runFEMacro thread: " << e.what() << __E__;
3390 __COUT_ERR__ << ss.str();
3391 feMacroRunThreadStruct->parameters_.feMacroRunError_ = ss.str();
3392 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3393 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3397 __SS__ <<
"Unknown error during runFEMacro thread." << __E__;
3402 catch(
const std::exception& e)
3404 ss <<
"Exception message: " << e.what();
3409 __COUT_ERR__ << ss.str();
3410 feMacroRunThreadStruct->parameters_.feMacroRunError_ = ss.str();
3411 feMacroRunThreadStruct->parameters_.doneTime_ = time(0);
3412 feMacroRunThreadStruct->feMacroRunDone_ =
true;
3417 std::string feClassSelected,
3418 std::string feUIDSelected,
3419 const std::string& macroType,
3420 const std::string& macroName,
3421 const std::string& inputArgs,
3422 const std::string outputArgs,
3424 const std::string& username,
3425 const std::string& userGroupPermissions)
3427 __SUP_COUTV__(feClassSelected);
3428 __SUP_COUTV__(feUIDSelected);
3429 __SUP_COUTV__(macroType);
3430 __SUP_COUTV__(macroName);
3431 __SUP_COUTV__(inputArgs);
3432 __SUP_COUTV__(outputArgs);
3433 __SUP_COUTV__(saveOutputs);
3434 __SUP_COUTV__(username);
3435 __SUP_COUTV__(userGroupPermissions);
3437 appendCommandToHistory(feClassSelected,
3446 std::set<std::string > feUIDs;
3448 if(feUIDSelected ==
"")
3449 feUIDSelected =
"*";
3450 if(feClassSelected ==
"")
3451 feClassSelected =
"*";
3453 if(feClassSelected ==
"" || feUIDSelected ==
"" || macroType ==
"" || macroName ==
"")
3455 __SUP_SS__ <<
"Illegal empty front-end parameter." << __E__;
3458 else if(feUIDSelected !=
"*")
3465 if(feClassSelected ==
"*")
3467 for(
auto& feTypePair : FEPluginTypetoFEsMap_)
3468 for(
auto& feUID : feTypePair.second)
3469 feUIDs.emplace(feUID);
3473 auto typeIt = FEPluginTypetoFEsMap_.find(feClassSelected);
3474 if(typeIt == FEPluginTypetoFEsMap_.end())
3476 __SUP_SS__ <<
"Illegal front-end type parameter '" << feClassSelected
3477 <<
"' not in list of types." << __E__;
3481 for(
auto& feUID : typeIt->second)
3482 feUIDs.emplace(feUID);
3488 std::string macroString;
3489 if(macroType ==
"public")
3490 loadMacro(macroName, macroString);
3491 else if(macroType ==
"private")
3492 loadMacro(macroName, macroString, username);
3494 __SUP_COUTV__(macroString);
3501 std::string filename =
"/macroOutput_" + std::to_string(time(0)) +
"_" +
3502 std::to_string(clock()) +
".txt";
3504 __SUP_COUTV__(filename);
3505 fp = fopen((CodeEditor::OTSDAQ_DATA_PATH + filename).c_str(),
"w");
3508 __SUP_SS__ <<
"Failed to open file to save macro output '"
3509 << CodeEditor::OTSDAQ_DATA_PATH << filename <<
"'..." << __E__;
3513 fprintf(fp,
"############################\n");
3515 "### Running '%s' at time %s\n",
3519 "### \t Target front-ends (count=%lu): %s\n",
3522 fprintf(fp,
"### \t\t Inputs: %s\n", inputArgs.c_str());
3523 fprintf(fp,
"############################\n\n\n");
3525 xmldoc.addTextElementToData(
"feMacroRunArgs_name",
"Filename");
3526 xmldoc.addTextElementToData(
"feMacroRunArgs_value",
3527 "$OTSDAQ_DATA/" + filename);
3531 for(
auto& feUID : feUIDs)
3533 auto feIt = FEtoSupervisorMap_.find(feUID);
3534 if(feIt == FEtoSupervisorMap_.end())
3536 __SUP_SS__ <<
"Destination front end interface ID '" << feUID
3537 <<
"' was not found in the list of front ends." << __E__;
3538 ss <<
"\n\nHere is the map:\n\n"
3543 unsigned int FESupervisorIndex = feIt->second;
3544 __SUP_COUT__ <<
"Found supervisor index: " << FESupervisorIndex << __E__;
3546 SupervisorInfoMap::iterator it = allFESupervisorInfo_.find(FESupervisorIndex);
3547 if(it == allFESupervisorInfo_.end())
3550 <<
"Error transmitting request to FE Supervisor '" << feUID <<
":"
3551 << FESupervisorIndex <<
".' \n\n"
3552 <<
"The FE Supervisor Index does not exist. Have you configured "
3553 "the state machine properly?"
3560 if(macroType ==
"fe")
3561 txParameters.
addParameter(
"Request",
"RunInterfaceMacro");
3563 txParameters.
addParameter(
"Request",
"RunMacroMakerMacro");
3565 if(macroType ==
"fe")
3574 txParameters.
addParameter(
"userPermissions", userGroupPermissions);
3584 "Running '%s' at time %s\n",
3588 "\t Target front-end: '%s::%s'\n",
3589 FEtoPluginTypeMap_[feUID].c_str(),
3592 "\t\t Inputs: %s\n",
3597 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
3598 it->second.getDescriptor(),
3599 "MacroMakerSupervisorRequest",
3602 __SUP_COUT__ <<
"Received response message: "
3603 << SOAPUtilities::translate(retMsg) << __E__;
3605 SOAPUtilities::receive(retMsg, rxParameters);
3607 __SUP_COUT__ <<
"Received it " << __E__;
3610 std::string outputResults = rxParameters.getValue(
"outputArgs");
3611 std::string error = rxParameters.getValue(
"Error");
3614 __SUP_COUT__ <<
"outputArgs = " << outputResults << __E__;
3618 __SS__ <<
"Attempted FE Macro Failed. Attempted target "
3619 <<
"was UID=" << feUID
3620 <<
" at feSupervisorID=" << FESupervisorIndex <<
"." << __E__;
3621 ss <<
"\n\n The error was:\n\n" << error << __E__;
3622 __SUP_COUT_ERR__ <<
"\n" << ss.str();
3623 xmldoc.addTextElementToData(
"Error", ss.str());
3630 DOMElement* feMacroExecParent =
3631 xmldoc.addTextElementToData(
"feMacroExec", macroName);
3637 "fe_type", FEtoPluginTypeMap_[feUID], feMacroExecParent);
3639 "fe_context", it->second.getContextName(), feMacroExecParent);
3641 "fe_supervisor", it->second.getName(), feMacroExecParent);
3643 "fe_hostname", it->second.getHostname(), feMacroExecParent);
3645 std::istringstream inputStream(outputResults);
3646 std::string splitVal, argName, argValue;
3647 while(getline(inputStream, splitVal,
';'))
3649 std::istringstream pairInputStream(splitVal);
3650 getline(pairInputStream, argName,
',');
3651 getline(pairInputStream, argValue,
',');
3656 "\t\t Output '%s' = %s\n",
3663 "outputArgs_name", argName, feMacroExecParent);
3665 "outputArgs_value", argValue, feMacroExecParent);
3667 __SUP_COUT__ << argName <<
": " << argValue << __E__;
3688 const std::string& username)
3690 __SUP_COUT__ <<
"Getting FE Macro list" << __E__;
3693 txParameters.
addParameter(
"Request",
"GetInterfaceMacros");
3698 std::string oneInterface;
3699 std::string rxFEMacros;
3703 for(
auto& appInfo : allFESupervisorInfo_)
3705 __SUP_COUT__ <<
"FESupervisor LID = " << appInfo.second.getId()
3706 <<
" name = " << appInfo.second.getName() << __E__;
3708 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(
3709 appInfo.second.getDescriptor(),
"MacroMakerSupervisorRequest", txParameters);
3710 SOAPUtilities::receive(retMsg, rxParameters);
3712 rxFEMacros = rxParameters.getValue(
"FEMacros");
3714 __SUP_COUT__ <<
"FE Macros received: \n" << rxFEMacros << __E__;
3716 std::istringstream allInterfaces(rxFEMacros);
3717 while(std::getline(allInterfaces, oneInterface))
3721 xmldoc.addTextElementToData(
"FEMacros", oneInterface);
3727 std::pair<std::vector<std::string> ,
3728 std::vector<std::string> >
3730 loadMacroNames(username, macroNames);
3732 __SUP_COUT__ <<
"Public macro count: " << macroNames.first.size() << __E__;
3733 __SUP_COUT__ <<
"Private macro count: " << macroNames.second.size() << __E__;
3735 std::string macroString;
3744 for(
int i = 0; i < 2; ++i)
3745 for(
auto& macroName : (i ? macroNames.second : macroNames.first))
3748 loadMacro(macroName, macroString, username);
3753 std::stringstream xmlMacroStream;
3754 xmlMacroStream << macro.macroName_;
3755 xmlMacroStream <<
":"
3757 xmlMacroStream <<
":" << macro.namesOfInputArguments_.size();
3758 for(
auto& inputArg : macro.namesOfInputArguments_)
3759 xmlMacroStream <<
":" << inputArg;
3760 xmlMacroStream <<
":" << macro.namesOfOutputArguments_.size();
3761 for(
auto& inputArg : macro.namesOfOutputArguments_)
3762 xmlMacroStream <<
":" << inputArg;
3764 xmldoc.addTextElementToData(i ?
"PrivateMacro" :
"PublicMacro",
3765 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)
ConfigurationTree getNode(const std::string &nodeString, bool doNotThrowOnBrokenUIDLinks=false) const
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, std::map< std::string, TableVersion > mergeInTables={}, std::map< std::string, TableVersion > overrideTables={})
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 void getMapFromString(const std::string &inputString, std::map< S, T > &mapToReturn, const std::set< char > &pairPairDelimiter={',', '|', '&'}, const std::set< char > &nameValueDelimiter={'=', ':'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
static std::string decodeURIComponent(const std::string &data)