-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterprocessCommMgr.cpp
More file actions
61 lines (52 loc) · 1.42 KB
/
InterprocessCommMgr.cpp
File metadata and controls
61 lines (52 loc) · 1.42 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
#include "InterprocessCommMgr.h"
#include <iostream>
InterprocessCommMgr& InterprocessCommMgr::GetInstance()
{
static InterprocessCommMgr instance;
return instance;
}
// Constructor
InterprocessCommMgr::InterprocessCommMgr() : instanceCount(0) {}
// Destructor
InterprocessCommMgr::~InterprocessCommMgr()
{
for (auto& entry : interprocessComms)
{
delete entry.second;
}
interprocessComms.clear();
}
InterprocessComm* InterprocessCommMgr::CreateInterprocessComm(const std::wstring& name, size_t size)
{
// Check if an instance with the same name already exists
if (interprocessComms.find(name) != interprocessComms.end())
{
return interprocessComms[name];
}
// Create a new InterprocessComm instance
InterprocessComm* comm = new InterprocessComm(name, size);
if (comm->CreateSharedMemory())
{
interprocessComms[name] = comm;
instanceCount++;
}
else
{
delete comm;
comm = nullptr;
}
return comm;
}
// Release an InterprocessComm instance and manage shared memory
void InterprocessCommMgr::ReleaseInterprocessComm(const std::wstring& name) {
auto it = interprocessComms.find(name);
if (it != interprocessComms.end()) {
// Clean up the InterprocessComm instance
delete it->second;
interprocessComms.erase(it);
}
}
int InterprocessCommMgr::GetInstanceCount() const
{
return instanceCount;
}