MeVisLab Toolbox Reference
SocketCreationSession.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3
4#pragma once
5
6#include <asio/Signal.h>
7#include <asio/Socket.h>
8
9#include <FMEThirdPartyWarningsDisable.h>
10#include <memory>
11#include <utility>
12#include <FMEThirdPartyWarningsRestore.h>
13
14namespace asio {
15
22 template<typename SessionType>
23 class SocketCreationSession : public std::enable_shared_from_this<SessionType>
24 {
25 public:
26
27 template<typename... Arguments>
28 static std::shared_ptr<SessionType> create(Arguments&&... arguments)
29 {
30 return std::shared_ptr<SessionType>(new SessionType(std::forward<Arguments>(arguments)...));
31 }
32
33 template<typename Slot>
35 {
36 return connectionEstablished.connect(std::forward<Slot>(slot));
37 }
38
39 template<typename Slot>
41 {
42 return errorOccured.connect(std::forward<Slot>(slot));
43 }
44
45 template<typename Slot>
47 {
48 return aboutToBeDestroyed.connect(std::forward<Slot>(slot));
49 }
50
52 {
53 aboutToBeDestroyed();
54 }
55
56 protected:
57
58 void emitConnectionEstablished(std::unique_ptr<Socket> socket)
59 {
60 connectionEstablished(socket);
61 }
62
64 {
65 errorOccured(ec);
66 }
67
68 private:
69
70 Signal<void(std::unique_ptr<Socket>&)> connectionEstablished;
71 Signal<void(const ErrorCode&)> errorOccured;
72 Signal<void()> aboutToBeDestroyed;
73 };
74
75}
Class template facilitating the definition of asio::Socket generators.
void emitConnectionEstablished(std::unique_ptr< Socket > socket)
SignalConnection observeErrorOccured(Slot &&slot)
static std::shared_ptr< SessionType > create(Arguments &&... arguments)
SignalConnection observeConnectionEstablished(Slot &&slot)
SignalConnection observeAboutToBeDestroyed(Slot &&slot)
void emitErrorOccured(const ErrorCode &ec)
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
boost::signals2::connection SignalConnection
Definition Signal.h:23
boost::signals2::signal< Signature... > Signal
Definition Signal.h:21
boost::system::error_code ErrorCode
Definition ErrorCodes.h:13