Commit cf973945 authored by Jussi Lindgren's avatar Jussi Lindgren

Plugins: Fixed an issue with multiple simultaneous Matlab boxes

parent fea6a949
......@@ -3,6 +3,8 @@
#include "ovpCBoxAlgorithmMatlabScripting.h"
#include <system/ovCMemory.h>
#include <system/ovCMath.h>
#include <iostream>
#include <stdio.h>
#include <sstream>
......@@ -130,18 +132,6 @@ boolean CBoxAlgorithmMatlabScripting::initialize(void)
m_pMatlabEngineHandle = NULL;
m_sMatlabBuffer = NULL;
m_sBoxInstanceVariableName = "OV_BOX_";
// we add a random identifier
srand((unsigned int)time(NULL));
unsigned short int l_ui16Value1=(rand()&0xffff);
unsigned short int l_ui16Value2=(rand()&0xffff);
unsigned short int l_ui16Value3=(rand()&0xffff);
unsigned short int l_ui16Value4=(rand()&0xffff);
char l_sBuffer[1024];
sprintf(l_sBuffer,"0x%04X%04X_0x%04X%04X", (int)l_ui16Value1, (int)l_ui16Value2, (int)l_ui16Value3, (int)l_ui16Value4);
m_sBoxInstanceVariableName = m_sBoxInstanceVariableName + CString(l_sBuffer);
m_sMatlabBuffer = NULL;
CString l_sSettingValue;
getStaticBoxContext().getSettingValue(0, l_sSettingValue);
m_ui64ClockFrequency=::atoi(l_sSettingValue.toASCIIString());
......@@ -306,6 +296,16 @@ boolean CBoxAlgorithmMatlabScripting::initialize(void)
getStaticBoxContext().getSettingValue(2, l_sWorkingDir); // working directory
sanitizePath(l_sWorkingDir);
// Try to find an unused box instance variable name
do
{
char l_sBuffer[1024];
sprintf(l_sBuffer, "OV_BOX_0x%08X_0x%08X", System::Math::randomUInteger32(), System::Math::randomUInteger32());
m_sBoxInstanceVariableName = CString(l_sBuffer);
this->getLogManager() << LogLevel_Trace << "Checking if variable " << m_sBoxInstanceVariableName << " is in use...\n";
} while (engGetVariable(m_pMatlabEngine, m_sBoxInstanceVariableName.toASCIIString() ) != NULL);
this->getLogManager() << LogLevel_Trace << "Selected variable name " << m_sBoxInstanceVariableName << "\n";
this->getLogManager() << LogLevel_Trace << "Setting working directory to " << l_sWorkingDir << "\n";
l_sCommand = CString("cd '") + l_sWorkingDir + CString("'");
if(!checkFailureRoutine(::engEvalString(m_pMatlabEngine, l_sCommand) == 0, "An error occurred while changing the working directory\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