cleanup: not necessary c_str() removed.

This commit is contained in:
Roland Jax
2014-05-12 17:59:41 +02:00
parent e339511647
commit 2a2b638fc4
3 changed files with 22 additions and 22 deletions
+5 -5
View File
@@ -48,7 +48,7 @@ void BaseLoop::start()
// send result to client // send result to client
result += '\n'; result += '\n';
Connection* connection = static_cast<Connection*>(message->getSource()); Connection* connection = static_cast<Connection*>(message->getSource());
connection->addResult(Message(result.c_str())); connection->addResult(Message(result));
delete message; delete message;
} }
@@ -98,7 +98,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
if (busCommand->getResult().c_str()[0] != '-') { if (busCommand->getResult().c_str()[0] != '-') {
// decode data // decode data
Command* command = new Command(index, (*m_commands)[index], busCommand->getResult().c_str()); Command* command = new Command(index, (*m_commands)[index], busCommand->getResult());
// return result // return result
result << command->calcResult(cmd); result << command->calcResult(cmd);
@@ -106,7 +106,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
delete command; delete command;
} else { } else {
L.log(bas, error, " %s", busCommand->getResult().c_str()); L.log(bas, error, " %s", busCommand->getResult().c_str());
result << busCommand->getResult().c_str(); result << busCommand->getResult();
} }
@@ -159,7 +159,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
} else { } else {
L.log(bas, error, " %s", busCommand->getResult().c_str()); L.log(bas, error, " %s", busCommand->getResult().c_str());
result << busCommand->getResult().c_str(); result << busCommand->getResult();
} }
delete busCommand; delete busCommand;
@@ -184,7 +184,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
cycdata = m_cycdata->getData(index); cycdata = m_cycdata->getData(index);
if (cycdata != "") { if (cycdata != "") {
// decode data // decode data
Command* command = new Command(index, (*m_commands)[index], cycdata.c_str()); Command* command = new Command(index, (*m_commands)[index], cycdata);
// return result // return result
result << command->calcResult(cmd); result << command->calcResult(cmd);
+4 -4
View File
@@ -37,12 +37,12 @@ public:
Message(const std::string data, void* source = NULL) : m_data(data), m_source(source) {} Message(const std::string data, void* source = NULL) : m_data(data), m_source(source) {}
Message(const Message& src) : m_data(src.m_data), m_source(src.m_source) {} Message(const Message& src) : m_data(src.m_data), m_source(src.m_source) {}
std::string getData() const { return m_data.c_str(); } std::string getData() const { return m_data; }
void* getSource() const { return m_source; } void* getSource() const { return m_source; }
private: private:
std::string m_data; std::string m_data;
void* m_source; void* m_source;
}; };
@@ -52,7 +52,7 @@ class BaseLoop
public: public:
BaseLoop(EBusLoop* ebusloop, CYCData* cycdata, Commands* commands) BaseLoop(EBusLoop* ebusloop, CYCData* cycdata, Commands* commands)
: m_ebusloop(ebusloop), m_cycdata(cycdata), m_commands(commands) {} : m_ebusloop(ebusloop), m_cycdata(cycdata), m_commands(commands) {}
void start(); void start();
WQueue<Message*>* getQueue() { return &m_queue; } WQueue<Message*>* getQueue() { return &m_queue; }
@@ -64,7 +64,7 @@ private:
Commands* m_commands; Commands* m_commands;
WQueue<Message*> m_queue; WQueue<Message*> m_queue;
enum ClientCommand { enum ClientCommand {
get, // get ebus data get, // get ebus data
set, // set ebus value set, // set ebus value
cyc, // fetch cycle data cyc, // fetch cycle data
+13 -13
View File
@@ -37,10 +37,10 @@ LogMessage::LogMessage(const Area area, const Level level, const std::string tex
struct timeval tv; struct timeval tv;
struct timezone tz; struct timezone tz;
struct tm* tm; struct tm* tm;
gettimeofday(&tv, &tz); gettimeofday(&tv, &tz);
tm = localtime(&tv.tv_sec); tm = localtime(&tv.tv_sec);
sprintf(&time[0], "%04d-%02d-%02d %02d:%02d:%02d.%03ld", sprintf(&time[0], "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec/1000); tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec/1000);
@@ -65,11 +65,11 @@ void* LogSink::run()
while (m_queue.size() == true) { while (m_queue.size() == true) {
LogMessage* message = m_queue.remove(); LogMessage* message = m_queue.remove();
write(*message); write(*message);
delete message; delete message;
} }
return NULL; return NULL;
} }
write(*message); write(*message);
delete message; delete message;
} }
@@ -129,7 +129,7 @@ LogInstance& LogInstance::operator+= (LogSink* sink)
return (*this); return (*this);
} }
LogInstance& LogInstance::operator-= (const LogSink* sink) LogInstance& LogInstance::operator-= (const LogSink* sink)
{ {
sinkCI_t itEnd = m_sinks.end(); sinkCI_t itEnd = m_sinks.end();
@@ -151,12 +151,12 @@ void LogInstance::log(const Area area, const Level level, const std::string& dat
char* tmp; char* tmp;
va_list ap; va_list ap;
va_start(ap, data); va_start(ap, data);
if (vasprintf(&tmp, data.c_str(), ap) != -1) { if (vasprintf(&tmp, data.c_str(), ap) != -1) {
std::string buffer(tmp); std::string buffer(tmp);
m_messages.add(new LogMessage(LogMessage(area, level, buffer.c_str(), LogMessage::Run))); m_messages.add(new LogMessage(LogMessage(area, level, buffer, LogMessage::Run)));
} }
va_end(ap); va_end(ap);
free(tmp); free(tmp);
} }
@@ -166,15 +166,15 @@ void LogInstance::log(const Area area, const Level level, const std::string& dat
void* LogInstance::run() void* LogInstance::run()
{ {
m_running = true; m_running = true;
while (m_running == true) { while (m_running == true) {
LogMessage* message = m_messages.remove(); LogMessage* message = m_messages.remove();
sinkCI_t iter = m_sinks.begin(); sinkCI_t iter = m_sinks.begin();
for (; iter != m_sinks.end(); ++iter) { for (; iter != m_sinks.end(); ++iter) {
if (*iter != 0) { if (*iter != 0) {
if (((*iter)->getAreas() & message->getArea() if (((*iter)->getAreas() & message->getArea()
&& (*iter)->getLevel() >= message->getLevel()) && (*iter)->getLevel() >= message->getLevel())
&& message->getStatus() == LogMessage::Run) { && message->getStatus() == LogMessage::Run) {
@@ -183,10 +183,10 @@ void* LogInstance::run()
(*iter)->addMessage(*message); (*iter)->addMessage(*message);
m_running = false; m_running = false;
} }
} }
} }
delete message; delete message;
} }