103 lines
2.7 KiB
C++
Executable File
103 lines
2.7 KiB
C++
Executable File
/**
|
|
* Communication with A/V system - fm server
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
|
|
#include "fm_control.h"
|
|
#include "exercise_context.h"
|
|
|
|
namespace AudioVideoManagement
|
|
{
|
|
|
|
FMControl::FMControl(const QString &fmServerHost, quint16 fmServerPort, QObject *parent)
|
|
: AVSocket(fmServerHost, fmServerPort, getLogger("FMControl"), getLogger("FMControl.IO"), parent)
|
|
{
|
|
}
|
|
|
|
FMControl::~FMControl()
|
|
{
|
|
}
|
|
|
|
|
|
void FMControl::onReadyRead()
|
|
{
|
|
static const QByteArray baGreeter("RCP_FM/1.0");
|
|
while (m_avsSocket->canReadLine())
|
|
{
|
|
const QByteArray line = m_avsSocket->readLine().trimmed();
|
|
if (line.isEmpty())
|
|
continue;
|
|
DEBUG_LOG(m_loggerIO) << "From A/V: '" << line << "'";
|
|
if (line == baGreeter)
|
|
onRcpLogin();
|
|
else
|
|
{
|
|
const auto baList = parseLine(line);
|
|
bool bOk;
|
|
const Commands cmdId = static_cast<Commands>(baList.at(0).toInt(&bOk));
|
|
if (!bOk)
|
|
{
|
|
ERROR_LOG(m_logger) << "Error parsing command: '" << line << "'";
|
|
continue;
|
|
}
|
|
switch (cmdId)
|
|
{
|
|
case Commands::SyslogEvent:
|
|
break;
|
|
case Commands::AvEvent:
|
|
handleSubcommandAvEvent(line, baList);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void FMControl::handleSubcommandAvEvent(const QByteArray &line, const QVector<QByteArray> &baList)
|
|
{
|
|
if (baList.size() < 2)
|
|
{
|
|
ERROR_LOG(m_logger) << "Got unknown command from fm server: '" << line << "'";
|
|
return;
|
|
}
|
|
bool bOk;
|
|
const Subcommands subCmdId = static_cast<Subcommands>(baList.at(1).toInt(&bOk));
|
|
if (!bOk)
|
|
{
|
|
ERROR_LOG(m_logger) << "Error parsing command: '" << line << "'";
|
|
return;
|
|
}
|
|
switch (subCmdId)
|
|
{
|
|
case Subcommands::AllFilesDeleted:
|
|
{
|
|
// 266 2306 1477395849 4 "ECCORSV01" "AVS_Server" "All files of directory /data/uebung_11/ECRS are deleted"
|
|
if (baList.size() < 7)
|
|
{
|
|
ERROR_LOG(m_logger) << "Can not parse command from fm server: '" << line << "'";
|
|
return;
|
|
}
|
|
const QByteArray &str = baList.at(6);
|
|
const QByteArray startsWith("All files of directory ");
|
|
if (!str.startsWith(startsWith))
|
|
ERROR_LOG(m_logger) << "Can not parse FileDeletion command: '" << line << "'";
|
|
const QList<QByteArray> dirParts = str.split(' ').at(4).split('/');
|
|
if (dirParts.size() < 2)
|
|
{
|
|
ERROR_LOG(m_logger) << "Can not parse command from fm server: '" << line << "'";
|
|
return;
|
|
}
|
|
const ExerciseContext context = ExerciseContext::fromByteArray(dirParts.at(dirParts.size() - 2)); // /foo/bar/ctx_42/ECRS
|
|
emit fileDeletionCompleted(context);
|
|
break;
|
|
}
|
|
case Subcommands::FileDeletionProgress:
|
|
DEBUG_LOG(m_logger) << "File deletion in progress: '" << line << "'";
|
|
break;
|
|
}
|
|
}
|
|
|
|
} // namespace AudioVideoManagement
|