MeVisLab Toolbox Reference
ProcessorConnection.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/Connection.h>
7#include <asio/Observable.h>
8#include <asio/Executable.h>
12
13#include <FMEThirdPartyWarningsDisable.h>
14#include <memory>
15#include <FMEThirdPartyWarningsRestore.h>
16
17namespace asio {
18
19 template<typename... Args>
21
60 template<typename... Args>
62 {
63 public:
64
65 using Source = Observable<Args...>;
66 using Target = Executable<Args...>;
67
69
70 ProcessorConnection(std::shared_ptr<Source> source, std::shared_ptr<Target> target, std::unique_ptr<ExecutionPolicy> execution_policy, bool mute_until_target_execution_finished = false)
71 : policy(std::move(execution_policy))
72 , isSynchronousExecution(dynamic_cast<SynchronousExecution*>(policy.get()) != nullptr)
73 {
74 auto handle = guard.handle();
76 connection = source->signal.connect_extended([this, handle, target](const SignalConnection& conn, const Args&... args) {
77 auto lock = handle.lock();
78 if (lock) {
80 if (isSynchronousExecution) {
81 target->execute(args...);
82 }
83 else {
84 policy->execute([target, skip_until_finished, args...]{
85 target->execute(args...);
86 });
87 }
88 }
89 });
90 }
91 else {
92 connection = source->signal.connect([this, handle, target](const Args&... args) {
93 auto lock = handle.lock();
94 if (lock) {
95 if (isSynchronousExecution) {
96 target->execute(args...);
97 }
98 else {
99 policy->execute([target, args...]{
100 target->execute(args...);
101 });
102 }
103 }
104 });
105 }
106 }
107
108 void suspend() override
109 {
110 block = SharedSignalConnectionBlock(connection);
111 }
112
113 void resume() override
114 {
116 }
117
118 private:
119
120 std::unique_ptr<ExecutionPolicy> policy;
121 bool isSynchronousExecution;
122 ScopedSignalConnection connection;
124
126 };
127
128}
Abstract base class for a connection between two I/O processors.
Definition Connection.h:16
ProcessorConnection(std::shared_ptr< Source > source, std::shared_ptr< Target > target, std::unique_ptr< ExecutionPolicy > execution_policy, bool mute_until_target_execution_finished=false)
A guard that protects resources of a given class from being detroyed if another thread still works wi...
An synchronous execution policy.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
boost::signals2::connection SignalConnection
Definition Signal.h:23
boost::signals2::shared_connection_block SharedSignalConnectionBlock
Definition Signal.h:27
boost::signals2::scoped_connection ScopedSignalConnection
Definition Signal.h:25
STL namespace.