Commit 250f19e7 authored by Serrière Guillaume's avatar Serrière Guillaume

Toolkit: add cpp stimulation files generation.

Signed-off-by: default avatarSerrière Guillaume <guillaume.serriere@inria.fr>
parent 44769d2f
......@@ -178,6 +178,7 @@ ADD_DEFINITIONS(-DOV_CMAKE_PATH_BIN="${CMAKE_INSTALL_FULL_BINDIR}")
ADD_DEFINITIONS(-DOV_CMAKE_PATH_DATA="${CMAKE_INSTALL_FULL_DATADIR}/openvibe")
ADD_DEFINITIONS(-DOV_CMAKE_PATH_LIB="${CMAKE_INSTALL_FULL_LIBDIR}")
ADD_SUBDIRECTORY("build-tool/")
# Traverse these directories and build their components
ADD_SUBDIRECTORY("common/")
ADD_SUBDIRECTORY("openvibe/")
......@@ -194,6 +195,8 @@ ADD_SUBDIRECTORY("documentation/") # needs to be the last since it uses the list
IF(openvibe-documentation)
ADD_DEPENDENCIES(openvibe-documentation openvibe-plugin-inspector)
ENDIF(openvibe-documentation)
ADD_DEPENDENCIES(openvibe-toolkit openvibe-stimulation-generator )
# make a copy of the dependency script, this is done so we can use the same launch scripts both in win install and win devel situations.
IF(WIN32)
INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/scripts/win32-dependencies.cmd DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} RENAME "openvibe-set-env.cmd")
......
# Add all the subdirs as projects of the named branch
OV_ADD_PROJECTS("BUILD_TOOL")
PROJECT(openvibe-stimulation-generator)
SET(PROJECT_VERSION_MAJOR ${OV_GLOBAL_VERSION_MAJOR})
SET(PROJECT_VERSION_MINOR ${OV_GLOBAL_VERSION_MINOR})
SET(PROJECT_VERSION_PATCH ${OV_GLOBAL_VERSION_PATCH})
SET(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
FILE(GLOB_RECURSE source_files src/*.cpp src/*.h src/*.inl)
ADD_EXECUTABLE(openvibe-stimulation-generator ${source_files})
SET(stim_generator_path "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "stim_generator_path")
# ---------------------------------
# Target macros
# Defines target operating system
# Defines target architecture
# Defines target compiler
# ---------------------------------
IF(WIN32)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
ADD_DEFINITIONS(-DTARGET_OS_Windows)
ADD_DEFINITIONS(-DTARGET_ARCHITECTURE_i386)
ADD_DEFINITIONS(-DTARGET_COMPILER_VisualStudio)
ENDIF(WIN32)
IF(UNIX)
# ADD_DEFINITIONS(-fvisibility=hidden) # This flag should be present... man gcc
ADD_DEFINITIONS(-g)
ADD_DEFINITIONS(-fnon-call-exceptions)
ADD_DEFINITIONS(-DTARGET_OS_Linux)
ADD_DEFINITIONS(-DTARGET_ARCHITECTURE_i386)
ADD_DEFINITIONS(-DTARGET_COMPILER_GCC)
ENDIF(UNIX)
#include "defines.h"
#include "file_generator_base.h"
#include <fstream>
using namespace std;
bool CCppCodeGenerator::openFile(const char* sFilename)
{
m_oFile.open(sFilename, ios::out | ios::trunc);
if(!m_oFile.is_open())
return false;
m_oFile << "#include \"toolkit/ovtk_all.h\"" << endl << endl;
m_oFile << "using namespace OpenViBE;" << endl;
m_oFile << "using namespace OpenViBE::Kernel;" << endl;
m_oFile << "using namespace OpenViBEToolkit;" << endl << endl << endl;
m_oFile << "boolean OpenViBEToolkit::initializeStimulationList(const IKernelContext& rKernelContext)" << endl;
m_oFile << "{" << endl;
m_oFile << "\tITypeManager& l_rTypeManager=rKernelContext.getTypeManager();" << endl << endl;
return true;
}
bool CCppCodeGenerator::appendStimulation(SStimulation &rStim)
{
m_oFile << "\tl_rTypeManager.registerEnumerationEntry(OV_TypeId_Stimulation, \""
<< rStim.m_sName
<< "\", "
<< rStim.m_sId
<< ");"
<< endl;
return true;
}
bool CCppCodeGenerator::closeFile(void)
{
m_oFile << endl << "\treturn true;" << endl;
m_oFile << "}" << endl;
m_oFile.close();
return true;
}
#include "defines.h"
#include "file_generator_base.h"
#include <fstream>
using namespace std;
bool CCppDefineGenerator::openFile(const char* sFilename)
{
m_oFile.open(sFilename, ios::out | ios::trunc);
if(!m_oFile.is_open())
return false;
m_oFile << "#ifndef __OpenViBEToolkit_Stimulations_Defines_H__" << endl;
m_oFile << "#define __OpenViBEToolkit_Stimulations_Defines_H__" << endl << endl;
return true;
}
bool CCppDefineGenerator::appendStimulation(SStimulation &rStim)
{
m_oFile << "#define " << rStim.m_sId << " " << rStim.m_sHexaCode << endl;
return true;
}
bool CCppDefineGenerator::closeFile(void)
{
m_oFile << endl << "#endif // __OpenViBEToolkit_Stimulations_Defines_H__" << endl;
m_oFile.close();
return true;
}
#ifndef DEFINES_H
#define DEFINES_H
#include <string>
struct SStimulation{
std::string m_sName;
std::string m_sId;
std::string m_sHexaCode;
};
#endif
\ No newline at end of file
#include "defines.h"
#include <fstream>
class CFileGeneratorBase{
public:
virtual bool openFile(const char* sFilename) =0;
virtual bool appendStimulation(SStimulation &rStim) =0;
virtual bool closeFile(void) =0;
protected:
std::ofstream m_oFile;
};
class CCppDefineGenerator: public CFileGeneratorBase{
public:
virtual bool openFile(const char* sFilename);
virtual bool appendStimulation(SStimulation &rStim);
virtual bool closeFile(void);
};
class CCppCodeGenerator: public CFileGeneratorBase{
public:
virtual bool openFile(const char* sFilename);
virtual bool appendStimulation(SStimulation &rStim);
virtual bool closeFile(void);
};
\ No newline at end of file
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "defines.h"
#include "file_generator_base.h"
using namespace std;
string getBrutHexaCode(string l_oFormatedHexaCode)
{
string res = l_oFormatedHexaCode;
res.erase(res.begin(), res.begin()+2);
return res;
}
int main (int argc, char** argv)
{
if(argc < 3)
return -1;
vector<SStimulation> l_oStimulationList;
vector<CFileGeneratorBase*> l_oGeneratorList;
ifstream l_oStimulationFile(argv[1]);
string l_sName, l_sId, l_sHexaCode;
while(l_oStimulationFile >> l_sName >> l_sId >> l_sHexaCode)
{
SStimulation l_oTemp = {l_sName, l_sId, l_sHexaCode};
l_oStimulationList.push_back(l_oTemp);
}
CFileGeneratorBase* gen = new CCppDefineGenerator();
if(!gen->openFile(argv[2]))
{
cerr << "Unable to open " << argv[2] << endl;
}
l_oGeneratorList.push_back(gen);
gen = new CCppCodeGenerator();
if(!gen->openFile(argv[3]))
{
cerr << "Unable to open " << argv[3] << endl;
}
l_oGeneratorList.push_back(gen);
//Now we generate all files that needs to be done
for(vector<SStimulation>::iterator it = l_oStimulationList.begin(); it != l_oStimulationList.end(); ++it)
{
SStimulation &l_oTemp = *it;
//cout << l_oTemp.m_sName << "," << l_oTemp.m_sId << "," << l_oTemp.m_sHexaCode << endl;
for(vector<CFileGeneratorBase*>::iterator it_gen = l_oGeneratorList.begin(); it_gen != l_oGeneratorList.end(); ++it_gen)
{
(*it_gen)->appendStimulation(l_oTemp);
}
}
for(vector<CFileGeneratorBase*>::iterator it_gen = l_oGeneratorList.begin(); it_gen != l_oGeneratorList.end(); ++it_gen)
{
(*it_gen)->closeFile();
}
return 0;
}
......@@ -6,8 +6,21 @@ SET(PROJECT_VERSION_MINOR ${OV_GLOBAL_VERSION_MINOR})
SET(PROJECT_VERSION_PATCH ${OV_GLOBAL_VERSION_PATCH})
SET(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
#We need to generate the stimulation files
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/toolkit/ovtk_stimulations.h ${CMAKE_CURRENT_SOURCE_DIR}/src/ovtk_stimulations.cpp
DEPENDS openvibe-stimulation-generator
COMMAND echo `pwd` & ${stim_generator_path}/openvibe-stimulation-generator
${CMAKE_CURRENT_SOURCE_DIR}/share/stim
${CMAKE_CURRENT_SOURCE_DIR}/include/toolkit/ovtk_stimulations.h
${CMAKE_CURRENT_SOURCE_DIR}/src/ovtk_stimulations.cpp
COMMENT "Generating stimulation sources..." )
add_custom_target(generate_stimulations_file DEPENDS include/toolkit/ovtk_stimulations.h src/ovtk_stimulations.cpp)
FILE(GLOB_RECURSE source_files src/*.cpp src/*.h src/*.inl src/*.hpp include/*.h)
INCLUDE_DIRECTORIES(${openvibe-toolkit_SOURCE_DIR}/share/)
INCLUDE_DIRECTORIES(${openvibe-toolkit_SOURCE_DIR}/include/)
INCLUDE_DIRECTORIES(${openvibe-toolkit_SOURCE_DIR}/include/toolkit/algorithms/scenario-io)
INCLUDE_DIRECTORIES(${openvibe-toolkit_SOURCE_DIR}/include/toolkit/algorithms/classification)
......@@ -16,7 +29,9 @@ INCLUDE_DIRECTORIES(${openvibe-toolkit_SOURCE_DIR}/include/toolkit/deprecated/re
INCLUDE_DIRECTORIES(${openvibe-toolkit_SOURCE_DIR}/include/toolkit/training)
INCLUDE_DIRECTORIES(${openvibe-toolkit_SOURCE_DIR}/include/toolkit/tools)
ADD_LIBRARY(${PROJECT_NAME} SHARED ${source_files})
ADD_LIBRARY(${PROJECT_NAME} SHARED ${source_files} ${CMAKE_CURRENT_SOURCE_DIR}/src/ovtk_stimulations.cpp)
add_dependencies(openvibe-toolkit generate_stimulations_file)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
......
......@@ -87,10 +87,14 @@
//___________________________________________________________________//
// //
namespace OpenViBEToolkit
{
OV_API OpenViBE::boolean initialize(const OpenViBE::Kernel::IKernelContext& rKernelContext);
OV_API OpenViBE::boolean uninitialize(const OpenViBE::Kernel::IKernelContext& rKernelContext);
//
OpenViBE::boolean initializeStimulationList(const OpenViBE::Kernel::IKernelContext& rKernelContext);
};
#endif // __OpenViBEToolkit_All_H__
This diff is collapsed.
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