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/inc/.gitempty Normal file
View File

View File

View File

@@ -0,0 +1,33 @@
#pragma once
#include "messages.pb.h"
#include <absl/base/thread_annotations.h>
#include <absl/synchronization/mutex.h>
#include <grpcpp/support/server_callback.h>
#include <vector>
class Service;
class ChatReactor
: public grpc::ServerBidiReactor<chat::chatMsg, chat::chatMsg> {
public:
ChatReactor(Service *service, absl::Mutex *mu,
std::vector<chat::chatMsg> *msgs);
void OnReadDone(bool ok) override;
void OnWriteDone(bool /*ok*/) override { StartRead(&m_msg); }
void OnDone() override {
std::cout << "RPC Completed";
delete this;
}
void OnCancel() override { std::cout << "RPC Cancelled"; }
private:
Service *m_service;
chat::chatMsg m_msg;
absl::Mutex *m_mu;
std::vector<chat::chatMsg> *m_messages ABSL_GUARDED_BY(m_mu);
};

View File

@@ -0,0 +1,20 @@
#pragma once
#include "logic/reactor.h"
#include "messages.pb.h"
#include "services.grpc.pb.h"
#include <grpcpp/server_context.h>
#include <grpcpp/support/server_callback.h>
class Service : public chat::Chat::CallbackService {
public:
~Service();
grpc::ServerBidiReactor<chat::chatMsg, chat::chatMsg> *
sendMsg(grpc::CallbackServerContext *context) override;
void sendToAll(const chat::chatMsg &msg);
private:
std::vector<ChatReactor *> m_clients;
absl::Mutex m_mu;
std::vector<chat::chatMsg> m_messages ABSL_GUARDED_BY(m_mu);
};

View File

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