save name/address of bus interface

This commit is contained in:
2018-07-18 14:29:00 +02:00
parent b18fbeb9ab
commit 7de7e48c98
2 changed files with 24 additions and 6 deletions

View File

@ -17,6 +17,7 @@
* *
***************************************************************/
#include <stdio.h>
#include "StreamBusInterface.h"
#include "StreamError.h"
@ -68,7 +69,20 @@ find(Client* client, const char* busname, int addr, const char* param)
bus = r->find(client, busname, addr, param);
debug("StreamBusInterface::find %s %s\n",
r->name, bus ? "matches" : "does not match");
if (bus) return bus;
if (bus)
{
if (addr >= 0)
{
bus->_name = new char[strlen(busname) + sizeof(int)*2 + sizeof(int)/2 + 2];
sprintf(bus->_name, "%s %d", busname, addr);
}
else
{
bus->_name = new char[strlen(busname) + 1];
strcpy(bus->_name, busname);
}
return bus;
}
}
return NULL;
}

View File

@ -34,7 +34,9 @@ public:
class Client
{
private:
friend class StreamBusInterface;
virtual void lockCallback(StreamIoStatus status) = 0;
virtual void writeCallback(StreamIoStatus status);
virtual ssize_t readCallback(StreamIoStatus status,
@ -96,27 +98,29 @@ public:
private:
friend class StreamBusInterfaceClass; // the iterator
friend class Client;
char* _name;
public:
Client* client;
virtual ~StreamBusInterface() {};
const char* name() { return _name; }
protected:
StreamBusInterface(Client* client);
// map client functions into StreamBusInterface namespace
void lockCallback(StreamIoStatus status)
void lockCallback(StreamIoStatus status = StreamIoSuccess)
{ client->lockCallback(status); }
void writeCallback(StreamIoStatus status)
void writeCallback(StreamIoStatus status = StreamIoSuccess)
{ client->writeCallback(status); }
ssize_t readCallback(StreamIoStatus status,
const void* input = NULL, size_t size = 0)
{ return client->readCallback(status, input, size); }
void eventCallback(StreamIoStatus status)
void eventCallback(StreamIoStatus status = StreamIoSuccess)
{ client->eventCallback(status); }
void connectCallback(StreamIoStatus status)
void connectCallback(StreamIoStatus status = StreamIoSuccess)
{ client->connectCallback(status); }
void disconnectCallback(StreamIoStatus status)
void disconnectCallback(StreamIoStatus status = StreamIoSuccess)
{ client->disconnectCallback(status); }
const char* getInTerminator(size_t& length)
{ return client->getInTerminator(length); }