Rivendellaudio/cae/session.cpp
Fred Gleason c6b18468f1 2023-09-15 Fred Gleason <fredg@paravelsystems.com>
* Added a 'Set Timeout' ['TO'] CAE command.
	* Added a 'Touch' ['TH'] CAE command.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
2023-09-15 11:52:18 -04:00

245 lines
3.9 KiB
C++

// session.cpp
//
// Persistent context for CAE protocol commands
//
// (C) Copyright 2023 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include "session.h"
SessionId::SessionId(const QHostAddress &src_addr,uint16_t src_port,int serial)
{
d_address=src_addr;
d_port=src_port;
d_serial_number=serial;
}
SessionId::SessionId()
{
d_serial_number=0;
}
QHostAddress SessionId::address() const
{
return d_address;
}
uint16_t SessionId::port() const
{
return d_port;
}
int SessionId::serialNumber() const
{
return d_serial_number;
}
void SessionId::setSerialNumber(int serial)
{
d_serial_number=serial;
}
QString SessionId::dump() const
{
return QString::asprintf("%s:%d:%d",d_address.toString().toUtf8().constData(),
0xFFFF&d_port,d_serial_number);
}
bool SessionId::belongsTo(const SessionId &other) const
{
return ((other.d_address==d_address)&&(other.d_port==d_port));
}
bool SessionId::operator!=(const SessionId &other) const
{
return (other.d_address!=d_address)||(other.d_port!=d_port)||
(other.d_serial_number!=d_serial_number);
}
bool SessionId::operator<(const SessionId &other) const
{
if(other.d_address.toIPv4Address()!=d_address.toIPv4Address()) {
return other.d_address.toIPv4Address()<d_address.toIPv4Address();
}
if(other.d_port!=d_port) {
return other.d_port<d_port;
}
return other.d_serial_number<d_serial_number;
}
Session::Session(const QHostAddress &addr,uint16_t port,int serial)
{
d_session_id=SessionId(addr,port,serial);
d_card_number=-1;
d_port_number=-1;
d_stream_number=-1;
d_start_position=-1;
d_end_position=-1;
d_speed=100000;
d_meter_port=0;
d_meters_enabled=false;
}
Session::Session(const SessionId &sid)
{
d_session_id=sid;
d_card_number=-1;
d_port_number=-1;
d_stream_number=-1;
d_start_position=-1;
d_end_position=-1;
d_speed=100000;
d_meter_port=0;
d_meters_enabled=false;
}
/*
Session::Session(const Connection &conn)
{
d_session_id=SessionId(conn);
d_session_id=sid;
d_card_number=-1;
d_port_number=-1;
d_stream_number=-1;
d_start_position=-1;
d_end_position=-1;
d_speed=100000;
d_meter_port=0;
d_meters_enabled=false;
}
*/
SessionId Session::sessionId() const
{
return d_session_id;
}
int Session::cardNumber() const
{
return d_card_number;
}
void Session::setCardNumber(int cardnum)
{
d_card_number=cardnum;
}
int Session::portNumber() const
{
return d_port_number;
}
void Session::setPortNumber(int portnum)
{
d_port_number=portnum;
}
int Session::streamNumber() const
{
return d_stream_number;
}
void Session::setStreamNumber(int streamnum)
{
d_stream_number=streamnum;
}
int Session::startPosition() const
{
return d_start_position;
}
void Session::setStartPosition(int pos)
{
d_start_position=pos;
}
int Session::endPosition() const
{
return d_end_position;
}
void Session::setEndPosition(int pos)
{
d_end_position=pos;
}
int Session::speed() const
{
return d_speed;
}
void Session::setSpeed(int speed)
{
d_speed=speed;
}
uint16_t Session::meterPort() const
{
return d_meter_port;
}
void Session::setMeterPort(uint16_t port)
{
d_meter_port=port;
}
bool Session::metersEnabled()
{
return d_meters_enabled;
}
void Session::setMetersEnabled(bool state)
{
d_meters_enabled=state;
}