summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/erebos/service.h4
-rw-r--r--src/network.cpp24
-rw-r--r--src/service.cpp10
-rw-r--r--src/service.h1
4 files changed, 30 insertions, 9 deletions
diff --git a/include/erebos/service.h b/include/erebos/service.h
index 2d6fbce..fa7f105 100644
--- a/include/erebos/service.h
+++ b/include/erebos/service.h
@@ -1,5 +1,6 @@
#pragma once
+#include <erebos/state.h>
#include <erebos/uuid.h>
#include <memory>
@@ -22,6 +23,9 @@ public:
const class Ref & ref() const;
const class Peer & peer() const;
+ const Stored<LocalState> & local() const;
+ void local(const LocalState &);
+
private:
std::unique_ptr<Priv> p;
};
diff --git a/src/network.cpp b/src/network.cpp
index eab0f67..c0bcc2a 100644
--- a/src/network.cpp
+++ b/src/network.cpp
@@ -550,16 +550,22 @@ void Server::Peer::updateService(ReplyBuilder & reply)
for (auto & x : serviceQueue) {
if (auto ref = std::get<1>(x)->check(reply)) {
if (lpeer) {
- Service::Context ctx(new Service::Context::Priv {
- .ref = *ref,
- .peer = erebos::Peer(lpeer),
- });
-
- for (auto & svc : server.services)
- if (svc->uuid() == std::get<UUID>(x)) {
- svc->handle(ctx);
- break;
+ server.localHead.update([&] (const Stored<LocalState> & local) {
+ Service::Context ctx(new Service::Context::Priv {
+ .ref = *ref,
+ .peer = erebos::Peer(lpeer),
+ .local = local,
+ });
+
+ for (auto & svc : server.services) {
+ if (svc->uuid() == std::get<UUID>(x)) {
+ svc->handle(ctx);
+ break;
+ }
}
+
+ return ctx.local();
+ });
}
} else {
next.push_back(std::move(x));
diff --git a/src/service.cpp b/src/service.cpp
index f8217c8..c731990 100644
--- a/src/service.cpp
+++ b/src/service.cpp
@@ -23,3 +23,13 @@ const Peer & Service::Context::peer() const
{
return p->peer;
}
+
+const Stored<LocalState> & Service::Context::local() const
+{
+ return p->local;
+}
+
+void Service::Context::local(const LocalState & ls)
+{
+ p->local = p->local.ref().storage().store(ls);
+}
diff --git a/src/service.h b/src/service.h
index 9980471..5296bb3 100644
--- a/src/service.h
+++ b/src/service.h
@@ -9,6 +9,7 @@ struct Service::Context::Priv
{
Ref ref;
Peer peer;
+ Stored<LocalState> local;
};
}