From b91f76491a81f63f6904946448bcae1efcacbb6a Mon Sep 17 00:00:00 2001 From: daleharvey Date: Sun, 6 Aug 2006 21:48:20 +0000 Subject: [PATCH] initial keynodetable work --- src/jabber_whiteboard/defines.cpp | 7 ++ src/jabber_whiteboard/defines.h | 5 +- src/jabber_whiteboard/inkboard-document.cpp | 71 ++++++++++++--------- src/jabber_whiteboard/inkboard-document.h | 22 ++++--- src/jabber_whiteboard/keynode.cpp | 7 +- src/jabber_whiteboard/keynode.h | 22 ++++--- src/jabber_whiteboard/pedrogui.cpp | 2 +- src/jabber_whiteboard/session-manager.cpp | 11 ++-- 8 files changed, 89 insertions(+), 58 deletions(-) diff --git a/src/jabber_whiteboard/defines.cpp b/src/jabber_whiteboard/defines.cpp index ca2bbab0e..725391deb 100644 --- a/src/jabber_whiteboard/defines.cpp +++ b/src/jabber_whiteboard/defines.cpp @@ -39,6 +39,13 @@ namespace Vars { const std::string INKBOARD_XMLNS("http://inkscape.org/inkboard"); + const std::string WHITEBOARD_MESSAGE( + "" + "%6" + ""); + + const std::string PROTOCOL_MESSAGE("<%1><%2 />"); + } namespace State { diff --git a/src/jabber_whiteboard/defines.h b/src/jabber_whiteboard/defines.h index 19b87624b..ade33cc78 100644 --- a/src/jabber_whiteboard/defines.h +++ b/src/jabber_whiteboard/defines.h @@ -68,7 +68,7 @@ namespace Whiteboard { namespace Message { typedef const std::string Wrapper; - typedef const std::string Message; + typedef std::string Message; extern Wrapper PROTOCOL; extern Wrapper NEW; @@ -88,6 +88,9 @@ namespace Message { namespace Vars { extern const std::string INKBOARD_XMLNS; + extern const std::string WHITEBOARD_MESSAGE; + extern const std::string PROTOCOL_MESSAGE; + extern const std::string NEW_MESSAGE; } diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index e9363ecd9..644db8e2a 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -14,17 +14,21 @@ #include "jabber_whiteboard/inkboard-document.h" + +#include "util/ucompose.hpp" + #include "xml/simple-session.h" #include "jabber_whiteboard/inkboard-session.h" #include "jabber_whiteboard/defines.h" #include "jabber_whiteboard/session-manager.h" +#include "jabber_whiteboard/node-tracker.h" namespace Inkscape { namespace Whiteboard { -InkboardDocument::InkboardDocument(int code, State::SessionType type, Glib::ustring const& to) : - XML::SimpleNode(code), _type(type), _recipient(to) +InkboardDocument::InkboardDocument(int code, State::SessionType sessionType, Glib::ustring const& to) : + XML::SimpleNode(code), sessionType(sessionType), recipient(to) { _initBindings(); } @@ -32,7 +36,7 @@ InkboardDocument::InkboardDocument(int code, State::SessionType type, Glib::ustr void InkboardDocument::_initBindings() { - this->_sm = &SessionManager::instance(); + this->sm = &SessionManager::instance(); this->state = State::INITIAL; _bindDocument(*this); _bindLogger(*(new XML::SimpleSession())); @@ -41,34 +45,34 @@ InkboardDocument::_initBindings() void InkboardDocument::setRecipient(Glib::ustring const& val) { - this->_recipient = val; + this->recipient = val; } Glib::ustring InkboardDocument::getRecipient() const { - return this->_recipient; + return this->recipient; } void InkboardDocument::setSessionId(Glib::ustring const& val) { - this->_session = val; + this->sessionId = val; } Glib::ustring InkboardDocument::getSessionId() const { - return this->_session; + return this->sessionId; } void InkboardDocument::startSessionNegotiation() { - if(_type == State::WHITEBOARD_PEER) - sendProtocol(_recipient, Message::PROTOCOL,Message::CONNECT_REQUEST); + if(this->sessionType == State::WHITEBOARD_PEER) + this->send(recipient, Message::PROTOCOL,Message::CONNECT_REQUEST); - else if(_type == State::WHITEBOARD_MUC) + else if(this->sessionType == State::WHITEBOARD_MUC) { // Check that the MUC room is whiteboard enabled, if not no need to send // anything, just set the room to be whiteboard enabled @@ -82,7 +86,7 @@ InkboardDocument::terminateSession() } void -InkboardDocument::processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element* data) +InkboardDocument::recieve(Message::Wrapper &wrapper, Pedro::Element* data) { if(this->handleIncomingState(wrapper,data)) { @@ -98,16 +102,18 @@ InkboardDocument::processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element { // TODO : Would be nice to create the desktop here - sendProtocol(getRecipient(),Message::PROTOCOL, Message::CONNECTED); - sendProtocol(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_BEGIN); + this->send(getRecipient(),Message::PROTOCOL, Message::CONNECTED); + this->send(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_BEGIN); - // Send the Document + // Send Document + this->tracker = new KeyNodeTable(); + this->sendDocument(); - sendProtocol(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_END); + this->send(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_END); }else if(message == Message::DECLINE_INVITATION) { - this->_sm->terminateSession(this->getSessionId()); + this->sm->terminateSession(this->getSessionId()); } } }else{ @@ -117,25 +123,22 @@ InkboardDocument::processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element } bool -InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper &wrapper, - Message::Message &message) +InkboardDocument::send(const Glib::ustring &destJid, Message::Wrapper &wrapper, Message::Message &message) { if(this->handleOutgoingState(wrapper,message)) { - char *fmt= - "" - "" - "<%s>" - "<%s />" - "" - "" - ""; - - if (!_sm->getClient().write(fmt, - _type.c_str(),_sm->getClient().getJid().c_str(),destJid.c_str(),Vars::INKBOARD_XMLNS.c_str(), - this->getSessionId().c_str(),wrapper.c_str(),message.c_str(),wrapper.c_str())) - { return false; } + Glib::ustring mes; + if(wrapper == Message::PROTOCOL) + mes = String::ucompose(Vars::PROTOCOL_MESSAGE,wrapper,message); + else + mes = message; + + char *finalmessage = const_cast(String::ucompose(Vars::WHITEBOARD_MESSAGE, + this->sessionType,this->sm->getClient().getJid(),destJid, + Vars::INKBOARD_XMLNS,this->getSessionId(),mes).c_str()); + if (!this->sm->getClient().write(finalmessage)) + { return false; } else { return true; } @@ -146,6 +149,12 @@ InkboardDocument::sendProtocol(const Glib::ustring &destJid, Message::Wrapper &w } } +void +InkboardDocument::sendDocument() +{ + +} + bool InkboardDocument::handleOutgoingState(Message::Wrapper &wrapper, Glib::ustring const& message) { diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h index 9eff38003..dfe001842 100644 --- a/src/jabber_whiteboard/inkboard-document.h +++ b/src/jabber_whiteboard/inkboard-document.h @@ -29,7 +29,7 @@ namespace Whiteboard { class InkboardDocument : public XML::SimpleNode, public XML::Document { public: - explicit InkboardDocument(int code, State::SessionType type, Glib::ustring const& to); + explicit InkboardDocument(int code, State::SessionType sessionType, Glib::ustring const& to); XML::NodeType type() const { @@ -44,9 +44,11 @@ public: void startSessionNegotiation(); void terminateSession(); - void processInkboardEvent(Message::Wrapper &wrapper, Pedro::Element* data); - bool sendProtocol(const Glib::ustring &destJid, Message::Wrapper &mwrapper, Message::Message &message); + void recieve(Message::Wrapper &wrapper, Pedro::Element* data); + bool send(const Glib::ustring &destJid, Message::Wrapper &mwrapper, Message::Message &message); + + void sendDocument(); bool handleOutgoingState(Message::Wrapper &wrapper,Glib::ustring const& message); bool handleIncomingState(Message::Wrapper &wrapper,Pedro::Element* data); @@ -60,7 +62,7 @@ protected: * \param orig Instance to copy. */ InkboardDocument(InkboardDocument const& orig) : - XML::Node(), XML::SimpleNode(orig), XML::Document(), _recipient(orig._recipient) + XML::Node(), XML::SimpleNode(orig), XML::Document(), recipient(orig.recipient) { _initBindings(); } @@ -74,15 +76,15 @@ private: void _initBindings(); - SessionManager *_sm; - SPDocument *_doc; - State::SessionType _type; + SessionManager *sm; + + State::SessionType sessionType; State::SessionState state; - Glib::ustring _session; - Glib::ustring _recipient; + Glib::ustring sessionId; + Glib::ustring recipient; - KeyNodeTable _tracker; + KeyNodeTable *tracker; }; } diff --git a/src/jabber_whiteboard/keynode.cpp b/src/jabber_whiteboard/keynode.cpp index d9af43f63..b338a91fe 100644 --- a/src/jabber_whiteboard/keynode.cpp +++ b/src/jabber_whiteboard/keynode.cpp @@ -8,7 +8,7 @@ * Copyright (c) 2005 Authors */ #include "keynode.h" - +#include "util/ucompose.hpp" namespace Inkscape { @@ -118,6 +118,11 @@ KeyNodePair KeyNodeTable::item(unsigned int index) const return items[index]; } +Glib::ustring +KeyNodeTable::generateKey(Glib::ustring jid) +{ + return String::ucompose("%1/%2",this->counter++,jid); +} } // namespace Whiteboard diff --git a/src/jabber_whiteboard/keynode.h b/src/jabber_whiteboard/keynode.h index a224b7c53..eb68f40b6 100644 --- a/src/jabber_whiteboard/keynode.h +++ b/src/jabber_whiteboard/keynode.h @@ -48,39 +48,43 @@ public: KeyNodeTable() {} - + KeyNodeTable(const KeyNodeTable &other) { items = other.items; } - + virtual ~KeyNodeTable() {} - + virtual void clear(); - + virtual void append(const KeyNodeTable &other); virtual void put(const KeyNodePair &pair); - + virtual void put(const Glib::ustring &key, const XML::Node *node); - + virtual XML::Node * get(const Glib::ustring &key) const; - + virtual void remove(const Glib::ustring &key); virtual Glib::ustring get(XML::Node *node) const; - + virtual void remove(XML::Node *node); virtual unsigned int size() const; - + virtual KeyNodePair item(unsigned int index) const; + virtual Glib::ustring generateKey(Glib::ustring); + private: std::vector items; + unsigned int counter; + }; diff --git a/src/jabber_whiteboard/pedrogui.cpp b/src/jabber_whiteboard/pedrogui.cpp index 3e8ee72a1..cd5bf6814 100644 --- a/src/jabber_whiteboard/pedrogui.cpp +++ b/src/jabber_whiteboard/pedrogui.cpp @@ -2114,7 +2114,7 @@ bool PedroGui::chatDeleteAll() bool PedroGui::chatMessage(const DOMString &from, const DOMString &data) { - if(data.size() < 1) + if(data.size() > 0) { std::vector::iterator iter; for (iter=chats.begin() ; iter != chats.end() ; iter++) diff --git a/src/jabber_whiteboard/session-manager.cpp b/src/jabber_whiteboard/session-manager.cpp index 3dcb8e217..35d87b4b5 100644 --- a/src/jabber_whiteboard/session-manager.cpp +++ b/src/jabber_whiteboard/session-manager.cpp @@ -234,7 +234,7 @@ SessionManager::processWhiteboardEvent(Pedro::XmppEvent const& event) } Pedro::DOMString session = root->getTagAttribute("wb", "session"); - Pedro::DOMString type = root->getTagAttribute("session", "type"); + Pedro::DOMString type = root->getTagAttribute("message", "type"); Pedro::DOMString domwrapper = root->getFirstChild()->getFirstChild()->getFirstChild()->getName(); if (session.empty()) { @@ -250,9 +250,10 @@ SessionManager::processWhiteboardEvent(Pedro::XmppEvent const& event) { Message::Wrapper wrapper = static_cast< Message::Wrapper >(domwrapper); InkboardDocument* doc = getInkboardSession(session); - doc->processInkboardEvent(wrapper, root->getFirstChild()); - } + if(doc != NULL) + doc->recieve(wrapper, root->getFirstChild()); + } } char* @@ -328,12 +329,12 @@ SessionManager::checkInvitationQueue() switch (reply) { case Dialog::ACCEPT_INVITATION:{ - inkdoc->sendProtocol(from, Message::PROTOCOL,Message::ACCEPT_INVITATION); + inkdoc->send(from, Message::PROTOCOL,Message::ACCEPT_INVITATION); makeInkboardDesktop(doc); break; } case Dialog::DECLINE_INVITATION: default: { - inkdoc->sendProtocol(from, Message::PROTOCOL,Message::DECLINE_INVITATION); + inkdoc->send(from, Message::PROTOCOL,Message::DECLINE_INVITATION); terminateSession(sessionId); break; } } -- 2.30.2