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

Add broadcast to universe

parent e91ca748
No related branches found
No related tags found
No related merge requests found
Pipeline #9682 passed
...@@ -58,6 +58,14 @@ class Universe { ...@@ -58,6 +58,14 @@ class Universe {
template <typename F> template <typename F>
void bind(const std::string &name, F func); void bind(const std::string &name, F func);
/**
* Subscribe a function to a resource. The subscribed function is
* triggered whenever that resource is published to. It is akin to
* RPC broadcast (no return value) to a subgroup of peers.
*/
template <typename F>
bool subscribe(const std::string &res, F func);
/** /**
* Send a non-blocking RPC call with no return value to all connected * Send a non-blocking RPC call with no return value to all connected
* peers. * peers.
...@@ -65,6 +73,15 @@ class Universe { ...@@ -65,6 +73,15 @@ class Universe {
template <typename... ARGS> template <typename... ARGS>
void broadcast(const std::string &name, ARGS... args); void broadcast(const std::string &name, ARGS... args);
/**
* Send a non-blocking RPC call with no return value to all subscribers
* of a resource. There may be no subscribers.
*/
template <typename... ARGS>
void publish(const std::string &res, ARGS... args);
// TODO(nick) Add find_one, find_all, call_any ...
private: private:
void _run(); void _run();
int _setDescriptors(); int _setDescriptors();
...@@ -82,8 +99,26 @@ class Universe { ...@@ -82,8 +99,26 @@ class Universe {
std::vector<ftl::net::Peer*> peers_; std::vector<ftl::net::Peer*> peers_;
ftl::UUID id_; ftl::UUID id_;
ftl::net::Dispatcher disp_; ftl::net::Dispatcher disp_;
// std::map<std::string, std::vector<ftl::net::Peer*>> subscriptions_;
}; };
//------------------------------------------------------------------------------
template <typename F>
void Universe::bind(const std::string &name, F func) {
disp_.bind(name, func,
typename ftl::internal::func_kind_info<F>::result_kind(),
typename ftl::internal::func_kind_info<F>::args_kind());
}
template <typename... ARGS>
void Universe::broadcast(const std::string &name, ARGS... args) {
for (auto p : peers_) {
p->send(name, args...);
}
}
}; // namespace net }; // namespace net
}; // namespace ftl }; // namespace ftl
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment