CatapultServer  v0.5.0.1 (Elephant)
ServiceUtils.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "ServiceLocator.h"
25 #include <string>
26 
27 namespace catapult { namespace extensions {
28 
30  template<typename TSink>
31  TSink CreatePushEntitySink(const extensions::ServiceLocator& locator, const std::string& serviceName) {
32  return [&locator, serviceName](const auto& entities) {
33  auto payload = ionet::CreateBroadcastPayload(entities);
34  locator.service<net::PacketWriters>(serviceName)->broadcast(payload);
35  };
36  }
37 
39  template<typename TSink>
40  TSink CreatePushEntitySink(const extensions::ServiceLocator& locator, const std::string& serviceName, ionet::PacketType packetType) {
41  return [&locator, serviceName, packetType](const auto& entities) {
42  auto payload = ionet::CreateBroadcastPayload(entities, packetType);
43  locator.service<net::PacketWriters>(serviceName)->broadcast(payload);
44  };
45  }
46 }}
catapult::net::PacketWriters
Manages a collection of connections that send data to external nodes.
Definition: PacketWriters.h:41
BroadcastUtils.h
PacketWriters.h
ServiceLocator.h
catapult::extensions::ServiceLocator::service
std::shared_ptr< TService > service(const std::string &serviceName) const
Gets the service with serviceName.
Definition: ServiceLocator.h:74
catapult::ionet::PacketType
PacketType
An enumeration of known packet types.
Definition: PacketType.h:171
catapult::ionet::CreateBroadcastPayload
PacketPayload CreateBroadcastPayload(const std::shared_ptr< const model::Block > &pBlock)
Creates a payload around pBlock for broadcasting.
Definition: BroadcastUtils.cpp:28
catapult::extensions::CreatePushEntitySink
TSink CreatePushEntitySink(const extensions::ServiceLocator &locator, const std::string &serviceName)
Creates a sink that pushes entities using a service identified by serviceName in locator.
Definition: ServiceUtils.h:31
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::extensions::ServiceLocator
A service locator for local node services.
Definition: ServiceLocator.h:33