Skip to content

Commit 7429731

Browse files
committed
Allow static libs, fix uninitialized member variable
- Remove SHARED option from add_library to allow static libs, CMake then respects the standard BUILD_SHARED_LIBS option. - Use singleton LoggerImpl to avoid problems with static lib startup order. - Fix uninitialized member variable (found using valgrind).
1 parent 89720d3 commit 7429731

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ link_directories(
126126

127127
file(GLOB CAPI_SRCS "src/CommonAPI/*.cpp")
128128
list(SORT CAPI_SRCS)
129-
add_library(CommonAPI SHARED ${CAPI_SRCS})
129+
add_library(CommonAPI ${CAPI_SRCS})
130130
target_link_libraries(CommonAPI PRIVATE ${DL_LIBRARY} ${DLT_LIBRARIES})
131131
set_target_properties(CommonAPI PROPERTIES VERSION ${LIBCOMMONAPI_MAJOR_VERSION}.${LIBCOMMONAPI_MINOR_VERSION}.${LIBCOMMONAPI_PATCH_VERSION} SOVERSION ${LIBCOMMONAPI_MAJOR_VERSION}.${LIBCOMMONAPI_MINOR_VERSION}.${LIBCOMMONAPI_PATCH_VERSION} LINKER_LANGUAGE C)
132132
set_target_properties (CommonAPI PROPERTIES INTERFACE_LINK_LIBRARY "")

include/CommonAPI/Logger.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Logger {
8484

8585
private:
8686
class LoggerImpl;
87-
static std::unique_ptr<LoggerImpl> loggerImpl_;
87+
static LoggerImpl &getInstance();
8888

8989
COMMONAPI_EXPORT static bool isLogged(Level _level);
9090
COMMONAPI_EXPORT static void doLog(Level _level, const std::string& _message);

src/CommonAPI/Logger.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,26 @@ class Logger::LoggerImpl {
176176
#endif
177177
};
178178

179-
std::unique_ptr<Logger::LoggerImpl> Logger::loggerImpl_ =
180-
std::unique_ptr<Logger::LoggerImpl>(new Logger::LoggerImpl());
179+
Logger::LoggerImpl &Logger::getInstance()
180+
{
181+
static LoggerImpl loggerImpl;
182+
return loggerImpl;
183+
}
181184

182185
Logger::Logger() = default;
183186
Logger::~Logger() = default;
184187

185188
void Logger::init(bool _useConsole, const std::string &_fileName, bool _useDlt,
186189
const std::string& _level) {
187-
loggerImpl_->init(_useConsole, _fileName, _useDlt, _level);
190+
getInstance().init(_useConsole, _fileName, _useDlt, _level);
188191
}
189192

190193
bool Logger::isLogged(Level _level) {
191-
return loggerImpl_->isLogged(_level);
194+
return getInstance().isLogged(_level);
192195
}
193196

194197
void Logger::doLog(Level _level, const std::string& _message) {
195-
loggerImpl_->doLog(_level, _message);
198+
getInstance().doLog(_level, _message);
196199
}
197200

198201
} //namespace CommonAPI

src/CommonAPI/Runtime.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ std::shared_ptr<Runtime> Runtime::get() {
7474
Runtime::Runtime()
7575
: defaultBinding_(COMMONAPI_DEFAULT_BINDING),
7676
defaultFolder_(COMMONAPI_DEFAULT_FOLDER),
77+
defaultCallTimeout_(0),
7778
isConfigured_(false),
7879
isInitialized_(false) {
7980
}

0 commit comments

Comments
 (0)