From 204e91b73b20bc171317a0e881bb124fd3449776 Mon Sep 17 00:00:00 2001 From: Giuseppe Carboni Date: Tue, 26 May 2020 15:53:34 +0200 Subject: [PATCH] Fix #539, parser now supports strings as return. Added a welcome message to the user (SRT). (#543) * Fix issue #539: parser expanded in order to support strings as return value. logString_type added to types list. This now should allow to 'project' command to send a wellcome message to the user. * Fix #539. Added a custom welcome message for the SRT station. The message reminds the user, whenever the `project` command is issued, to check the status of the telescope in the relative webpage. * Fix #539, moved the welcomeMessage parameter to DataBlock Co-authored-by: Andrea Orlati --- .../SystemTerminal/src/_tui_SysTerm.py | 35 +++++++++++++------ .../config/CDB/schemas/Station.xsd | 4 ++- .../ManagmentInterface/idl/Scheduler.idl | 5 +-- .../ParserLibrary/include/SP_typeConversion.h | 13 +++++++ .../ParserLibrary/include/SP_types.h | 1 + .../ParserLibrary/src/TestParser.cpp | 13 +++++++ .../Servers/Scheduler/include/Configuration.h | 6 ++++ .../Scheduler/include/Core_Operations.h | 3 +- .../Servers/Scheduler/include/SchedulerImpl.h | 3 +- .../Servers/Scheduler/src/Configuration.cpp | 13 +++++++ Common/Servers/Scheduler/src/Core.cpp | 2 +- .../Servers/Scheduler/src/Core_Operations.i | 7 +++- .../Servers/Scheduler/src/SchedulerImpl.cpp | 6 ++-- .../CDB/alma/DataBlock/Station/Station.xml | 3 +- .../CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml | 2 +- .../CDB/alma/DataBlock/Station/Station.xml | 3 +- .../CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml | 2 +- Noto/CDB/alma/DataBlock/Station/Station.xml | 3 +- .../CDB/alma/DataBlock/Station/Station.xml | 3 +- SRT/CDB/alma/DataBlock/Station/Station.xml | 3 +- SRT/CDB/alma/MANAGEMENT/Gavino/Gavino.xml | 2 +- .../CDB/alma/DataBlock/Station/Station.xml | 3 +- .../CDB/alma/MANAGEMENT/Gavino/Gavino.xml | 2 +- 23 files changed, 107 insertions(+), 30 deletions(-) diff --git a/Common/Clients/SystemTerminal/src/_tui_SysTerm.py b/Common/Clients/SystemTerminal/src/_tui_SysTerm.py index dfbc8a579..436552f03 100644 --- a/Common/Clients/SystemTerminal/src/_tui_SysTerm.py +++ b/Common/Clients/SystemTerminal/src/_tui_SysTerm.py @@ -133,7 +133,6 @@ def main(): cmd=raw_input("<%d> "%cmdCounter) except IOError: cmd='exit' - pass else: cmd="version" cmdCounter=cmdCounter+1 @@ -157,15 +156,24 @@ def main(): idx = res.find('\\') cmd_name, response = res[:idx+1], res[idx+1:].rstrip('\\') if success and response: - groups = response.split(',') - for group in groups: - values = group.split(';') - if len(values) > 1: - print cmd_name - for i, value in enumerate(values): - print '%02d) %s' %(i, value) - elif res: - print res + if response.startswith('STR '): + # We got a formatted string in return, print it + # without any modification + response = response[4:] + lines = response.split('\n') + print cmd_name + for line in lines: + print line + else: + groups = response.split(',') + for group in groups: + values = group.split(';') + if len(values) > 1: + print cmd_name + for i, value in enumerate(values): + print '%02d) %s' %(i, value) + elif res: + print res elif res: print res except Exception, ex: @@ -173,8 +181,13 @@ def main(): newEx.setAction("command()") newEx.setReason(ex.message) newEx.log(simpleClient.getLogger(),ACSLog.ACS_LOG_ERROR) - except KeyboardInterrupt: + except EOFError: + # CTRL + D event: Equivalent to the exit command, we stop the loop stopAll=True + except KeyboardInterrupt: + # CTRL + C event: Ignore whatever string was written on the + # terminal and show a new prompt line + print '^C' readline.write_history_file(historyFile) simpleClient.releaseComponent(compName) diff --git a/Common/Interfaces/AntennaInterface/config/CDB/schemas/Station.xsd b/Common/Interfaces/AntennaInterface/config/CDB/schemas/Station.xsd index 97741a9e7..8959f9c44 100644 --- a/Common/Interfaces/AntennaInterface/config/CDB/schemas/Station.xsd +++ b/Common/Interfaces/AntennaInterface/config/CDB/schemas/Station.xsd @@ -33,9 +33,11 @@ + + - \ No newline at end of file + diff --git a/Common/Interfaces/ManagmentInterface/idl/Scheduler.idl b/Common/Interfaces/ManagmentInterface/idl/Scheduler.idl index 675fc059e..d1aad1d63 100644 --- a/Common/Interfaces/ManagmentInterface/idl/Scheduler.idl +++ b/Common/Interfaces/ManagmentInterface/idl/Scheduler.idl @@ -204,11 +204,12 @@ module Management { /** * This method sets the current project code. If the project does not exists an error is thrown. - * @param code code of the project, if blank the selected code will be default one + * @param code code of the project, if blank the selected code will be default one + * @param message this will returns a wellcome message from the control software * @throw ManagementErrors::ManagementErrorsEx * @throw CORBA::SystemExcpetion */ - void setProjectCode(in string code) raises (ManagementErrors::ManagementErrorsEx); + void setProjectCode(in string code, out string message) raises (ManagementErrors::ManagementErrorsEx); /** * It allows to immediately start a scan that involves a primary focus axis or a subreflector axis. The scan is performed of the currently diff --git a/Common/Libraries/ParserLibrary/include/SP_typeConversion.h b/Common/Libraries/ParserLibrary/include/SP_typeConversion.h index ed2f9da44..822347d11 100644 --- a/Common/Libraries/ParserLibrary/include/SP_typeConversion.h +++ b/Common/Libraries/ParserLibrary/include/SP_typeConversion.h @@ -107,6 +107,19 @@ public: } }; +class longString_converter +{ +public: + IRA::CString strToVal(const char * str) throw (ParserErrors::BadTypeFormatExImpl) { + return IRA::CString(str); + } + char *valToStr(const IRA::CString& val) { + char *c=new char[val.GetLength()+1]; + strcpy(c,(const char*)val); + return c; + } +}; + template <_sp_symbols OUT> class angle_converter { public: diff --git a/Common/Libraries/ParserLibrary/include/SP_types.h b/Common/Libraries/ParserLibrary/include/SP_types.h index 6ec8c6d17..af1269ccc 100644 --- a/Common/Libraries/ParserLibrary/include/SP_types.h +++ b/Common/Libraries/ParserLibrary/include/SP_types.h @@ -163,6 +163,7 @@ typedef basic_type time_type; typedef basic_type interval_type; typedef basic_type longSeq_type; typedef basic_type doubleSeq_type; +typedef basic_type longString_type; class string_type: public virtual basic_type diff --git a/Common/Libraries/ParserLibrary/src/TestParser.cpp b/Common/Libraries/ParserLibrary/src/TestParser.cpp index 6c8e6a1b7..d621ddddd 100644 --- a/Common/Libraries/ParserLibrary/src/TestParser.cpp +++ b/Common/Libraries/ParserLibrary/src/TestParser.cpp @@ -47,6 +47,16 @@ void positivo(const long& var,TBools& res) { void stampa(const char *str) { printf("%s\n",str); } + +void answer(const char *str,IRA::CString& answer) const +{ + if (str!=NULL) { + answer.Format("Wellcome %s",str); + } + else { + answer="Wellcome"; + } +} int somma(const int&i,const int&j) { return i+j; } @@ -175,6 +185,9 @@ int main(int argc, char *argv[]) parser.add("sumSeq",new function1 >(&test,&CTest::sumSeq),1); parser.add("sequence",new function2,I >(&test,&CTest::sequence),1); parser.add("wait",new function1 >(&test,&CTest::wait),1); + + parser.add("answer",new function2, O >(&test,&CTest::answer),1); + parser.add("naviga","firefox",1); diff --git a/Common/Servers/Scheduler/include/Configuration.h b/Common/Servers/Scheduler/include/Configuration.h index 700764f2a..e49eb4fb7 100644 --- a/Common/Servers/Scheduler/include/Configuration.h +++ b/Common/Servers/Scheduler/include/Configuration.h @@ -219,6 +219,11 @@ public: */ const IRA::CString& getRecordingLockFile() const { return m_recordingLockFile;} + /** + * @return the welcome message string + */ + const IRA::CString& getWelcomeMessage() const { return m_welcomeMessage;} + private: IRA::CString m_schedDir; IRA::CString m_dataDir; @@ -241,6 +246,7 @@ private: IRA::CString m_proceduresLocation; IRA::CString m_defaultProceduresFile; IRA::CString m_defaultProjectCode; + IRA::CString m_welcomeMessage; bool m_checkProjectCode; long m_minorServoMappings; long m_fTrackDigits; diff --git a/Common/Servers/Scheduler/include/Core_Operations.h b/Common/Servers/Scheduler/include/Core_Operations.h index 6988c0ee6..54b2cdbf4 100644 --- a/Common/Servers/Scheduler/include/Core_Operations.h +++ b/Common/Servers/Scheduler/include/Core_Operations.h @@ -132,9 +132,10 @@ void _setDevice(const long& deviceID) throw (ComponentErrors::CouldntGetComponen * It allows to set a new project code. If requested by the component configuration (CheckProjectCode) the project is checked to be registered in the system. * If not present an error is thrown. The check consist in verifying a folder named "code" exists in SchedDir of the configuration. * @param code new project code + * @param message this is a wellcome message from the control system * @throw ManagementErrors::UnkownProjectCodeErrorExImpl */ -void _setProjectCode(const char* code) throw (ManagementErrors::UnkownProjectCodeErrorExImpl); +void _setProjectCode(const char* code,IRA::CString& message) throw (ManagementErrors::UnkownProjectCodeErrorExImpl); /** * called to set proper values for the rest frequency diff --git a/Common/Servers/Scheduler/include/SchedulerImpl.h b/Common/Servers/Scheduler/include/SchedulerImpl.h index e022c41d5..d700bedf9 100644 --- a/Common/Servers/Scheduler/include/SchedulerImpl.h +++ b/Common/Servers/Scheduler/include/SchedulerImpl.h @@ -305,10 +305,11 @@ public: * This method allows to set the current running project code. The code will be used to locate schedules files and to store data files on system disks. If the project is not present/registered in the * system an error is thrown. * @param code new project code. If an empty string is given the default code is adopted, the default code is part of the component configuration. + * @param message a wellcome message from control software * @throw CORBA::SystemException * @throw ManagementErrors::ManagementErrorsEx */ - virtual void setProjectCode(const char *code) throw (CORBA::SystemException,ManagementErrors::ManagementErrorsEx); + virtual void setProjectCode(const char *code,CORBA::String_out message) throw (CORBA::SystemException,ManagementErrors::ManagementErrorsEx); /** * This method allow to set the current value for the rest frequency diff --git a/Common/Servers/Scheduler/src/Configuration.cpp b/Common/Servers/Scheduler/src/Configuration.cpp index cbd199194..69003a17c 100644 --- a/Common/Servers/Scheduler/src/Configuration.cpp +++ b/Common/Servers/Scheduler/src/Configuration.cpp @@ -300,6 +300,19 @@ void CConfiguration::init(maci::ContainerServices *Services) throw (ComponentErr ACS_LOG(LM_FULL_INFO,"CConfiguration::init()",(LM_WARNING,"Default backend does not exist")); m_currentBackendIndex=-1; } + + if (!CIRATools::getDBValue(Services,"welcomeMessage",m_welcomeMessage,"alma/","DataBlock/Station")) { + m_welcomeMessage = (const char*)""; + } + std::string welcomeMessage = std::string(m_welcomeMessage); + //Replace every occurrence of the string "\n" (2 characters) with a new line character + while(true) { + std::size_t found = welcomeMessage.find("\\n"); + if(found == std::string::npos) + break; + welcomeMessage.replace(found, 2, "\n"); + } + m_welcomeMessage = welcomeMessage.c_str(); } Management::TScanAxis CConfiguration::str2Axis(const IRA::CString& axis) const diff --git a/Common/Servers/Scheduler/src/Core.cpp b/Common/Servers/Scheduler/src/Core.cpp index 8024f029d..aaefba4a2 100644 --- a/Common/Servers/Scheduler/src/Core.cpp +++ b/Common/Servers/Scheduler/src/Core.cpp @@ -123,7 +123,7 @@ void CCore::execute() throw (ComponentErrors::TimerErrorExImpl,ComponentErrors:: m_parser->add("log",new function1 >(this,&CCore::_changeLogFile),1); m_parser->add("logMessage",new function1 >(this,&CCore::_logMessage),1); m_parser->add("wx",new function4,O,O,O >(this,&CCore::_getWeatherStationParameters),0); - m_parser->add("project",new function1 >(this,&CCore::_setProjectCode),1); + m_parser->add("project",new function2,O >(this,&CCore::_setProjectCode),1); // no range checks because * is allowed m_parser->add("skydip",new function3 >,I >,I >(this,&CCore::skydip),3); m_parser->add("agc","_tp_agc",2,"NONE"); diff --git a/Common/Servers/Scheduler/src/Core_Operations.i b/Common/Servers/Scheduler/src/Core_Operations.i index 8875c6a8d..bb03cb7b4 100644 --- a/Common/Servers/Scheduler/src/Core_Operations.i +++ b/Common/Servers/Scheduler/src/Core_Operations.i @@ -733,7 +733,7 @@ void CCore::_fTrack(const char *dev) throw (ComponentErrors::CouldntGetComponent } } -void CCore::_setProjectCode(const char* code) throw (ManagementErrors::UnkownProjectCodeErrorExImpl) +void CCore::_setProjectCode(const char* code,IRA::CString& message) throw (ManagementErrors::UnkownProjectCodeErrorExImpl) { IRA::CString newCode(code); if (newCode=="''") { // if '' given...maps to default user @@ -750,6 +750,11 @@ void CCore::_setProjectCode(const char* code) throw (ManagementErrors::UnkownPro if (m_schedExecuter) { m_schedExecuter->setProjectCode(newCode); } + std::string msg = "Welcome to this facility, " + std::string(code) + "!"; + std::string welcome = std::string(m_config->getWelcomeMessage()); + if(welcome != "") + msg += "\n" + welcome; + message.Format("STR %s", msg.c_str()); } /*void CCore::_winkingMark(const char *arg) throw (ComponentErrors::ValidationErrorExImpl); diff --git a/Common/Servers/Scheduler/src/SchedulerImpl.cpp b/Common/Servers/Scheduler/src/SchedulerImpl.cpp index a36f333f4..9d39125c1 100644 --- a/Common/Servers/Scheduler/src/SchedulerImpl.cpp +++ b/Common/Servers/Scheduler/src/SchedulerImpl.cpp @@ -362,10 +362,12 @@ void SchedulerImpl::fTrack(const char* dev) throw (ComponentErrors::ComponentErr m_core->_fTrack(dev); } -void SchedulerImpl::setProjectCode(const char *code) throw (CORBA::SystemException,ManagementErrors::ManagementErrorsEx) +void SchedulerImpl::setProjectCode(const char *code, CORBA::String_out message) throw (CORBA::SystemException,ManagementErrors::ManagementErrorsEx) { + IRA::CString msg; try { - m_core->_setProjectCode(code); + m_core->_setProjectCode(code, msg); + message=(const char *)msg; } catch (ManagementErrors::ManagementErrorsExImpl& ex) { ex.log(LM_DEBUG); diff --git a/Medicina/CDB/alma/DataBlock/Station/Station.xml b/Medicina/CDB/alma/DataBlock/Station/Station.xml index 882640efc..4f0e8522d 100644 --- a/Medicina/CDB/alma/DataBlock/Station/Station.xml +++ b/Medicina/CDB/alma/DataBlock/Station/Station.xml @@ -16,4 +16,5 @@ height="28.0" yPolarMotion="0.0" xPolarMotion="0.0" - geodeticModel="0" /> + geodeticModel="0" + welcomeMessage="" /> diff --git a/Medicina/CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml b/Medicina/CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml index 11a597382..7e0cc626b 100644 --- a/Medicina/CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml +++ b/Medicina/CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml @@ -30,7 +30,7 @@ DefaultBackendInstance="BACKENDS/TotalPower" DefaultDataReceiverInstance="MANAGEMENT/FitsZilla" DefaultProjectCode="maintenance" - CheckProjectCode="false" + CheckProjectCode="true" > diff --git a/Medicina/Configuration/CDB/alma/DataBlock/Station/Station.xml b/Medicina/Configuration/CDB/alma/DataBlock/Station/Station.xml index 882640efc..4f0e8522d 100644 --- a/Medicina/Configuration/CDB/alma/DataBlock/Station/Station.xml +++ b/Medicina/Configuration/CDB/alma/DataBlock/Station/Station.xml @@ -16,4 +16,5 @@ height="28.0" yPolarMotion="0.0" xPolarMotion="0.0" - geodeticModel="0" /> + geodeticModel="0" + welcomeMessage="" /> diff --git a/Medicina/Configuration/CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml b/Medicina/Configuration/CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml index 11a597382..7e0cc626b 100644 --- a/Medicina/Configuration/CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml +++ b/Medicina/Configuration/CDB/alma/MANAGEMENT/Palmiro/Palmiro.xml @@ -30,7 +30,7 @@ DefaultBackendInstance="BACKENDS/TotalPower" DefaultDataReceiverInstance="MANAGEMENT/FitsZilla" DefaultProjectCode="maintenance" - CheckProjectCode="false" + CheckProjectCode="true" > diff --git a/Noto/CDB/alma/DataBlock/Station/Station.xml b/Noto/CDB/alma/DataBlock/Station/Station.xml index 6c71799b2..ea4f26624 100644 --- a/Noto/CDB/alma/DataBlock/Station/Station.xml +++ b/Noto/CDB/alma/DataBlock/Station/Station.xml @@ -16,4 +16,5 @@ height="32.0" yPolarMotion="0.0" xPolarMotion="0.0" - geodeticModel="0" /> + geodeticModel="0" + welcomeMessage="" /> diff --git a/Noto/Configuration/CDB/alma/DataBlock/Station/Station.xml b/Noto/Configuration/CDB/alma/DataBlock/Station/Station.xml index 6c71799b2..ea4f26624 100644 --- a/Noto/Configuration/CDB/alma/DataBlock/Station/Station.xml +++ b/Noto/Configuration/CDB/alma/DataBlock/Station/Station.xml @@ -16,4 +16,5 @@ height="32.0" yPolarMotion="0.0" xPolarMotion="0.0" - geodeticModel="0" /> + geodeticModel="0" + welcomeMessage="" /> diff --git a/SRT/CDB/alma/DataBlock/Station/Station.xml b/SRT/CDB/alma/DataBlock/Station/Station.xml index b541a6a66..e30eebd0a 100644 --- a/SRT/CDB/alma/DataBlock/Station/Station.xml +++ b/SRT/CDB/alma/DataBlock/Station/Station.xml @@ -17,4 +17,5 @@ height="700.0" yPolarMotion="0.0" xPolarMotion="0.0" - geodeticModel="0" /> + geodeticModel="0" + welcomeMessage="Before starting to observe, it is important that you check the status of the telescope visiting the following website:\nhttps://bit.ly/2Xf3aUl\nYou can find it as a bookmark in the browser as well." /> diff --git a/SRT/CDB/alma/MANAGEMENT/Gavino/Gavino.xml b/SRT/CDB/alma/MANAGEMENT/Gavino/Gavino.xml index 7969bde5d..8bf8de487 100644 --- a/SRT/CDB/alma/MANAGEMENT/Gavino/Gavino.xml +++ b/SRT/CDB/alma/MANAGEMENT/Gavino/Gavino.xml @@ -30,7 +30,7 @@ DefaultBackendInstance="BACKENDS/TotalPower" DefaultDataReceiverInstance="MANAGEMENT/FitsZilla" DefaultProjectCode="Maintenance" - CheckProjectCode="false" + CheckProjectCode="true" > diff --git a/SRT/Configuration/CDB/alma/DataBlock/Station/Station.xml b/SRT/Configuration/CDB/alma/DataBlock/Station/Station.xml index 7b56a74e5..2fd571543 100644 --- a/SRT/Configuration/CDB/alma/DataBlock/Station/Station.xml +++ b/SRT/Configuration/CDB/alma/DataBlock/Station/Station.xml @@ -17,4 +17,5 @@ height="650.0" yPolarMotion="0.0" xPolarMotion="0.0" - geodeticModel="0" /> + geodeticModel="0" + welcomeMessage="Before starting to observe, it is important that you check the status of the telescope visiting the following website:\nhttps://bit.ly/2Xf3aUl\nYou can find it as a bookmark in the browser as well." /> diff --git a/SRT/Configuration/CDB/alma/MANAGEMENT/Gavino/Gavino.xml b/SRT/Configuration/CDB/alma/MANAGEMENT/Gavino/Gavino.xml index fbbdbdcda..0e7feb798 100644 --- a/SRT/Configuration/CDB/alma/MANAGEMENT/Gavino/Gavino.xml +++ b/SRT/Configuration/CDB/alma/MANAGEMENT/Gavino/Gavino.xml @@ -30,7 +30,7 @@ DefaultBackendInstance="BACKENDS/TotalPower" DefaultDataReceiverInstance="MANAGEMENT/FitsZilla" DefaultProjectCode="Maintenance" - CheckProjectCode="false" + CheckProjectCode="true" > -- GitLab