@@ -49,7 +49,7 @@ namespace AMC {
4949 {
5050 }
5151
52- void CStateSignalHandler::addSignalDefinition (const std::string& sInstanceName , const std::string& sSignalName , const std::list <CStateSignalParameter>& Parameters, const std::list <CStateSignalParameter>& Results, uint32_t nSignalReactionTimeOutInMS, uint32_t nSignalQueueSize, PParameterGroup pSignalInformationGroup)
52+ void CStateSignalHandler::addSignalDefinition (const std::string& sInstanceName , const std::string& sSignalName , const std::vector <CStateSignalParameter>& Parameters, const std::vector <CStateSignalParameter>& Results, uint32_t nSignalReactionTimeOutInMS, uint32_t nSignalQueueSize, PParameterGroup pSignalInformationGroup)
5353 {
5454 std::lock_guard<std::mutex> lockGuard (m_SignalMapMutex);
5555
@@ -61,7 +61,7 @@ namespace AMC {
6161 throw ELibMCCustomException (LIBMC_ERROR_DUPLICATESIGNAL , sInstanceName + " /" + sSignalName );
6262
6363 auto pSignal = std::make_shared<CStateSignalSlot>(sInstanceName , sSignalName , Parameters, Results, nSignalReactionTimeOutInMS, nSignalQueueSize, pSignalInformationGroup);
64- m_SignalMap.insert (std::make_pair ( std::make_pair (sInstanceName , sSignalName ), pSignal) );
64+ m_SignalMap.emplace (std::make_pair (sInstanceName , sSignalName ), pSignal);
6565 }
6666
6767 bool CStateSignalHandler::addNewInQueueSignal (const std::string& sInstanceName , const std::string& sSignalName , const std::string& sSignalUUID , const std::string& sParameterData , uint32_t nResponseTimeOutInMS, uint64_t nTimestamp)
@@ -85,9 +85,9 @@ namespace AMC {
8585 if (iUUIDIter != m_SignalUUIDLookupMap.end ())
8686 throw ELibMCCustomException (LIBMC_ERROR_SIGNALALREADYTRIGGERED , sNormalizedUUID );
8787
88-
89- if (pSlot-> addNewInQueueSignalInternal ( sNormalizedUUID , sParameterData , nResponseTimeOutInMS, nTimestamp) ) {
90- m_SignalUUIDLookupMap.insert ( std::make_pair ( sNormalizedUUID , pSlot) );
88+ auto pMessage = pSlot-> addNewInQueueSignalInternal ( sNormalizedUUID , sParameterData , nResponseTimeOutInMS, nTimestamp);
89+ if (pMessage. get () != nullptr ) {
90+ m_SignalUUIDLookupMap.emplace ( sNormalizedUUID , pSlot);
9191 return true ;
9292 }
9393
@@ -114,24 +114,26 @@ namespace AMC {
114114 for (auto it = m_SignalMap.begin (); it != m_SignalMap.end (); it++) {
115115 // Check if the first element of the key matches
116116 if (it->first .first == sInstanceName ) {
117- slotList.push_back (it->second );
117+ slotList.push_back (it->second );
118118 }
119119 }
120- }
121120
122- std::vector<std::string> clearedUUIDs;
123- for (auto pSlot : slotList) {
124- pSlot->clearQueueInternal (clearedUUIDs, nTimestamp);
125- }
126121
127- if (! clearedUUIDs. empty ())
128- {
129- std::lock_guard<std::mutex> lockGuard (m_SignalUUIDMapMutex );
122+ std::vector<std::string> clearedUUIDs;
123+ for ( auto pSlot : slotList) {
124+ pSlot-> clearQueueInternal (clearedUUIDs, nTimestamp );
130125
131- for (auto & sUUID : clearedUUIDs)
132- m_SignalUUIDLookupMap.erase (sUUID );
133- }
134126
127+ if (!clearedUUIDs.empty ())
128+ {
129+ std::lock_guard<std::mutex> lockGuard (m_SignalUUIDMapMutex);
130+
131+ for (auto & sUUID : clearedUUIDs)
132+ m_SignalUUIDLookupMap.erase (sUUID );
133+ }
134+
135+ }
136+ }
135137 }
136138
137139 void CStateSignalHandler::clearUnhandledSignalsOfType (const std::string& sInstanceName , const std::string& sSignalTypeName , uint64_t nTimestamp)
@@ -203,15 +205,19 @@ namespace AMC {
203205
204206 void CStateSignalHandler::changeSignalPhaseToHandled (const std::string& sSignalUUID , const std::string& sResultData , uint64_t nTimestamp)
205207 {
206- std::lock_guard<std::mutex> lockGuard (m_SignalUUIDMapMutex);
207-
208208 std::string sNormalizedUUID = AMCCommon::CUtils::normalizeUUIDString (sSignalUUID );
209209
210- auto iter = m_SignalUUIDLookupMap.find (sNormalizedUUID );
211- if (iter == m_SignalUUIDLookupMap.end ())
212- throw ELibMCCustomException (LIBMC_ERROR_SIGNALNOTFOUND , " signal not found while changing phase to handled (" + sNormalizedUUID + " )" );
210+ AMC ::PStateSignalSlot pSlot;
211+ {
212+ std::lock_guard<std::mutex> lockGuard (m_SignalUUIDMapMutex);
213+
214+ auto iter = m_SignalUUIDLookupMap.find (sNormalizedUUID );
215+ if (iter == m_SignalUUIDLookupMap.end ())
216+ throw ELibMCCustomException (LIBMC_ERROR_SIGNALNOTFOUND , " signal not found while changing phase to handled (" + sNormalizedUUID + " )" );
213217
214- iter->second ->changeSignalPhaseToHandledInternal (sNormalizedUUID , sResultData , nTimestamp);
218+ pSlot = iter->second ;
219+ }
220+ pSlot->changeSignalPhaseToHandledInternal (sNormalizedUUID , sResultData , nTimestamp);
215221 }
216222
217223 void CStateSignalHandler::changeSignalPhaseToInProcess (const std::string& sSignalUUID , uint64_t nTimestamp)
@@ -229,28 +235,39 @@ namespace AMC {
229235
230236 void CStateSignalHandler::changeSignalPhaseToFailed (const std::string& sSignalUUID , const std::string& sResultData , const std::string& sErrorMessage , uint64_t nTimestamp)
231237 {
232- std::lock_guard<std::mutex> lockGuard (m_SignalUUIDMapMutex);
233-
234238 std::string sNormalizedUUID = AMCCommon::CUtils::normalizeUUIDString (sSignalUUID );
235239
236- auto iter = m_SignalUUIDLookupMap.find (sNormalizedUUID );
237- if (iter == m_SignalUUIDLookupMap.end ())
238- throw ELibMCCustomException (LIBMC_ERROR_SIGNALNOTFOUND , " signal not found while changing phase to failed (" + sNormalizedUUID + " )" );
240+ PStateSignalSlot pSlot;
241+ {
242+
243+ std::lock_guard<std::mutex> lockGuard (m_SignalUUIDMapMutex);
244+ auto iter = m_SignalUUIDLookupMap.find (sNormalizedUUID );
245+ if (iter == m_SignalUUIDLookupMap.end ())
246+ throw ELibMCCustomException (LIBMC_ERROR_SIGNALNOTFOUND , " signal not found while changing phase to failed (" + sNormalizedUUID + " )" );
239247
240- iter->second ->changeSignalPhaseToInFailedInternal (sNormalizedUUID , sResultData , sErrorMessage , nTimestamp);
248+ pSlot = iter->second ;
249+ }
250+
251+ pSlot->changeSignalPhaseToInFailedInternal (sNormalizedUUID , sResultData , sErrorMessage , nTimestamp);
241252 }
242253
243254 AMC ::eAMCSignalPhase CStateSignalHandler::getSignalPhase (const std::string& sSignalUUID )
244255 {
245- std::lock_guard<std::mutex> lockGuard (m_SignalUUIDMapMutex);
246256
247257 std::string sNormalizedUUID = AMCCommon::CUtils::normalizeUUIDString (sSignalUUID );
248258
249- auto iter = m_SignalUUIDLookupMap.find (sNormalizedUUID );
250- if (iter == m_SignalUUIDLookupMap.end ())
251- throw ELibMCCustomException (LIBMC_ERROR_SIGNALNOTFOUND , " signal not found while getting signal phase (" + sNormalizedUUID + " )" );
259+ PStateSignalSlot pSlot;
260+ {
261+ std::lock_guard<std::mutex> lockGuard (m_SignalUUIDMapMutex);
262+
263+ auto iter = m_SignalUUIDLookupMap.find (sNormalizedUUID );
264+ if (iter == m_SignalUUIDLookupMap.end ())
265+ throw ELibMCCustomException (LIBMC_ERROR_SIGNALNOTFOUND , " signal not found while getting signal phase (" + sNormalizedUUID + " )" );
252266
253- return iter->second ->getSignalPhaseInternal (sNormalizedUUID );
267+ pSlot = iter->second ;
268+ }
269+
270+ return pSlot->getSignalPhaseInternal (sNormalizedUUID );
254271 }
255272
256273 std::string CStateSignalHandler::peekSignalMessageFromQueue (const std::string& sInstanceName , const std::string& sSignalName , bool bCheckForTimeouts, uint64_t nGlobalTimestamp)
@@ -275,7 +292,7 @@ namespace AMC {
275292
276293 void CStateSignalHandler::checkForReactionTimeouts (uint64_t nGlobalTimestamp)
277294 {
278- std::list <AMC ::PStateSignalSlot> slots;
295+ std::vector <AMC ::PStateSignalSlot> slots;
279296 {
280297 std::lock_guard<std::mutex> lockGuard (m_SignalMapMutex);
281298 for (auto iIter : m_SignalMap)
@@ -353,11 +370,10 @@ namespace AMC {
353370
354371 pSlot = iter->second ;
355372
356-
357- return pSlot->getReactionTimeoutInternal (sNormalizedUUID );
358-
359373 }
360374
375+ return pSlot->getReactionTimeoutInternal (sNormalizedUUID );
376+
361377 }
362378
363379 std::string CStateSignalHandler::getResultDataJSON (const std::string& sSignalUUID )
@@ -373,11 +389,10 @@ namespace AMC {
373389 throw ELibMCCustomException (LIBMC_ERROR_SIGNALNOTFOUND , " signal not found while getting result data JSON (" + sNormalizedUUID + " )" );
374390
375391 pSlot = iter->second ;
376-
377-
378- return pSlot->getResultDataJSONInternal (sNormalizedUUID );
379392 }
380393
394+
395+ return pSlot->getResultDataJSONInternal (sNormalizedUUID );
381396 }
382397
383398 bool CStateSignalHandler::findSignalPropertiesByUUID (const std::string& sSignalUUID , std::string& sInstanceName , std::string& sSignalName , std::string& sParameterData )
@@ -393,18 +408,17 @@ namespace AMC {
393408 pSlot = iter->second ;
394409 }
395410
411+ }
396412
413+ if (pSlot.get () != nullptr ) {
414+ sInstanceName = pSlot->getInstanceNameInternal ();
415+ sSignalName = pSlot->getNameInternal ();
416+ sParameterData = pSlot->getParameterDataJSONInternal (sNormalizedUUID );
417+ return true ;
418+ }
397419
398- if (pSlot.get () != nullptr ) {
399- sInstanceName = pSlot->getInstanceNameInternal ();
400- sSignalName = pSlot->getNameInternal ();
401- sParameterData = pSlot->getParameterDataJSONInternal (sNormalizedUUID );
402- return true ;
403- }
404-
405- return false ;
420+ return false ;
406421
407- }
408422
409423 }
410424
0 commit comments