Skip to content

Commit 54f5fea

Browse files
committed
ZeroMQ's std::string support is too new
1 parent 4fad197 commit 54f5fea

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/ZmqLogger.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ZmqLogger *ZmqLogger::Instance()
7171
}
7272

7373
// Set the connection for this logger
74-
void ZmqLogger::Connection(string new_connection)
74+
void ZmqLogger::Connection(std::string new_connection)
7575
{
7676
// Create a scoped lock, allowing only a single thread to run the following code at one time
7777
const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
@@ -102,7 +102,7 @@ void ZmqLogger::Connection(string new_connection)
102102
publisher->bind(connection.c_str());
103103

104104
} catch (zmq::error_t &e) {
105-
cout << "ZmqLogger::Connection - Error binding to " << connection << ". Switching to an available port." << endl;
105+
std::cout << "ZmqLogger::Connection - Error binding to " << connection << ". Switching to an available port." << std::endl;
106106
connection = "tcp://*:*";
107107
publisher->bind(connection.c_str());
108108
}
@@ -111,7 +111,7 @@ void ZmqLogger::Connection(string new_connection)
111111
usleep(250000);
112112
}
113113

114-
void ZmqLogger::Log(string message)
114+
void ZmqLogger::Log(std::string message)
115115
{
116116
if (!enabled)
117117
// Don't do anything
@@ -120,15 +120,14 @@ void ZmqLogger::Log(string message)
120120
// Create a scoped lock, allowing only a single thread to run the following code at one time
121121
const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
122122

123-
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 1)
124123
// Send message over socket (ZeroMQ)
125-
zmq::message_t reply(message);
124+
zmq::message_t reply (message.length());
125+
std::memcpy (reply.data(), message.c_str(), message.length());
126126

127+
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 1)
127128
// Set flags for immediate delivery (new API)
128129
publisher->send(reply, zmq::send_flags::dontwait);
129130
#else
130-
zmq::message_t reply (message.length());
131-
memcpy (reply.data(), message.c_str(), message.length());
132131
publisher->send(reply);
133132
#endif
134133

@@ -137,14 +136,14 @@ void ZmqLogger::Log(string message)
137136
}
138137

139138
// Log message to a file (if path set)
140-
void ZmqLogger::LogToFile(string message)
139+
void ZmqLogger::LogToFile(std::string message)
141140
{
142141
// Write to log file (if opened, and force it to write to disk in case of a crash)
143142
if (log_file.is_open())
144143
log_file << message << std::flush;
145144
}
146145

147-
void ZmqLogger::Path(string new_path)
146+
void ZmqLogger::Path(std::string new_path)
148147
{
149148
// Update path
150149
file_path = new_path;
@@ -154,14 +153,14 @@ void ZmqLogger::Path(string new_path)
154153
log_file.close();
155154

156155
// Open file (write + append)
157-
log_file.open (file_path.c_str(), ios::out | ios::app);
156+
log_file.open (file_path.c_str(), std::ios::out | std::ios::app);
158157

159158
// Get current time and log first message
160-
time_t now = time(0);
161-
tm* localtm = localtime(&now);
162-
log_file << "------------------------------------------" << endl;
163-
log_file << "libopenshot logging: " << asctime(localtm);
164-
log_file << "------------------------------------------" << endl;
159+
std::time_t now = std::time(0);
160+
std::tm* localtm = std::localtime(&now);
161+
log_file << "------------------------------------------" << std::endl;
162+
log_file << "libopenshot logging: " << std::asctime(localtm);
163+
log_file << "------------------------------------------" << std::endl;
165164
}
166165

167166
void ZmqLogger::Close()
@@ -182,13 +181,13 @@ void ZmqLogger::Close()
182181
}
183182

184183
// Append debug information
185-
void ZmqLogger::AppendDebugMethod(string method_name,
186-
string arg1_name, float arg1_value,
187-
string arg2_name, float arg2_value,
188-
string arg3_name, float arg3_value,
189-
string arg4_name, float arg4_value,
190-
string arg5_name, float arg5_value,
191-
string arg6_name, float arg6_value)
184+
void ZmqLogger::AppendDebugMethod(std::string method_name,
185+
std::string arg1_name, float arg1_value,
186+
std::string arg2_name, float arg2_value,
187+
std::string arg3_name, float arg3_value,
188+
std::string arg4_name, float arg4_value,
189+
std::string arg5_name, float arg5_value,
190+
std::string arg6_name, float arg6_value)
192191
{
193192
if (!enabled)
194193
// Don't do anything
@@ -198,8 +197,8 @@ void ZmqLogger::AppendDebugMethod(string method_name,
198197
// Create a scoped lock, allowing only a single thread to run the following code at one time
199198
const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
200199

201-
stringstream message;
202-
message << fixed << setprecision(4);
200+
std::stringstream message;
201+
message << std::fixed << std::setprecision(4);
203202
message << method_name << " (";
204203

205204
// Add attributes to method JSON

0 commit comments

Comments
 (0)