Skip to content

Commit ac9a9f0

Browse files
authored
feature/cli-runner (#90)
* Add DlError for CLI runner * Fix logging in HelloWorld component for cli runner.
1 parent 88f5c73 commit ac9a9f0

5 files changed

Lines changed: 17 additions & 74 deletions

File tree

detection/examples/HelloWorldComponent/HelloWorld.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <map>
2828
#include <iostream>
2929
#include <detectionComponentUtils.h>
30-
#include <log4cxx/xml/domconfigurator.h>
3130

3231
#include "HelloWorld.h"
3332

@@ -42,7 +41,6 @@ using namespace MPF::COMPONENT;
4241
run_directory = ".";
4342
}
4443

45-
log4cxx::xml::DOMConfigurator::configure(run_directory + "/HelloWorldComponent/config/Log4cxxConfig.xml");
4644
hw_logger_ = log4cxx::Logger::getLogger("HelloWorldSample");
4745
LOG4CXX_INFO(hw_logger_, "Running in directory \"" << run_directory << "\"");
4846

detection/examples/HelloWorldComponent/StreamingHelloWorld.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
******************************************************************************/
2626

2727

28-
#include <log4cxx/xml/domconfigurator.h>
2928
#include <detectionComponentUtils.h>
3029

3130
#include "StreamingHelloWorld.h"
@@ -35,20 +34,14 @@ using namespace MPF::COMPONENT;
3534

3635
StreamingHelloWorld::StreamingHelloWorld(const MPFStreamingVideoJob &job)
3736
: MPFStreamingDetectionComponent(job)
38-
, hw_logger_(GetLogger(job.run_directory))
37+
, hw_logger_(log4cxx::Logger::getLogger("StreamingHelloWorldSample"))
3938
, job_name_(job.job_name)
4039
, confidence_threshold_(DetectionComponentUtils::GetProperty(job.job_properties, "CONFIDENCE_THRESHOLD", -1.0))
4140
{
4241
LOG4CXX_INFO(hw_logger_, "[" << job_name_ << "] Initialized StreamingHelloWorld component.")
4342
}
4443

4544

46-
log4cxx::LoggerPtr StreamingHelloWorld::GetLogger(const std::string &run_directory) {
47-
log4cxx::xml::DOMConfigurator::configure(run_directory + "/HelloWorldComponent/config/Log4cxxConfig.xml");
48-
return log4cxx::Logger::getLogger("StreamingHelloWorldSample");
49-
}
50-
51-
5245
void StreamingHelloWorld::BeginSegment(const VideoSegmentInfo &segment_info) {
5346
LOG4CXX_INFO(hw_logger_, "[" << job_name_ << "] Preparing to process segment " << segment_info.segment_number)
5447
segment_detections_.clear();

detection/examples/HelloWorldComponent/StreamingHelloWorld.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class StreamingHelloWorld : public MPF::COMPONENT::MPFStreamingDetectionComponen
6161
double confidence_threshold_;
6262

6363
std::vector<MPF::COMPONENT::MPFVideoTrack> segment_detections_;
64-
65-
static log4cxx::LoggerPtr GetLogger(const std::string &run_directory);
6664
};
6765

6866

detection/examples/HelloWorldComponent/plugin-files/config/Log4cxxConfig.xml

Lines changed: 0 additions & 58 deletions
This file was deleted.

detection/utils/include/DlClassLoader.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
#ifndef OPENMPF_CPP_COMPONENT_SDK_DLCLASSLOADER_H
2828
#define OPENMPF_CPP_COMPONENT_SDK_DLCLASSLOADER_H
2929

30-
#include <string>
31-
#include <memory>
3230
#include <dlfcn.h>
31+
32+
#include <memory>
33+
#include <string>
34+
#include <type_traits>
35+
#include <utility>
36+
3337
#include <MPFDetectionException.h>
3438

3539

@@ -49,6 +53,14 @@ namespace MPF { namespace COMPONENT {
4953
};
5054

5155

56+
class DlError : public MPFDetectionException {
57+
public:
58+
explicit DlError(const std::string &what)
59+
: MPFDetectionException(MPF_DETECTION_NOT_INITIALIZED, what) {
60+
}
61+
};
62+
63+
5264
template <typename DlClass>
5365
class DlClassLoader {
5466
public:
@@ -94,7 +106,7 @@ namespace MPF { namespace COMPONENT {
94106
const std::string &deleter_func_name,
95107
CreatorArgs&&... args) {
96108
if (lib_handle == nullptr) {
97-
throw std::runtime_error("Failed to open \"" + lib_path + "\" due to: " + dlerror());
109+
throw DlError("Failed to open \"" + lib_path + "\" due to: " + dlerror());
98110
}
99111

100112
auto create_instance_fn = LoadFunction<creator_func_t<CreatorArgs...>>(lib_handle, creator_func_name);
@@ -126,7 +138,7 @@ namespace MPF { namespace COMPONENT {
126138
static TFunc* LoadFunction(void* lib_handle, const std::string &symbol_name) {
127139
auto result = reinterpret_cast<TFunc*>(dlsym(lib_handle, symbol_name.c_str()));
128140
if (result == nullptr) {
129-
throw std::runtime_error("dlsym failed for " + symbol_name + ": " + dlerror());
141+
throw DlError("dlsym failed for " + symbol_name + ": " + dlerror());
130142
}
131143
return result;
132144
}

0 commit comments

Comments
 (0)