@@ -45,7 +45,8 @@ using namespace ocpp::x509;
4545DefaultCentralSystemEventsHandler::DefaultCentralSystemEventsHandler (std::filesystem::path iso_v2g_root_ca,
4646                                                                     std::filesystem::path iso_mo_root_ca,
4747                                                                     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),
4950      m_iso_mo_root_ca(iso_mo_root_ca),
5051      m_set_pending_status(set_pending_status),
5152      m_chargepoints(),
@@ -83,6 +84,9 @@ bool DefaultCentralSystemEventsHandler::checkCredentials(const std::string& char
8384void  DefaultCentralSystemEventsHandler::chargePointConnected (std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
8485{
8586    cout << " Charge point ["   << chargepoint->identifier () << " ] connected"   << endl;
87+ 
88+     std::lock_guard<std::mutex> lock (m_chargepoints_mutex);
89+ 
8690    auto  iter_chargepoint = m_chargepoints.find (chargepoint->identifier ());
8791    if  (iter_chargepoint == m_chargepoints.end ())
8892    {
@@ -103,13 +107,38 @@ void DefaultCentralSystemEventsHandler::removeChargePoint(const std::string& ide
103107        [this , identifier = identifier]
104108        {
105109            std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
110+ 
111+             std::lock_guard<std::mutex> lock (m_chargepoints_mutex);
106112            m_chargepoints.erase (identifier);
107113            m_pending_chargepoints.erase (identifier);
108114            m_accepted_chargepoints.erase (identifier);
109115        });
110116    t.detach ();
111117}
112118
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+ 
113142/* * @brief Constructor */ 
114143DefaultCentralSystemEventsHandler::ChargePointRequestHandler::ChargePointRequestHandler (
115144    DefaultCentralSystemEventsHandler& event_handler, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>& chargepoint)
@@ -170,12 +199,9 @@ ocpp::types::RegistrationStatus DefaultCentralSystemEventsHandler::ChargePointRe
170199    ocpp::types::RegistrationStatus ret = RegistrationStatus::Accepted;
171200    if  (m_event_handler.setPendingEnabled ())
172201    {
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 ()))
176203        {
177-             m_event_handler.pendingChargePoints ()[m_chargepoint->identifier ()] = m_chargepoint;
178- 
204+             m_event_handler.addPendingChargePoint (m_chargepoint);
179205            ret = RegistrationStatus::Pending;
180206        }
181207    }
0 commit comments