Skip to content

Commit

Permalink
Issue 6: Scoring
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanP committed Jun 1, 2012
1 parent d24fc27 commit 30110c0
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 16 deletions.
3 changes: 2 additions & 1 deletion ievent-service/ievent-service/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "boost/shared_ptr.hpp"
#include "yaml-cpp/yaml.h"

#include "Types.hpp"

using namespace std;

namespace IEvent
Expand All @@ -23,7 +25,6 @@ namespace IEvent
};

typedef boost::shared_ptr<Driver> DriverPtr;
typedef boost::shared_ptr<YAML::Emitter> EmitterPtr;

void driverToYaml(DriverPtr driver, EmitterPtr em);
}
Expand Down
17 changes: 17 additions & 0 deletions ievent-service/ievent-service/ResultsEntry.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#include "ResultsEntry.h"

using namespace IEvent::Service;

void IEvent::Service::resultsEntryToYaml(ResultsEntryPtr ptr, EmitterPtr em) {
(*em) << YAML::BeginMap;
(*em) << YAML::Key << "CarNumber" << YAML::Value << ptr->driver->carNumber;
(*em) << YAML::Key << "FastestLapNumber" << YAML::Value << ptr->fastestLapNumber;
(*em) << YAML::Key << "FastestLapTime" << YAML::Value << ptr->fastestLapTime;
(*em) << YAML::Key << "Lap" << YAML::Value << ptr->lap;
(*em) << YAML::Key << "LapsComplete" << YAML::Value << ptr->lapsComplete;
(*em) << YAML::Key << "LapsDriven" << YAML::Value << ptr->lapsDriven;
(*em) << YAML::Key << "LapsLed" << YAML::Value << ptr->lapsLed;
(*em) << YAML::Key << "LastLapTime" << YAML::Value << ptr->lastLapTime;
(*em) << YAML::Key << "Position" << YAML::Value << ptr->position;
// TODO (*em) << YAML::Key << "PositionInClass" << YAML::Value << ptr->positionInClass;
(*em) << YAML::Key << "ReasonOut" << YAML::Value << ptr->reasonOut;
(*em) << YAML::Key << "Time" << YAML::Value << ptr->time;
(*em) << YAML::EndMap;
}
2 changes: 2 additions & 0 deletions ievent-service/ievent-service/ResultsEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace IEvent
};

typedef boost::shared_ptr<ResultsEntry> ResultsEntryPtr;

void resultsEntryToYaml(ResultsEntryPtr ptr, EmitterPtr em);
}

}
5 changes: 5 additions & 0 deletions ievent-service/ievent-service/Session.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#include "Session.h"


using namespace IEvent::Service;

void IEvent::Service::sessionToYaml(SessionPtr session, EmitterPtr em) {

}
2 changes: 2 additions & 0 deletions ievent-service/ievent-service/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace IEvent
};

typedef boost::shared_ptr<Session> SessionPtr;

void sessionToYaml(SessionPtr session, EmitterPtr em);
}
}

17 changes: 2 additions & 15 deletions ievent-service/ievent-service/SessionInfoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void SessionInfoHandler::handleSessionInfo(const YAML::Node& yamlSessionInfo, ch
assert(ptr->driver);
SessionInfo::sessions[sessionId]->resultsByCarIdx[carIdx] = ptr;
changed = true;
positionChanged = true;
}


Expand Down Expand Up @@ -275,26 +276,12 @@ void SessionInfoHandler::handleSessionInfo(const YAML::Node& yamlSessionInfo, ch
(*em) << YAML::BeginMap << YAML::Key << "SessionNum" << YAML::Value << sessionId;
(*em) << YAML::Key << "Results" << YAML::Value <<YAML::BeginSeq;
BOOST_FOREACH (ResultsEntryPtr ptr, changedEntries) {
(*em) << YAML::BeginMap;
(*em) << YAML::Key << "CarNumber" << YAML::Value << ptr->driver->carNumber;
(*em) << YAML::Key << "FastestLapNumber" << YAML::Value << ptr->fastestLapNumber;
(*em) << YAML::Key << "FastestLapTime" << YAML::Value << ptr->fastestLapTime;
(*em) << YAML::Key << "Lap" << YAML::Value << ptr->lap;
(*em) << YAML::Key << "LapsComplete" << YAML::Value << ptr->lapsComplete;
(*em) << YAML::Key << "LapsDriven" << YAML::Value << ptr->lapsDriven;
(*em) << YAML::Key << "LapsLed" << YAML::Value << ptr->lapsLed;
(*em) << YAML::Key << "LastLapTime" << YAML::Value << ptr->lastLapTime;
(*em) << YAML::Key << "Position" << YAML::Value << ptr->position;
// TODO (*em) << YAML::Key << "PositionInClass" << YAML::Value << ptr->positionInClass;
(*em) << YAML::Key << "ReasonOut" << YAML::Value << ptr->reasonOut;
(*em) << YAML::Key << "Time" << YAML::Value << ptr->time;
(*em) << YAML::EndMap;
resultsEntryToYaml(ptr, em);
}
(*em) << YAML::EndSeq << YAML::EndMap;
}
} // for each session
(*em) << YAML::EndSeq << YAML::EndMap << YAML::EndMap;
std::cerr << em->c_str() << std::endl;
}

void SessionInfoHandler::handleDriverInfo(const YAML::Node& yamlDriverInfo) {
Expand Down
43 changes: 43 additions & 0 deletions ievent-service/ievent-service/SessionInfoRequestHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "SessionInfoRequestHandler.h"

#include "boost/foreach.hpp"

#include "SessionInfo.h"
#include "Types.hpp"

using namespace IEvent::Service;

SessionInfoRequestHandler::SessionInfoRequestHandler(void)
{
}


SessionInfoRequestHandler::~SessionInfoRequestHandler(void)
{
}


std::string SessionInfoRequestHandler::handleRequest(std::string messageType, const YAML::Node& yaml) {
//const YAML::Node& yaml = *node;
EmitterPtr em ( new YAML::Emitter() );
(*em) << YAML::BeginMap << YAML::Key << "Response" << YAML::Value << "OK" ;

if (messageType == "GetAllSessions") {
(*em) << YAML::Key << "SessionInfo" << YAML::Value << YAML::BeginMap;
(*em) << YAML::Key << "CurrentSession" << YAML::Value << SessionInfo::currentSession;
(*em) << YAML::Key << "Sessions" << YAML::Value << YAML::BeginSeq;
std::pair<int, SessionPtr> p;
BOOST_FOREACH(p, SessionInfo::sessions) {
SessionPtr sptr = p.second;
(*em) << YAML::BeginMap << YAML::Key << "SessionNum" << YAML::Value << sptr->sessionNum;
(*em) << YAML::Key << "Results" << YAML::Value <<YAML::BeginSeq;
std::pair <int, ResultsEntryPtr> resultPair;
BOOST_FOREACH (resultPair, sptr->resultsByPosition) {
resultsEntryToYaml(resultPair.second, em);
}
(*em) << YAML::EndSeq << YAML::EndMap;
}
(*em) << YAML::EndSeq << YAML::EndMap << YAML::EndMap;
}
return em->c_str();
}
18 changes: 18 additions & 0 deletions ievent-service/ievent-service/SessionInfoRequestHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "requesthandler.h"

namespace IEvent
{
namespace Service
{
class SessionInfoRequestHandler :
public RequestHandler
{
public:
SessionInfoRequestHandler(void);
~SessionInfoRequestHandler(void);

std::string handleRequest(std::string messageType, const YAML::Node& node);
};
}
}
6 changes: 6 additions & 0 deletions ievent-service/ievent-service/Types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "boost/shared_ptr.hpp"
#include "yaml-cpp/yaml.h"

typedef boost::shared_ptr<YAML::Emitter> EmitterPtr;
3 changes: 3 additions & 0 deletions ievent-service/ievent-service/ievent-service.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
<ClInclude Include="scoringimpulse.hpp" />
<ClInclude Include="scoringimpulsehandler.hpp" />
<ClInclude Include="sectortracker.hpp" />
<ClInclude Include="SessionInfoRequestHandler.h" />
<ClInclude Include="Types.hpp" />
<ClInclude Include="weekendinfo.hpp" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
Expand All @@ -166,6 +168,7 @@
<ClCompile Include="scoringimpulse.cpp" />
<ClCompile Include="scoringimpulsehandler.cpp" />
<ClCompile Include="sectortracker.cpp" />
<ClCompile Include="SessionInfoRequestHandler.cpp" />
<ClCompile Include="weekendinfo.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand Down
9 changes: 9 additions & 0 deletions ievent-service/ievent-service/ievent-service.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<ClInclude Include="ResultsEntry.h">
<Filter>Datatypes\WeekendInfo\SessionInfo</Filter>
</ClInclude>
<ClInclude Include="SessionInfoRequestHandler.h">
<Filter>Comms\ReqResp\Handlers</Filter>
</ClInclude>
<ClInclude Include="Types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -194,6 +200,9 @@
<ClCompile Include="ResultsEntry.cpp">
<Filter>Datatypes\WeekendInfo\SessionInfo</Filter>
</ClCompile>
<ClCompile Include="SessionInfoRequestHandler.cpp">
<Filter>Comms\ReqResp\Handlers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ievent-service.rc">
Expand Down
4 changes: 4 additions & 0 deletions ievent-service/ievent-service/irreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "SessionInfoHandler.h"
#include "CameraRequestHandler.h"
#include "DriverInfoRequestHandler.h"
#include "SessionInfoRequestHandler.h"


IEvent::Service::iRacingReader::iRacingReader ():
Expand All @@ -29,6 +30,9 @@ IEvent::Service::iRacingReader::iRacingReader ():
RequestHandlerPtr drivers ( new DriverInfoRequestHandler() );
_resp.registerHandler("GetAllDrivers", drivers);

RequestHandlerPtr session ( new SessionInfoRequestHandler() );
_resp.registerHandler("GetAllSessions", session);

_resp.start();
}

Expand Down

0 comments on commit 30110c0

Please sign in to comment.