pass log function instead of Logger to avoid dependencies, started decodeMessage for get

This commit is contained in:
john30
2014-12-01 22:14:01 +01:00
parent 3b99ca0b4d
commit 671aa54468
6 changed files with 46 additions and 25 deletions
+4 -5
View File
@@ -30,7 +30,6 @@
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "logger.h"
#ifdef HAVE_PPOLL
#include <poll.h>
@@ -252,10 +251,10 @@ void DeviceNetwork::closeDevice()
}
Port::Port(const string deviceName, const bool noDeviceCheck, const bool logRaw, Logger* loggerRaw,
Port::Port(const string deviceName, const bool noDeviceCheck, const bool logRaw, void (*logRawFunc)(const unsigned char byte),
const bool dumpRaw, const char* dumpRawFile, const long dumpRawMaxSize)
: m_deviceName(deviceName), m_noDeviceCheck(noDeviceCheck),
m_logRaw(logRaw), m_loggerRaw(loggerRaw),
m_logRaw(logRaw), m_logRawFunc(logRawFunc),
m_dumpRawFile(dumpRawFile), m_dumpRawMaxSize(dumpRawMaxSize)
{
m_device = NULL;
@@ -275,8 +274,8 @@ unsigned char Port::byte()
{
unsigned char byte = m_device->getByte();
if (m_logRaw == true && m_loggerRaw != NULL)
m_loggerRaw->log(bus, event, "%02x", byte);
if (m_logRaw == true && m_logRawFunc != NULL)
(*m_logRawFunc)(byte);
if (m_dumpRaw == true && m_dumpRawStream.is_open() == true) {
m_dumpRawStream.write((char*)&byte, 1);
+8 -4
View File
@@ -26,7 +26,6 @@
#include <unistd.h>
#include <iostream>
#include <fstream>
#include "logger.h"
#include "result.h"
using namespace std;
@@ -203,8 +202,13 @@ public:
* @brief constructs a new instance and determine device type.
* @param deviceName to determine device type.
* @param noDeviceCheck en-/disable device check.
* @param logRaw whether logging of raw data is enabled.
* @param logRawFunc a function to call for logging raw data, or NULL.
* @param dumpRaw whether dumping of raw data to a file is enabled.
* @param dumpRawFile the name of the file to dump raw data to.
* @param dumpRawMaxSize the maximum size of @a m_dumpFile.
*/
Port(const string deviceName, const bool noDeviceCheck, const bool logRaw, Logger* loggerRaw,
Port(const string deviceName, const bool noDeviceCheck, const bool logRaw, void (*logRawFunc)(const unsigned char byte),
const bool dumpRaw, const char* dumpRawFile, const long dumpRawMaxSize);
/**
@@ -307,8 +311,8 @@ private:
/** whether logging of raw data is enabled. */
bool m_logRaw;
/** the @a Logger used for logging of raw data, or NULL. */
Logger* m_loggerRaw;
/** a function to call for logging raw data, or NULL. */
void (*m_logRawFunc)(const unsigned char byte);
/** whether dumping of raw data to a file is enabled. */
bool m_dumpRaw;
+1 -2
View File
@@ -10,8 +10,7 @@ noinst_PROGRAMS = test_port \
test_message
test_port_SOURCES = test_port.cpp
test_port_LDADD = $(top_srcdir)/src/lib/utils/libutils.a \
$(top_srcdir)/src/lib/ebus/libebus.a
test_port_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a
test_symbol_SOURCES = test_symbol.cpp
test_symbol_LDADD = $(top_srcdir)/src/lib/ebus/libebus.a