diff options
| author | Edwin Mons <edwin.mons@isode.com> | 2014-05-23 09:01:23 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2014-06-22 12:35:26 (GMT) |
| commit | bd7f30aec53fc776be678577dbe4f9afec5898a6 (patch) | |
| tree | 66afad4382dc16f7405a856dd0b5abc38db51653 /Sluift/SluiftClient.cpp | |
| parent | 1eb14b6bde145ca54ac9b981df339fb8c56d3930 (diff) | |
| download | swift-contrib-bd7f30aec53fc776be678577dbe4f9afec5898a6.zip swift-contrib-bd7f30aec53fc776be678577dbe4f9afec5898a6.tar.bz2 | |
Sluift component support
Change-Id: Ib8af01c04c866e198c04d35236dea4da464c9116
Diffstat (limited to 'Sluift/SluiftClient.cpp')
| -rw-r--r-- | Sluift/SluiftClient.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Sluift/SluiftClient.cpp b/Sluift/SluiftClient.cpp index 9ff9d18..69472b8 100644 --- a/Sluift/SluiftClient.cpp +++ b/Sluift/SluiftClient.cpp @@ -1,115 +1,115 @@ /* - * Copyright (c) 2013-2014 Remko Tronçon + * Copyright (c) 2013-2014 Kevin Smith and Remko Tronçon * Licensed under the GNU General Public License. * See the COPYING file for more information. */ #include <Sluift/SluiftClient.h> #include <boost/numeric/conversion/cast.hpp> #include <Swiften/Client/ClientXMLTracer.h> #include <Swiften/Client/Client.h> #include <Swiften/Roster/XMPPRoster.h> #include <Sluift/SluiftGlobals.h> #include <Sluift/Lua/Exception.h> #include <Swiften/Elements/Message.h> #include <Swiften/Elements/PubSubEvent.h> #include <Swiften/Queries/RawRequest.h> -#include <Sluift/ClientHelpers.h> +#include <Sluift/Helpers.h> #include <Swiften/Elements/Presence.h> using namespace Swift; SluiftClient::SluiftClient( const JID& jid, const std::string& password, NetworkFactories* networkFactories, SimpleEventLoop* eventLoop) : networkFactories(networkFactories), eventLoop(eventLoop), tracer(NULL) { client = new Client(jid, password, networkFactories); client->setAlwaysTrustCertificates(); client->onDisconnected.connect(boost::bind(&SluiftClient::handleDisconnected, this, _1)); client->onMessageReceived.connect(boost::bind(&SluiftClient::handleIncomingMessage, this, _1)); client->onPresenceReceived.connect(boost::bind(&SluiftClient::handleIncomingPresence, this, _1)); client->getPubSubManager()->onEvent.connect(boost::bind(&SluiftClient::handleIncomingPubSubEvent, this, _1, _2)); client->getRoster()->onInitialRosterPopulated.connect(boost::bind(&SluiftClient::handleInitialRosterPopulated, this)); } SluiftClient::~SluiftClient() { delete tracer; delete client; } void SluiftClient::connect() { rosterReceived = false; disconnectedError = boost::optional<ClientError>(); client->connect(options); } void SluiftClient::connect(const std::string& host, int port) { rosterReceived = false; options.manualHostname = host; options.manualPort = port; disconnectedError = boost::optional<ClientError>(); client->connect(options); } void SluiftClient::setTraceEnabled(bool b) { if (b && !tracer) { tracer = new ClientXMLTracer(client, options.boshURL.isEmpty()? false: true); } else if (!b && tracer) { delete tracer; tracer = NULL; } } void SluiftClient::waitConnected(int timeout) { Watchdog watchdog(timeout, networkFactories->getTimerFactory()); while (!watchdog.getTimedOut() && client->isActive() && !client->isAvailable()) { eventLoop->runUntilEvents(); } if (watchdog.getTimedOut()) { client->disconnect(); throw Lua::Exception("Timeout while connecting"); } if (disconnectedError) { - throw Lua::Exception(getClientErrorString(*disconnectedError)); + throw Lua::Exception(getErrorString(*disconnectedError)); } } bool SluiftClient::isConnected() const { return client->isAvailable(); } void SluiftClient::disconnect() { client->disconnect(); while (client->isActive()) { eventLoop->runUntilEvents(); } } void SluiftClient::setSoftwareVersion(const std::string& name, const std::string& version, const std::string& os) { client->setSoftwareVersion(name, version, os); } boost::optional<SluiftClient::Event> SluiftClient::getNextEvent( int timeout, boost::function<bool (const Event&)> condition) { Watchdog watchdog(timeout, networkFactories->getTimerFactory()); size_t currentIndex = 0; while (true) { // Look for pending events in the queue while (currentIndex < pendingEvents.size()) { Event event = pendingEvents[currentIndex]; if (!condition || condition(event)) { pendingEvents.erase( pendingEvents.begin() + boost::numeric_cast<int>(currentIndex)); return event; } ++currentIndex; } |
Swift