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)
{
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 < IScenario* > op_pScenario(l_pImporter->getOutputParameter(OVTK_Algorithm_ScenarioImporter_OutputParameterId_Scenario));
......@@ -1045,10 +1045,11 @@ boolean CApplication::openScenario(const char* sFileName)
ip_pMemoryBuffer=&l_oMemoryBuffer;
op_pScenario=&l_rScenario;
l_pImporter->process();
l_pImporter->uninitialize();
l_bSuccess &= l_pImporter->process();
l_bSuccess &= l_pImporter->uninitialize();
m_rKernelContext.getAlgorithmManager().releaseAlgorithm(*l_pImporter);
l_bSuccess=true;
}
}
}
......@@ -1120,16 +1121,18 @@ boolean CApplication::openScenario(const char* sFileName)
}
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);
std::stringstream l_oStringStream;
l_oStringStream << "The requested file: " << sFileName << "\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...";
if(!this->isNoGuiActive())
{
::GtkWidget* l_pErrorDialog=gtk_message_dialog_new(
NULL,
GTK_DIALOG_MODAL,
......@@ -1140,7 +1143,13 @@ boolean CApplication::openScenario(const char* sFileName)
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;
......
......@@ -101,13 +101,17 @@ boolean CAlgorithmProxy::activateInputTrigger(
boolean CAlgorithmProxy::initialize(void)
{
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)
{
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)
......
......@@ -63,6 +63,7 @@ CAlgorithmXMLScenarioImporter::CAlgorithmXMLScenarioImporter(void)
:m_pContext(NULL)
,m_ui32Status(Status_ParsingNothing)
,m_pReader(NULL)
,m_bScenarioRecognized(false)
{
m_pReader=XML::createReader(*this);
}
......@@ -80,7 +81,7 @@ void CAlgorithmXMLScenarioImporter::openChild(const char* sName, const char** sA
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=="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)
boolean CAlgorithmXMLScenarioImporter::import(IAlgorithmScenarioImporterContext& rContext, const IMemoryBuffer& rMemoryBuffer)
{
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
OpenViBE::uint32 m_ui32Status;
XML::IReader* m_pReader;
std::stack < std::string > m_vNodes;
OpenViBE::boolean m_bScenarioRecognized;
};
class CAlgorithmXMLScenarioImporterDesc : public OpenViBEToolkit::CAlgorithmScenarioImporterDesc
......
......@@ -175,7 +175,7 @@ boolean CAlgorithmScenarioImporter::process(void)
IScenario* l_pScenario=op_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;
}
......@@ -183,7 +183,7 @@ boolean CAlgorithmScenarioImporter::process(void)
IMemoryBuffer* l_pMemoryBuffer=ip_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;
}
......@@ -196,7 +196,7 @@ boolean CAlgorithmScenarioImporter::process(void)
CAlgorithmScenarioImporterContext l_oContext(this->getAlgorithmContext());
if(!this->import(l_oContext, *l_pMemoryBuffer))
{
this->getLogManager() << LogLevel_ImportantWarning << "Import failed\n";
this->getLogManager() << LogLevel_Error << "Import failed\n";
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