Skip to content
Snippets Groups Projects
Commit 02e8f497 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Merge branch 'feature/#48' into 'main'

#48 Add service provider

See merge request beyondaka/beyond-protocol!37
parents 2cc9f67c b9bf520e
No related branches found
No related tags found
No related merge requests found
...@@ -192,6 +192,7 @@ add_library(beyond-protocol STATIC ...@@ -192,6 +192,7 @@ add_library(beyond-protocol STATIC
src/protocol.cpp src/protocol.cpp
src/rpc.cpp src/rpc.cpp
src/channelUtils.cpp src/channelUtils.cpp
src/service.cpp
) )
target_include_directories(beyond-protocol PUBLIC target_include_directories(beyond-protocol PUBLIC
......
...@@ -25,6 +25,7 @@ namespace protocol { ...@@ -25,6 +25,7 @@ namespace protocol {
class Node; class Node;
class Stream; class Stream;
class Service;
/** /**
* @brief A wrapper providing RPC API and local node management. Internally the * @brief A wrapper providing RPC API and local node management. Internally the
...@@ -48,6 +49,16 @@ class Self { ...@@ -48,6 +49,16 @@ class Self {
*/ */
std::shared_ptr<ftl::protocol::Node> connectNode(const std::string &uri); std::shared_ptr<ftl::protocol::Node> connectNode(const std::string &uri);
/**
* @brief Connect to the web service.
*
* Only one service connection is allowed per self object.
*
* @param uri
* @return std::shared_ptr<ftl::protocol::Service>
*/
std::shared_ptr<ftl::protocol::Service> connectService(const std::string &uri);
/** /**
* @brief Create a new stream. Use the namespace method if possible. * @brief Create a new stream. Use the namespace method if possible.
* *
......
/**
* @file service.hpp
* @copyright Copyright (c) 2022 University of Turku, MIT License
* @author Nicolas Pope
*/
#pragma once
#include <ftl/protocol/node.hpp>
namespace ftl {
namespace protocol {
class Service: public ftl::protocol::Node {
public:
explicit Service(const ftl::net::PeerPtr &impl);
virtual ~Service();
};
} // namespace protocol
} // namespace ftl
...@@ -36,9 +36,9 @@ std::shared_ptr<ftl::protocol::Self> ftl::createDummySelf() { ...@@ -36,9 +36,9 @@ std::shared_ptr<ftl::protocol::Self> ftl::createDummySelf() {
return std::make_shared<ftl::protocol::Self>(u); return std::make_shared<ftl::protocol::Self>(u);
} }
/*std::shared_ptr<ftl::protocol::Service> ftl::setServiceProvider(const std::string &uri) { std::shared_ptr<ftl::protocol::Service> ftl::setServiceProvider(const std::string &uri) {
return getSelf()->connectService(uri);
}*/ }
std::shared_ptr<ftl::protocol::Node> ftl::connectNode(const std::string &uri) { std::shared_ptr<ftl::protocol::Node> ftl::connectNode(const std::string &uri) {
return getSelf()->connectNode(uri); return getSelf()->connectNode(uri);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "universe.hpp" #include "universe.hpp"
#include <ftl/protocol/self.hpp> #include <ftl/protocol/self.hpp>
#include <ftl/protocol/service.hpp>
#include "./streams/netstream.hpp" #include "./streams/netstream.hpp"
#include "./streams/filestream.hpp" #include "./streams/filestream.hpp"
#include <ftl/protocol/muxer.hpp> #include <ftl/protocol/muxer.hpp>
...@@ -24,6 +25,10 @@ std::shared_ptr<ftl::protocol::Node> Self::connectNode(const std::string &uri) { ...@@ -24,6 +25,10 @@ std::shared_ptr<ftl::protocol::Node> Self::connectNode(const std::string &uri) {
return std::make_shared<ftl::protocol::Node>(universe_->connect(uri)); return std::make_shared<ftl::protocol::Node>(universe_->connect(uri));
} }
std::shared_ptr<ftl::protocol::Service> Self::connectService(const std::string &uri) {
return std::make_shared<ftl::protocol::Service>(universe_->connect(uri));
}
std::shared_ptr<ftl::protocol::Stream> Self::createStream(const std::string &uri) { std::shared_ptr<ftl::protocol::Stream> Self::createStream(const std::string &uri) {
ftl::URI u(uri); ftl::URI u(uri);
......
/**
* @file service.cpp
* @copyright Copyright (c) 2022 University of Turku, MIT License
* @author Nicolas Pope
*/
#include <ftl/protocol/service.hpp>
using ftl::protocol::Service;
using ftl::protocol::Node;
Service::Service(const ftl::net::PeerPtr &impl): Node(impl) {}
Service::~Service() {}
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <ftl/protocol.hpp> #include <ftl/protocol.hpp>
#include <ftl/protocol/self.hpp> #include <ftl/protocol/self.hpp>
#include <ftl/protocol/node.hpp> #include <ftl/protocol/node.hpp>
#include <ftl/protocol/service.hpp>
#include <ftl/uri.hpp> #include <ftl/uri.hpp>
#include <ftl/exception.hpp> #include <ftl/exception.hpp>
#include <ftl/lib/nlohmann/json.hpp> #include <ftl/lib/nlohmann/json.hpp>
...@@ -50,7 +51,7 @@ TEST_CASE("RPC List Streams", "[rpc]") { ...@@ -50,7 +51,7 @@ TEST_CASE("RPC List Streams", "[rpc]") {
{ {
auto uri = "tcp://127.0.0.1:" + std::to_string(self->getListeningURIs().front().getPort()); auto uri = "tcp://127.0.0.1:" + std::to_string(self->getListeningURIs().front().getPort());
LOG(INFO) << uri; LOG(INFO) << uri;
auto p = ftl::connectNode(uri); auto p = ftl::setServiceProvider(uri);
REQUIRE(p); REQUIRE(p);
REQUIRE(p->waitConnection(5)); REQUIRE(p->waitConnection(5));
REQUIRE(self->waitConnections(5) == 1); REQUIRE(self->waitConnections(5) == 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment