summaryrefslogtreecommitdiff
path: root/src/test/service.cpp
blob: 32fca5201437df816ec8b7a7242cbb1f73b8545a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "service.h"

#include <erebos/network.h>

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;
}