-
Notifications
You must be signed in to change notification settings - Fork 1
/
ServiceContainer.cpp
65 lines (60 loc) · 2.87 KB
/
ServiceContainer.cpp
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
#include "ServiceContainer.h"
#include "Service.h"
#include "Settings.h"
#include "XFS/Logger.h"
#include <cassert>
ServiceContainer::~ServiceContainer() {
for (ServiceMap::const_iterator it = services.begin(); it != services.end(); ++it) {
assert(it->second != NULL && "Internal error: no service data while cleanup");
delete it->second;
}
services.clear();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Service& ServiceContainer::create(Manager& manager, HSERVICE hService, const Settings& settings) {
assert(!isValid(hService) && "Try to create already registered service");
Service* service = new Service(manager, hService, settings);
services.insert(std::make_pair(hService, service));
return *service;
}
Service& ServiceContainer::get(HSERVICE hService) {
assert(isValid(hService) && "Try to get not registered service");
Service* service = services.find(hService)->second;
assert(service != NULL && "Internal error: no service data for valid service handle while get service");
return *service;
}
void ServiceContainer::remove(HSERVICE hService) {
assert(isValid(hService) && "Try to remove not registered service");
ServiceMap::iterator it = services.find(hService);
assert(it->second != NULL && "Internal error: no service data for valid service handle while remove service");
// Закрытие PC/SC соединения происходит в деструкторе Service.
delete it->second;
services.erase(it);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool ServiceContainer::addSubscriber(HSERVICE hService, HWND hWndReg, DWORD dwEventClass) {
ServiceMap::iterator it = services.find(hService);
if (it == services.end()) {
return false;
}
assert(it->second != NULL && "Internal error: no service data for valid service handle while add subscribe");
it->second->add(hWndReg, dwEventClass);
return true;
}
bool ServiceContainer::removeSubscriber(HSERVICE hService, HWND hWndReg, DWORD dwEventClass) {
ServiceMap::iterator it = services.find(hService);
if (it == services.end()) {
return false;
}
assert(it->second != NULL && "Internal error: no service data for valid service handle while remove subscribe");
it->second->remove(hWndReg, dwEventClass);
return true;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void ServiceContainer::notifyChanges(const SCARD_READERSTATE& state, bool deviceChange) {
{XFS::Logger() << "ServiceContainer::notifyChanges";}
for (ServiceMap::const_iterator it = services.begin(); it != services.end(); ++it) {
assert(it->second != NULL && "Internal error: no service data while do notification");
it->second->notify(state, deviceChange);
}
}