35 lines
793 B
C++
35 lines
793 B
C++
#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) override;
|
|
void OnWriteDone(bool) override;
|
|
|
|
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);
|
|
// std::atomic<bool> m_reading{false};
|
|
};
|