-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDevicesManager.cxx
More file actions
58 lines (52 loc) · 1.96 KB
/
DevicesManager.cxx
File metadata and controls
58 lines (52 loc) · 1.96 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "Framework/DevicesManager.h"
#include "Framework/RuntimeError.h"
#include "Framework/Logger.h"
#include "Framework/DeviceController.h"
namespace o2::framework
{
void DevicesManager::queueMessage(char const* target, char const* message)
{
for (int di = 0; di < specs.size(); ++di) {
if (specs[di].id == target) {
messages.push_back({di, message});
}
}
}
void DevicesManager::flush()
{
static bool notifiedUnavailable = false;
static bool notifiedAvailable = false;
for (auto& handle : messages) {
auto controller = controls[handle.ref.index].controller;
// Device might not be started yet, by the time we write to it.
if (!controller) {
if (!notifiedUnavailable) {
LOGP(info, "Controller for {} not yet available.", specs[handle.ref.index].id);
notifiedUnavailable = true;
}
continue;
}
if (notifiedUnavailable && !notifiedAvailable) {
LOGP(info, "Controller for {} now available.", specs[handle.ref.index].id);
notifiedAvailable = true;
}
controller->write(handle.message.c_str(), handle.message.size());
}
auto checkIfController = [this](DeviceMessageHandle const& handle) {
return this->controls[handle.ref.index].controller != nullptr;
};
auto it = std::remove_if(messages.begin(), messages.end(), checkIfController);
auto r = std::distance(it, messages.end());
messages.erase(it, messages.end());
}
} // namespace o2::framework