diff --git a/CMakeLists.txt b/CMakeLists.txt
index cebd3adf..2cf5c0a6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,32 +1,16 @@
-cmake_minimum_required(VERSION 3.15)
+cmake_minimum_required(VERSION 3.2)
project(fosscord-media)
set(CMAKE_CXX_STANDARD 17)
find_package(Threads REQUIRED)
-find_package(Protobuf REQUIRED)
-find_package(gRPC CONFIG REQUIRED)
-find_package(absl REQUIRED)
-find_package(nlohmann_json REQUIRED)
-file(GLOB SourceFiles ${PROJECT_SOURCE_DIR}/src/*.cpp)
-
-file(GLOB ProtoFiles ${PROJECT_SOURCE_DIR}/src/protodefs/*.proto)
-set(PROTOBUF_INPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/src/protodefs)
-set(PROTOBUF_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/src/protodefs/include)
-
-foreach(file ${ProtoFiles})
- execute_process(COMMAND "LD_LIBRARY_PATH=/usr/local/lib protoc --proto_path=\"${PROTOBUF_INPUT_DIRECTORY}\"
- --cpp_out=\"${PROJECT_SOURCE_DIR}/src/protodefs/include\" --grpc_out=\"${PROJECT_SOURCE_DIR}/src/protodefs/include\"
- --plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin protos.proto"
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
-endforeach()
+find_package(mongocxx REQUIRED)
+find_package(Boost REQUIRED)
-include_directories(${Protobuf_INCLUDE_DIRS})
-
-#protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ProtoFiles)
-
+file(GLOB SourceFiles ${PROJECT_SOURCE_DIR}/src/*.cpp)
+#include_directories("bsoncxx/v_noabi/bsoncxx/")
add_executable(${CMAKE_PROJECT_NAME} ${SourceFiles})
-target_link_libraries(${CMAKE_PROJECT_NAME} datachannel gRPC::grpc++ absl::base absl::synchronization absl::strings ${Protobuf_LIBRARIES} nlohmann_json::nlohmann_json)
\ No newline at end of file
+target_link_libraries(${CMAKE_PROJECT_NAME} datachannel mongo::mongocxx_shared Boost::boost)
\ No newline at end of file
diff --git a/README.md b/README.md
index 4ddd4708..a1ff3c08 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ A Fosscord media (voice and video) server
## Installation
### Prerequisites
- Install the [libdatachannel](https://github.com/paullouisageneau/libdatachannel) library
-- Install the [gRPC](https://github.com/grpc/grpc) library
+- Install the [limbongocxx]() driver
### Building
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
|