1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-13 05:53:06 +01:00

intermediate: introduce an abstract channel

This commit is contained in:
wellenvogel
2021-12-31 18:38:11 +01:00
parent 0acb988f31
commit 47fb805ee6
9 changed files with 351 additions and 259 deletions

View File

@@ -133,25 +133,23 @@ void GwSocketServer::loop(bool handleRead, bool handleWrite)
}
}
bool GwSocketServer::readMessages(GwMessageFetcher *writer)
void GwSocketServer::readMessages(GwMessageFetcher *writer)
{
if (!allowReceive || !clients)
return false;
bool hasMessages = false;
return;
for (int i = 0; i < maxClients; i++)
{
writer->id = minId + i;
if (!clients[i]->hasClient())
continue;
if (clients[i]->messagesFromBuffer(writer))
hasMessages = true;
clients[i]->messagesFromBuffer(writer);
}
return hasMessages;
return;
}
void GwSocketServer::sendToClients(const char *buf, int source)
size_t GwSocketServer::sendToClients(const char *buf, int source,bool partial)
{
if (!clients)
return;
return 0;
int len = strlen(buf);
int sourceIndex = source - minId;
for (int i = 0; i < maxClients; i++)
@@ -166,6 +164,7 @@ void GwSocketServer::sendToClients(const char *buf, int source)
client->enqueue((uint8_t *)buf, len);
}
}
return len;
}
int GwSocketServer::numClients()

View File

@@ -3,10 +3,11 @@
#include "GWConfig.h"
#include "GwLog.h"
#include "GwBuffer.h"
#include "GwChannelInterface.h"
#include <memory>
class GwSocketConnection;
class GwSocketServer{
class GwSocketServer: public GwChannelInterface{
private:
const GwConfigHandler *config;
GwLog *logger;
@@ -22,9 +23,9 @@ class GwSocketServer{
GwSocketServer(const GwConfigHandler *config,GwLog *logger,int minId);
~GwSocketServer();
void begin();
void loop(bool handleRead=true,bool handleWrite=true);
void sendToClients(const char *buf,int sourceId);
virtual void loop(bool handleRead=true,bool handleWrite=true);
virtual size_t sendToClients(const char *buf,int sourceId, bool partialWrite=false);
int numClients();
bool readMessages(GwMessageFetcher *writer);
virtual void readMessages(GwMessageFetcher *writer);
};
#endif