summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/StreamStack/WhitespacePingLayer.cpp')
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/Swiften/StreamStack/WhitespacePingLayer.cpp b/Swiften/StreamStack/WhitespacePingLayer.cpp
new file mode 100644
index 0000000..5c1eb00
--- /dev/null
+++ b/Swiften/StreamStack/WhitespacePingLayer.cpp
@@ -0,0 +1,39 @@
+#include "Swiften/StreamStack/WhitespacePingLayer.h"
+
+#include <boost/bind.hpp>
+
+#include "Swiften/Network/TimerFactory.h"
+#include "Swiften/Network/Timer.h"
+
+namespace Swift {
+
+static const int TIMEOUT_MILLISECONDS = 60000;
+
+WhitespacePingLayer::WhitespacePingLayer(TimerFactory* timerFactory) : isActive(false) {
+ timer = timerFactory->createTimer(TIMEOUT_MILLISECONDS);
+ timer->onTick.connect(boost::bind(&WhitespacePingLayer::handleTimerTick, this));
+}
+
+void WhitespacePingLayer::writeData(const ByteArray& data) {
+ onWriteData(data);
+}
+
+void WhitespacePingLayer::handleDataRead(const ByteArray& data) {
+ onDataRead(data);
+}
+
+void WhitespacePingLayer::handleTimerTick() {
+ onWriteData(" ");
+}
+
+void WhitespacePingLayer::setActive() {
+ isActive = true;
+ timer->start();
+}
+
+void WhitespacePingLayer::setInactive() {
+ timer->stop();
+ isActive = false;
+}
+
+}