TrafficLightTimer.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * Copyright (c) 2012 committers of YAKINDU and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. * Contributors:
  8. * m.muehlbrandt - initial API and implementation
  9. *
  10. */
  11. #include "TrafficLightTimer.h"
  12. TrafficLightTimer::TrafficLightTimer(TrafficLightWaiting *sc_handle) :
  13. QObject() {
  14. this->sc_handle = sc_handle;
  15. }
  16. void TrafficLightTimer::setTimer(const sc_eventid evid,
  17. const sc_integer time_ms, const sc_boolean periodic) {
  18. TimeEvent *timeEvent = new TimeEvent(evid, time_ms, periodic);
  19. timerMap.insert(evid, timeEvent);
  20. connect(timeEvent, SIGNAL(timeout(sc_eventid)), this,
  21. SLOT(raiseTimeEvent(sc_eventid)));
  22. }
  23. void TrafficLightTimer::unsetTimer(const sc_eventid evid) {
  24. if (timerMap.contains(evid)) {
  25. TimeEvent *timeEvent = timerMap.value(evid);
  26. disconnect(timeEvent, SIGNAL(timeout(sc_eventid)), this,
  27. SLOT(raiseTimeEvent(sc_eventid)));
  28. delete timeEvent;
  29. timerMap.remove(evid);
  30. }
  31. }
  32. void TrafficLightTimer::raiseTimeEvent(sc_eventid evid) {
  33. trafficLightWaiting_raiseTimeEvent(sc_handle, evid);
  34. }
  35. TrafficLightTimer::~TrafficLightTimer() {
  36. }