summaryrefslogtreecommitdiff
path: root/sapsocket.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sapsocket.cc')
-rw-r--r--sapsocket.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/sapsocket.cc b/sapsocket.cc
new file mode 100644
index 0000000..ce85c0c
--- /dev/null
+++ b/sapsocket.cc
@@ -0,0 +1,62 @@
+#include <QtCore/QDebug>
+
+#include "sappeer.h"
+#include "sapconnection.h"
+#include "sapsocket.h"
+
+SAPSocket::SAPSocket(SAPConnection *conn, int sessionId) :
+ QObject(conn), _sessionId(sessionId), _open(false)
+{
+}
+
+SAPPeer * SAPSocket::peer()
+{
+ return connection()->peer();
+}
+
+SAPConnection * SAPSocket::connection()
+{
+ return static_cast<SAPConnection*>(parent());
+}
+
+bool SAPSocket::isOpen() const
+{
+ return _open;
+}
+
+bool SAPSocket::messageAvailable() const
+{
+ return !_in.empty();
+}
+
+QByteArray SAPSocket::receive()
+{
+ if (!_in.empty()) {
+ return _in.dequeue();
+ } else {
+ return QByteArray();
+ }
+}
+
+bool SAPSocket::send(const QByteArray &data)
+{
+ return peer()->writeToSession(_sessionId, data);
+}
+
+void SAPSocket::setOpen(bool open)
+{
+ _open = open;
+}
+
+void SAPSocket::acceptIncomingData(const QByteArray &data)
+{
+ if (data.isEmpty()) return;
+ _in.enqueue(data);
+
+ emit messageReceived();
+}
+
+int SAPSocket::sessionId() const
+{
+ return _sessionId;
+}