/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include #include namespace Swift { std::string InputEventSerializer::serializePayload(boost::shared_ptr payload) const { XMLElement inputevt("inputevt", "http://sip-comunicator.org/protocol/inputevt"); inputevt.setAttribute("action", actionToString(payload->getAction())); XMLElement::ref remoteControlNode = boost::make_shared("remote-control", "http://sip-communicator.org/protocol/inputevt"); foreach (InputEventPayload::Event event, payload->getEvents()) { XMLElement::ref eventNode = boost::make_shared(eventTypeToString(event.type)); switch (event.type) { case InputEventPayload::Event::MouseMove: eventNode->setAttribute("x", boost::lexical_cast(event.realArg1)); eventNode->setAttribute("y", boost::lexical_cast(event.realArg2)); break; case InputEventPayload::Event::MouseWheel: eventNode->setAttribute("notch", boost::lexical_cast(event.integerArg)); break; case InputEventPayload::Event::MousePress: case InputEventPayload::Event::MouseRelease: eventNode->setAttribute("btns", boost::lexical_cast(event.integerArg)); break; case InputEventPayload::Event::KeyType: eventNode->setAttribute("keychar", boost::lexical_cast(event.integerArg)); break; case InputEventPayload::Event::KeyPress: case InputEventPayload::Event::KeyRelease: eventNode->setAttribute("keycode", boost::lexical_cast(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 ""; } }