Mentions légales du service

Skip to content
Snippets Groups Projects

Resolve "Update: DLLBridge Clang and Coding Rules"

6 files
+ 138
83
Compare changes
  • Side-by-side
  • Inline
Files
6
#include "ovpCBoxAlgorithmDLLBridge.h"
///-------------------------------------------------------------------------------------------------
///
/// \author Jussi T. Lindgren (Inria)
/// \copyright (C) 2022 Inria
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as published
/// by the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// This program 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 Affero General Public License for more details.
///
/// You should have received a copy of the GNU Affero General Public License
/// along with this program. If not, see <https://www.gnu.org/licenses/>.
///
///-------------------------------------------------------------------------------------------------
#include "CBoxAlgorithmDLLBridge.hpp"
#include <iostream>
@@ -60,51 +80,44 @@ bool CDLLBridge::initialize()
m_dllFile = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
m_parameters = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
if (m_dllFile == CString(""))
{
if (m_dllFile == CString("")) {
this->getLogManager() << Kernel::LogLevel_Error << "Need a DLL file\n";
return false;
}
OPEN_FUNC(m_dllFile, m_library)
if (!m_library)
{
if (!m_library) {
this->getLogManager() << Kernel::LogLevel_Error << "Failed to load " << m_dllFile << ", error code " << int64_t(ERR_FUNC()) << "\n";
return false;
}
m_initialize = INITFUNC(PROC_FUNC(m_library, "box_init"));
if (!m_initialize)
{
if (!m_initialize) {
this->getLogManager() << Kernel::LogLevel_Error << "Unable to find box_init() in the DLL\n";
return false;
}
m_process = PROCESSFUNC(PROC_FUNC(m_library, "box_process"));
if (!m_process)
{
if (!m_process) {
this->getLogManager() << Kernel::LogLevel_Error << "Unable to find box_process() in the DLL\n";
return false;
}
m_processHeader = PROCESSHEADERFUNC(PROC_FUNC(m_library, "box_process_header"));
if (!m_processHeader)
{
if (!m_processHeader) {
this->getLogManager() << Kernel::LogLevel_Error << "Unable to find box_process_header() in the DLL\n";
return false;
}
m_uninitialize = UNINITFUNC(PROC_FUNC(m_library, "box_uninit"));
if (!m_uninitialize)
{
if (!m_uninitialize) {
this->getLogManager() << Kernel::LogLevel_Error << "Unable to find box_uninit() in the DLL\n";
return false;
}
const Kernel::IBox& boxContext = this->getStaticBoxContext();
boxContext.getInputType(0, m_inputTypeID);
if (m_inputTypeID == OV_TypeId_StreamedMatrix)
{
if (m_inputTypeID == OV_TypeId_StreamedMatrix) {
Toolkit::TStreamedMatrixDecoder<CDLLBridge>* decoder = new Toolkit::TStreamedMatrixDecoder<CDLLBridge>;
Toolkit::TStreamedMatrixEncoder<CDLLBridge>* encoder = new Toolkit::TStreamedMatrixEncoder<CDLLBridge>;
@@ -114,8 +127,7 @@ bool CDLLBridge::initialize()
m_decoder = decoder;
m_encoder = encoder;
}
else if (m_inputTypeID == OV_TypeId_Signal)
{
else if (m_inputTypeID == OV_TypeId_Signal) {
Toolkit::TSignalDecoder<CDLLBridge>* decoder = new Toolkit::TSignalDecoder<CDLLBridge>;
Toolkit::TSignalEncoder<CDLLBridge>* encoder = new Toolkit::TSignalEncoder<CDLLBridge>;
@@ -125,8 +137,7 @@ bool CDLLBridge::initialize()
m_decoder = decoder;
m_encoder = encoder;
}
else
{
else {
this->getLogManager() << Kernel::LogLevel_Error << "Unknown input type " << m_inputTypeID << ". This should never happen.\n";
return false;
}
@@ -134,11 +145,10 @@ bool CDLLBridge::initialize()
this->getLogManager() << Kernel::LogLevel_Trace << "DLL box_init() : Calling\n";
// Do some initialization in DLL
int length = m_parameters.length();
int length = int(m_parameters.length());
int code = 0;
m_initialize(&length, m_parameters.toASCIIString(), &code);
if (code)
{
if (code) {
this->getLogManager() << Kernel::LogLevel_Error << "DLL box_init() : Returned error code " << code << "\n";
return false;
}
@@ -151,37 +161,32 @@ bool CDLLBridge::uninitialize()
{
this->getLogManager() << Kernel::LogLevel_Debug << "Uninitializing\n";
if (m_uninitialize)
{
if (m_uninitialize) {
this->getLogManager() << Kernel::LogLevel_Trace << "DLL box_uninit() : Calling\n";
// Do some uninitialization in DLL
int code = 0;
m_uninitialize(&code);
if (code)
{
if (code) {
this->getLogManager() << Kernel::LogLevel_Error << "DLL box_uninit() : Returned error code " << code << "\n";
return false;
}
this->getLogManager() << Kernel::LogLevel_Trace << "DLL box_uninit() : Return ok\n";
}
if (m_encoder)
{
if (m_encoder) {
m_encoder->uninitialize();
delete m_encoder;
m_encoder = nullptr;
}
if (m_decoder)
{
if (m_decoder) {
m_decoder->uninitialize();
delete m_decoder;
m_decoder = nullptr;
}
if (m_library)
{
if (m_library) {
CLOSE_FUNC(m_library);
m_library = nullptr;
}
@@ -202,8 +207,7 @@ bool CDLLBridge::process()
Kernel::IBoxIO& boxContext = this->getDynamicBoxContext();
for (uint32_t i = 0; i < boxContext.getInputChunkCount(0); ++i)
{
for (uint32_t i = 0; i < boxContext.getInputChunkCount(0); ++i) {
// m_decoder/m_encoder should point to StreamedMatrix*coder or Signal*Coder by construction,
// the latter appears to be static castable to the former, in practice.
// n.b. dynamic cast does not work here runtime (this does, for the moment). I do not hazard
@@ -214,18 +218,15 @@ bool CDLLBridge::process()
decoder->decode(i);
if (decoder->isHeaderReceived())
{
if (decoder->getOutputMatrix()->getDimensionCount() != 2)
{
if (decoder->isHeaderReceived()) {
if (decoder->getOutputMatrix()->getDimensionCount() != 2) {
this->getLogManager() << Kernel::LogLevel_Error << "Only 2 dimensional matrices supported\n";
return false;
}
int iSampling = 0;
if (m_inputTypeID == OV_TypeId_Signal)
{
if (m_inputTypeID == OV_TypeId_Signal) {
Toolkit::TSignalDecoder<CDLLBridge>* signalDecoder = dynamic_cast<Toolkit::TSignalDecoder<CDLLBridge>*>(m_decoder);
iSampling = int(signalDecoder->getOutputSamplingRate());
}
@@ -237,8 +238,7 @@ bool CDLLBridge::process()
int code = 0, oNRows = 0, oNCols = 0, oSampling = 0;
m_processHeader(&iNRows, &iNCols, &iSampling, &oNRows, &oNCols, &oSampling, &code);
if (code)
{
if (code) {
this->getLogManager() << Kernel::LogLevel_Error << "DLL box_process_header() : Returned error code " << code << "\n";
return false;
}
@@ -247,8 +247,7 @@ bool CDLLBridge::process()
encoder->getInputMatrix()->resize(oNRows, oNCols);
if (m_inputTypeID == OV_TypeId_Signal)
{
if (m_inputTypeID == OV_TypeId_Signal) {
Toolkit::TSignalEncoder<CDLLBridge>* signalEncoder = dynamic_cast<Toolkit::TSignalEncoder<CDLLBridge>*>(m_encoder);
signalEncoder->getInputSamplingRate() = oSampling;
@@ -259,8 +258,7 @@ bool CDLLBridge::process()
boxContext.markOutputAsReadyToSend(0, boxContext.getInputChunkStartTime(0, i), boxContext.getInputChunkEndTime(0, i));
}
if (decoder->isBufferReceived())
{
if (decoder->isBufferReceived()) {
double* input = decoder->getOutputMatrix()->getBuffer();
double* output = encoder->getInputMatrix()->getBuffer();
@@ -269,8 +267,7 @@ bool CDLLBridge::process()
// Process the sample chunk in DLL
int errorCode = 0;
m_process(input, output, &errorCode);
if (errorCode)
{
if (errorCode) {
this->getLogManager() << Kernel::LogLevel_Error << "DLL box_process() : Returned error code " << errorCode << "\n";
return false;
}
@@ -279,8 +276,7 @@ bool CDLLBridge::process()
encoder->encodeBuffer();
boxContext.markOutputAsReadyToSend(0, boxContext.getInputChunkStartTime(0, i), boxContext.getInputChunkEndTime(0, i));
}
if (decoder->isEndReceived())
{
if (decoder->isEndReceived()) {
encoder->encodeEnd();
boxContext.markOutputAsReadyToSend(0, boxContext.getInputChunkStartTime(0, i), boxContext.getInputChunkEndTime(0, i));
}
Loading