diff options
author | dknn <yoann.blein@free.fr> | 2012-08-10 18:04:56 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:32:38 (GMT) |
commit | 955c4589ca254814ae7ec6ed911e0a62febc5da1 (patch) | |
tree | 1d3ba8ecc732f8239462f7428e758224f3d38b94 /Swiften/Serializer/PayloadSerializers | |
parent | 577fffec4a1da6909740a392cf76617bdcbe5570 (diff) | |
download | swift-contrib-955c4589ca254814ae7ec6ed911e0a62febc5da1.zip swift-contrib-955c4589ca254814ae7ec6ed911e0a62febc5da1.tar.bz2 |
Capture and send user UI events
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
5 files changed, 113 insertions, 14 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 3a423d1..081284b 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -64,6 +64,7 @@ #include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptSerializer.h> #include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h> #include <Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/InputEventSerializer.h> namespace Swift { @@ -124,6 +125,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new DeliveryReceiptSerializer()); serializers_.push_back(new DeliveryReceiptRequestSerializer()); serializers_.push_back(new JingleRTPDescriptionSerializer()); + serializers_.push_back(new InputEventSerializer()); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); diff --git a/Swiften/Serializer/PayloadSerializers/InputEventSerializer.cpp b/Swiften/Serializer/PayloadSerializers/InputEventSerializer.cpp new file mode 100644 index 0000000..5692308 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/InputEventSerializer.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/InputEventSerializer.h> + +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> + +namespace Swift { + +std::string InputEventSerializer::serializePayload(boost::shared_ptr<InputEventPayload> payload) const { + XMLElement inputevt("inputevt", "http://sip-comunicator.org/protocol/inputevt"); + inputevt.setAttribute("action", actionToString(payload->getAction())); + + XMLElement::ref remoteControlNode = boost::make_shared<XMLElement>("remote-control", "http://sip-communicator.org/protocol/inputevt"); + foreach (InputEventPayload::Event event, payload->getEvents()) { + XMLElement::ref eventNode = boost::make_shared<XMLElement>(eventTypeToString(event.type)); + switch (event.type) { + case InputEventPayload::Event::MouseMove: + eventNode->setAttribute("x", boost::lexical_cast<std::string>(event.realArg1)); + eventNode->setAttribute("y", boost::lexical_cast<std::string>(event.realArg2)); + break; + case InputEventPayload::Event::MouseWheel: + eventNode->setAttribute("notch", boost::lexical_cast<std::string>(event.integerArg)); + break; + case InputEventPayload::Event::MousePress: + case InputEventPayload::Event::MouseRelease: + eventNode->setAttribute("btns", boost::lexical_cast<std::string>(event.integerArg)); + break; + case InputEventPayload::Event::KeyType: + eventNode->setAttribute("keychar", boost::lexical_cast<std::string>(event.integerArg)); + break; + case InputEventPayload::Event::KeyPress: + case InputEventPayload::Event::KeyRelease: + eventNode->setAttribute("keycode", boost::lexical_cast<std::string>(event.integerArg)); + break; + default: + break; + } + remoteControlNode->addNode(eventNode); + } + + inputevt.addNode(remoteControlNode); + return inputevt.serialize(); +} + +std::string InputEventSerializer::actionToString(InputEventPayload::Action action) { + switch (action) { + case InputEventPayload::Notify: + return "notify"; + default: + std::cerr << "Serializing unknown action." << std::endl; + } + return ""; +} + +std::string InputEventSerializer::eventTypeToString(InputEventPayload::Event::EventType eventType) { + switch (eventType) { + case InputEventPayload::Event::MouseMove: + return "mouse-move"; + case InputEventPayload::Event::MousePress: + return "mouse-press"; + case InputEventPayload::Event::MouseRelease: + return "mouse-release"; + case InputEventPayload::Event::MouseWheel: + return "mouse-wheel"; + case InputEventPayload::Event::KeyPress: + return "key-press"; + case InputEventPayload::Event::KeyRelease: + return "key-release"; + case InputEventPayload::Event::KeyType: + return "key-type"; + default: + std::cerr << "Serializing unknown event type." << std::endl; + } + return ""; +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/InputEventSerializer.h b/Swiften/Serializer/PayloadSerializers/InputEventSerializer.h new file mode 100644 index 0000000..d7bdc11 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/InputEventSerializer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/InputEventPayload.h> + +#include <boost/shared_ptr.hpp> + +namespace Swift { + class InputEventSerializer : public GenericPayloadSerializer<InputEventPayload> { + public: + virtual std::string serializePayload(boost::shared_ptr<InputEventPayload>) const; + + private: + static std::string actionToString(InputEventPayload::Action action); + static std::string eventTypeToString(InputEventPayload::Event::EventType eventType); + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp index c0dfba1..34bc75c 100644 --- a/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp @@ -19,9 +19,6 @@ namespace Swift { -JingleRTPDescriptionSerializer::JingleRTPDescriptionSerializer() { -} - std::string JingleRTPDescriptionSerializer::serializePayload(boost::shared_ptr<JingleRTPDescription> payload) const { XMLElement description("description", "urn:xmpp:jingle:apps:rtp:1"); description.setAttribute("media", mediaTypeToString(payload->getMedia())); @@ -48,7 +45,7 @@ std::string JingleRTPDescriptionSerializer::serializePayload(boost::shared_ptr<J return description.serialize(); } -std::string JingleRTPDescriptionSerializer::mediaTypeToString(JingleRTPDescription::MediaType mediaType) const { +std::string JingleRTPDescriptionSerializer::mediaTypeToString(JingleRTPDescription::MediaType mediaType) { switch (mediaType) { case JingleRTPDescription::Audio: return "audio"; diff --git a/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.h b/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.h index 3d23d85..1911b69 100644 --- a/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.h @@ -4,25 +4,17 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ - #pragma once #include <Swiften/Serializer/GenericPayloadSerializer.h> #include <Swiften/Elements/JingleRTPDescription.h> - - namespace Swift { - class PayloadSerializerCollection; - class XMLElement; - class JingleRTPDescriptionSerializer : public GenericPayloadSerializer<JingleRTPDescription> { public: - JingleRTPDescriptionSerializer(); - - virtual std::string serializePayload(boost::shared_ptr<JingleRTPDescription>) const; + virtual std::string serializePayload(boost::shared_ptr<JingleRTPDescription>) const; private: - std::string mediaTypeToString(JingleRTPDescription::MediaType mediaType) const; + static std::string mediaTypeToString(JingleRTPDescription::MediaType mediaType); }; } |