ConfigFileUtilsObservable.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "ConfigFileUtilsObservable.hpp"
  14. using namespace CONFIGURATOR;
  15. void CConfigFileUtilsObservable::addObserver(IConfigFileUtilsObserver& observer)
  16. {
  17. CriticalBlock block(m_critsecObserverQueue);
  18. //allow observers to register only once
  19. if (m_qObservers.find(&observer) == (unsigned)-1)
  20. m_qObservers.enqueue(&observer);
  21. }
  22. void CConfigFileUtilsObservable::removeObserver(IConfigFileUtilsObserver& observer)
  23. {
  24. CriticalBlock block(m_critsecObserverQueue);
  25. m_qObservers.dequeue(&observer);
  26. }
  27. void CConfigFileUtilsObservable::notify(enum IConfigFileUtilsObserver::CF_EVENT_TYPES eventType)
  28. {
  29. CriticalBlock block(m_critsecObserverQueue);
  30. for (unsigned int idxObservers = 0; idxObservers < m_qObservers.ordinality(); idxObservers++)
  31. {
  32. IConfigFileUtilsObserver *pConfigFileUtilsObserver = m_qObservers.query(idxObservers);
  33. if (pConfigFileUtilsObserver->getEventType() == eventType || pConfigFileUtilsObserver->getEventType() == IConfigFileUtilsObserver::CF_FILE_ANY_EVENT)
  34. {
  35. //m_qObservers.query(idxObservers)->onNotify(eventType);
  36. }
  37. }
  38. }