class BusCommand separated from class Bus.

This commit is contained in:
Roland Jax
2014-10-29 18:20:40 +01:00
parent cbbfe1ccd9
commit 6eab3adc42
7 changed files with 168 additions and 84 deletions
+1 -33
View File
@@ -24,6 +24,7 @@
#include "result.h"
#include "port.h"
#include "dump.h"
#include "buscommand.h"
#include <cstring>
#include <cstdlib>
#include <sstream>
@@ -36,39 +37,6 @@ namespace libebus
// the maximum time allowed for retrieving a byte from an addressed slave
#define RECV_TIMEOUT 10000
enum CommandType { invalid, broadcast, masterMaster, masterSlave };
class BusCommand
{
public:
BusCommand(const std::string commandStr, const bool isPoll);
~BusCommand();
CommandType getType() const { return m_type; }
bool isPoll() const { return m_isPoll; }
SymbolString getCommand() const { return m_command; }
bool isErrorResult() const { return m_resultCode < 0; }
const char* getResultCodeCStr();
SymbolString getResult() const { return m_result; }
void setResult(const SymbolString result, const int resultCode) { m_result = result; m_resultCode = resultCode; }
const std::string getMessageStr();
void waitSignal() { pthread_cond_wait(&m_cond, &m_mutex); } // TODO timeout
void sendSignal() { pthread_cond_signal(&m_cond); }
private:
CommandType m_type;
bool m_isPoll;
SymbolString m_command;
SymbolString m_result;
int m_resultCode;
pthread_mutex_t m_mutex;
pthread_cond_t m_cond;
};
class Bus
{