blob: 5692308e39c6ee300fefab466ffa5140ee37cb49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 "";
}
}
|