summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-24 17:51:06 +0200
committerGitHub <noreply@github.com>2021-05-24 17:51:06 +0200
commit2e1a821601299f212df414262defaf72edbeaa67 (patch)
tree626afe93c2bf9ad7176964f4beb70f2059daf798 /src
parentMerge pull request #19 from ItsNewe/master (diff)
parent[edit] Deprecate gRPC in favor of MongoDB (diff)
downloadserver-2e1a821601299f212df414262defaf72edbeaa67.tar.xz
Merge pull request #20 from ItsNewe/master
[edit] Deprecate gRPC in favor of MongoDB
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp15
-rw-r--r--src/mongoStub.cpp26
-rw-r--r--src/mongoStub.hpp29
-rw-r--r--src/rpcStub.cpp32
-rw-r--r--src/rpcStub.hpp15
5 files changed, 67 insertions, 50 deletions
diff --git a/src/main.cpp b/src/main.cpp

index 2fdeceee..bd4ebbec 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -22,15 +22,24 @@ // #include "rtcPeerHandler.hpp" //Handle peer connection requests -#include "rpcStub.hpp" //Handle gRPC communications between the different fosscord elements +#include "mongoStub.hpp" //Handle communication with the MongoDB server int main(int argc, char **argv){ auto commsHandler = std::make_shared<rtcPeerHandler>(); - auto rpcHandler = std::unique_ptr<rpcStub>(new rpcStub(commsHandler, 8057)); + auto mongoHandler = std::make_unique<mongoStub>(); + mongocxx::options::change_stream options; + mongocxx::change_stream colCs = mongoHandler->getCol().watch(options); + + //Check for new messages in the collection + for (;;){ + std::vector<std::string> t = mongoHandler->getNewMessages(&colCs); + for(auto &i : t){ + std::cout << i << std::endl; + } + } std::cout << "Server created" << std::endl; - //rpcHandler->server->Wait(); //blocking, this will need to be threaded return 0; } \ No newline at end of file diff --git a/src/mongoStub.cpp b/src/mongoStub.cpp new file mode 100644
index 00000000..50312fc6 --- /dev/null +++ b/src/mongoStub.cpp
@@ -0,0 +1,26 @@ +#include "mongoStub.hpp" + +mongoStub::mongoStub() { + if (this->client) { + this->db = client["fosscord"]; + + if (this->db) { + this->col = db["events"]; + + } else { + std::cout << "db not found"; + exit(-1); + } + } else { + std::cout << "Client couldn't be initialized"; + exit(-1); + } +} + +std::vector<std::string>mongoStub::getNewMessages(mongocxx::change_stream* colCs) { + std::vector<std::string> retVec; + for (const auto& event : *colCs) { + retVec.push_back(bsoncxx::to_json(event)); + } + return retVec; +} diff --git a/src/mongoStub.hpp b/src/mongoStub.hpp new file mode 100644
index 00000000..3cee472c --- /dev/null +++ b/src/mongoStub.hpp
@@ -0,0 +1,29 @@ +#ifndef MONGOSTUB_HPP +#define MONGOSTUB_HPP + +#include <boost/utility.hpp> +#include <cstdint> +#include <iostream> +#include <vector> +#include <mongocxx/client.hpp> +#include <mongocxx/instance.hpp> +#include <mongocxx/v_noabi/mongocxx/change_stream.hpp> +#include <bsoncxx/json.hpp> + + +class mongoStub : boost::noncopyable { + public: + mongoStub(); + std::vector<std::string> getNewMessages(mongocxx::change_stream* colCs); + + mongocxx::collection getCol() const { return col; } + + private: + mongocxx::instance instance; + mongocxx::client client{mongocxx::uri{}}; + mongocxx::database db; + mongocxx::collection col; + mongocxx::change_stream* colCs = nullptr; +}; + +#endif diff --git a/src/rpcStub.cpp b/src/rpcStub.cpp deleted file mode 100644
index 1633aab8..00000000 --- a/src/rpcStub.cpp +++ /dev/null
@@ -1,32 +0,0 @@ -#include "rpcStub.hpp" - -class fossCordInternalsImpl final : public fosscordMedia::fosscordInternals::Service { - std::shared_ptr<rtcPeerHandler> ph; - fossCordInternalsImpl(std::shared_ptr<rtcPeerHandler> handler){ - this->ph= handler; - } - grpc::Status vRequest(grpc::ServerContext* ctx, - const fosscordMedia::voiceRequest* req, - fosscordMedia::voiceAnswer* resp) override { - - this->ph->initiateConnection(req->ip(), req->port()); - return grpc::Status::OK; - } -}; - -rpcStub::rpcStub(std::shared_ptr<rtcPeerHandler> handler, int port) { - if (not port) { - port = 8057; - } - this->ph = handler; - - fossCordInternalsImpl* service; - grpc::ServerBuilder builder; - builder.AddListeningPort("0.0.0.0:" + std::to_string(port), - grpc::InsecureServerCredentials()); - builder.RegisterService(service); - - this->server = builder.BuildAndStart(); - - std::cout << "RPC stub listening on port " << port << std::endl; -} \ No newline at end of file diff --git a/src/rpcStub.hpp b/src/rpcStub.hpp deleted file mode 100644
index d183cf3c..00000000 --- a/src/rpcStub.hpp +++ /dev/null
@@ -1,15 +0,0 @@ -#include <grpc++/grpc++.h> -#include "protodefs/include/protos.grpc.pb.h" -#include "rtcPeerHandler.hpp" - -#ifndef RPCSTUB -#define RPCSTUB -class rpcStub{ - public: - rpcStub(std::shared_ptr<rtcPeerHandler> peerHandler, int port); - std::unique_ptr<grpc::Server> server; - - private: - std::shared_ptr<rtcPeerHandler> ph; -}; -#endif \ No newline at end of file