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);
|
||||
};
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
class Message {
|
||||
public:
|
||||
Message(int, QDateTime, QString);
|
||||
Message(QString, QDateTime, QString);
|
||||
~Message() {}
|
||||
|
||||
QString toString() const;
|
||||
|
||||
private:
|
||||
int m_userId;
|
||||
QString m_userId;
|
||||
QDateTime m_timestamp;
|
||||
QString m_content;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "logic/client_reactor.h"
|
||||
#include "messages.pb.h"
|
||||
#include "models/chatroom.h"
|
||||
#include <QMainWindow>
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@@ -17,9 +20,12 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
void sendMsg(const QString &);
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
Chatroom m_chatroom;
|
||||
std::unique_ptr<Reactor> m_reactor;
|
||||
|
||||
public slots:
|
||||
void receiveMsg(QString &);
|
||||
void receiveMsg(const chat::chatMsg &);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user