...
 
Commits (6)
......@@ -178,6 +178,7 @@ endif(PROCESSLIB_ENABLE_GSL)
target_include_directories(processlib PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/core/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tasks/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
if(WIN32)
......@@ -195,7 +196,7 @@ if(CMAKE_THREAD_LIBS_INIT)
endif()
if(WIN32)
target_compile_definitions(processlib PRIVATE LIBPROCESSLIB_EXPORTS)
target_compile_definitions(processlib PRIVATE processlib_EXPORTS)
set_target_properties(processlib PROPERTIES PREFIX "lib")
set_target_properties(processlib PROPERTIES IMPORT_PREFIX "lib")
endif()
......@@ -209,6 +210,7 @@ if(PROCESSLIB_ENABLE_PYTHON)
set(SIP_DISABLE_FEATURES "BPM_SUPPORT")
endif(NOT PROCESSLIB_ENABLE_GSL)
add_sip_python_module(processlib "${CMAKE_CURRENT_BINARY_DIR}/sip/processlib.sip")
target_compile_definitions(python_module_processlib PRIVATE processlib_EXPORTS)
target_include_directories(python_module_processlib PRIVATE ${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/sip)
target_link_libraries(python_module_processlib PRIVATE processlib)
endif()
......@@ -283,8 +285,13 @@ endif()
## Tests
if(PROCESSLIB_ENABLE_TESTS)
find_package(Boost COMPONENTS
unit_test_framework
REQUIRED
)
enable_testing()
#add_subdirectory(test)
add_subdirectory(test)
endif()
# Packages
......
//###########################################################################
// This file is part of ProcessLib, a submodule of LImA project the
// Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#if !defined(PROCESSLIB_COMPATIBILITY_H)
#define PROCESSLIB_COMPATIBILITY_H
#ifdef WIN32
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
#ifdef WIN32
#if (_WIN32_WINNT < _WIN32_WINNT_LONGHORN)
#define PTHREAD_WIN_XP_SYNC
#endif
#endif
#endif //! defined(PROCESSLIB_COMPATIBILITY_H)
......@@ -39,12 +39,12 @@
#include <string>
#include <vector>
#include "processlib/Compatibility.h"
#include <processlib_export.h>
#include "processlib/ProcessExceptions.h"
struct DLL_EXPORT Buffer
struct PROCESSLIB_EXPORT Buffer
{
class DLL_EXPORT Callback
class PROCESSLIB_EXPORT Callback
{
public:
virtual ~Callback() {}
......@@ -93,9 +93,9 @@ struct DLL_EXPORT Buffer
std::mutex _mutex;
Callback *callback;
};
struct DLL_EXPORT Data
struct PROCESSLIB_EXPORT Data
{
class DLL_EXPORT HeaderContainer
class PROCESSLIB_EXPORT HeaderContainer
{
public:
typedef std::map<std::string, std::string> Header;
......@@ -567,7 +567,7 @@ Data Data::cast(Data::TYPE aType)
return aReturnData;
}
DLL_EXPORT std::ostream &operator<<(std::ostream &os, const Data::HeaderContainer &aHeader);
PROCESSLIB_EXPORT std::ostream &operator<<(std::ostream &os, const Data::HeaderContainer &aHeader);
inline std::ostream &operator<<(std::ostream &os, const Buffer &aBuffer)
{
......
......@@ -35,11 +35,11 @@
#include <string>
#include <thread>
#include "processlib/Compatibility.h"
#include <processlib_export.h>
/** @brief this class manage error message in thread safe maner
*/
class DLL_EXPORT GslErrorMgr
class PROCESSLIB_EXPORT GslErrorMgr
{
typedef std::map<std::thread::id, std::string> ErrorMessageType;
typedef std::map<std::thread::id, int> ErrnoType;
......
......@@ -29,7 +29,8 @@
#include "processlib/Data.h"
#include "processlib/TaskEventCallback.h"
class DLL_EXPORT LinkTask
class PROCESSLIB_EXPORT LinkTask
{
public:
LinkTask();
......
......@@ -37,19 +37,17 @@
#include <thread>
#include <vector>
#include "processlib/Compatibility.h"
#include <processlib_export.h>
class TaskMgr;
struct Data;
class DLL_EXPORT PoolThreadMgr
class PROCESSLIB_EXPORT PoolThreadMgr
{
public:
typedef std::pair<int, int> TaskPriority;
PoolThreadMgr() = default;
~PoolThreadMgr() = default;
static PoolThreadMgr &get() throw();
static PoolThreadMgr &get();
void addProcess(TaskMgr *aProcess, bool lock = true);
void removeProcess(TaskMgr *aProcess, bool lock = true);
......@@ -63,6 +61,12 @@ class DLL_EXPORT PoolThreadMgr
void quit();
private:
// Thread safe Singleton (guaranted in C++11)
PoolThreadMgr() : _stopFlag(false), _suspendFlag(false), _runningThread(0), _taskMgr(NULL) {}
~PoolThreadMgr()= default;
PoolThreadMgr(const PoolThreadMgr&)= delete;
PoolThreadMgr& operator=(const PoolThreadMgr&)= delete;
struct cmp
{
bool operator()(const TaskPriority &a, const TaskPriority &b)
......
......@@ -32,7 +32,7 @@
#include "processlib/SinkTaskMgr.h"
#include "processlib/TaskEventCallback.h"
class DLL_EXPORT SinkTaskBase
class PROCESSLIB_EXPORT SinkTaskBase
{
public:
SinkTaskBase();
......
......@@ -35,7 +35,7 @@
#include "processlib/PoolThreadMgr.h"
template <class Result>
class DLL_EXPORT SinkTaskMgr
class PROCESSLIB_EXPORT SinkTaskMgr
{
typedef std::vector<Result> FrameResultList;
......
......@@ -30,7 +30,7 @@
#include <stdlib.h>
#include <string>
class DLL_EXPORT Stat
class PROCESSLIB_EXPORT Stat
{
public:
Stat(const Data &data, const std::string &info) : _data(data), _info(info)
......
......@@ -30,7 +30,7 @@
#include "processlib/Data.h"
class DLL_EXPORT TaskEventCallback
class PROCESSLIB_EXPORT TaskEventCallback
{
public:
TaskEventCallback();
......
......@@ -26,7 +26,7 @@
#if !defined(PROCESSLIB_TASKMGR_H)
#define PROCESSLIB_TASKMGR_H
#include "processlib/Compatibility.h"
#include <processlib_export.h>
#include "processlib/Data.h"
#include <deque>
......@@ -34,7 +34,7 @@ class LinkTask;
class SinkTaskBase;
class PoolThreadMgr;
class DLL_EXPORT TaskMgr
class PROCESSLIB_EXPORT TaskMgr
{
friend class PoolThreadMgr;
struct Task
......
......@@ -194,9 +194,12 @@ void PoolThreadMgr::_createProcessThread(size_t aNumber)
m_threads.emplace_back(_run, this);
}
PoolThreadMgr &PoolThreadMgr::get() throw()
PoolThreadMgr &PoolThreadMgr::get()
{
static PoolThreadMgr singleton;
// Defere the creation of the threads to the first call of get
std::call_once(PoolThreadMgr::init_flag, []() { _processMgrPt->_createProcessThread(NB_DEFAULT_THREADS); });
return *_processMgrPt;
std::call_once(PoolThreadMgr::init_flag, []() { singleton._createProcessThread(NB_DEFAULT_THREADS); });
return singleton;
}
......@@ -482,6 +482,7 @@ class PoolThreadMgr
private:
PoolThreadMgr(const PoolThreadMgr&);
~PoolThreadMgr();
};
%Feature BPM_SUPPORT
......
......@@ -24,7 +24,7 @@
#define __BACKGROUNDSUBSTRACTION__H_
#include "processlib/LinkTask.h"
namespace Tasks {
class DLL_EXPORT BackgroundSubstraction : public LinkTask
class PROCESSLIB_EXPORT BackgroundSubstraction : public LinkTask
{
public:
BackgroundSubstraction();
......
......@@ -22,7 +22,7 @@
//###########################################################################
#include "processlib/LinkTask.h"
namespace Tasks {
class DLL_EXPORT Binning : public LinkTask
class PROCESSLIB_EXPORT Binning : public LinkTask
{
public:
Binning();
......
......@@ -30,7 +30,7 @@ class BpmResult;
typedef SinkTaskMgr<BpmResult> BpmManager;
class DLL_EXPORT BpmResult
class PROCESSLIB_EXPORT BpmResult
{
public:
BpmResult()
......@@ -88,7 +88,7 @@ class DLL_EXPORT BpmResult
}
};
class DLL_EXPORT BpmTask : public SinkTask<BpmResult>
class PROCESSLIB_EXPORT BpmTask : public SinkTask<BpmResult>
{
public:
BpmTask(BpmManager &);
......
......@@ -22,7 +22,7 @@
//###########################################################################
#include "processlib/LinkTask.h"
namespace Tasks {
class DLL_EXPORT FlatfieldCorrection : public LinkTask
class PROCESSLIB_EXPORT FlatfieldCorrection : public LinkTask
{
public:
FlatfieldCorrection();
......
......@@ -22,7 +22,7 @@
//###########################################################################
#include "processlib/LinkTask.h"
namespace Tasks {
class DLL_EXPORT Flip : public LinkTask
class PROCESSLIB_EXPORT Flip : public LinkTask
{
public:
enum FLIP_MODE { FLIP_NONE, FLIP_X, FLIP_Y, FLIP_ALL };
......
......@@ -23,7 +23,7 @@
#include "processlib/LinkTask.h"
namespace Tasks {
class DLL_EXPORT Mask : public LinkTask
class PROCESSLIB_EXPORT Mask : public LinkTask
{
public:
enum Type { STANDARD, DUMMY };
......
......@@ -31,7 +31,7 @@ struct PeakFinderResult;
typedef SinkTaskMgr<PeakFinderResult> PeakFinderManager;
struct DLL_EXPORT PeakFinderResult
struct PROCESSLIB_EXPORT PeakFinderResult
{
PeakFinderResult() : x_peak(0.), y_peak(0.), frameNumber(-1), errorCode(PeakFinderManager::OK) {}
explicit PeakFinderResult(PeakFinderManager::ErrorCode code) : errorCode(code) {}
......@@ -52,7 +52,7 @@ inline std::ostream &operator<<(std::ostream &os, const PeakFinderResult &aPeakR
return os;
}
class DLL_EXPORT PeakFinderTask : public SinkTask<PeakFinderResult>
class PROCESSLIB_EXPORT PeakFinderTask : public SinkTask<PeakFinderResult>
{
public:
enum ComputingMode { MAXIMUM, CM };
......
......@@ -30,7 +30,7 @@ struct Roi2SpectrumResult;
typedef SinkTaskMgr<Roi2SpectrumResult> Roi2SpectrumManager;
struct DLL_EXPORT Roi2SpectrumResult
struct PROCESSLIB_EXPORT Roi2SpectrumResult
{
Roi2SpectrumResult() : frameNumber(-1), errorCode(Roi2SpectrumManager::OK) {}
explicit Roi2SpectrumResult(Roi2SpectrumManager::ErrorCode code) : errorCode(code) {}
......@@ -49,7 +49,7 @@ inline std::ostream &operator<<(std::ostream &os, const Roi2SpectrumResult &aRes
return os;
}
class DLL_EXPORT Roi2SpectrumTask : public SinkTask<Roi2SpectrumResult>
class PROCESSLIB_EXPORT Roi2SpectrumTask : public SinkTask<Roi2SpectrumResult>
{
public:
enum Mode { LINES_SUM, COLUMN_SUM };
......
......@@ -31,7 +31,7 @@ struct RoiCounterResult;
typedef SinkTaskMgr<RoiCounterResult> RoiCounterManager;
struct DLL_EXPORT RoiCounterResult
struct PROCESSLIB_EXPORT RoiCounterResult
{
RoiCounterResult()
: sum(0.), average(0.), std(0.), minValue(0.), maxValue(0.), frameNumber(-1), errorCode(RoiCounterManager::OK)
......@@ -61,7 +61,7 @@ inline std::ostream &operator<<(std::ostream &os, const RoiCounterResult &aRoiRe
return os;
}
class DLL_EXPORT RoiCounterTask : public SinkTask<RoiCounterResult>
class PROCESSLIB_EXPORT RoiCounterTask : public SinkTask<RoiCounterResult>
{
public:
enum type { UNDEF, SQUARE, ARC, LUT, MASK };
......
......@@ -25,7 +25,7 @@
#include "processlib/LinkTask.h"
namespace Tasks {
class DLL_EXPORT Rotation : public LinkTask
class PROCESSLIB_EXPORT Rotation : public LinkTask
{
public:
enum Type { R_90, R_180, R_270 };
......
......@@ -24,7 +24,7 @@
#define PROCESSLIB_SOFTROI_H
#include "processlib/LinkTask.h"
namespace Tasks {
class DLL_EXPORT SoftRoi : public LinkTask
class PROCESSLIB_EXPORT SoftRoi : public LinkTask
{
public:
SoftRoi();
......
add_subdirectory(cpp)
macro(add_utf_test name)
add_executable(${name} ${name}.cpp)
target_link_libraries(${name}
core-headers
Boost::unit_test_framework
)
add_test(NAME ${name} COMMAND ${name})
endmacro(add_utf_test)
add_utf_test(test_data)
add_utf_test(test_pool_thread_mgr)
#define BOOST_TEST_MODULE core
#include <boost/test/unit_test.hpp>
#define BOOST_TEST_MODULE data
#include <boost/test/unit_test.hpp>
#include <processlib/Data.h>
BOOST_AUTO_TEST_CASE(test_data)
{
Data beam_data;
beam_data.frameNumber = 1;
beam_data.dimensions = { 2048, 2048 };
beam_data.type = Data::INT8;
Buffer *buffer = new Buffer(2048 * 2048);
//Transfer ownership to Data
beam_data.setBuffer(buffer);
buffer->unref();
BOOST_CHECK_EQUAL(0, 0);
}
#define BOOST_TEST_MODULE pool_thread_mgr
#include <boost/test/unit_test.hpp>
#include <processlib/TaskMgr.h>
#include <processlib/PoolThreadMgr.h>
#include <processlib/BackgroundSubstraction.h>
#include <processlib/Binning.h>
#include <processlib/RoiCounter.h>
BOOST_AUTO_TEST_CASE(test_pool_thread_mgr)
{
// Order of Data, Buffer and TaskMgr construction matters!
Buffer *backgroundBuffer = new Buffer(2048 * 2048);
TaskMgr *task_mgr = new TaskMgr();
// Background
Tasks::BackgroundSubstraction *bckground = new Tasks::BackgroundSubstraction();
Data backgroundData;
backgroundData.setBuffer(backgroundBuffer);
backgroundBuffer->unref();
backgroundData.type = Data::INT8;
backgroundData.dimensions = { 2048, 2048 };
bckground->setBackgroundImageData(backgroundData);
task_mgr->setLinkTask(0, bckground);
// Binning
Tasks::Binning *binning = new Tasks::Binning();
binning->mXFactor = 2;
binning->mYFactor = 2;
task_mgr->setLinkTask(1, binning);
// Roi Counter
Tasks::RoiCounterManager rc_mgr;
Tasks::RoiCounterTask *RCTask = new Tasks::RoiCounterTask(rc_mgr);
RCTask->setRoi(0, 0, 2048, 2048);
task_mgr->addSinkTask(1, RCTask);
// NOTE: TaskMgr takes ownership of the tasks pointer
// And finnaly set the chain task for all input images
PoolThreadMgr& poolThreadMgr = PoolThreadMgr::get();
poolThreadMgr.setNumberOfThread(2);
Buffer *inputBuffer = new Buffer(2048 * 2048);
Data inputData;
inputData.setBuffer(inputBuffer);
inputBuffer->unref();
inputData.type = Data::INT8;
inputData.dimensions = { 2048, 2048 };
task_mgr->setInputData(inputData);
poolThreadMgr.addProcess(task_mgr);
poolThreadMgr.wait(5);
BOOST_CHECK_EQUAL(0, 0);
}