From a689af61eb91dcbc135890276a3c6281166d30f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 18 Aug 2024 22:15:56 +0200 Subject: Test message service for sending arbitrary data --- src/test/service.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/service.cpp (limited to 'src/test/service.cpp') diff --git a/src/test/service.cpp b/src/test/service.cpp new file mode 100644 index 0000000..32fca52 --- /dev/null +++ b/src/test/service.cpp @@ -0,0 +1,37 @@ +#include "service.h" + +#include + +using namespace erebos; + +static const UUID myUUID("cb46b92c-9203-4694-8370-8742d8ac9dc8"); + +TestService::TestService( Config && c, const Server & ): + config( move(c) ) +{ +} + +TestService::~TestService() = default; + +UUID TestService::uuid() const +{ + return myUUID; +} + +void TestService::handle( Context & ctx ) +{ + auto msg = Stored< Object >::load( ctx.ref() ); + for (const auto & w : config.watchers) + w( msg ); +} + +void TestService::send( const Peer & peer, const Ref & msg ) +{ + peer.send( myUUID, msg ); +} + +TestService::Config & TestService::Config::onMessage( MessageWatcher w ) +{ + watchers.push_back(w); + return *this; +} -- cgit v1.2.3