TrafficLight.cpp
Go to the documentation of this file.
00001 
00002 #include <iostream>
00003 
00004 #include <QtCore/QCoreApplication>
00005 #include <QtCore/QTimer>
00006 #include <QtCore/QDebug>
00007 #include <QtCore/QDir>
00008 
00009 #include <QsLog.h>
00010 #include <QsLogDest.h>
00011 
00012 #include <SmQtObserver.h>
00013 
00014 #include "TrafficLight.h"
00015 #include "Light.h"
00016 #include <TrafficLightFsm.h> // Generated header
00017 
00018 TrafficLight::TrafficLight()
00019 {
00020     logInit();
00021     m_pLight = new Light();
00022     // Generated TrafficLightContext
00023     m_pTrafficLightContext = new TrafficLightContext(*m_pLight, this);
00024     m_pTrafficLightContext->SetObserver(SmQtObserver::GetInstance());
00025     QObject::connect(m_pTrafficLightContext,
00026                      SIGNAL(end()),
00027                      this,
00028                      SLOT(contextEnd()));
00029 }
00030 
00031 TrafficLight::~TrafficLight()
00032 {
00033     delete m_pLight;
00034 }
00035 
00036 void TrafficLight::logInit()
00037 {
00038    QCoreApplication *pApp = QCoreApplication::instance();
00039    QsLogging::Logger& logger = QsLogging::Logger::instance();
00040    logger.setLoggingLevel(QsLogging::TraceLevel);
00041    //Log to file
00042    const QString logPath(QDir(pApp->applicationDirPath()).filePath("Log.txt"));
00043    QsLogging::DestinationPtr fileDestination(
00044       QsLogging::DestinationFactory::MakeFileDestination(logPath) );
00045    logger.addDestination(fileDestination);
00046    //Log to standard output
00047    QsLogging::DestinationPtr debugDestination = QsLogging::DestinationFactory::MakeDebugOutputDestination();
00048    logger.addDestination(debugDestination);
00049 }
00050 
00051 void TrafficLight::contextEnd()
00052 {
00053     QCoreApplication::exit(0);
00054 }
00055 
00056 void TrafficLight::start()
00057 {
00058     QLOG_INFO();
00059     m_pTrafficLightContext->EnterInitialState();
00060 }
00061 
00062 #include "TrafficLight.moc"