Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ftl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Pope
ftl
Commits
80dd8500
Commit
80dd8500
authored
6 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
Add broadcast to universe
parent
e91ca748
No related branches found
No related tags found
No related merge requests found
Pipeline
#9682
passed
6 years ago
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
net/cpp/include/ftl/net/universe.hpp
+35
-0
35 additions, 0 deletions
net/cpp/include/ftl/net/universe.hpp
with
35 additions
and
0 deletions
net/cpp/include/ftl/net/universe.hpp
+
35
−
0
View file @
80dd8500
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment