-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPoggetContainerManager.cpp
More file actions
66 lines (57 loc) · 2.23 KB
/
Copy pathPoggetContainerManager.cpp
File metadata and controls
66 lines (57 loc) · 2.23 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
59
60
61
62
63
64
65
66
#include "../framework.h"
#include "PoggetContainerManager.hpp"
namespace PoggetCore {
std::shared_ptr<ContainerModel> PoggetContainerManager::CreateContainer(const std::wstring& id) {
std::lock_guard<std::mutex> lock(m_mutex);
auto it = m_containers.find(id);
if (it != m_containers.end()) {
return it->second;
}
auto model = std::make_shared<ContainerModel>();
model->id = id;
m_containers[id] = model;
return model;
}
void PoggetContainerManager::RegisterContainer(const std::wstring& id, std::shared_ptr<ContainerModel> model) {
if (id.empty() || !model) return;
std::lock_guard<std::mutex> lock(m_mutex);
model->id = id;
m_containers[id] = model;
}
std::shared_ptr<ContainerModel> PoggetContainerManager::GetContainer(const std::wstring& id) const {
std::lock_guard<std::mutex> lock(m_mutex);
auto it = m_containers.find(id);
if (it != m_containers.end()) {
return it->second;
}
return nullptr;
}
std::shared_ptr<ContainerModel> PoggetContainerManager::GetMergedHostByColor(const std::wstring& colorKey) const {
if (colorKey.empty()) return nullptr;
std::lock_guard<std::mutex> lock(m_mutex);
for (const auto& pair : m_containers) {
const auto& model = pair.second;
if (model && model->IsMergedHost && model->MergedHostColor == colorKey) {
return model;
}
}
return nullptr;
}
void PoggetContainerManager::RemoveContainer(const std::wstring& id) {
std::lock_guard<std::mutex> lock(m_mutex);
m_containers.erase(id);
}
std::vector<std::shared_ptr<ContainerModel>> PoggetContainerManager::GetAllContainers() const {
std::lock_guard<std::mutex> lock(m_mutex);
std::vector<std::shared_ptr<ContainerModel>> result;
result.reserve(m_containers.size());
for (const auto& pair : m_containers) {
result.push_back(pair.second);
}
return result;
}
void PoggetContainerManager::Clear() {
std::lock_guard<std::mutex> lock(m_mutex);
m_containers.clear();
}
} // namespace PoggetCore