diff options
Diffstat (limited to 'Swift/Controllers/XMPPEvents')
-rw-r--r-- | Swift/Controllers/XMPPEvents/ErrorEvent.h | 35 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/EventController.cpp | 80 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/EventController.h | 41 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h | 24 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/MUCInviteEvent.h | 49 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/MessageEvent.h | 49 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/StanzaEvent.h | 36 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h | 65 |
8 files changed, 188 insertions, 191 deletions
diff --git a/Swift/Controllers/XMPPEvents/ErrorEvent.h b/Swift/Controllers/XMPPEvents/ErrorEvent.h index ee0284e..c0b5e52 100644 --- a/Swift/Controllers/XMPPEvents/ErrorEvent.h +++ b/Swift/Controllers/XMPPEvents/ErrorEvent.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,25 +7,26 @@ #pragma once #include <cassert> +#include <memory> +#include <string> -#include "Swiften/Base/boost_bsignals.h" -#include <boost/shared_ptr.hpp> +#include <boost/signals2.hpp> -#include "Swift/Controllers/XMPPEvents/StanzaEvent.h" -#include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> + +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - class ErrorEvent : public StanzaEvent { - public: - ErrorEvent(const JID& jid, const std::string& text) : jid_(jid), text_(text){} - virtual ~ErrorEvent(){} - const JID& getJID() const {return jid_;} - const std::string& getText() const {return text_;} - - private: - JID jid_; - std::string text_; - }; + class ErrorEvent : public StanzaEvent { + public: + ErrorEvent(const JID& jid, const std::string& text) : jid_(jid), text_(text){} + virtual ~ErrorEvent(){} + const JID& getJID() const {return jid_;} + const std::string& getText() const {return text_;} + + private: + JID jid_; + std::string text_; + }; } diff --git a/Swift/Controllers/XMPPEvents/EventController.cpp b/Swift/Controllers/XMPPEvents/EventController.cpp index bbe7356..f8fb192 100644 --- a/Swift/Controllers/XMPPEvents/EventController.cpp +++ b/Swift/Controllers/XMPPEvents/EventController.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,8 +11,6 @@ #include <boost/bind.hpp> #include <boost/numeric/conversion/cast.hpp> -#include <Swiften/Base/foreach.h> - #include <Swift/Controllers/XMPPEvents/ErrorEvent.h> #include <Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h> #include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h> @@ -25,56 +23,56 @@ EventController::EventController() { } EventController::~EventController() { - foreach(boost::shared_ptr<StanzaEvent> event, events_) { - event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event)); - } + for (auto&& event : events_) { + event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event)); + } } -void EventController::handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceEvent) { - boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(sourceEvent); - boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent); - boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(sourceEvent); - boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent); - boost::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(sourceEvent); +void EventController::handleIncomingEvent(std::shared_ptr<StanzaEvent> sourceEvent) { + std::shared_ptr<MessageEvent> messageEvent = std::dynamic_pointer_cast<MessageEvent>(sourceEvent); + std::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent); + std::shared_ptr<ErrorEvent> errorEvent = std::dynamic_pointer_cast<ErrorEvent>(sourceEvent); + std::shared_ptr<MUCInviteEvent> mucInviteEvent = std::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent); + std::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = std::dynamic_pointer_cast<IncomingFileTransferEvent>(sourceEvent); - /* If it's a duplicate subscription request, remove the previous request first */ - if (subscriptionEvent) { - EventList existingEvents(events_); - foreach(boost::shared_ptr<StanzaEvent> existingEvent, existingEvents) { - boost::shared_ptr<SubscriptionRequestEvent> existingSubscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(existingEvent); - if (existingSubscriptionEvent) { - if (existingSubscriptionEvent->getJID() == subscriptionEvent->getJID()) { - existingEvent->conclude(); - } - } - } - } + /* If it's a duplicate subscription request, remove the previous request first */ + if (subscriptionEvent) { + EventList existingEvents(events_); + for (auto&& existingEvent : existingEvents) { + std::shared_ptr<SubscriptionRequestEvent> existingSubscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(existingEvent); + if (existingSubscriptionEvent) { + if (existingSubscriptionEvent->getJID() == subscriptionEvent->getJID()) { + existingEvent->conclude(); + } + } + } + } - if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent || incomingFileTransferEvent) { - events_.push_back(sourceEvent); - sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent)); - onEventQueueLengthChange(boost::numeric_cast<int>(events_.size())); - onEventQueueEventAdded(sourceEvent); - if (sourceEvent->getConcluded()) { - handleEventConcluded(sourceEvent); - } - } + if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent || incomingFileTransferEvent) { + events_.push_back(sourceEvent); + sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent)); + onEventQueueLengthChange(boost::numeric_cast<int>(events_.size())); + onEventQueueEventAdded(sourceEvent); + if (sourceEvent->getConcluded()) { + handleEventConcluded(sourceEvent); + } + } } -void EventController::handleEventConcluded(boost::shared_ptr<StanzaEvent> event) { - event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event)); - events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end()); - onEventQueueLengthChange(boost::numeric_cast<int>(events_.size())); +void EventController::handleEventConcluded(std::shared_ptr<StanzaEvent> event) { + event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event)); + events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end()); + onEventQueueLengthChange(boost::numeric_cast<int>(events_.size())); } void EventController::disconnectAll() { - onEventQueueLengthChange.disconnect_all_slots(); - onEventQueueEventAdded.disconnect_all_slots(); + onEventQueueLengthChange.disconnect_all_slots(); + onEventQueueEventAdded.disconnect_all_slots(); } void EventController::clear() { - events_.clear(); - onEventQueueLengthChange(0); + events_.clear(); + onEventQueueLengthChange(0); } } diff --git a/Swift/Controllers/XMPPEvents/EventController.h b/Swift/Controllers/XMPPEvents/EventController.h index 35938ac..8a095d9 100644 --- a/Swift/Controllers/XMPPEvents/EventController.h +++ b/Swift/Controllers/XMPPEvents/EventController.h @@ -1,36 +1,35 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <memory> #include <vector> -#include <boost/shared_ptr.hpp> - -#include <Swiften/Base/boost_bsignals.h> +#include <boost/signals2.hpp> #include <Swift/Controllers/XMPPEvents/MessageEvent.h> #include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - typedef std::vector<boost::shared_ptr<StanzaEvent> > EventList; - class EventController { - public: - EventController(); - ~EventController(); - - void handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceEvent); - boost::signal<void (int)> onEventQueueLengthChange; - boost::signal<void (boost::shared_ptr<StanzaEvent>)> onEventQueueEventAdded; - const EventList& getEvents() const {return events_;} - void disconnectAll(); - void clear(); - - private: - void handleEventConcluded(boost::shared_ptr<StanzaEvent> event); - EventList events_; - }; + typedef std::vector<std::shared_ptr<StanzaEvent> > EventList; + class EventController { + public: + EventController(); + ~EventController(); + + void handleIncomingEvent(std::shared_ptr<StanzaEvent> sourceEvent); + boost::signals2::signal<void (int)> onEventQueueLengthChange; + boost::signals2::signal<void (std::shared_ptr<StanzaEvent>)> onEventQueueEventAdded; + const EventList& getEvents() const {return events_;} + void disconnectAll(); + void clear(); + + private: + void handleEventConcluded(std::shared_ptr<StanzaEvent> event); + EventList events_; + }; } diff --git a/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h b/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h index 24af640..3d4303d 100644 --- a/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h +++ b/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h @@ -1,30 +1,30 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <Swiften/JID/JID.h> #include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - class IncomingFileTransferEvent : public StanzaEvent { - public: - typedef boost::shared_ptr<IncomingFileTransferEvent> ref; + class IncomingFileTransferEvent : public StanzaEvent { + public: + typedef std::shared_ptr<IncomingFileTransferEvent> ref; - IncomingFileTransferEvent(const JID& sender) : sender_(sender) {} + IncomingFileTransferEvent(const JID& sender) : sender_(sender) {} - const JID& getSender() const { - return sender_; - } + const JID& getSender() const { + return sender_; + } - private: - JID sender_; - }; + private: + JID sender_; + }; } diff --git a/Swift/Controllers/XMPPEvents/MUCInviteEvent.h b/Swift/Controllers/XMPPEvents/MUCInviteEvent.h index 1ae9891..4cdbbff 100644 --- a/Swift/Controllers/XMPPEvents/MUCInviteEvent.h +++ b/Swift/Controllers/XMPPEvents/MUCInviteEvent.h @@ -5,43 +5,42 @@ */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <memory> #include <string> -#include <boost/shared_ptr.hpp> - #include <Swiften/JID/JID.h> #include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - class MUCInviteEvent : public StanzaEvent { - public: - typedef boost::shared_ptr<MUCInviteEvent> ref; - - public: - MUCInviteEvent(const JID& inviter, const JID& roomJID, const std::string& reason, const std::string& password, bool direct, bool impromptu) : inviter_(inviter), roomJID_(roomJID), reason_(reason), password_(password), direct_(direct), impromptu_(impromptu) {} - - const JID& getInviter() const { return inviter_; } - const JID& getRoomJID() const { return roomJID_; } - const std::string& getReason() const { return reason_; } - const std::string& getPassword() const { return password_; } - bool getDirect() const { return direct_; } - bool getImpromptu() const { return impromptu_; } - - private: - JID inviter_; - JID roomJID_; - std::string reason_; - std::string password_; - bool direct_; - bool impromptu_; - }; + class MUCInviteEvent : public StanzaEvent { + public: + typedef std::shared_ptr<MUCInviteEvent> ref; + + public: + MUCInviteEvent(const JID& inviter, const JID& roomJID, const std::string& reason, const std::string& password, bool direct, bool impromptu) : inviter_(inviter), roomJID_(roomJID), reason_(reason), password_(password), direct_(direct), impromptu_(impromptu) {} + + const JID& getInviter() const { return inviter_; } + const JID& getRoomJID() const { return roomJID_; } + const std::string& getReason() const { return reason_; } + const std::string& getPassword() const { return password_; } + bool getDirect() const { return direct_; } + bool getImpromptu() const { return impromptu_; } + + private: + JID inviter_; + JID roomJID_; + std::string reason_; + std::string password_; + bool direct_; + bool impromptu_; + }; } diff --git a/Swift/Controllers/XMPPEvents/MessageEvent.h b/Swift/Controllers/XMPPEvents/MessageEvent.h index b5b1215..7af2be6 100644 --- a/Swift/Controllers/XMPPEvents/MessageEvent.h +++ b/Swift/Controllers/XMPPEvents/MessageEvent.h @@ -4,45 +4,44 @@ * See the COPYING file for more information. */ -#pragma once +#pragma once #include <cassert> - -#include <boost/shared_ptr.hpp> +#include <memory> #include <Swiften/Elements/Message.h> #include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - class MessageEvent : public StanzaEvent { - public: - typedef boost::shared_ptr<MessageEvent> ref; + class MessageEvent : public StanzaEvent { + public: + typedef std::shared_ptr<MessageEvent> ref; - MessageEvent(boost::shared_ptr<Message> stanza) : stanza_(stanza), targetsMe_(true) {} + MessageEvent(std::shared_ptr<Message> stanza) : stanza_(stanza), targetsMe_(true) {} - boost::shared_ptr<Message> getStanza() {return stanza_;} + std::shared_ptr<Message> getStanza() {return stanza_;} - bool isReadable() { - return getStanza()->isError() || !getStanza()->getBody().get_value_or("").empty(); - } + bool isReadable() { + return getStanza()->isError() || !getStanza()->getBody().get_value_or("").empty(); + } - void read() { - assert (isReadable()); - conclude(); - } + void read() { + assert (isReadable()); + conclude(); + } - void setTargetsMe(bool targetsMe) { - targetsMe_ = targetsMe; - } + void setTargetsMe(bool targetsMe) { + targetsMe_ = targetsMe; + } - bool targetsMe() const { - return targetsMe_; - } + bool targetsMe() const { + return targetsMe_; + } - private: - boost::shared_ptr<Message> stanza_; - bool targetsMe_; - }; + private: + std::shared_ptr<Message> stanza_; + bool targetsMe_; + }; } diff --git a/Swift/Controllers/XMPPEvents/StanzaEvent.h b/Swift/Controllers/XMPPEvents/StanzaEvent.h index a16aac9..56c4ea3 100644 --- a/Swift/Controllers/XMPPEvents/StanzaEvent.h +++ b/Swift/Controllers/XMPPEvents/StanzaEvent.h @@ -1,29 +1,29 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/date_time/posix_time/posix_time.hpp> +#include <memory> -#include "Swiften/Base/boost_bsignals.h" +#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/signals2.hpp> namespace Swift { - class StanzaEvent { - public: - StanzaEvent() : time_(boost::posix_time::microsec_clock::universal_time()) {concluded_ = false;} - virtual ~StanzaEvent() {} - void conclude() {concluded_ = true; onConclusion();} - /** Do not call this directly from outside the class. - * If you connect to this signal, you *must* disconnect from it manually. */ - boost::signal<void()> onConclusion; - bool getConcluded() {return concluded_;} - boost::posix_time::ptime getTime() {return time_;} - private: - bool concluded_; - boost::posix_time::ptime time_; - }; + class StanzaEvent { + public: + StanzaEvent() : time_(boost::posix_time::microsec_clock::universal_time()) {concluded_ = false;} + virtual ~StanzaEvent() {} + void conclude() {concluded_ = true; onConclusion();} + /** Do not call this directly from outside the class. + * If you connect to this signal, you *must* disconnect from it manually. */ + boost::signals2::signal<void()> onConclusion; + bool getConcluded() {return concluded_;} + boost::posix_time::ptime getTime() {return time_;} + private: + bool concluded_; + boost::posix_time::ptime time_; + }; } diff --git a/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h b/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h index 1eb9cb1..8e3fd32 100644 --- a/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h +++ b/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,40 +7,41 @@ #pragma once #include <cassert> +#include <memory> +#include <string> -#include "Swiften/Base/boost_bsignals.h" -#include <boost/shared_ptr.hpp> +#include <boost/signals2.hpp> -#include "Swift/Controllers/XMPPEvents/StanzaEvent.h" -#include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> + +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - class SubscriptionRequestEvent : public StanzaEvent { - public: - SubscriptionRequestEvent(const JID& jid, const std::string& reason) : jid_(jid), reason_(reason){} - virtual ~SubscriptionRequestEvent(){} - const JID& getJID() const {return jid_;} - const std::string& getReason() const {return reason_;} - boost::signal<void()> onAccept; - boost::signal<void()> onDecline; - void accept() { - onAccept(); - conclude(); - } - - void decline() { - onDecline(); - conclude(); - } - - void defer() { - conclude(); - } - - private: - JID jid_; - std::string reason_; - }; + class SubscriptionRequestEvent : public StanzaEvent { + public: + SubscriptionRequestEvent(const JID& jid, const std::string& reason) : jid_(jid), reason_(reason){} + virtual ~SubscriptionRequestEvent(){} + const JID& getJID() const {return jid_;} + const std::string& getReason() const {return reason_;} + boost::signals2::signal<void()> onAccept; + boost::signals2::signal<void()> onDecline; + void accept() { + onAccept(); + conclude(); + } + + void decline() { + onDecline(); + conclude(); + } + + void defer() { + conclude(); + } + + private: + JID jid_; + std::string reason_; + }; } |