Able to send and receive messages, server panicking and not relaying userids yet
This commit is contained in:
34
client/inc/logic/client_reactor.h
Normal file
34
client/inc/logic/client_reactor.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "logic/message_handler.h"
|
||||
#include "messages.pb.h"
|
||||
#include "services.grpc.pb.h"
|
||||
#include <QObject>
|
||||
#include <condition_variable>
|
||||
#include <grpcpp/support/client_callback.h>
|
||||
#include <grpcpp/support/status.h>
|
||||
#include <memory>
|
||||
|
||||
class Reactor : public QObject,
|
||||
public grpc::ClientBidiReactor<chat::chatMsg, chat::chatMsg> {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Reactor(chat::Chat::Stub *);
|
||||
void OnWriteDone(bool ok) override;
|
||||
void OnReadDone(bool ok) override;
|
||||
void OnDone(const grpc::Status &s) override;
|
||||
grpc::Status Await();
|
||||
void SendMessage(const chat::chatMsg &msg);
|
||||
bool IsConnected() const;
|
||||
std::shared_ptr<MessageHandler> getHandler();
|
||||
|
||||
private:
|
||||
chat::Chat::Stub *m_stub;
|
||||
grpc::ClientContext m_context;
|
||||
chat::chatMsg m_msg;
|
||||
std::shared_ptr<MessageHandler> m_handler;
|
||||
std::mutex m_mutex;
|
||||
std::condition_variable m_cv;
|
||||
bool m_done = false;
|
||||
grpc::Status m_status;
|
||||
};
|
||||
14
client/inc/logic/message_handler.h
Normal file
14
client/inc/logic/message_handler.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages.pb.h"
|
||||
#include <QObject>
|
||||
|
||||
class MessageHandler : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MessageHandler(QObject *parent = nullptr) {}
|
||||
void emitMessageReceived(const chat::chatMsg &message);
|
||||
|
||||
signals:
|
||||
void messageReceived(const chat::chatMsg &message);
|
||||
};
|
||||
Reference in New Issue
Block a user