-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMachineObserver.hpp
86 lines (66 loc) · 3.59 KB
/
MachineObserver.hpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2019-2021 (c) Christian von Arnim, ISW University of Stuttgart (for umati and VDW e.V.)
* Copyright 2020 (c) Dominik Basner, Sotec GmbH (for VDW e.V.)
* Copyright 2021 (c) Moritz Walker, ISW University of Stuttgart (for umati and VDW e.V.)
*/
#pragma once
#include "DashboardClient.hpp"
#include <IDashboardDataClient.hpp>
#include <map>
#include <mutex>
#include <vector>
#include <set>
namespace Umati {
namespace MachineObserver {
class MachineObserver {
public:
MachineObserver(
std::shared_ptr<Dashboard::IDashboardDataClient> pDataClient,
std::shared_ptr<Umati::Dashboard::OpcUaTypeReader> pTypeReader,
std::vector<ModelOpcUa::NodeId_t> machinesFilter
);
virtual ~MachineObserver() = 0;
const int NumSkipAfterInvalid = 10; ///< in 10s, e.g. 5 means 5*10s = 50s
const int NumSkipAfterOffline = 3; ///< in 10s,
protected:
void UpdateMachines();
bool machineListsNotEqual(std::list<ModelOpcUa::BrowseResult_t> &machineList);
void recreateKnownMachineToolsMap(std::list<ModelOpcUa::BrowseResult_t> &machineList);
bool ignoreInvalidMachinesTemporarily(const ModelOpcUa::NodeId_t &newMachineId);
void addNewMachine(const ModelOpcUa::BrowseResult_t &newMachine);
void removeOfflineMachines(std::set<ModelOpcUa::NodeId_t> &toBeRemovedMachines);
bool canBrowseMachineList(std::list<ModelOpcUa::BrowseResult_t> &machineList);
void findNewAndOfflineMachines(std::list<ModelOpcUa::BrowseResult_t> &machineList,
std::set<ModelOpcUa::NodeId_t> &toBeRemovedMachines,
std::set<ModelOpcUa::NodeId_t> &newMachines,
std::map<ModelOpcUa::NodeId_t, nlohmann::json> &machinesIdentifications);
virtual void addMachine(ModelOpcUa::BrowseResult_t machine) = 0;
virtual void removeMachine(ModelOpcUa::NodeId_t machineNodeId) = 0;
virtual bool isOnline(
const ModelOpcUa::NodeId_t &machineNodeId,
nlohmann::json &identificationAsJson,
const ModelOpcUa::NodeId_t &typeDefinition
) = 0;
std::shared_ptr<Dashboard::IDashboardDataClient> m_pDataClient;
std::map<ModelOpcUa::NodeId_t, ModelOpcUa::BrowseResult_t> m_knownMachines;
std::set<ModelOpcUa::NodeId_t> m_knownMachineToolsSet;
std::map<ModelOpcUa::NodeId_t, ModelOpcUa::NodeId_t> m_parentOfMachine;
std::shared_ptr<Umati::Dashboard::OpcUaTypeReader> m_pOpcUaTypeReader;
std::mutex m_machineIdentificationsCache_mutex;
std::map<ModelOpcUa::NodeId_t, nlohmann::json> m_machineIdentificationsCache;
std::set<ModelOpcUa::NodeId_t> m_machinesFilter;
/// Blacklist of invalid machines, that will not be checked periodically
/// The value is decremented each time the machine would be checked and will only be added, when it reaches 0 again.
std::map<ModelOpcUa::NodeId_t, std::pair<int, std::string>> m_invalidMachines;
static void logMachinesChanging(const std::string &text,
const std::map<ModelOpcUa::NodeId_t, ModelOpcUa::BrowseResult_t> &newMachines);
static void logMachinesChanging(const std::string &text,
const std::set<ModelOpcUa::NodeId_t> &newMachines);
std::list<ModelOpcUa::BrowseResult_t> browseForMachines(ModelOpcUa::NodeId_t nodeid = Umati::Dashboard::NodeId_MachinesFolder, ModelOpcUa::NodeId_t parentId = Umati::Dashboard::NodeId_MachinesFolder, std::function<bool(ModelOpcUa::NodeId_t)> filter = nullptr);
std::list<ModelOpcUa::BrowseResult_t> findComponentsFolder(ModelOpcUa::NodeId_t nodeid);
};
}
}