/* * Copyright (c) 2013-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Swift { namespace Detail { template struct PubSubPayloadTraits; #define SWIFTEN_PUBSUB_DECLARE_PAYLOAD_TRAITS(PAYLOAD, CONTAINER, RESPONSE) \ template<> struct PubSubPayloadTraits< PAYLOAD > { \ typedef CONTAINER ContainerType; \ typedef RESPONSE ResponseType; \ }; SWIFTEN_PUBSUB_FOREACH_PUBSUB_PAYLOAD_TYPE( SWIFTEN_PUBSUB_DECLARE_PAYLOAD_TRAITS) } template class SWIFTEN_API PubSubRequest : public Request { typedef typename Detail::PubSubPayloadTraits::ContainerType ContainerType; typedef typename Detail::PubSubPayloadTraits::ResponseType ResponseType; public: PubSubRequest( IQ::Type type, const JID& receiver, std::shared_ptr payload, IQRouter* router) : Request(type, receiver, router) { std::shared_ptr wrapper = std::make_shared(); wrapper->setPayload(payload); setPayload(wrapper); } PubSubRequest( IQ::Type type, const JID& sender, const JID& receiver, std::shared_ptr payload, IQRouter* router) : Request(type, sender, receiver, router) { std::shared_ptr wrapper = std::make_shared(); wrapper->setPayload(payload); setPayload(wrapper); } virtual void handleResponse( std::shared_ptr payload, ErrorPayload::ref error) { std::shared_ptr result; if (std::shared_ptr container = std::dynamic_pointer_cast(payload)) { result = std::dynamic_pointer_cast(container->getPayload()); } onResponse(result, error); } public: boost::signals2::signal, ErrorPayload::ref)> onResponse; }; }