Falcon
Toggle main menu visibility
Loading...
Searching...
No Matches
processorgraph.hpp
1
// ---------------------------------------------------------------------
2
// This file is part of falcon-core.
3
//
4
// Copyright (C) 2015, 2016, 2017 Neuro-Electronics Research Flanders
5
//
6
// Falcon-server is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
10
//
11
// Falcon-server is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License
17
// along with falcon-core. If not, see <http://www.gnu.org/licenses/>.
18
// ---------------------------------------------------------------------
19
20
#pragma once
21
22
#include <cstring>
23
#include <exception>
24
#include <map>
25
#include <memory>
26
#include <string>
27
#include <utility>
28
#include <vector>
29
30
#include "connectionparser.hpp"
31
#include "graphexceptions.hpp"
32
#include "iprocessor.hpp"
33
#include "logging/log.hpp"
34
#include "runinfo.hpp"
35
#include "yaml-cpp/yaml.h"
36
47
YAML::Node LoadProcessorDoc(std::string processor);
48
49
namespace
graph {
50
51
enum class
GraphState {
52
NOGRAPH,
53
CONSTRUCTING,
54
PREPARING,
55
READY,
56
STARTING,
57
PROCESSING,
58
STOPPING,
59
ERROR
60
};
61
62
class
ProcessorGraph {
63
public
:
64
ProcessorGraph(
GlobalContext
& context);
65
66
bool
terminated() {
return
terminate_signal_.load(); }
67
68
bool
done() {
69
// graph is done, if it has terminated or PROCESSING and no processor is
70
// running
71
if
(state_ != GraphState::PROCESSING) {
72
return
false
;
73
}
74
75
if
(terminated()) {
76
LOG(DEBUG) <<
"done: terminated=true."
;
77
return
true
;
78
}
79
80
return
!any_processor_running();
81
}
82
83
bool
all_processors_running() {
84
for
(
auto
& it : processors_) {
85
if
(!it.second.second->running()) {
86
return
false
;
87
}
88
}
89
return
true
;
90
}
91
bool
any_processor_running() {
92
for
(
auto
& it : processors_) {
93
if
(it.second.second->running()) {
94
return
true
;
95
}
96
}
97
return
false
;
98
}
99
109
void
ConstructProcessorEngines
(
const
YAML::Node& node);
110
115
YAML::Node
GetProcessorDocumentation
();
116
124
void
Build
(
const
YAML::Node& node);
125
void
Destroy();
126
void
StartProcessing(
const
std::string& run_group_id,
const
std::string& run_id,
127
const
std::string& template_id,
bool
test_flag);
128
void
StopProcessing();
134
void
Update
(YAML::Node& node);
140
void
Retrieve
(YAML::Node& node);
146
void
Apply
(YAML::Node& node);
147
148
std::string ExportYAML();
149
150
GraphState state()
const
{
return
state_; }
151
std::string state_string()
const
;
152
void
set_state(GraphState state) {
153
state_ = state;
154
LOG(STATE) << state_string();
155
}
156
157
const
ProcessorMap& processors()
const
{
return
processors_; }
158
const
StreamConnections& connections()
const
{
return
connections_; }
159
160
IProcessor
* LookUpProcessor(
const
std::string& name);
161
std::vector<std::pair<std::string, std::shared_ptr<IState>>> LookUpStates(
162
const
std::vector<std::string>& state_addresses);
163
164
void
BuildSharedStates(
const
YAML::Node& node);
165
166
protected
:
167
void
CreateConnection(
SlotAddress
& out,
SlotAddress
& in);
168
169
private
:
170
YAML::Node yaml_;
171
YAML::Node documentation_;
172
173
GlobalContext
& global_context_;
174
175
ProcessorMap processors_;
176
StreamConnections connections_;
177
178
SharedStateMap
shared_state_map_;
179
180
GraphState state_ = GraphState::NOGRAPH;
181
182
std::unique_ptr<RunContext> run_context_;
183
std::atomic<bool> terminate_signal_;
184
};
185
186
}
// namespace graph
GlobalContext
Definition
context.hpp:54
IProcessor
Definition
iprocessor.hpp:59
SharedStateMap
Definition
sharedstate.hpp:376
SlotAddress
Definition
connections.hpp:54
graph::ProcessorGraph::Build
void Build(const YAML::Node &node)
Definition
processorgraph.cpp:361
graph::ProcessorGraph::ConstructProcessorEngines
void ConstructProcessorEngines(const YAML::Node &node)
Definition
processorgraph.cpp:137
graph::ProcessorGraph::Apply
void Apply(YAML::Node &node)
Definition
processorgraph.cpp:687
graph::ProcessorGraph::Retrieve
void Retrieve(YAML::Node &node)
Definition
processorgraph.cpp:633
graph::ProcessorGraph::GetProcessorDocumentation
YAML::Node GetProcessorDocumentation()
Definition
processorgraph.cpp:239
graph::ProcessorGraph::Update
void Update(YAML::Node &node)
Definition
processorgraph.cpp:571
falcon
processorgraph.hpp
Generated by
1.18.0