From 54f5fea2013cc3410071be911634304624ae8c21 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 25 Mar 2020 11:42:19 -0400 Subject: [PATCH 1/2] ZeroMQ's std::string support is too new --- src/ZmqLogger.cpp | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/ZmqLogger.cpp b/src/ZmqLogger.cpp index f607d08f8..0be04bfaa 100644 --- a/src/ZmqLogger.cpp +++ b/src/ZmqLogger.cpp @@ -71,7 +71,7 @@ ZmqLogger *ZmqLogger::Instance() } // Set the connection for this logger -void ZmqLogger::Connection(string new_connection) +void ZmqLogger::Connection(std::string new_connection) { // Create a scoped lock, allowing only a single thread to run the following code at one time const GenericScopedLock lock(loggerCriticalSection); @@ -102,7 +102,7 @@ void ZmqLogger::Connection(string new_connection) publisher->bind(connection.c_str()); } catch (zmq::error_t &e) { - cout << "ZmqLogger::Connection - Error binding to " << connection << ". Switching to an available port." << endl; + std::cout << "ZmqLogger::Connection - Error binding to " << connection << ". Switching to an available port." << std::endl; connection = "tcp://*:*"; publisher->bind(connection.c_str()); } @@ -111,7 +111,7 @@ void ZmqLogger::Connection(string new_connection) usleep(250000); } -void ZmqLogger::Log(string message) +void ZmqLogger::Log(std::string message) { if (!enabled) // Don't do anything @@ -120,15 +120,14 @@ void ZmqLogger::Log(string message) // Create a scoped lock, allowing only a single thread to run the following code at one time const GenericScopedLock lock(loggerCriticalSection); -#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 1) // Send message over socket (ZeroMQ) - zmq::message_t reply(message); + zmq::message_t reply (message.length()); + std::memcpy (reply.data(), message.c_str(), message.length()); +#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 1) // Set flags for immediate delivery (new API) publisher->send(reply, zmq::send_flags::dontwait); #else - zmq::message_t reply (message.length()); - memcpy (reply.data(), message.c_str(), message.length()); publisher->send(reply); #endif @@ -137,14 +136,14 @@ void ZmqLogger::Log(string message) } // Log message to a file (if path set) -void ZmqLogger::LogToFile(string message) +void ZmqLogger::LogToFile(std::string message) { // Write to log file (if opened, and force it to write to disk in case of a crash) if (log_file.is_open()) log_file << message << std::flush; } -void ZmqLogger::Path(string new_path) +void ZmqLogger::Path(std::string new_path) { // Update path file_path = new_path; @@ -154,14 +153,14 @@ void ZmqLogger::Path(string new_path) log_file.close(); // Open file (write + append) - log_file.open (file_path.c_str(), ios::out | ios::app); + log_file.open (file_path.c_str(), std::ios::out | std::ios::app); // Get current time and log first message - time_t now = time(0); - tm* localtm = localtime(&now); - log_file << "------------------------------------------" << endl; - log_file << "libopenshot logging: " << asctime(localtm); - log_file << "------------------------------------------" << endl; + std::time_t now = std::time(0); + std::tm* localtm = std::localtime(&now); + log_file << "------------------------------------------" << std::endl; + log_file << "libopenshot logging: " << std::asctime(localtm); + log_file << "------------------------------------------" << std::endl; } void ZmqLogger::Close() @@ -182,13 +181,13 @@ void ZmqLogger::Close() } // Append debug information -void ZmqLogger::AppendDebugMethod(string method_name, - string arg1_name, float arg1_value, - string arg2_name, float arg2_value, - string arg3_name, float arg3_value, - string arg4_name, float arg4_value, - string arg5_name, float arg5_value, - string arg6_name, float arg6_value) +void ZmqLogger::AppendDebugMethod(std::string method_name, + std::string arg1_name, float arg1_value, + std::string arg2_name, float arg2_value, + std::string arg3_name, float arg3_value, + std::string arg4_name, float arg4_value, + std::string arg5_name, float arg5_value, + std::string arg6_name, float arg6_value) { if (!enabled) // Don't do anything @@ -198,8 +197,8 @@ void ZmqLogger::AppendDebugMethod(string method_name, // Create a scoped lock, allowing only a single thread to run the following code at one time const GenericScopedLock lock(loggerCriticalSection); - stringstream message; - message << fixed << setprecision(4); + std::stringstream message; + message << std::fixed << std::setprecision(4); message << method_name << " ("; // Add attributes to method JSON From adf6165083fd2f227d354094b3764a117ca7bb9a Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 25 Mar 2020 11:57:22 -0400 Subject: [PATCH 2/2] Add version reporting to FindZeroMQ --- cmake/Modules/FindZeroMQ.cmake | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cmake/Modules/FindZeroMQ.cmake b/cmake/Modules/FindZeroMQ.cmake index 6c3669199..1f1dc083e 100644 --- a/cmake/Modules/FindZeroMQ.cmake +++ b/cmake/Modules/FindZeroMQ.cmake @@ -5,14 +5,16 @@ pkg_check_modules(PC_LIBZMQ QUIET libzmq) set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION}) find_path(ZeroMQ_INCLUDE_DIR zmq.h - PATHS ${ZeroMQ_DIR}/include - ${PC_LIBZMQ_INCLUDE_DIRS}) + PATHS + ${ZeroMQ_DIR}/include + ${PC_LIBZMQ_INCLUDE_DIRS}) find_library(ZeroMQ_LIBRARY - NAMES zmq - PATHS ${ZeroMQ_DIR}/lib - ${PC_LIBZMQ_LIBDIR} - ${PC_LIBZMQ_LIBRARY_DIRS}) + NAMES zmq + PATHS + ${ZeroMQ_DIR}/lib + ${PC_LIBZMQ_LIBDIR} + ${PC_LIBZMQ_LIBRARY_DIRS}) if(ZeroMQ_LIBRARY) set(ZeroMQ_FOUND ON) @@ -31,4 +33,9 @@ endif() include ( FindPackageHandleStandardArgs ) # handle the QUIETLY and REQUIRED arguments and set ZMQ_FOUND to TRUE # if all listed variables are TRUE -find_package_handle_standard_args ( ZeroMQ DEFAULT_MSG ZeroMQ_LIBRARIES ZeroMQ_INCLUDE_DIRS ) +find_package_handle_standard_args(ZeroMQ + REQUIRED_VARS + ZeroMQ_LIBRARIES + ZeroMQ_INCLUDE_DIRS + VERSION_VAR + ZeroMQ_VERSION)