summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-01 08:48:42 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-01 09:24:28 (GMT)
commit2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch)
treed46294f35150c4f0f43deaf2d31fceaf945ae715 /Swiften/Presence
downloadswift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip
swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2
Import.
Diffstat (limited to 'Swiften/Presence')
-rw-r--r--Swiften/Presence/Makefile.inc4
-rw-r--r--Swiften/Presence/PresenceOracle.cpp29
-rw-r--r--Swiften/Presence/PresenceOracle.h25
-rw-r--r--Swiften/Presence/UnitTest/Makefile.inc0
4 files changed, 58 insertions, 0 deletions
diff --git a/Swiften/Presence/Makefile.inc b/Swiften/Presence/Makefile.inc
new file mode 100644
index 0000000..ca8c95e
--- /dev/null
+++ b/Swiften/Presence/Makefile.inc
@@ -0,0 +1,4 @@
+SWIFTEN_SOURCES += \
+ Swiften/Presence/PresenceOracle.cpp
+
+include Swiften/Presence/UnitTest/Makefile.inc
diff --git a/Swiften/Presence/PresenceOracle.cpp b/Swiften/Presence/PresenceOracle.cpp
new file mode 100644
index 0000000..af98510
--- /dev/null
+++ b/Swiften/Presence/PresenceOracle.cpp
@@ -0,0 +1,29 @@
+#include "PresenceOracle.h"
+
+#include <boost/bind.hpp>
+#include "Swiften/Client/StanzaChannel.h"
+namespace Swift {
+
+typedef std::pair<JID, std::map<JID, boost::shared_ptr<Presence> > > JIDMapPair;
+typedef std::pair<JID, boost::shared_ptr<Presence> > JIDPresencePair;
+
+PresenceOracle::PresenceOracle(StanzaChannel* stanzaChannel) {
+ stanzaChannel->onPresenceReceived.connect(boost::bind(&PresenceOracle::handleIncomingPresence, this, _1));
+}
+
+void PresenceOracle::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
+ JID bareJID = JID(presence->getFrom().toBare());
+ std::map<JID, boost::shared_ptr<Presence> > jidMap = entries_[bareJID];
+ boost::shared_ptr<Presence> last;
+ foreach(JIDPresencePair pair, jidMap) {
+ if (pair.first == presence->getFrom()) {
+ last = pair.second;
+ break;
+ }
+ }
+ jidMap[presence->getFrom()] = presence;
+ entries_[bareJID] = jidMap;
+ onPresenceChange(presence, last);
+}
+
+}
diff --git a/Swiften/Presence/PresenceOracle.h b/Swiften/Presence/PresenceOracle.h
new file mode 100644
index 0000000..81f289b
--- /dev/null
+++ b/Swiften/Presence/PresenceOracle.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Elements/Presence.h"
+
+#include <map>
+#include <boost/signal.hpp>
+
+namespace Swift {
+class StanzaChannel;
+
+class PresenceOracle {
+ public:
+ PresenceOracle(StanzaChannel* stanzaChannel);
+ ~PresenceOracle() {};
+
+ boost::signal<void (boost::shared_ptr<Presence>, boost::shared_ptr<Presence>)> onPresenceChange;
+
+ private:
+ void handleIncomingPresence(boost::shared_ptr<Presence> presence);
+ std::map<JID, std::map<JID, boost::shared_ptr<Presence> > > entries_;
+ StanzaChannel* stanzaChannel_;
+};
+}
+
diff --git a/Swiften/Presence/UnitTest/Makefile.inc b/Swiften/Presence/UnitTest/Makefile.inc
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Swiften/Presence/UnitTest/Makefile.inc