Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lobby/glooxwrapper/glooxwrapper.cpp
Show First 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
public: | public: | ||||
glooxwrapper::Jingle::SessionHandler* m_Wrapped; | glooxwrapper::Jingle::SessionHandler* m_Wrapped; | ||||
bool m_Owned; | bool m_Owned; | ||||
SessionHandlerWrapper(glooxwrapper::Jingle::SessionHandler* wrapped, bool owned) | SessionHandlerWrapper(glooxwrapper::Jingle::SessionHandler* wrapped, bool owned) | ||||
: m_Wrapped(wrapped), m_Owned(owned) {} | : m_Wrapped(wrapped), m_Owned(owned) {} | ||||
~SessionHandlerWrapper() | |||||
{ | |||||
if (m_Owned) | |||||
delete m_Wrapped; | |||||
} | |||||
virtual void handleSessionAction(gloox::Jingle::Action action, gloox::Jingle::Session* session, const gloox::Jingle::Session::Jingle* jingle) | virtual void handleSessionAction(gloox::Jingle::Action action, gloox::Jingle::Session* session, const gloox::Jingle::Session::Jingle* jingle) | ||||
{ | { | ||||
glooxwrapper::Jingle::Session wrapped_session(session, false); | glooxwrapper::Jingle::Session sessionWrapper(session, false); | ||||
glooxwrapper::Jingle::Session::Jingle wrapped_jingle(jingle, false); | glooxwrapper::Jingle::Session::Jingle jingleWrapper(jingle, false); | ||||
m_Wrapped->handleSessionAction(action, &wrapped_session, &wrapped_jingle); | m_Wrapped->handleSessionAction(action, sessionWrapper, jingleWrapper); | ||||
} | } | ||||
virtual void handleSessionActionError(gloox::Jingle::Action UNUSED(action), gloox::Jingle::Session* UNUSED(session), const gloox::Error* UNUSED(error)) | virtual void handleSessionActionError(gloox::Jingle::Action UNUSED(action), gloox::Jingle::Session* UNUSED(session), const gloox::Error* UNUSED(error)) | ||||
{ | { | ||||
} | } | ||||
virtual void handleIncomingSession(gloox::Jingle::Session* UNUSED(session)) | virtual void handleIncomingSession(gloox::Jingle::Session* UNUSED(session)) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||
void glooxwrapper::Client::disconnect() | void glooxwrapper::Client::disconnect() | ||||
{ | { | ||||
m_Wrapped->disconnect(); | m_Wrapped->disconnect(); | ||||
} | } | ||||
void glooxwrapper::Client::registerStanzaExtension(glooxwrapper::StanzaExtension* ext) | void glooxwrapper::Client::registerStanzaExtension(glooxwrapper::StanzaExtension* ext) | ||||
{ | { | ||||
gloox::StanzaExtension* stanza = new StanzaExtensionWrapper(ext, true); | // ~StanzaExtensionFactory() deletes this new StanzaExtensionWrapper | ||||
m_Wrapped->registerStanzaExtension(stanza); | m_Wrapped->registerStanzaExtension(new StanzaExtensionWrapper(ext, true)); | ||||
} | } | ||||
void glooxwrapper::Client::registerConnectionListener(glooxwrapper::ConnectionListener* hnd) | void glooxwrapper::Client::registerConnectionListener(glooxwrapper::ConnectionListener* hnd) | ||||
{ | { | ||||
gloox::ConnectionListener* listener = new ConnectionListenerWrapper(hnd); | gloox::ConnectionListener* listener = new ConnectionListenerWrapper(hnd); | ||||
m_Wrapped->registerConnectionListener(listener); | m_Wrapped->registerConnectionListener(listener); | ||||
m_Impl->m_ConnectionListeners.push_back(shared_ptr<gloox::ConnectionListener>(listener)); | m_Impl->m_ConnectionListeners.push_back(shared_ptr<gloox::ConnectionListener>(listener)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 396 Lines • ▼ Show 20 Lines | if (m_Owned) | ||||
delete m_Wrapped; | delete m_Wrapped; | ||||
} | } | ||||
const glooxwrapper::Jingle::Plugin glooxwrapper::Jingle::Plugin::findPlugin(int type) const | const glooxwrapper::Jingle::Plugin glooxwrapper::Jingle::Plugin::findPlugin(int type) const | ||||
{ | { | ||||
return glooxwrapper::Jingle::Plugin(m_Wrapped->findPlugin(type), false); | return glooxwrapper::Jingle::Plugin(m_Wrapped->findPlugin(type), false); | ||||
} | } | ||||
glooxwrapper::Jingle::Content::Content(const string& name, const PluginList& plugins) | |||||
: glooxwrapper::Jingle::Plugin(NULL, false) | |||||
{ | |||||
gloox::Jingle::PluginList glooxPluginList; | |||||
for (const glooxwrapper::Jingle::Plugin* const& plugin: plugins) | |||||
glooxPluginList.push_back(plugin->getWrapped()); | |||||
m_Wrapped = new gloox::Jingle::Content(name.to_string(), glooxPluginList); | |||||
m_Owned = true; | |||||
} | |||||
glooxwrapper::Jingle::Content::Content() | |||||
: glooxwrapper::Jingle::Plugin(NULL, false) | |||||
{ | |||||
m_Wrapped = new gloox::Jingle::Content(); | |||||
m_Owned = true; | |||||
} | |||||
glooxwrapper::Jingle::ICEUDP::Candidate glooxwrapper::Jingle::Session::Jingle::getCandidate() const | glooxwrapper::Jingle::ICEUDP::Candidate glooxwrapper::Jingle::Session::Jingle::getCandidate() const | ||||
{ | { | ||||
const gloox::Jingle::Content* content = static_cast<const gloox::Jingle::Content*>(m_Wrapped->plugins().front()); | const gloox::Jingle::Content* content = static_cast<const gloox::Jingle::Content*>(m_Wrapped->plugins().front()); | ||||
if (!content) | if (!content) | ||||
return glooxwrapper::Jingle::ICEUDP::Candidate(); | return glooxwrapper::Jingle::ICEUDP::Candidate(); | ||||
const gloox::Jingle::ICEUDP* iceUDP = static_cast<const gloox::Jingle::ICEUDP*>(content->findPlugin(gloox::Jingle::PluginICEUDP)); | const gloox::Jingle::ICEUDP* iceUDP = static_cast<const gloox::Jingle::ICEUDP*>(content->findPlugin(gloox::Jingle::PluginICEUDP)); | ||||
if (!iceUDP) | if (!iceUDP) | ||||
return glooxwrapper::Jingle::ICEUDP::Candidate(); | return glooxwrapper::Jingle::ICEUDP::Candidate(); | ||||
gloox::Jingle::ICEUDP::Candidate glooxCandidate = iceUDP->candidates().front(); | gloox::Jingle::ICEUDP::Candidate glooxCandidate = iceUDP->candidates().front(); | ||||
return glooxwrapper::Jingle::ICEUDP::Candidate{glooxCandidate.ip, glooxCandidate.port}; | return glooxwrapper::Jingle::ICEUDP::Candidate{glooxCandidate.ip, glooxCandidate.port}; | ||||
} | } | ||||
glooxwrapper::Jingle::Session::Session(gloox::Jingle::Session* wrapped, bool owned) | |||||
: m_Wrapped(wrapped), m_Owned(owned) | |||||
{ | |||||
} | |||||
glooxwrapper::Jingle::Session::~Session() | |||||
{ | |||||
if (m_Owned) | |||||
delete m_Wrapped; | |||||
} | |||||
bool glooxwrapper::Jingle::Session::sessionInitiate(char* ipStr, u16 port) | bool glooxwrapper::Jingle::Session::sessionInitiate(char* ipStr, u16 port) | ||||
{ | { | ||||
gloox::Jingle::ICEUDP::CandidateList candidateList; | gloox::Jingle::ICEUDP::CandidateList candidateList; | ||||
candidateList.push_back(gloox::Jingle::ICEUDP::Candidate | candidateList.push_back(gloox::Jingle::ICEUDP::Candidate | ||||
{ | { | ||||
"1", // component_id, | "1", // component_id, | ||||
"1", // foundation | "1", // foundation | ||||
"0", // andidate_generation | "0", // andidate_generation | ||||
"1", // candidate_id | "1", // candidate_id | ||||
ipStr, | ipStr, | ||||
"0", // network | "0", // network | ||||
port, | port, | ||||
0, // priotiry | 0, // priotiry | ||||
"udp", | "udp", | ||||
"", // base_ip | "", // base_ip | ||||
0, // base_port | 0, // base_port | ||||
gloox::Jingle::ICEUDP::ServerReflexive | gloox::Jingle::ICEUDP::ServerReflexive | ||||
}); | }); | ||||
// sessionInitiate deletes the new Content, and | |||||
// the Plugin destructor inherited by Content frees the ICEUDP plugin. | |||||
gloox::Jingle::PluginList pluginList; | gloox::Jingle::PluginList pluginList; | ||||
pluginList.push_back(new gloox::Jingle::ICEUDP(/*local_pwd*/"", /*local_ufrag*/"", candidateList)); | pluginList.push_back(new gloox::Jingle::ICEUDP(/*local_pwd*/"", /*local_ufrag*/"", candidateList)); | ||||
// This is safe as gloox will free Content which will free the ICEUDP object | |||||
return m_Wrapped->sessionInitiate(new gloox::Jingle::Content(std::string("game-data"), pluginList)); | |||||
} | |||||
glooxwrapper::Jingle::ICEUDP::ICEUDP(glooxwrapper::Jingle::ICEUDP::CandidateList& candidates) | |||||
: glooxwrapper::Jingle::Plugin(NULL, false) | |||||
{ | |||||
gloox::Jingle::ICEUDP::CandidateList glooxCandidates; | |||||
for (const glooxwrapper::Jingle::ICEUDP::Candidate& candidate : candidates) | |||||
glooxCandidates.push_back(gloox::Jingle::ICEUDP::Candidate | |||||
{ | |||||
"1", // component_id, | |||||
"1", // foundation | |||||
"0", // candidate_generation | |||||
"1", // candidate_id | |||||
candidate.ip.to_string(), | |||||
"0", // network | |||||
candidate.port, | |||||
0, // priority | |||||
"udp", | |||||
"", // base_ip | |||||
0, // base_port | |||||
gloox::Jingle::ICEUDP::ServerReflexive | |||||
}); | |||||
m_Wrapped = new gloox::Jingle::ICEUDP(/*local_pwd*/"", /*local_ufrag*/"", glooxCandidates); | |||||
m_Owned = true; | |||||
} | |||||
glooxwrapper::Jingle::ICEUDP::ICEUDP() | |||||
: glooxwrapper::Jingle::Plugin(NULL, false) | |||||
{ | |||||
m_Wrapped = new gloox::Jingle::ICEUDP(); | |||||
m_Owned = true; | |||||
} | |||||
const glooxwrapper::Jingle::ICEUDP::CandidateList glooxwrapper::Jingle::ICEUDP::candidates() const | return m_Wrapped->sessionInitiate(new gloox::Jingle::Content(std::string("game-data"), pluginList)); | ||||
{ | |||||
glooxwrapper::Jingle::ICEUDP::CandidateList candidateListWrapper; | |||||
for (const gloox::Jingle::ICEUDP::Candidate& candidate : static_cast<const gloox::Jingle::ICEUDP*>(m_Wrapped)->candidates()) | |||||
candidateListWrapper.push_back(glooxwrapper::Jingle::ICEUDP::Candidate{candidate.ip, candidate.port}); | |||||
return candidateListWrapper; | |||||
} | } | ||||
glooxwrapper::SessionManager::SessionManager(Client* parent, Jingle::SessionHandler* sh) | glooxwrapper::SessionManager::SessionManager(Client* parent, Jingle::SessionHandler* sh) | ||||
{ | { | ||||
m_HandlerWrapper = new SessionHandlerWrapper(sh, false); | m_HandlerWrapper = new SessionHandlerWrapper(sh, false); | ||||
m_Wrapped = new gloox::Jingle::SessionManager(parent->getWrapped(), m_HandlerWrapper); | m_Wrapped = new gloox::Jingle::SessionManager(parent->getWrapped(), m_HandlerWrapper); | ||||
} | } | ||||
glooxwrapper::SessionManager::~SessionManager() | glooxwrapper::SessionManager::~SessionManager() | ||||
{ | { | ||||
delete m_Wrapped; | delete m_Wrapped; | ||||
delete m_HandlerWrapper; | delete m_HandlerWrapper; | ||||
} | } | ||||
void glooxwrapper::SessionManager::registerPlugins() | void glooxwrapper::SessionManager::registerPlugins() | ||||
{ | { | ||||
// This calls m_factory.registerPlugin (see jinglesessionmanager.cpp), hence | |||||
// ~PluginFactory() will delete these new plugin templates. | |||||
m_Wrapped->registerPlugin(new gloox::Jingle::Content()); | m_Wrapped->registerPlugin(new gloox::Jingle::Content()); | ||||
m_Wrapped->registerPlugin(new gloox::Jingle::ICEUDP()); | m_Wrapped->registerPlugin(new gloox::Jingle::ICEUDP()); | ||||
} | } | ||||
glooxwrapper::Jingle::Session glooxwrapper::SessionManager::createSession(const JID& callee) | glooxwrapper::Jingle::Session glooxwrapper::SessionManager::createSession(const JID& callee) | ||||
{ | { | ||||
// The wrapped gloox SessionManager keeps track of this session and deletes it on ~SessionManager(). | |||||
gloox::Jingle::Session* glooxSession = m_Wrapped->createSession(callee.getWrapped(), m_HandlerWrapper); | gloox::Jingle::Session* glooxSession = m_Wrapped->createSession(callee.getWrapped(), m_HandlerWrapper); | ||||
// Hence the glooxwrapper::Jingle::Session may not own the gloox::Jingle::Session. | |||||
return glooxwrapper::Jingle::Session(glooxSession, false); | return glooxwrapper::Jingle::Session(glooxSession, false); | ||||
} | } |
Wildfire Games · Phabricator