Started work on the server, continuing client to be able to test

This commit is contained in:
2026-02-03 17:04:20 +01:00
parent 7fc64a03ad
commit a0d9d9c6de
15 changed files with 112 additions and 1 deletions

0
server/src/.gitempty Normal file
View File

View File

View File

@@ -0,0 +1,20 @@
#include "logic/reactor.h"
#include "logic/service.h"
ChatReactor::ChatReactor(Service *service, absl::Mutex *mu,
std::vector<chat::chatMsg> *msgs)
: m_service(service), m_mu(mu), m_messages(msgs) {
StartRead(&m_msg);
}
void ChatReactor::OnReadDone(bool ok) {
if (ok) {
m_mu->lock();
m_messages->push_back(m_msg);
m_mu->unlock();
m_service->sendToAll(m_msg);
StartRead(&m_msg);
} else {
Finish(grpc::Status::OK);
}
}

View File

@@ -0,0 +1,21 @@
#include "logic/service.h"
#include "logic/reactor.h"
Service::~Service() {
for (auto *client : m_clients) {
delete client;
}
}
grpc::ServerBidiReactor<chat::chatMsg, chat::chatMsg> *
Service::sendMsg(grpc::CallbackServerContext *context) {
auto newClient = new ChatReactor(this, &m_mu, &m_messages);
m_clients.push_back(newClient);
return newClient;
}
void Service::sendToAll(const chat::chatMsg &msg) {
for (auto *client : m_clients) {
client->StartWrite(&msg);
}
}

View File

0
server/src/ui/.gitempty Normal file
View File