Commit 4156ba93 authored by Jussi Lindgren's avatar Jussi Lindgren

Everything: Fixes to handling non-compatible scenarios

- Designer will now be more strict in returning an error if non-compatible file is attempted to be loaded as a scenario
- Suppressed the GUI warning about it when running with --no-gui
- Upgraded some warnings to errors
parent d8a77457
...@@ -1037,7 +1037,7 @@ boolean CApplication::openScenario(const char* sFileName) ...@@ -1037,7 +1037,7 @@ boolean CApplication::openScenario(const char* sFileName)
{ {
m_rKernelContext.getLogManager() << LogLevel_Info << "Importing scenario...\n"; m_rKernelContext.getLogManager() << LogLevel_Info << "Importing scenario...\n";
l_pImporter->initialize(); l_bSuccess = l_pImporter->initialize();
TParameterHandler < const IMemoryBuffer* > ip_pMemoryBuffer(l_pImporter->getInputParameter(OVTK_Algorithm_ScenarioImporter_InputParameterId_MemoryBuffer)); TParameterHandler < const IMemoryBuffer* > ip_pMemoryBuffer(l_pImporter->getInputParameter(OVTK_Algorithm_ScenarioImporter_InputParameterId_MemoryBuffer));
TParameterHandler < IScenario* > op_pScenario(l_pImporter->getOutputParameter(OVTK_Algorithm_ScenarioImporter_OutputParameterId_Scenario)); TParameterHandler < IScenario* > op_pScenario(l_pImporter->getOutputParameter(OVTK_Algorithm_ScenarioImporter_OutputParameterId_Scenario));
...@@ -1045,10 +1045,11 @@ boolean CApplication::openScenario(const char* sFileName) ...@@ -1045,10 +1045,11 @@ boolean CApplication::openScenario(const char* sFileName)
ip_pMemoryBuffer=&l_oMemoryBuffer; ip_pMemoryBuffer=&l_oMemoryBuffer;
op_pScenario=&l_rScenario; op_pScenario=&l_rScenario;
l_pImporter->process(); l_bSuccess &= l_pImporter->process();
l_pImporter->uninitialize(); l_bSuccess &= l_pImporter->uninitialize();
m_rKernelContext.getAlgorithmManager().releaseAlgorithm(*l_pImporter); m_rKernelContext.getAlgorithmManager().releaseAlgorithm(*l_pImporter);
l_bSuccess=true;
} }
} }
} }
...@@ -1120,27 +1121,35 @@ boolean CApplication::openScenario(const char* sFileName) ...@@ -1120,27 +1121,35 @@ boolean CApplication::openScenario(const char* sFileName)
} }
else else
{ {
m_rKernelContext.getLogManager() << LogLevel_Warning << "Importing scenario failed...\n"; m_rKernelContext.getLogManager() << LogLevel_Error << "Importing scenario from [" << sFileName << "] failed...\n";
m_pScenarioManager->releaseScenario(l_oScenarioIdentifier); m_pScenarioManager->releaseScenario(l_oScenarioIdentifier);
std::stringstream l_oStringStream; std::stringstream l_oStringStream;
l_oStringStream << "The requested file: " << sFileName << "\n"; l_oStringStream << "The requested file: " << sFileName << "\n";
l_oStringStream << "may either not be an OpenViBE scenario file, \n"; l_oStringStream << "may either not be an OpenViBE scenario file, \n";
l_oStringStream << "be corrupted or not be compatible with \n"; l_oStringStream << "it may be corrupted or not compatible with \n";
l_oStringStream << "the selected scenario importer..."; l_oStringStream << "the selected scenario importer...";
::GtkWidget* l_pErrorDialog=gtk_message_dialog_new( if(!this->isNoGuiActive())
NULL, {
GTK_DIALOG_MODAL, ::GtkWidget* l_pErrorDialog=gtk_message_dialog_new(
GTK_MESSAGE_WARNING, NULL,
GTK_BUTTONS_OK, GTK_DIALOG_MODAL,
"Scenario importation process failed !"); GTK_MESSAGE_WARNING,
gtk_message_dialog_format_secondary_text( GTK_BUTTONS_OK,
GTK_MESSAGE_DIALOG(l_pErrorDialog), "%s", l_oStringStream.str().c_str()); "Scenario importation process failed !");
gtk_dialog_run(GTK_DIALOG(l_pErrorDialog)); gtk_message_dialog_format_secondary_text(
gtk_widget_destroy(l_pErrorDialog); GTK_MESSAGE_DIALOG(l_pErrorDialog), "%s", l_oStringStream.str().c_str());
gtk_dialog_run(GTK_DIALOG(l_pErrorDialog));
gtk_widget_destroy(l_pErrorDialog);
}
else
{
m_rKernelContext.getLogManager() << LogLevel_Error << l_oStringStream.str().c_str() << "\n";
releasePlayer();
return false;
}
} }
} }
return false; return false;
......
...@@ -101,13 +101,17 @@ boolean CAlgorithmProxy::activateInputTrigger( ...@@ -101,13 +101,17 @@ boolean CAlgorithmProxy::activateInputTrigger(
boolean CAlgorithmProxy::initialize(void) boolean CAlgorithmProxy::initialize(void)
{ {
if(m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Can not initialize already initialized algorithm\n"; if(m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Can not initialize already initialized algorithm\n";
return (m_bIsInitialized=m_rAlgorithm.initialize());
m_bIsInitialized=m_rAlgorithm.initialize();
return m_bIsInitialized;
} }
boolean CAlgorithmProxy::uninitialize(void) boolean CAlgorithmProxy::uninitialize(void)
{ {
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Can not uninitialize uninitialized algorithm\n"; if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Can not uninitialize uninitialized algorithm\n";
return (m_bIsInitialized=!m_rAlgorithm.uninitialize());
return (m_bIsInitialized && m_rAlgorithm.uninitialize());
} }
boolean CAlgorithmProxy::process(void) boolean CAlgorithmProxy::process(void)
......
...@@ -63,6 +63,7 @@ CAlgorithmXMLScenarioImporter::CAlgorithmXMLScenarioImporter(void) ...@@ -63,6 +63,7 @@ CAlgorithmXMLScenarioImporter::CAlgorithmXMLScenarioImporter(void)
:m_pContext(NULL) :m_pContext(NULL)
,m_ui32Status(Status_ParsingNothing) ,m_ui32Status(Status_ParsingNothing)
,m_pReader(NULL) ,m_pReader(NULL)
,m_bScenarioRecognized(false)
{ {
m_pReader=XML::createReader(*this); m_pReader=XML::createReader(*this);
} }
...@@ -80,7 +81,7 @@ void CAlgorithmXMLScenarioImporter::openChild(const char* sName, const char** sA ...@@ -80,7 +81,7 @@ void CAlgorithmXMLScenarioImporter::openChild(const char* sName, const char** sA
if(false) { } if(false) { }
else if(l_sTop=="OpenViBE-Scenario" && m_ui32Status==Status_ParsingNothing) { m_ui32Status=Status_ParsingScenario; m_pContext->processStart(OVTK_Algorithm_ScenarioExporter_NodeId_OpenViBEScenario); } else if(l_sTop=="OpenViBE-Scenario" && m_ui32Status==Status_ParsingNothing) { m_ui32Status=Status_ParsingScenario; m_pContext->processStart(OVTK_Algorithm_ScenarioExporter_NodeId_OpenViBEScenario); m_bScenarioRecognized = true; }
else if(l_sTop=="Attribute" && m_ui32Status==Status_ParsingScenario) { m_ui32Status=Status_ParsingScenarioAttribute; m_pContext->processStart(OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Attribute); } else if(l_sTop=="Attribute" && m_ui32Status==Status_ParsingScenario) { m_ui32Status=Status_ParsingScenarioAttribute; m_pContext->processStart(OVTK_Algorithm_ScenarioExporter_NodeId_Scenario_Attribute); }
else if(l_sTop=="Box" && m_ui32Status==Status_ParsingScenario) { m_ui32Status=Status_ParsingBox; m_pContext->processStart(OVTK_Algorithm_ScenarioExporter_NodeId_Box); } else if(l_sTop=="Box" && m_ui32Status==Status_ParsingScenario) { m_ui32Status=Status_ParsingBox; m_pContext->processStart(OVTK_Algorithm_ScenarioExporter_NodeId_Box); }
...@@ -256,5 +257,16 @@ void CAlgorithmXMLScenarioImporter::closeChild(void) ...@@ -256,5 +257,16 @@ void CAlgorithmXMLScenarioImporter::closeChild(void)
boolean CAlgorithmXMLScenarioImporter::import(IAlgorithmScenarioImporterContext& rContext, const IMemoryBuffer& rMemoryBuffer) boolean CAlgorithmXMLScenarioImporter::import(IAlgorithmScenarioImporterContext& rContext, const IMemoryBuffer& rMemoryBuffer)
{ {
m_pContext=&rContext; m_pContext=&rContext;
return m_pReader->processData(rMemoryBuffer.getDirectPointer(), rMemoryBuffer.getSize());
m_bScenarioRecognized = false;
boolean m_bOk = m_pReader->processData(rMemoryBuffer.getDirectPointer(), rMemoryBuffer.getSize());
if(!m_bScenarioRecognized)
{
// This is not a conforming openvibe XML scenario, lacking the <OpenViBE-Scenario> tag
return false;
}
return m_bOk;
} }
...@@ -40,6 +40,8 @@ namespace OpenViBEPlugins ...@@ -40,6 +40,8 @@ namespace OpenViBEPlugins
OpenViBE::uint32 m_ui32Status; OpenViBE::uint32 m_ui32Status;
XML::IReader* m_pReader; XML::IReader* m_pReader;
std::stack < std::string > m_vNodes; std::stack < std::string > m_vNodes;
OpenViBE::boolean m_bScenarioRecognized;
}; };
class CAlgorithmXMLScenarioImporterDesc : public OpenViBEToolkit::CAlgorithmScenarioImporterDesc class CAlgorithmXMLScenarioImporterDesc : public OpenViBEToolkit::CAlgorithmScenarioImporterDesc
......
...@@ -175,7 +175,7 @@ boolean CAlgorithmScenarioImporter::process(void) ...@@ -175,7 +175,7 @@ boolean CAlgorithmScenarioImporter::process(void)
IScenario* l_pScenario=op_pScenario; IScenario* l_pScenario=op_pScenario;
if(!l_pScenario) if(!l_pScenario)
{ {
this->getLogManager() << LogLevel_Warning << "No scenario to import to\n"; this->getLogManager() << LogLevel_Error << "No scenario to import to\n";
return false; return false;
} }
...@@ -183,7 +183,7 @@ boolean CAlgorithmScenarioImporter::process(void) ...@@ -183,7 +183,7 @@ boolean CAlgorithmScenarioImporter::process(void)
IMemoryBuffer* l_pMemoryBuffer=ip_pMemoryBuffer; IMemoryBuffer* l_pMemoryBuffer=ip_pMemoryBuffer;
if(!l_pMemoryBuffer) if(!l_pMemoryBuffer)
{ {
this->getLogManager() << LogLevel_Warning << "No memory buffer to import scenario from\n"; this->getLogManager() << LogLevel_Error << "No memory buffer to import scenario from\n";
return false; return false;
} }
...@@ -196,7 +196,7 @@ boolean CAlgorithmScenarioImporter::process(void) ...@@ -196,7 +196,7 @@ boolean CAlgorithmScenarioImporter::process(void)
CAlgorithmScenarioImporterContext l_oContext(this->getAlgorithmContext()); CAlgorithmScenarioImporterContext l_oContext(this->getAlgorithmContext());
if(!this->import(l_oContext, *l_pMemoryBuffer)) if(!this->import(l_oContext, *l_pMemoryBuffer))
{ {
this->getLogManager() << LogLevel_ImportantWarning << "Import failed\n"; this->getLogManager() << LogLevel_Error << "Import failed\n";
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment