diff options
author | Javier <dev.git@javispedro.com> | 2015-12-13 20:36:52 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2015-12-13 20:36:52 +0100 |
commit | ce8a092a235c8d59f01631c80786f920eb6a777b (patch) | |
tree | cc59e0bdd786a681ff831619ae9a60bf85814064 | |
parent | c48db815c7847b88907aae58f2a1af5c20d9dc8f (diff) | |
download | sapd-ce8a092a235c8d59f01631c80786f920eb6a777b.tar.gz sapd-ce8a092a235c8d59f01631c80786f920eb6a777b.zip |
Add terminate connection frame structs
-rw-r--r-- | saprotocol.cc | 73 | ||||
-rw-r--r-- | saprotocol.h | 21 |
2 files changed, 93 insertions, 1 deletions
diff --git a/saprotocol.cc b/saprotocol.cc index c580f12..9f25613 100644 --- a/saprotocol.cc +++ b/saprotocol.cc @@ -364,6 +364,79 @@ QByteArray SAProtocol::packServiceConnectionResponseFrame(const ServiceConnectio return data; } +SAProtocol::ServiceTerminationRequestFrame SAProtocol::unpackServiceTerminationRequestFrame(const QByteArray &data) +{ + ServiceTerminationRequestFrame frame; + int offset = 0; + + frame.messageType = read<quint8>(data, offset); + frame.acceptorId = read<quint8>(data, offset); + frame.initiatorId = read<quint8>(data, offset); + + int marker = data.indexOf(';', offset); + if (marker == -1) { + qWarning() << "No profile in termination request"; + return frame; + } + + frame.profile = QString::fromUtf8(&data.constData()[offset], marker - offset); + + return frame; +} + +QByteArray SAProtocol::packServiceTerminationRequestFrame(const ServiceTerminationRequestFrame &frame) +{ + QByteArray data; + + append<quint8>(data, frame.messageType); + append<quint16>(data, frame.acceptorId); + append<quint16>(data, frame.initiatorId); + + data.append(frame.profile.toUtf8()); + data.append(';'); + + return data; +} + +SAProtocol::ServiceTerminationResponseFrame SAProtocol::unpackServiceTerminationResponseFrame(const QByteArray &data) +{ + ServiceTerminationResponseFrame frame; + int offset = 0; + + frame.messageType = read<quint8>(data, offset); + frame.acceptorId = read<quint8>(data, offset); + frame.initiatorId = read<quint8>(data, offset); + + int marker = data.indexOf(';', offset); + if (marker == -1) { + qWarning() << "No profile in termination response"; + return frame; + } + + frame.profile = QString::fromUtf8(&data.constData()[offset], marker - offset); + offset = marker + 1; + + frame.statusCode = read<quint8>(data, offset); + + return frame; +} + +QByteArray SAProtocol::packServiceTerminationResponseFrame(const ServiceTerminationResponseFrame &frame) +{ + QByteArray data; + + append<quint8>(data, frame.messageType); + append<quint16>(data, frame.acceptorId); + append<quint16>(data, frame.initiatorId); + + data.append(frame.profile.toUtf8()); + data.append(';'); + + append<quint8>(data, frame.statusCode); + + return data; +} + SAProtocol::CapabilityDiscoveryQuery SAProtocol::unpackCapabilityDiscoveryQuery(const QByteArray &data) { CapabilityDiscoveryQuery msg; diff --git a/saprotocol.h b/saprotocol.h index a9f5ac0..443206b 100644 --- a/saprotocol.h +++ b/saprotocol.h @@ -135,7 +135,26 @@ public: static ServiceConnectionResponseFrame unpackServiceConnectionResponseFrame(const QByteArray &data); static QByteArray packServiceConnectionResponseFrame(const ServiceConnectionResponseFrame &frame); - // TODO service conn termination request. probably trivial. + struct ServiceTerminationRequestFrame { + quint8 messageType; + quint16 acceptorId; + quint16 initiatorId; + QString profile; + }; + + static ServiceTerminationRequestFrame unpackServiceTerminationRequestFrame(const QByteArray &data); + static QByteArray packServiceTerminationRequestFrame(const ServiceTerminationRequestFrame &frame); + + struct ServiceTerminationResponseFrame { + quint8 messageType; + quint16 acceptorId; + quint16 initiatorId; + QString profile; + quint8 statusCode; + }; + + static ServiceTerminationResponseFrame unpackServiceTerminationResponseFrame(const QByteArray &data); + static QByteArray packServiceTerminationResponseFrame(const ServiceTerminationResponseFrame &frame); static const QLatin1String capabilityDiscoveryProfile; static const quint16 capabilityDiscoveryChannel = 255; |