Project
Loading...
Searching...
No Matches
DevicesManager.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include "Framework/Logger.h"
16#include "Framework/Signpost.h"
17
18O2_DECLARE_DYNAMIC_LOG(devices_manager);
19
20namespace o2::framework
21{
22
23void DevicesManager::queueMessage(char const* target, char const* message)
24{
25 O2_SIGNPOST_ID_GENERATE(sid, devices_manager);
26 O2_SIGNPOST_EVENT_EMIT(devices_manager, sid, "queue",
27 "Queuing message for %{public}s: %{public}s",
29 for (int di = 0; di < specs.size(); ++di) {
30 if (specs[di].id == target) {
31 messages.push_back({di, message});
32 }
33 }
34}
35
37{
38 static bool notifiedUnavailable = false;
39 static bool notifiedAvailable = false;
40 for (auto& handle : messages) {
41 auto controller = controls[handle.ref.index].controller;
42 // Device might not be started yet, by the time we write to it.
43 if (!controller) {
44 if (!notifiedUnavailable) {
45 LOGP(info, "Controller for {} not yet available.", specs[handle.ref.index].id);
46 notifiedUnavailable = true;
47 }
48 continue;
49 }
50 if (notifiedUnavailable && !notifiedAvailable) {
51 LOGP(info, "Controller for {} now available.", specs[handle.ref.index].id);
52 notifiedAvailable = true;
53 }
54 O2_SIGNPOST_ID_GENERATE(sid, devices_manager);
55 O2_SIGNPOST_EVENT_EMIT(devices_manager, sid, "flush",
56 "Flushing message to %{public}s: %{public}s",
57 specs[handle.ref.index].id.c_str(), handle.message.c_str());
58 controller->write(handle.message.c_str(), handle.message.size());
59 }
60
61 auto checkIfController = [this](DeviceMessageHandle const& handle) {
62 return this->controls[handle.ref.index].controller != nullptr;
63 };
64 auto it = std::remove_if(messages.begin(), messages.end(), checkIfController);
65 auto r = std::distance(it, messages.end());
66 messages.erase(it, messages.end());
67}
68
69} // namespace o2::framework
#define O2_DECLARE_DYNAMIC_LOG(name)
Definition Signpost.h:490
#define O2_SIGNPOST_ID_GENERATE(name, log)
Definition Signpost.h:507
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format,...)
Definition Signpost.h:523
GLenum target
Definition glcorearb.h:1641
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
GLboolean r
Definition glcorearb.h:1233
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< DeviceMessageHandle > messages
std::vector< DeviceControl > & controls
void queueMessage(char const *receiver, char const *msg)
std::vector< DeviceSpec > & specs