192 lines
No EOL
4.2 KiB
C++
192 lines
No EOL
4.2 KiB
C++
#include "Tracker_win32.h"
|
|
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <sys/timeb.h>
|
|
|
|
#include "Util/OutputFileStream.h"
|
|
#include "Util/InputMemoryStream.h"
|
|
#include "EngineImpl.h"
|
|
|
|
Util::DynamicArray< Soundwich::ISoundwichTracking* > Soundwich::Tracker_win32::m_callbacks;
|
|
|
|
Soundwich::Tracker_win32::Tracker_win32()
|
|
: _stream (nullptr),
|
|
_writer (nullptr),
|
|
_trackingRunning (false),
|
|
_recordActivation (false),
|
|
_activationCounter (0),
|
|
_isActive (false),
|
|
_exportFilePath ("")
|
|
{
|
|
}
|
|
|
|
Soundwich::Tracker_win32::~Tracker_win32()
|
|
{
|
|
StopTracking();
|
|
}
|
|
|
|
//Switch on/off Tracking
|
|
void Soundwich::Tracker_win32::Switch( bool enable, const char* exportFilePath )
|
|
{
|
|
if (_trackingRunning != enable)
|
|
{
|
|
_trackingRunning = enable;
|
|
|
|
if (_trackingRunning)
|
|
{
|
|
_exportFilePath = exportFilePath;
|
|
StartTracking();
|
|
}
|
|
else
|
|
{
|
|
StopTracking();
|
|
}
|
|
}
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::ClearBuffer()
|
|
{
|
|
_trackComponents.Clear();
|
|
_trackConnections.Clear();
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::StartTracking ()
|
|
{
|
|
_activationCounter = 0;
|
|
|
|
ExecuteCallbacks();
|
|
|
|
_stream = new Util::OutputFileStream(_exportFilePath);
|
|
|
|
if (_stream->Exists())
|
|
{
|
|
_writer = new Util::XmlWriter(*_stream);
|
|
_writer->OpenElement("Activations");
|
|
}
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::StopTracking()
|
|
{
|
|
if (_stream->Exists())
|
|
{
|
|
//Close Activations
|
|
_writer->CloseElement();
|
|
delete _writer;
|
|
|
|
//Close Stream (Finalize and Save file)
|
|
_stream->Close();
|
|
delete _stream;
|
|
|
|
ClearBuffer();
|
|
}
|
|
_recordActivation = false;
|
|
}
|
|
|
|
bool Soundwich::Tracker_win32::StartActivation()
|
|
{
|
|
if (_trackingRunning)
|
|
{
|
|
if (!_recordActivation)
|
|
{
|
|
_recordActivation = true;
|
|
ExecuteCallbacks();
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::CloseActivation()
|
|
{
|
|
if (_trackingRunning && _recordActivation)
|
|
{
|
|
SaveActivationInXmlFile();
|
|
ClearBuffer();
|
|
_activationCounter++;
|
|
_recordActivation = false;
|
|
}
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::AddTrackConnection(const char* dataType, const Util::String& compOut, const Util::String& compIn, int portOut, int portIn, const char* value)
|
|
{
|
|
if (_trackingRunning && _recordActivation)
|
|
{
|
|
_trackConnections.PushBack(TrackConnection(dataType, compOut, compIn, portOut, portIn, value));
|
|
}
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::AddTrackComponent(const Util::String& name, const Util::String& type)
|
|
{
|
|
if (_trackingRunning && _recordActivation)
|
|
{
|
|
for (TrackComponentArray::Iterator it = _trackComponents.Begin(); it != _trackComponents.End(); ++it)
|
|
{
|
|
TrackComponent component = *it;
|
|
if (component.GetName() == name)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
_trackComponents.PushBack(TrackComponent(name, type));
|
|
}
|
|
}
|
|
|
|
SoundResult Soundwich::Tracker_win32::SaveActivationInXmlFile()
|
|
{
|
|
if (_stream->Exists())
|
|
{
|
|
_writer->OpenElement("Activation");
|
|
_writer->WriteAttribute("ActivationId", _activationCounter);
|
|
auto result = SerializeActivation();
|
|
_writer->CloseElement();
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
return SaveError;
|
|
}
|
|
}
|
|
|
|
SoundResult Soundwich::Tracker_win32::SerializeActivation()
|
|
{
|
|
int connectionCounter = 0;
|
|
|
|
_writer->OpenElement("Connections");
|
|
for (TrackConnectionArray::Iterator it = _trackConnections.Begin(); it != _trackConnections.End(); ++it)
|
|
{
|
|
TrackConnection connection = *it;
|
|
connection.SerializeConnection(*_writer, connectionCounter);
|
|
|
|
connectionCounter++;
|
|
}
|
|
_writer->CloseElement();
|
|
|
|
_writer->OpenElement("Components");
|
|
for (TrackComponentArray::Iterator it = _trackComponents.Begin(); it != _trackComponents.End(); ++it)
|
|
{
|
|
TrackComponent component = *it;
|
|
component.SerializeComponent(*_writer);
|
|
}
|
|
_writer->CloseElement();
|
|
|
|
return Ok;
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::RegisterCallback(ISoundwichTracking* cb)
|
|
{
|
|
m_callbacks.PushBack(cb);
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::UnregisterCallback(ISoundwichTracking* cb)
|
|
{
|
|
m_callbacks.Remove(cb);
|
|
}
|
|
|
|
void Soundwich::Tracker_win32::ExecuteCallbacks()
|
|
{
|
|
for (uint32 count = 0; count < m_callbacks.Size(); ++count)
|
|
{
|
|
m_callbacks[count]->OnUpdateTracking(_activationCounter);
|
|
}
|
|
} |