@@ -45,7 +45,8 @@ using namespace ocpp::x509;
45
45
DefaultCentralSystemEventsHandler::DefaultCentralSystemEventsHandler (std::filesystem::path iso_v2g_root_ca,
46
46
std::filesystem::path iso_mo_root_ca,
47
47
bool set_pending_status)
48
- : m_iso_v2g_root_ca(iso_v2g_root_ca),
48
+ : m_chargepoints_mutex(),
49
+ m_iso_v2g_root_ca(iso_v2g_root_ca),
49
50
m_iso_mo_root_ca(iso_mo_root_ca),
50
51
m_set_pending_status(set_pending_status),
51
52
m_chargepoints(),
@@ -83,6 +84,9 @@ bool DefaultCentralSystemEventsHandler::checkCredentials(const std::string& char
83
84
void DefaultCentralSystemEventsHandler::chargePointConnected (std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
84
85
{
85
86
cout << " Charge point [" << chargepoint->identifier () << " ] connected" << endl;
87
+
88
+ std::lock_guard<std::mutex> lock (m_chargepoints_mutex);
89
+
86
90
auto iter_chargepoint = m_chargepoints.find (chargepoint->identifier ());
87
91
if (iter_chargepoint == m_chargepoints.end ())
88
92
{
@@ -103,13 +107,38 @@ void DefaultCentralSystemEventsHandler::removeChargePoint(const std::string& ide
103
107
[this , identifier = identifier]
104
108
{
105
109
std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
110
+
111
+ std::lock_guard<std::mutex> lock (m_chargepoints_mutex);
106
112
m_chargepoints.erase (identifier);
107
113
m_pending_chargepoints.erase (identifier);
108
114
m_accepted_chargepoints.erase (identifier);
109
115
});
110
116
t.detach ();
111
117
}
112
118
119
+ /* * @brief Indicate if a charge point must be accepted */
120
+ bool DefaultCentralSystemEventsHandler::isAcceptedChargePoint (const std::string& identifier)
121
+ {
122
+ std::lock_guard<std::mutex> lock (m_chargepoints_mutex);
123
+ return (m_accepted_chargepoints.find (identifier) != m_accepted_chargepoints.end ());
124
+ }
125
+
126
+ /* * @brief Add a charge point to the pending list */
127
+ void DefaultCentralSystemEventsHandler::addPendingChargePoint (
128
+ std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
129
+ {
130
+ std::lock_guard<std::mutex> lock (m_chargepoints_mutex);
131
+ m_pending_chargepoints[chargepoint->identifier ()] = chargepoint;
132
+ }
133
+
134
+ /* * @brief Add a charge point to the accepted list */
135
+ void DefaultCentralSystemEventsHandler::addAcceptedChargePoint (
136
+ std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
137
+ {
138
+ std::lock_guard<std::mutex> lock (m_chargepoints_mutex);
139
+ m_accepted_chargepoints[chargepoint->identifier ()] = chargepoint;
140
+ }
141
+
113
142
/* * @brief Constructor */
114
143
DefaultCentralSystemEventsHandler::ChargePointRequestHandler::ChargePointRequestHandler (
115
144
DefaultCentralSystemEventsHandler& event_handler, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>& chargepoint)
@@ -170,12 +199,9 @@ ocpp::types::RegistrationStatus DefaultCentralSystemEventsHandler::ChargePointRe
170
199
ocpp::types::RegistrationStatus ret = RegistrationStatus::Accepted;
171
200
if (m_event_handler.setPendingEnabled ())
172
201
{
173
- auto accepted_chargepoint = m_event_handler.acceptedChargePoints ();
174
- auto iter_accepted = accepted_chargepoint.find (m_chargepoint->identifier ());
175
- if (iter_accepted == accepted_chargepoint.end ())
202
+ if (!m_event_handler.isAcceptedChargePoint (m_chargepoint->identifier ()))
176
203
{
177
- m_event_handler.pendingChargePoints ()[m_chargepoint->identifier ()] = m_chargepoint;
178
-
204
+ m_event_handler.addPendingChargePoint (m_chargepoint);
179
205
ret = RegistrationStatus::Pending;
180
206
}
181
207
}
0 commit comments